[WebNN EP] Fixed bug in usage of Array.reduce() (#22944)
In JS, reduce of empty array with no initial value will throw error. Fix it by checking the array length firstly.
This commit is contained in:
Родитель
c284a686f2
Коммит
fe749a88a5
|
@ -78,7 +78,7 @@ const calculateByteLength = (dataType: MLOperandDataType, shape: readonly number
|
|||
if (!size) {
|
||||
throw new Error('Unsupported data type.');
|
||||
}
|
||||
return Math.ceil((shape.reduce((a, b) => a * b) * size) / 8);
|
||||
return shape.length > 0 ? Math.ceil((shape.reduce((a, b) => a * b) * size) / 8) : 0;
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
Загрузка…
Ссылка в новой задаче