|
2 | 2 |
|
3 | 3 | @license Apache-2.0 |
4 | 4 |
|
5 | | -Copyright (c) 2025 The Stdlib Authors. |
| 5 | +Copyright (c) 2026 The Stdlib Authors. |
6 | 6 |
|
7 | 7 | Licensed under the Apache License, Version 2.0 (the "License"); |
8 | 8 | you may not use this file except in compliance with the License. |
@@ -95,6 +95,153 @@ console.log( v ); |
95 | 95 |
|
96 | 96 | <!-- /.examples --> |
97 | 97 |
|
| 98 | +<!-- C interface documentation. --> |
| 99 | + |
| 100 | +* * * |
| 101 | + |
| 102 | +<section class="c"> |
| 103 | + |
| 104 | +## C APIs |
| 105 | + |
| 106 | +<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. --> |
| 107 | + |
| 108 | +<section class="intro"> |
| 109 | + |
| 110 | +</section> |
| 111 | + |
| 112 | +<!-- /.intro --> |
| 113 | + |
| 114 | +<!-- C usage documentation. --> |
| 115 | + |
| 116 | +<section class="usage"> |
| 117 | + |
| 118 | +### Usage |
| 119 | + |
| 120 | +```c |
| 121 | +#include "stdlib/stats/base/ndarray/dmin.h" |
| 122 | +``` |
| 123 | + |
| 124 | +#### stdlib_stats_dmin( arrays ) |
| 125 | + |
| 126 | +Computes the minimum value of a one-dimensional double-precision floating-point ndarray. |
| 127 | + |
| 128 | +```c |
| 129 | +#include "stdlib/ndarray/ctor.h" |
| 130 | +#include "stdlib/ndarray/dtypes.h" |
| 131 | +#include "stdlib/ndarray/index_modes.h" |
| 132 | +#include "stdlib/ndarray/orders.h" |
| 133 | +#include "stdlib/ndarray/base/bytes_per_element.h" |
| 134 | +#include <stdint.h> |
| 135 | + |
| 136 | +// Create an ndarray: |
| 137 | +const double data[] = { 1.0, 2.0, 3.0, 4.0 }; |
| 138 | +int64_t shape[] = { 4 }; |
| 139 | +int64_t strides[] = { STDLIB_NDARRAY_FLOAT64_BYTES_PER_ELEMENT }; |
| 140 | +int8_t submodes[] = { STDLIB_NDARRAY_INDEX_ERROR }; |
| 141 | + |
| 142 | +struct ndarray *x = stdlib_ndarray_allocate( STDLIB_NDARRAY_FLOAT64, (uint8_t *)data, 1, shape, strides, 0, STDLIB_NDARRAY_ROW_MAJOR, STDLIB_NDARRAY_INDEX_ERROR, 1, submodes ); |
| 143 | + |
| 144 | +// Compute the minimum value: |
| 145 | +const struct ndarray *arrays[] = { x }; |
| 146 | +double v = stdlib_stats_dmin( arrays ); |
| 147 | +// returns 1.0 |
| 148 | + |
| 149 | +// Free allocated memory: |
| 150 | +stdlib_ndarray_free( x ); |
| 151 | +``` |
| 152 | +
|
| 153 | +The function accepts the following arguments: |
| 154 | +
|
| 155 | +- **arrays**: `[in] struct ndarray**` list containing a one-dimensional input ndarray. |
| 156 | +
|
| 157 | +```c |
| 158 | +double stdlib_stats_dmin( const struct ndarray *arrays[] ); |
| 159 | +``` |
| 160 | + |
| 161 | +</section> |
| 162 | + |
| 163 | +<!-- /.usage --> |
| 164 | + |
| 165 | +<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 166 | + |
| 167 | +<section class="notes"> |
| 168 | + |
| 169 | +</section> |
| 170 | + |
| 171 | +<!-- /.notes --> |
| 172 | + |
| 173 | +<!-- C API usage examples. --> |
| 174 | + |
| 175 | +<section class="examples"> |
| 176 | + |
| 177 | +### Examples |
| 178 | + |
| 179 | +```c |
| 180 | +#include "stdlib/stats/base/ndarray/dmin.h" |
| 181 | +#include "stdlib/ndarray/ctor.h" |
| 182 | +#include "stdlib/ndarray/dtypes.h" |
| 183 | +#include "stdlib/ndarray/index_modes.h" |
| 184 | +#include "stdlib/ndarray/orders.h" |
| 185 | +#include "stdlib/ndarray/base/bytes_per_element.h" |
| 186 | +#include <stdint.h> |
| 187 | +#include <stdlib.h> |
| 188 | +#include <stdio.h> |
| 189 | + |
| 190 | +int main( void ) { |
| 191 | + // Create a data buffer: |
| 192 | + const double data[] = { 1.0, -2.0, 3.0, -4.0, 5.0, -6.0, 7.0, -8.0 }; |
| 193 | + |
| 194 | + // Specify the number of array dimensions: |
| 195 | + const int64_t ndims = 1; |
| 196 | + |
| 197 | + // Specify the array shape: |
| 198 | + int64_t shape[] = { 4 }; |
| 199 | + |
| 200 | + // Specify the array strides: |
| 201 | + int64_t strides[] = { 2*STDLIB_NDARRAY_FLOAT64_BYTES_PER_ELEMENT }; |
| 202 | + |
| 203 | + // Specify the byte offset: |
| 204 | + const int64_t offset = 0; |
| 205 | + |
| 206 | + // Specify the array order: |
| 207 | + const enum STDLIB_NDARRAY_ORDER order = STDLIB_NDARRAY_ROW_MAJOR; |
| 208 | + |
| 209 | + // Specify the index mode: |
| 210 | + const enum STDLIB_NDARRAY_INDEX_MODE imode = STDLIB_NDARRAY_INDEX_ERROR; |
| 211 | + |
| 212 | + // Specify the subscript index modes: |
| 213 | + int8_t submodes[] = { STDLIB_NDARRAY_INDEX_ERROR }; |
| 214 | + const int64_t nsubmodes = 1; |
| 215 | + |
| 216 | + // Create an ndarray: |
| 217 | + struct ndarray *x = stdlib_ndarray_allocate( STDLIB_NDARRAY_FLOAT64, (uint8_t *)data, ndims, shape, strides, offset, order, imode, nsubmodes, submodes ); |
| 218 | + if ( x == NULL ) { |
| 219 | + fprintf( stderr, "Error allocating memory.\n" ); |
| 220 | + exit( 1 ); |
| 221 | + } |
| 222 | + |
| 223 | + // Define a list of ndarrays: |
| 224 | + const struct ndarray *arrays[] = { x }; |
| 225 | + |
| 226 | + // Compute the minimum value: |
| 227 | + double v = stdlib_stats_dmin( arrays ); |
| 228 | + |
| 229 | + // Print the result: |
| 230 | + printf( "min: %lf\n", v ); |
| 231 | + |
| 232 | + // Free allocated memory: |
| 233 | + stdlib_ndarray_free( x ); |
| 234 | +} |
| 235 | +``` |
| 236 | +
|
| 237 | +</section> |
| 238 | +
|
| 239 | +<!-- /.examples --> |
| 240 | +
|
| 241 | +</section> |
| 242 | +
|
| 243 | +<!-- /.c --> |
| 244 | +
|
98 | 245 | <!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. --> |
99 | 246 |
|
100 | 247 | <section class="related"> |
|
0 commit comments