Skip to content

Commit fff8a4b

Browse files
authored
Fix #288 Add empty shape for 0-D scalar constant / scalar input (#289)
1 parent bc4cf3d commit fff8a4b

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

code/samples/mul_add.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const context = await navigator.ml.createContext();
33
const builder = new MLGraphBuilder(context);
44
// 1. Create a computational graph 'C = 0.2 * A + B'.
55
const constant = builder.constant(
6-
{dataType: 'float32'}, new Float32Array([0.2]));
6+
{dataType: 'float32', shape: []}, new Float32Array([0.2]));
77
const A = builder.input('A', desc);
88
const B = builder.input('B', desc);
99
const C = builder.add(builder.mul(A, constant), B);

nnotepad/js/nnotepad.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -447,8 +447,9 @@ export class NNotepad {
447447

448448
function serializeScalar(number, dataType) {
449449
const ctor = WebNNUtil.dataTypeToBufferType(dataType);
450-
return `_.constant({dataType:"${dataType}"}, new ${ctor.name}([${
451-
Util.stringifyNumber(number, dataType)}]))`;
450+
// building a 0-D scalar input with empty shape
451+
return `_.constant({dataType:"${dataType}", dimensions: [], shape: []},
452+
new ${ctor.name}([${Util.stringifyNumber(number, dataType)}]))`;
452453
}
453454
function suffixToDataType(suffix) {
454455
return {

0 commit comments

Comments
 (0)