@@ -111,6 +111,182 @@ console.log( ndarray2array( out ) );
111111
112112<!-- /.examples -->
113113
114+ <!-- C interface documentation. -->
115+
116+ * * *
117+
118+ <section class =" c " >
119+
120+ ## C APIs
121+
122+ <!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
123+
124+ <section class =" intro " >
125+
126+ </section >
127+
128+ <!-- /.intro -->
129+
130+ <!-- C usage documentation. -->
131+
132+ <section class =" usage " >
133+
134+ ### Usage
135+
136+ ``` c
137+ #include " stdlib/blas/ext/base/ndarray/dwhere.h"
138+ ```
139+
140+ #### stdlib_blas_ext_dwhere( arrays )
141+
142+ Takes elements from one of two one-dimensional double-precision floating-point ndarrays depending on a condition.
143+
144+ ``` c
145+ #include " stdlib/ndarray/ctor.h"
146+ #include " stdlib/ndarray/dtypes.h"
147+ #include " stdlib/ndarray/index_modes.h"
148+ #include " stdlib/ndarray/orders.h"
149+ #include " stdlib/ndarray/base/bytes_per_element.h"
150+ #include < stdint.h>
151+ #include < stdbool.h>
152+
153+ // Create data buffers:
154+ const uint8_t dataC[] = { 1, 0, 1, 0 };
155+ const double dataX[ ] = { 1.0, 2.0, 3.0, 4.0 };
156+ const double dataY[ ] = { 5.0, 6.0, 7.0, 8.0 };
157+ double dataOut[ ] = { 0.0, 0.0, 0.0, 0.0 };
158+
159+ int64_t shape[ ] = { 4 };
160+ int64_t stridesC[ ] = { STDLIB_NDARRAY_BOOL_BYTES_PER_ELEMENT };
161+ int64_t strides[ ] = { STDLIB_NDARRAY_FLOAT64_BYTES_PER_ELEMENT };
162+ int8_t submodes[ ] = { STDLIB_NDARRAY_INDEX_ERROR };
163+
164+ struct ndarray * c = stdlib_ndarray_allocate( STDLIB_NDARRAY_BOOL, (uint8_t * )dataC, 1, shape, stridesC, 0, STDLIB_NDARRAY_ROW_MAJOR, STDLIB_NDARRAY_INDEX_ERROR, 1, submodes );
165+ struct ndarray * x = stdlib_ndarray_allocate( STDLIB_NDARRAY_FLOAT64, (uint8_t * )dataX, 1, shape, strides, 0, STDLIB_NDARRAY_ROW_MAJOR, STDLIB_NDARRAY_INDEX_ERROR, 1, submodes );
166+ struct ndarray * y = stdlib_ndarray_allocate( STDLIB_NDARRAY_FLOAT64, (uint8_t * )dataY, 1, shape, strides, 0, STDLIB_NDARRAY_ROW_MAJOR, STDLIB_NDARRAY_INDEX_ERROR, 1, submodes );
167+ struct ndarray * out = stdlib_ndarray_allocate( STDLIB_NDARRAY_FLOAT64, (uint8_t * )dataOut, 1, shape, strides, 0, STDLIB_NDARRAY_ROW_MAJOR, STDLIB_NDARRAY_INDEX_ERROR, 1, submodes );
168+
169+ // Perform computation:
170+ const struct ndarray * arrays[ ] = { c, x, y, out };
171+ stdlib_blas_ext_dwhere ( arrays );
172+
173+ // Free allocated memory:
174+ stdlib_ndarray_free ( c );
175+ stdlib_ndarray_free ( x );
176+ stdlib_ndarray_free ( y );
177+ stdlib_ndarray_free ( out );
178+ ```
179+
180+ The function accepts the following arguments:
181+
182+ - **arrays**: `[in] struct ndarray**` list containing the following ndarrays:
183+
184+ - `[in] struct ndarray*` a one-dimensional condition ndarray.
185+ - `[in] struct ndarray*` first one-dimensional input ndarray.
186+ - `[in] struct ndarray*` second one-dimensional input ndarray.
187+ - `[out] struct ndarray*` a one-dimensional output ndarray.
188+
189+ ```c
190+ void stdlib_blas_ext_dwhere( const struct ndarray *arrays[] );
191+ ```
192+
193+ </section >
194+
195+ <!-- /.usage -->
196+
197+ <!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
198+
199+ <section class =" notes " >
200+
201+ </section >
202+
203+ <!-- /.notes -->
204+
205+ <!-- C API usage examples. -->
206+
207+ <section class =" examples " >
208+
209+ ### Examples
210+
211+ ``` c
212+ #include " stdlib/blas/ext/base/ndarray/dwhere.h"
213+ #include " stdlib/ndarray/ctor.h"
214+ #include " stdlib/ndarray/dtypes.h"
215+ #include " stdlib/ndarray/index_modes.h"
216+ #include " stdlib/ndarray/orders.h"
217+ #include " stdlib/ndarray/base/bytes_per_element.h"
218+ #include < stdint.h>
219+ #include < stdbool.h>
220+ #include < stdlib.h>
221+ #include < stdio.h>
222+
223+ int main ( void ) {
224+ // Create data buffers:
225+ const uint8_t dataC[ ] = { 1, 0, 1, 0 };
226+ const double dataX[ ] = { 1.0, 2.0, 3.0, 4.0 };
227+ const double dataY[ ] = { 5.0, 6.0, 7.0, 8.0 };
228+ double dataOut[ ] = { 0.0, 0.0, 0.0, 0.0 };
229+
230+ // Specify the number of array dimensions:
231+ const int64_t ndims = 1;
232+
233+ // Specify the array shape:
234+ int64_t shape[] = { 4 };
235+
236+ // Specify the array strides:
237+ int64_t stridesC[] = { STDLIB_NDARRAY_BOOL_BYTES_PER_ELEMENT };
238+ int64_t strides[] = { STDLIB_NDARRAY_FLOAT64_BYTES_PER_ELEMENT };
239+
240+ // Specify the byte offset:
241+ const int64_t offset = 0;
242+
243+ // Specify the array order:
244+ const enum STDLIB_NDARRAY_ORDER order = STDLIB_NDARRAY_ROW_MAJOR;
245+
246+ // Specify the index mode:
247+ const enum STDLIB_NDARRAY_INDEX_MODE imode = STDLIB_NDARRAY_INDEX_ERROR;
248+
249+ // Specify the subscript index modes:
250+ int8_t submodes[] = { STDLIB_NDARRAY_INDEX_ERROR };
251+ const int64_t nsubmodes = 1;
252+
253+ // Create ndarrays:
254+ struct ndarray *c = stdlib_ndarray_allocate( STDLIB_NDARRAY_BOOL, (uint8_t *)dataC, ndims, shape, stridesC, offset, order, imode, nsubmodes, submodes );
255+ struct ndarray *x = stdlib_ndarray_allocate( STDLIB_NDARRAY_FLOAT64, (uint8_t *)dataX, ndims, shape, strides, offset, order, imode, nsubmodes, submodes );
256+ struct ndarray *y = stdlib_ndarray_allocate( STDLIB_NDARRAY_FLOAT64, (uint8_t *)dataY, ndims, shape, strides, offset, order, imode, nsubmodes, submodes );
257+ struct ndarray *out = stdlib_ndarray_allocate( STDLIB_NDARRAY_FLOAT64, (uint8_t *)dataOut, ndims, shape, strides, offset, order, imode, nsubmodes, submodes );
258+ if ( c == NULL || x == NULL || y == NULL || out == NULL ) {
259+ fprintf( stderr, "Error allocating memory.\n" );
260+ exit( 1 );
261+ }
262+
263+ // Define a list of ndarrays:
264+ const struct ndarray *arrays[] = { c, x, y, out };
265+
266+ // Perform computation:
267+ stdlib_blas_ext_dwhere( arrays );
268+
269+ // Print the result:
270+ for ( int i = 0; i < 4; i++ ) {
271+ printf( "out[ %i ] = %lf\n", i, dataOut[ i ] );
272+ }
273+
274+ // Free allocated memory:
275+ stdlib_ndarray_free( c );
276+ stdlib_ndarray_free( x );
277+ stdlib_ndarray_free( y );
278+ stdlib_ndarray_free( out );
279+ }
280+ ```
281+
282+ </section>
283+
284+ <!-- /.examples -->
285+
286+ </section>
287+
288+ <!-- /.c -->
289+
114290<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
115291
116292<section class="related">
0 commit comments