Skip to content

feat: add c implementation for blas/bae/sspmv #7141

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

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from
Draft
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
70 changes: 70 additions & 0 deletions lib/node_modules/@stdlib/blas/base/sspmv/src/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#/
# @license Apache-2.0
#
# 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.
# 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.
#/

# VARIABLES #

ifndef VERBOSE
QUIET := @
else
QUIET :=
endif

# Determine the OS ([1][1], [2][2]).
#
# [1]: https://en.wikipedia.org/wiki/Uname#Examples
# [2]: http://stackoverflow.com/a/27776822/2225624
OS ?= $(shell uname)
ifneq (, $(findstring MINGW,$(OS)))
OS := WINNT
else
ifneq (, $(findstring MSYS,$(OS)))
OS := WINNT
else
ifneq (, $(findstring CYGWIN,$(OS)))
OS := WINNT
else
ifneq (, $(findstring Windows_NT,$(OS)))
OS := WINNT
endif
endif
endif
endif


# RULES #

#/
# Removes generated files for building an add-on.
#
# @example
# make clean-addon
#/
clean-addon:
$(QUIET) -rm -f *.o *.node

.PHONY: clean-addon

#/
# Removes generated files.
#
# @example
# make clean
#/
clean: clean-addon

.PHONY: clean
105 changes: 105 additions & 0 deletions lib/node_modules/@stdlib/blas/base/sspmv/src/sspmv_ndarray.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2024 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/sspmv.h"
#include "stdlib/blas/base/shared.h"
#include "stdlib/blas/ext/base/sfill.h"
#include "stdlib/blas/base/sscal.h"

/**
* Performs the matrix-vector operation `Y = α*A*X + β*Y` where `α` and `β` are scalars, `X` and `Y` are `N` element vectors, and `A` is an `N` by `N` symmetric matrix supplied in packed form.
*
* @param order storage layout
* @param uplo specifies whether the upper or lower triangular part of the symmetric matrix `A` is supplied
* @param N number of elements along each dimension of `A`
* @param alpha scalar constant
* @param AP packed form of a symmetric matrix `A`
* @param strideAP `AP` stride length
* @param offsetAP starting index for `AP`
* @param X first input array
* @param strideX `X` stride length
* @param offsetX starting `X` index
* @param beta scalar constant
* @param Y second input array
* @param strideY `Y` stride length
* @param offsetY starting `Y` index
*/
void API_SUFFIX(c_sspmv_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, const float beta, float *Y, const CBLAS_INT strideY, const CBLAS_INT offsetY ) {
CBLAS_INT ix;
CBLAS_INT i;
CBLAS_INT m;

if ( beta != 1.0f ) {
if ( beta == 0.0f ) {
stdlib_strided_sfill_ndarray( N, beta, Y, strideY, offsetY );
} else {
c_sscal_ndarray( N, beta, Y, strideY, offsetY );
}
}
if ( alpha === 0.0f ) {
return;
}
kk = offsetAP;
ox = offsetX;
oy = offsetY;
if ( ( CblasColMajor && CblasUpper ) || ( CblasRowMajor && uplo === CblasLower ) ) {
ix1 = ox;
iy1 = oy;
for ( i1 = 0; i1 < N; i1++ ) {
tmp1 = alpha * X[ ix1 ];
tmp2 = 0.0f;
ix0 = ox;
iy0 = oy;
iap = kk;
for ( i0 = 0; i0 < i1; i0++ ) {
Y[ iy0 ] += tmp1 * AP[ iap ];
tmp2 += AP[ iap ] * X[ ix0 ];
ix0 += strideX;
iy0 += strideY;
iap += strideAP;
}
Y[ iy1 ] += ( tmp1 * AP[ iap ] ) + ( alpha * tmp2 );
ix1 += strideX;
iy1 += strideY;
kk += ( i1 + 1 ) * strideAP;
}
return;
}
ix1 = ox;
iy1 = oy;
for ( i1 = 0; i1 < N; i1++ ) {
tmp1 = alpha * X[ ix1 ];
tmp2 = 0.0f;
Y[ iy1 ] += tmp1 * AP[ kk ];
iap = kk;
ix0 = ix1;
iy0 = iy1;
for ( i0 = i1+1; i0 < N; i0++ ) {
ix0 += strideX;
iy0 += strideY;
iap += strideAP;
Y[ iy0 ] += tmp1 * AP[ iap ];
tmp2 += AP[ iap ] * X[ ix0 ];
}
Y[ iy1 ] += alpha * tmp2;
ix1 += strideX;
iy1 += strideY;
kk += ( N - i1 ) * strideAP;
}
return;
}
Loading