Skip to content

Commit

Permalink
[UPDATE] README. [EXAMPLES] mget.
Browse files Browse the repository at this point in the history
  • Loading branch information
kgryte committed Jun 1, 2015
1 parent 865fbcc commit d81a6bf
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 0 deletions.
61 changes: 61 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,67 @@ value = mat.iget( -3 );
__Note__: out-of-bounds indices will return a value of `undefined`.


<a name="matrix-mget"></a>
#### mat.mget( i[, j] )

Returns multiple `Matrix` elements. If provided a single argument, `i` is treated as an `array` of linear [indices](#linear-indexing) (`index >= 0`). Otherwise, `i` and `j` are `integer` arrays which specify rows and column indices.

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

var mat = matrix( data, [5,2] );
/*
[ 0 2
4 6
8 10
12 14
16 18 ]
*/

// Scramble the second column:
var vals = mat.mget( [1,5,3,9,7] );
// returns [2,10,6,18,14]

// Extract select rows and columns in arbitrary order:
var mat1 = mat.mget( [1,3,2], [1] );
/*
[ 4
14
8 ]
*/
```

If `i` or `j` is `null`, all rows (columns) are extracted.

```
// Replicate a column:
var rep = mat.mget( null, [1,1,1,1,1] );
/*
[ 2 2 2 2 2
6 6 6 6 6
10 10 10 10 10
14 14 14 14 14
18 18 18 18 18 ]
*/
// Tile select rows and columns:
var tile = mat.mget( [1,2,1,2], [0,1,0,1] );
/*
[
4 6 4 6
8 10 8 10
4 6 4 6
8 10 8 10
]
*/
```

__Note__: out-of-bounds indices are ignored.


<a name="matrix-sget"></a>
#### mat.sget( subsequence )

Expand Down
6 changes: 6 additions & 0 deletions examples/fancy_getters.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,9 @@ console.log( mat.sget( ':,::-1' ) );

// Out-of-bounds subsequence:
console.log( mat.sget( '50:100,:' ) );

// Replicate a column:
console.log( mat.mget( null, [1,1,1,1,1] ) );

// Tile extracted rows and columns:
console.log( mat.mget( [1,2,1,2,1,2,1,2], [0,1,0,1,0,1,0,1] ) );

0 comments on commit d81a6bf

Please sign in to comment.