From 79797359f151c46f211f9c832403b0a97350e643 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Jul 2024 06:29:50 +0000 Subject: [PATCH] Auto-generated commit --- CHANGELOG.md | 3 ++ base/dcopy/src/dcopy.c | 12 +---- base/shared/include/stdlib/blas/base/shared.h | 1 + .../include/stdlib/blas/base/shared/macros.h | 47 +++++++++++++++++++ 4 files changed, 53 insertions(+), 10 deletions(-) create mode 100644 base/shared/include/stdlib/blas/base/shared/macros.h diff --git a/CHANGELOG.md b/CHANGELOG.md index 770419064..b3d6c1d0b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1033,6 +1033,7 @@ This release closes the following issue: ##### Features +- [`8248b4a`](https://github.com/stdlib-js/stdlib/commit/8248b4a4c72d7a981a72075583561b98646c8068) - add macro to convert a stride to an index offset - [`123f7f9`](https://github.com/stdlib-js/stdlib/commit/123f7f945a9154c7518c6c0837110e0712811b5f) - add `blas/base/diagonal-types` - [`9174c02`](https://github.com/stdlib-js/stdlib/commit/9174c02e42ca651f8959fff0626ae8147a75ee09) - add `blas/base/shared` @@ -2143,6 +2144,8 @@ A total of 35 people contributed to this release. Thank you to the following con
+- [`5418177`](https://github.com/stdlib-js/stdlib/commit/5418177d92f26a6d99bd53d19713f2fa0d536b27) - **refactor:** use macro to convert stride to offset _(by Athan Reines)_ +- [`8248b4a`](https://github.com/stdlib-js/stdlib/commit/8248b4a4c72d7a981a72075583561b98646c8068) - **feat:** add macro to convert a stride to an index offset _(by Athan Reines)_ - [`c3895df`](https://github.com/stdlib-js/stdlib/commit/c3895df672126473f5803e93b529bcdd0775c75a) - **refactor:** use utility to resolve an index offset _(by Athan Reines)_ - [`1654659`](https://github.com/stdlib-js/stdlib/commit/1654659445a6dee281706379770c9cb0498c36c7) - **refactor:** update implementation to reduce code duplication [(#2480)](https://github.com/stdlib-js/stdlib/pull/2480) _(by Aman Bhansali, Athan Reines)_ - [`4d08374`](https://github.com/stdlib-js/stdlib/commit/4d0837401b68ebd4e5b8c38e0214158dbe410a07) - **refactor:** reduce code duplication [(#2479)](https://github.com/stdlib-js/stdlib/pull/2479) _(by Aman Bhansali, Athan Reines)_ diff --git a/base/dcopy/src/dcopy.c b/base/dcopy/src/dcopy.c index e784b10f3..5ab63d324 100644 --- a/base/dcopy/src/dcopy.c +++ b/base/dcopy/src/dcopy.c @@ -61,16 +61,8 @@ void API_SUFFIX(c_dcopy)( const CBLAS_INT N, const double *X, const CBLAS_INT st } return; } - if ( strideX < 0 ) { - ix = (1-N) * strideX; - } else { - ix = 0; - } - if ( strideY < 0 ) { - iy = (1-N) * strideY; - } else { - iy = 0; - } + ix = STDLIB_BLAS_BASE_STRIDE2OFFSET( N, strideX ); + iy = STDLIB_BLAS_BASE_STRIDE2OFFSET( N, strideY ); for ( i = 0; i < N; i++ ) { Y[ iy ] = X[ ix ]; ix += strideX; diff --git a/base/shared/include/stdlib/blas/base/shared.h b/base/shared/include/stdlib/blas/base/shared.h index 13312f9a1..eeed3795a 100644 --- a/base/shared/include/stdlib/blas/base/shared.h +++ b/base/shared/include/stdlib/blas/base/shared.h @@ -20,5 +20,6 @@ #define STDLIB_BLAS_BASE_SHARED_H #include "shared/cblas.h" +#include "shared/macros.h" #endif // !STDLIB_BLAS_BASE_SHARED_H diff --git a/base/shared/include/stdlib/blas/base/shared/macros.h b/base/shared/include/stdlib/blas/base/shared/macros.h new file mode 100644 index 000000000..1dee25d5a --- /dev/null +++ b/base/shared/include/stdlib/blas/base/shared/macros.h @@ -0,0 +1,47 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2023 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. +*/ + +#ifndef STDLIB_BLAS_BASE_SHARED_MACROS_H +#define STDLIB_BLAS_BASE_SHARED_MACROS_H + +/* +* If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler. +*/ +#ifdef __cplusplus +extern "C" { +#endif + +/** +* Macro for converting a stride to an index offset. +* +* @param N number of indexed elements +* @param stride index increment +* +* @example +* #include +* +* int64_t offset = STDLIB_BLAS_BASE_STRIDE2OFFSET( 10, -10 ); +* // returns 90 +*/ +#define STDLIB_BLAS_BASE_STRIDE2OFFSET( N, stride ) ( ( (stride) > 0 ) ? 0 : ( 1-(N) ) * (stride) ) + +#ifdef __cplusplus +} +#endif + +#endif // !STDLIB_BLAS_BASE_SHARED_MACROS_H