maths: switch dot to faster for loop (#667)
* maths: switch dot to faster for loop * Update src/utils/maths.js --------- Co-authored-by: Joshua Lochner <admin@xenova.com>
This commit is contained in:
parent
cdbc532cf6
commit
15b90b7523
|
@ -174,7 +174,11 @@ export function log_softmax(arr) {
|
|||
* @returns {number} The dot product of arr1 and arr2.
|
||||
*/
|
||||
export function dot(arr1, arr2) {
|
||||
return arr1.reduce((acc, val, i) => acc + val * arr2[i], 0);
|
||||
let result = 0;
|
||||
for (let i = 0; i < arr1.length; ++i) {
|
||||
result += arr1[i] * arr2[i];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue