to-matrix
Construct a matrix from an array of arrays.
Installation
$ npm install compute-to-matrix
For use in the browser, use browserify.
Usage
var toMatrix = ;
toMatrix( arr[, options ] )
Constructs a matrix
from an array
of arrays
.
var arr =1 2 34 5 67 8 9var mat = ;/*[ 1 2 34 5 67 8 9 ]*/
The function accepts the following options
:
- accessor: accessor
function
for accessingarray
values. - dtype:
matrix
data type. Default:float64
.
For non-numeric nested arrays
, provide an accessor function
for accessing array
values.
var arr ='x': 1 'x': 0 'x': 0'x': 0 'x': 1 'x': 0'x': 0 'x': 0 'x': 1;{return dx;}var mat =;/*[ 1 0 00 1 00 0 1 ]*/
The accessor
function is provided three arguments:
- d: the current element
- i: the row index of the current element
- j: the column index of the current element
By default, the matrix
elements are floating-point 64-bit numbers (float64
). To specify a different data type, set the dtype
option.
var arr =11 2332 41;var mat =;/*[ 1 23 4 ]*/
For supported data types, see dstructs-matrix.
Examples
var toMatrix = ;var nRowsnColsarrmati j;arr =2 4 3 11 2 2 17 3 9 711 9 9 83 2 3 1;nRows = arrlength;nCols = arr 0 length;mat = ;for i = 0; i < nRows; i++for j = 0; j < nCols; j++console;
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.