Skip to content

Commit e1bcdb7

Browse files
committed
Merge branch 'develop' of https://github.com/stdlib-js/stdlib into develop
2 parents c45c37c + 987242f commit e1bcdb7

34 files changed

+5949
-84
lines changed

lib/node_modules/@stdlib/ndarray/base/ctor/lib/get.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ function get() {
4040
for ( i = 0; i < arguments.length; i++ ) {
4141
idx += this._strides[ i ] * arguments[ i ];
4242
}
43-
if ( this._getter ) {
44-
return this._getter.call( this._buffer, idx );
43+
if ( this._accessors ) {
44+
return this._buffer.get( idx );
4545
}
4646
return this._buffer[ idx ];
4747
}

lib/node_modules/@stdlib/ndarray/base/ctor/lib/iget.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,23 +42,23 @@ function iget( idx ) {
4242

4343
ndims = this._ndims;
4444
if ( ndims === 0 ) {
45-
if ( this._getter ) {
46-
return this._getter.call( this._buffer, this._offset );
45+
if ( this._accessors ) {
46+
return this._buffer.get( this._offset );
4747
}
4848
return this._buffer[ this._offset ];
4949
}
5050
if ( this._flags.ROW_MAJOR_CONTIGUOUS || this._flags.COLUMN_MAJOR_CONTIGUOUS ) { // eslint-disable-line max-len
5151
// Trivial case where we have all positive strides...
5252
if ( this._iterationOrder === 1 ) {
53-
if ( this._getter ) {
54-
return this._getter.call( this._buffer, this._offset+idx );
53+
if ( this._accessors ) {
54+
return this._buffer.get( this._offset+idx );
5555
}
5656
return this._buffer[ this._offset+idx ];
5757
}
5858
// Trivial case where we have all negative strides...
5959
if ( this._iterationOrder === -1 ) {
60-
if ( this._getter ) {
61-
return this._getter.call( this._buffer, this.offset-idx );
60+
if ( this._accessors ) {
61+
return this._buffer.get( this.offset-idx );
6262
}
6363
return this._buffer[ this._offset-idx ];
6464
}
@@ -74,8 +74,8 @@ function iget( idx ) {
7474
idx /= shape[ i ];
7575
ind += s * strides[ i ];
7676
}
77-
if ( this._getter ) {
78-
return this._getter.call( this._buffer, ind );
77+
if ( this._accessors ) {
78+
return this._buffer.get( ind );
7979
}
8080
return this._buffer[ ind ];
8181
}
@@ -86,8 +86,8 @@ function iget( idx ) {
8686
idx /= shape[ i ];
8787
ind += s * strides[ i ];
8888
}
89-
if ( this._getter ) {
90-
return this._getter.call( this._buffer, ind );
89+
if ( this._accessors ) {
90+
return this._buffer.get( ind );
9191
}
9292
return this._buffer[ ind ];
9393
}

lib/node_modules/@stdlib/ndarray/base/ctor/lib/iset.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ function iset( idx, v ) {
4343

4444
ndims = this._ndims;
4545
if ( ndims === 0 ) {
46-
if ( this._setter ) {
47-
this._setter.call( this._buffer, idx, this._offset );
46+
if ( this._accessors ) {
47+
this._buffer.set( idx, this._offset );
4848
} else {
4949
this._buffer[ this._offset ] = idx;
5050
}
@@ -53,17 +53,17 @@ function iset( idx, v ) {
5353
if ( this._flags.ROW_MAJOR_CONTIGUOUS || this._flags.COLUMN_MAJOR_CONTIGUOUS ) { // eslint-disable-line max-len
5454
// Trivial case where we have all positive strides...
5555
if ( this._iterationOrder === 1 ) {
56-
if ( this._setter ) {
57-
this._setter.call( this._buffer, v, this._offset+idx );
56+
if ( this._accessors ) {
57+
this._buffer.set( v, this._offset+idx );
5858
} else {
5959
this._buffer[ this._offset+idx ] = v;
6060
}
6161
return this;
6262
}
6363
// Trivial case where we have all negative strides...
6464
if ( this._iterationOrder === -1 ) {
65-
if ( this._setter ) {
66-
this._setter.call( this._buffer, v, this._offset-idx );
65+
if ( this._accessors ) {
66+
this._buffer.set( v, this._offset-idx );
6767
} else {
6868
this._buffer[ this._offset-idx ] = v;
6969
}
@@ -81,8 +81,8 @@ function iset( idx, v ) {
8181
idx /= shape[ i ];
8282
ind += s * strides[ i ];
8383
}
84-
if ( this._setter ) {
85-
this._setter.call( this._buffer, v, ind );
84+
if ( this._accessors ) {
85+
this._buffer.set( v, ind );
8686
} else {
8787
this._buffer[ ind ] = v;
8888
}
@@ -95,8 +95,8 @@ function iset( idx, v ) {
9595
idx /= shape[ i ];
9696
ind += s * strides[ i ];
9797
}
98-
if ( this._setter ) {
99-
this._setter.call( this._buffer, v, ind );
98+
if ( this._accessors ) {
99+
this._buffer.set( v, ind );
100100
} else {
101101
this._buffer[ ind ] = v;
102102
}

lib/node_modules/@stdlib/ndarray/base/ctor/lib/main.js

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -105,14 +105,7 @@ function ndarray( dtype, buffer, shape, strides, offset, order ) {
105105
this._order = order;
106106
this._shape = shape;
107107
this._strides = strides;
108-
109-
if ( buffer.get && buffer.set ) {
110-
this._getter = buffer.get;
111-
this._setter = buffer.set;
112-
} else {
113-
this._getter = null;
114-
this._setter = null;
115-
}
108+
this._accessors = Boolean( buffer.get && buffer.set );
116109

117110
this._iterationOrder = iterationOrder( strides );
118111

lib/node_modules/@stdlib/ndarray/base/ctor/lib/set.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ function set() {
4141
for ( i = 0; i < arguments.length-1; i++ ) {
4242
idx += this._strides[ i ] * arguments[ i ];
4343
}
44-
if ( this._setter ) {
45-
this._setter.call( this._buffer, arguments[ i ], idx );
44+
if ( this._accessors ) {
45+
this._buffer.set( arguments[ i ], idx );
4646
} else {
4747
this._buffer[ idx ] = arguments[ i ];
4848
}

lib/node_modules/@stdlib/ndarray/base/unary/include/stdlib/ndarray/base/unary/macros/1d.h

Lines changed: 165 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,170 @@
2323
#include <stdint.h>
2424

2525
/**
26-
* Macro for operating on elements of a one-dimensional ndarray.
26+
* Macro containing the preamble for a loop which operates on elements of a one-dimensional ndarray.
27+
*
28+
* ## Notes
29+
*
30+
* - Variable naming conventions:
31+
*
32+
* - `sx#`, `px#`, and `d@x#` where `#` corresponds to the ndarray argument number, starting at `1`.
33+
* - `S@`, `i@`, and `d@x#` where `@` corresponds to the loop number, with `0` being the innermost loop.
34+
*
35+
* @example
36+
* STDLIB_NDARRAY_UNARY_1D_LOOP_PREMABLE {
37+
* // Innermost loop body...
38+
* }
39+
* STDLIB_NDARRAY_UNARY_1D_LOOP_EPILOGUE
40+
*/
41+
#define STDLIB_NDARRAY_UNARY_1D_LOOP_PREAMBLE \
42+
struct ndarray *x1 = arrays[ 0 ]; \
43+
struct ndarray *x2 = arrays[ 1 ]; \
44+
int64_t *shape = stdlib_ndarray_shape( x1 ); \
45+
int64_t *sx1 = stdlib_ndarray_strides( x1 ); \
46+
int64_t *sx2 = stdlib_ndarray_strides( x2 ); \
47+
uint8_t *px1 = stdlib_ndarray_data( x1 ); \
48+
uint8_t *px2 = stdlib_ndarray_data( x2 ); \
49+
int64_t d0x1; \
50+
int64_t d0x2; \
51+
int64_t S0; \
52+
int64_t i0; \
53+
/* Extract loop variables: dimensions and loop offset (pointer) increments... */ \
54+
S0 = shape[ 0 ]; \
55+
d0x1 = sx1[ 0 ]; \
56+
d0x2 = sx2[ 0 ]; \
57+
/* Set the pointers to the first indexed elements... */ \
58+
px1 += stdlib_ndarray_offset( x1 ); \
59+
px2 += stdlib_ndarray_offset( x2 ); \
60+
/* Iterate over the ndarray dimensions... */ \
61+
for ( i0 = 0; i0 < S0; i0++, px1 += d0x1, px2 += d0x2 )
62+
63+
/**
64+
* Macro containing the preamble for a loop which operates on elements of a one-dimensional input ndarray and updates two output ndarrays.
65+
*
66+
* ## Notes
67+
*
68+
* - Variable naming conventions:
69+
*
70+
* - `sx#`, `px#`, and `d@x#` where `#` corresponds to the ndarray argument number, starting at `1`.
71+
* - `S@`, `i@`, and `d@x#` where `@` corresponds to the loop number, with `0` being the innermost loop.
72+
*
73+
* @example
74+
* STDLIB_NDARRAY_UNARY_1D_LOOP_TWO_OUT_PREMABLE {
75+
* // Innermost loop body...
76+
* }
77+
* STDLIB_NDARRAY_UNARY_1D_LOOP_EPILOGUE
78+
*/
79+
#define STDLIB_NDARRAY_UNARY_1D_LOOP_TWO_OUT_PREAMBLE \
80+
struct ndarray *x1 = arrays[ 0 ]; \
81+
struct ndarray *x2 = arrays[ 1 ]; \
82+
struct ndarray *x3 = arrays[ 2 ]; \
83+
int64_t *shape = stdlib_ndarray_shape( x1 ); \
84+
int64_t *sx1 = stdlib_ndarray_strides( x1 ); \
85+
int64_t *sx2 = stdlib_ndarray_strides( x2 ); \
86+
int64_t *sx3 = stdlib_ndarray_strides( x3 ); \
87+
uint8_t *px1 = stdlib_ndarray_data( x1 ); \
88+
uint8_t *px2 = stdlib_ndarray_data( x2 ); \
89+
uint8_t *px3 = stdlib_ndarray_data( x3 ); \
90+
int64_t d0x1; \
91+
int64_t d0x2; \
92+
int64_t d0x3; \
93+
int64_t S0; \
94+
int64_t i0; \
95+
/* Extract loop variable: dimensions and loop offset (pointer) increments... */ \
96+
S0 = shape[ 0 ]; \
97+
d0x1 = sx1[ 0 ]; \
98+
d0x2 = sx2[ 0 ]; \
99+
d0x3 = sx3[ 0 ]; \
100+
/* Set the pointers to the first indexed elements... */ \
101+
px1 += stdlib_ndarray_offset( x1 ); \
102+
px2 += stdlib_ndarray_offset( x2 ); \
103+
px3 += stdlib_ndarray_offset( x3 ); \
104+
/* Iterate over the ndarray dimensions... */ \
105+
for ( i0 = 0; i0 < S0; i0++, px1 += d0x1, px2 += d0x2, px3 += d0x3 )
106+
107+
/**
108+
* Macro containing the epilogue for loops which operate on elements of a one-dimensional ndarray.
109+
*
110+
* @example
111+
* STDLIB_NDARRAY_UNARY_1D_LOOP_PREMABLE {
112+
* // Innermost loop body...
113+
* }
114+
* STDLIB_NDARRAY_UNARY_1D_LOOP_EPILOGUE
115+
*/
116+
#define STDLIB_NDARRAY_UNARY_1D_LOOP_EPILOGUE
117+
118+
/**
119+
* Macro for a unary one-dimensional ndarray loop which inlines an expression.
120+
*
121+
* ## Notes
122+
*
123+
* - Retrieves each ndarray element according to type `tin` via the pointer `px1` as `in1`.
124+
* - Creates a pointer `tout *out` to the output ndarray element.
125+
* - Expects a provided expression to operate on `tin in1` and to store the result in `tout *out`.
126+
*
127+
* @param tin input type
128+
* @param tout output type
129+
* @param expr expression to inline
130+
*
131+
* @example
132+
* STDLIB_NDARRAY_UNARY_1D_LOOP_INLINE( double, double, *out = in1 * in1 )
133+
*/
134+
#define STDLIB_NDARRAY_UNARY_1D_LOOP_INLINE( tin, tout, expr ) \
135+
STDLIB_NDARRAY_UNARY_1D_LOOP_PREAMBLE { \
136+
const tin in1 = *(tin *)px1; \
137+
tout *out = (tout *)px2; \
138+
expr; \
139+
} \
140+
STDLIB_NDARRAY_UNARY_1D_LOOP_EPILOGUE
141+
142+
/**
143+
* Macro for a unary one-dimensional ndarray loop which invokes a callback.
144+
*
145+
* ## Notes
146+
*
147+
* - Retrieves each ndarray element according to type `tin` via the pointer `px1`.
148+
* - Explicitly casts each function `f` invocation result to `tout`.
149+
* - Stores the result in an output ndarray via the pointer `px2`.
150+
*
151+
* @param tin input type
152+
* @param tout output type
153+
*
154+
* @example
155+
* STDLIB_NDARRAY_UNARY_1D_LOOP_CLBK( double, double )
156+
*/
157+
#define STDLIB_NDARRAY_UNARY_1D_LOOP_CLBK( tin, tout ) \
158+
STDLIB_NDARRAY_UNARY_1D_LOOP_PREAMBLE { \
159+
const tin x = *(tin *)px1; \
160+
*(tout *)px2 = (tout)f( x ); \
161+
} \
162+
STDLIB_NDARRAY_UNARY_1D_LOOP_EPILOGUE
163+
164+
/**
165+
* Macro for a unary one-dimensional ndarray loop which invokes a callback requiring arguments be explicitly cast to a different type.
166+
*
167+
* ## Notes
168+
*
169+
* - Retrieves each ndarray element according to type `tin` via the pointer `px1`.
170+
* - Explicitly casts each function argument to `fin`.
171+
* - Explicitly casts each function `f` invocation result to `tout`.
172+
* - Stores the result in an output ndarray via the pointer `px2`.
173+
*
174+
* @param tin input type
175+
* @param tout output type
176+
* @param fin callback argument type
177+
*
178+
* @example
179+
* STDLIB_NDARRAY_UNARY_1D_LOOP_CLBK_ARG_CAST( float, float, double )
180+
*/
181+
#define STDLIB_NDARRAY_UNARY_1D_LOOP_CLBK_ARG_CAST( tin, tout, fin ) \
182+
STDLIB_NDARRAY_UNARY_1D_LOOP_PREAMBLE { \
183+
const tin x = *(tin *)px1; \
184+
*(tout *)px2 = (tout)f( (fin)x ); \
185+
} \
186+
STDLIB_NDARRAY_UNARY_1D_LOOP_EPILOGUE
187+
188+
/**
189+
* Macro for operating on elements of a one-dimensional ndarray using a unary strided array function.
27190
*
28191
* @param strided_array_fcn strided array function
29192
@@ -32,7 +195,7 @@
32195
*
33196
* STDLIB_NDARRAY_UNARY_1D( stdlib_strided_b_b )
34197
*/
35-
#define STDLIB_NDARRAY_UNARY_1D( strided_array_fcn ) \
198+
#define STDLIB_NDARRAY_UNARY_1D_VIA_STRIDED( strided_array_fcn ) \
36199
struct ndarray *x1 = arrays[ 0 ]; \
37200
struct ndarray *x2 = arrays[ 1 ]; \
38201
int64_t shape[] = { \

0 commit comments

Comments
 (0)