tensorflow / swift

Swift for TensorFlow
https://tensorflow.org/swift
Apache License 2.0
6.12k stars 608 forks source link

Differentiable needs func moved(along: directions) -> Self #508

Open dabrahams opened 4 years ago

dabrahams commented 4 years ago

When a differentiable value uses heap storage and is multiply-referenced, move(along: directions) will first copy, and then update, the storage, which is inefficient. It should instead create new storage initialized with the result.

If you think about the way this plays out for an Array of differentiable values, you'll see that the only choice the Array currently has is to invoke e.move(along: d), in-place, which causes each element with shared storage to be copied and then updated.