question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Use TypedArray to instantiate tensor - Doc/code inconsistency

See original GitHub issue

TensorFlow.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

See https://github.com/tensorflow/tfjs-core/blob/fa37dd0e9f4729c78eceba7b89632cbbfcbde3cb/src/util.ts#L416

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:

  1. Rework the doc so that TypedArray is replaced by the actual expected types or
  2. Allow any kind of TypedArray (preferred solution of course).

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:8
  • Comments:5

github_iconTop GitHub Comments

2reactions
jellingcommented, Apr 29, 2020

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.

0reactions
aknoerigcommented, Jul 9, 2020

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found