Skip to content

Commit 44cc909

Browse files
committed
Auto-generated commit
1 parent 7b6c0e6 commit 44cc909

File tree

4 files changed

+35
-7
lines changed

4 files changed

+35
-7
lines changed

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,17 @@ var obj = ndarraylike2object( arr );
8888
- **getter**: accessor for retrieving a data buffer element.
8989
- **setter**: accessor for setting a data buffer element.
9090

91+
- The getter accessor accepts two arguments:
92+
93+
- **data**: data buffer.
94+
- **idx**: element index.
95+
96+
- The setter accessor accepts three arguments:
97+
98+
- **data**: data buffer.
99+
- **idx**: element index.
100+
- **value**: value to set.
101+
91102
- This function is intended as a potential performance optimization. In V8, for example, even if two objects share common properties, if those properties were added in different orders or if one object has additional properties not shared by the other object, then those objects will have different "hidden" classes. If a function is provided many objects having different "shapes", some JavaScript VMs (e.g., V8) will consider the function "megamorphic" and fail to perform various runtime optimizations. Accordingly, the intent of this function is to standardize the "shape" of the object holding [`ndarray`][@stdlib/ndarray/ctor] meta data to ensure that internal functions operating on ndarrays are provided consistent argument "shapes".
92103

93104
</section>

docs/repl.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,17 @@
1717
- getter: accessor for retrieving a data buffer element.
1818
- setter: accessor for setting a data buffer element.
1919

20+
The getter accessor accepts two arguments:
21+
22+
- data: data buffer.
23+
- idx: element index.
24+
25+
The setter accessor accepts three arguments:
26+
27+
- data: data buffer.
28+
- idx: element index.
29+
- value: value to set.
30+
2031
Parameters
2132
----------
2233
x: ndarray

docs/types/test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ function array(): ndarray {
5151

5252
// TESTS //
5353

54-
// The function returns a ndarray object...
54+
// The function returns an ndarray object...
5555
{
5656
const x = array();
5757
ndarraylike2object( x ); // $ExpectType ndarrayObject

test/test.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ tape( 'the function converts an ndarray to a standardized object', function test
5151

5252
expected = {
5353
'ref': x,
54+
'data': x.data,
5455
'dtype': x.dtype,
5556
'length': x.length,
5657
'shape': x.shape,
@@ -62,6 +63,7 @@ tape( 'the function converts an ndarray to a standardized object', function test
6263
actual = ndarraylike2object( x );
6364

6465
t.strictEqual( actual.ref, expected.ref, 'returns expected value' );
66+
t.strictEqual( actual.data, expected.data, 'returns expected value' );
6567
t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' );
6668
t.strictEqual( actual.length, expected.length, 'returns expected value' );
6769
t.deepEqual( actual.shape, expected.shape, 'returns expected value' );
@@ -74,8 +76,8 @@ tape( 'the function converts an ndarray to a standardized object', function test
7476
t.strictEqual( typeof actual.setter, 'function', 'returns expected value' );
7577
t.strictEqual( actual.setter.length, 3, 'returns expected value' );
7678

77-
actual.setter( xbuf, 0, 1.0 );
78-
v = actual.getter( xbuf, 0 );
79+
actual.setter( actual.data, 0, 1.0 );
80+
v = actual.getter( actual.data, 0 );
7981
t.strictEqual( v, 1.0, 'returns expected value' );
8082

8183
t.end();
@@ -101,6 +103,7 @@ tape( 'the function converts an ndarray-like object to a standardized object', f
101103

102104
expected = {
103105
'ref': x,
106+
'data': x.data,
104107
'dtype': x.dtype,
105108
'length': x.length,
106109
'shape': x.shape,
@@ -112,6 +115,7 @@ tape( 'the function converts an ndarray-like object to a standardized object', f
112115
actual = ndarraylike2object( x );
113116

114117
t.strictEqual( actual.ref, expected.ref, 'returns expected value' );
118+
t.strictEqual( actual.data, expected.data, 'returns expected value' );
115119
t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' );
116120
t.strictEqual( actual.length, expected.length, 'returns expected value' );
117121
t.deepEqual( actual.shape, expected.shape, 'returns expected value' );
@@ -124,8 +128,8 @@ tape( 'the function converts an ndarray-like object to a standardized object', f
124128
t.strictEqual( typeof actual.setter, 'function', 'returns expected value' );
125129
t.strictEqual( actual.setter.length, 3, 'returns expected value' );
126130

127-
actual.setter( xbuf, 0, 1.0 );
128-
v = actual.getter( xbuf, 0 );
131+
actual.setter( actual.data, 0, 1.0 );
132+
v = actual.getter( actual.data, 0 );
129133
t.strictEqual( v, 1.0, 'returns expected value' );
130134

131135
t.end();
@@ -143,6 +147,7 @@ tape( 'the function converts an ndarray to a standardized object (data buffer ac
143147

144148
expected = {
145149
'ref': x,
150+
'data': x.data,
146151
'dtype': x.dtype,
147152
'length': x.length,
148153
'shape': x.shape,
@@ -154,6 +159,7 @@ tape( 'the function converts an ndarray to a standardized object (data buffer ac
154159
actual = ndarraylike2object( x );
155160

156161
t.strictEqual( actual.ref, expected.ref, 'returns expected value' );
162+
t.strictEqual( actual.data, expected.data, 'returns expected value' );
157163
t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' );
158164
t.strictEqual( actual.length, expected.length, 'returns expected value' );
159165
t.deepEqual( actual.shape, expected.shape, 'returns expected value' );
@@ -166,8 +172,8 @@ tape( 'the function converts an ndarray to a standardized object (data buffer ac
166172
t.strictEqual( typeof actual.setter, 'function', 'returns expected value' );
167173
t.strictEqual( actual.setter.length, 3, 'returns expected value' );
168174

169-
actual.setter( xbuf, 0, new Complex64( 1.0, 2.0 ) );
170-
v = actual.getter( xbuf, 0 );
175+
actual.setter( actual.data, 0, new Complex64( 1.0, 2.0 ) );
176+
v = actual.getter( actual.data, 0 );
171177
t.strictEqual( realf( v ), 1.0, 'returns expected value' );
172178
t.strictEqual( imagf( v ), 2.0, 'returns expected value' );
173179

0 commit comments

Comments
 (0)