Skip to content

Commit 15b5f08

Browse files
adressed changes
1 parent 37519d5 commit 15b5f08

File tree

5 files changed

+403
-60
lines changed

5 files changed

+403
-60
lines changed

lib/node_modules/@stdlib/stats/base/ndarray/smeanpw/README.md

Lines changed: 148 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
@license Apache-2.0
44
5-
Copyright (c) 2025 The Stdlib Authors.
5+
Copyright (c) 2026 The Stdlib Authors.
66
77
Licensed under the Apache License, Version 2.0 (the "License");
88
you may not use this file except in compliance with the License.
@@ -111,6 +111,153 @@ console.log( v );
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/stats/base/ndarray/smeanpw.h"
138+
```
139+
140+
#### stdlib_stats_smeanpw( arrays )
141+
142+
Computes the arithmetic mean of a one-dimensional single-precision floating-point ndarray using pairwise summation.
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+
152+
// Create an ndarray:
153+
const float data[] = { 1.0f, 2.0f, 3.0f, 4.0f };
154+
int64_t shape[] = { 4 };
155+
int64_t strides[] = { STDLIB_NDARRAY_FLOAT32_BYTES_PER_ELEMENT };
156+
int8_t submodes[] = { STDLIB_NDARRAY_INDEX_ERROR };
157+
158+
struct ndarray *x = stdlib_ndarray_allocate( STDLIB_NDARRAY_FLOAT32, (uint8_t *)data, 1, shape, strides, 0, STDLIB_NDARRAY_ROW_MAJOR, STDLIB_NDARRAY_INDEX_ERROR, 1, submodes );
159+
160+
// Compute the arithmetic mean:
161+
const struct ndarray *arrays[] = { x };
162+
float v = stdlib_stats_smeanpw( arrays );
163+
// returns 2.5f
164+
165+
// Free allocated memory:
166+
stdlib_ndarray_free( x );
167+
```
168+
169+
The function accepts the following arguments:
170+
171+
- **arrays**: `[in] struct ndarray**` list containing a one-dimensional input ndarray.
172+
173+
```c
174+
float stdlib_stats_smeanpw( const struct ndarray *arrays[] );
175+
```
176+
177+
</section>
178+
179+
<!-- /.usage -->
180+
181+
<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
182+
183+
<section class="notes">
184+
185+
</section>
186+
187+
<!-- /.notes -->
188+
189+
<!-- C API usage examples. -->
190+
191+
<section class="examples">
192+
193+
### Examples
194+
195+
```c
196+
#include "stdlib/stats/base/ndarray/smeanpw.h"
197+
#include "stdlib/ndarray/ctor.h"
198+
#include "stdlib/ndarray/dtypes.h"
199+
#include "stdlib/ndarray/index_modes.h"
200+
#include "stdlib/ndarray/orders.h"
201+
#include "stdlib/ndarray/base/bytes_per_element.h"
202+
#include <stdint.h>
203+
#include <stdlib.h>
204+
#include <stdio.h>
205+
206+
int main( void ) {
207+
// Create a data buffer:
208+
const float data[] = { 1.0f, -2.0f, 3.0f, -4.0f, 5.0f, -6.0f, 7.0f, -8.0f };
209+
210+
// Specify the number of array dimensions:
211+
const int64_t ndims = 1;
212+
213+
// Specify the array shape:
214+
int64_t shape[] = { 4 };
215+
216+
// Specify the array strides:
217+
int64_t strides[] = { 2*STDLIB_NDARRAY_FLOAT32_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 an ndarray:
233+
struct ndarray *x = stdlib_ndarray_allocate( STDLIB_NDARRAY_FLOAT32, (uint8_t *)data, ndims, shape, strides, offset, order, imode, nsubmodes, submodes );
234+
if ( x == NULL ) {
235+
fprintf( stderr, "Error allocating memory.\n" );
236+
exit( 1 );
237+
}
238+
239+
// Define a list of ndarrays:
240+
const struct ndarray *arrays[] = { x };
241+
242+
// Compute the arithmetic mean:
243+
float v = stdlib_stats_smeanpw( arrays );
244+
245+
// Print the result:
246+
printf( "mean: %f\n", v );
247+
248+
// Free allocated memory:
249+
stdlib_ndarray_free( x );
250+
}
251+
```
252+
253+
</section>
254+
255+
<!-- /.examples -->
256+
257+
</section>
258+
259+
<!-- /.c -->
260+
114261
* * *
115262
116263
<section class="references">

lib/node_modules/@stdlib/stats/base/ndarray/smeanpw/benchmark/benchmark.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ var pow = require( '@stdlib/math/base/special/pow' );
2727
var ndarray = require( '@stdlib/ndarray/base/ctor' );
2828
var format = require( '@stdlib/string/format' );
2929
var pkg = require( './../package.json' ).name;
30-
var smeanpw = require( './../lib' );
30+
var smeanpw = require( './../lib/main.js' );
3131

3232

3333
// VARIABLES //
Lines changed: 157 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +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
121
{
2-
"targets": [
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:
352
{
4-
"target_name": "addon",
5-
"dependencies": [
6-
"<!@(node -p \"var manifest = require('./manifest.json'); manifest.libpath.join('\" \"');\")"
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)',
763
],
8-
"sources": [
9-
"./src/addon.c",
10-
"./src/main.c"
64+
65+
# List of source files:
66+
'sources': [
67+
'<@(src_files)',
1168
],
12-
"libraries": [
13-
"<!@(node -p \"var manifest = require('./manifest.json'); var libs = manifest.libraries; libs = libs.map(function(lib) { if (process.platform === 'win32') { return lib + '.lib'; } return '-l' + lib; }); libs.join(' ');\")"
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',
1490
],
15-
"include_dirs": [
16-
"./include",
17-
"<!@(node -p \"require( 'path' ).dirname( require.resolve( '@stdlib/utils/napi/include' ) );\")",
18-
"<!@(node -p \"var manifest = require('./manifest.json'); var arr = manifest.include; var len = arr.length; var sep = require( 'path' ).sep; var out = ''; var i; for ( i = 0; i < len; i++ ) { if ( i > 0 ) { out += ' '; } out += arr[ i ].replace( /\\\\/g, sep ); } out;\")"
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',
1996
],
20-
"defines": [
21-
"STDLIB_NDARRAY_STRICT_SINGLE_INDEXING_MODE"
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',
22102
],
23-
"conditions": [
103+
104+
# Linker flags:
105+
'ldflags': [],
106+
107+
# Apply conditions based on the host OS:
108+
'conditions': [
24109
[
25-
"OS==\"win\"",
110+
'OS=="mac"',
26111
{
27-
"libraries": [
28-
"<!@(node -p \"var manifest = require('./manifest.json'); var path = require( 'path' ); var libs = manifest.libpath; var sep = path.sep; libs = libs.map(function(lib) { return lib.replace( /\\\\/g, sep ); }); libs.join(' ');\")"
112+
# Linker flags:
113+
'ldflags': [
114+
'-undefined dynamic_lookup',
115+
'-Wl,-no-pie',
116+
'-Wl,-search_paths_first',
29117
],
30-
"defines": [
31-
"NOMINMAX"
32-
]
33-
}
34-
],
118+
},
119+
], # end condition (OS=="mac")
35120
[
36-
"OS!=\"win\"",
121+
'OS!="win"',
37122
{
38-
"cflags": [
39-
"-std=c99"
123+
# C/C++ flags:
124+
'cflags': [
125+
# Generate platform-independent code:
126+
'-fPIC',
40127
],
41-
"libraries": [
42-
"<!@(node -p \"var manifest = require('./manifest.json'); var path = require( 'path' ); var libs = manifest.libpath; var sep = path.sep; libs = libs.map(function(lib) { lib = lib.replace( /\\\\/g, sep ); return '-L' + lib; }); libs.join(' ');\")"
43-
]
44-
}
45-
],
46-
[
47-
"OS==\"mac\"",
48-
{
49-
"xcode_settings": {
50-
"OTHER_CFLAGS": [
51-
"-std=c99"
52-
]
53-
}
54-
}
55-
]
56-
]
57-
}
58-
]
59-
}
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)