compute-flipud
v1.0.0
Published
Flips a matrix vertically.
Downloads
13
Maintainers
Readme
flipud
Flips a matrix vertically.
Installation
$ npm install compute-flipud
For use in the browser, use browserify.
Usage
var flipud = require( 'compute-flipud' );
flipud( x[, opts] )
Flips a matrix vertically.
var matrix = require( 'dstructs-matrix' );
var mat = matrix( [2,3] );
mat.set( 1, 0, 1 )
.set( 0, 1, 2 )
.set( 1, 2, 3 );
/*
[ 0 2 0
1 0 3 ]
*/
var ud = flipud( mat );
/*
[ 1 0 3
0 2 0 ]
*/
By default, the function returns a new matrix instance. To mutate the input matrix, set the copy
option to false
.
var ud = flipud( mat, {
'copy': false
});
/*
[ 1 0 3
0 2 0 ]
*/
var bool = ( mat === ud );
// returns true
Examples
var matrix = require( 'dstructs-matrix' ),
flipud = require( 'compute-flipud' );
var data,
mat,
ud, i;
data = new Int8Array( 10 );
for ( i = 0; i < data.length; i++ ) {
data[ i ] = i;
}
mat = matrix( data, [5,2], 'int8' );
/*
[ 0 1
2 3
4 5
6 7
8 9 ]
*/
ud = flipud( mat );
/*
[ 8 9
6 7
4 5
2 3
0 1 ]
*/
To run the example code from the top-level application directory,
$ node ./examples/index.js
Tests
Unit
Unit tests use the Mocha test framework with Chai assertions. To run the tests, execute the following command in the top-level application directory:
$ make test
All new feature development should have corresponding unit tests to validate correct functionality.
Test Coverage
This repository uses Istanbul as its code coverage tool. To generate a test coverage report, execute the following command in the top-level application directory:
$ make test-cov
Istanbul creates a ./reports/coverage
directory. To access an HTML version of the report,
$ make view-cov
License
Copyright
Copyright © 2015. The Compute.io Authors.