Skip to content

Commit e016288

Browse files
committed
Refactor ndarray constructor
This commit refactors the awkward constructor factory interface and should ensure better performance on V8 due to having a single object "shape", rather than many shapes stemming from multiple constructors.
1 parent 6ce3e31 commit e016288

File tree

82 files changed

+2113
-31346
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

82 files changed

+2113
-31346
lines changed

lib/node_modules/@stdlib/ndarray/ctor/README.md

Lines changed: 52 additions & 195 deletions
Large diffs are not rendered by default.

lib/node_modules/@stdlib/ndarray/ctor/benchmark/benchmark.js

Lines changed: 280 additions & 1870 deletions
Large diffs are not rendered by default.

lib/node_modules/@stdlib/ndarray/ctor/docs/repl.txt

Lines changed: 38 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,31 @@
11

2-
{{alias}}( dtype, ndims[, options] )
3-
Returns an ndarray constructor.
2+
{{alias}}( dtype, buffer, shape, strides, offset, order[, options] )
3+
Returns an ndarray.
44

55
Parameters
66
----------
77
dtype: string
88
Underlying data type.
99

10-
ndims: integer
11-
Number of dimensions.
10+
buffer: ArrayLikeObject|TypedArray|Buffer
11+
Data buffer.
12+
13+
shape: ArrayLikeObject
14+
Array shape.
15+
16+
strides: ArrayLikeObject
17+
Array strides.
18+
19+
offset: integer
20+
Index offset.
21+
22+
order: string
23+
Specifies whether an array is row-major (C-style) or column-major
24+
(Fortran-style).
1225

1326
options: Object (optional)
1427
Options.
1528

16-
options.codegen: boolean (optional)
17-
Boolean indicating whether to use code generation. Code generation can
18-
boost performance, but may be problematic in browser contexts enforcing
19-
a strict content security policy (CSP). Default: true.
20-
2129
options.mode: string (optional)
2230
Specifies how to handle indices which exceed array dimensions. If equal
2331
to 'throw', an ndarray instance throws an error when an index exceeds
@@ -39,88 +47,76 @@
3947

4048
Returns
4149
-------
42-
ctor: Function
43-
ndarray constructor.
50+
ndarray: ndarray
51+
ndarray instance.
4452

45-
ctor.BYTES_PER_ELEMENT: integer
46-
Size (in bytes) of each array element (if known).
47-
48-
ctor.dtype: string
49-
Underlying data type.
50-
51-
ctor.ndims: integer
52-
Number of dimensions.
53-
54-
ctor.prototype.byteLength: integer
53+
ndarray.prototype.byteLength: integer
5554
Size (in bytes) of the array (if known).
5655

57-
ctor.prototype.BYTES_PER_ELEMENT: integer
56+
ndarray.prototype.BYTES_PER_ELEMENT: integer
5857
Size (in bytes) of each array element (if known).
5958

60-
ctor.prototype.data: ArrayLikeObject|TypedArray|Buffer
59+
ndarray.prototype.data: ArrayLikeObject|TypedArray|Buffer
6160
Pointer to the underlying data buffer.
6261

63-
ctor.prototype.dtype: string
62+
ndarray.prototype.dtype: string
6463
Underlying data type.
6564

66-
ctor.prototype.flags: Object
65+
ndarray.prototype.flags: Object
6766
Information about the memory layout of the array.
6867

69-
ctor.prototype.length: integer
68+
ndarray.prototype.length: integer
7069
Length of the array (i.e., number of elements).
7170

72-
ctor.prototype.ndims: integer
71+
ndarray.prototype.ndims: integer
7372
Number of dimensions.
7473

75-
ctor.prototype.offset: integer
74+
ndarray.prototype.offset: integer
7675
Index offset which specifies the buffer index at which to start
7776
iterating over array elements.
7877

79-
ctor.prototype.order: string
78+
ndarray.prototype.order: string
8079
Array order. The array order is either row-major (C-style) or column-
8180
major (Fortran-style).
8281

83-
ctor.prototype.shape: Array
82+
ndarray.prototype.shape: Array
8483
Array shape.
8584

86-
ctor.prototype.strides: Array
85+
ndarray.prototype.strides: Array
8786
Index strides which specify how to access data along corresponding array
8887
dimensions.
8988

90-
ctor.prototype.get: Function
89+
ndarray.prototype.get: Function
9190
Returns an array element specified according to provided subscripts. The
9291
number of provided subscripts should equal the number of dimensions.
9392

94-
ctor.prototype.iget: Function
93+
ndarray.prototype.iget: Function
9594
Returns an array element located at a specified linear index.
9695

97-
ctor.prototype.set: Function
96+
ndarray.prototype.set: Function
9897
Sets an array element specified according to provided subscripts. The
9998
number of provided subscripts should equal the number of dimensions.
10099

101-
ctor.prototype.iset: Function
100+
ndarray.prototype.iset: Function
102101
Sets an array element located at a specified linear index.
103102

104-
ctor.prototype.toString: Function
103+
ndarray.prototype.toString: Function
105104
Serializes an ndarray as a string. This method does **not** serialize
106105
data outside of the buffer region defined by the array configuration.
107106

108-
ctor.prototype.toJSON: Function
107+
ndarray.prototype.toJSON: Function
109108
Serializes an ndarray as a JSON object. This method does **not**
110109
serialize data outside of the buffer region defined by the array
111110
configuration.
112111

113112
Examples
114113
--------
115-
> var ctor = {{alias}}( 'generic', 2 )
116-
<Function>
117-
118-
// To create a new instance...
114+
// Create a new instance...
119115
> var b = [ 1.0, 2.0, 3.0, 4.0 ]; // underlying data buffer
120116
> var d = [ 2, 2 ]; // shape
121117
> var s = [ 2, 1 ]; // strides
122118
> var o = 0; // index offset
123-
> var arr = ctor( b, d, s, o, 'row-major' )
119+
> var arr = {{alias}}( 'generic', b, d, s, o, 'row-major' )
124120
<ndarray>
125121

126122
// Get an element using subscripts:

lib/node_modules/@stdlib/ndarray/ctor/examples/index.js

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,10 @@
1616
* limitations under the License.
1717
*/
1818

19-
/* eslint-disable stdlib/return-annotations-quote-props */
20-
2119
'use strict';
2220

2321
var Float32Array = require( '@stdlib/array/float32' );
24-
var ctor = require( './../lib' );
25-
26-
// Create an ndarray constructor for a 4-dimensional array containing single-precision floating-point numbers:
27-
var ndarray = ctor( 'float32', 4 );
22+
var ndarray = require( './../lib' );
2823

2924
// Create a data buffer:
3025
var buffer = new Float32Array( (3*3*3*3) + 100 );
@@ -42,7 +37,7 @@ var offset = 4;
4237
var order = 'row-major'; // C-style
4338

4439
// Create a new ndarray:
45-
var arr = ndarray( buffer, shape, strides, offset, order );
40+
var arr = ndarray( 'float32', buffer, shape, strides, offset, order );
4641

4742
// Retrieve an array value:
4843
var v = arr.get( 1, 2, 1, 2 );
@@ -59,8 +54,8 @@ console.log( v );
5954

6055
// Serialize the array as a string:
6156
console.log( arr.toString() );
62-
// => ndarray( new Float32Array( [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ] ), [ 3, 3, 3, 3 ], [ 27, 9, 3, 1 ], 0, 'row-major' )
57+
// => "ndarray( 'float32', new Float32Array( [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ] ), [ 3, 3, 3, 3 ], [ 27, 9, 3, 1 ], 0, 'row-major' )"
6358

6459
// Serialize the array as JSON:
6560
console.log( JSON.stringify( arr.toJSON() ) );
66-
// => {"type":"ndarray","dtype":"float32","flags":{},"order":"row-major","shape":[3,3,3,3],"strides":[27,9,3,1],"data":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,10,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]}
61+
// => '{"type":"ndarray","dtype":"float32","flags":{},"order":"row-major","shape":[3,3,3,3],"strides":[27,9,3,1],"data":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,10,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]}'

lib/node_modules/@stdlib/ndarray/ctor/lib/compile_get.js

Lines changed: 0 additions & 129 deletions
This file was deleted.

0 commit comments

Comments
 (0)