After tf.Tensor creation, its value can be changed by input TypedArray (not immutable)
See original GitHub issuePlease make sure that this is a bug. As per our GitHub Policy, we only address code/doc bugs, performance issues, feature requests and build/installation issues on GitHub. tag:bug_template
System information
- Have I written custom code (as opposed to using a stock example script provided in TensorFlow.js): yes
- OS Platform and Distribution (e.g., Linux Ubuntu 16.04): macOS 11.2.3
- Mobile device (e.g. iPhone 8, Pixel 2, Samsung Galaxy) if the issue happens on mobile device: N/A
- TensorFlow.js installed from (npm or script link): <script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs@3.2.0"> </script>
- TensorFlow.js version (use command below): 3.2.0
- Browser version: Google Chrome | 89.0.4389.114
- Tensorflow.js Converter Version: N/A
Describe the current behavior
const array = new Float32Array([1, 2, 3, 4]);
const tensor = tf.tensor(array, [2, 2]);
tensor.print();
// Tensor
// [[1, 2],
// [3, 4]]
array[0] = 2;
tensor.print();
// Tensor
// [[2, 2],
// [3, 4]]
Describe the expected behavior
As the doc says, tf.Tensor
should be immutable. So change array
should not change the value of tensor
. It is expected that:
const array = new Float32Array([1, 2, 3, 4]);
const tensor = tf.tensor(array, [2, 2]);
tensor.print();
// Tensor
// [[1, 2],
// [3, 4]]
array[0] = 2;
tensor.print();
// Tensor
// [[1, 2],
// [3, 4]]
Standalone code to reproduce the issue Provide a reproducible test case that is the bare minimum necessary to generate the problem. If possible, please share a link to Colab/CodePen/any notebook.
Other info / logs Include any logs or source code that would be helpful to diagnose the problem. If including tracebacks, please include the full traceback. Large logs and files should be attached.
Issue Analytics
- State:
- Created 2 years ago
- Comments:10 (3 by maintainers)
Top GitHub Comments
@huningxin Thank you for raising this issue. I agree, we should document this limitation properly.
Are you satisfied with the resolution of your issue? Yes No