compute-dims
Advanced tools
Comparing version 1.0.0 to 1.1.0
@@ -1,29 +0,1 @@ | ||
/** | ||
* | ||
* COMPUTE: dims | ||
* | ||
* | ||
* DESCRIPTION: | ||
* - Computes array dimensions. | ||
* | ||
* | ||
* NOTES: | ||
* [1] | ||
* | ||
* | ||
* TODO: | ||
* [1] | ||
* | ||
* | ||
* LICENSE: | ||
* MIT | ||
* | ||
* Copyright (c) 2014. Athan Reines. | ||
* | ||
* | ||
* AUTHOR: | ||
* Athan Reines. kgryte@gmail.com. 2014. | ||
* | ||
*/ | ||
'use strict'; | ||
@@ -33,3 +5,6 @@ | ||
var isInteger = require( 'validate.io-integer' ); | ||
var isPositiveInteger = require( 'validate.io-positive-integer' ), | ||
isArray = require( 'validate.io-array' ), | ||
ndarrayLike = require( 'validate.io-ndarray-like' ), | ||
createCopy = require( 'utils-copy' ); | ||
@@ -40,3 +15,3 @@ | ||
/** | ||
* FUNCTION: dims( arr, d, max ) | ||
* FUNCTION: dims( x, d, max ) | ||
* Computes array dimensions. | ||
@@ -54,3 +29,3 @@ * | ||
} | ||
if ( !Array.isArray( arr[0] ) ) { | ||
if ( !isArray( arr[0] ) ) { | ||
return; | ||
@@ -80,3 +55,3 @@ } | ||
val = arr[ i ]; | ||
if ( !Array.isArray( val ) || val.length !== dim ) { | ||
if ( !isArray( val ) || val.length !== dim ) { | ||
return false; | ||
@@ -95,34 +70,45 @@ } | ||
/** | ||
* FUNCTION: compute( arr[, max] ) | ||
* Computes array dimensions. | ||
* FUNCTION: compute( x[, max] ) | ||
* Computes dimensions. | ||
* | ||
* @param {Array} arr - input array | ||
* @param {Array} x - input object | ||
* @param {Number} [max] - limits the number of dimensions returned | ||
* @returns {Array|null} array of dimensions or null | ||
*/ | ||
function compute( arr, max ) { | ||
if ( !Array.isArray( arr ) ) { | ||
throw new TypeError( 'dims()::invalid input argument. Must provide an array.' ); | ||
} | ||
function compute( x, max ) { | ||
var d, flg; | ||
if ( arguments.length > 1 ) { | ||
if ( !isInteger( max ) || max < 1 ) { | ||
if ( !isPositiveInteger( max ) ) { | ||
throw new TypeError( 'dims()::invalid input argument. `max` option must be a positive integer.' ); | ||
} | ||
} | ||
var d, flg; | ||
// [0] Initialize the dimensions array: | ||
d = [ arr.length ]; | ||
if ( ndarrayLike( x ) === true ) { | ||
d = createCopy( x.shape ); | ||
if ( max && max <= d.length ) { | ||
d.length = max; | ||
} | ||
return d; | ||
} | ||
// [1] Recursively determine array dimensions: | ||
dims( arr, d, max ); | ||
if ( isArray( x ) ) { | ||
// [0] Initialize the dimensions array: | ||
d = [ x.length ]; | ||
// [2] Check that all array element dimensions are consistent... | ||
if ( d.length > 1 ) { | ||
flg = check( arr, d.slice( 1 ) ); | ||
if ( !flg ) { | ||
return null; | ||
// [1] Recursively determine array dimensions: | ||
dims( x, d, max ); | ||
// [2] Check that all array element dimensions are consistent... | ||
if ( d.length > 1 ) { | ||
flg = check( x, d.slice( 1 ) ); | ||
if ( !flg ) { | ||
return null; | ||
} | ||
} | ||
return d; | ||
} | ||
return d; | ||
throw new TypeError( 'dims()::invalid input argument. Must provide an array, matrix or ndarray.' ); | ||
} // end FUNCTION compute() | ||
@@ -129,0 +115,0 @@ |
{ | ||
"name": "compute-dims", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "Computes array dimensions.", | ||
@@ -41,16 +41,18 @@ "author": { | ||
"dependencies": { | ||
"validate.io-integer": "^1.0.2" | ||
"utils-copy": "^1.0.0", | ||
"validate.io-array": "^1.0.6", | ||
"validate.io-matrix-like": "^1.0.2", | ||
"validate.io-ndarray-like": "^1.0.0", | ||
"validate.io-positive-integer": "^1.0.0" | ||
}, | ||
"devDependencies": { | ||
"chai": "1.x.x", | ||
"mocha": "1.x.x", | ||
"chai": "3.x.x", | ||
"coveralls": "^2.11.1", | ||
"istanbul": "^0.3.0" | ||
"dstructs-matrix": "^2.0.0", | ||
"istanbul": "^0.3.0", | ||
"jshint": "2.x.x", | ||
"jshint-stylish": "2.x.x", | ||
"mocha": "2.x.x" | ||
}, | ||
"licenses": [ | ||
{ | ||
"type": "MIT", | ||
"url": "http://www.opensource.org/licenses/MIT" | ||
} | ||
] | ||
"license": "MIT" | ||
} |
@@ -5,3 +5,3 @@ dims | ||
> Computes array dimensions. | ||
> Computes dimensions for arrays and matrices. | ||
@@ -20,3 +20,2 @@ | ||
To use the module, | ||
@@ -27,8 +26,10 @@ ``` javascript | ||
#### dims( arr[, max] ) | ||
#### dims( x[, max] ) | ||
Computes `array` dimensions, including nested `arrays`. | ||
Computes dimensions of `x`. `x` may be either an [`array`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array) (including nested `arrays`) or a [`matrix`](https://github.com/dstructs/matrix). | ||
``` javascript | ||
var data, d; | ||
var matrix = require( 'dstructs-matrix' ), | ||
data, | ||
d; | ||
@@ -42,5 +43,9 @@ data = [ 1, 2 ]; | ||
// returns [2,2] | ||
data = matrix( [1,2,3,4], [2,2] ) | ||
d = dims( data ); | ||
// returns [2,2] | ||
``` | ||
If an `array` element has a dimension inconsistent with other elements, the function returns `null`. | ||
If an `array` element has a dimension inconsistent with other elements, the function returns `null`. | ||
@@ -66,2 +71,6 @@ ``` javascript | ||
// returns [1,2] | ||
data = matrix( [1,2,3,4], [2,2] ); | ||
d = dims( data, 1 ); | ||
// returns [2] | ||
``` | ||
@@ -83,3 +92,3 @@ | ||
Unit tests use the [Mocha](http://visionmedia.github.io/mocha) test framework with [Chai](http://chaijs.com) assertions. To run the tests, execute the following command in the top-level application directory: | ||
Unit tests use the [Mocha](http://mochajs.org) test framework with [Chai](http://chaijs.com) assertions. To run the tests, execute the following command in the top-level application directory: | ||
@@ -108,13 +117,12 @@ ``` bash | ||
--- | ||
## License | ||
[MIT license](http://opensource.org/licenses/MIT). | ||
[MIT license](http://opensource.org/licenses/MIT). | ||
--- | ||
## Copyright | ||
Copyright © 2014. Athan Reines. | ||
Copyright © 2014-2015. The [Compute.io](https://github.com/compute-io) Authors. | ||
[npm-image]: http://img.shields.io/npm/v/compute-dims.svg | ||
@@ -121,0 +129,0 @@ [npm-url]: https://npmjs.org/package/compute-dims |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
8350
138
5
7
96
+ Addedutils-copy@^1.0.0
+ Addedvalidate.io-array@^1.0.6
+ Addedconst-max-uint32@1.0.2(transitive)
+ Addedconst-pinf-float64@1.0.0(transitive)
+ Addedobject-keys@1.1.1(transitive)
+ Addedregex-regex@1.0.0(transitive)
+ Addedtype-name@2.0.2(transitive)
+ Addedutils-copy@1.1.1(transitive)
+ Addedutils-copy-error@1.0.1(transitive)
+ Addedutils-indexof@1.0.0(transitive)
+ Addedutils-regex-from-string@1.0.0(transitive)
+ Addedvalidate.io-array@1.0.6(transitive)
+ Addedvalidate.io-array-like@1.0.2(transitive)
+ Addedvalidate.io-buffer@1.0.2(transitive)
+ Addedvalidate.io-integer-primitive@1.0.0(transitive)
+ Addedvalidate.io-matrix-like@1.0.2(transitive)
+ Addedvalidate.io-ndarray-like@1.0.0(transitive)
+ Addedvalidate.io-nonnegative-integer@1.0.0(transitive)
+ Addedvalidate.io-number-primitive@1.0.0(transitive)
+ Addedvalidate.io-positive-integer@1.0.0(transitive)
+ Addedvalidate.io-string-primitive@1.0.1(transitive)
- Removedvalidate.io-integer@^1.0.2