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 | 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 102x 102x 102x 102x 102x 102x 102x 102x 102x 102x 102x 102x 102x 102x 102x 102x 4x 4x 102x 28x 28x 28x 28x 250x 250x 80x 80x 250x 102x 37x 37x 37x 30x 37x 17x 17x 17x 61x 61x 86x 86x 86x 86x 86x 61x 61x 61x 17x 17x 61x 61x 47x 47x 61x 37x 20x 20x 20x 20x 67x 67x 67x 89x 89x 89x 89x 89x 67x 53x 53x 67x 20x 70x 33x 33x 33x 33x 33x 33x 27x 33x 13x 13x 50x 37x 37x 37x 37x 37x 50x 50x 33x 20x 20x 63x 43x 43x 43x 43x 63x 63x 20x 33x 33x 33x 33x 33x 33x 27x 33x 13x 13x 50x 50x 48x 36x 36x 36x 48x 12x 12x 12x 48x 50x 50x 33x 20x 20x 63x 63x 61x 43x 43x 43x 61x 18x 18x 18x 61x 63x 63x 20x 33x 33x 98x 102x 3x 3x 3x 3x 3x | /**
* @license Apache-2.0
*
* Copyright (c) 2026 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 */
'use strict';
// MODULES //
var abs = require( '@stdlib/math/base/special/abs' );
var sqrt = require( '@stdlib/math/base/special/sqrt' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var Float64Array = require( '@stdlib/array/float64' );
var isRowMajor = require( '@stdlib/ndarray/base/assert/is-row-major-string' );
var isColumnMajor = require( '@stdlib/ndarray/base/assert/is-column-major-string' );
var dlassq = require( '@stdlib/lapack/base/dlassq' ).ndarray;
// MAIN //
/**
* Returns the value of the one-norm, Frobenius norm, infinity-norm, or the largest absolute value of any element of a real symmetric matrix `A` supplied in packed form.
*
* @private
* @param {string} order - storage layout ('row-major' or 'column-major')
* @param {string} norm - specifies the norm: 'M' (max abs), '1'/'O' (one-norm), 'I' (infinity-norm), 'F'/'E' (Frobenius)
* @param {string} uplo - specifies whether the upper or lower triangular part of the symmetric matrix `A` is supplied ('upper' or 'lower')
* @param {NonNegativeInteger} N - order of the matrix `A`
* @param {Float64Array} AP - packed form of a symmetric matrix `A`
* @param {integer} strideAP - `AP` stride length
* @param {NonNegativeInteger} offsetAP - starting `AP` index
* @returns {number} matrix norm
*
* @example
* var Float64Array = require( '@stdlib/array/float64' );
*
* // AP = [ 1.0, 2.0, 5.0 ] (2x2 symmetric packed column-major upper)
* var AP = new Float64Array( [ 1.0, 2.0, 5.0 ] );
*
* var norm = dlansp( 'column-major', 'M', 'upper', 2, AP, 1, 0 );
* // returns 5.0
*/
function dlansp( order, norm, uplo, N, AP, strideAP, offsetAP ) {
var anorm;
var scale;
var sumsq;
var ratio;
var absa;
var work;
var temp;
var out;
var sum;
var P;
var i;
var j;
var k;
if ( N <= 0 ) {
return 0.0;
}
if ( norm === 'M' || norm === 'm' ) {
// Find max(abs(A(i,j)))
P = N * ( N + 1 ) / 2;
anorm = 0.0;
for ( i = 0; i < P; i++ ) {
temp = abs( AP[ offsetAP + ( i * strideAP ) ] );
if ( anorm < temp || isnan( temp ) ) {
anorm = temp;
}
}
} else if ( norm === 'I' || norm === 'i' || norm === 'O' || norm === 'o' || norm === '1' ) {
// Find normI(A) ( = norm1(A), since A is symmetric)
if (
( isColumnMajor( order ) && uplo === 'upper' ) ||
( isRowMajor( order ) && uplo === 'lower' )
) {
work = new Float64Array( N );
k = 0;
for ( j = 0; j < N; j++ ) {
sum = 0.0;
for ( i = 0; i < j; i++ ) {
absa = abs( AP[ offsetAP + ( k * strideAP ) ] );
sum += absa;
work[ i ] += absa;
k += 1;
}
work[ j ] = sum + abs( AP[ offsetAP + ( k * strideAP ) ] );
k += 1;
}
anorm = 0.0;
for ( i = 0; i < N; i++ ) {
temp = work[ i ];
if ( anorm < temp || isnan( temp ) ) {
anorm = temp;
}
}
} else {
work = new Float64Array( N );
k = 0;
anorm = 0.0;
for ( j = 0; j < N; j++ ) {
sum = work[ j ] + abs( AP[ offsetAP + ( k * strideAP ) ] );
k += 1;
for ( i = j + 1; i < N; i++ ) {
absa = abs( AP[ offsetAP + ( k * strideAP ) ] );
sum += absa;
work[ i ] += absa;
k += 1;
}
if ( anorm < sum || isnan( sum ) ) {
anorm = sum;
}
}
}
} else if ( norm === 'F' || norm === 'f' || norm === 'E' || norm === 'e' ) {
// Find normF(A) = Frobenius norm
out = new Float64Array( 2 );
scale = 0.0;
sumsq = 1.0;
if (
( isColumnMajor( order ) && uplo === 'upper' ) ||
( isRowMajor( order ) && uplo === 'lower' )
) {
k = 0;
for ( j = 0; j < N; j++ ) {
if ( j > 0 ) {
dlassq( j, AP, strideAP, offsetAP + ( k * strideAP ), scale, sumsq, out, 1, 0 );
scale = out[ 0 ];
sumsq = out[ 1 ];
k += j;
}
k += 1;
}
} else {
k = 0;
for ( j = 0; j < N; j++ ) {
if ( j < N - 1 ) {
dlassq( N - j - 1, AP, strideAP, offsetAP + ( ( k + 1 ) * strideAP ), scale, sumsq, out, 1, 0 );
scale = out[ 0 ];
sumsq = out[ 1 ];
}
k += N - j;
}
}
sumsq *= 2.0;
// Add diagonal elements
if (
( isColumnMajor( order ) && uplo === 'upper' ) ||
( isRowMajor( order ) && uplo === 'lower' )
) {
k = 0;
for ( i = 0; i < N; i++ ) {
absa = abs( AP[ offsetAP + ( k * strideAP ) ] );
if ( absa !== 0.0 ) {
if ( scale < absa ) {
ratio = scale / absa;
sumsq = 1.0 + ( sumsq * ( ratio * ratio ) );
scale = absa;
} else {
ratio = absa / scale;
sumsq += ratio * ratio;
}
}
k += i + 2;
}
} else {
k = 0;
for ( i = 0; i < N; i++ ) {
absa = abs( AP[ offsetAP + ( k * strideAP ) ] );
if ( absa !== 0.0 ) {
if ( scale < absa ) {
ratio = scale / absa;
sumsq = 1.0 + ( sumsq * ( ratio * ratio ) );
scale = absa;
} else {
ratio = absa / scale;
sumsq += ratio * ratio;
}
}
k += N - i;
}
}
anorm = scale * sqrt( sumsq );
}
return anorm;
}
// EXPORTS //
module.exports = dlansp;
|