Skip to content

Commit def6a3c

Browse files
committed
feat: add lapack/base/dladiv
--- 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: passed - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: passed - 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 660d87d commit def6a3c

File tree

9 files changed

+516
-0
lines changed

9 files changed

+516
-0
lines changed
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
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+
'use strict';
20+
21+
// MODULES //
22+
23+
var bench = require( '@stdlib/bench' );
24+
var uniform = require( '@stdlib/random/array/uniform' );
25+
var isnan = require( '@stdlib/math/base/assert/is-nan' );
26+
var Float64Array = require( '@stdlib/array/float64' );
27+
var pkg = require( './../package.json' ).name;
28+
var dladiv = require( './../lib' );
29+
30+
31+
// VARIABLES //
32+
33+
var options = {
34+
'dtype': 'float64'
35+
};
36+
37+
38+
// MAIN //
39+
40+
bench( pkg, function benchmark( b ) {
41+
var re;
42+
var im;
43+
var N;
44+
var P;
45+
var Q;
46+
var i;
47+
var j;
48+
var k;
49+
50+
N = 100;
51+
re = uniform( N, -500.0, 500.0, options );
52+
im = uniform( N, -500.0, 500.0, options );
53+
54+
P = new Float64Array( 1 );
55+
Q = new Float64Array( 1 );
56+
57+
b.tic();
58+
for ( i = 0; i < b.iterations; i++ ) {
59+
j = i % N;
60+
k = ( i+1 ) % N;
61+
dladiv( re[ j ], im[ j ], re[ k ], im[ k ], P, Q );
62+
if ( isnan( P[ 0 ] ) || isnan( Q[ 0 ] ) ) {
63+
b.fail( 'should not return NaN' );
64+
}
65+
}
66+
b.toc();
67+
if ( isnan( P[ 0 ] ) || isnan( Q[ 0 ] ) ) {
68+
b.fail( 'should not return NaN' );
69+
}
70+
b.pass( 'benchmark finished' );
71+
b.end();
72+
});
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
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+
'use strict';
20+
21+
// MODULES //
22+
23+
var bench = require( '@stdlib/bench' );
24+
var uniform = require( '@stdlib/random/array/uniform' );
25+
var isnan = require( '@stdlib/math/base/assert/is-nan' );
26+
var Float64Array = require( '@stdlib/array/float64' );
27+
var pkg = require( './../package.json' ).name;
28+
var dladiv = require( './../lib/ndarray.js' );
29+
30+
31+
// VARIABLES //
32+
33+
var options = {
34+
'dtype': 'float64'
35+
};
36+
37+
38+
// MAIN //
39+
40+
bench( pkg, function benchmark( b ) {
41+
var re;
42+
var im;
43+
var N;
44+
var P;
45+
var Q;
46+
var i;
47+
var j;
48+
var k;
49+
50+
N = 100;
51+
re = uniform( N, -500.0, 500.0, options );
52+
im = uniform( N, -500.0, 500.0, options );
53+
54+
P = new Float64Array( 1 );
55+
Q = new Float64Array( 1 );
56+
57+
b.tic();
58+
for ( i = 0; i < b.iterations; i++ ) {
59+
j = i % N;
60+
k = ( i+1 ) % N;
61+
dladiv( re[ j ], im[ j ], re[ k ], im[ k ], P, 0, Q, 0 );
62+
if ( isnan( P[ 0 ] ) || isnan( Q[ 0 ] ) ) {
63+
b.fail( 'should not return NaN' );
64+
}
65+
}
66+
b.toc();
67+
if ( isnan( P[ 0 ] ) || isnan( Q[ 0 ] ) ) {
68+
b.fail( 'should not return NaN' );
69+
}
70+
b.pass( 'benchmark finished' );
71+
b.end();
72+
});
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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+
'use strict';
20+
21+
var Float64Array = require( '@stdlib/array/float64' );
22+
var dladiv = require( './../lib' );
23+
24+
var P = new Float64Array( 1 );
25+
var Q = new Float64Array( 1 );
26+
dladiv( 2.0, 1.0, 3.0, 4.0, P, Q );
27+
console.log( '(2+i)/(3+4i) =', P[ 0 ], '+', Q[ 0 ], 'i' );
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
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+
'use strict';
20+
21+
// MODULES //
22+
23+
var cdiv = require( '@stdlib/complex/float64/base/div' ).assign;
24+
var Float64Array = require( '@stdlib/array/float64' );
25+
26+
27+
// VARIABLES //
28+
29+
var out = new Float64Array( 2 );
30+
31+
32+
// MAIN //
33+
34+
/**
35+
* Divides two double-precision complex floating-point numbers in real arithmetic.
36+
*
37+
* @private
38+
* @param {number} a - real component of numerator
39+
* @param {number} b - imaginary component of numerator
40+
* @param {number} c - real component of denominator
41+
* @param {number} d - imaginary component of denominator
42+
* @param {Float64Array} P - array containing a single element which is overwritten by the real part of the quotient
43+
* @param {NonNegativeInteger} offsetP - index of the element in `P`
44+
* @param {Float64Array} Q - array containing a single element which is overwritten by the imaginary part of the quotient
45+
* @param {NonNegativeInteger} offsetQ - index of the element in `Q`
46+
* @returns {void}
47+
*
48+
* @example
49+
* var Float64Array = require( '@stdlib/array/float64' );
50+
*
51+
* var P = new Float64Array( 1 );
52+
* var Q = new Float64Array( 1 );
53+
*
54+
* dladiv( -13.0, -1.0, -2.0, 1.0, P, 0, Q, 0 );
55+
* // P => <Float64Array>[ 5.0 ]
56+
* // Q => <Float64Array>[ 3.0 ]
57+
*/
58+
function dladiv( a, b, c, d, P, offsetP, Q, offsetQ ) {
59+
cdiv( a, b, c, d, out, 1, 0 );
60+
P[ offsetP ] = out[ 0 ];
61+
Q[ offsetQ ] = out[ 1 ];
62+
}
63+
64+
65+
// EXPORTS //
66+
67+
module.exports = dladiv;
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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+
'use strict';
20+
21+
// MODULES //
22+
23+
var base = require( './base.js' );
24+
25+
26+
// MAIN //
27+
28+
/**
29+
* Divides two double-precision complex floating-point numbers in real arithmetic.
30+
*
31+
* @param {number} a - real component of numerator
32+
* @param {number} b - imaginary component of numerator
33+
* @param {number} c - real component of denominator
34+
* @param {number} d - imaginary component of denominator
35+
* @param {Float64Array} P - array containing a single element which is overwritten by the real part of the quotient
36+
* @param {Float64Array} Q - array containing a single element which is overwritten by the imaginary part of the quotient
37+
* @returns {void}
38+
*
39+
* @example
40+
* var Float64Array = require( '@stdlib/array/float64' );
41+
*
42+
* var P = new Float64Array( 1 );
43+
* var Q = new Float64Array( 1 );
44+
*
45+
* dladiv( -13.0, -1.0, -2.0, 1.0, P, Q );
46+
* // P => <Float64Array>[ 5.0 ]
47+
* // Q => <Float64Array>[ 3.0 ]
48+
*/
49+
function dladiv( a, b, c, d, P, Q ) {
50+
return base( a, b, c, d, P, 0, Q, 0 );
51+
}
52+
53+
54+
// EXPORTS //
55+
56+
module.exports = dladiv;
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
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+
'use strict';
20+
21+
/**
22+
* LAPACK routine to divide two double-precision complex floating-point numbers.
23+
*
24+
* @module @stdlib/lapack/base/dladiv
25+
*
26+
* @example
27+
* var Float64Array = require( '@stdlib/array/float64' );
28+
* var dladiv = require( '@stdlib/lapack/base/dladiv' );
29+
*
30+
* var P = new Float64Array( 1 );
31+
* var Q = new Float64Array( 1 );
32+
*
33+
* dladiv( -13.0, -1.0, -2.0, 1.0, P, Q );
34+
* // P => <Float64Array>[ 5.0 ]
35+
* // Q => <Float64Array>[ 3.0 ]
36+
*/
37+
38+
// MODULES //
39+
40+
var join = require( 'path' ).join;
41+
var tryRequire = require( '@stdlib/utils/try-require' );
42+
var isError = require( '@stdlib/assert/is-error' );
43+
var main = require( './main.js' );
44+
45+
46+
// MAIN //
47+
48+
var dladiv;
49+
var tmp = tryRequire( join( __dirname, './native.js' ) );
50+
if ( isError( tmp ) ) {
51+
dladiv = main;
52+
} else {
53+
dladiv = tmp;
54+
}
55+
56+
57+
// EXPORTS //
58+
59+
module.exports = dladiv;
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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+
'use strict';
20+
21+
// MODULES //
22+
23+
var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' );
24+
var dladiv = require( './dladiv.js' );
25+
var ndarray = require( './ndarray.js' );
26+
27+
28+
// MAIN //
29+
30+
setReadOnly( dladiv, 'ndarray', ndarray );
31+
32+
33+
// EXPORTS //
34+
35+
module.exports = dladiv;

0 commit comments

Comments
 (0)