Skip to content

Problem when running TF.js with Jest (unit testing) #545

Closed
@DABH

Description

@DABH

TensorFlow.js version

0.12.3

Browser version

Node.js 10.6.0 (no browser)
Typescript 2.7.1

Describe the problem or feature request

I'm trying to use tf.sum() and tf.squaredDifference() (see below). Two issues -- some or all might be my fault:

  1. According to the docs, I can pass a tf.scalar to tf.squaredDifference; however, I get a Typescript error when passing a tf.scalar unless I cast to any. Seems it's expecting a Tensor. Are the docs wrong, or is the Typescript definition too restrictive here?
  2. When I run the below code to sum my tensor (vector), I get the error tensor1d() requires values to be a flat/TypedArray. This already should be a 1D tensor/vector, so why is tfjs complaining here? But moreover, the docs suggest I can sum with higher-order tensors as well, so not sure what the 1D restriction is about. Any ideas would be welcome!

Thanks in advance!

Code to reproduce the bug / link to feature request

    // state is a tf.Tensor1D
    console.log(state.squaredDifference(tf.scalar(0) as any).sum());

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions