Use TypedArray to instantiate tensor - Doc/code inconsistency
See original GitHub issueTensorFlow.js version
tfjs-core: 0.13.2 tfjs-layers: 0.8.1 tfjs-converter: 0.6.1 tfjs: 0.13.1
Browser version
Chrome 69.0.3497.100 (Official Build) (64-bit)
Describe the problem or feature request
The doc says: tf.tensor1d (values, dtype?) values (TypedArray|Array) The values of the tensor. Can be array of numbers, or a TypedArray
However the code checks that values is either:
- Float32Array
- Int32Array
- Uint8Array
Code to reproduce the bug / link to feature request
Result: I have been scratching my head for an hour on this:
> tf.tensor1d(new Uint16Array([1, 2, 3, 4]))
tf-core.esm.js:17 Uncaught Error: tensor1d() requires values to be a flat/TypedArray
But this IS a TypedArray.
I would suggest to either:
- Rework the doc so that TypedArray is replaced by the actual expected types or
- Allow any kind of TypedArray (preferred solution of course).
Issue Analytics
- State:
- Created 5 years ago
- Reactions:8
- Comments:5
Top Results From Across the Web
tensor1d requires value to be a flat/ typedarray - Stack Overflow
As @alkanen already commented the value you pass to tensor1d is an array of arrays. ( [[val],[val]] ). As I understood the values...
Read more >Best way to convert a list to a tensor? - PyTorch Forums
But I think better way is using torch.tensor() (note the case of 't' character). It converts your data to tensor but retains data...
Read more >TypedArray - JavaScript - MDN Web Docs
A TypedArray object describes an array-like view of an underlying binary data buffer. There is no global property named TypedArray, ...
Read more >Creates a tf.Tensor with the provided values, shape and dtype.
Pass an array of values to create a vector. tf.tensor([1, 2, 3, 4]).print(); ... tf.tensor(), but in general we recommend using tf.tensor1d() as...
Read more >Tensors in JavaScript | Kevin Scott
js using plain arrays as input. Another way of constructing a tensor is with a TypedArray . Typed Arrays. A Typed Array is...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Error message should still be improved as passing an Int16Array will return a message saying that a typed array is required and int16array is a typed array.
Thanks, but I wouldn’t feel comfortable to patch this in a solid way. 😕 Btw, adapting the documentation would be sufficient as a first step: just explicitly name the supported types of
TypedArray
.