Skip to content

Commit

Permalink
Auto-generated commit
Browse files Browse the repository at this point in the history
  • Loading branch information
stdlib-bot committed Sep 12, 2024
1 parent b9c0c9d commit ec87c77
Show file tree
Hide file tree
Showing 13 changed files with 599 additions and 9 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<section class="release" id="unreleased">

## Unreleased (2024-09-09)
## Unreleased (2024-09-12)

<section class="packages">

Expand Down Expand Up @@ -145,6 +145,8 @@ A total of 3 people contributed to this release. Thank you to the following cont

<details>

- [`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)_
Expand Down
108 changes: 107 additions & 1 deletion base/max-view-buffer-index/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -122,6 +122,112 @@ for ( i = 0; i < 100; i++ ) {

<!-- /.examples -->

<!-- C interface documentation. -->

* * *

<section class="c">

## C APIs

<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->

<section class="intro">

</section>

<!-- /.intro -->

<!-- C usage documentation. -->

<section class="usage">

### 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 <stdint.h>

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 );
```

</section>

<!-- /.usage -->

<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->

<section class="notes">

</section>

<!-- /.notes -->

<!-- C API usage examples. -->

<section class="examples">

### Examples

```c
#include "stdlib/ndarray/base/max_view_buffer_index.h"
#include <stdint.h>
#include <stdio.h>
#include <inttypes.h>

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 );
}
```
</section>
<!-- /.examples -->
</section>
<!-- /.c -->
<!-- Section to include cited references. If references are included, add a horizontal rule *before* the section. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
<section class="references">
Expand Down
2 changes: 1 addition & 1 deletion base/max-view-buffer-index/benchmark/c/benchmark.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@
* limitations under the License.
*/

#include "stdlib/ndarray/base/max_view_buffer_index.h"
#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
#include <math.h>
#include <time.h>
#include <sys/time.h>
#include "stdlib/ndarray/base/max_view_buffer_index.h"

#define NAME "max-view-buffer-index"
#define ITERATIONS 1000000
Expand Down
146 changes: 146 additions & 0 deletions base/max-view-buffer-index/examples/c/Makefile
Original file line number Diff line number Diff line change
@@ -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
42 changes: 42 additions & 0 deletions base/max-view-buffer-index/examples/c/example.c
Original file line number Diff line number Diff line change
@@ -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 <stdint.h>
#include <stdio.h>
#include <inttypes.h>

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 );
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion base/max-view-buffer-index/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Loading

0 comments on commit ec87c77

Please sign in to comment.