Skip to content

Binary operation for ArrayView #237

Closed
@termoshtt

Description

@termoshtt

I'm confusing errors arising around +.

let dist = Range::new(0, 1);
let a = Array::<f64, _>::random((5, 5));
let x0 = Array::<f64, _>::random(5);
let xs: Vec<_> = a.axis_iter(Axis(0)).map(|x| x + &x0);

I expect that x + &x0 produces new array since document says

&A @ &A which produces a new Array

But it produces an error:

error[E0369]: binary operation `+` cannot be applied to type `ndarray::ArrayBase<ndarray::ViewRepr<&f64>, usize>` 

After struggling, I find it works when I rewrite the last line as following:

let xs: Vec<_> = a.axis_iter(Axis(0)).map(|x| x.to_owned() + &x0);

I hope the first my code works. Is there any technical problem to implement Add for ArrayView?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions