Code Monkey home page Code Monkey logo

Comments (5)

sebcrozet avatar sebcrozet commented on May 28, 2024

Hi! You could do something like this:

    let mut mat = Matrix4x3::repeat(1);
    let vec = RowVector3::new(1, 2, 3);
    mat.row_iter_mut().for_each(|mut row| row -= vec);

from nalgebra.

guchengxi1994 avatar guchengxi1994 commented on May 28, 2024

@sebcrozet Thanks for your advice, but according to your advide, I was using RowVector to construct a vector, but it seems not right

let m = rs.row_mean();
let _v = m.as_slice().to_vec();
for row in rs.row_iter_mut(){
      row = row - RowVector::from_vec(_v);       
}

rs is a Matrix.
image
I cannot fix this ...

from nalgebra.

sebcrozet avatar sebcrozet commented on May 28, 2024

The error here originates from the fact that the compiler doesn’t know what kind of row vector you want (dynamically sized? staticaly sized?) So you can for example do DRowVector::from_vec(_v) instead, where DRowVector is a dynamically sized row vector.

Anyway, you don’t need that conversion at all. Your variable m is already a row vector (because row_mean returns a row vector). So the to_vec/from_vec are not needed.

In addition, you can’t do row = row - RowVector::from_vec(_v) because row is a matrix view (whereas the result of a binary operation must be a whole new vector, it can’t be a view on an existing vector). So you need to apply the subtraction in-place:

let mean = rs.row_mean();
for mut row in rs.row_iter_mut() {
    row -= &mean;
}

from nalgebra.

guchengxi1994 avatar guchengxi1994 commented on May 28, 2024

@sebcrozet Thanks for your help!

from nalgebra.

wesley800 avatar wesley800 commented on May 28, 2024

@sebcrozet Sorry but I didn't found the DRowVector type. Maybe we just left out pub type DRowVector<T>=Matrix<T, U1, Dyn, VecStorage<T, U1, Dyn>>; somewhere?

Regarding another question, though which I'm not sure if worth a new issue, I'm trying to subtracting a row from another row within the same matrix. Of course this can't be written as in other languages because of rust's borrow checker. So I have to copy the subtractee into a new DRowVector (which led me to this issue) like this:

pub type DRowVector<T>=Matrix<T, U1, Dyn, VecStorage<T, U1, Dyn>>;
let t: DRowVector<f64> = mat.row(i-1).into();
mat.row_mut(i).sub_assign(t);

which seems to be redundant. Is there already a zero-copy way to do this operation, or should we add something like split_at_mut?

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.