Skip to content

Commit a934d8c

Browse files
committed
build: add documentation template
--- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed ---
1 parent 5543e2c commit a934d8c

File tree

1 file changed

+178
-0
lines changed
  • lib/node_modules/@stdlib/ndarray/base/every/scripts/templates

1 file changed

+178
-0
lines changed
Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
#### stdlib_ndarray_every_{{SIGNATURE}}( \*arrays\[], \*data )
2+
3+
Tests whether every element in an ndarray is truthy.
4+
5+
```c
6+
#include "stdlib/ndarray/dtypes.h"
7+
#include "stdlib/ndarray/index_modes.h"
8+
#include "stdlib/ndarray/orders.h"
9+
#include "stdlib/ndarray/ctor.h"{{EXAMPLE_INCLUDES}}
10+
#include <stdint.h>
11+
#include <stdlib.h>
12+
#include <stdio.h>
13+
#include <stdbool.h>
14+
15+
// Define the ndarray data types:
16+
enum STDLIB_NDARRAY_DTYPE xdtype = STDLIB_NDARRAY_{{INPUT_NDARRAY_1_DTYPE_UPPER}};
17+
enum STDLIB_NDARRAY_DTYPE ydtype = STDLIB_NDARRAY_BOOL;
18+
19+
// Create underlying byte arrays:
20+
uint8_t xbuf[] = { {{INPUT_NDARRAY_1_BYTES_2D}} };
21+
uint8_t ybuf[] = { 0 };
22+
23+
// Define the number of dimensions:
24+
int64_t ndims = 2;
25+
26+
// Define the array shapes:
27+
int64_t shx[] = { {{NDARRAY_SHAPE_2D}} };
28+
int64_t shy[] = {};
29+
30+
// Define the strides:
31+
int64_t sx[] = { {{OUTPUT_NDARRAY_STRIDES_2D}} };
32+
int64_t sy[] = { 0 };
33+
34+
// Define the index offsets:
35+
int64_t ox = 0;
36+
int64_t oy = 0;
37+
38+
// Define the array order:
39+
enum STDLIB_NDARRAY_ORDER order = STDLIB_NDARRAY_ROW_MAJOR;
40+
41+
// Specify the index mode:
42+
enum STDLIB_NDARRAY_INDEX_MODE imode = STDLIB_NDARRAY_INDEX_ERROR;
43+
44+
// Specify the subscript index modes:
45+
int8_t submodes[] = { imode };
46+
int64_t nsubmodes = 1;
47+
48+
// Create an input ndarray:
49+
struct ndarray *x = stdlib_ndarray_allocate( xdtype, xbuf, ndims, shx, sx, ox, order, imode, nsubmodes, submodes );
50+
if ( x == NULL ) {
51+
fprintf( stderr, "Error allocating memory.\n" );
52+
exit( EXIT_FAILURE );
53+
}
54+
55+
// Create an output ndarray:
56+
struct ndarray *y = stdlib_ndarray_allocate( ydtype, ybuf, 0, shy, sy, oy, order, imode, nsubmodes, submodes );
57+
if ( y == NULL ) {
58+
fprintf( stderr, "Error allocating memory.\n" );
59+
exit( EXIT_FAILURE );
60+
}
61+
62+
// Create an array containing the ndarrays:
63+
struct ndarray *arrays[] = { x, y };
64+
65+
// Test elements:
66+
int8_t status = stdlib_ndarray_{{SIGNATURE}}( arrays, NULL );
67+
if ( status != 0 ) {
68+
fprintf( stderr, "Error during computation.\n" );
69+
exit( EXIT_FAILURE );
70+
}
71+
72+
// ...
73+
74+
// Free allocated memory:
75+
stdlib_ndarray_free( x );
76+
stdlib_ndarray_free( y );
77+
```
78+
79+
The function accepts the following arguments:
80+
81+
- **arrays**: `[inout] struct ndarray**` array whose first element is a pointer to an input ndarray and whose second element is a pointer to a zero-dimensional output ndarray.
82+
- **data**: `[in] void*` function data. This argument is unused and should be a `NULL` pointer.
83+
84+
```c
85+
int8_t stdlib_ndarray_every_{{SIGNATURE}}( struct ndarray *arrays[], void *data );
86+
```
87+
88+
#### stdlib_ndarray_every_by_{{SIGNATURE}}( \*arrays\[], \*fcn )
89+
90+
Tests whether every element in an ndarray is truthy according to a predicate function.
91+
92+
```c
93+
#include "stdlib/ndarray/dtypes.h"
94+
#include "stdlib/ndarray/index_modes.h"
95+
#include "stdlib/ndarray/orders.h"
96+
#include "stdlib/ndarray/ctor.h"{{EXAMPLE_INCLUDES}}
97+
#include <stdint.h>
98+
#include <stdlib.h>
99+
#include <stdio.h>
100+
#include <stdbool.h>
101+
102+
// Define the ndarray data types:
103+
enum STDLIB_NDARRAY_DTYPE xdtype = STDLIB_NDARRAY_{{INPUT_NDARRAY_1_DTYPE_UPPER}};
104+
enum STDLIB_NDARRAY_DTYPE ydtype = STDLIB_NDARRAY_BOOL;
105+
106+
// Create underlying byte arrays:
107+
uint8_t xbuf[] = { {{INPUT_NDARRAY_1_BYTES_2D}} };
108+
uint8_t ybuf[] = { 0 };
109+
110+
// Define the number of dimensions:
111+
int64_t ndims = 2;
112+
113+
// Define the array shapes:
114+
int64_t shx[] = { {{NDARRAY_SHAPE_2D}} };
115+
int64_t shy[] = {};
116+
117+
// Define the strides:
118+
int64_t sx[] = { {{OUTPUT_NDARRAY_STRIDES_2D}} };
119+
int64_t sy[] = { 0 };
120+
121+
// Define the index offsets:
122+
int64_t ox = 0;
123+
int64_t oy = 0;
124+
125+
// Define the array order:
126+
enum STDLIB_NDARRAY_ORDER order = STDLIB_NDARRAY_ROW_MAJOR;
127+
128+
// Specify the index mode:
129+
enum STDLIB_NDARRAY_INDEX_MODE imode = STDLIB_NDARRAY_INDEX_ERROR;
130+
131+
// Specify the subscript index modes:
132+
int8_t submodes[] = { imode };
133+
int64_t nsubmodes = 1;
134+
135+
// Create an input ndarray:
136+
struct ndarray *x = stdlib_ndarray_allocate( xdtype, xbuf, ndims, shx, sx, ox, order, imode, nsubmodes, submodes );
137+
if ( x == NULL ) {
138+
fprintf( stderr, "Error allocating memory.\n" );
139+
exit( EXIT_FAILURE );
140+
}
141+
142+
// Create an output ndarray:
143+
struct ndarray *y = stdlib_ndarray_allocate( ydtype, ybuf, 0, shy, sy, oy, order, imode, nsubmodes, submodes );
144+
if ( y == NULL ) {
145+
fprintf( stderr, "Error allocating memory.\n" );
146+
exit( EXIT_FAILURE );
147+
}
148+
149+
// Create an array containing the ndarrays:
150+
struct ndarray *arrays[] = { x, y };
151+
152+
// Define a callback:
153+
static bool fcn( const {{CALLBACK_PARAM_1_DTYPE}} x ) {
154+
{{CALLBACK_BODY}}
155+
}
156+
157+
// Test elements:
158+
int8_t status = stdlib_ndarray_every_by_{{SIGNATURE}}( arrays, (void *)fcn );
159+
if ( status != 0 ) {
160+
fprintf( stderr, "Error during computation.\n" );
161+
exit( EXIT_FAILURE );
162+
}
163+
164+
// ...
165+
166+
// Free allocated memory:
167+
stdlib_ndarray_free( x );
168+
stdlib_ndarray_free( y );
169+
```
170+
171+
The function accepts the following arguments:
172+
173+
- **arrays**: `[inout] struct ndarray**` array whose first element is a pointer to an input ndarray and whose second element is a pointer to an output ndarray.
174+
- **fcn**: `[in] void*` a `bool (*f)({{CALLBACK_PARAM_1_DTYPE}})` predicate function to apply provided as a `void` pointer.
175+
176+
```c
177+
int8_t stdlib_ndarray_every_by_{{SIGNATURE}}( struct ndarray *arrays[], void *fcn );
178+
```

0 commit comments

Comments
 (0)