Skip to content

Commit bfa978e

Browse files
committed
feat: add C implementation for blas/ext/base/ndarray/dcusum
--- 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_pkg_readmes status: passed - task: lint_markdown_docs status: na - task: lint_markdown status: na - task: lint_package_json status: passed - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: missing_dependencies - task: lint_c_examples status: missing_dependencies - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed ---
1 parent acbf27e commit bfa978e

14 files changed

Lines changed: 1346 additions & 1 deletion

File tree

lib/node_modules/@stdlib/blas/ext/base/ndarray/dcusum/README.md

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,155 @@ console.log( ndarray2array( v ) );
113113

114114
<!-- /.examples -->
115115

116+
<!-- C interface documentation. -->
117+
118+
<section class="c">
119+
120+
## C APIs
121+
122+
<!-- C usage documentation. -->
123+
124+
<section class="usage">
125+
126+
### Usage
127+
128+
```c
129+
#include "stdlib/blas/ext/base/ndarray/dcusum.h"
130+
```
131+
132+
#### stdlib_blas_ext_dcusum( sum, arrays )
133+
134+
Computes the cumulative sum of a one-dimensional double-precision floating-point ndarray.
135+
136+
```c
137+
#include "stdlib/ndarray/ctor.h"
138+
#include "stdlib/ndarray/dtypes.h"
139+
#include "stdlib/ndarray/index_modes.h"
140+
#include "stdlib/ndarray/orders.h"
141+
#include "stdlib/ndarray/base/bytes_per_element.h"
142+
#include <stdint.h>
143+
144+
// Create ndarrays:
145+
const double dataX[] = { 1.0, 2.0, 3.0, 4.0, 5.0 };
146+
double dataY[] = { 0.0, 0.0, 0.0, 0.0, 0.0 };
147+
int64_t shape[] = { 5 };
148+
int64_t strides[] = { STDLIB_NDARRAY_FLOAT64_BYTES_PER_ELEMENT };
149+
int8_t submodes[] = { STDLIB_NDARRAY_INDEX_ERROR };
150+
151+
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 );
152+
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 );
153+
154+
// Perform computation:
155+
const struct ndarray *arrays[] = { x, y };
156+
stdlib_blas_ext_dcusum( 0.0, arrays );
157+
158+
// Free allocated memory:
159+
stdlib_ndarray_free( x );
160+
stdlib_ndarray_free( y );
161+
```
162+
163+
The function accepts the following arguments:
164+
165+
- **sum**: `[in] double` initial sum.
166+
167+
- **arrays**: `[in] struct ndarray**` list containing the following ndarrays:
168+
169+
- `[in] struct ndarray*` a one-dimensional input ndarray.
170+
- `[inout] struct ndarray*` a one-dimensional output ndarray.
171+
172+
```c
173+
void stdlib_blas_ext_dcusum( const double sum, const struct ndarray *arrays[] );
174+
```
175+
176+
</section>
177+
178+
<!-- /.usage -->
179+
180+
<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
181+
182+
<section class="notes">
183+
184+
</section>
185+
186+
<!-- /.notes -->
187+
188+
<!-- C API usage examples. -->
189+
190+
<section class="examples">
191+
192+
### Examples
193+
194+
```c
195+
#include "stdlib/blas/ext/base/ndarray/dcusum.h"
196+
#include "stdlib/ndarray/ctor.h"
197+
#include "stdlib/ndarray/dtypes.h"
198+
#include "stdlib/ndarray/index_modes.h"
199+
#include "stdlib/ndarray/orders.h"
200+
#include "stdlib/ndarray/base/bytes_per_element.h"
201+
#include <stdint.h>
202+
#include <stdlib.h>
203+
#include <stdio.h>
204+
205+
int main( void ) {
206+
// Create data buffers:
207+
const double dataX[] = { 1.0, -2.0, 3.0, -4.0, 5.0, -6.0, 7.0, -8.0 };
208+
double dataY[] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };
209+
210+
// Specify the number of array dimensions:
211+
const int64_t ndims = 1;
212+
213+
// Specify the array shape:
214+
int64_t shape[] = { 8 };
215+
216+
// Specify the array strides:
217+
int64_t strides[] = { STDLIB_NDARRAY_FLOAT64_BYTES_PER_ELEMENT };
218+
219+
// Specify the byte offset:
220+
const int64_t offset = 0;
221+
222+
// Specify the array order:
223+
const enum STDLIB_NDARRAY_ORDER order = STDLIB_NDARRAY_ROW_MAJOR;
224+
225+
// Specify the index mode:
226+
const enum STDLIB_NDARRAY_INDEX_MODE imode = STDLIB_NDARRAY_INDEX_ERROR;
227+
228+
// Specify the subscript index modes:
229+
int8_t submodes[] = { STDLIB_NDARRAY_INDEX_ERROR };
230+
const int64_t nsubmodes = 1;
231+
232+
// Create ndarrays:
233+
struct ndarray *x = stdlib_ndarray_allocate( STDLIB_NDARRAY_FLOAT64, (uint8_t *)dataX, ndims, shape, strides, offset, order, imode, nsubmodes, submodes );
234+
struct ndarray *y = stdlib_ndarray_allocate( STDLIB_NDARRAY_FLOAT64, (uint8_t *)dataY, ndims, shape, strides, offset, order, imode, nsubmodes, submodes );
235+
if ( x == NULL || y == NULL ) {
236+
fprintf( stderr, "Error allocating memory.\n" );
237+
exit( 1 );
238+
}
239+
240+
// Define a list of ndarrays:
241+
const struct ndarray *arrays[] = { x, y };
242+
243+
// Perform computation:
244+
stdlib_blas_ext_dcusum( 0.0, arrays );
245+
246+
// Print the result:
247+
for ( int i = 0; i < 8; i++ ) {
248+
printf( "y[ %i ] = %lf\n", i, dataY[ i ] );
249+
}
250+
251+
// Free allocated memory:
252+
stdlib_ndarray_free( x );
253+
stdlib_ndarray_free( y );
254+
}
255+
```
256+
257+
</section>
258+
259+
<!-- /.examples -->
260+
261+
</section>
262+
263+
<!-- /.c -->
264+
116265
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
117266
118267
<section class="related">
Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
# @license Apache-2.0
2+
#
3+
# Copyright (c) 2026 The Stdlib Authors.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
# A `.gyp` file for building a Node.js native add-on.
18+
#
19+
# [1]: https://gyp.gsrc.io/docs/InputFormatReference.md
20+
# [2]: https://gyp.gsrc.io/docs/UserDocumentation.md
21+
{
22+
# List of files to include in this file:
23+
'includes': [
24+
'./include.gypi',
25+
],
26+
27+
# Define variables to be used throughout the configuration for all targets:
28+
'variables': {
29+
# Target name should match the add-on export name:
30+
'addon_target_name%': 'addon',
31+
32+
# Set variables based on the host OS:
33+
'conditions': [
34+
[
35+
'OS=="win"',
36+
{
37+
# Define the object file suffix:
38+
'obj': 'obj',
39+
},
40+
{
41+
# Define the object file suffix:
42+
'obj': 'o',
43+
}
44+
], # end condition (OS=="win")
45+
], # end conditions
46+
}, # end variables
47+
48+
# Define compile targets:
49+
'targets': [
50+
51+
# Target to generate an add-on:
52+
{
53+
# The target name should match the add-on export name:
54+
'target_name': '<(addon_target_name)',
55+
56+
# Define dependencies:
57+
'dependencies': [],
58+
59+
# Define directories which contain relevant include headers:
60+
'include_dirs': [
61+
# Local include directory:
62+
'<@(include_dirs)',
63+
],
64+
65+
# List of source files:
66+
'sources': [
67+
'<@(src_files)',
68+
],
69+
70+
# Settings which should be applied when a target's object files are used as linker input:
71+
'link_settings': {
72+
# Define libraries:
73+
'libraries': [
74+
'<@(libraries)',
75+
],
76+
77+
# Define library directories:
78+
'library_dirs': [
79+
'<@(library_dirs)',
80+
],
81+
},
82+
83+
# C/C++ compiler flags:
84+
'cflags': [
85+
# Enable commonly used warning options:
86+
'-Wall',
87+
88+
# Aggressive optimization:
89+
'-O3',
90+
],
91+
92+
# C specific compiler flags:
93+
'cflags_c': [
94+
# Specify the C standard to which a program is expected to conform:
95+
'-std=c99',
96+
],
97+
98+
# C++ specific compiler flags:
99+
'cflags_cpp': [
100+
# Specify the C++ standard to which a program is expected to conform:
101+
'-std=c++11',
102+
],
103+
104+
# Linker flags:
105+
'ldflags': [],
106+
107+
# Apply conditions based on the host OS:
108+
'conditions': [
109+
[
110+
'OS=="mac"',
111+
{
112+
# Linker flags:
113+
'ldflags': [
114+
'-undefined dynamic_lookup',
115+
'-Wl,-no-pie',
116+
'-Wl,-search_paths_first',
117+
],
118+
},
119+
], # end condition (OS=="mac")
120+
[
121+
'OS!="win"',
122+
{
123+
# C/C++ flags:
124+
'cflags': [
125+
# Generate platform-independent code:
126+
'-fPIC',
127+
],
128+
},
129+
], # end condition (OS!="win")
130+
], # end conditions
131+
}, # end target <(addon_target_name)
132+
133+
# Target to copy a generated add-on to a standard location:
134+
{
135+
'target_name': 'copy_addon',
136+
137+
# Declare that the output of this target is not linked:
138+
'type': 'none',
139+
140+
# Define dependencies:
141+
'dependencies': [
142+
# Require that the add-on be generated before building this target:
143+
'<(addon_target_name)',
144+
],
145+
146+
# Define a list of actions:
147+
'actions': [
148+
{
149+
'action_name': 'copy_addon',
150+
'message': 'Copying addon...',
151+
152+
# Explicitly list the inputs in the command-line invocation below:
153+
'inputs': [],
154+
155+
# Declare the expected outputs:
156+
'outputs': [
157+
'<(addon_output_dir)/<(addon_target_name).node',
158+
],
159+
160+
# Define the command-line invocation:
161+
'action': [
162+
'cp',
163+
'<(PRODUCT_DIR)/<(addon_target_name).node',
164+
'<(addon_output_dir)/<(addon_target_name).node',
165+
],
166+
},
167+
], # end actions
168+
}, # end target copy_addon
169+
], # end targets
170+
}

0 commit comments

Comments
 (0)