Comments (4)
With non-view matrices we can do this:
let mut a = matrix![1, 2; 3, 4];
let b = matrix![10, 11; 12, 13];
a = b;
assert_eq!(a, b);
With view matrices, we can’t do this:
let mut a = matrix![1, 2; 3, 4];
let b = matrix![10, 11; 12, 13];
let mut view_a = a.fixed_view_mut::<2, 2>();
view_a = b;
Which makes sense, since view_a
and b
don’t have the same type anyway.
But I’ve seen many beginners struggle with the fact that it doesn’t compile. They usually expect that this effectively fills view_a
with the content of b
.
Or even worst, they will often assume that doing view_a = view_b
will actually change the content of the matrix targeted by view_a
(just like a = b
changes the value identified by a
).
All this is obvious when you are very familiar with rust and have some experience with nalgebra
. But many users of nalgebra
come from straight from C++ or python before having a chance to fully grasp the subtlety (or rather, the lack of subtlety) of the semantic of rust’s =
So the message I would like to give in the doc is that view_a = b
doesn’t compile, and even view_a = view_b
won’t do what you might think it will when it compiles (i.e. it won’t replace the content of the matrix targeted by view_a
).
from nalgebra.
I do not understand correctly. what is the meaning.
Do you mean that the assignment operator =
does not work for views due to the fact that if you try:
use nalgebra::{matrix, vector};
fn main() {
let mut a = matrix![1.0, 2.0; 3.0, 4.0];
let mut b = a.fixed_view_mut::<2, 1>(0, 0);
let c = vector![5.0, 6.0];
b = c;
}
It fails because it is a vector?
But in general you are allowed to assign =
a view to another view (if they have the same dimensions) like here:
use nalgebra::{matrix, vector};
fn main() {
let mut a = matrix![1.0, 2.0; 3.0, 4.0];
let mut b = a.fixed_view_mut::<2, 1>(0, 0);
let mut d = matrix![5.0, 6.0; 7.0, 8.0];
let mut c = d.fixed_view_mut::<2, 1>(0, 0);
b = c;
}
from nalgebra.
I'm... actually not sure what makes sense to say here. We also cannot use =
to assign to a matrix, we also have to use .copy_from
there, so there doesn't seem to be any particular limitations of views here. I'm not sure, @sebcrozet maybe you can elaborate on what you had in mind in the discussion forum post?
from nalgebra.
@Andlon and @sebcrozet thanks for your support.
I have opened a pull request on the repository of the documentation. I hope it solved the problem.
from nalgebra.
Related Issues (20)
- Nalgebra compile error in release mode only HOT 1
- [feature request] Add pseudo determinant HOT 1
- add symmetric_eigen_unordered
- Macros for RowVector and RowDVector
- Alga traits not implemented by statically-sized matrices/vectors? HOT 5
- Incorrect results from pseudo_inverse HOT 4
- Matrix multiplication does not work over all generics, with misleading compiler error HOT 1
- Similarity scaling private
- `VectorView?` type alias too restrictive? HOT 1
- nalgebra_glm's Functions Don't Account for Unsigned Integer Types.
- Changed serialization breaks things HOT 3
- Instable Matrix determinants (compared to numpy, online calculator) HOT 18
- assertion at VectorView3::<T>::from(&view3_from_owned3).clone_owned()
- Add a way to get a column slice HOT 2
- Missed minor version bump? HOT 2
- Wrong result of min() and max() in nalgebra::base::min_max::Matrix when f64::NAN is included HOT 4
- CUDA target is unmaintained HOT 1
- lapack qr factorization HOT 1
- When using nalgebra_glm, how to call transform_point?
- Planes and Culling Frustums HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nalgebra.