Skip to content

Commit 8248b4a

Browse files
committed
feat: add macro to convert a stride to an index offset
1 parent c3895df commit 8248b4a

File tree

2 files changed

+48
-0
lines changed
  • lib/node_modules/@stdlib/blas/base/shared/include/stdlib/blas/base

2 files changed

+48
-0
lines changed

lib/node_modules/@stdlib/blas/base/shared/include/stdlib/blas/base/shared.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,6 @@
2020
#define STDLIB_BLAS_BASE_SHARED_H
2121

2222
#include "shared/cblas.h"
23+
#include "shared/macros.h"
2324

2425
#endif // !STDLIB_BLAS_BASE_SHARED_H
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2023 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
#ifndef STDLIB_BLAS_BASE_SHARED_MACROS_H
20+
#define STDLIB_BLAS_BASE_SHARED_MACROS_H
21+
22+
/*
23+
* If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler.
24+
*/
25+
#ifdef __cplusplus
26+
extern "C" {
27+
#endif
28+
29+
/**
30+
* Macro for converting a stride to an index offset.
31+
*
32+
* @param N number of indexed elements
33+
* @param stride index increment
34+
*
35+
* @example
36+
* #include <stdint.h>
37+
*
38+
* int64_t offset = STDLIB_BLAS_BASE_STRIDE2OFFSET( 10, -10 );
39+
* // returns 90
40+
*/
41+
#define STDLIB_BLAS_BASE_STRIDE2OFFSET( N, stride ) ( ( (stride) > 0 ) ? 0 : ( 1-(N) ) * (stride) )
42+
43+
#ifdef __cplusplus
44+
}
45+
#endif
46+
47+
#endif // !STDLIB_BLAS_BASE_SHARED_MACROS_H

0 commit comments

Comments
 (0)