Skip to content

Commit

Permalink
[EXAMPLES] split examples into sep files.
Browse files Browse the repository at this point in the history
  • Loading branch information
kgryte committed May 31, 2015
1 parent 647b4bf commit 5219b69
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 21 deletions.
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ __Note__: out-of-bounds indices will silently fail.
<a name="matrix-sset"></a>
#### mat.sset( subsequence, value[, thisArg] )

Sets `Matrix` elements according to a specified [subsequence](https://github.com/compute-io/indexspace). The subsequence must specify __both__ row and column subsequences; e.g., `'3:7,5:9'`, where `3:7` corresponds to row subscripts `3,4,5,6` and `5:9` corresponds to column subscripts `5,6,7,8`. The second argument may be either a `number` primitive, a `Matrix` containing values to set, or a callback `function`.
Sets `Matrix` elements according to a specified [`subsequence`](https://github.com/compute-io/indexspace). The `subsequence` must specify __both__ row and column subsequences; e.g., `'3:7,5:9'`, where `3:7` corresponds to row subscripts `3,4,5,6` and `5:9` corresponds to column subscripts `5,6,7,8`. The second argument may be either a `number` primitive, a `Matrix` containing values to set, or a callback `function`.

``` javascript
var data = new Float32Array( 10*10 );
Expand Down Expand Up @@ -345,7 +345,7 @@ __Note__: out-of-bounds indices will return a value of `undefined`.
<a name="matrix-sget"></a>
#### mat.sget( subsequence )

Returns `Matrix` elements in a new `Matrix` according to a specified [`subsequence`](https://github.com/compute-io/indexspace). The subsequence must specify __both__ row and column subsequences; e.g., `'3:7,5:9'`, where `3:7` corresponds to row subscripts `3,4,5,6` and `5:9` corresponds to column subscripts `5,6,7,8`. If no `subsequence` subscripts correspond to `Matrix` elements, the method return an empty `Matrix`.
Returns `Matrix` elements in a new `Matrix` according to a specified [`subsequence`](https://github.com/compute-io/indexspace). The `subsequence` must specify __both__ row and column subsequences; e.g., `'3:7,5:9'`, where `3:7` corresponds to row subscripts `3,4,5,6` and `5:9` corresponds to column subscripts `5,6,7,8`. If no `subsequence` subscripts correspond to `Matrix` elements, the method returns an empty `Matrix`.

``` javascript
var submatrix;
Expand All @@ -359,7 +359,7 @@ submatrix = mat.sget( ':,:' ); // Copy a matrix
8 9 ]
*/

submatrix = mat.sget( '1:5,:' );
submatrix = mat.sget( '1:4,:' );
/*
[ 2 3
4 5
Expand All @@ -384,7 +384,7 @@ submatrix = mat.sget( ':,::-1' ); // flip left-to-right
9 8 ]
*/

submarix = mat.sget( '50:100,:' );
submatrix = mat.sget( '50:100,:' );
/*
[]
*/
Expand All @@ -393,6 +393,8 @@ submarix = mat.sget( '50:100,:' );
For further subsequence documentation, see [compute-indexspace](https://github.com/compute-io/indexspace).




===
<a name="matrix-constructor"></a>
### Constructor
Expand Down
3 changes: 2 additions & 1 deletion TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,6 @@ TODO
- separate module? => `compute-print-matrix`
- does not seem essential to core functionality
11. validate.io-matrix / validate.io-matrix-like
12.
12. benchmark fancy (subsequence) get versus normal `get`
13.

27 changes: 27 additions & 0 deletions examples/fancy_getters.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
'use strict';

var matrix = require( './../lib' );

var data, mat, i;

data = new Int8Array( 5*2 );
for ( i = 0; i < data.length; i++ ) {
data[ i ] = i;
}

mat = matrix( data, [5,2] );

// Copy a matrix:
console.log( mat.sget( ':,:' ) );

// Extract a submatrix:
console.log( mat.sget( '1:4,:' ) );

// Flip a matrix top-to-bottom:
console.log( mat.sget( '::-1,:' ) );

// Flip a matrix left-to-right:
console.log( mat.sget( ':,::-1' ) );

// Out-of-bounds subsequence:
console.log( mat.sget( '50:100,:' ) );
22 changes: 22 additions & 0 deletions examples/fancy_setters.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
'use strict';

var matrix = require( './../lib' );

var data, A, B, i;

data = new Int8Array( 10*10 );
for ( i = 0; i < data.length; i++ ) {
data[ i ] = i;
}
// Create a 10x10 matrix:
A = matrix( data, [10,10] );

// Extract a 4x4 submatrix from A:
console.log( A.sget( '3:7,5:9' ) );

// Create a zero-filled matrix:
B = matrix( [2,2], 'int8' );

// Set a submatrix in A to the zero-filled matrix B:
A.sset( '4:6,6:8', B );
console.log( A.sget( '3:7,5:9' ) );
16 changes: 0 additions & 16 deletions examples/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,3 @@ mat.set( 1, 1, 5 );

// Confirm that the matrix element was set:
console.log( mat.get( 1, 1 ) );


var arr = new Float32Array( 10*10 );

for ( var i = 0; i < arr.length; i++ ) {
arr[ i ] = i;
}

mat = matrix( arr, [10,10] );

console.log( mat.sget( '3:7,5:9' ) );

var mat1 = matrix( [2,2], 'float32' );

mat.sset( '4:6,6:8', mat1 );
console.log( mat.sget( '3:7,5:9' ) );

0 comments on commit 5219b69

Please sign in to comment.