Gathering detailed insights and metrics for @stdlib/ndarray-ctor
Gathering detailed insights and metrics for @stdlib/ndarray-ctor
Gathering detailed insights and metrics for @stdlib/ndarray-ctor
Gathering detailed insights and metrics for @stdlib/ndarray-ctor
npm install @stdlib/ndarray-ctor
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
3 Stars
74 Commits
3 Watching
5 Branches
10 Contributors
Updated on 21 Nov 2024
C (81.88%)
JavaScript (18.12%)
Cumulative downloads
Total Downloads
Last day
22.7%
395
Compared to previous day
Last week
16.1%
2,019
Compared to previous week
Last month
-2%
8,253
Compared to previous month
Last year
8.2%
97,629
Compared to previous year
32
We believe in a future in which the web is a preferred environment for numerical computation. To help realize this future, we've built stdlib. stdlib is a standard library, with an emphasis on numerical and scientific computation, written in JavaScript (and C) for execution in browsers and in Node.js.
The library is fully decomposable, being architected in such a way that you can swap out and mix and match APIs and functionality to cater to your exact preferences and use cases.
When you use stdlib, you can be absolutely certain that you are using the most thorough, rigorous, well-written, studied, documented, tested, measured, and high-quality code out there.
To join us in bringing numerical computing to the web, get started by checking us out on GitHub, and please consider financially supporting stdlib. We greatly appreciate your continued support!
Multidimensional array constructor.
1npm install @stdlib/ndarray-ctor
Alternatively,
script
tag without installation and bundlers, use the ES Module available on the esm
branch (see README).deno
branch (see README for usage intructions).umd
branch (see README).The branches.md file summarizes the available branches and displays a diagram illustrating their relationships.
To view installation and usage instructions specific to each branch build, be sure to explicitly navigate to the respective README files on each branch, as linked to above.
1var ndarray = require( '@stdlib/ndarray-ctor' );
Returns an ndarray
instance.
1// Specify the array configuration: 2var buffer = [ 1.0, 2.0, 3.0, 4.0 ]; 3var shape = [ 2, 2 ]; 4var order = 'row-major'; 5var strides = [ 2, 1 ]; 6var offset = 0; 7 8// Create a new ndarray: 9var arr = ndarray( 'generic', buffer, shape, strides, offset, order ); 10// returns <ndarray>
The constructor expects the following arguments:
row-major
(C-style) or column-major
(Fortran-style).The constructor accepts the following options
:
'throw'
.[ options.mode ]
.boolean
indicating whether an array should be read-only. Default: false
.The constructor supports the following modes
:
ndarray
instance should throw an error when an index exceeds array dimensions.ndarray
instance should normalize negative indices and throw an error when an index exceeds array dimensions.ndarray
instance should wrap around an index exceeding array dimensions using modulo arithmetic.ndarray
instance should set an index exceeding array dimensions to either 0
(minimum index) or the maximum index.By default, an ndarray
instance throws when provided an index which exceeds array dimensions. To support alternative indexing behavior, set the mode
option, which will affect all public methods for getting and setting array elements.
1var opts = { 2 'mode': 'clamp' 3}; 4 5// Specify the array configuration: 6var buffer = [ 1.0, 2.0, 3.0, 4.0 ]; 7var shape = [ 2, 2 ]; 8var order = 'row-major'; 9var strides = [ 2, 1 ]; 10var offset = 0; 11 12// Create a new ndarray: 13var arr = ndarray( 'generic', buffer, shape, strides, offset, order, opts ); 14// returns <ndarray> 15 16// Attempt to access an out-of-bounds linear index (clamped): 17var v = arr.iget( 10 ); 18// returns 4.0
By default, the mode
option is applied to subscripts which exceed array dimensions. To specify behavior for each dimension, set the submode
option.
1var opts = { 2 'submode': [ 'wrap', 'clamp' ] 3}; 4 5// Specify the array configuration: 6var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ]; 7var shape = [ 2, 2, 2 ]; 8var order = 'row-major'; 9var strides = [ 4, 2, 1 ]; 10var offset = 0; 11 12// Create a new ndarray: 13var arr = ndarray( 'generic', buffer, shape, strides, offset, order, opts ); 14// returns <ndarray> 15 16// Attempt to access out-of-bounds subscripts: 17var v = arr.get( -2, 10, -1 ); // linear index: 3 18// returns 4.0
String value of the ndarray constructor name.
1var str = ndarray.name; 2// returns 'ndarray'
Size (in bytes) of the array (if known).
1var Float64Array = require( '@stdlib/array-float64' ); 2 3// Specify the array configuration: 4var buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); 5var shape = [ 2, 2 ]; 6var order = 'row-major'; 7var strides = [ 2, 1 ]; 8var offset = 0; 9 10// Create a new ndarray: 11var arr = ndarray( 'float64', buffer, shape, strides, offset, order ); 12 13// Get the byte length: 14var nbytes = arr.byteLength; 15// returns 32
If unable to determine the size of the array, the property value is null
.
1// Specify the array configuration: 2var buffer = [ 1.0, 2.0, 3.0, 4.0 ]; 3var shape = [ 2, 2 ]; 4var order = 'row-major'; 5var strides = [ 2, 1 ]; 6var offset = 0; 7 8// Create a new ndarray: 9var arr = ndarray( 'generic', buffer, shape, strides, offset, order ); 10 11// Get the byte length: 12var nbytes = arr.byteLength; 13// returns null
Size (in bytes) of each array element (if known).
1var Float32Array = require( '@stdlib/array-float32' ); 2 3// Specify the array configuration: 4var buffer = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); 5var shape = [ 2, 2 ]; 6var order = 'row-major'; 7var strides = [ 2, 1 ]; 8var offset = 0; 9 10// Create a new ndarray: 11var arr = ndarray( 'float32', buffer, shape, strides, offset, order ); 12 13// Get the number of bytes per element: 14var nbytes = arr.BYTES_PER_ELEMENT; 15// returns 4
If size of each array element is unknown, the property value is null
.
1// Specify the array configuration: 2var buffer = [ 1.0, 2.0, 3.0, 4.0 ]; 3var shape = [ 2, 2 ]; 4var order = 'row-major'; 5var strides = [ 2, 1 ]; 6var offset = 0; 7 8// Create a new ndarray: 9var arr = ndarray( 'generic', buffer, shape, strides, offset, order ); 10 11// Get the number of bytes per element: 12var nbytes = arr.BYTES_PER_ELEMENT; 13// returns null
A reference to the underlying data buffer.
1var Int8Array = require( '@stdlib/array-int8' ); 2 3// Specify the array configuration: 4var buffer = new Int8Array( [ 1, 2, 3, 4 ] ); 5var shape = [ 2, 2 ]; 6var order = 'row-major'; 7var strides = [ 2, 1 ]; 8var offset = 0; 9 10// Create a new ndarray: 11var arr = ndarray( 'int8', buffer, shape, strides, offset, order ); 12 13// Get the buffer reference: 14var d = arr.data; 15// returns <Int8Array>[ 1, 2, 3, 4 ] 16 17var bool = ( d === buffer ); 18// returns true
Underlying data type.
1var Uint8Array = require( '@stdlib/array-uint8' ); 2 3// Specify the array configuration: 4var buffer = new Uint8Array( [ 1, 2, 3, 4 ] ); 5var shape = [ 2, 2 ]; 6var order = 'row-major'; 7var strides = [ -2, 1 ]; 8var offset = 2; 9 10// Create a new ndarray: 11var arr = ndarray( 'uint8', buffer, shape, strides, offset, order ); 12 13// Get the underlying data type: 14var dtype = arr.dtype; 15// returns 'uint8'
Meta information, such as information regarding the memory layout of the array. The returned object
has the following properties:
boolean
indicating if an array is row-major contiguous.boolean
indicating if an array is column-major contiguous.boolean
indicating whether an array is read-only.An array is contiguous if (1) an array is compatible with being stored in a single memory segment and (2) each array element is adjacent to the next array element. Note that an array can be both row-major contiguous and column-major contiguous at the same time (e.g., if an array is a 1-dimensional ndarray with strides = [1]
).
1var Int32Array = require( '@stdlib/array-int32' ); 2 3// Specify the array configuration: 4var buffer = new Int32Array( [ 1, 2, 3, 4 ] ); 5var shape = [ 2, 2 ]; 6var order = 'column-major'; 7var strides = [ 1, 2 ]; 8var offset = 0; 9 10// Create a new ndarray: 11var arr = ndarray( 'int32', buffer, shape, strides, offset, order ); 12 13// Get the array flags: 14var flg = arr.flags; 15// returns {...}
Number of array elements.
1var Uint16Array = require( '@stdlib/array-uint16' ); 2 3// Specify the array configuration: 4var buffer = new Uint16Array( [ 1, 2, 3, 4 ] ); 5var shape = [ 2, 2 ]; 6var order = 'column-major'; 7var strides = [ -1, -2 ]; 8var offset = 3; 9 10// Create a new ndarray: 11var arr = ndarray( 'uint16', buffer, shape, strides, offset, order ); 12 13// Get the array length: 14var len = arr.length; 15// returns 4
Number of dimensions.
1var Uint8ClampedArray = require( '@stdlib/array-uint8c' ); 2 3// Specify the array configuration: 4var buffer = new Uint8ClampedArray( [ 1, 2, 3, 4 ] ); 5var shape = [ 2, 2 ]; 6var order = 'row-major'; 7var strides = [ -2, -1 ]; 8var offset = 3; 9 10// Create a new ndarray: 11var arr = ndarray( 'uint8c', buffer, shape, strides, offset, order ); 12 13// Get the number of dimensions: 14var ndims = arr.ndims; 15// returns 2
Index offset which specifies the buffer
index at which to start iterating over array elements.
1var Int16Array = require( '@stdlib/array-int16' ); 2 3// Specify the array configuration: 4var buffer = new Int16Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] ); 5var shape = [ 2, 2 ]; 6var order = 'row-major'; 7var strides = [ -2, -1 ]; 8var offset = 10; 9 10// Create a new ndarray: 11var arr = ndarray( 'int16', buffer, shape, strides, offset, order ); 12 13// Get the index offset: 14var o = arr.offset; 15// returns 10
Array order. The array order is either row-major (C-style) or column-major (Fortran-style).
1var Uint32Array = require( '@stdlib/array-uint32' ); 2 3// Specify the array configuration: 4var buffer = new Uint32Array( [ 1, 2, 3, 4 ] ); 5var shape = [ 2, 2 ]; 6var order = 'row-major'; 7var strides = [ 2, 1 ]; 8var offset = 0; 9 10// Create a new ndarray: 11var arr = ndarray( 'uint32', buffer, shape, strides, offset, order ); 12 13// Get the array order: 14var ord = arr.order; 15// returns 'row-major'
Returns a copy of the array shape.
1// Specify the array configuration: 2var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; 3var shape = [ 2, 2 ]; 4var order = 'row-major'; 5var strides = [ 2, 1 ]; 6var offset = 2; 7 8// Create a new ndarray: 9var arr = ndarray( 'generic', buffer, shape, strides, offset, order ); 10 11// Get the array shape: 12var dims = arr.shape; 13// returns [ 2, 2 ]
Returns a copy of the array strides which specify how to access data along corresponding array dimensions.
1// Specify the array configuration: 2var buffer = [ 1.0, 2.0, 3.0, 4.0 ]; 3var shape = [ 2, 2 ]; 4var order = 'column-major'; 5var strides = [ -1, 2 ]; 6var offset = 1; 7 8// Create a new ndarray: 9var arr = ndarray( 'generic', buffer, shape, strides, offset, order ); 10 11// Get the array strides: 12var s = arr.strides; 13// returns [ -1, 2 ]
Returns an array element specified according to provided subscripts. The number of provided subscripts must equal the number of dimensions.
1// Specify the array configuration: 2var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ]; 3var shape = [ 2, 2 ]; 4var order = 'row-major'; 5var strides = [ 2, 1 ]; 6var offset = 2; 7 8// Create a new ndarray: 9var arr = ndarray( 'generic', buffer, shape, strides, offset, order ); 10 11// Get the element located at (1,1): 12var v = arr.get( 1, 1 ); 13// returns 6.0
Returns an array element located at a specified linear index.
1// Specify the array configuration: 2var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ]; 3var shape = [ 2, 2 ]; 4var order = 'row-major'; 5var strides = [ 2, 1 ]; 6var offset = 2; 7 8// Create a new ndarray: 9var arr = ndarray( 'generic', buffer, shape, strides, offset, order ); 10 11// Get the element located at index 3: 12var v = arr.iget( 3 ); 13// returns 6.0
For zero-dimensional arrays, the input argument is ignored and, for clarity, should not be provided.
Sets an array element specified according to provided subscripts. The number of provided subscripts must equal the number of dimensions.
1// Specify the array configuration: 2var buffer = [ 1.0, 2.0, 3.0, 4.0 ]; 3var shape = [ 2, 2 ]; 4var order = 'row-major'; 5var strides = [ 2, 1 ]; 6var offset = 0; 7 8// Create a new ndarray: 9var arr = ndarray( 'generic', buffer, shape, strides, offset, order ); 10 11// Set the element located at (1,1): 12arr.set( 1, 1, 40.0 ); 13var v = arr.get( 1, 1 ); 14// returns 40.0 15 16// Get the underlying buffer: 17var d = arr.data; 18// returns [ 1.0, 2.0, 3.0, 40.0 ]
The method returns the ndarray
instance. If an array is read-only, the method raises an exception.
Sets an array element located at a specified linear index.
1// Specify the array configuration: 2var buffer = [ 1.0, 2.0, 3.0, 4.0 ]; 3var shape = [ 2, 2 ]; 4var order = 'row-major'; 5var strides = [ 2, 1 ]; 6var offset = 0; 7 8// Create a new ndarray: 9var arr = ndarray( 'generic', buffer, shape, strides, offset, order ); 10 11// Set the element located at index 3: 12arr.iset( 3, 40.0 ); 13var v = arr.iget( 3 ); 14// returns 40.0 15 16// Get the underlying buffer: 17var d = arr.data; 18// returns [ 1.0, 2.0, 3.0, 40.0 ]
For zero-dimensional arrays, the first, and only, argument should be the value v
to set.
The method returns the ndarray
instance. If an array is read-only, the method raises an exception.
Serializes an ndarray
as a string
.
1// Specify the array configuration: 2var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ]; 3var shape = [ 3, 2 ]; 4var order = 'row-major'; 5var strides = [ 2, 1 ]; 6var offset = 2; 7 8// Create a new ndarray: 9var arr = ndarray( 'generic', buffer, shape, strides, offset, order ); 10 11// Serialize to a string: 12var str = arr.toString(); 13// returns "ndarray( 'generic', [ 3, 4, 5, 6, 7, 8 ], [ 3, 2 ], [ 2, 1 ], 0, 'row-major' )"
The method does not serialize data outside of the buffer region defined by the array configuration.
Serializes an ndarray
as a JSON object
. JSON.stringify()
implicitly calls this method when stringifying an ndarray
instance.
1// Specify the array configuration: 2var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ]; 3var shape = [ 3, 2 ]; 4var order = 'row-major'; 5var strides = [ 2, 1 ]; 6var offset = 2; 7 8// Create a new ndarray: 9var arr = ndarray( 'generic', buffer, shape, strides, offset, order ); 10 11// Serialize to JSON: 12var o = arr.toJSON(); 13// returns { 'type': 'ndarray', 'dtype': 'generic', 'flags': {...}, 'offset': 0, 'order': 'row-major', 'shape': [ 3, 2 ], 'strides': [ 2, 1 ], 'data': [ 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] }
The method does not serialize data outside of the buffer region defined by the array configuration.
To create a zero-dimensional array, provide an empty shape
and a single strides
element equal to 0
. The order
can be either row-major
or column-major
and has no effect on data storage or access.
1var buffer = [ 1 ]; 2var shape = []; 3var order = 'row-major'; 4var strides = [ 0 ]; 5var offset = 0; 6 7// Create a new zero-dimensional array: 8var arr = ndarray( 'generic', buffer, shape, strides, offset, order ); 9// returns <ndarray>
1var Float32Array = require( '@stdlib/array-float32' ); 2var ndarray = require( '@stdlib/ndarray-ctor' ); 3 4// Create a data buffer: 5var buffer = new Float32Array( (3*3*3*3) + 100 ); 6 7// Specify the array shape: 8var shape = [ 3, 3, 3, 3 ]; 9 10// Specify the array strides: 11var strides = [ 27, 9, 3, 1 ]; 12 13// Specify the index offset: 14var offset = 4; 15 16// Specify the order: 17var order = 'row-major'; // C-style 18 19// Create a new ndarray: 20var arr = ndarray( 'float32', buffer, shape, strides, offset, order ); 21 22// Retrieve an array value: 23var v = arr.get( 1, 2, 1, 2 ); 24// returns 0.0 25 26// Set an array value: 27arr.set( 1, 2, 1, 2, 10.0 ); 28 29// Retrieve the array value: 30v = arr.get( 1, 2, 1, 2 ); 31// returns 10.0 32 33// Serialize the array as a string: 34var str = arr.toString(); 35// returns "ndarray( 'float32', new Float32Array( [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ] ), [ 3, 3, 3, 3 ], [ 27, 9, 3, 1 ], 0, 'row-major' )" 36 37// Serialize the array as JSON: 38str = JSON.stringify( arr.toJSON() ); 39// e.g., returns '{"type":"ndarray","dtype":"float32","flags":{"READONLY":false},"order":"row-major","shape":[3,3,3,3],"strides":[27,9,3,1],"data":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,10,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]}'
1#include "stdlib/ndarray/ctor.h"
Structure holding ndarray data.
1#include "stdlib/ndarray/dtypes.h" 2#include "stdlib/ndarray/index_modes.h" 3#include "stdlib/ndarray/orders.h" 4#include "stdlib/ndarray/base/bytes_per_element.h" 5#include <stdint.h> 6 7struct ndarray { 8 // Underlying data type: 9 int16_t dtype; 10 11 // Pointer to the underlying byte array: 12 uint8_t *data; 13 14 // Number of array dimensions: 15 int64_t ndims; 16 17 // Array shape (dimensions): 18 int64_t *shape; 19 20 // Array strides (in bytes) specifying how to iterate over a strided array: 21 int64_t *strides; 22 23 // Byte offset which specifies the location at which to start iterating over array elements: 24 int64_t offset; 25 26 // Array order (either row-major (C-style) or column-major (Fortran-style)): 27 int8_t order; 28 29 // Mode specifying how to handle indices which exceed array dimensions: 30 int8_t imode; 31 32 // Number of subscript modes: 33 int64_t nsubmodes; 34 35 // Mode(s) specifying how to handle subscripts which exceed array dimensions on a per dimension basis: 36 int8_t *submodes; 37 38 // Number of array elements: 39 int64_t length; 40 41 // Size in bytes: 42 int64_t byteLength; 43 44 // Number of bytes per element (i.e., item size): 45 int64_t BYTES_PER_ELEMENT; 46 47 // Bit mask providing information regarding the memory layout of the array (e.g., see macros): 48 int64_t flags; 49};
Macro defining a flag indicating whether an ndarray is row-major (C-style) contiguous.
1#define STDLIB_NDARRAY_ROW_MAJOR_CONTIGUOUS_FLAG 0x0001
Notes:
strides
array is in reverse order to that of column-major order.Macro defining a flag indicating whether an ndarray is column-major (Fortran-style) contiguous.
1#define STDLIB_NDARRAY_COLUMN_MAJOR_CONTIGUOUS_FLAG 0x0002
Notes:
strides
array is in reverse order to that of row-major order.Returns a pointer to a dynamically allocated ndarray.
1#include "stdlib/ndarray/ctor.h" 2#include "stdlib/ndarray/dtypes.h" 3#include "stdlib/ndarray/index_modes.h" 4#include "stdlib/ndarray/orders.h" 5#include "stdlib/ndarray/base/bytes_per_element.h" 6#include <stdlib.h> 7#include <stdio.h> 8#include <stdint.h> 9 10// Specify the underlying data type: 11enum STDLIB_NDARRAY_DTYPE dtype = STDLIB_NDARRAY_FLOAT64; 12 13// Create an underlying byte array: 14uint8_t buffer[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; 15 16// Specify the number of array dimensions: 17int64_t ndims = 1; 18 19// Specify the array shape: 20int64_t shape[] = { 3 }; // vector consisting of 3 doubles 21 22// Specify the array strides: 23int64_t strides[] = { STDLIB_NDARRAY_FLOAT64_BYTES_PER_ELEMENT }; 24 25// Specify the byte offset: 26int64_t offset = 0; 27 28// Specify the array order (note: this does not matter for a 1-dimensional array): 29enum STDLIB_NDARRAY_ORDER order = STDLIB_NDARRAY_ROW_MAJOR; 30 31// Specify the index mode: 32enum STDLIB_NDARRAY_INDEX_MODE imode = STDLIB_NDARRAY_INDEX_ERROR; 33 34// Specify the subscript index modes: 35int8_t submodes[] = { STDLIB_NDARRAY_INDEX_ERROR }; 36int64_t nsubmodes = 1; 37 38// Create an ndarray: 39struct ndarray *x = stdlib_ndarray_allocate( dtype, buffer, ndims, shape, strides, offset, order, imode, nsubmodes, submodes ); 40if ( x == NULL ) { 41 fprintf( stderr, "Error allocating memory.\n" ); 42 exit( 1 ); 43} 44 45// Free allocated memory: 46stdlib_ndarray_free( x );
The function accepts the following arguments:
[in] int16_t
data type.[in] uint8_t*
pointer to the underlying byte array.[in] int64_t
number of dimensions.[in] int64_t*
array shape (i.e., dimensions).[in] int64_t*
array strides (in bytes).[in] int64_t
byte offset specifying the location of the first element.[in] int8_t
specifies whether an array is row-major (C-style) or column-major (Fortran-style).[in] int8_t
specifies the index mode (i.e., how to handle indices which exceed array dimensions).[in] int64_t
number of subscript modes.[in] int8_t*
specifies how to handle subscripts which exceed array dimensions on a per dimension basis (if provided fewer submodes than dimensions, submodes are recycled using modulo arithmetic).1struct ndarray * stdlib_ndarray_allocate( int16_t dtype, uint8_t *data, int64_t ndims, int64_t *shape, int64_t *strides, int64_t offset, int8_t order, int8_t imode, int64_t nsubmodes, int8_t *submodes );
Notes:
Returns the size of an ndarray (in bytes).
1#include "stdlib/ndarray/ctor.h" 2#include <stdint.h> 3#include <stdlib.h> 4#include <stdio.h> 5 6// ... 7 8// Create an ndarray: 9struct ndarray *x = stdlib_ndarray_allocate( ... ); 10if ( x == NULL ) { 11 fprintf( stderr, "Error allocating memory.\n" ); 12 exit( 1 ); 13} 14 15// ... 16 17// Retrieve the ndarray size: 18int64_t N = stdlib_ndarray_bytelength( x ); 19 20// ... 21 22// Free allocated memory: 23stdlib_ndarray_free( x );
The function accepts the following arguments:
[in] struct ndarray*
input ndarray.1int64_t stdlib_ndarray_bytelength( const struct ndarray *arr );
Returns a pointer to an ndarray's underlying byte array.
1#include "stdlib/ndarray/ctor.h" 2#include <stdint.h> 3#include <stdlib.h> 4#include <stdio.h> 5 6// ... 7 8// Create an ndarray: 9struct ndarray *x = stdlib_ndarray_allocate( ... ); 10if ( x == NULL ) { 11 fprintf( stderr, "Error allocating memory.\n" ); 12 exit( 1 ); 13} 14 15// ... 16 17// Retrieve the underlying byte array: 18uint8_t *data = stdlib_ndarray_data( x ); 19 20// ... 21 22// Free allocated memory: 23stdlib_ndarray_free( x );
The function accepts the following arguments:
[in] struct ndarray*
input ndarray.1uint8_t * stdlib_ndarray_data( const struct ndarray *arr );
Returns an ndarray dimension.
1#include "stdlib/ndarray/ctor.h" 2#include <stdint.h> 3#include <stdlib.h> 4#include <stdio.h> 5 6// ... 7 8// Create an ndarray: 9struct ndarray *x = stdlib_ndarray_allocate( ... ); 10if ( x == NULL ) { 11 fprintf( stderr, "Error allocating memory.\n" ); 12 exit( 1 ); 13} 14 15// ... 16 17// Retrieve a dimension: 18int64_t dim = stdlib_ndarray_dimension( x, 0 ); 19 20// ... 21 22// Free allocated memory: 23stdlib_ndarray_free( x );
The function accepts the following arguments:
[in] struct ndarray*
input ndarray.[in] int64_t
dimension index.1int64_t stdlib_ndarray_dimension( const struct ndarray *arr, const int64_t i );
Notes:
Disables specified ndarray flags.
1#include "stdlib/ndarray/ctor.h" 2#include <stdint.h> 3#include <stdlib.h> 4#include <stdio.h> 5 6// ... 7 8// Create an ndarray: 9struct ndarray *x = stdlib_ndarray_allocate( ... ); 10if ( x == NULL ) { 11 fprintf( stderr, "Error allocating memory.\n" ); 12 exit( 1 ); 13} 14 15// ... 16 17// Disables specified ndarray flags: 18int8_t status = stdlib_ndarray_disable_flags( x, STDLIB_NDARRAY_ROW_MAJOR_CONTIGUOUS_FLAG ); 19 20// ... 21 22// Free allocated memory: 23stdlib_ndarray_free( x );
The function accepts the following arguments:
[in] struct ndarray*
input ndarray.[in] int64_t
bit mask to disable flags.The function returns a status code of 0
if able to successfully disable flags.
1int8_t stdlib_ndarray_disable_flags( const struct ndarray *arr, const int64_t flags );
Notes:
Returns the data type of an ndarray.
1#include "stdlib/ndarray/ctor.h" 2#include "stdlib/ndarray/dtypes.h" 3#include <stdlib.h> 4#include <stdio.h> 5 6// ... 7 8// Create an ndarray: 9struct ndarray *x = stdlib_ndarray_allocate( ... ); 10if ( x == NULL ) { 11 fprintf( stderr, "Error allocating memory.\n" ); 12 exit( 1 ); 13} 14 15// ... 16 17// Retrieve the dtype: 18enum STDLIB_NDARRAY_DTYPE dtype = stdlib_ndarray_dtype( x ); 19 20// ... 21 22// Free allocated memory: 23stdlib_ndarray_free( x );
The function accepts the following arguments:
[in] struct ndarray*
input ndarray.1int16_t stdlib_ndarray_dtype( const struct ndarray *arr );
Enables specified ndarray flags.
1#include "stdlib/ndarray/ctor.h" 2#include <stdint.h> 3#include <stdlib.h> 4#include <stdio.h> 5 6// ... 7 8// Create an ndarray: 9struct ndarray *x = stdlib_ndarray_allocate( ... ); 10if ( x == NULL ) { 11 fprintf( stderr, "Error allocating memory.\n" ); 12 exit( 1 ); 13} 14 15// ... 16 17// Enables specified ndarray flags: 18int8_t status = stdlib_ndarray_enable_flags( x, STDLIB_NDARRAY_ROW_MAJOR_CONTIGUOUS_FLAG ); 19 20// ... 21 22// Free allocated memory: 23stdlib_ndarray_free( x );
The function accepts the following arguments:
[in] struct ndarray*
input ndarray.[in] int64_t
bit mask to enable flags.The function returns a status code of 0
if able to successfully enable flags.
1int8_t stdlib_ndarray_enable_flags( const struct ndarray *arr, const int64_t flags );
Notes:
Returns ndarray flags as a single integer value.
1#include "stdlib/ndarray/ctor.h" 2#include <stdint.h> 3#include <stdlib.h> 4#include <stdio.h> 5 6// ... 7 8// Create an ndarray: 9struct ndarray *x = stdlib_ndarray_allocate( ... ); 10if ( x == NULL ) { 11 fprintf( stderr, "Error allocating memory.\n" ); 12 exit( 1 ); 13} 14 15// ... 16 17// Retrieve the ndarray flags: 18int64_t flags = stdlib_ndarray_flags( x ); 19 20// ... 21 22// Free allocated memory: 23stdlib_ndarray_free( x );
The function accepts the following arguments:
[in] struct ndarray*
input ndarray.1int64_t stdlib_ndarray_flags( const struct ndarray *arr );
Frees an ndarray's allocated memory.
1#include "stdlib/ndarray/ctor.h" 2#include <stdlib.h> 3#include <stdio.h> 4 5// ... 6 7// Create an ndarray: 8struct ndarray *x = stdlib_ndarray_allocate( ... ); 9if ( x == NULL ) { 10 fprintf( stderr, "Error allocating memory.\n" ); 11 exit( 1 ); 12} 13 14// ... 15 16// Free allocated memory: 17stdlib_ndarray_free( x );
The function accepts the following arguments:
[in] struct ndarray*
input ndarray.1void stdlib_ndarray_free( struct ndarray *arr );
Tests whether an ndarray has specified flags enabled.
1#include "stdlib/ndarray/ctor.h" 2#include <stdint.h> 3#include <stdlib.h> 4#include <stdio.h> 5 6// ... 7 8// Create an ndarray: 9struct ndarray *x = stdlib_ndarray_allocate( ... ); 10if ( x == NULL ) { 11 fprintf( stderr, "Error allocating memory.\n" ); 12 exit( 1 ); 13} 14 15// ... 16 17// Test whether an ndarray is row-major contiguous: 18int8_t out = stdlib_ndarray_flags( x, STDLIB_NDARRAY_ROW_MAJOR_CONTIGUOUS_FLAG ); 19 20// ... 21 22// Free allocated memory: 23stdlib_ndarray_free( x );
The function accepts the following arguments:
[in] struct ndarray*
input ndarray.[in] int64_t
bit mask specifying flags to test against.The function returns 1
if flags are set and 0
otherwise.
1int8_t stdlib_ndarray_has_flags( const struct ndarray *arr, const int64_t flags );
Returns the index mode of an ndarray.
1#include "stdlib/ndarray/ctor.h" 2#include "stdlib/ndarray/index_modes.h" 3#include <stdlib.h> 4#include <stdio.h> 5 6// ... 7 8// Create an ndarray: 9struct ndarray *x = stdlib_ndarray_allocate( ... ); 10if ( x == NULL ) { 11 fprintf( stderr, "Error allocating memory.\n" ); 12 exit( 1 ); 13} 14 15// ... 16 17// Retrieve the index mode: 18enum STDLIB_NDARRAY_INDEX_MODE imode = stdlib_ndarray_index_mode( x ); 19 20// ... 21 22// Free allocated memory: 23stdlib_ndarray_free( x );
The function accepts the following arguments:
[in] struct ndarray*
input ndarray.1int8_t stdlib_ndarray_index_mode( const struct ndarray *arr );
Returns the number of elements in an ndarray.
1#include "stdlib/ndarray/ctor.h" 2#include <stdint.h> 3#include <stdlib.h> 4#include <stdio.h> 5 6// ... 7 8// Create an ndarray: 9struct ndarray *x = stdlib_ndarray_allocate( ... ); 10if ( x == NULL ) { 11 fprintf( stderr, "Error allocating memory.\n" ); 12 exit( 1 ); 13} 14 15// ... 16 17// Retrieve the number of elements: 18int64_t N = stdlib_ndarray_length( x ); 19 20// ... 21 22// Free allocated memory: 23stdlib_ndarray_free( x );
The function accepts the following arguments:
[in] struct ndarray*
input ndarray.1int64_t stdlib_ndarray_length( const struct ndarray *arr );
Returns the number of ndarray dimensions.
1#include "stdlib/ndarray/ctor.h" 2#include <stdint.h> 3#include <stdlib.h> 4#include <stdio.h> 5 6// ... 7 8// Create an ndarray: 9struct ndarray *x = stdlib_ndarray_allocate( ... ); 10if ( x == NULL ) { 11 fprintf( stderr, "Error allocating memory.\n" ); 12 exit( 1 ); 13} 14 15// ... 16 17// Retrieve the number of dimensions: 18int64_t ndims = stdlib_ndarray_ndims( x ); 19 20// ... 21 22// Free allocated memory: 23stdlib_ndarray_free( x );
The function accepts the following arguments:
[in] struct ndarray*
input ndarray.1int64_t stdlib_ndarray_ndims( const struct ndarray *arr );
Returns the number of ndarray subscript modes.
1#include "stdlib/ndarray/ctor.h" 2#include <stdint.h> 3#include <stdlib.h> 4#include <stdio.h> 5 6// ... 7 8// Create an ndarray: 9struct ndarray *x = stdlib_ndarray_allocate( ... ); 10if ( x == NULL ) { 11 fprintf( stderr, "Error allocating memory.\n" ); 12 exit( 1 ); 13} 14 15// ... 16 17// Retrieve the number of index modes: 18int64_t n = stdlib_ndarray_nsubmodes( x ); 19 20// ... 21 22// Free allocated memory: 23stdlib_ndarray_free( x );
The function accepts the following arguments:
[in] struct ndarray*
input ndarray.1int64_t stdlib_ndarray_nsubmodes( const struct ndarray *arr );
Returns an ndarray index offset (in bytes).
1#include "stdlib/ndarray/ctor.h" 2#include <stdint.h> 3#include <stdlib.h> 4#include <stdio.h> 5 6// ... 7 8// Create an ndarray: 9struct ndarray *x = stdlib_ndarray_allocate( ... ); 10if ( x == NULL ) { 11 fprintf( stderr, "Error allocating memory.\n" ); 12 exit( 1 ); 13} 14 15// ... 16 17// Retrieve the index offset: 18int64_t offset = stdlib_ndarray_offset( x ); 19 20// ... 21 22// Free allocated memory: 23stdlib_ndarray_free( x );
The function accepts the following arguments:
[in] struct ndarray*
input ndarray.1int64_t stdlib_ndarray_offset( const struct ndarray *arr );
Returns the order of an ndarray.
1#include "stdlib/ndarray/ctor.h" 2#include "stdlib/ndarray/orders.h" 3#include <stdlib.h> 4#include <stdio.h> 5 6// ... 7 8// Create an ndarray: 9struct ndarray *x = stdlib_ndarray_allocate( ... ); 10if ( x == NULL ) { 11 fprintf( stderr, "Error allocating memory.\n" ); 12 exit( 1 ); 13} 14 15// ... 16 17// Retrieve the order: 18enum STDLIB_NDARRAY_ORDER order = stdlib_ndarray_order( x ); 19 20// ... 21 22// Free allocated memory: 23stdlib_ndarray_free( x );
The function accepts the following arguments:
[in] struct ndarray*
input ndarray.1int8_t stdlib_ndarray_order( const struct ndarray *arr );
Returns a pointer to an array containing an ndarray shape (dimensions).
1#include "stdlib/ndarray/ctor.h" 2#include <stdint.h> 3#include <stdlib.h> 4#include <stdio.h> 5 6// ... 7 8// Create an ndarray: 9struct ndarray *x = stdlib_ndarray_allocate( ... ); 10if ( x == NULL ) { 11 fprintf( stderr, "Error allocating memory.\n" ); 12 exit( 1 ); 13} 14 15// ... 16 17// Retrieve the shape: 18int64_t *shape = stdlib_ndarray_shape( x ); 19 20// ... 21 22// Free allocated memory: 23stdlib_ndarray_free( x );
The function accepts the following arguments:
[in] struct ndarray*
input ndarray.1int64_t * stdlib_ndarray_shape( const struct ndarray *arr );
Returns an ndarray stride (in bytes).
1#include "stdlib/ndarray/ctor.h" 2#include <stdint.h> 3#include <stdlib.h> 4#include <stdio.h> 5 6// ... 7 8// Create an ndarray: 9struct ndarray *x = stdlib_ndarray_allocate( ... ); 10if ( x == NULL ) { 11 fprintf( stderr, "Error allocating memory.\n" ); 12 exit( 1 ); 13} 14 15// ... 16 17// Retrieve a stride: 18int64_t s = stdlib_ndarray_stride( x, 0 ); 19 20// ... 21 22// Free allocated memory: 23stdlib_ndarray_free( x );
The function accepts the following arguments:
[in] struct ndarray*
input ndarray.[in] int64_t
dimension index.1int64_t stdlib_ndarray_stride( const struct ndarray *arr, const int64_t i );
Notes:
Returns a pointer to an array containing ndarray strides (in bytes).
1#include "stdlib/ndarray/ctor.h" 2#include <stdint.h> 3#include <stdlib.h> 4#include <stdio.h> 5 6// ... 7 8// Create an ndarray: 9struct ndarray *x = stdlib_ndarray_allocate( ... ); 10if ( x == NULL ) { 11 fprintf( stderr, "Error allocating memory.\n" ); 12 exit( 1 ); 13} 14 15// ... 16 17// Retrieve the strides: 18int64_t *strides = stdlib_ndarray_strides( x ); 19 20// ... 21 22// Free allocated memory: 23stdlib_ndarray_free( x );
The function accepts the following arguments:
[in] struct ndarray*
input ndarray.1int64_t * stdlib_ndarray_strides( const struct ndarray *arr );
Returns an ndarray subscript mode.
1#include "stdlib/ndarray/ctor.h" 2#include "stdlib/ndarray/index_modes.h" 3#include <stdlib.h> 4#include <stdio.h> 5 6// ... 7 8// Create an ndarray: 9struct ndarray *x = stdlib_ndarray_allocate( ... ); 10if ( x == NULL ) { 11 fprintf( stderr, "Error allocating memory.\n" ); 12 exit( 1 ); 13} 14 15// ... 16 17// Retrieve an index mode: 18enum STDLIB_NDARRAY_INDEX_MODE mode = stdlib_ndarray_submode( x, 0 ); 19 20// ... 21 22// Free allocated memory: 23stdlib_ndarray_free( x );
The function accepts the following arguments:
[in] struct ndarray*
input ndarray.[in] int64_t
dimension index.1int8_t stdlib_ndarray_submode( const struct ndarray *arr, const int64_t i );
Notes:
Returns ndarray subscript modes.
1#include "stdlib/ndarray/ctor.h" 2#include "stdlib/ndarray/index_modes.h" 3#include <stdlib.h> 4#include <stdio.h> 5 6// ... 7 8// Create an ndarray: 9struct ndarray *x = stdlib_ndarray_allocate( ... ); 10if ( x == NULL ) { 11 fprintf( stderr, "Error allocating memory.\n" ); 12 exit( 1 ); 13} 14 15// ... 16 17// Retrieve the index subscript modes: 18int8_t *modes = stdlib_ndarray_submodes( x ); 19 20// ... 21 22// Free allocated memory: 23stdlib_ndarray_free( x );
The function accepts the following arguments:
[in] struct ndarray*
input ndarray.1int8_t * stdlib_ndarray_submodes( const struct ndarray *arr );
Returns an ndarray data element.
1int8_t stdlib_ndarray_get( const struct ndarray *arr, const int64_t *sub, void *out );
The function accepts the following arguments:
[in] struct ndarray *
input ndarray.[in] int64_t *
ndarray subscripts.[out] void *
output address.Notes:
-1
if unable to get an element and 0
otherwise.void
pointer for the output address out
in order to provide a generic API supporting ndarrays having different data types.Returns a double-precision floating-point ndarray data element.
1int8_t stdlib_ndarray_get_float64( const struct ndarray *arr, const int64_t *sub, double *out );
The function accepts the following arguments:
[in] struct ndarray *
input ndarray.[in] int64_t *
ndarray subscripts.[out] double *
output address.Notes:
-1
if unable to get an element and 0
otherwise.Returns a single-precision floating-point ndarray data element.
1int8_t stdlib_ndarray_get_float32( const struct ndarray *arr, const int64_t *sub, float *out );
The function accepts the following arguments:
[in] struct ndarray *
input ndarray.[in] int64_t *
ndarray subscripts.[out] float *
output address.Notes:
-1
if unable to get an element and 0
otherwise.Returns an unsigned 64-bit integer ndarray data element.
1int8_t stdlib_ndarray_get_uint64( const struct ndarray *arr, const int64_t *sub, uint64_t *out );
The function accepts the following arguments:
[in] struct ndarray *
input ndarray.[in] int64_t *
ndarray subscripts.[out] uint64_t *
output address.Notes:
-1
if unable to get an element and 0
otherwise.Returns a signed 64-bit integer ndarray data element.
1int8_t stdlib_ndarray_get_int64( const struct ndarray *arr, const int64_t *sub, int64_t *out );
The function accepts the following arguments:
[in] struct ndarray *
input ndarray.[in] int64_t *
ndarray subscripts.[out] int64_t *
output address.Notes:
-1
if unable to get an element and 0
otherwise.Returns an unsigned 32-bit integer ndarray data element.
1int8_t stdlib_ndarray_get_uint32( const struct ndarray *arr, const int64_t *sub, uint32_t *out );
The function accepts the following arguments:
[in] struct ndarray *
input ndarray.[in] int64_t *
ndarray subscripts.[out] uint32_t *
output address.Notes:
-1
if unable to get an element and 0
otherwise.Returns a signed 32-bit integer ndarray data element.
1int8_t stdlib_ndarray_get_int32( const struct ndarray *arr, const int64_t *sub, int32_t *out );
The function accepts the following arguments:
[in] struct ndarray *
input ndarray.[in] int64_t *
ndarray subscripts.[out] int32_t *
output address.Notes:
-1
if unable to get an element and 0
otherwise.Returns an unsigned 16-bit integer ndarray data element.
1int8_t stdlib_ndarray_get_uint16( const struct ndarray *arr, const int64_t *sub, uint16_t *out );
The function accepts the following arguments:
[in] struct ndarray *
input ndarray.[in] int64_t *
ndarray subscripts.[out] uint16_t *
output address.Notes:
-1
if unable to get an element and 0
otherwise.Returns a signed 16-bit integer ndarray data element.
1int8_t stdlib_ndarray_get_int16( const struct ndarray *arr, const int64_t *sub, int16_t *out );
The function accepts the following arguments:
[in] struct ndarray *
input ndarray.[in] int64_t *
ndarray subscripts.[out] int16_t *
output address.Notes:
-1
if unable to get an element and 0
otherwise.Returns an unsigned 8-bit integer ndarray data element.
1int8_t stdlib_ndarray_get_uint8( const struct ndarray *arr, const int64_t *sub, uint8_t *out );
The function accepts the following arguments:
[in] struct ndarray *
input ndarray.[in] int64_t *
ndarray subscripts.[out] uint8_t *
output address.Notes:
-1
if unable to get an element and 0
otherwise.Returns a signed 8-bit integer ndarray data element.
1int8_t stdlib_ndarray_get_int8( const struct ndarray *arr, const int64_t *sub, int8_t *out );
The function accepts the following arguments:
[in] struct ndarray *
input ndarray.[in] int64_t *
ndarray subscripts.[out] int8_t *
output address.Notes:
-1
if unable to get an element and 0
otherwise.Returns a double-precision complex floating-point ndarray data element.
1int8_t stdlib_ndarray_get_complex128( const struct ndarray *arr, const int64_t *sub, stdlib_complex128_t *out );
The function accepts the following arguments:
[in] struct ndarray *
input ndarray.[in] int64_t *
ndarray subscripts.[out] stdlib_complex128_t *
output address.Notes:
-1
if unable to get an element and 0
otherwise.Returns a single-precision complex floating-point ndarray data element.
1int8_t stdlib_ndarray_get_complex64( const struct ndarray *arr, const int64_t *sub, stdlib_complex64_t *out );
The function accepts the following arguments:
[in] struct ndarray *
input ndarray.[in] int64_t *
ndarray subscripts.[out] stdlib_complex64_t *
output address.Notes:
-1
if unable to get an element and 0
otherwise.Returns a boolean ndarray data element.
1int8_t stdlib_ndarray_get_bool( const struct ndarray *arr, const int64_t *sub, bool *out );
The function accepts the following arguments:
[in] struct ndarray *
input ndarray.[in] int64_t *
ndarray subscripts.[out] bool *
output address.Notes:
-1
if unable to get an element and 0
otherwise.Returns a pointer to an ndarray data element in the underlying byte array.
1uint8_t * stdlib_ndarray_get_ptr( const struct ndarray *arr, const int64_t *sub );
The function accepts the following arguments:
[in] struct ndarray *
input ndarray.[in] int64_t *
ndarray subscripts.Returns an ndarray data element specified by a byte array pointer.
1int8_t stdlib_ndarray_get_ptr_value( const struct ndarray *arr, const uint8_t *idx, void *out );
The function accepts the following arguments:
[in] struct ndarray *
input ndarray.[in] uint8_t *
byte array pointer to an ndarray data element.[out] void *
output address.Notes:
-1
if unable to get an element and 0
otherwise.void
pointer for the output address out
in order to provide a generic API supporting ndarrays having different data types.Returns a double-precision floating-point ndarray data element specified by a byte array pointer.
1int8_t stdlib_ndarray_get_ptr_float64( const uint8_t *idx, double *out );
The function accepts the following arguments:
[in] uint8_t *
byte array pointer to an ndarray data element.[out] double *
output address.Notes:
idx
actually points to a compatible memory address. Accordingly, accessing unowned memory is possible, and this function assumes you know what you are doing.0
.Returns a single-precision floating-point ndarray data element specified by a byte array pointer.
1int8_t stdlib_ndarray_get_ptr_float32( const uint8_t *idx, float *out );
The function accepts the following arguments:
[in] uint8_t *
byte array pointer to an ndarray data element.[out] float *
output address.Notes:
idx
actually points to a compatible memory address. Accordingly, accessing unowned memory is possible, and this function assumes you know what you are doing.0
.Returns an unsigned 64-bit integer ndarray data element specified by a byte array pointer.
1int8_t stdlib_ndarray_get_ptr_uint64( const uint8_t *idx, uint64_t *out );
The function accepts the following arguments:
[in] uint8_t *
byte array pointer to an ndarray data element.[out] uint64_t *
output address.Notes:
idx
actually points to a compatible memory address. Accordingly, accessing unowned memory is possible, and this function assumes you know what you are doing.0
.Returns a signed 64-bit integer ndarray data element specified by a byte array pointer.
1int8_t stdlib_ndarray_get_ptr_int64( const uint8_t *idx, int64_t *out );
The function accepts the following arguments:
[in] uint8_t *
byte array pointer to an ndarray data element.[out] int64_t *
output address.Notes:
idx
actually points to a compatible memory address. Accordingly, accessing unowned memory is possible, and this function assumes you know what you are doing.0
.Returns an unsigned 32-bit integer ndarray data element specified by a byte array pointer.
1int8_t stdlib_ndarray_get_ptr_uint32( const uint8_t *idx, uint32_t *out );
The function accepts the following arguments:
[in] uint8_t *
byte array pointer to an ndarray data element.[out] uint32_t *
output address.Notes:
idx
actually points to a compatible memory address. Accordingly, accessing unowned memory is possible, and this function assumes you know what you are doing.0
.Returns a signed 32-bit integer ndarray data element specified by a byte array pointer.
1int8_t stdlib_ndarray_get_ptr_int32( const uint8_t *idx, int32_t *out );
The function accepts the following arguments:
[in] uint8_t *
byte array pointer to an ndarray data element.[out] int32_t *
output address.Notes:
idx
actually points to a compatible memory address. Accordingly, accessing unowned memory is possible, and this function assumes you know what you are doing.0
.Returns an unsigned 16-bit integer ndarray data element specified by a byte array pointer.
1int8_t stdlib_ndarray_get_ptr_uint16( const uint8_t *idx, uint16_t *out );
The function accepts the following arguments:
[in] uint8_t *
byte array pointer to an ndarray data element.[out] uint16_t *
output address.Notes:
idx
actually points to a compatible memory address. Accordingly, accessing unowned memory is possible, and this function assumes you know what you are doing.0
.Returns a signed 16-bit integer ndarray data element specified by a byte array pointer.
1int8_t stdlib_ndarray_get_ptr_int16( const uint8_t *idx, int16_t *out );
The function accepts the following arguments:
[in] uint8_t *
byte array pointer to an ndarray data element.[out] int16_t *
output address.Notes:
idx
actually points to a compatible memory address. Accordingly, accessing unowned memory is possible, and this function assumes you know what you are doing.0
.Returns an unsigned 8-bit integer ndarray data element specified by a byte array pointer.
1int8_t stdlib_ndarray_get_ptr_uint8( const uint8_t *idx, uint8_t *out );
The function accepts the following arguments:
[in] uint8_t *
byte array pointer to an ndarray data element.[out] uint8_t *
output address.Notes:
0
.Returns a signed 8-bit integer ndarray data element specified by a byte array pointer.
1int8_t stdlib_ndarray_get_ptr_int8( const uint8_t *idx, int8_t *out );
The function accepts the following arguments:
[in] uint8_t *
byte array pointer to an ndarray data element.[out] int8_t *
output address.Notes:
0
.Returns a double-precision complex floating-point ndarray data element specified by a byte array pointer.
1int8_t stdlib_ndarray_get_ptr_complex128( const uint8_t *idx, stdlib_complex128_t *out );
The function accepts the following arguments:
[in] uint8_t *
byte array pointer to an ndarray data element.[out] stdlib_complex128_t *
output address.Notes:
idx
actually points to a compatible memory address. Accordingly, accessing unowned memory is possible, and this function assumes you know what you are doing.0
.Returns a single-precision complex floating-point ndarray data element specified by a byte array pointer.
1int8_t stdlib_ndarray_get_ptr_complex64( const uint8_t *idx, stdlib_complex64_t *out );
The function accepts the following arguments:
[in] uint8_t *
byte array pointer to an ndarray data element.[out] stdlib_complex64_t *
output address.Notes:
idx
actually points to a compatible memory address. Accordingly, accessing unowned memory is possible, and this function assumes you know what you are doing.0
.Returns a boolean ndarray data element specified by a byte array pointer.
1int8_t stdlib_ndarray_get_ptr_bool( const uint8_t *idx, bool *out );
The function accepts the following arguments:
[in] uint8_t *
byte array pointer to an ndarray data element.[out] bool *
output address.Notes:
idx
actually points to a compatible memory address. Accordingly, accessing unowned memory is possible, and this function assumes you know what you are doing.0
.Returns an ndarray data element located at a specified linear index.
1int8_t stdlib_ndarray_iget( const struct ndarray *arr, const int64_t idx, void *out );
The function accepts the following arguments:
[in] struct ndarray*
input ndarray.[in] int64_t
linear view index.[out] void *
output address.Notes:
-1
if unable to get an element and 0
otherwise.void
pointer for the output address out
in order to provide a generic API supporting ndarrays having different data types.idx
.Returns a double-precision floating-point ndarray data element located at a specified linear index.
1int8_t stdlib_ndarray_iget_float64( const struct ndarray *arr, const int64_t idx, double *out );
The function accepts the following arguments:
[in] struct ndarray*
input ndarray.[in] int64_t
linear view index.[out] double *
output address.Notes:
-1
if unable to get an element and 0
otherwise.idx
.Returns a single-precision floating-point ndarray data element located at a specified linear index.
1int8_t stdlib_ndarray_iget_float32( const struct ndarray *arr, const int64_t idx, float *out );
The function accepts the following arguments:
[in] struct ndarray*
input ndarray.[in] int64_t
linear view index.[out] float *
output address.Notes:
-1
if unable to get an element and 0
otherwise.idx
.Returns an unsigned 64-bit integer ndarray data element located at a specified linear index.
1int8_t stdlib_ndarray_iget_uint64( const struct ndarray *arr, const int64_t idx, uint64_t *out );
The function accepts the following arguments:
[in] struct ndarray*
input ndarray.[in] int64_t
linear view index.[out] uint64_t *
output address.Notes:
-1
if unable to get an element and 0
otherwise.idx
.Returns a signed 64-bit integer ndarray data element located at a specified linear index.
1int8_t stdlib_ndarray_iget_int64( const struct ndarray *arr, const int64_t idx, int64_t *out );
The function accepts the following arguments:
[in] struct ndarray*
input ndarray.[in] int64_t
linear view index.[out] int64_t *
output address.Notes:
-1
if unable to get an element and 0
otherwise.idx
.Returns an unsigned 32-bit integer ndarray data element located at a specified linear index.
1int8_t stdlib_ndarray_iget_uint32( const struct ndarray *arr, const int64_t idx, uint32_t *out );
The function accepts the following arguments:
[in] struct ndarray*
input ndarray.[in] int64_t
linear view index.[out] uint32_t *
output address.Notes:
-1
if unable to get an element and 0
otherwise.idx
.Returns a signed 32-bit integer ndarray data element located at a specified linear index.
1int8_t stdlib_ndarray_iget_int32( const struct ndarray *arr, const int64_t idx, int32_t *out );
The function accepts the following arguments:
[in] struct ndarray*
input ndarray.[in] int64_t
linear view index.[out] int32_t *
output address.Notes:
-1
if unable to get an element and 0
otherwise.idx
.Returns an unsigned 16-bit integer ndarray data element located at a specified linear index.
1int8_t stdlib_ndarray_iget_uint16( const struct ndarray *arr, const int64_t idx, uint16_t *out );
The function accepts the following arguments:
[in] struct ndarray*
input ndarray.[in] int64_t
linear view index.[out] uint16_t *
output address.Notes:
-1
if unable to get an element and 0
otherwise.idx
.Returns a signed 16-bit integer ndarray data element located at a specified linear index.
1int8_t stdlib_ndarray_iget_int16( const struct ndarray *arr, const int64_t idx, int16_t *out );
The function accepts the following arguments:
[in] struct ndarray*
input ndarray.[in] int64_t
linear view index.[out] int16_t *
output address.Notes:
-1
if unable to get an element and 0
otherwise.idx
.Returns an unsigned 8-bit integer ndarray data element located at a specified linear index.
1int8_t stdlib_ndarray_iget_uint8( const struct ndarray *arr, const int64_t idx, uint8_t *out );
The function accepts the following arguments:
[in] struct ndarray*
input ndarray.[in] int64_t
linear view index.[out] uint8_t *
output address.Notes:
-1
if unable to get an element and 0
otherwise.idx
.Returns a signed 8-bit integer ndarray data element located at a specified linear index.
1int8_t stdlib_ndarray_iget_int8( const struct ndarray *arr, const int64_t idx, int8_t *out );
The function accepts the following arguments:
[in] struct ndarray*
input ndarray.[in] int64_t
linear view index.[out] int8_t *
output address.Notes:
-1
if unable to get an element and 0
otherwise.idx
.Returns a double-precision complex floating-point ndarray data element located at a specified linear index.
1int8_t stdlib_ndarray_iget_complex128( const struct ndarray *arr, const int64_t idx, stdlib_complex128_t *out );
The function accepts the following arguments:
[in] struct ndarray*
input ndarray.[in] int64_t
linear view index.[out] stdlib_complex128_t *
output address.Notes:
-1
if unable to get an element and 0
otherwise.idx
.Returns a single-precision complex floating-point ndarray data element located at a specified linear index.
1int8_t stdlib_ndarray_iget_complex64( const struct ndarray *arr, const int64_t idx, stdlib_complex64_t *out );
The function accepts the following arguments:
[in] struct ndarray*
input ndarray.[in] int64_t
linear view index.[out] stdlib_complex64_t *
output address.Notes:
-1
if unable to get an element and 0
otherwise.idx
.Returns a boolean ndarray data element located at a specified linear index.
1int8_t stdlib_ndarray_iget_bool( const struct ndarray *arr, const int64_t idx, bool *out );
The function accepts the following arguments:
[in] struct ndarray*
input ndarray.[in] int64_t
linear view index.[out] bool *
output address.Notes:
-1
if unable to get an element and 0
otherwise.idx
.Returns a pointer in the underlying byte array for an ndarray data element located at a specified linear index.
1uint8_t * stdlib_ndarray_iget_ptr( const struct ndarray *arr, const int64_t idx );
The function accepts the following arguments:
[in] struct ndarray*
input ndarray.[in] int64_t
linear view index.For zero-dimensional arrays, the function returns a pointer to the first (and only) indexed element, regardless of the value of idx
.
Sets an ndarray data element located at a specified linear index.
1int8_t stdlib_ndarray_iset( const struct ndarray *arr, const int64_t idx, const void *v );
The function accepts the following arguments:
[in] struct ndarray*
input ndarray.[in] int64_t
linear view index.[in] void*
value to set.Notes:
-1
if unable to set an element and 0
otherwise.v
in order to provide a generic API supporting ndarrays having different data types.v
actually points to a memory address compatible with the underlying input ndarray data type. Accordingly, accessing unowned memory is possible, and this function assumes you know what you are doing.idx
.Sets a double-precision floating-point ndarray data element located at a specified linear index.
1int8_t stdlib_ndarray_iset_float64( const struct ndarray *arr, const int64_t idx, const double v );
The function accepts the following arguments:
[in] struct ndarray*
input ndarray.[in] int64_t
linear view index.[in] double
value to set.Notes:
v
matches the underlying input ndarray data type, and, thus, overwriting unowned memory is possible. The function assumes that you know what you are doing.-1
if unable to set an element and 0
otherwise.idx
.Sets a single-precision floating-point ndarray data element located at a specified linear index.
1int8_t stdlib_ndarray_iset_float32( const struct ndarray *arr, const int64_t idx, const float v );
The function accepts the following arguments:
[in] struct ndarray*
input ndarray.[in] int64_t
linear view index.[in] float
value to set.Notes:
v
matches the underlying input ndarray data type, and, thus, overwriting unowned memory is possible. The function assumes that you know what you are doing.-1
if unable to set an element and 0
otherwise.idx
.Sets an unsigned 64-bit integer ndarray data element located at a specified linear index.
1int8_t stdlib_ndarray_iset_uint64( const struct ndarray *arr, const int64_t idx, const uint64_t v );
The function accepts the following arguments:
[in] struct ndarray*
input ndarray.[in] int64_t
linear view index.[in] uint64_t
value to set.Notes:
v
matches the underlying input ndarray data type, and, thus, overwriting unowned memory is possible. The function assumes that you know what you are doing.-1
if unable to set an element and 0
otherwise.idx
.Sets a signed 64-bit integer ndarray data element located at a specified linear index.
1int8_t stdlib_ndarray_iset_int64( const struct ndarray *arr, const int64_t idx, const int64_t v );
The function accepts the following arguments:
[in] struct ndarray*
input ndarray.[in] int64_t
linear view index.[in] int64_t
value to set.Notes:
v
matches the underlying input ndarray data type, and, thus, overwriting unowned memory is possible. The function assumes that you know what you are doing.-1
if unable to set an element and 0
otherwise.idx
.Sets an unsigned 32-bit integer ndarray data element located at a specified linear index.
1int8_t stdlib_ndarray_iset_uint32( const struct ndarray *arr, const int64_t idx, const uint32_t v );
The function accepts the following arguments:
[in] struct ndarray*
input ndarray.[in] int64_t
linear view index.[in] uint32_t
value to set.Notes:
v
matches the underlying input ndarray data type, and, thus, overwriting unowned memory is possible. The function assumes that you know what you are doing.-1
if unable to set an element and 0
otherwise.idx
.Sets a signed 32-bit integer ndarray data element located at a specified linear index.
1int8_t stdlib_ndarray_iset_int32( const struct ndarray *arr, const int64_t idx, const int32_t v );
The function accepts the following arguments:
[in] struct ndarray*
input ndarray.[in] int64_t
linear view index.[in] int32_t
value to set.Notes:
v
matches the underlying input ndarray data type, and, thus, overwriting unowned memory is possible. The function assumes that you know what you are doing.-1
if unable to set an element and 0
otherwise.idx
.Sets an unsigned 16-bit integer ndarray data element located at a specified linear index.
1int8_t stdlib_ndarray_iset_uint16( const struct ndarray *arr, const int64_t idx, const uint16_t v );
The function accepts the following arguments:
[in] struct ndarray*
input ndarray.[in] int64_t
linear view index.[in] uint16_t
value to set.Notes:
v
matches the underlying input ndarray data type, and, thus, overwriting unowned memory is possible. The function assumes that you know what you are doing.-1
if unable to set an element and 0
otherwise.idx
.Sets a signed 16-bit integer ndarray data element located at a specified linear index.
1int8_t stdlib_ndarray_iset_int16( const struct ndarray *arr, const int64_t idx, const int16_t v );
The function accepts the following arguments:
[in] struct ndarray*
input ndarray.[in] int64_t
linear view index.[in] int16_t
value to set.Notes:
v
matches the underlying input ndarray data type, and, thus, overwriting unowned memory is possible. The function assumes that you know what you are doing.-1
if unable to set an element and 0
otherwise.idx
.Sets an unsigned 8-bit integer ndarray data element located at a specified linear index.
1int8_t stdlib_ndarray_iset_uint8( const struct ndarray *arr, const int64_t idx, const uint8_t v );
The function accepts the following arguments:
[in] struct ndarray*
input ndarray.[in] int64_t
linear view index.[in] uint8_t
value to set.Notes:
-1
if unable to set an element and 0
otherwise.idx
.Sets a signed 8-bit integer ndarray data element located at a specified linear index.
1int8_t stdlib_ndarray_iset_int8( const struct ndarray *arr, const int64_t idx, const int8_t v );
The function accepts the following arguments:
[in] struct ndarray*
input ndarray.[in] int64_t
linear view index.[in] int8_t
value to set.Notes:
-1
if unable to set an element and 0
otherwise.idx
.Sets a double-precision complex floating-point ndarray data element located at a specified linear index.
1int8_t stdlib_ndarray_iset_complex128( const struct ndarray *arr, const int64_t idx, const stdlib_complex128_t v );
The function accepts the following arguments:
[in] struct ndarray*
input ndarray.[in] int64_t
linear view index.[in] stdlib_complex128_t
value to set.Notes:
v
matches the underlying input ndarray data type, and, thus, overwriting unowned memory is possible. The function assumes that you know what you are doing.-1
if unable to set an element and 0
otherwise.idx
.Sets a single-precision complex floating-point ndarray data element located at a specified linear index.
1int8_t stdlib_ndarray_iset_complex64( const struct ndarray *arr, const int64_t idx, const stdlib_complex64_t v );
The function accepts the following arguments:
[in] struct ndarray*
input ndarray.[in] int64_t
linear view index.[in] stdlib_complex64_t
value to set.Notes:
v
matches the underlying input ndarray data type, and, thus, overwriting unowned memory is possible. The function assumes that you know what you are doing.-1
if unable to set an element and 0
otherwise.idx
.Sets a boolean ndarray data element located at a specified linear index.
1int8_t stdlib_ndarray_iset_bool( const struct ndarray *arr, const int64_t idx, const bool v );
The function accepts the following arguments:
[in] struct ndarray*
input ndarray.[in] int64_t
linear view index.[in] bool
value to set.Notes:
v
matches the underlying input ndarray data type, and, thus, overwriting unowned memory is possible. The function assumes that you know what you are doing.-1
if unable to set an element and 0
otherwise.idx
.Sets an ndarray data element.
1int8_t stdlib_ndarray_set( const struct ndarray *arr, const int64_t *sub, const void *v );
The function accepts the following arguments:
[in] struct ndarray*
input ndarray.[in] int64_t*
ndarray subscripts.[in] void*
value to set.Notes
-1
if unable to set an element and 0
otherwise.v
in order to provide a generic API supporting ndarrays having different data types.v
actually points to a memory address compatible with the underlying input ndarray data type. Accordingly, accessing unowned memory is possible, and this function assumes you know what you are doing.Sets a double-precision floating-point ndarray data element.
1int8_t stdlib_ndarray_set_float64( const struct ndarray *arr, const int64_t *sub, const double v );
The function accepts the following arguments:
[in] struct ndarray*
input ndarray.[in] int64_t*
ndarray subscripts.[in] double
value to set.Notes
v
matches the underlying input ndarray data type, and, thus, overwriting unowned memory is possible. The function assumes that you know what you are doing.-1
if unable to set an element and 0
otherwise.Sets a single-precision floating-point ndarray data element.
1int8_t stdlib_ndarray_set_float32( const struct ndarray *arr, const int64_t *sub, const float v );
The function accepts the following arguments:
[in] struct ndarray*
input ndarray.[in] int64_t*
ndarray subscripts.[in] float
value to set.Notes
v
matches the underlying input ndarray data type, and, thus, overwriting unowned memory is possible. The function assumes that you know what you are doing.-1
if unable to set an element and 0
otherwise.Sets an unsigned 64-bit integer ndarray data element.
1int8_t stdlib_ndarray_set_uint64( const struct ndarray *arr, const int64_t *sub, const uint64_t v );
The function accepts the following arguments:
[in] struct ndarray*
input ndarray.[in] int64_t*
ndarray subscripts.[in] uint64_t
value to set.Notes
v
matches the underlying input ndarray data type, and, thus, overwriting unowned memory is possible. The function assumes that you know what you are doing.-1
if unable to set an element and 0
otherwise.Sets a signed 64-bit integer ndarray data element.
1int8_t stdlib_ndarray_set_int64( const struct ndarray *arr, const int64_t *sub, const int64_t v );
The function accepts the following arguments:
[in] struct ndarray*
input ndarray.[in] int64_t*
ndarray subscripts.[in] int64_t
value to set.Notes
v
matches the underlying input ndarray data type, and, thus, overwriting unowned memory is possible. The function assumes that you know what you are doing.-1
if unable to set an element and 0
otherwise.Sets an unsigned 32-bit integer ndarray data element.
1int8_t stdlib_ndarray_set_uint32( const struct ndarray *arr, const int64_t *sub, const uint32_t v );
The function accepts the following arguments:
[in] struct ndarray*
input ndarray.[in] int64_t*
ndarray subscripts.[in] uint32_t
value to set.Notes
v
matches the underlying input ndarray data type, and, thus, overwriting unowned memory is possible. The function assumes that you know what you are doing.-1
if unable to set an element and 0
otherwise.Sets a signed 32-bit integer ndarray data element.
1int8_t stdlib_ndarray_set_int32( const struct ndarray *arr, const int64_t *sub, const int32_t v );
The function accepts the following arguments:
[in] struct ndarray*
input ndarray.[in] int64_t*
ndarray subscripts.[in] int32_t
value to set.Notes
v
matches the underlying input ndarray data type, and, thus, overwriting unowned memory is possible. The function assumes that you know what you are doing.-1
if unable to set an element and 0
otherwise.Sets an unsigned 16-bit integer ndarray data element.
1int8_t stdlib_ndarray_set_uint16( const struct ndarray *arr, const int64_t *sub, const uint16_t v );
The function accepts the following arguments:
[in] struct ndarray*
input ndarray.[in] int64_t*
ndarray subscripts.[in] uint16_t
value to set.Notes
v
matches the underlying input ndarray data type, and, thus, overwriting unowned memory is possible. The function assumes that you know what you are doing.-1
if unable to set an element and 0
otherwise.Sets a signed 16-bit integer ndarray data element.
1int8_t stdlib_ndarray_set_int16( const struct ndarray *arr, const int64_t *sub, const int16_t v );
The function accepts the following arguments:
[in] struct ndarray*
input ndarray.[in] int64_t*
ndarray subscripts.[in] int16_t
value to set.Notes
v
matches the underlying input ndarray data type, and, thus, overwriting unowned memory is possible. The function assumes that you know what you are doing.-1
if unable to set an element and 0
otherwise.Sets an unsigned 8-bit integer ndarray data element.
1int8_t stdlib_ndarray_set_uint8( const struct ndarray *arr, const int64_t *sub, const uint8_t v );
The function accepts the following arguments:
[in] struct ndarray*
input ndarray.[in] int64_t*
ndarray subscripts.[in] uint8_t
value to set.Notes
-1
if unable to set an element and 0
otherwise.Sets a signed 8-bit integer ndarray data element.
1int8_t stdlib_ndarray_set_int8( const struct ndarray *arr, const int64_t *sub, const int8_t v );
The function accepts the following arguments:
[in] struct ndarray*
input ndarray.[in] int64_t*
ndarray subscripts.[in] int8_t
value to set.Notes
-1
if unable to set an element and 0
otherwise.Sets a double-precision complex floating-point ndarray data element.
1int8_t stdlib_ndarray_set_complex128( const struct ndarray *arr, const int64_t *sub, const stdlib_complex128_t v );
The function accepts the following arguments:
[in] struct ndarray*
input ndarray.[in] int64_t*
ndarray subscripts.[in] stdlib_complex128_t
value to set.Notes
v
matches the underlying input ndarray data type, and, thus, overwriting unowned memory is possible. The function assumes that you know what you are doing.-1
if unable to set an element and 0
otherwise.Sets a single-precision complex floating-point ndarray data element.
1int8_t stdlib_ndarray_set_complex64( const struct ndarray *arr, const int64_t *sub, const stdlib_complex64_t v );
The function accepts the following arguments:
[in] struct ndarray*
input ndarray.[in] int64_t*
ndarray subscripts.[in] stdlib_complex64_t
value to set.Notes
v
matches the underlying input ndarray data type, and, thus, overwriting unowned memory is possible. The function assumes that you know what you are doing.-1
if unable to set an element and 0
otherwise.Sets a boolean ndarray data element.
1int8_t stdlib_ndarray_set_bool( const struct ndarray *arr, const int64_t *sub, const bool v );
The function accepts the following arguments:
[in] struct ndarray*
input ndarray.[in] int64_t*
ndarray subscripts.[in] bool
value to set.Notes
v
matches the underlying input ndarray data type, and, thus, overwriting unowned memory is possible. The function assumes that you know what you are doing.-1
if unable to set an element and 0
otherwise.Sets an ndarray data element specified by a byte array pointer.
1int8_t stdlib_ndarray_set_ptr_value( const struct ndarray *arr, uint8_t *idx, const void *v );
The function accepts the following arguments:
[in] struct ndarray*
input ndarray.[in] uint8_t*
byte array pointer to an ndarray data element.[in] void*
value to set.Notes:
-1
if unable to set an element and 0
otherwise.v
in order to provide a generic API supporting ndarrays having different data types.Sets a double-precision floating-point ndarray data element specified by a byte array pointer.
1int8_t stdlib_ndarray_set_ptr_float64( uint8_t *idx, const double v );
The function accepts the following arguments:
[in] uint8_t*
byte array pointer to an ndarray data element.[in] double
value to set.Notes:
idx
actually points to a compatible memory address. Accordingly, overwriting unowned memory is possible, and this function assumes you know what you are doing.0
.Sets a single-precision floating-point ndarray data element specified by a byte array pointer.
1int8_t stdlib_ndarray_set_ptr_float32( uint8_t *idx, const float v );
The function accepts the following arguments:
[in] uint8_t*
byte array pointer to an ndarray data element.[in] float
value to set.Notes:
idx
actually points to a compatible memory address. Accordingly, overwriting unowned memory is possible, and this function assumes you know what you are doing.0
.Sets an unsigned 64-bit integer ndarray data element specified by a byte array pointer.
1int8_t stdlib_ndarray_set_ptr_uint64( uint8_t *idx, const uint64_t v );
The function accepts the following arguments:
[in] uint8_t*
byte array pointer to an ndarray data element.[in] uint64_t
value to set.Notes:
idx
actually points to a compatible memory address. Accordingly, overwriting unowned memory is possible, and this function assumes you know what you are doing.0
.Sets a signed 64-bit integer ndarray data element specified by a byte array pointer.
1int8_t stdlib_ndarray_set_ptr_int64( uint8_t *idx, const int64_t v );
The function accepts the following arguments:
[in] uint8_t*
byte array pointer to an ndarray data element.[in] int64_t
value to set.Notes:
idx
actually points to a compatible memory address. Accordingly, overwriting unowned memory is possible, and this function assumes you know what you are doing.0
.Sets an unsigned 32-bit integer ndarray data element specified by a byte array pointer.
1int8_t stdlib_ndarray_set_ptr_uint32( uint8_t *idx, const uint32_t v );
The function accepts the following arguments:
[in] uint8_t*
byte array pointer to an ndarray data element.[in] uint32_t
value to set.Notes:
idx
actually points to a compatible memory address. Accordingly, overwriting unowned memory is possible, and this function assumes you know what you are doing.0
.Sets a signed 32-bit integer ndarray data element specified by a byte array pointer.
1int8_t stdlib_ndarray_set_ptr_int32( uint8_t *idx, const int32_t v );
The function accepts the following arguments:
[in] uint8_t*
byte array pointer to an ndarray data element.[in] int32_t
value to set.Notes:
idx
actually points to a compatible memory address. Accordingly, overwriting unowned memory is possible, and this function assumes you know what you are doing.0
.Sets an unsigned 16-bit integer ndarray data element specified by a byte array pointer.
1int8_t stdlib_ndarray_set_ptr_uint16( uint8_t *idx, const uint16_t v );
The function accepts the following arguments:
[in] uint8_t*
byte array pointer to an ndarray data element.[in] uint16_t
value to set.Notes:
idx
actually points to a compatible memory address. Accordingly, overwriting unowned memory is possible, and this function assumes you know what you are doing.0
.Sets a signed 16-bit integer ndarray data element specified by a byte array pointer.
1int8_t stdlib_ndarray_set_ptr_int16( uint8_t *idx, const int16_t v );
The function accepts the following arguments:
[in] uint8_t*
byte array pointer to an ndarray data element.[in] int16_t
value to set.Notes:
idx
actually points to a compatible memory address. Accordingly, overwriting unowned memory is possible, and this function assumes you know what you are doing.0
.Sets an unsigned 8-bit integer ndarray data element specified by a byte array pointer.
1int8_t stdlib_ndarray_set_ptr_uint8( uint8_t *idx, const uint8_t v );
The function accepts the following arguments:
[in] uint8_t*
byte array pointer to an ndarray data element.[in] uint8_t
value to set.Notes:
0
.Sets a signed 8-bit integer ndarray data element specified by a byte array pointer.
1int8_t stdlib_ndarray_set_ptr_int8( uint8_t *idx, const int8_t v );
The function accepts the following arguments:
[in] uint8_t*
byte array pointer to an ndarray data element.[in] int8_t
value to set.Notes:
0
.Sets a double-precision complex floating-point ndarray data element specified by a byte array pointer.
1int8_t stdlib_ndarray_set_ptr_complex128( uint8_t *idx, const stdlib_complex128_t v );
The function accepts the following arguments:
[in] uint8_t*
byte array pointer to an ndarray data element.[in] stdlib_complex128_t
value to set.Notes:
idx
actually points to a compatible memory address. Accordingly, overwriting unowned memory is possible, and this function assumes you know what you are doing.0
.Sets a single-precision complex floating-point ndarray data element specified by a byte array pointer.
1int8_t stdlib_ndarray_set_ptr_complex64( uint8_t *idx, const stdlib_complex64_t v );
The function accepts the following arguments:
[in] uint8_t*
byte array pointer to an ndarray data element.[in] stdlib_complex64_t
value to set.Notes:
idx
actually points to a compatible memory address. Accordingly, overwriting unowned memory is possible, and this function assumes you know what you are doing.0
.Sets a boolean ndarray data element specified by a byte array pointer.
1int8_t stdlib_ndarray_set_ptr_bool( uint8_t *idx, const bool v );
The function accepts the following arguments:
[in] uint8_t*
byte array pointer to an ndarray data element.[in] bool
value to set.Notes:
idx
actually points to a compatible memory address. Accordingly, overwriting unowned memory is possible, and this function assumes you know what you are doing.0
.1#include "stdlib/ndarray/ctor.h" 2#include "stdlib/ndarray/dtypes.h" 3#include "stdlib/ndarray/index_modes.h" 4#include "stdlib/ndarray/orders.h" 5#include "stdlib/ndarray/base/bytes_per_element.h" 6#include "stdlib/ndarray/base/dtype_char.h" 7#include <stdlib.h> 8#include <stdio.h> 9#include <stdint.h> 10#include <inttypes.h> 11 12void print_ndarray_contents( const struct ndarray *x ) { 13 int64_t i; 14 double v; 15 int8_t s; 16 17 for ( i = 0; i < stdlib_ndarray_length( x ); i++ ) { 18 s = stdlib_ndarray_iget_float64( x, i, &v ); // WARNING: assumes `x->dtype` is float64 19 if ( s != 0 ) { 20 printf( "Unable to resolve data element.\n" ); 21 exit( 1 ); 22 } 23 printf( "data[%"PRId64"] = %f\n", i, v ); 24 } 25} 26 27int main( void ) { 28 // Manually create an ndarray (WARNING: this is for illustration purposes only, as the fields of an ndarray are subject to change; for ABI compatibility, use utility functions for accessing ndarray data)... 29 struct ndarray *x1 = malloc( sizeof( struct ndarray ) ); 30 if ( x1 == NULL ) { 31 printf( "Error allocating memory.\n" ); 32 exit( 1 ); 33 } 34 35 // Specify the underlying data type: 36 enum STDLIB_NDARRAY_DTYPE dtype = STDLIB_NDARRAY_FLOAT64; 37 x1->dtype = dtype; 38 39 // Create an underlying byte array: 40 uint8_t buffer[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; 41 x1->data = buffer; 42 43 // Explicitly specify the number of bytes per element: 44 x1->BYTES_PER_ELEMENT = STDLIB_NDARRAY_FLOAT64_BYTES_PER_ELEMENT; 45 46 // Specify the array shape: 47 int64_t shape[] = { 3 }; // vector consisting of 3 doubles 48 x1->shape = shape; 49 50 // Specify the array strides: 51 int64_t strides[] = { x1->BYTES_PER_ELEMENT }; 52 x1->strides = strides; 53 54 // Specify the byte offset: 55 x1->offset = 0; 56 57 // Specify the array order (note: this does not matter for a 1-dimensional array): 58 enum STDLIB_NDARRAY_ORDER order = STDLIB_NDARRAY_ROW_MAJOR; 59 x1->order = order; 60 61 // Specify the index mode: 62 enum STDLIB_NDARRAY_INDEX_MODE imode = STDLIB_NDARRAY_INDEX_ERROR; 63 x1->imode = imode; 64 65 // Specify the subscript index modes: 66 int8_t submodes[] = { imode }; 67 x1->submodes = submodes; 68 x1->nsubmodes = 1; 69 70 // Explicitly specify the number of array dimensions: 71 x1->ndims = 1; // vector 72 73 // Explicitly specify the number of array elements (doubles): 74 x1->length = x1->shape[ 0 ]; 75 76 // Explicitly specify the number of bytes: 77 x1->byteLength = (x1->length) * (x1->BYTES_PER_ELEMENT); 78 79 // Explicitly set the array flags: 80 x1->flags = stdlib_ndarray_flags( x1 ); 81 82 printf( "dtype = %u\n", stdlib_ndarray_dtype( x1 ) ); 83 printf( "length = %"PRId64"\n", stdlib_ndarray_length( x1 ) ); 84 printf( "byteLength = %"PRId64"\n", stdlib_ndarray_bytelength( x1 ) ); 85 printf( "ltr = %u\n", stdlib_ndarray_dtype_char( stdlib_ndarray_dtype( x1 ) ) ); 86 printf( "\n" ); 87 88 // Use the function interface to create an ndarray (NOTE: for future ABI compatibility, using the following function interface should be preferred)... 89 struct ndarray *x2 = stdlib_ndarray_allocate( dtype, buffer, 1, shape, strides, 0, order, imode, 1, submodes ); 90 if ( x2 == NULL ) { 91 printf( "Error allocating memory.\n" ); 92 exit( 1 ); 93 } 94 95 printf( "dtype = %u\n", stdlib_ndarray_dtype( x2 ) ); 96 printf( "length = %"PRId64"\n", stdlib_ndarray_length( x2 ) ); 97 printf( "byteLength = %"PRId64"\n", stdlib_ndarray_bytelength( x2 ) ); 98 printf( "ltr = %u\n", stdlib_ndarray_dtype_char( stdlib_ndarray_dtype( x2 ) ) ); 99 printf( "\n" ); 100 101 // Set values in the underlying byte array using pointers: 102 int64_t sub[] = { 0 }; 103 uint8_t *ptr = stdlib_ndarray_get_ptr( x2, sub ); 104 if ( ptr == NULL ) { 105 printf( "Unable to resolve data pointer.\n" ); 106 exit( 1 ); 107 } 108 *(double *)ptr = 1.0; 109 110 sub[ 0 ] = 1; 111 ptr = stdlib_ndarray_get_ptr( x2, sub ); 112 if ( ptr == NULL ) { 113 printf( "Unable to resolve data pointer.\n" ); 114 exit( 1 ); 115 } 116 *(double *)ptr = 2.0; 117 118 sub[ 0 ] = 2; 119 ptr = stdlib_ndarray_get_ptr( x2, sub ); 120 if ( ptr == NULL ) { 121 printf( "Unable to resolve data pointer.\n" ); 122 exit( 1 ); 123 } 124 *(double *)ptr = 3.0; 125 126 // Print out the current ndarray elements: 127 print_ndarray_contents( x2 ); 128 printf( "\n" ); 129 130 // Set values in the underlying byte array using a "generic" function: 131 sub[ 0 ] = 0; 132 double v = 4.0; 133 int8_t status = stdlib_ndarray_set( x2, sub, (void *)&v ); 134 if ( status != 0 ) { 135 printf( "Unable to set data element.\n" ); 136 exit( 1 ); 137 } 138 139 sub[ 0 ] = 1; 140 v = 5.0; 141 status = stdlib_ndarray_set( x2, sub, (void *)&v ); 142 if ( status != 0 ) { 143 printf( "Unable to set data element.\n" ); 144 exit( 1 ); 145 } 146 147 sub[ 0 ] = 2; 148 v = 6.0; 149 status = stdlib_ndarray_set( x2, sub, (void *)&v ); 150 if ( status != 0 ) { 151 printf( "Unable to set data element.\n" ); 152 exit( 1 ); 153 } 154 155 // Print out the current ndarray elements: 156 print_ndarray_contents( x2 ); 157 printf( "\n" ); 158 159 // Set values in the underlying byte array using a specialized function: 160 sub[ 0 ] = 0; 161 status = stdlib_ndarray_set_float64( x2, sub, 7.0 ); 162 if ( status != 0 ) { 163 printf( "Unable to set data element.\n" ); 164 exit( 1 ); 165 } 166 167 sub[ 0 ] = 1; 168 status = stdlib_ndarray_set_float64( x2, sub, 8.0 ); 169 if ( status != 0 ) { 170 printf( "Unable to set data element.\n" ); 171 exit( 1 ); 172 } 173 174 sub[ 0 ] = 2; 175 status = stdlib_ndarray_set_float64( x2, sub, 9.0 ); 176 if ( status != 0 ) { 177 printf( "Unable to set data element.\n" ); 178 exit( 1 ); 179 } 180 181 // Print out the current ndarray elements: 182 print_ndarray_contents( x2 ); 183 printf( "\n" ); 184 185 // Free allocated memory: 186 stdlib_ndarray_free( x1 ); 187 stdlib_ndarray_free( x2 ); 188}
@stdlib/ndarray-array
: multidimensional arrays.@stdlib/ndarray-fancy
: fancy multidimensional array constructor.This package is part of stdlib, a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more.
For more information on the project, filing bug reports and feature requests, and guidance on how to develop stdlib, see the main project repository.
See LICENSE.
Copyright © 2016-2024. The Stdlib Authors.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
no dangerous workflow patterns detected
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
security policy file detected
Details
Reason
dependency not pinned by hash detected -- score normalized to 3
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
Found 0/30 approved changesets -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no SAST tool detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Score
Last Scanned on 2024-11-18
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More