Skip to content

Commit 86ac66b

Browse files
aayush0325kgrytestdlib-bot
authored
feat: add lapack/base/iladlc
PR-URL: #7083 Co-authored-by: Athan Reines <[email protected]> Reviewed-by: Athan Reines <[email protected]> Co-authored-by: stdlib-bot <[email protected]>
1 parent b16cee9 commit 86ac66b

36 files changed

+2401
-0
lines changed
Lines changed: 259 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,259 @@
1+
<!--
2+
3+
@license Apache-2.0
4+
5+
Copyright (c) 2025 The Stdlib Authors.
6+
7+
Licensed under the Apache License, Version 2.0 (the "License");
8+
you may not use this file except in compliance with the License.
9+
You may obtain a copy of the License at
10+
11+
http://www.apache.org/licenses/LICENSE-2.0
12+
13+
Unless required by applicable law or agreed to in writing, software
14+
distributed under the License is distributed on an "AS IS" BASIS,
15+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
See the License for the specific language governing permissions and
17+
limitations under the License.
18+
19+
-->
20+
21+
# iladlc
22+
23+
> Find the index of the last non-zero column in a matrix `A`.
24+
25+
<section class="usage">
26+
27+
## Usage
28+
29+
```javascript
30+
var iladlc = require( '@stdlib/lapack/base/iladlc' );
31+
```
32+
33+
#### iladlc( order, M, N, A, LDA )
34+
35+
Returns the index of the last non-zero column in a matrix `A`.
36+
37+
```javascript
38+
var Float64Array = require( '@stdlib/array/float64' );
39+
40+
var A = new Float64Array( [ 1.0, 2.0, 0.0, 3.0, 4.0, 0.0 ] );
41+
42+
/*
43+
A = [
44+
[ 1.0, 2.0, 0.0 ],
45+
[ 3.0, 4.0, 0.0 ]
46+
]
47+
*/
48+
49+
var out = iladlc( 'row-major', 2, 3, A, 3 );
50+
// returns 1
51+
```
52+
53+
The function has the following parameters:
54+
55+
- **order**: storage layout.
56+
- **M**: number of rows in `A`.
57+
- **N**: number of columns in `A`.
58+
- **A**: input [`Float64Array`][mdn-float64array].
59+
- **LDA**: stride of the first dimension of `A` (a.k.a., leading dimension of the matrix `A`).
60+
61+
Note that indexing is relative to the first index. To introduce an offset, use [`typed array`][mdn-typed-array] views.
62+
63+
<!-- eslint-disable stdlib/capitalized-comments -->
64+
65+
```javascript
66+
var Float64Array = require( '@stdlib/array/float64' );
67+
68+
// Initial array:
69+
var A0 = new Float64Array( [ 9999.0, 1.0, 2.0, 0.0, 3.0, 4.0, 0.0 ] );
70+
71+
// Create an offset view:
72+
var A1 = new Float64Array( A0.buffer, A0.BYTES_PER_ELEMENT*1 ); // start at 2nd element
73+
74+
var out = iladlc( 'row-major', 2, 3, A1, 3 );
75+
// returns 1
76+
```
77+
78+
#### iladlc.ndarray( M, N, A, strideA1, strideA2, offsetA )
79+
80+
Returns the index of the last non-zero column in a matrix `A` using alternative indexing semantics.
81+
82+
```javascript
83+
var Float64Array = require( '@stdlib/array/float64' );
84+
85+
var A = new Float64Array( [ 1.0, 2.0, 0.0, 3.0, 4.0, 0.0 ] );
86+
87+
/*
88+
A = [
89+
[ 1.0, 2.0, 0.0 ],
90+
[ 3.0, 4.0, 0.0 ]
91+
]
92+
*/
93+
94+
var out = iladlc.ndarray( 2, 3, A, 3, 1, 0 );
95+
// returns 1
96+
```
97+
98+
The function has the following parameters:
99+
100+
- **M**: number of rows in `A`.
101+
- **N**: number of columns in `A`.
102+
- **A**: input [`Float64Array`][mdn-float64array].
103+
- **strideA1**: stride of the first dimension of `A`.
104+
- **strideA2**: stride of the second dimension of `A`.
105+
- **offsetA**: starting index for `A`.
106+
107+
While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying buffer, the offset parameter supports indexing semantics based on a starting index. For example,
108+
109+
```javascript
110+
var Float64Array = require( '@stdlib/array/float64' );
111+
112+
var A = new Float64Array( [ 9999.0, 1.0, 2.0, 0.0, 3.0, 4.0, 0.0 ] );
113+
114+
/*
115+
A = [
116+
[ 1.0, 2.0, 0.0 ],
117+
[ 3.0, 4.0, 0.0 ]
118+
]
119+
*/
120+
121+
var out = iladlc.ndarray( 2, 3, A, 3, 1, 1 );
122+
// returns 1
123+
```
124+
125+
</section>
126+
127+
<!-- /.usage -->
128+
129+
<section class="notes">
130+
131+
## Notes
132+
133+
- This routine is commonly used throughout LAPACK to shrink work domains (e.g., before bulge-chasing, deflation, or when trimming Householder panels), thus ensuring that higher-level routines operate only on numerically relevant sub-matrices.
134+
- `iladlc()` corresponds to the [LAPACK][lapack] routine [`iladlc`][lapack-iladlc].
135+
136+
</section>
137+
138+
<!-- /.notes -->
139+
140+
<section class="examples">
141+
142+
## Examples
143+
144+
<!-- eslint no-undef: "error" -->
145+
146+
```javascript
147+
var ndarray2array = require( '@stdlib/ndarray/base/to-array' );
148+
var Float64Array = require( '@stdlib/array/float64' );
149+
var shape2strides = require( '@stdlib/ndarray/base/shape2strides' );
150+
var iladlc = require( '@stdlib/lapack/base/iladlc' );
151+
152+
var shape = [ 3, 3 ];
153+
var order = 'row-major';
154+
var strides = shape2strides( shape, order );
155+
156+
var A = new Float64Array( [ 1.0, 2.0, 0.0, 3.0, 4.0, 0.0, 5.0, 6.0, 0.0 ] );
157+
console.log( ndarray2array( A, shape, strides, 0, order ) );
158+
159+
var out = iladlc( order, shape[ 0 ], shape[ 1 ], A, strides[ 0 ] );
160+
console.log( out );
161+
```
162+
163+
</section>
164+
165+
<!-- /.examples -->
166+
167+
<!-- C interface documentation. -->
168+
169+
* * *
170+
171+
<section class="c">
172+
173+
## C APIs
174+
175+
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
176+
177+
<section class="intro">
178+
179+
</section>
180+
181+
<!-- /.intro -->
182+
183+
<!-- C usage documentation. -->
184+
185+
<section class="usage">
186+
187+
### Usage
188+
189+
```c
190+
TODO
191+
```
192+
193+
#### TODO
194+
195+
TODO.
196+
197+
```c
198+
TODO
199+
```
200+
201+
TODO
202+
203+
```c
204+
TODO
205+
```
206+
207+
</section>
208+
209+
<!-- /.usage -->
210+
211+
<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
212+
213+
<section class="notes">
214+
215+
</section>
216+
217+
<!-- /.notes -->
218+
219+
<!-- C API usage examples. -->
220+
221+
<section class="examples">
222+
223+
### Examples
224+
225+
```c
226+
TODO
227+
```
228+
229+
</section>
230+
231+
<!-- /.examples -->
232+
233+
</section>
234+
235+
<!-- /.c -->
236+
237+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
238+
239+
<section class="related">
240+
241+
</section>
242+
243+
<!-- /.related -->
244+
245+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
246+
247+
<section class="links">
248+
249+
[lapack]: https://www.netlib.org/lapack/explore-html/
250+
251+
[lapack-iladlc]: https://www.netlib.org/lapack/explore-html-3.6.1/d7/d43/group__aux_o_t_h_e_rauxiliary_gab8b3783390380038c9d26de61d7aefb4.html
252+
253+
[mdn-float64array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float64Array
254+
255+
[mdn-typed-array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray
256+
257+
</section>
258+
259+
<!-- /.links -->
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
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 isnan = require( '@stdlib/math/base/assert/is-nan' );
25+
var zeros = require( '@stdlib/array/zeros' );
26+
var pow = require( '@stdlib/math/base/special/pow' );
27+
var floor = require( '@stdlib/math/base/special/floor' );
28+
var pkg = require( './../package.json' ).name;
29+
var iladlc = require( './../lib/iladlc.js' );
30+
31+
32+
// VARIABLES //
33+
34+
var LAYOUTS = [
35+
'row-major',
36+
'column-major'
37+
];
38+
39+
40+
// FUNCTIONS //
41+
42+
/**
43+
* Creates a benchmark function.
44+
*
45+
* @private
46+
* @param {string} order - storage layout
47+
* @param {PositiveInteger} N - number of elements along each dimension
48+
* @returns {Function} benchmark function
49+
*/
50+
function createBenchmark( order, N ) {
51+
var A = zeros( N*N, 'float64' );
52+
return benchmark;
53+
54+
/**
55+
* Benchmark function.
56+
*
57+
* @private
58+
* @param {Benchmark} b - benchmark instance
59+
*/
60+
function benchmark( b ) {
61+
var z;
62+
var i;
63+
64+
b.tic();
65+
for ( i = 0; i < b.iterations; i++ ) {
66+
A[ 0 ] = i;
67+
z = iladlc( order, N, N, A, N );
68+
if ( isnan( z ) ) {
69+
b.fail( 'should not return NaN' );
70+
}
71+
}
72+
b.toc();
73+
if ( isnan( z ) ) {
74+
b.fail( 'should not return NaN' );
75+
}
76+
b.pass( 'benchmark finished' );
77+
b.end();
78+
}
79+
}
80+
81+
82+
// MAIN //
83+
84+
/**
85+
* Main execution sequence.
86+
*
87+
* @private
88+
*/
89+
function main() {
90+
var min;
91+
var max;
92+
var ord;
93+
var N;
94+
var f;
95+
var i;
96+
var k;
97+
98+
min = 1; // 10^min
99+
max = 6; // 10^max
100+
101+
for ( k = 0; k < LAYOUTS.length; k++ ) {
102+
ord = LAYOUTS[ k ];
103+
for ( i = min; i <= max; i++ ) {
104+
N = floor( pow( pow( 10, i ), 1.0/2.0 ) );
105+
f = createBenchmark( ord, N );
106+
bench( pkg+'::square_matrix:order='+ord+',size='+(N*N), f );
107+
}
108+
}
109+
}
110+
111+
main();

0 commit comments

Comments
 (0)