Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 | 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 2x 2x 2x 1x 1x 1x 3x 3x 3x 1x 3x 6x 6x 6x 3x 1x 1x 2x 3x 6x 12x 12x 12x 6x 2x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 2x 2x 2x 1x 1x 1x 3x 3x 3x 1x 3x 6x 6x 6x 3x 1x 1x 2x 3x 6x 12x 12x 12x 6x 2x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 53x 53x 53x 53x 53x 53x 53x 53x 53x 53x 53x 53x 53x 53x 53x 53x 53x 53x 53x 9x 9x 53x 29x 29x 29x 29x 29x 40x 15x 15x 15x 15x 15x 15x 53x 3x 53x 3x 3x 44x 53x 6x 6x 38x 38x 53x 31x 53x 10x 30x 60x 60x 180x 180x 180x 180x 60x 60x 60x 30x 10x 10x 28x 53x 21x 53x 11x 33x 66x 66x 198x 198x 198x 198x 66x 66x 66x 33x 11x 11x 17x 53x 13x 53x 7x 21x 42x 42x 126x 126x 126x 126x 42x 42x 42x 21x 7x 7x 10x 53x 30x 60x 60x 180x 180x 180x 180x 60x 60x 60x 30x 10x 53x 3x 3x 3x 3x 3x | /** * @license Apache-2.0 * * Copyright (c) 2025 The Stdlib Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /* eslint-disable max-len, max-params */ 'use strict'; // MODULES // var isRowMajor = require( '@stdlib/ndarray/base/assert/is-row-major' ); // FUNCTIONS // /** * Fills a upper or lower triangular part of a matrix with zeros. * * @private * @param {string} uplo - specifies whether the upper or lower triangular part of the matrix should be referenced * @param {NonNegativeInteger} N - order of the matrix * @param {Float64Array} X - matrix to fill * @param {integer} strideX1 - stride of the first dimension of `X` * @param {integer} strideX2 - stride of the second dimension of `X` * @param {NonNegativeInteger} offsetX - starting index for `X` * @returns {Float64Array} input matrix * * @example * var Float64Array = require( '@stdlib/array/float64' ); * * var X = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0 ] ); * * zeros( 'lower', 3, X, 3, 1, 0 ); * // X => <Float64Array>[ 0.0, 2.0, 3.0, 0.0, 0.0, 6.0, 0.0, 0.0, 0.0 ] * * @example * var Float64Array = require( '@stdlib/array/float64' ); * * var X = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0 ] ); * * zeros( 'lower', 3, X, 1, 3, 0 ); * // X => <Float64Array>[ 0.0, 0.0, 0.0, 4.0, 0.0, 0.0, 7.0, 8.0, 0.0 ] */ function zeros( uplo, N, X, strideX1, strideX2, offsetX ) { // TODO: consider moving to a separate package var isrm; var idx; var x0; var x1; var i1; var i0; isrm = isRowMajor( [ strideX1, strideX2 ] ); if ( isrm ) { x0 = strideX2; // stride for innermost loop x1 = strideX1; // stride for outermost loop } else { // column-major x0 = strideX1; // stride for innermost loop x1 = strideX2; // stride for outermost loop } if ( ( isrm && uplo === 'upper' ) || ( !isrm && uplo === 'lower' ) ) { for ( i1 = 0; i1 < N; i1++ ) { for ( i0 = i1; i0 < N; i0++ ) { idx = offsetX + ( i1 * x1 ) + ( i0 * x0 ); X[ idx ] = 0.0; } } return X; } // ( isrm && uplo === 'lower' ) || ( !isrm && uplo === 'upper' ) for ( i1 = 0; i1 < N; i1++ ) { for ( i0 = 0; i0 <= i1; i0++ ) { idx = offsetX + ( i1 * x1 ) + ( i0 * x0 ); X[ idx ] = 0.0; } } return X; } /** * Scales each element in a the upper or lower triangular part of matrix by a scalar `β`. * * @private * @param {string} uplo - specifies whether the upper or lower triangular part of the symmetric matrix should be referenced * @param {NonNegativeInteger} N - order of the matrix * @param {number} beta - scalar * @param {Float64Array} X - matrix to fill * @param {integer} strideX1 - stride of the first dimension of `X` * @param {integer} strideX2 - stride of the second dimension of `X` * @param {NonNegativeInteger} offsetX - starting index for `X` * @returns {Float64Array} input matrix * * @example * var Float64Array = require( '@stdlib/array/float64' ); * * var X = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0 ] ); * * scal( 'lower', 3, 5.0, X, 3, 1, 0 ); * // X => <Float64Array>[ 5.0, 2.0, 3.0, 20.0, 25.0, 6.0, 35.0, 40.0, 45.0 ] * * @example * var Float64Array = require( '@stdlib/array/float64' ); * * var X = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0 ] ); * * scal( 'lower', 3, 5.0, X, 1, 2, 0 ); * // X => <Float64Array>[ 5.0, 10.0, 15.0, 20.0, 25.0, 6.0, 35.0, 8.0, 9.0 ] */ function scal( uplo, N, beta, X, strideX1, strideX2, offsetX ) { // TODO: consider moving to a separate package var isrm; var idx; var x0; var x1; var i1; var i0; isrm = isRowMajor( [ strideX1, strideX2 ] ); if ( isrm ) { x0 = strideX2; // stride for innermost loop x1 = strideX1; // stride for outermost loop } else { x0 = strideX1; // stride for innermost loop x1 = strideX2; // stride for outermost loop } if ( ( isrm && uplo === 'upper' ) || ( !isrm && uplo === 'lower' ) ) { for ( i1 = 0; i1 < N; i1++ ) { for ( i0 = i1; i0 < N; i0++ ) { idx = offsetX + ( i1 * x1 ) + ( i0 * x0 ); X[ idx ] = X[ idx ] * beta; } } return X; } // ( isrm && uplo === 'lower' ) || ( !isrm && uplo === 'upper' ) for ( i1 = 0; i1 < N; i1++ ) { for ( i0 = 0; i0 <= i1; i0++ ) { idx = offsetX + ( i1 * x1 ) + ( i0 * x0 ); X[ idx ] = X[ idx ] * beta; } } return X; } // MAIN // /** * Performs one of the symmetric rank `K` operations `C = α*A*A**T + β*C` or `C = α*A**T*A + β*C` where `α` and `β` are scalars, `C` is an `N` by `N` symmetric matrix and `A` is an `N` by `K` matrix in the first case and a `K` by `N` matrix in the second case. * * @private * @param {string} uplo - specifies whether the upper or lower triangular part of the symmetric matrix `C` is supplied * @param {string} trans - specifies whether `A` should be transposed, conjugate-transposed, or not transposed * @param {NonNegativeInteger} N - order of the matrix `C` * @param {NonNegativeInteger} K - number of columns or number of rows of the matrix `A` * @param {number} alpha - scalar constant * @param {Float64Array} A - first matrix * @param {integer} strideA1 - stride of the first dimension of `A` * @param {integer} strideA2 - stride of the second dimension of `A` * @param {NonNegativeInteger} offsetA - starting index for `A` * @param {number} beta - scalar constant * @param {Float64Array} C - second matrix * @param {integer} strideC1 - stride of the first dimension of `C` * @param {integer} strideC2 - stride of the second dimension of `C` * @param {NonNegativeInteger} offsetC - starting index for `C` * @returns {Float64Array} `C` * * @example * var Float64Array = require( '@stdlib/array/float64' ); * * var A = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0 ] ); * var C = new Float64Array( [ 1.0, 2.0, 3.0, 0.0, 4.0, 5.0, 0.0, 0.0, 6.0 ] ); * * dsyrk( 'upper', 'no-transpose', 3, 3, 1.0, A, 3, 1, 0, 1.0, C, 3, 1, 0 ); * // C => <Float64Array>[ 15.0, 34.0, 53.0, 0.0, 81.0, 127.0, 0.0, 0.0, 200.0 ] */ function dsyrk( uplo, trans, N, K, alpha, A, strideA1, strideA2, offsetA, beta, C, strideC1, strideC2, offsetC ) { var isrma; var sa0; var sa1; var sc0; var sc1; var oa1; var oa2; var idx; var tmp; var oa; var i2; var i1; var i0; isrma = isRowMajor( [ strideA1, strideA2 ] ); // Check whether we can early return... if ( N === 0 || ( ( beta === 1.0 ) && ( ( alpha === 0.0 ) || ( K === 0 ) ) ) ) { return C; } if ( isrma ) { // For row-major matrices, the last dimension has the fastest changing index... sa0 = strideA2; // stride for innermost loop sa1 = strideA1; // stride for outermost loop sc0 = strideC2; sc1 = strideC1; } else { // isColMajor // For column-major matrices, the first dimension has the fastest changing index... sa0 = strideA1; // stride for innermost loop sa1 = strideA2; // stride for outermost loop sc0 = strideC1; sc1 = strideC2; } if ( beta === 0.0 ) { zeros( uplo, N, C, strideC1, strideC2, offsetC ); } else if ( beta !== 1.0 ) { scal( uplo, N, beta, C, strideC1, strideC2, offsetC ); } // Check whether we can early return... if ( alpha === 0.0 ) { return C; } oa = offsetA; if ( ( isrma && trans === 'no-transpose' && uplo === 'upper' ) || ( !isrma && trans !== 'no-transpose' && uplo === 'lower' ) ) { for ( i2 = 0; i2 < N; i2++ ) { for ( i1 = i2; i1 < N; i1++ ) { tmp = 0.0; for ( i0 = 0; i0 < K; i0++ ) { oa1 = oa + ( i2 * sa1 ) + ( i0 * sa0 ); oa2 = oa + ( i1 * sa1 ) + ( i0 * sa0 ); tmp += A[ oa1 ] * A[ oa2 ]; } idx = offsetC + ( i2 * sc1 ) + ( i1 * sc0 ); C[ idx ] += alpha * tmp; } } return C; } if ( ( isrma && trans === 'no-transpose' && uplo === 'lower' ) || ( !isrma && trans !== 'no-transpose' && uplo === 'upper' ) ) { for ( i2 = 0; i2 < N; i2++ ) { for ( i1 = 0; i1 <= i2; i1++ ) { tmp = 0.0; for ( i0 = 0; i0 < K; i0++ ) { oa1 = oa + ( i2 * sa1 ) + ( i0 * sa0 ); oa2 = oa + ( i1 * sa1 ) + ( i0 * sa0 ); tmp += A[ oa1 ] * A[ oa2 ]; } idx = offsetC + ( i2 * sc1 ) + ( i1 * sc0 ); C[ idx ] += alpha * tmp; } } return C; } if ( ( isrma && trans !== 'no-transpose' && uplo === 'upper' ) || ( !isrma && trans === 'no-transpose' && uplo === 'lower' ) ) { for ( i2 = 0; i2 < N; i2++ ) { for ( i1 = i2; i1 < N; i1++ ) { tmp = 0.0; for ( i0 = 0; i0 < K; i0++ ) { oa1 = oa + ( i0 * sa1 ) + ( i2 * sa0 ); oa2 = oa + ( i0 * sa1 ) + ( i1 * sa0 ); tmp += A[ oa1 ] * A[ oa2 ]; } idx = offsetC + ( i2 * sc1 ) + ( i1 * sc0 ); C[ idx ] += alpha * tmp; } } return C; } // ( isrma && trans !== 'no-transpose' && uplo === 'lower' ) || ( !isrma && trans === 'no-transpose' && uplo === 'upper' ) for ( i2 = 0; i2 < N; i2++ ) { for ( i1 = 0; i1 <= i2; i1++ ) { tmp = 0.0; for ( i0 = 0; i0 < K; i0++ ) { oa1 = oa + ( i0 * sa1 ) + ( i2 * sa0 ); oa2 = oa + ( i0 * sa1 ) + ( i1 * sa0 ); tmp += A[ oa1 ] * A[ oa2 ]; } idx = offsetC + ( i2 * sc1 ) + ( i1 * sc0 ); C[ idx ] += alpha * tmp; } } return C; } // EXPORTS // module.exports = dsyrk; |