@thi.ng/tensors
Version:
0D/1D/2D/3D/4D tensors with extensible polymorphic operations and customizable storage
18 lines (17 loc) • 428 B
JavaScript
import { defOpRT } from "./defoprt.js";
const filteredIndices = (pred) => defOpRT(
(acc, data, i) => {
if (pred(data[i])) acc.push(i);
return acc;
},
() => []
);
const nonZeroIndices = filteredIndices((x) => x !== 0);
const negativeIndices = filteredIndices((x) => x < 0);
const positiveIndices = filteredIndices((x) => x > 0);
export {
filteredIndices,
negativeIndices,
nonZeroIndices,
positiveIndices
};