Skip to content

pow(1, NaN) differs between cpu and wasm backend #7461

Open
@hujiajie

Description

@hujiajie

Please 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

Describe the current behavior

{
  await tf.setBackend('cpu');
  const a = tf.scalar(1);
  const b = tf.scalar(NaN);
  const c = tf.pow(a, b);  // NaN
  const msg = `${tf.getBackend()}: pow(${(await a.data())[0]}, ${(await b.data())[0]}) = ${(await c.data())[0]}`;
  document.body.appendChild(document.createTextNode(msg));
  document.body.appendChild(document.createElement('br'));
}

{
  await tf.setBackend('wasm');
  const a = tf.scalar(1);
  const b = tf.scalar(NaN);
  const c = tf.pow(a, b);  // 1
  const msg = `${tf.getBackend()}: pow(${(await a.data())[0]}, ${(await b.data())[0]}) = ${(await c.data())[0]}`;
  document.body.appendChild(document.createTextNode(msg));
  document.body.appendChild(document.createElement('br'));
}

Describe the expected behavior
Not sure...

Should the results of different backends be consistent in this corner case?

If yes, pow(1, NaN) = 1 in the WASM and IEEE 754 spec, but ECMAScript prefers NaN propagation.

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.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions