|
| 1 | +<!-- |
| 2 | +
|
| 3 | +@license Apache-2.0 |
| 4 | +
|
| 5 | +Copyright (c) 2026 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 | +# ctril |
| 22 | + |
| 23 | +> Copy the lower triangular part of a single-precision complex floating-point matrix `A` to another matrix `B`. |
| 24 | +
|
| 25 | +<section class="intro"> |
| 26 | + |
| 27 | +</section> |
| 28 | + |
| 29 | +<!-- /.intro --> |
| 30 | + |
| 31 | +<section class="usage"> |
| 32 | + |
| 33 | +## Usage |
| 34 | + |
| 35 | +```javascript |
| 36 | +var ctril = require( '@stdlib/blas/ext/base/ctril' ); |
| 37 | +``` |
| 38 | + |
| 39 | +#### ctril( order, M, N, k, A, LDA, B, LDB ) |
| 40 | + |
| 41 | +Copies the lower triangular part of a single-precision complex floating-point matrix `A` to another matrix `B`. |
| 42 | + |
| 43 | +```javascript |
| 44 | +var Complex64Array = require( '@stdlib/array/complex64' ); |
| 45 | + |
| 46 | +var A = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); |
| 47 | +var B = new Complex64Array( 4 ); |
| 48 | + |
| 49 | +ctril( 'row-major', 2, 2, 0, A, 2, B, 2 ); |
| 50 | +// B => <Complex64Array>[ 1.0, 2.0, 0.0, 0.0, 5.0, 6.0, 7.0, 8.0 ] |
| 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 | +- **k**: diagonal above which to ignore. A value of `k = 0` refers to the main diagonal, `k < 0` refers to a diagonal below the main diagonal, and `k > 0` refers to a diagonal above the main diagonal. Accordingly, when `k > 0`, the function copies the lower triangle **and** one or more super-diagonals (i.e., part of the upper triangle), and, when `k < 0`, the function copies only part of the lower triangle. |
| 59 | +- **A**: input matrix. |
| 60 | +- **LDA**: stride of the first dimension of `A` (a.k.a., leading dimension of the matrix `A`). |
| 61 | +- **B**: output matrix. |
| 62 | +- **LDB**: stride of the first dimension of `B` (a.k.a., leading dimension of the matrix `B`). |
| 63 | + |
| 64 | +Setting the `k` parameter to a value other than `0` allows including and excluding super- and sub-diagonals, respectively. For example, to copy the lower triangle and the first super-diagonal, |
| 65 | + |
| 66 | +```javascript |
| 67 | +var Complex64Array = require( '@stdlib/array/complex64' ); |
| 68 | + |
| 69 | +var A = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); |
| 70 | +var B = new Complex64Array( 4 ); |
| 71 | + |
| 72 | +ctril( 'row-major', 2, 2, 1, A, 2, B, 2 ); |
| 73 | +// B => <Complex64Array>[ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] |
| 74 | +``` |
| 75 | + |
| 76 | +Note that indexing is relative to the first index. To introduce an offset, use [`typed array`][mdn-typed-array] views. |
| 77 | + |
| 78 | +<!-- eslint-disable stdlib/capitalized-comments, max-len --> |
| 79 | + |
| 80 | +```javascript |
| 81 | +var Complex64Array = require( '@stdlib/array/complex64' ); |
| 82 | + |
| 83 | +// Initial arrays... |
| 84 | +var A0 = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0 ] ); |
| 85 | +var B0 = new Complex64Array( 5 ); |
| 86 | + |
| 87 | +// Create offset views... |
| 88 | +var A1 = new Complex64Array( A0.buffer, A0.BYTES_PER_ELEMENT*1 ); // start at 2nd element |
| 89 | +var B1 = new Complex64Array( B0.buffer, B0.BYTES_PER_ELEMENT*1 ); // start at 2nd element |
| 90 | + |
| 91 | +ctril( 'row-major', 2, 2, 0, A1, 2, B1, 2 ); |
| 92 | +// B0 => <Complex64Array>[ 0.0, 0.0, 3.0, 4.0, 0.0, 0.0, 7.0, 8.0, 9.0, 10.0 ] |
| 93 | +``` |
| 94 | + |
| 95 | +#### ctril.ndarray( M, N, k, A, sa1, sa2, oa, B, sb1, sb2, ob ) |
| 96 | + |
| 97 | +Copies the lower triangular part of a single-precision complex floating-point matrix `A` to another matrix `B` using alternative indexing semantics. |
| 98 | + |
| 99 | +```javascript |
| 100 | +var Complex64Array = require( '@stdlib/array/complex64' ); |
| 101 | + |
| 102 | +var A = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); |
| 103 | +var B = new Complex64Array( 4 ); |
| 104 | + |
| 105 | +ctril.ndarray( 2, 2, 0, A, 2, 1, 0, B, 2, 1, 0 ); |
| 106 | +// B => <Complex64Array>[ 1.0, 2.0, 0.0, 0.0, 5.0, 6.0, 7.0, 8.0 ] |
| 107 | +``` |
| 108 | + |
| 109 | +The function has the following parameters: |
| 110 | + |
| 111 | +- **M**: number of rows in `A`. |
| 112 | +- **N**: number of columns in `A`. |
| 113 | +- **k**: diagonal above which to ignore. |
| 114 | +- **A**: input matrix. |
| 115 | +- **sa1**: stride of the first dimension of `A`. |
| 116 | +- **sa2**: stride of the second dimension of `A`. |
| 117 | +- **oa**: starting index for `A`. |
| 118 | +- **B**: output matrix. |
| 119 | +- **sb1**: stride of the first dimension of `B`. |
| 120 | +- **sb2**: stride of the second dimension of `B`. |
| 121 | +- **ob**: starting index for `B`. |
| 122 | + |
| 123 | +While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying buffer, the offset parameters support indexing semantics based on starting indices. For example, |
| 124 | + |
| 125 | +<!-- eslint-disable max-len --> |
| 126 | + |
| 127 | +```javascript |
| 128 | +var Complex64Array = require( '@stdlib/array/complex64' ); |
| 129 | + |
| 130 | +var A = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); |
| 131 | +var B = new Complex64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); |
| 132 | + |
| 133 | +ctril.ndarray( 2, 2, 0, A, 2, 1, 0, B, 2, 1, 2 ); |
| 134 | +// B => <Complex64Array>[ 0.0, 0.0, 0.0, 0.0, 1.0, 2.0, 0.0, 0.0, 5.0, 6.0, 7.0, 8.0 ] |
| 135 | +``` |
| 136 | + |
| 137 | +</section> |
| 138 | + |
| 139 | +<!-- /.usage --> |
| 140 | + |
| 141 | +<section class="notes"> |
| 142 | + |
| 143 | +## Notes |
| 144 | + |
| 145 | +- Elements outside of the copied region are left unchanged. |
| 146 | + |
| 147 | +</section> |
| 148 | + |
| 149 | +<!-- /.notes --> |
| 150 | + |
| 151 | +<section class="examples"> |
| 152 | + |
| 153 | +## Examples |
| 154 | + |
| 155 | +<!-- eslint no-undef: "error" --> |
| 156 | + |
| 157 | +```javascript |
| 158 | +var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); |
| 159 | +var uniform = require( '@stdlib/random/array/discrete-uniform' ); |
| 160 | +var Complex64Array = require( '@stdlib/array/complex64' ); |
| 161 | +var numel = require( '@stdlib/ndarray/base/numel' ); |
| 162 | +var shape2strides = require( '@stdlib/ndarray/base/shape2strides' ); |
| 163 | +var ctril = require( '@stdlib/blas/ext/base/ctril' ); |
| 164 | + |
| 165 | +var shape = [ 5, 8 ]; |
| 166 | +var order = 'row-major'; |
| 167 | +var strides = shape2strides( shape, order ); |
| 168 | + |
| 169 | +var N = numel( shape ); |
| 170 | + |
| 171 | +var opts = { |
| 172 | + 'dtype': 'float32' |
| 173 | +}; |
| 174 | +var A = new Complex64Array( uniform( N*2, -10, 10, opts ) ); |
| 175 | +console.log( ndarray2array( A, shape, strides, 0, order ) ); |
| 176 | + |
| 177 | +var B = new Complex64Array( uniform( N*2, -10, 10, opts ) ); |
| 178 | +console.log( ndarray2array( B, shape, strides, 0, order ) ); |
| 179 | + |
| 180 | +ctril( order, shape[ 0 ], shape[ 1 ], 0, A, strides[ 0 ], B, strides[ 0 ] ); |
| 181 | +console.log( ndarray2array( B, shape, strides, 0, order ) ); |
| 182 | +``` |
| 183 | + |
| 184 | +</section> |
| 185 | + |
| 186 | +<!-- /.examples --> |
| 187 | + |
| 188 | +<!-- C interface documentation. --> |
| 189 | + |
| 190 | +* * * |
| 191 | + |
| 192 | +<section class="c"> |
| 193 | + |
| 194 | +## C APIs |
| 195 | + |
| 196 | +<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. --> |
| 197 | + |
| 198 | +<section class="intro"> |
| 199 | + |
| 200 | +</section> |
| 201 | + |
| 202 | +<!-- /.intro --> |
| 203 | + |
| 204 | +<!-- C usage documentation. --> |
| 205 | + |
| 206 | +<section class="usage"> |
| 207 | + |
| 208 | +### Usage |
| 209 | + |
| 210 | +```c |
| 211 | +#include "stdlib/blas/ext/base/ctril.h" |
| 212 | +``` |
| 213 | + |
| 214 | +#### stdlib_strided_ctril( layout, M, N, k, \*A, LDA, \*B, LDB ) |
| 215 | + |
| 216 | +Copies the lower triangular part of a single-precision complex floating-point matrix `A` to another matrix `B`. |
| 217 | + |
| 218 | +```c |
| 219 | +#include "stdlib/blas/base/shared.h" |
| 220 | +#include "stdlib/complex/float32/ctor.h" |
| 221 | + |
| 222 | +const float A[] = { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f }; |
| 223 | +float B[] = { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f }; |
| 224 | + |
| 225 | +stdlib_strided_ctril( CblasRowMajor, 2, 2, 0, (stdlib_complex64_t *)A, 2, (stdlib_complex64_t *)B, 2 ); |
| 226 | +``` |
| 227 | +
|
| 228 | +The function accepts the following arguments: |
| 229 | +
|
| 230 | +- **layout**: `[in] CBLAS_LAYOUT` storage layout. |
| 231 | +- **M**: `[in] CBLAS_INT` number of rows in `A`. |
| 232 | +- **N**: `[in] CBLAS_INT` number of columns in `A`. |
| 233 | +- **k**: `[in] CBLAS_INT` diagonal above which to ignore. |
| 234 | +- **A**: `[in] stdlib_complex64_t*` input matrix. |
| 235 | +- **LDA**: `[in] CBLAS_INT` stride of the first dimension of `A` (a.k.a., leading dimension of the matrix `A`). |
| 236 | +- **B**: `[out] stdlib_complex64_t*` output matrix. |
| 237 | +- **LDB**: `[in] CBLAS_INT` stride of the first dimension of `B` (a.k.a., leading dimension of the matrix `B`). |
| 238 | +
|
| 239 | +```c |
| 240 | +void API_SUFFIX(stdlib_strided_ctril)( const CBLAS_LAYOUT layout, const CBLAS_INT M, const CBLAS_INT N, const CBLAS_INT k, const stdlib_complex64_t *A, const CBLAS_INT LDA, stdlib_complex64_t *B, const CBLAS_INT LDB ); |
| 241 | +``` |
| 242 | + |
| 243 | +#### stdlib_strided_ctril_ndarray( M, N, k, \*A, sa1, sa2, oa, \*B, sb1, sb2, ob ) |
| 244 | + |
| 245 | +Copies the lower triangular part of a single-precision complex floating-point matrix `A` to another matrix `B` using alternative indexing semantics. |
| 246 | + |
| 247 | +```c |
| 248 | +#include "stdlib/complex/float32/ctor.h" |
| 249 | + |
| 250 | +const float A[] = { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f }; |
| 251 | +float B[] = { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f }; |
| 252 | + |
| 253 | +stdlib_strided_ctril_ndarray( 2, 2, 0, (stdlib_complex64_t *)A, 2, 1, 0, (stdlib_complex64_t *)B, 2, 1, 0 ); |
| 254 | +``` |
| 255 | +
|
| 256 | +The function accepts the following arguments: |
| 257 | +
|
| 258 | +- **M**: `[in] CBLAS_INT` number of rows in `A`. |
| 259 | +- **N**: `[in] CBLAS_INT` number of columns in `A`. |
| 260 | +- **k**: `[in] CBLAS_INT` diagonal above which to ignore. |
| 261 | +- **A**: `[in] stdlib_complex64_t*` input matrix. |
| 262 | +- **sa1**: `[in] CBLAS_INT` stride of the first dimension of `A`. |
| 263 | +- **sa2**: `[in] CBLAS_INT` stride of the second dimension of `A`. |
| 264 | +- **oa**: `[in] CBLAS_INT` starting index for `A`. |
| 265 | +- **B**: `[out] stdlib_complex64_t*` output matrix. |
| 266 | +- **sb1**: `[in] CBLAS_INT` stride of the first dimension of `B`. |
| 267 | +- **sb2**: `[in] CBLAS_INT` stride of the second dimension of `B`. |
| 268 | +- **ob**: `[in] CBLAS_INT` starting index for `B`. |
| 269 | +
|
| 270 | +```c |
| 271 | +void API_SUFFIX(stdlib_strided_ctril_ndarray)( const CBLAS_INT M, const CBLAS_INT N, const CBLAS_INT k, const stdlib_complex64_t *A, const CBLAS_INT strideA1, const CBLAS_INT strideA2, const CBLAS_INT offsetA, stdlib_complex64_t *B, const CBLAS_INT strideB1, const CBLAS_INT strideB2, const CBLAS_INT offsetB ); |
| 272 | +``` |
| 273 | + |
| 274 | +</section> |
| 275 | + |
| 276 | +<!-- /.usage --> |
| 277 | + |
| 278 | +<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 279 | + |
| 280 | +<section class="notes"> |
| 281 | + |
| 282 | +</section> |
| 283 | + |
| 284 | +<!-- /.notes --> |
| 285 | + |
| 286 | +<!-- C API usage examples. --> |
| 287 | + |
| 288 | +<section class="examples"> |
| 289 | + |
| 290 | +### Examples |
| 291 | + |
| 292 | +```c |
| 293 | +#include "stdlib/blas/ext/base/ctril.h" |
| 294 | +#include "stdlib/blas/base/shared.h" |
| 295 | +#include "stdlib/complex/float32/ctor.h" |
| 296 | +#include <stdio.h> |
| 297 | + |
| 298 | +int main( void ) { |
| 299 | + // Define a 3x3 input matrix stored in row-major order: |
| 300 | + const float A[] = { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f, 11.0f, 12.0f, 13.0f, 14.0f, 15.0f, 16.0f, 17.0f, 18.0f }; |
| 301 | + |
| 302 | + // Define a 3x3 output matrix: |
| 303 | + float B[] = { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f }; |
| 304 | + |
| 305 | + // Specify the number of elements along each dimension of `A`: |
| 306 | + const CBLAS_INT M = 3; |
| 307 | + const CBLAS_INT N = 3; |
| 308 | + |
| 309 | + // Copy the lower triangular part of `A` to `B`: |
| 310 | + stdlib_strided_ctril( CblasRowMajor, M, N, 0, (stdlib_complex64_t *)A, N, (stdlib_complex64_t *)B, N ); |
| 311 | + |
| 312 | + // Print the result: |
| 313 | + for ( int i = 0; i < M; i++ ) { |
| 314 | + for ( int j = 0; j < N; j++ ) { |
| 315 | + int idx = ( (i*N) + j ) * 2; |
| 316 | + printf( "B[ %i,%i ] = %f + %fi\n", i, j, B[ idx ], B[ idx+1 ] ); |
| 317 | + } |
| 318 | + } |
| 319 | + |
| 320 | + // Copy the lower triangular part of `A`, including the first super-diagonal, to `B` using alternative indexing semantics: |
| 321 | + stdlib_strided_ctril_ndarray( M, N, 1, (stdlib_complex64_t *)A, N, 1, 0, (stdlib_complex64_t *)B, N, 1, 0 ); |
| 322 | + |
| 323 | + // Print the result: |
| 324 | + for ( int i = 0; i < M; i++ ) { |
| 325 | + for ( int j = 0; j < N; j++ ) { |
| 326 | + int idx = ( (i*N) + j ) * 2; |
| 327 | + printf( "B[ %i,%i ] = %f + %fi\n", i, j, B[ idx ], B[ idx+1 ] ); |
| 328 | + } |
| 329 | + } |
| 330 | +} |
| 331 | +``` |
| 332 | +
|
| 333 | +</section> |
| 334 | +
|
| 335 | +<!-- /.examples --> |
| 336 | +
|
| 337 | +</section> |
| 338 | +
|
| 339 | +<!-- /.c --> |
| 340 | +
|
| 341 | +<section class="references"> |
| 342 | +
|
| 343 | +</section> |
| 344 | +
|
| 345 | +<!-- /.references --> |
| 346 | +
|
| 347 | +<section class="related"> |
| 348 | +
|
| 349 | +</section> |
| 350 | +
|
| 351 | +<!-- /.related --> |
| 352 | +
|
| 353 | +<section class="links"> |
| 354 | +
|
| 355 | +[mdn-typed-array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray |
| 356 | +
|
| 357 | +</section> |
| 358 | +
|
| 359 | +<!-- /.links --> |
0 commit comments