Hello everyone,
I have used nimhdf5 <https://github.com/Vindaar/nimhdf5> to open netcdf files and casted the data to tensor. Everything worked fine. The problem I encountered was that, I want to operate on those elements of tensor that are not equal to zero. The certain code which gave an error was:
x[x !=. 0.0] *.= sort(y[y !=. 0.0]) /. sort(x[x !=. 0.0])
The error message said that x is immutable not var but I declared x as var. Maybe nim treated those elements of x that are not equal to zero as immutable. Does anyone know any solution to this problem.
Thanks in advance.
[x !=. 0] *.= ....
. Thanks anyway.First of all I'm happy to hear that nimhdf5 works well to read NetCDF files!
Slicing on tensors in arraymancer based on boolean conditionals was only added relatively recently. I assume that it's an oversight that there is no variant of index_select and similar (which [x !=. 0.0] calls), which returns a var Tensor.
It would be great if you could open an issue on the arraymancer repository! I'll try to take a look at this.
Yes, nimhdf5 works great. Thanks @Vindaar.
I'll try to open an issue on the arraymancer repository.
The result of a slicing is immutable, I tried to make the returned value mutable if the base tensor is mutable in the past but all hell broke lose.
Workaround is to assign it to a temporary first:
var x_tmp = x[x !=. 0.0]
x_tmp *.= sort(y[y !=. 0.0]) /. sort(x[x !=. 0.0])
I tried to make the returned value mutable if the base tensor is mutable in the past but all hell broke lose.
That's what I was worried about when I quickly checked the code yesterday. :|