Skip to content

Commit

Permalink
Merge pull request #3 from compute-io/develop
Browse files Browse the repository at this point in the history
Support new matrix API.
  • Loading branch information
Planeshifter committed Jun 9, 2015
2 parents 7969312 + 75e7716 commit 0b4f0bb
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 7 deletions.
4 changes: 3 additions & 1 deletion lib/matrix.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ function variance( out, mat, bias, dim ) {
x,
M, N,
s0, s1,
o,
i, j, k;

if ( dim === 1 ) {
Expand All @@ -35,8 +36,9 @@ function variance( out, mat, bias, dim ) {
if ( M === 0 || N === 0 ) {
return null;
}
o = mat.offset;
for ( i = 0; i < M; i++ ) {
k = i * s0;
k = o + i*s0;
M2 = 0;
mu = 0;
delta = 0;
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,17 @@
},
"dependencies": {
"compute-array-constructors": "^1.0.0",
"dstructs-matrix": "^1.0.0",
"dstructs-matrix": "^2.0.0",
"validate.io-array-like": "^1.0.0",
"validate.io-boolean-primitive": "^1.0.0",
"validate.io-function": "^1.0.2",
"validate.io-matrix-like": "^1.0.0",
"validate.io-matrix-like": "^1.0.2",
"validate.io-object": "^1.0.4",
"validate.io-positive-integer": "^1.0.0",
"validate.io-string-primitive": "^1.0.0"
},
"devDependencies": {
"chai": "2.x.x",
"chai": "3.x.x",
"mocha": "2.x.x",
"coveralls": "^2.11.1",
"istanbul": "^0.3.0",
Expand Down
26 changes: 23 additions & 3 deletions test/test.matrix.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* global describe, it, require */
/* global describe, it, require, beforeEach */
'use strict';

// MODULES //
Expand Down Expand Up @@ -31,8 +31,10 @@ describe( 'matrix variance', function tests() {
for ( i = 0; i < data.length; i++ ) {
data[ i ] = i + 1;
}
mat = matrix( data, [5,5], 'int8' );

beforeEach( function before() {
mat = matrix( data, [5,5], 'int8' );
});

it( 'should export a function', function test() {
expect( variance ).to.be.a( 'function' );
Expand All @@ -52,6 +54,15 @@ describe( 'matrix variance', function tests() {
expected = '2.5;2.5;2.5;2.5;2.5';

assert.strictEqual( p.toString(), expected );

// Flip matrix up-down:
mat.strides[ 0 ] *= -1;
mat.offset = mat.length + mat.strides[ 0 ];

p = variance( out, mat );
expected = '2.5;2.5;2.5;2.5;2.5';

assert.strictEqual( p.toString(), expected, 'flipud' );
});

it( 'should compute the variance along matrix rows', function test() {
Expand All @@ -63,9 +74,18 @@ describe( 'matrix variance', function tests() {
expected = '62.5,62.5,62.5,62.5,62.5';

assert.strictEqual( p.toString(), expected );

// Flip matrix left-right:
mat.strides[ 1 ] *= -1;
mat.offset = mat.strides[ 0 ] - 1;

p = variance( out, mat, false, 1 );
expected = '62.5,62.5,62.5,62.5,62.5';

assert.strictEqual( p.toString(), expected, 'fliplr' );
});

it( 'should compute the (biased) variance along matrix rows', function test() {
it( 'should compute the population (biased sample) variance', function test() {
var out, p, expected;

out = matrix( [1,5], 'float64' );
Expand Down

0 comments on commit 0b4f0bb

Please sign in to comment.