Socket
Book a DemoInstallSign in
Socket

zeros

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

zeros - npm Package Compare versions

Comparing version

to
1.0.0

8

package.json
{
"name": "zeros",
"version": "0.0.0",
"version": "1.0.0",
"description": "Initialize an ndarray with zeros",

@@ -10,9 +10,9 @@ "main": "zeros.js",

"dependencies": {
"ndarray": "~1.0.0"
"ndarray": "^1.0.16"
},
"devDependencies": {
"tape": "~1.0.4"
"tape": "^4.0.0"
},
"scripts": {
"test": "tap test/*.js"
"test": "tape test/*.js"
},

@@ -19,0 +19,0 @@ "repository": {

@@ -14,2 +14,16 @@ zeros

It also accepts an optional dtype as specified in the [ndarray](https://github.com/scijs/ndarray) docs. For example,
```javascript
//Creates a 64x64 ndarray over a float32array filled with 0
var x = zeros([64, 64], 'float32')
```
This makes it easy to create an array with the same size and dtype as an existing array:
```javascript
var x = zeros([64, 64], 'float32')
var y = zeros( x.shape, x.dtype )
```
If you find yourself frequently creating the same array over and over though, [ndarray-scratch](https://github.com/mikolalysenko/ndarray-scratch) may be a better option.
## Install

@@ -20,6 +34,21 @@ Just use npm:

### `require("zeros")(shape)`
### `require("zeros")(shape[, dtype])`
Creates an ndarray with the given shape that is initialized to zero
* `shape` is the shape of the resulting array
* `dtype` is the data type of the array to allocate. Must be one of:
+ `"array"`
+ `"uint8"`
+ `"uint16"`
+ `"uint32"`
+ `"int8"`
+ `"int16"`
+ `"int32"`
+ `"float"`
+ `"float32"`
+ `"double"`
+ `"float64"`
+ `"data"`
+ `"uint8_clamped"`
+ `"buffer"`

@@ -26,0 +55,0 @@ **Returns** An array which is initialized to 0

@@ -5,8 +5,41 @@ "use strict"

module.exports = function zeros(shape) {
var sz = 1
function dtypeToType(dtype) {
switch(dtype) {
case 'uint8':
return Uint8Array;
case 'uint16':
return Uint16Array;
case 'uint32':
return Uint32Array;
case 'int8':
return Int8Array;
case 'int16':
return Int16Array;
case 'int32':
return Int32Array;
case 'float':
case 'float32':
return Float32Array;
case 'double':
case 'float64':
return Float64Array;
case 'uint8_clamped':
return Uint8ClampedArray;
case 'generic':
case 'buffer':
case 'data':
case 'dataview':
return ArrayBuffer;
case 'array':
return Array;
}
}
module.exports = function zeros(shape, dtype) {
dtype = dtype || 'float64';
var sz = 1;
for(var i=0; i<shape.length; ++i) {
sz *= shape[i]
sz *= shape[i];
}
return ndarray(new Float64Array(sz), shape)
}
return ndarray(new (dtypeToType(dtype))(sz), shape);
}
SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.