@hoff97/tensor-js
Version:
PyTorch like deep learning inferrence library
38 lines • 1.66 kB
JavaScript
import { CPUTensor } from '../../../../tensor/cpu/tensor';
import { SparseTensor } from '../../../../tensor/sparse/tensor';
import { WASMTensor } from '../../../../tensor/wasm/tensor';
import { divideDenseCPU, divideSparseCPU } from './cpu';
import { divideDenseWASM, divideSparseWASM } from './wasm';
export function divide(a, b, resultShape, alpha) {
if (b instanceof SparseTensor) {
return divideSparse(a, b, resultShape, alpha);
}
else {
return divideDense(a, b, resultShape, alpha);
}
}
function divideSparse(a, b, resultShape, alpha) {
if (a.nnz !== b.nnz) {
throw new Error('Element wise division with two sparse tensors expects the same sparsity pattern, and thus the same number of nonzero entries in both tensors');
}
else if (a.denseDims !== b.denseDims) {
throw new Error('Element wise division with two sparse tensors expects the same number of sparse and dense dimensions in both tensors');
}
if (a.values instanceof CPUTensor) {
return divideSparseCPU(a, b, resultShape, alpha);
}
else if (a.values instanceof WASMTensor) {
return divideSparseWASM(a, b, resultShape, alpha);
}
throw new Error('Sparse-sparse matrix division not supported on WebGL backend');
}
function divideDense(a, b, resultShape, alpha) {
if (b instanceof CPUTensor) {
return divideDenseCPU(a, b, resultShape, alpha);
}
else if (b instanceof WASMTensor) {
return divideDenseWASM(a, b, resultShape, alpha);
}
throw new Error('Sparse-dense matrix element wise division not supported on WebGL backend');
}
//# sourceMappingURL=divide.js.map