1

I am attempting to multiply an arrayfire Matrix by a matrix of closures. Is there anyway to achieve this without using for loops?

My current code is as follows:

//Initialize the closures and assign to an arry
    let a = |x| {x*2.0};
    let b = |x| {x*3.0};
    let c = |x| {x*4.0};
    let values: [fn(f64) -> f64; 3] = [a,b,c];

//Create an arrayfire Matrix
    let dims = Dim4::new(&[3, 1, 1, 1]);
    let v = randu::<f64>(dims);

//Printing out the original arrayfire matrix 
    arrayfire::print(&v);

//A failed attempt to apply the closures to the matrix
    let v = &v * values;

//The desired output
    arrayfire::print(&v);

ExtaticGUR
  • 31
  • 4
  • I don't think that is possible even with rust's standard library vector. You would need to run map/filter on the iterator of the vector afaik. Having said that, such an operation cannot be done on object's of Array(from arrayfire crate). You can multiple an Array with another Array or a scalar only. – pradeep Sep 07 '20 at 06:00

0 Answers0