Skip to content

refactor: c ndarray implementation of blas/base/sspr #6949

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/node_modules/@stdlib/blas/base/sspr/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ Performs the symmetric rank 1 operation `A = α*x*x^T + A` where `α` is a scala
float AP[] = { 1.0f, 2.0f, 3.0f, 1.0f, 2.0f, 1.0f };
const float x[] = { 1.0f, 2.0f, 3.0f };

c_sspr( CblasColMajor, CblasUpper, 3, 1.0f, x, 1, AP );
c_sspr( CblasRowMajor, CblasUpper, 3, 1.0f, x, 1, AP );
```

The function accepts the following arguments:
Expand All @@ -223,13 +223,13 @@ Performs the symmetric rank 1 operation `A = α*x*x^T + A` where `α` is a scala
float AP[] = { 1.0f, 2.0f, 3.0f, 1.0f, 2.0f, 1.0f };
const float x[] = { 1.0f, 2.0f, 3.0f };

c_sspr_ndarray( CblasColMajor, CblasUpper, 3, 1.0f, x, 1, AP, 1, 0 );
c_sspr_ndarray( CblasRowMajor, CblasUpper, 3, 1.0f, x, 1, AP, 1, 0 );
```

The function accepts the following arguments:

- **order**: `[in] CBLAS_LAYOUT` storage layout.
- **uplo**: `[in] CBLAS_UPLO` specifies whether the upper or lower triangular part of the symmetric matrix `A` should be referenced.
- **uplo**: `[in] CBLAS_UPLO` specifies whether the upper or lower triangular part of the symmetric matrix `A` is supplied.
- **N**: `[in] CBLAS_INT` number of elements along each dimension of `A`.
- **alpha**: `[in] float` scalar.
- **X**: `[in] float*` input vector.
Expand Down
12 changes: 8 additions & 4 deletions lib/node_modules/@stdlib/blas/base/sspr/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,8 @@
"blas": "",
"wasm": false,
"src": [
"./src/sspr.c"
"./src/sspr.c",
"./src/sspr_ndarray.c"
],
"include": [
"./include"
Expand All @@ -256,7 +257,8 @@
"blas": "",
"wasm": false,
"src": [
"./src/sspr.c"
"./src/sspr.c",
"./src/sspr_ndarray.c"
],
"include": [
"./include"
Expand All @@ -276,7 +278,8 @@
"blas": "",
"wasm": false,
"src": [
"./src/sspr.c"
"./src/sspr.c",
"./src/sspr_ndarray.c"
],
"include": [
"./include"
Expand All @@ -295,7 +298,8 @@
"blas": "",
"wasm": true,
"src": [
"./src/sspr.c"
"./src/sspr.c",
"./src/sspr_ndarray.c"
],
"include": [
"./include"
Expand Down
2 changes: 1 addition & 1 deletion lib/node_modules/@stdlib/blas/base/sspr/src/Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#/
# @license Apache-2.0
#
# Copyright (c) 2025 The Stdlib Authors.
# Copyright (c) 2020 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.
Expand Down
69 changes: 1 addition & 68 deletions lib/node_modules/@stdlib/blas/base/sspr/src/sspr.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,75 +32,8 @@
* @param AP packed form of a symmetric matrix `A`
*/
void API_SUFFIX(c_sspr)( const CBLAS_LAYOUT order, const CBLAS_UPLO uplo, const CBLAS_INT N, const float alpha, const float *X, const CBLAS_INT strideX, float *AP ) {
const CBLAS_INT ox = STDLIB_BLAS_BASE_STRIDE2OFFSET( N, strideX );
const CBLAS_INT ox = stdlib_strided_stride2offset( N, strideX );
API_SUFFIX(c_sspr_ndarray)( order, uplo, N, alpha, X, strideX, ox, AP, 1, 0 );
return;
}

/**
* Performs the symmetric rank 1 operation `A = α*x*x^T + A` where `α` is a scalar, `x` is an `N` element vector, and `A` is an `N` by `N` symmetric matrix supplied in packed form using alternative indexing semantics.
*
* @param uplo specifies whether the upper or lower triangular part of the symmetric matrix `A` should be referenced
* @param N number of elements along each dimension of `A`
* @param alpha scalar
* @param X input vector
* @param strideX `X` stride length
* @param offsetX starting index of `x`
* @param AP packed form of a symmetric matrix `A`
* @param strideAP stride of the first dimension of `AP`
* @param offsetAP starting index of `AP`
*/
void API_SUFFIX(c_sspr_ndarray)( const CBLAS_LAYOUT order, const CBLAS_UPLO uplo, const CBLAS_INT N, const float alpha, const float *X, const CBLAS_INT strideX, const CBLAS_INT offsetX, float *AP, const CBLAS_INT strideAP, const CBLAS_INT offsetAP ) {
CBLAS_INT iap;
CBLAS_INT ix0;
CBLAS_INT ix1;
CBLAS_INT i0;
CBLAS_INT i1;
CBLAS_INT kk;
CBLAS_INT ox;
float tmp;

if ( N == 0 || alpha == 0.0f ) {
return;
}
ox = offsetX;
kk = offsetAP;
if (
( order == CblasRowMajor && uplo == CblasLower ) ||
( order == CblasColMajor && uplo == CblasUpper )
) {
ix1 = ox;
for ( i1 = 0; i1 < N; i1++ ) {
if ( X[ ix1 ] != 0.0f ) {
tmp = alpha * X[ ix1 ];
ix0 = ox;
iap = kk;
for ( i0 = 0; i0 <= i1; i0++ ) {
AP[ iap ] += X[ ix0 ] * tmp;
ix0 += strideX;
iap += strideAP;
}
}
ix1 += strideX;
kk += ( i1 + 1 ) * strideAP;
}
return;
}
// ( order == CblasColMajor && uplo == CblasLower ) || ( order == CblasRowMajor && uplo == CblasUpper )
ix1 = ox;
for ( i1 = 0; i1 < N; i1++ ) {
if ( X[ ix1 ] != 0.0f ) {
tmp = alpha * X[ ix1 ];
ix0 = ix1;
iap = kk;
for ( i0 = 0; i0 < N - i1; i0++ ) {
AP[ iap ] += X[ ix0 ] * tmp;
ix0 += strideX;
iap += strideAP;
}
}
ix1 += strideX;
kk += ( N - i1 ) * strideAP;
}
return;
}
30 changes: 29 additions & 1 deletion lib/node_modules/@stdlib/blas/base/sspr/src/sspr_cblas.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,33 @@
* @param AP packed form of a symmetric matrix `A`
*/
void API_SUFFIX(c_sspr)( const CBLAS_LAYOUT order, const CBLAS_UPLO uplo, const CBLAS_INT N, const float alpha, const float *X, const CBLAS_INT strideX, float *AP ) {
API_SUFFIX(cblas_sspr)( order, uplo, N, alpha, X, strideX, AP );
CBLAS_INT sx = strideX;
if ( sx < 0 ) {
sx = -sx;
}
API_SUFFIX(cblas_sspr)( order, uplo, N, alpha, X, sx, AP );
}

/**
* Performs the symmetric rank 1 operation `A = α*x*x^T + A` where `α` is a scalar, `x` is an `N` element vector, and `A` is an `N` by `N` symmetric matrix supplied in packed form using alternative indexing semantics.
*
* @param order storage layout
* @param uplo specifies whether the upper or lower triangular part of the symmetric matrix `A` should be referenced
* @param N number of elements along each dimension of `A`
* @param alpha scalar
* @param X input vector
* @param strideX `x` stride length
* @param offsetX starting index for `x`
* @param AP packed form of a symmetric matrix `A`
* @param strideAP `AP` stride length
* @param offsetAP starting index for `AP`
*/
void API_SUFFIX(c_sspr_ndarray)( const CBLAS_LAYOUT order, const CBLAS_UPLO uplo, const CBLAS_INT N, const float alpha, const float *X, const CBLAS_INT strideX, const CBLAS_INT offsetX, float *AP, const CBLAS_INT strideAP, const CBLAS_INT offsetAP ) {
CBLAS_INT sx = strideX;
X += stdlib_strided_min_view_buffer_index( N, strideX, offsetX ); // adjust array pointer
AP += stdlib_strided_min_view_buffer_index( N, strideAP, offsetAP ); // adjust array pointer
if ( sx < 0 ) {
sx = -sx;
}
API_SUFFIX(cblas_sspr)( order, uplo, N, alpha, X, sx, AP );
}
88 changes: 88 additions & 0 deletions lib/node_modules/@stdlib/blas/base/sspr/src/sspr_ndarray.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/**
* @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.
*/

#include "stdlib/blas/base/sspr.h"
#include "stdlib/blas/base/shared.h"

/**
* Performs the symmetric rank 1 operation `A = α*x*x^T + A` where `α` is a scalar, `x` is an `N` element vector, and `A` is an `N` by `N` symmetric matrix supplied in packed form using alternative indexing semantics.
*
* @param uplo specifies whether the upper or lower triangular part of the symmetric matrix `A` should be referenced
* @param N number of elements along each dimension of `A`
* @param alpha scalar
* @param X input vector
* @param strideX `X` stride length
* @param offsetX starting index of `x`
* @param AP packed form of a symmetric matrix `A`
* @param strideAP stride of the first dimension of `AP`
* @param offsetAP starting index of `AP`
*/
void API_SUFFIX(c_sspr_ndarray)( const CBLAS_LAYOUT order, const CBLAS_UPLO uplo, const CBLAS_INT N, const float alpha, const float *X, const CBLAS_INT strideX, const CBLAS_INT offsetX, float *AP, const CBLAS_INT strideAP, const CBLAS_INT offsetAP ) {
CBLAS_INT iap;
CBLAS_INT ix0;
CBLAS_INT ix1;
CBLAS_INT i0;
CBLAS_INT i1;
CBLAS_INT kk;
CBLAS_INT ox;
float tmp;

if ( N == 0 || alpha == 0.0f ) {
return;
}
ox = offsetX;
kk = offsetAP;
if (
( order == CblasRowMajor && uplo == CblasLower ) ||
( order == CblasColMajor && uplo == CblasUpper )
) {
ix1 = ox;
for ( i1 = 0; i1 < N; i1++ ) {
if ( X[ ix1 ] != 0.0f ) {
tmp = alpha * X[ ix1 ];
ix0 = ox;
iap = kk;
for ( i0 = 0; i0 <= i1; i0++ ) {
AP[ iap ] += X[ ix0 ] * tmp;
ix0 += strideX;
iap += strideAP;
}
}
ix1 += strideX;
kk += ( i1 + 1 ) * strideAP;
}
return;
}
// ( order == CblasColMajor && uplo == CblasLower ) || ( order == CblasRowMajor && uplo == CblasUpper )
ix1 = ox;
for ( i1 = 0; i1 < N; i1++ ) {
if ( X[ ix1 ] != 0.0f ) {
tmp = alpha * X[ ix1 ];
ix0 = ix1;
iap = kk;
for ( i0 = 0; i0 < N - i1; i0++ ) {
AP[ iap ] += X[ ix0 ] * tmp;
ix0 += strideX;
iap += strideAP;
}
}
ix1 += strideX;
kk += ( N - i1 ) * strideAP;
}
return;
}