Skip to content

Commit bd33456

Browse files
chore: update the signum implementation and improve test coverage
--- 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: 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: 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: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed ---
1 parent 2fd0866 commit bd33456

2 files changed

Lines changed: 55 additions & 30 deletions

File tree

lib/node_modules/@stdlib/lapack/base/dlasv2/lib/base.js

Lines changed: 11 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -22,28 +22,10 @@
2222

2323
// MODULES //
2424

25-
var signum = require( '@stdlib/math/base/special/signum' );
25+
var dlamch = require( '@stdlib/lapack/base/dlamch' );
2626
var sqrt = require( '@stdlib/math/base/special/sqrt' );
2727
var abs = require( '@stdlib/math/base/special/abs' );
28-
29-
30-
// FUNCTIONS //
31-
32-
/**
33-
* Returns `x` multipled by `signum( y )`.
34-
*
35-
* @private
36-
* @param {number} x - scalar element
37-
* @param {number} y - scalar element
38-
* @returns {number} computed value
39-
*
40-
* @example
41-
* var out = sign( 1.0, -0.9 );
42-
* // out => -1.0
43-
*/
44-
function sign( x, y ) {
45-
return x * signum( y );
46-
}
28+
var copysign = require( '@stdlib/math/base/special/copysign' );
4729

4830

4931
// MAIN //
@@ -62,6 +44,7 @@ function sign( x, y ) {
6244
*
6345
* @example
6446
* var Float64Array = require( '@stdlib/array/float64' );
47+
*
6548
* var out = new Float64Array( 6 );
6649
*
6750
* out = dlasv2( 2.0, 3.0, 4.0, out, 1, 0 );
@@ -139,9 +122,7 @@ function dlasv2( F, G, H, out, strideOut, offsetOut ) {
139122
gasmal = true;
140123
if ( ga > fa ) {
141124
PMAX = 2;
142-
143-
// TODO: replace 1.11022302E-16 with dlamch( 'E' )
144-
if ( ( fa / ga ) < 1.11022302E-16 ) {
125+
if ( ( fa / ga ) < dlamch( 'E' ) ) {
145126
// Case of very large GA
146127
gasmal = false;
147128
ssmax = ga;
@@ -193,9 +174,9 @@ function dlasv2( F, G, H, out, strideOut, offsetOut ) {
193174
if ( mm === 0.0 ) {
194175
// Note that M is very tiny
195176
if ( l === 0.0 ) {
196-
t = sign( 2.0, ft ) * sign( 1.0, gt );
177+
t = copysign( 2.0, ft ) * copysign( 1.0, gt );
197178
} else {
198-
t = ( ( gt / sign( d, ft ) ) + ( m / t ) );
179+
t = ( ( gt / copysign( d, ft ) ) + ( m / t ) );
199180
}
200181
} else {
201182
t = ( ( m / ( s + t ) ) + ( m / ( r + l ) ) ) * ( 1.0 + a );
@@ -221,16 +202,16 @@ function dlasv2( F, G, H, out, strideOut, offsetOut ) {
221202

222203
// Correct signs 0f ssmax and ssmin
223204
if ( PMAX === 1 ) {
224-
tsign = sign( 1.0, csr ) * sign( 1.0, csl ) * sign( 1.0, F );
205+
tsign = copysign( 1.0, csr ) * copysign( 1.0, csl ) * copysign( 1.0, F );
225206
}
226207
if ( PMAX === 2 ) {
227-
tsign = sign( 1.0, snr ) * sign( 1.0, csl ) * sign( 1.0, G );
208+
tsign = copysign( 1.0, snr ) * copysign( 1.0, csl ) * copysign( 1.0, G );
228209
}
229210
if ( PMAX === 3 ) {
230-
tsign = sign( 1.0, snr ) * sign( 1.0, snl ) * sign( 1.0, H );
211+
tsign = copysign( 1.0, snr ) * copysign( 1.0, snl ) * copysign( 1.0, H );
231212
}
232-
ssmax = sign( ssmax, tsign );
233-
ssmin = sign( ssmin, tsign * sign( 1.0, F ) * sign( 1.0, H ) );
213+
ssmax = copysign( ssmax, tsign );
214+
ssmin = copysign( ssmin, tsign * copysign( 1.0, F ) * copysign( 1.0, H ) );
234215

235216
out[ offsetOut ] = ssmin;
236217
out[ offsetOut + strideOut ] = ssmax;

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

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,3 +133,47 @@ tape( 'the function correctly computes svd of diagonal matrix', function test( t
133133
isApprox( t, out, expected, 1.0 );
134134
t.end();
135135
});
136+
137+
tape( 'the function correctly computes svd of diagonal matrix with a very large `G`', function test( t ) {
138+
var expected;
139+
var out;
140+
141+
expected = new Float64Array( [ 2.0e-20, 1.0e+20, 1.0, 2.0e-20, 1.0e-20, 1.0 ] );
142+
out = new Float64Array( 6 );
143+
out = dlasv2( 2.0, 1.0e+20, 1.0, out );
144+
isApprox( t, out, expected, 1.0 );
145+
t.end();
146+
});
147+
148+
tape( 'the function computes svd of diagonal matrix with a very large `G` when `H` is greater than 1', function test( t ) {
149+
var expected;
150+
var out;
151+
152+
expected = new Float64Array( [ 6.0e-20, 1.0e+20, 1.0, 2.0e-20, 3.0e-20, 1.0 ] );
153+
out = new Float64Array( 6 );
154+
out = dlasv2( 2.0, 1.0e+20, 3.0, out );
155+
isApprox( t, out, expected, 1.0 );
156+
t.end();
157+
});
158+
159+
tape( 'the function correctly computes svd of diagonal matrix with an infinite `F`', function test( t ) {
160+
var expected;
161+
var out;
162+
163+
expected = new Float64Array( [ 1.0, Infinity, 0.0, 1.0, 0.0, 1.0 ] );
164+
out = new Float64Array( 6 );
165+
out = dlasv2( Infinity, 2.0, 1.0, out );
166+
isApprox( t, out, expected, 1.0 );
167+
t.end();
168+
});
169+
170+
tape( 'the function computes svd of diagonal matrix with tiny off-diagonal entries when `F` and `H` are equal', function test( t ) {
171+
var expected;
172+
var out;
173+
174+
expected = new Float64Array( [ 3.0, 3.0, 0.7071067811865475, 0.7071067811865475, 0.7071067811865475, 0.7071067811865475 ] );
175+
out = new Float64Array( 6 );
176+
out = dlasv2( 3.0, 5e-324, 3.0, out );
177+
isApprox( t, out, expected, 1.0 );
178+
t.end();
179+
});

0 commit comments

Comments
 (0)