-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
144 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
'use strict'; | ||
|
||
// MODULES // | ||
|
||
var matrix = require( './../lib' ); | ||
|
||
|
||
// VARIABLES // | ||
|
||
var start, | ||
stop, | ||
iArr, | ||
nRows, | ||
nCols, | ||
res, | ||
len, | ||
m, s, | ||
i; | ||
|
||
|
||
// -------------------------------------- | ||
// WARM-UP | ||
|
||
len = 1e6; | ||
for ( i = 0; i < len; i++ ) { | ||
i = i; | ||
} | ||
|
||
|
||
// -------------------------------------- | ||
// BENCHMARK | ||
|
||
len = 1e3; | ||
nRows = 128; | ||
nCols = 128; | ||
|
||
res = new Array( 1 ); | ||
|
||
iArr = new Float64Array( nRows*nCols ); | ||
for ( i = 0; i < nRows*nCols; i++ ) { | ||
iArr[ i ] = i; | ||
} | ||
|
||
m = matrix( iArr, [nRows,nCols] ); | ||
|
||
start = process.hrtime(); | ||
for ( i = 0; i < len; i++ ) { | ||
s = m.toString(); | ||
} | ||
stop = process.hrtime( start ); | ||
|
||
res[ 0 ] = stop[ 0 ] + stop[ 1 ]*1e-9; | ||
|
||
|
||
// -------------------------------------- | ||
// RESULTS | ||
|
||
console.log( 'toString:\t%d ops/sec', Math.floor( len/res[ 0 ] ) ); | ||
console.log( '\n' ); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
'use strict'; | ||
|
||
/** | ||
* FUNCTION: toString() | ||
* Returns a string representation of Matrix elements. Rows are delineated by semicolons. Column values are comma-delimited. | ||
* | ||
* @returns {String} string representation | ||
*/ | ||
function toString() { | ||
/* jshint validthis: true */ | ||
var nRows = this.shape[ 0 ], | ||
nCols = this.shape[ 1 ], | ||
s0 = this.strides[ 0 ], | ||
s1 = this.strides[ 1 ], | ||
m = nRows - 1, | ||
n = nCols - 1, | ||
str = '', | ||
r, | ||
i, j; | ||
|
||
for ( i = 0; i < nRows; i++ ) { | ||
r = i * s0; | ||
for ( j = 0; j < nCols; j++ ) { | ||
str += this.data[ r + j*s1 ]; | ||
if ( j < n ) { | ||
str += ','; | ||
} | ||
} | ||
if ( i < m ) { | ||
str += ';'; | ||
} | ||
} | ||
return str; | ||
} // end FUNCTION toString() | ||
|
||
|
||
// EXPORTS // | ||
|
||
module.exports = toString; |