Coder Social home page Coder Social logo

Comments (4)

sebcrozet avatar sebcrozet commented on May 29, 2024 2

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.

robbespo00 avatar robbespo00 commented on May 29, 2024

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.

Andlon avatar Andlon commented on May 29, 2024

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.

robbespo00 avatar robbespo00 commented on May 29, 2024

@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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.