Skip to content

Commit 4b9e117

Browse files
committed
docs: add README
--- 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: passed - 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 9635155 commit 4b9e117

File tree

1 file changed

+275
-0
lines changed
  • lib/node_modules/@stdlib/ndarray/base/includes

1 file changed

+275
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,275 @@
1+
<!--
2+
3+
@license Apache-2.0
4+
5+
Copyright (c) 2025 The Stdlib Authors.
6+
7+
Licensed under the Apache License, Version 2.0 (the "License");
8+
you may not use this file except in compliance with the License.
9+
You may obtain a copy of the License at
10+
11+
http://www.apache.org/licenses/LICENSE-2.0
12+
13+
Unless required by applicable law or agreed to in writing, software
14+
distributed under the License is distributed on an "AS IS" BASIS,
15+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
See the License for the specific language governing permissions and
17+
limitations under the License.
18+
19+
-->
20+
21+
# includes
22+
23+
> Test whether an ndarray contains a specified value.
24+
25+
<section class="intro">
26+
27+
</section>
28+
29+
<!-- /.intro -->
30+
31+
<section class="usage">
32+
33+
## Usage
34+
35+
```javascript
36+
var includes = require( '@stdlib/ndarray/base/includes' );
37+
```
38+
39+
#### includes( arrays )
40+
41+
Tests whether an ndarray contains a specified value.
42+
43+
<!-- eslint-disable max-len -->
44+
45+
```javascript
46+
var Float64Array = require( '@stdlib/array/float64' );
47+
48+
// Create a data buffer:
49+
var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] );
50+
51+
// Define the shape of the input array:
52+
var shape = [ 3, 1, 2 ];
53+
54+
// Define the array strides:
55+
var sx = [ 4, 4, 1 ];
56+
57+
// Define the index offset:
58+
var ox = 0;
59+
60+
// Create the input ndarray-like object:
61+
var x = {
62+
'dtype': 'float64',
63+
'data': xbuf,
64+
'shape': shape,
65+
'strides': sx,
66+
'offset': ox,
67+
'order': 'row-major'
68+
};
69+
70+
// Create the search element ndarray-like object:
71+
var searchElement = {
72+
'dtype': 'float64',
73+
'data': new Float64Array( [ 6.0 ] ),
74+
'shape': [],
75+
'strides': [ 0 ],
76+
'offset': 0,
77+
'order': 'row-major'
78+
};
79+
80+
// Perform reduction:
81+
var out = includes( [ x, searchElement ] );
82+
// returns true
83+
```
84+
85+
The function accepts the following arguments:
86+
87+
- **arrays**: array-like object containing an input ndarray and a zero-dimensional search element ndarray.
88+
89+
Each provided ndarray should be an object with the following properties:
90+
91+
- **dtype**: data type.
92+
- **data**: data buffer.
93+
- **shape**: dimensions.
94+
- **strides**: stride lengths.
95+
- **offset**: index offset.
96+
- **order**: specifies whether an ndarray is row-major (C-style) or column major (Fortran-style).
97+
98+
</section>
99+
100+
<!-- /.usage -->
101+
102+
<section class="notes">
103+
104+
## Notes
105+
106+
- For very high-dimensional ndarrays which are non-contiguous, one should consider copying the underlying data to contiguous memory before performing the operation in order to achieve better performance.
107+
108+
</section>
109+
110+
<!-- /.notes -->
111+
112+
<section class="examples">
113+
114+
## Examples
115+
116+
<!-- eslint no-undef: "error" -->
117+
118+
```javascript
119+
var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
120+
var ndarray2array = require( '@stdlib/ndarray/base/to-array' );
121+
var includes = require( '@stdlib/ndarray/base/includes' );
122+
123+
var x = {
124+
'dtype': 'generic',
125+
'data': discreteUniform( 10, 0, 10, {
126+
'dtype': 'generic'
127+
}),
128+
'shape': [ 5, 2 ],
129+
'strides': [ 2, 1 ],
130+
'offset': 0,
131+
'order': 'row-major'
132+
};
133+
console.log( ndarray2array( x.data, x.shape, x.strides, x.offset, x.order ) );
134+
135+
var v = {
136+
'dtype': x.dtype,
137+
'data': [ 1 ],
138+
'shape': [],
139+
'strides': [ 0 ],
140+
'offset': 0,
141+
'order': x.order
142+
};
143+
var out = includes( [ x, v ] );
144+
console.log( out );
145+
```
146+
147+
</section>
148+
149+
<!-- /.examples -->
150+
151+
<!-- C interface documentation. -->
152+
153+
* * *
154+
155+
<section class="c">
156+
157+
## C APIs
158+
159+
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
160+
161+
<section class="intro">
162+
163+
Character codes for data types:
164+
165+
<!-- The following is auto-generated. Do not manually edit. See scripts/loops.js. -->
166+
167+
<!-- charcodes -->
168+
169+
- **x**: `bool` (boolean).
170+
- **z**: `complex128` (double-precision floating-point complex number).
171+
- **c**: `complex64` (single-precision floating-point complex number).
172+
- **f**: `float32` (single-precision floating-point number).
173+
- **d**: `float64` (double-precision floating-point number).
174+
- **k**: `int16` (signed 16-bit integer).
175+
- **i**: `int32` (signed 32-bit integer).
176+
- **s**: `int8` (signed 8-bit integer).
177+
- **t**: `uint16` (unsigned 16-bit integer).
178+
- **u**: `uint32` (unsigned 32-bit integer).
179+
- **b**: `uint8` (unsigned 8-bit integer).
180+
181+
<!-- ./charcodes -->
182+
183+
Function name suffix naming convention:
184+
185+
```text
186+
stdlib_ndarray_includes_<input_data_type><search_element_data_type>_<output_data_type>[_as_<input_cast_data_type><search_element_cast_data_type>_<output_data_type>]
187+
```
188+
189+
For example,
190+
191+
<!-- run-disable -->
192+
193+
```c
194+
void stdlib_ndarray_includes_dd_x(...) {...}
195+
```
196+
197+
is a function which accepts one double-precision floating-point input ndarray, a double-precision floating-point search element ndarray, and one boolean output ndarray.
198+
199+
TODO: document casting convention
200+
201+
</section>
202+
203+
<!-- /.intro -->
204+
205+
<!-- C usage documentation. -->
206+
207+
<section class="usage">
208+
209+
### Usage
210+
211+
```c
212+
#include "stdlib/ndarray/base/includes.h"
213+
```
214+
215+
<!-- The following is auto-generated. Do not manually edit. See scripts/*loops.js. -->
216+
217+
<!-- loops -->
218+
219+
<!-- ./loops -->
220+
221+
<!-- macros -->
222+
223+
<!-- TODO: consider documenting macros -->
224+
225+
<!-- ./macros -->
226+
227+
</section>
228+
229+
<!-- /.usage -->
230+
231+
<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
232+
233+
<section class="notes">
234+
235+
</section>
236+
237+
<!-- /.notes -->
238+
239+
<!-- C API usage examples. -->
240+
241+
* * *
242+
243+
<section class="examples">
244+
245+
### Examples
246+
247+
```c
248+
// TODO
249+
```
250+
251+
</section>
252+
253+
<!-- /.examples -->
254+
255+
</section>
256+
257+
<!-- /.c -->
258+
259+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
260+
261+
<section class="related">
262+
263+
</section>
264+
265+
<!-- /.related -->
266+
267+
<section class="links">
268+
269+
<!-- <related-links> -->
270+
271+
<!-- </related-links> -->
272+
273+
</section>
274+
275+
<!-- /.links -->

0 commit comments

Comments
 (0)