UNPKG

ml-matrix

Version:

Matrix manipulation and computation library

37 lines (33 loc) 984 B
'use strict'; exports.hypotenuse = function hypotenuse(a, b) { if (Math.abs(a) > Math.abs(b)) { var r = b / a; return Math.abs(a) * Math.sqrt(1 + r * r); } if (b !== 0) { var r = a / b; return Math.abs(b) * Math.sqrt(1 + r * r); } return 0; }; // For use in the decomposition algorithms. With big matrices, access time is // too long on elements from array subclass // todo check when it is fixed in v8 // http://jsperf.com/access-and-write-array-subclass exports.getEmpty2DArray = function (rows, columns) { var array = new Array(rows); for (var i = 0; i < rows; i++) { array[i] = new Array(columns); } return array; }; exports.getFilled2DArray = function (rows, columns, value) { var array = new Array(rows); for (var i = 0; i < rows; i++) { array[i] = new Array(columns); for (var j = 0; j < columns; j++) { array[i][j] = value; } } return array; };