Description
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
- Have I written custom code (as opposed to using a stock example script provided in TensorFlow.js):
- OS Platform and Distribution (e.g., Linux Ubuntu 16.04): Windows 11
- Mobile device (e.g. iPhone 8, Pixel 2, Samsung Galaxy) if the issue happens on mobile device:
- TensorFlow.js installed from (npm or script link):
https://cdn.jsdelivr.net/npm/@tensorflow/tfjs-core/dist/tf-core.js
https://cdn.jsdelivr.net/npm/@tensorflow/tfjs-backend-cpu/dist/tf-backend-cpu.js
https://cdn.jsdelivr.net/npm/@tensorflow/tfjs-backend-wasm/dist/tf-backend-wasm.js - TensorFlow.js version (use command below):
- Browser version: Chrome 110
- Tensorflow.js Converter Version:
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.