array-kit 0.2.13 → 0.2.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/lib/NDArray.js +41 -8
  2. package/package.json +1 -1
package/lib/NDArray.js CHANGED
@@ -375,6 +375,39 @@ NDArray.prototype.flipAll = function() {
375
375
 
376
376
 
377
377
 
378
+ // Transpose: swap coordinates orders
379
+ NDArray.prototype.transpose = function( ... dimensionList ) {
380
+ // It's not possible to swap because each dimension look up for the source at its original place
381
+ const dMax = Math.min( dimensionList.length , this.dimensions ) ,
382
+ sizes = new Array( this.dimensions ) ,
383
+ mins = new Array( this.dimensions ) ,
384
+ maxs = new Array( this.dimensions ) ,
385
+ order = new Array( this.dimensions ) ,
386
+ strides = new Array( this.dimensions ) ,
387
+ backStrides = new Array( this.dimensions ) ;
388
+
389
+ for ( let d = 0 ; d < dMax ; d ++ ) {
390
+ const fromD = dimensionList[ d ] ;
391
+ sizes[ d ] = this.sizes[ fromD ] ;
392
+ mins[ d ] = this.mins[ fromD ] ;
393
+ maxs[ d ] = this.maxs[ fromD ] ;
394
+ order[ d ] = this.order[ fromD ] ;
395
+ strides[ d ] = this.strides[ fromD ] ;
396
+ backStrides[ d ] = this.backStrides[ fromD ] ;
397
+ }
398
+
399
+ this.sizes = sizes ;
400
+ this.mins = mins ;
401
+ this.maxs = maxs ;
402
+ this.order = order ;
403
+ this.strides = strides ;
404
+ this.backStrides = backStrides ;
405
+
406
+ return this ;
407
+ } ;
408
+
409
+
410
+
378
411
  /*
379
412
  Fix some axis and reduce the number of dimensions.
380
413
  Like .pick() in the "ndarray" package.
@@ -417,7 +450,7 @@ NDArray.prototype.select = function( ... coords ) {
417
450
  // Clone only the view, the data storage is the same
418
451
  NDArray.prototype.cloneView =
419
452
  NDArray.prototype.view = function() {
420
- const newNDArray = this._cloneGeometry( true ) ;
453
+ const newNDArray = this._cloneLogical( true ) ;
421
454
  newNDArray.data = this.data ;
422
455
  return newNDArray ;
423
456
  } ;
@@ -426,7 +459,7 @@ NDArray.prototype.view = function() {
426
459
 
427
460
  // Full clone
428
461
  NDArray.prototype.clone = function() {
429
- const newNDArray = this._cloneGeometry() ;
462
+ const newNDArray = this._cloneLogical() ;
430
463
  newNDArray._createDataFrom( this.data , this.dataStart , this.dataEnd ) ;
431
464
  return newNDArray ;
432
465
  } ;
@@ -435,7 +468,7 @@ NDArray.prototype.clone = function() {
435
468
 
436
469
  // Create a new clone of the current NDArray with the same geometry but an empty (but ready) data
437
470
  // The new data is limited to the used size (dataStart = 0) except if keepDataStart is set to true.
438
- NDArray.prototype._cloneGeometry = function( keepDataStart = false ) {
471
+ NDArray.prototype._cloneLogical = function( keepDataStart = false ) {
439
472
  const newNDArray = new NDArray( this.dimensions ) ;
440
473
 
441
474
  // Copy geometry
@@ -464,7 +497,7 @@ NDArray.prototype._cloneGeometry = function( keepDataStart = false ) {
464
497
 
465
498
 
466
499
  // Clone with a modified geometry
467
- NDArray.prototype._resizeGeometry = function( mins , maxs ) {
500
+ NDArray.prototype._resizeLogical = function( mins , maxs ) {
468
501
  const newNDArray = new NDArray( this.dimensions ) ;
469
502
 
470
503
  Object.assign( newNDArray.order , this.order ) ;
@@ -1114,7 +1147,7 @@ NDArray.prototype.fillVectorInRegion = function( mins , maxs , vector ) {
1114
1147
  The classic .map(), returning a new ND-Array with its own data storage.
1115
1148
  */
1116
1149
  NDArray.prototype.map = function( callback ) {
1117
- const newNDArray = this._cloneGeometry() ;
1150
+ const newNDArray = this._cloneLogical() ;
1118
1151
  newNDArray.data = this._newStorageOfTheSameKind() ;
1119
1152
 
1120
1153
  this._forEach( ( value , coords , index ) => {
@@ -1138,7 +1171,7 @@ NDArray.prototype.mapInRegion = function( mins , maxs , callback ) {
1138
1171
  }
1139
1172
 
1140
1173
  this._checkRegion( mins , maxs ) ;
1141
- const newNDArray = this._resizeGeometry( mins , maxs ) ;
1174
+ const newNDArray = this._resizeLogical( mins , maxs ) ;
1142
1175
  newNDArray.data = this._newStorageOfTheSameKind( newNDArray.dataEnd ) ;
1143
1176
 
1144
1177
  this._dualStepCallback( newNDArray , mins , maxs , mins , maxs , callback ) ;
@@ -1169,7 +1202,7 @@ NDArray.prototype.mapVectorInRegion = function( mins , maxs , callback ) {
1169
1202
  strideEndCoords[ vectorDimension ] = this.maxs[ vectorDimension ] ;
1170
1203
 
1171
1204
  this._checkRegion( strideStartCoords , strideEndCoords , vectorDimension ) ;
1172
- const newNDArray = this._resizeGeometry( strideStartCoords , strideEndCoords ) ;
1205
+ const newNDArray = this._resizeLogical( strideStartCoords , strideEndCoords ) ;
1173
1206
  newNDArray.data = this._newStorageOfTheSameKind( newNDArray.dataEnd ) ;
1174
1207
 
1175
1208
  this._dualStepVectorCallback( newNDArray , strideStartCoords , strideEndCoords , strideStartCoords , strideEndCoords , vectorDimension , callback ) ;
@@ -1254,7 +1287,7 @@ NDArray.prototype.extractRegion = function( mins , maxs ) {
1254
1287
  }
1255
1288
 
1256
1289
  this._checkRegion( mins , maxs ) ;
1257
- const newNDArray = this._resizeGeometry( mins , maxs ) ;
1290
+ const newNDArray = this._resizeLogical( mins , maxs ) ;
1258
1291
  newNDArray.data = this._newStorageOfTheSameKind( newNDArray.dataEnd ) ;
1259
1292
 
1260
1293
  this._dualStepCopy( newNDArray , mins , maxs , mins , maxs ) ;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "array-kit",
3
- "version": "0.2.13",
3
+ "version": "0.2.14",
4
4
  "description": "An array manipulation toolbox.",
5
5
  "main": "lib/array-kit.js",
6
6
  "directories": {