From ec87c77aef3fb1d43ded3f69c62a3ae753e3db14 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 12 Sep 2024 05:35:04 +0000 Subject: [PATCH] Auto-generated commit --- CHANGELOG.md | 4 +- base/max-view-buffer-index/README.md | 108 ++++++++++++- .../benchmark/c/benchmark.c | 2 +- .../max-view-buffer-index/examples/c/Makefile | 146 ++++++++++++++++++ .../examples/c/example.c | 42 +++++ .../ndarray/base/max_view_buffer_index.h | 2 +- base/max-view-buffer-index/src/main.c | 2 +- base/min-view-buffer-index/README.md | 108 ++++++++++++- .../benchmark/c/benchmark.c | 2 +- .../min-view-buffer-index/examples/c/Makefile | 146 ++++++++++++++++++ .../examples/c/example.c | 42 +++++ .../ndarray/base/min_view_buffer_index.h | 2 +- base/min-view-buffer-index/src/main.c | 2 +- 13 files changed, 599 insertions(+), 9 deletions(-) create mode 100644 base/max-view-buffer-index/examples/c/Makefile create mode 100644 base/max-view-buffer-index/examples/c/example.c create mode 100644 base/min-view-buffer-index/examples/c/Makefile create mode 100644 base/min-view-buffer-index/examples/c/example.c diff --git a/CHANGELOG.md b/CHANGELOG.md index 9d09f7c0..c9d0bb6a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@
-## Unreleased (2024-09-09) +## Unreleased (2024-09-12)
@@ -145,6 +145,8 @@ A total of 3 people contributed to this release. Thank you to the following cont
+- [`037a7a8`](https://github.com/stdlib-js/stdlib/commit/037a7a81819bbbf2c0d784678b42d423f47d62ce) - **refactor:** use `const` qualifier and update examples _(by Athan Reines)_ +- [`00651e7`](https://github.com/stdlib-js/stdlib/commit/00651e7847283dadfb29ef6c90addd78380a3c5b) - **refactor:** use `const` qualifier and update examples _(by Athan Reines)_ - [`114f651`](https://github.com/stdlib-js/stdlib/commit/114f651d1f29cc711adf2990a10d56470650af48) - **refactor:** use base array assertion utility _(by Athan Reines)_ - [`98e4809`](https://github.com/stdlib-js/stdlib/commit/98e480997058c3f21d3016b97d25f4c4e62231b9) - **feat:** add `isBooleanDataType` to namespace _(by Athan Reines)_ - [`3e7f2ca`](https://github.com/stdlib-js/stdlib/commit/3e7f2ca3c987040575b732129281c384c453e0b8) - **feat:** add `hasEqualShape` to namespace _(by Athan Reines)_ diff --git a/base/max-view-buffer-index/README.md b/base/max-view-buffer-index/README.md index d252e0a0..4156a1a5 100644 --- a/base/max-view-buffer-index/README.md +++ b/base/max-view-buffer-index/README.md @@ -18,7 +18,7 @@ limitations under the License. --> -# Max View Buffer Index +# maxViewBufferIndex > Compute the maximum linear index in an underlying data buffer accessible to an array view. @@ -122,6 +122,112 @@ for ( i = 0; i < 100; i++ ) { + + +* * * + +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +#include "stdlib/ndarray/base/max_view_buffer_index.h" +``` + +#### stdlib_ndarray_max_view_buffer_index( ndims, \*shape, \*strides, offset ) + +Computes the maximum linear index (in bytes) in an underlying data buffer accessible to an array view. + +```c +#include + +int64_t ndims = 2; +int64_t shape[] = { 10, 10 }; +int64_t strides[] = { 10, 1 }; +int64_t offset = 0; + +int64_t idx = stdlib_ndarray_max_view_buffer_index( ndims, shape, strides, offset ); +// returns 99 +``` + +The function accepts the following arguments: + +- **ndims**: `[in] int64_t` number of dimensions. +- **shape**: `[in] int64_t*` array shape (dimensions). +- **strides**: `[in] int64_t*` array strides (in bytes). +- **offset**: `[in] int64_t` index offset. + +```c +int64_t stdlib_ndarray_max_view_buffer_index( const int64_t ndims, const int64_t *shape, const int64_t *strides, const int64_t offset ); +``` + +
+ + + + + +
+ +
+ + + + + +
+ +### Examples + +```c +#include "stdlib/ndarray/base/max_view_buffer_index.h" +#include +#include +#include + +int main( void ) { + // Specify the number of dimensions: + const int64_t ndims = 2; + + // Define an array shape: + const int64_t shape[] = { 10, 10 }; + + // Define array strides: + const int64_t strides[] = { -2, 5 }; + + // Define an offset: + const int64_t offset = 100; + + // Compute the maximum accessible index: + int64_t idx = stdlib_ndarray_max_view_buffer_index( ndims, shape, strides, offset ); + + // Print the results: + printf( "idx: %"PRId64"\n", idx ); +} +``` + +
+ + + +
+ + +
diff --git a/base/max-view-buffer-index/benchmark/c/benchmark.c b/base/max-view-buffer-index/benchmark/c/benchmark.c index 077163b2..04ac010e 100644 --- a/base/max-view-buffer-index/benchmark/c/benchmark.c +++ b/base/max-view-buffer-index/benchmark/c/benchmark.c @@ -16,13 +16,13 @@ * limitations under the License. */ +#include "stdlib/ndarray/base/max_view_buffer_index.h" #include #include #include #include #include #include -#include "stdlib/ndarray/base/max_view_buffer_index.h" #define NAME "max-view-buffer-index" #define ITERATIONS 1000000 diff --git a/base/max-view-buffer-index/examples/c/Makefile b/base/max-view-buffer-index/examples/c/Makefile new file mode 100644 index 00000000..6aed70da --- /dev/null +++ b/base/max-view-buffer-index/examples/c/Makefile @@ -0,0 +1,146 @@ +#/ +# @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. +#/ + +# 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 + +# Define the program used for compiling C source files: +ifdef C_COMPILER + CC := $(C_COMPILER) +else + CC := gcc +endif + +# Define the command-line options when compiling C files: +CFLAGS ?= \ + -std=c99 \ + -O3 \ + -Wall \ + -pedantic + +# Determine whether to generate position independent code ([1][1], [2][2]). +# +# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options +# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option +ifeq ($(OS), WINNT) + fPIC ?= +else + fPIC ?= -fPIC +endif + +# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): +INCLUDE ?= + +# List of source files: +SOURCE_FILES ?= + +# List of libraries (e.g., `-lopenblas -lpthread`): +LIBRARIES ?= + +# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): +LIBPATH ?= + +# List of C targets: +c_targets := example.out + + +# RULES # + +#/ +# Compiles source files. +# +# @param {string} [C_COMPILER] - C compiler (e.g., `gcc`) +# @param {string} [CFLAGS] - C compiler options +# @param {(string|void)} [fPIC] - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) +# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop/include`) +# @param {string} [SOURCE_FILES] - list of source files +# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) +# @param {string} [LIBRARIES] - list of libraries (e.g., `-lopenblas -lpthread`) +# +# @example +# make +# +# @example +# make all +#/ +all: $(c_targets) + +.PHONY: all + +#/ +# Compiles C source files. +# +# @private +# @param {string} CC - C compiler (e.g., `gcc`) +# @param {string} CFLAGS - C compiler options +# @param {(string|void)} fPIC - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) +# @param {string} INCLUDE - list of includes (e.g., `-I /foo/bar`) +# @param {string} SOURCE_FILES - list of source files +# @param {string} LIBPATH - list of library paths (e.g., `-L /foo/bar`) +# @param {string} LIBRARIES - list of libraries (e.g., `-lopenblas`) +#/ +$(c_targets): %.out: %.c + $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) + +#/ +# Runs compiled examples. +# +# @example +# make run +#/ +run: $(c_targets) + $(QUIET) ./$< + +.PHONY: run + +#/ +# Removes generated files. +# +# @example +# make clean +#/ +clean: + $(QUIET) -rm -f *.o *.out + +.PHONY: clean diff --git a/base/max-view-buffer-index/examples/c/example.c b/base/max-view-buffer-index/examples/c/example.c new file mode 100644 index 00000000..ee081f0d --- /dev/null +++ b/base/max-view-buffer-index/examples/c/example.c @@ -0,0 +1,42 @@ +/** +* @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/ndarray/base/max_view_buffer_index.h" +#include +#include +#include + +int main( void ) { + // Specify the number of dimensions: + const int64_t ndims = 2; + + // Define an array shape: + const int64_t shape[] = { 10, 10 }; + + // Define array strides: + const int64_t strides[] = { -2, 5 }; + + // Define an offset: + const int64_t offset = 100; + + // Compute the maximum accessible index: + int64_t idx = stdlib_ndarray_max_view_buffer_index( ndims, shape, strides, offset ); + + // Print the results: + printf( "idx: %"PRId64"\n", idx ); +} diff --git a/base/max-view-buffer-index/include/stdlib/ndarray/base/max_view_buffer_index.h b/base/max-view-buffer-index/include/stdlib/ndarray/base/max_view_buffer_index.h index b7de4a6b..6a35bfec 100644 --- a/base/max-view-buffer-index/include/stdlib/ndarray/base/max_view_buffer_index.h +++ b/base/max-view-buffer-index/include/stdlib/ndarray/base/max_view_buffer_index.h @@ -31,7 +31,7 @@ extern "C" { /** * Computes the maximum linear index (in bytes) in an underlying data buffer accessible to an array view. */ -int64_t stdlib_ndarray_max_view_buffer_index( int64_t ndims, int64_t *shape, int64_t *strides, int64_t offset ); +int64_t stdlib_ndarray_max_view_buffer_index( const int64_t ndims, const int64_t *shape, const int64_t *strides, const int64_t offset ); #ifdef __cplusplus } diff --git a/base/max-view-buffer-index/src/main.c b/base/max-view-buffer-index/src/main.c index 30447423..c63eb0fc 100644 --- a/base/max-view-buffer-index/src/main.c +++ b/base/max-view-buffer-index/src/main.c @@ -40,7 +40,7 @@ * int64_t idx = stdlib_ndarray_max_view_buffer_index( ndims, shape, strides, offset ); * // returns 99 */ -int64_t stdlib_ndarray_max_view_buffer_index( int64_t ndims, int64_t *shape, int64_t *strides, int64_t offset ) { +int64_t stdlib_ndarray_max_view_buffer_index( const int64_t ndims, const int64_t *shape, const int64_t *strides, const int64_t offset ) { int64_t idx; int64_t i; diff --git a/base/min-view-buffer-index/README.md b/base/min-view-buffer-index/README.md index a8ff0591..7cba91cc 100644 --- a/base/min-view-buffer-index/README.md +++ b/base/min-view-buffer-index/README.md @@ -18,7 +18,7 @@ limitations under the License. --> -# Min View Buffer Index +# minViewBufferIndex > Compute the minimum linear index in an underlying data buffer accessible to an array view. @@ -122,6 +122,112 @@ for ( i = 0; i < 100; i++ ) { + + +* * * + +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +#include "stdlib/ndarray/base/min_view_buffer_index.h" +``` + +#### stdlib_ndarray_min_view_buffer_index( ndims, \*shape, \*strides, offset ) + +Computes the minimum linear index (in bytes) in an underlying data buffer accessible to an array view. + +```c +#include + +int64_t ndims = 2; +int64_t shape[] = { 10, 10 }; +int64_t strides[] = { 10, 1 }; +int64_t offset = 10; + +int64_t idx = stdlib_ndarray_min_view_buffer_index( ndims, shape, strides, offset ); +// returns 10 +``` + +The function accepts the following arguments: + +- **ndims**: `[in] int64_t` number of dimensions. +- **shape**: `[in] int64_t*` array shape (dimensions). +- **strides**: `[in] int64_t*` array strides (in bytes). +- **offset**: `[in] int64_t` index offset. + +```c +int64_t stdlib_ndarray_min_view_buffer_index( const int64_t ndims, const int64_t *shape, const int64_t *strides, const int64_t offset ); +``` + +
+ + + + + +
+ +
+ + + + + +
+ +### Examples + +```c +#include "stdlib/ndarray/base/min_view_buffer_index.h" +#include +#include +#include + +int main( void ) { + // Specify the number of dimensions: + const int64_t ndims = 2; + + // Define an array shape: + const int64_t shape[] = { 10, 10 }; + + // Define array strides: + const int64_t strides[] = { -2, 5 }; + + // Define an offset: + const int64_t offset = 100; + + // Compute the minimum accessible index: + int64_t idx = stdlib_ndarray_min_view_buffer_index( ndims, shape, strides, offset ); + + // Print the results: + printf( "idx: %"PRId64"\n", idx ); +} +``` + +
+ + + +
+ + +
diff --git a/base/min-view-buffer-index/benchmark/c/benchmark.c b/base/min-view-buffer-index/benchmark/c/benchmark.c index 60fcd17d..c4bd8651 100644 --- a/base/min-view-buffer-index/benchmark/c/benchmark.c +++ b/base/min-view-buffer-index/benchmark/c/benchmark.c @@ -16,13 +16,13 @@ * limitations under the License. */ +#include "stdlib/ndarray/base/min_view_buffer_index.h" #include #include #include #include #include #include -#include "stdlib/ndarray/base/min_view_buffer_index.h" #define NAME "min-view-buffer-index" #define ITERATIONS 1000000 diff --git a/base/min-view-buffer-index/examples/c/Makefile b/base/min-view-buffer-index/examples/c/Makefile new file mode 100644 index 00000000..6aed70da --- /dev/null +++ b/base/min-view-buffer-index/examples/c/Makefile @@ -0,0 +1,146 @@ +#/ +# @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. +#/ + +# 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 + +# Define the program used for compiling C source files: +ifdef C_COMPILER + CC := $(C_COMPILER) +else + CC := gcc +endif + +# Define the command-line options when compiling C files: +CFLAGS ?= \ + -std=c99 \ + -O3 \ + -Wall \ + -pedantic + +# Determine whether to generate position independent code ([1][1], [2][2]). +# +# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options +# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option +ifeq ($(OS), WINNT) + fPIC ?= +else + fPIC ?= -fPIC +endif + +# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): +INCLUDE ?= + +# List of source files: +SOURCE_FILES ?= + +# List of libraries (e.g., `-lopenblas -lpthread`): +LIBRARIES ?= + +# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): +LIBPATH ?= + +# List of C targets: +c_targets := example.out + + +# RULES # + +#/ +# Compiles source files. +# +# @param {string} [C_COMPILER] - C compiler (e.g., `gcc`) +# @param {string} [CFLAGS] - C compiler options +# @param {(string|void)} [fPIC] - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) +# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop/include`) +# @param {string} [SOURCE_FILES] - list of source files +# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) +# @param {string} [LIBRARIES] - list of libraries (e.g., `-lopenblas -lpthread`) +# +# @example +# make +# +# @example +# make all +#/ +all: $(c_targets) + +.PHONY: all + +#/ +# Compiles C source files. +# +# @private +# @param {string} CC - C compiler (e.g., `gcc`) +# @param {string} CFLAGS - C compiler options +# @param {(string|void)} fPIC - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) +# @param {string} INCLUDE - list of includes (e.g., `-I /foo/bar`) +# @param {string} SOURCE_FILES - list of source files +# @param {string} LIBPATH - list of library paths (e.g., `-L /foo/bar`) +# @param {string} LIBRARIES - list of libraries (e.g., `-lopenblas`) +#/ +$(c_targets): %.out: %.c + $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) + +#/ +# Runs compiled examples. +# +# @example +# make run +#/ +run: $(c_targets) + $(QUIET) ./$< + +.PHONY: run + +#/ +# Removes generated files. +# +# @example +# make clean +#/ +clean: + $(QUIET) -rm -f *.o *.out + +.PHONY: clean diff --git a/base/min-view-buffer-index/examples/c/example.c b/base/min-view-buffer-index/examples/c/example.c new file mode 100644 index 00000000..906227a6 --- /dev/null +++ b/base/min-view-buffer-index/examples/c/example.c @@ -0,0 +1,42 @@ +/** +* @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/ndarray/base/min_view_buffer_index.h" +#include +#include +#include + +int main( void ) { + // Specify the number of dimensions: + const int64_t ndims = 2; + + // Define an array shape: + const int64_t shape[] = { 10, 10 }; + + // Define array strides: + const int64_t strides[] = { -2, 5 }; + + // Define an offset: + const int64_t offset = 100; + + // Compute the minimum accessible index: + int64_t idx = stdlib_ndarray_min_view_buffer_index( ndims, shape, strides, offset ); + + // Print the results: + printf( "idx: %"PRId64"\n", idx ); +} diff --git a/base/min-view-buffer-index/include/stdlib/ndarray/base/min_view_buffer_index.h b/base/min-view-buffer-index/include/stdlib/ndarray/base/min_view_buffer_index.h index 0f89b5aa..7f8857b7 100644 --- a/base/min-view-buffer-index/include/stdlib/ndarray/base/min_view_buffer_index.h +++ b/base/min-view-buffer-index/include/stdlib/ndarray/base/min_view_buffer_index.h @@ -31,7 +31,7 @@ extern "C" { /** * Computes the minimum linear index (in bytes) in an underlying data buffer accessible to an array view. */ -int64_t stdlib_ndarray_min_view_buffer_index( int64_t ndims, int64_t *shape, int64_t *strides, int64_t offset ); +int64_t stdlib_ndarray_min_view_buffer_index( const int64_t ndims, const int64_t *shape, const int64_t *strides, const int64_t offset ); #ifdef __cplusplus } diff --git a/base/min-view-buffer-index/src/main.c b/base/min-view-buffer-index/src/main.c index 003b8a25..50507cdd 100644 --- a/base/min-view-buffer-index/src/main.c +++ b/base/min-view-buffer-index/src/main.c @@ -40,7 +40,7 @@ * int64_t idx = stdlib_ndarray_min_view_buffer_index( ndims, shape, strides, offset ); * // returns 10 */ -int64_t stdlib_ndarray_min_view_buffer_index( int64_t ndims, int64_t *shape, int64_t *strides, int64_t offset ) { +int64_t stdlib_ndarray_min_view_buffer_index( const int64_t ndims, const int64_t *shape, const int64_t *strides, const int64_t offset ) { int64_t idx; int64_t i;