Skip to content
This repository has been archived by the owner on Oct 17, 2022. It is now read-only.

Commit

Permalink
max and min return shaped arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
abtExp committed Nov 1, 2017
1 parent a3ee579 commit 94100da
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 9 deletions.
2 changes: 1 addition & 1 deletion util/axisOps.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ module.exports = (shape, axis) => {
jumpLen *= shape[i];
}
jumpLen /= shape[axis];
for (let i = 0; i < (size - jumpLen); i++) {
for (let i = 0; i <= (size - jumpLen); i++) {
let inElems = [];
inElems.push(i);
for (let k = 1; k < shape[axis]; k++) {
Expand Down
13 changes: 6 additions & 7 deletions util/max.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,22 @@
module.exports = function max({ ar1, ar2 = null, axis = 0 }) {
const axisOps = require('./axisOps'),
{ flatten, arrange, calc_shape, calc_size } = require('../lib/core');
let maxElems = [];
let maxElems = [],
opShape = [];
if (!ar2) {
let shape = calc_shape(ar1),
elems = axisOps(shape, axis);
ar1 = flatten(ar1);
for (let i = 0; i < elems.length; i++) {
let max = ar1[elems[i][0]];
for (let j = 0; j < elems[i].length; j++) {
console.log(ar1[elems[i][j]]);
if (ar1[elems[i][j]] > max) {
max = ar1[elems[i][j]];
console.log('max is now :', max);
}
max = Math.max(ar1[elems[i][j]], max);
}
maxElems.push(max);
}
opShape = [];
} else {
opShape = calc_shape(ar2);
if (!Array.isArray(ar1) && Array.isArray(ar2)) {
ar2 = flatten(ar2);
maxElems = ar2.map(i => Math.max(ar1, i));
Expand All @@ -47,5 +46,5 @@ module.exports = function max({ ar1, ar2 = null, axis = 0 }) {
}
}
}
return maxElems;
return arrange(opShape, maxElems);
}
1 change: 0 additions & 1 deletion util/product.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ module.exports =
s2 = calc_shape(arr2);
if (s1.length === 2 && s2.length === 2) {
if (s1[1] === s2[0] && mode === 'matrix') {
console.log('producting matrix');
return arrange([s1[0], s2[1]], matmul(s1, s2, t1, t2, ));
} else if (mode === 'dot') {
if (s1.toString() === s2.toString()) {
Expand Down

0 comments on commit 94100da

Please sign in to comment.