Skip to content

Commit eaee0ca

Browse files
added tests and modified package.json
--- type: pre_push_report description: Results of running various checks prior to pushing changes. report: - task: run_javascript_examples status: na - task: run_c_examples status: na - task: run_cpp_examples status: na - task: run_javascript_readme_examples status: na - task: run_c_benchmarks status: na - task: run_cpp_benchmarks status: na - task: run_fortran_benchmarks status: na - task: run_javascript_benchmarks status: na - task: run_julia_benchmarks status: na - task: run_python_benchmarks status: na - task: run_r_benchmarks status: na - task: run_javascript_tests status: passed ---
1 parent 90baf51 commit eaee0ca

File tree

8 files changed

+1081
-2
lines changed

8 files changed

+1081
-2
lines changed

lib/node_modules/@stdlib/blas/ext/base/wasm/dapxsum/package.json

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@stdlib/blas/base/ext/wasm/dapxsum",
33
"version": "0.0.0",
4-
"description": "Add a constant to each double-precision floating-point strided array element and compute the sum using an improved Kahan–Babuška algorithm.",
4+
"description": "Add a constant to each double-precision floating-point strided array element and compute the sum.",
55
"license": "Apache-2.0",
66
"author": {
77
"name": "The Stdlib Authors",
@@ -13,9 +13,20 @@
1313
"url": "https://github.com/stdlib-js/stdlib/graphs/contributors"
1414
}
1515
],
16+
"main": "./lib",
17+
"browser": {
18+
"./lib/binary.js": "./lib/binary.browser.js"
19+
},
1620
"directories": {
17-
"src": "./src"
21+
"benchmark": "./benchmark",
22+
"doc": "./docs",
23+
"example": "./examples",
24+
"lib": "./lib",
25+
"scripts": "./scripts",
26+
"src": "./src",
27+
"test": "./test"
1828
},
29+
"types": "./docs/types",
1930
"scripts": {},
2031
"homepage": "https://github.com/stdlib-js/stdlib",
2132
"repository": {
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2024 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
'use strict';
20+
21+
// MODULES //
22+
23+
var tape = require( 'tape' );
24+
var dapxsum = require( './../lib' );
25+
26+
27+
// TESTS //
28+
29+
tape( 'main export is an object', function test( t ) {
30+
t.ok( true, __filename );
31+
t.strictEqual( typeof dapxsum, 'object', 'returns expected value' );
32+
t.end();
33+
});
34+
35+
tape( 'attached to the main export is a `main` method', function test( t ) {
36+
t.strictEqual( typeof dapxsum.main, 'function', 'returns expected value' );
37+
t.end();
38+
});
39+
40+
tape( 'attached to the main export is an `ndarray` method', function test( t ) {
41+
t.strictEqual( typeof dapxsum.ndarray, 'function', 'returns expected value' );
42+
t.end();
43+
});
44+
45+
tape( 'attached to the main export is a `Module` constructor', function test( t ) {
46+
t.strictEqual( typeof dapxsum.Module, 'function', 'returns expected value' );
47+
t.end();
48+
});
49+
50+
tape( 'the main export is a `Module` instance', function test( t ) {
51+
t.strictEqual( dapxsum instanceof dapxsum.Module, true, 'returns expected value' );
52+
t.end();
53+
});
Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2024 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
'use strict';
20+
21+
// MODULES //
22+
23+
var tape = require( 'tape' );
24+
var isnan = require( '@stdlib/math/base/assert/is-nan' );
25+
var Float64Array = require( '@stdlib/array/float64' );
26+
var dapxsum = require( './../lib' );
27+
28+
29+
// TESTS //
30+
31+
tape( 'main export is an object', function test( t ) {
32+
t.ok( true, __filename );
33+
t.strictEqual( typeof dapxsum, 'object', 'main export is an object' );
34+
t.end();
35+
});
36+
37+
tape( 'the `main` method has an arity of 4', function test( t ) {
38+
t.strictEqual( dapxsum.main.length, 4, 'returns expected value' );
39+
t.end();
40+
});
41+
42+
tape( 'the `main` method adds a constant and calculates the sum of all strided array elements', function test( t ) {
43+
var x;
44+
var v;
45+
46+
x = new Float64Array( [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0, 0.0, -3.0, 3.0 ] );
47+
v = dapxsum.main( x.length, 5.0, x, 1 );
48+
t.strictEqual( v, 48.0, 'returns expected value' );
49+
50+
x = new Float64Array( [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ] );
51+
v = dapxsum.main( x.length, 5.0, x, 1 );
52+
t.strictEqual( v, 33.0, 'returns expected value' );
53+
54+
x = new Float64Array( [ -4.0, -4.0 ] );
55+
v = dapxsum.main( x.length, 5.0, x, 1 );
56+
t.strictEqual( v, 2.0, 'returns expected value' );
57+
58+
x = new Float64Array( [ NaN, 4.0 ] );
59+
v = dapxsum.main( x.length, 5.0, x, 1 );
60+
t.strictEqual( isnan( v ), true, 'returns expected value' );
61+
62+
x = new Float64Array( [ 1.0, 1e100, 1.0, -1.0e100 ] );
63+
v = dapxsum.main( x.length, 5.0, x, 1 );
64+
t.strictEqual( v, 12.0, 'returns expected value' );
65+
66+
t.end();
67+
});
68+
69+
tape( 'if provided an `N` parameter less than or equal to `0`, the `main` method returns `0.0`', function test( t ) {
70+
var x;
71+
var v;
72+
73+
x = new Float64Array( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] );
74+
75+
v = dapxsum.main( 0, 5.0, x, 1 );
76+
t.strictEqual( v, 0.0, 'returns expected value' );
77+
78+
v = dapxsum.main( -1, 5.0, x, 1 );
79+
t.strictEqual( v, 0.0, 'returns expected value' );
80+
81+
t.end();
82+
});
83+
84+
tape( 'if provided an `N` parameter equal to `1`, the `main` method returns the first element plus a constant', function test( t ) {
85+
var x;
86+
var v;
87+
88+
x = new Float64Array( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] );
89+
90+
v = dapxsum.main( 1, 5.0, x, 1 );
91+
t.strictEqual( v, 6.0, 'returns expected value' );
92+
93+
t.end();
94+
});
95+
96+
tape( 'the `main` method supports a `stride` parameter', function test( t ) {
97+
var x;
98+
var v;
99+
100+
x = new Float64Array([
101+
1.0, // 0
102+
2.0,
103+
2.0, // 1
104+
-7.0,
105+
-2.0, // 2
106+
3.0,
107+
4.0, // 3
108+
2.0
109+
]);
110+
111+
v = dapxsum.main( 4, 5.0, x, 2 );
112+
113+
t.strictEqual( v, 25.0, 'returns expected value' );
114+
t.end();
115+
});
116+
117+
tape( 'the `main` method supports a negative `stride` parameter', function test( t ) {
118+
var x;
119+
var v;
120+
121+
x = new Float64Array([
122+
1.0, // 3
123+
2.0,
124+
2.0, // 2
125+
-7.0,
126+
-2.0, // 1
127+
3.0,
128+
4.0, // 0
129+
2.0
130+
]);
131+
132+
v = dapxsum.main( 4, 5.0, x, -2 );
133+
134+
t.strictEqual( v, 25.0, 'returns expected value' );
135+
t.end();
136+
});
137+
138+
tape( 'if provided a `stride` parameter equal to `0`, the `main` method returns the first element plus a constant repeated N times', function test( t ) {
139+
var x;
140+
var v;
141+
142+
x = new Float64Array( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] );
143+
144+
v = dapxsum.main( x.length, 5.0, x, 0 );
145+
146+
t.strictEqual( v, x.length * (x[0]+5.0), 'returns expected value' );
147+
t.end();
148+
});
149+
150+
tape( 'the `main` method supports view offsets', function test( t ) {
151+
var x0;
152+
var x1;
153+
var v;
154+
155+
x0 = new Float64Array([
156+
2.0,
157+
1.0, // 0
158+
2.0,
159+
-2.0, // 1
160+
-2.0,
161+
2.0, // 2
162+
3.0,
163+
4.0, // 3
164+
6.0
165+
]);
166+
167+
x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element
168+
v = dapxsum.main( 4, 5.0, x1, 2 );
169+
t.strictEqual( v, 25.0, 'returns expected value' );
170+
171+
t.end();
172+
});

0 commit comments

Comments
 (0)