"use strict" var ndarray = require("ndarray") var ops = require("ndarray-ops") var pool = require("typedarray-pool") function clone(array) { var dtype = array.dtype if(dtype === "generic" || dtype === "array") { dtype = "double" } var data = pool.malloc(array.size, dtype) var result = ndarray(data, array.shape) ops.assign(result, array) return result } exports.clone = clone function malloc(shape, dtype) { if(!dtype) { dtype = "double" } var sz = 1 var stride = new Array(shape.length) for(var i=shape.length-1; i>=0; --i) { stride[i] = sz sz *= shape[i] } return ndarray(pool.malloc(sz, dtype), shape, stride, 0) } exports.malloc = malloc function free(array) { if(array.dtype === "generic" || array.dtype === "array") { return } pool.free(array.data) } exports.free = free function zeros(shape, dtype) { if(!dtype) { dtype = "double" } var sz = 1 var stride = new Array(shape.length) for(var i=shape.length-1; i>=0; --i) { stride[i] = sz sz *= shape[i] } var buf = pool.malloc(sz, dtype) for(var i=0; i=0; --i) { stride[i] = sz sz *= shape[i] } var buf = pool.malloc(sz, dtype) for(var i=0; i=0; --i) { stride[i] = sz sz *= shape[i] } var buf = pool.malloc(sz, dtype) for(i=0; i=0; i--) { offsum += stride[i] mindim = Math.min(mindim,shape[i]) } for(i=0,offset=0; i