-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Clone() doesn't actually clone? #1032
Comments
I think the problem is this: Tensors are supposed to be immutable, so This demonstrates the mutability more directly:
Output:
So, to produce the expected behavior, I think the CPU |
Clone makes a shallow copy of the tensor for performance reasons. If we do a true copy upon dataSync(), it will come at a cost of memory read/writes and increased garbage collection. We'll have to do it for the WebGL backend as well, for tensors that haven't been uploaded to GPU yet, or have recently been downloaded. I think we should start with documenting clone() better (emphasize that it does shallow copy) and revisit this if it becomes a more frequent issue. |
So in what other way can one achieve to sort the array / tensor without modifying the original tensor? Use a variable tensor and |
Slice the TypedArray using TypedArray.slice(). In this case: const myData = x.dataSync().slice();
myData.sort() |
To get help from the community, check out our Google group.
TensorFlow.js version
Latest (0.14.1)
Browser version
Latest Firefox + Chrome
Describe the problem or feature request
Clone() doesn't actually clone.
Code to reproduce the bug / link to feature request
You can run the following code on the tfjs API console (https://js.tensorflow.org/api/0.14.1/#clone)
Or seen synchronous:
Output:
Expected output:
The text was updated successfully, but these errors were encountered: