liuliu / s4nnc

Swift for NNC
https://libnnc.org
BSD 3-Clause "New" or "Revised" License
70 stars 8 forks source link

How to copy data to a variable from a tensor? #5

Closed ghost closed 1 year ago

ghost commented 1 year ago

i tried

graph!.variable(Tensor<Float16>(ten))[0..<320, 0..<320, 0..<3, 0..<3] =  graph!.variable(Tensor<Float16>(cached_weights[name]))[0..<320, 0..<320, 0..<3, 0..<3] 

both ten and cached_weights[name] are any tensors.

I get this error: examples/dylib_interface.swift:114:56: error: cannot assign through subscript: function call returns immutable value

liuliu commented 1 year ago
variable[0..<320, 0..<320, 0..<3, 0..<3] = graph.variable(tensor[0..<320, 0..<320, 0..<3, 0..<3])

You cannot create a variable inplace and assign values.