Skip to content

Commit 5653d0f

Browse files
committed
test: add initial ndarray tests
--- 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: passed - 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 d51e004 commit 5653d0f

File tree

2 files changed

+253
-0
lines changed

2 files changed

+253
-0
lines changed

lib/node_modules/@stdlib/lapack/base/dlange/test/test.dlange.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,22 @@ tape( 'the function throws an error if provided a fourth argument which is not a
163163
}
164164
});
165165

166+
tape( 'the function returns zero if number of rows or columns is zero', function test( t ) {
167+
var data;
168+
var work;
169+
var out;
170+
var A;
171+
172+
data = ONE_NORM_ROW_MAJOR;
173+
174+
A = new Float64Array( data.A );
175+
work = new Float64Array( data.work );
176+
177+
out = dlange( data.order, data.norm, 0, data.N, A, data.LDA, work );
178+
t.strictEqual( out, 0.0, 'returns expected value' );
179+
t.end();
180+
});
181+
166182
tape( 'the function calculates the one norm for a given matrix A (row-major)', function test( t ) {
167183
var data;
168184
var work;
Lines changed: 237 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,237 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2025 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+
/* eslint-disable id-length, max-len */
20+
21+
'use strict';
22+
23+
// MODULES //
24+
25+
var tape = require( 'tape' );
26+
var Float64Array = require( '@stdlib/array/float64' );
27+
var dlange = require( './../lib/ndarray.js' );
28+
29+
30+
// FIXTURES //
31+
32+
var ONE_NORM_ROW_MAJOR = require( './fixtures/one_norm_row_major.json' );
33+
var ONE_NORM_COLUMN_MAJOR = require( './fixtures/one_norm_column_major.json' );
34+
var INFINITY_NORM_ROW_MAJOR = require( './fixtures/infinity_norm_row_major.json' );
35+
var INFINITY_NORM_COLUMN_MAJOR = require( './fixtures/infinity_norm_column_major.json' );
36+
var MAX_ELEMENT_ROW_MAJOR = require( './fixtures/max_element_row_major.json' );
37+
var MAX_ELEMENT_COLUMN_MAJOR = require( './fixtures/max_element_column_major.json' );
38+
var FROBENIUS_NORM_ROW_MAJOR = require( './fixtures/frobenius_norm_row_major.json' );
39+
var FROBENIUS_NORM_COLUMN_MAJOR = require( './fixtures/frobenius_norm_column_major.json' );
40+
41+
42+
// TESTS //
43+
44+
tape( 'main export is a function', function test( t ) {
45+
t.ok( true, __filename );
46+
t.strictEqual( typeof dlange, 'function', 'main export is a function' );
47+
t.end();
48+
});
49+
50+
tape( 'the function has an arity of 10', function test( t ) {
51+
t.strictEqual( dlange.length, 10, 'returns expected value' );
52+
t.end();
53+
});
54+
55+
tape( 'the function throws an error if provided a second argument which is not a valid operation', function test( t ) {
56+
var values;
57+
var data;
58+
var work;
59+
var A;
60+
var i;
61+
62+
data = FROBENIUS_NORM_ROW_MAJOR;
63+
64+
values = [
65+
'foo',
66+
'bar',
67+
'beep',
68+
'boop',
69+
-5,
70+
NaN,
71+
true,
72+
false,
73+
null,
74+
void 0,
75+
[],
76+
{},
77+
function noop() {}
78+
];
79+
80+
A = new Float64Array( data.A );
81+
work = new Float64Array( data.work );
82+
83+
for ( i = 0; i < values.length; i++ ) {
84+
t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] );
85+
}
86+
t.end();
87+
88+
function badValue( value ) {
89+
return function badValue() {
90+
dlange( value, data.M, data.N, A, data.strideA1, data.strideA2, data.offsetA, work, data.strideWork, data.offsetWork );
91+
};
92+
}
93+
});
94+
95+
tape( 'the function returns zero if number of rows or columns is zero', function test( t ) {
96+
var data;
97+
var work;
98+
var out;
99+
var A;
100+
101+
data = ONE_NORM_ROW_MAJOR;
102+
103+
A = new Float64Array( data.A );
104+
work = new Float64Array( data.work );
105+
106+
out = dlange( data.norm, 0, data.N, A, data.strideA1, data.strideA2, data.offsetA, work, data.strideWork, data.offsetWork );
107+
t.strictEqual( out, 0.0, 'returns expected value' );
108+
t.end();
109+
});
110+
111+
tape( 'the function calculates the one norm for a given matrix A (row-major)', function test( t ) {
112+
var data;
113+
var work;
114+
var out;
115+
var A;
116+
117+
data = ONE_NORM_ROW_MAJOR;
118+
119+
A = new Float64Array( data.A );
120+
work = new Float64Array( data.work );
121+
122+
out = dlange( data.norm, data.M, data.N, A, data.strideA1, data.strideA2, data.offsetA, work, data.strideWork, data.offsetWork );
123+
t.strictEqual( out, data.expected, 'returns expected value' );
124+
t.end();
125+
});
126+
127+
tape( 'the function calculates the one norm for a given matrix A (column-major)', function test( t ) {
128+
var data;
129+
var work;
130+
var out;
131+
var A;
132+
133+
data = ONE_NORM_COLUMN_MAJOR;
134+
135+
A = new Float64Array( data.A );
136+
work = new Float64Array( data.work );
137+
138+
out = dlange( data.norm, data.M, data.N, A, data.strideA1, data.strideA2, data.offsetA, work, data.strideWork, data.offsetWork );
139+
t.strictEqual( out, data.expected, 'returns expected value' );
140+
t.end();
141+
});
142+
143+
tape( 'the function calculates the infinity norm for a given matrix A (row-major)', function test( t ) {
144+
var data;
145+
var work;
146+
var out;
147+
var A;
148+
149+
data = INFINITY_NORM_ROW_MAJOR;
150+
151+
A = new Float64Array( data.A );
152+
work = new Float64Array( data.work );
153+
154+
out = dlange( data.norm, data.M, data.N, A, data.strideA1, data.strideA2, data.offsetA, work, data.strideWork, data.offsetWork );
155+
t.strictEqual( out, data.expected, 'returns expected value' );
156+
t.end();
157+
});
158+
159+
tape( 'the function calculates the infinity norm for a given matrix A (column-major)', function test( t ) {
160+
var data;
161+
var work;
162+
var out;
163+
var A;
164+
165+
data = INFINITY_NORM_COLUMN_MAJOR;
166+
167+
A = new Float64Array( data.A );
168+
work = new Float64Array( data.work );
169+
170+
out = dlange( data.norm, data.M, data.N, A, data.strideA1, data.strideA2, data.offsetA, work, data.strideWork, data.offsetWork );
171+
t.strictEqual( out, data.expected, 'returns expected value' );
172+
t.end();
173+
});
174+
175+
tape( 'the function calculates the frobenius norm for a given matrix A (row-major)', function test( t ) {
176+
var data;
177+
var work;
178+
var out;
179+
var A;
180+
181+
data = FROBENIUS_NORM_ROW_MAJOR;
182+
183+
A = new Float64Array( data.A );
184+
work = new Float64Array( data.work );
185+
186+
out = dlange( data.norm, data.M, data.N, A, data.strideA1, data.strideA2, data.offsetA, work, data.strideWork, data.offsetWork );
187+
t.strictEqual( out, data.expected, 'returns expected value' );
188+
t.end();
189+
});
190+
191+
tape( 'the function calculates the frobenius norm for a given matrix A (column-major)', function test( t ) {
192+
var data;
193+
var work;
194+
var out;
195+
var A;
196+
197+
data = FROBENIUS_NORM_COLUMN_MAJOR;
198+
199+
A = new Float64Array( data.A );
200+
work = new Float64Array( data.work );
201+
202+
out = dlange( data.norm, data.M, data.N, A, data.strideA1, data.strideA2, data.offsetA, work, data.strideWork, data.offsetWork );
203+
t.strictEqual( out, data.expected, 'returns expected value' );
204+
t.end();
205+
});
206+
207+
tape( 'the function calculates the maximum absolute value for a given matrix A (row-major)', function test( t ) {
208+
var data;
209+
var work;
210+
var out;
211+
var A;
212+
213+
data = MAX_ELEMENT_ROW_MAJOR;
214+
215+
A = new Float64Array( data.A );
216+
work = new Float64Array( data.work );
217+
218+
out = dlange( data.norm, data.M, data.N, A, data.strideA1, data.strideA2, data.offsetA, work, data.strideWork, data.offsetWork );
219+
t.strictEqual( out, data.expected, 'returns expected value' );
220+
t.end();
221+
});
222+
223+
tape( 'the function calculates the maximum absolute value for a given matrix A (column-major)', function test( t ) {
224+
var data;
225+
var work;
226+
var out;
227+
var A;
228+
229+
data = MAX_ELEMENT_COLUMN_MAJOR;
230+
231+
A = new Float64Array( data.A );
232+
work = new Float64Array( data.work );
233+
234+
out = dlange( data.norm, data.M, data.N, A, data.strideA1, data.strideA2, data.offsetA, work, data.strideWork, data.offsetWork );
235+
t.strictEqual( out, data.expected, 'returns expected value' );
236+
t.end();
237+
});

0 commit comments

Comments
 (0)