type dMatrix with
member t.Item
with get(a: int, b: int) = t.dArray.[b+a*t.num_cols |> SizeT]
and set(a: int, b: int) (value: floatType) = t.dArray.[b+a*t.num_cols |> SizeT] <- value
member t.setItem(a: int, b: int) (value: floatType) = t.dArray.[b+a*t.num_cols |> SizeT] <- value
let a = dMatrix.createRandomUniformMatrix n m 50.f 50.0f
a.[1,1] <- 654.0f // Gives 'A value must be mutable in order to mutate the contents or take the address of a value type, e.g. 'let mutable x = ...''
a.setItem(1,1) 654.0f // Works fine.
I am not sure what is going in the above. dArray
is of type CudaDeviceVariable<float32>
from the ManagedCuda library if that helps.
Edit:
type dMatrix =
struct
val num_rows:int
val num_cols:int
val dArray: CudaDeviceVariable<floatType>
Here is how the struct above looks. Even if I make dArray mutable, it still does not work, but writing something like a.dArray.[SizeT 0] <- 2.5f
does. Is there any workaround for this?
Edit2: Turning the above into a record or a class solves the problem.