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)
- matrix literals or const constructors HOT 1
- `normalize` docs need expansion HOT 1
- Test flake in `f64::symmetric_eigen`
- Unit Quaternion logarithm inconsistent with exp HOT 1
- Matrix Views: non contiguous/regular slices
- Minimizing trait bound complexity when working with dimensional generics HOT 3
- SVD Computes Wrong Singular Values for Very Small-Valued Matrices HOT 1
- Make nalgebra_lapack::qr::QRScalar trait public
- Homographic transform via SVD/DLT - is it broken or am I doing it wrong?
- Inconsistency between Numpy/MATLAB and and nalgebra HOT 2
- Export crates used in public APIs
- unit quaternions and orthonormal matrices are only closed under successive multiplications in theory HOT 1
- Memory leak in generic_resize/reallocate_copy
- Inverting a 4x4 matrix with `try_inverse_mut` doesn't leave `self` unchanged if the inversion fails.
- Numerically vulnerable axis calculation in Rotation3
- How to construct a symmetric matrix in nalgebra? HOT 3
- `from_iter` implementation may run indefinitely HOT 8
- Request: Allow the multiplication of matrices of matrices
- Owned MatrixView Lifetime issues
- GAT in Allocator Trait HOT 2
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.