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.
我不确定上面发生了什么。如果有帮助,则属于ManagedCuda库dArray
中的类型。CudaDeviceVariable<float32>
编辑:
type dMatrix =
struct
val num_rows:int
val num_cols:int
val dArray: CudaDeviceVariable<floatType>
这是上面的结构的外观。即使我使 dArray 可变,它仍然不起作用,但编写类似的东西a.dArray.[SizeT 0] <- 2.5f
。有什么解决方法吗?
Edit2:将上述内容转换为记录或类可以解决问题。