Skip to content

Commit 2339ecb

Browse files
committed
feat: add lapack/base/dlaset
--- 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: na - 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 cb44d2a commit 2339ecb

File tree

1 file changed

+237
-0
lines changed
  • lib/node_modules/@stdlib/lapack/base/dlaset/lib

1 file changed

+237
-0
lines changed
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+
'use strict';
20+
21+
// MODULES //
22+
23+
var isRowMajor = require( '@stdlib/ndarray/base/assert/is-row-major' );
24+
var loopOrder = require( '@stdlib/ndarray/base/nullary-loop-interchange-order' );
25+
var min = require( '@stdlib/math/base/special/fast/min' );
26+
27+
28+
// FUNCTIONS //
29+
30+
/**
31+
* Initialises an M by N matrix `A` to `beta` on the diagonals and `alpha` on the off diagonals, setting all of matrix `A`.
32+
*
33+
* @private
34+
* @param {NonNegativeInteger} M - number of rows in matrix `A`
35+
* @param {NonNegativeInteger} N - number of columns in matrix `A`
36+
* @param {Float64Array} A - input matrix
37+
* @param {integer} strideA1 - stride of the first dimension of `A`
38+
* @param {integer} strideA2 - stride of the second dimension of `A`
39+
* @param {NonNegativeInteger} offsetA - starting index for `A`
40+
* @param {number} alpha - number to set on off diagonal elements
41+
* @param {number} beta - number to set on diagonal elements
42+
* @returns {Float64Array} `A`
43+
*
44+
* @example
45+
* var Float64Array = require( '@stdlib/array/float64' );
46+
*
47+
* var A = new Float64Array( 4 );
48+
*
49+
* setAll( 2, 2, A, 2, 1, 0, 0.0, 1.0 );
50+
* // A => <Float64Array>[ 1.0, 0.0, 0.0, 1.0 ]
51+
*/
52+
function setAll( M, N, A, strideA1, strideA2, offsetA, alpha, beta ) {
53+
var da0;
54+
var da1;
55+
var sh;
56+
var S0;
57+
var S1;
58+
var sa;
59+
var ia;
60+
var i0;
61+
var i1;
62+
var o;
63+
64+
// Resolve the loop interchange order:
65+
o = loopOrder( [ M, N ], [ strideA1, strideA2 ] );
66+
sh = o.sh;
67+
sa = o.sx;
68+
69+
// Extract loop variables for purposes of loop interchange: dimensions and loop offset (pointer) increments...
70+
S0 = sh[ 0 ];
71+
S1 = sh[ 1 ];
72+
da0 = sa[ 0 ];
73+
da1 = sa[ 1 ] - ( S0*sa[0] );
74+
75+
// Set the pointers to the first indexed elements in the respective matrices...
76+
ia = offsetA;
77+
78+
// Iterate over the matrix dimensions...
79+
for ( i1 = 0; i1 < S1; i1++ ) {
80+
for ( i0 = 0; i0 < S0; i0++ ) {
81+
A[ ia ] = alpha;
82+
ia += da0;
83+
}
84+
ia += da1;
85+
}
86+
87+
ia = offsetA;
88+
for ( i1 = 0; i1 < min( M, N ); i1++ ) {
89+
A[ ia ] = beta;
90+
ia += strideA1 + strideA2;
91+
}
92+
return A;
93+
}
94+
95+
/**
96+
* Initialises an M by N matrix `A` to `beta` on the diagonals and `alpha` on the off diagonals, setting upper triangular elements of `A`.
97+
*
98+
* @private
99+
* @param {NonNegativeInteger} M - number of rows in matrix `A`
100+
* @param {NonNegativeInteger} N - number of columns in matrix `A`
101+
* @param {Float64Array} A - input matrix
102+
* @param {integer} strideA1 - stride of the first dimension of `A`
103+
* @param {integer} strideA2 - stride of the second dimension of `A`
104+
* @param {NonNegativeInteger} offsetA - starting index for `A`
105+
* @param {number} alpha - number to set on off diagonal elements
106+
* @param {number} beta - number to set on diagonal elements
107+
* @returns {Float64Array} `A`
108+
*
109+
* @example
110+
* var Float64Array = require( '@stdlib/array/float64' );
111+
*
112+
* var A = new Float64Array( 4 );
113+
*
114+
* setUpper( 2, 2, A, 2, 1, 0, 1.0, 2.0 );
115+
* // A => <Float64Array>[ 2.0, 1.0, 0.0, 2.0 ]
116+
*/
117+
function setUpper( M, N, A, strideA1, strideA2, offsetA, alpha, beta ) {
118+
var ia;
119+
var i0;
120+
var i1;
121+
122+
ia = offsetA;
123+
if ( isRowMajor( [ strideA1, strideA2 ] ) ) {
124+
for ( i1 = 0; i1 < M; i1++ ) {
125+
for ( i0 = i1; i0 < N; i0++ ) {
126+
A[ ia+(i0*strideA2) ] = alpha;
127+
}
128+
ia += strideA1;
129+
}
130+
} else {
131+
for ( i1 = 0; i1 < N; i1++ ) {
132+
for ( i0 = 0; i0 <= min( i1, M-1 ); i0++ ) {
133+
A[ ia+(i0*strideA1) ] = alpha;
134+
}
135+
ia += strideA2;
136+
}
137+
}
138+
139+
ia = offsetA;
140+
for ( i1 = 0; i1 < min( M, N ); i1++ ) {
141+
A[ ia ] = beta;
142+
ia += strideA1 + strideA2;
143+
}
144+
return A;
145+
}
146+
147+
/**
148+
* Initialises an M by N matrix `A` to `beta` on the diagonals and `alpha` on the off diagonals, setting upper triangular elements of `A`.
149+
*
150+
* @private
151+
* @param {NonNegativeInteger} M - number of rows in matrix `A`
152+
* @param {NonNegativeInteger} N - number of columns in matrix `A`
153+
* @param {Float64Array} A - input matrix
154+
* @param {integer} strideA1 - stride of the first dimension of `A`
155+
* @param {integer} strideA2 - stride of the second dimension of `A`
156+
* @param {NonNegativeInteger} offsetA - starting index for `A`
157+
* @param {number} alpha - number to set on off diagonal elements
158+
* @param {number} beta - number to set on diagonal elements
159+
* @returns {Float64Array} `A`
160+
*
161+
* @example
162+
* var Float64Array = require( '@stdlib/array/float64' );
163+
*
164+
* var A = new Float64Array( 4 );
165+
*
166+
* setLower( 2, 2, A, 2, 1, 0, 1.0, 2.0 );
167+
* // A => <Float64Array>[ 2.0, 0.0, 1.0, 2.0 ]
168+
*/
169+
function setLower( M, N, A, strideA1, strideA2, offsetA, alpha, beta ) {
170+
var ia;
171+
var i0;
172+
var i1;
173+
174+
ia = offsetA;
175+
if ( isRowMajor( [ strideA1, strideA2 ] ) ) {
176+
for ( i1 = 0; i1 < M; i1++ ) {
177+
for ( i0 = 0; i0 <= min( i1, N-1 ); i0++ ) {
178+
A[ ia+(i0*strideA2) ] = alpha;
179+
}
180+
ia += strideA1;
181+
}
182+
} else {
183+
for ( i1 = 0; i1 < N; i1++ ) {
184+
for ( i0 = i1; i0 < M; i0++ ) {
185+
A[ ia+(i0*strideA1) ] = alpha;
186+
}
187+
ia += strideA2;
188+
}
189+
}
190+
ia = offsetA;
191+
for ( i1 = 0; i1 < min( M, N ); i1++ ) {
192+
A[ ia ] = beta;
193+
ia += strideA1 + strideA2;
194+
}
195+
return A;
196+
}
197+
198+
199+
// MAIN //
200+
201+
/**
202+
* Initialises an M by N matrix `A` to `beta` on the diagonals and `alpha` on the off diagonals.
203+
*
204+
* @private
205+
* @param {string} uplo - specifies whether to copy the upper or lower triangular/trapezoidal part of matrix `A`
206+
* @param {NonNegativeInteger} M - number of rows in matrix `A`
207+
* @param {NonNegativeInteger} N - number of columns in matrix `A`
208+
* @param {Float64Array} A - input matrix
209+
* @param {integer} strideA1 - stride of the first dimension of `A`
210+
* @param {integer} strideA2 - stride of the second dimension of `A`
211+
* @param {NonNegativeInteger} offsetA - starting index for `A`
212+
* @param {number} alpha - number to set on off diagonal elements
213+
* @param {number} beta - number to set on diagonal elements
214+
* @returns {Float64Array} `A`
215+
*
216+
* @example
217+
* var Float64Array = require( '@stdlib/array/float64' );
218+
*
219+
* var A = new Float64Array( 4 );
220+
*
221+
* dlaset( 'all', 2, 2, A, 2, 1, 0, 0.0, 1.0 );
222+
* // A => <Float64Array>[ 1.0, 0.0, 0.0, 1.0 ]
223+
*/
224+
function dlaset( uplo, M, N, A, strideA1, strideA2, offsetA, alpha, beta ) {
225+
if ( uplo === 'upper' ) {
226+
return setUpper( M, N, A, strideA1, strideA2, offsetA, alpha, beta );
227+
}
228+
if ( uplo === 'lower' ) {
229+
return setLower( M, N, A, strideA1, strideA2, offsetA, alpha, beta );
230+
}
231+
return setAll( M, N, A, strideA1, strideA2, offsetA, alpha, beta );
232+
}
233+
234+
235+
// EXPORTS //
236+
237+
module.exports = dlaset;

0 commit comments

Comments
 (0)