About stdlib...
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.
npm install @stdlib/ndarray-ctorAlternatively,
- To load the package in a website via a
scripttag without installation and bundlers, use the ES Module available on theesmbranch (see README). - If you are using Deno, visit the
denobranch (see README for usage intructions). - For use in Observable, or in browser/node environments, use the Universal Module Definition (UMD) build available on the
umdbranch (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.
varndarray=require('@stdlib/ndarray-ctor');Returns an ndarray instance.
// Specify the array configuration:varbuffer=[1.0,2.0,3.0,4.0];varshape=[2,2];varorder='row-major';varstrides=[2,1];varoffset=0;// Create a new ndarray:vararr=ndarray('generic',buffer,shape,strides,offset,order);// returns <ndarray>The constructor expects the following arguments:
- dtype: underlying data type.
- buffer: data buffer.
- shape: array shape (dimensions).
- strides: array strides which are index offsets specifying how to access along corresponding dimensions.
- offset: index offset specifying the location of the first indexed element in the data buffer.
- order: array order, which is either
row-major(C-style) orcolumn-major(Fortran-style).
The constructor accepts the following options:
- mode: specifies how to handle indices which exceed array dimensions. Default:
'throw'. - submode: a mode array which specifies for each dimension how to handle subscripts which exceed array dimensions. If provided fewer modes than dimensions, the constructor recycles modes using modulo arithmetic. Default:
[ options.mode ]. - readonly:
booleanindicating whether an array should be read-only. Default:false.
The constructor supports the following modes:
- throw: specifies that an
ndarrayinstance should throw an error when an index exceeds array dimensions. - normalize: specifies that an
ndarrayinstance should normalize negative indices and throw an error when an index exceeds array dimensions. - wrap: specifies that an
ndarrayinstance should wrap around an index exceeding array dimensions using modulo arithmetic. - clamp: specifies that an
ndarrayinstance should set an index exceeding array dimensions to either0(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.
varopts={'mode': 'clamp'};// Specify the array configuration:varbuffer=[1.0,2.0,3.0,4.0];varshape=[2,2];varorder='row-major';varstrides=[2,1];varoffset=0;// Create a new ndarray:vararr=ndarray('generic',buffer,shape,strides,offset,order,opts);// returns <ndarray>// Attempt to access an out-of-bounds linear index (clamped):varv=arr.iget(10);// returns 4.0By default, the mode option is applied to subscripts which exceed array dimensions. To specify behavior for each dimension, set the submode option.
varopts={'submode': ['wrap','clamp']};// Specify the array configuration:varbuffer=[1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0];varshape=[2,2,2];varorder='row-major';varstrides=[4,2,1];varoffset=0;// Create a new ndarray:vararr=ndarray('generic',buffer,shape,strides,offset,order,opts);// returns <ndarray>// Attempt to access out-of-bounds subscripts:varv=arr.get(-2,10,-1);// linear index: 3// returns 4.0String value of the ndarray constructor name.
varstr=ndarray.name;// returns 'ndarray'Size (in bytes) of the array (if known).
varFloat64Array=require('@stdlib/array-float64');// Specify the array configuration:varbuffer=newFloat64Array([1.0,2.0,3.0,4.0]);varshape=[2,2];varorder='row-major';varstrides=[2,1];varoffset=0;// Create a new ndarray:vararr=ndarray('float64',buffer,shape,strides,offset,order);// Get the byte length:varnbytes=arr.byteLength;// returns 32If unable to determine the size of the array, the property value is null.
// Specify the array configuration:varbuffer=[1.0,2.0,3.0,4.0];varshape=[2,2];varorder='row-major';varstrides=[2,1];varoffset=0;// Create a new ndarray:vararr=ndarray('generic',buffer,shape,strides,offset,order);// Get the byte length:varnbytes=arr.byteLength;// returns nullSize (in bytes) of each array element (if known).
varFloat32Array=require('@stdlib/array-float32');// Specify the array configuration:varbuffer=newFloat32Array([1.0,2.0,3.0,4.0]);varshape=[2,2];varorder='row-major';varstrides=[2,1];varoffset=0;// Create a new ndarray:vararr=ndarray('float32',buffer,shape,strides,offset,order);// Get the number of bytes per element:varnbytes=arr.BYTES_PER_ELEMENT;// returns 4If size of each array element is unknown, the property value is null.
// Specify the array configuration:varbuffer=[1.0,2.0,3.0,4.0];varshape=[2,2];varorder='row-major';varstrides=[2,1];varoffset=0;// Create a new ndarray:vararr=ndarray('generic',buffer,shape,strides,offset,order);// Get the number of bytes per element:varnbytes=arr.BYTES_PER_ELEMENT;// returns nullA reference to the underlying data buffer.
varInt8Array=require('@stdlib/array-int8');// Specify the array configuration:varbuffer=newInt8Array([1,2,3,4]);varshape=[2,2];varorder='row-major';varstrides=[2,1];varoffset=0;// Create a new ndarray:vararr=ndarray('int8',buffer,shape,strides,offset,order);// Get the buffer reference:vard=arr.data;// returns <Int8Array>[ 1, 2, 3, 4 ]varbool=(d===buffer);// returns trueUnderlying data type.
varUint8Array=require('@stdlib/array-uint8');// Specify the array configuration:varbuffer=newUint8Array([1,2,3,4]);varshape=[2,2];varorder='row-major';varstrides=[-2,1];varoffset=2;// Create a new ndarray:vararr=ndarray('uint8',buffer,shape,strides,offset,order);// Get the underlying data type:vardtype=arr.dtype;// returns 'uint8'Meta information, such as information regarding the memory layout of the array. The returned object has the following properties:
- ROW_MAJOR_CONTIGUOUS: boolean indicating if an array is row-major contiguous.
- COLUMN_MAJOR_CONTIGUOUS: boolean indicating if an array is column-major contiguous.
- READONLY: 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]).
varInt32Array=require('@stdlib/array-int32');// Specify the array configuration:varbuffer=newInt32Array([1,2,3,4]);varshape=[2,2];varorder='column-major';varstrides=[1,2];varoffset=0;// Create a new ndarray:vararr=ndarray('int32',buffer,shape,strides,offset,order);// Get the array flags:varflg=arr.flags;// returns {...}Number of array elements.
varUint16Array=require('@stdlib/array-uint16');// Specify the array configuration:varbuffer=newUint16Array([1,2,3,4]);varshape=[2,2];varorder='column-major';varstrides=[-1,-2];varoffset=3;// Create a new ndarray:vararr=ndarray('uint16',buffer,shape,strides,offset,order);// Get the array length:varlen=arr.length;// returns 4Number of dimensions.
varUint8ClampedArray=require('@stdlib/array-uint8c');// Specify the array configuration:varbuffer=newUint8ClampedArray([1,2,3,4]);varshape=[2,2];varorder='row-major';varstrides=[-2,-1];varoffset=3;// Create a new ndarray:vararr=ndarray('uint8c',buffer,shape,strides,offset,order);// Get the number of dimensions:varndims=arr.ndims;// returns 2Index offset which specifies the buffer index at which to start iterating over array elements.
varInt16Array=require('@stdlib/array-int16');// Specify the array configuration:varbuffer=newInt16Array([1,2,3,4,5,6,7,8,9,10,11,12]);varshape=[2,2];varorder='row-major';varstrides=[-2,-1];varoffset=10;// Create a new ndarray:vararr=ndarray('int16',buffer,shape,strides,offset,order);// Get the index offset:varo=arr.offset;// returns 10Array order. The array order is either row-major (C-style) or column-major (Fortran-style).
varUint32Array=require('@stdlib/array-uint32');// Specify the array configuration:varbuffer=newUint32Array([1,2,3,4]);varshape=[2,2];varorder='row-major';varstrides=[2,1];varoffset=0;// Create a new ndarray:vararr=ndarray('uint32',buffer,shape,strides,offset,order);// Get the array order:varord=arr.order;// returns 'row-major'Returns a copy of the array shape.
// Specify the array configuration:varbuffer=[1.0,2.0,3.0,4.0,5.0,6.0];varshape=[2,2];varorder='row-major';varstrides=[2,1];varoffset=2;// Create a new ndarray:vararr=ndarray('generic',buffer,shape,strides,offset,order);// Get the array shape:vardims=arr.shape;// returns [ 2, 2 ]Returns a copy of the array strides which specify how to access data along corresponding array dimensions.
// Specify the array configuration:varbuffer=[1.0,2.0,3.0,4.0];varshape=[2,2];varorder='column-major';varstrides=[-1,2];varoffset=1;// Create a new ndarray:vararr=ndarray('generic',buffer,shape,strides,offset,order);// Get the array strides:vars=arr.strides;// returns [ -1, 2 ]Returns an array element specified according to provided subscripts. The number of provided subscripts must equal the number of dimensions.
// Specify the array configuration:varbuffer=[1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0];varshape=[2,2];varorder='row-major';varstrides=[2,1];varoffset=2;// Create a new ndarray:vararr=ndarray('generic',buffer,shape,strides,offset,order);// Get the element located at (1,1):varv=arr.get(1,1);// returns 6.0Returns an array element located at a specified linear index.
// Specify the array configuration:varbuffer=[1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0];varshape=[2,2];varorder='row-major';varstrides=[2,1];varoffset=2;// Create a new ndarray:vararr=ndarray('generic',buffer,shape,strides,offset,order);// Get the element located at index 3:varv=arr.iget(3);// returns 6.0For 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.
// Specify the array configuration:varbuffer=[1.0,2.0,3.0,4.0];varshape=[2,2];varorder='row-major';varstrides=[2,1];varoffset=0;// Create a new ndarray:vararr=ndarray('generic',buffer,shape,strides,offset,order);// Set the element located at (1,1):arr.set(1,1,40.0);varv=arr.get(1,1);// returns 40.0// Get the underlying buffer:vard=arr.data;// 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.
// Specify the array configuration:varbuffer=[1.0,2.0,3.0,4.0];varshape=[2,2];varorder='row-major';varstrides=[2,1];varoffset=0;// Create a new ndarray:vararr=ndarray('generic',buffer,shape,strides,offset,order);// Set the element located at index 3:arr.iset(3,40.0);varv=arr.iget(3);// returns 40.0// Get the underlying buffer:vard=arr.data;// 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.
// Specify the array configuration:varbuffer=[1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0];varshape=[3,2];varorder='row-major';varstrides=[2,1];varoffset=2;// Create a new ndarray:vararr=ndarray('generic',buffer,shape,strides,offset,order);// Serialize to a string:varstr=arr.toString();// 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 JSONobject. JSON.stringify() implicitly calls this method when stringifying an ndarray instance.
// Specify the array configuration:varbuffer=[1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0];varshape=[3,2];varorder='row-major';varstrides=[2,1];varoffset=2;// Create a new ndarray:vararr=ndarray('generic',buffer,shape,strides,offset,order);// Serialize to JSON:varo=arr.toJSON();// 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
shapeand a singlestrideselement equal to0. Theordercan be eitherrow-majororcolumn-majorand has no effect on data storage or access.varbuffer=[1];varshape=[];varorder='row-major';varstrides=[0];varoffset=0;// Create a new zero-dimensional array:vararr=ndarray('generic',buffer,shape,strides,offset,order);// returns <ndarray>
varFloat32Array=require('@stdlib/array-float32');varndarray=require('@stdlib/ndarray-ctor');// Create a data buffer:varbuffer=newFloat32Array((3*3*3*3)+100);// Specify the array shape:varshape=[3,3,3,3];// Specify the array strides:varstrides=[27,9,3,1];// Specify the index offset:varoffset=4;// Specify the order:varorder='row-major';// C-style// Create a new ndarray:vararr=ndarray('float32',buffer,shape,strides,offset,order);// Retrieve an array value:varv=arr.get(1,2,1,2);// returns 0.0// Set an array value:arr.set(1,2,1,2,10.0);// Retrieve the array value:v=arr.get(1,2,1,2);// returns 10.0// Serialize the array as a string:varstr=arr.toString();// 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' )"// Serialize the array as JSON:str=JSON.stringify(arr.toJSON());// 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]}'#include"stdlib/ndarray/ctor.h"Structure holding ndarray data.
#include"stdlib/ndarray/dtypes.h"#include"stdlib/ndarray/index_modes.h"#include"stdlib/ndarray/orders.h"#include"stdlib/ndarray/base/bytes_per_element.h"#include<stdint.h>structndarray {
// Underlying data type:int16_tdtype;
// Pointer to the underlying byte array:uint8_t*data;
// Number of array dimensions:int64_tndims;
// Array shape (dimensions):int64_t*shape;
// Array strides (in bytes) specifying how to iterate over a strided array:int64_t*strides;
// Byte offset which specifies the location at which to start iterating over array elements:int64_toffset;
// Array order (either row-major (C-style) or column-major (Fortran-style)):int8_torder;
// Mode specifying how to handle indices which exceed array dimensions:int8_timode;
// Number of subscript modes:int64_tnsubmodes;
// Mode(s) specifying how to handle subscripts which exceed array dimensions on a per dimension basis:int8_t*submodes;
// Number of array elements:int64_tlength;
// Size in bytes:int64_tbyteLength;
// Number of bytes per element (i.e., item size):int64_tBYTES_PER_ELEMENT;
// Bit mask providing information regarding the memory layout of the array (e.g., see macros):int64_tflags;
};Macro defining a flag indicating whether an ndarray is row-major (C-style) contiguous.
#defineSTDLIB_NDARRAY_ROW_MAJOR_CONTIGUOUS_FLAG 0x0001Notes:
- Row-major order indicates that the last ndarray index varies the fastest.
- Contiguous means that an ndarray is compatible with being stored in a single memory segment and that ndarray elements are adjacent to each other in memory.
stridesarray is in reverse order to that of column-major order.- An ndarray can be both row-major and column-major contiguous (e.g., if an ndarray is one-dimensional).
Macro defining a flag indicating whether an ndarray is column-major (Fortran-style) contiguous.
#defineSTDLIB_NDARRAY_COLUMN_MAJOR_CONTIGUOUS_FLAG 0x0002Notes:
- Column-major order indicates that the first ndarray index varies the fastest.
- Contiguous means that an ndarray is compatible with being stored in a single memory segment and that ndarray elements are adjacent to each other in memory.
stridesarray is in reverse order to that of row-major order.- An ndarray can be both row-major and column-major contiguous (e.g., if an ndarray is one-dimensional).
stdlib_ndarray_allocate( dtype, *data, ndims, *shape, *strides, offset, order, imode, nsubmodes, *submodes )
Returns a pointer to a dynamically allocated ndarray.
#include"stdlib/ndarray/ctor.h"#include"stdlib/ndarray/dtypes.h"#include"stdlib/ndarray/index_modes.h"#include"stdlib/ndarray/orders.h"#include"stdlib/ndarray/base/bytes_per_element.h"#include<stdlib.h>#include<stdio.h>#include<stdint.h>// Specify the underlying data type:enumSTDLIB_NDARRAY_DTYPEdtype=STDLIB_NDARRAY_FLOAT64;
// Create an underlying byte array:uint8_tbuffer[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
// Specify the number of array dimensions:int64_tndims=1;
// Specify the array shape:int64_tshape[] = { 3 }; // vector consisting of 3 doubles// Specify the array strides:int64_tstrides[] = { STDLIB_NDARRAY_FLOAT64_BYTES_PER_ELEMENT };
// Specify the byte offset:int64_toffset=0;
// Specify the array order (note: this does not matter for a 1-dimensional array):enumSTDLIB_NDARRAY_ORDERorder=STDLIB_NDARRAY_ROW_MAJOR;
// Specify the index mode:enumSTDLIB_NDARRAY_INDEX_MODEimode=STDLIB_NDARRAY_INDEX_ERROR;
// Specify the subscript index modes:int8_tsubmodes[] = { STDLIB_NDARRAY_INDEX_ERROR };
int64_tnsubmodes=1;
// Create an ndarray:structndarray*x=stdlib_ndarray_allocate( dtype, buffer, ndims, shape, strides, offset, order, imode, nsubmodes, submodes );
if ( x==NULL ) {
fprintf( stderr, "Error allocating memory.\n" );
exit( 1 );
}
// Free allocated memory:stdlib_ndarray_free( x );The function accepts the following arguments:
- dtype:
[in] int16_tdata type. - data:
[in] uint8_t*pointer to the underlying byte array. - ndims:
[in] int64_tnumber of dimensions. - shape:
[in] int64_t*array shape (i.e., dimensions). - strides:
[in] int64_t*array strides (in bytes). - offset:
[in] int64_tbyte offset specifying the location of the first element. - order:
[in] int8_tspecifies whether an array is row-major (C-style) or column-major (Fortran-style). - imode:
[in] int8_tspecifies the index mode (i.e., how to handle indices which exceed array dimensions). - nsubmodes:
[in] int64_tnumber of subscript modes. - submodes:
[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).
structndarray*stdlib_ndarray_allocate( int16_tdtype, uint8_t*data, int64_tndims, int64_t*shape, int64_t*strides, int64_toffset, int8_torder, int8_timode, int64_tnsubmodes, int8_t*submodes );Notes:
- The user is responsible for freeing the allocated memory.
- To allocate a zero-dimensional ndarray, provide a
shapeargument equal to a null pointer, anndimsargument equal to0, and astridesargument consisting of a single element equal to0. Theorderargument can be either row-major or column-major and has no effect on data storage or access.
Returns the size of an ndarray (in bytes).
#include"stdlib/ndarray/ctor.h"#include<stdint.h>#include<stdlib.h>#include<stdio.h>// ...// Create an ndarray:structndarray*x=stdlib_ndarray_allocate( ... );
if ( x==NULL ) {
fprintf( stderr, "Error allocating memory.\n" );
exit( 1 );
}
// ...// Retrieve the ndarray size:int64_tN=stdlib_ndarray_byte_length( x );
// ...// Free allocated memory:stdlib_ndarray_free( x );The function accepts the following arguments:
- arr:
[in] struct ndarray*input ndarray.
int64_tstdlib_ndarray_byte_length( conststructndarray*arr );Returns the number of bytes per ndarray element.
#include"stdlib/ndarray/ctor.h"#include<stdint.h>#include<stdlib.h>#include<stdio.h>// ...// Create an ndarray:structndarray*x=stdlib_ndarray_allocate( ... );
if ( x==NULL ) {
fprintf( stderr, "Error allocating memory.\n" );
exit( 1 );
}
// ...// Retrieve the number of bytes per element:int64_tnb=stdlib_ndarray_byte_length_per_element( x );
// ...// Free allocated memory:stdlib_ndarray_free( x );The function accepts the following arguments:
- arr:
[in] struct ndarray*input ndarray.
int64_tstdlib_ndarray_byte_length_per_element( conststructndarray*arr );Returns a pointer to an ndarray's underlying byte array.
#include"stdlib/ndarray/ctor.h"#include<stdint.h>#include<stdlib.h>#include<stdio.h>// ...// Create an ndarray:structndarray*x=stdlib_ndarray_allocate( ... );
if ( x==NULL ) {
fprintf( stderr, "Error allocating memory.\n" );
exit( 1 );
}
// ...// Retrieve the underlying byte array:uint8_t*data=stdlib_ndarray_data( x );
// ...// Free allocated memory:stdlib_ndarray_free( x );The function accepts the following arguments:
- arr:
[in] struct ndarray*input ndarray.
uint8_t*stdlib_ndarray_data( conststructndarray*arr );Returns an ndarray dimension.
#include"stdlib/ndarray/ctor.h"#include<stdint.h>#include<stdlib.h>#include<stdio.h>// ...// Create an ndarray:structndarray*x=stdlib_ndarray_allocate( ... );
if ( x==NULL ) {
fprintf( stderr, "Error allocating memory.\n" );
exit( 1 );
}
// ...// Retrieve a dimension:int64_tdim=stdlib_ndarray_dimension( x, 0 );
// ...// Free allocated memory:stdlib_ndarray_free( x );The function accepts the following arguments:
- arr:
[in] struct ndarray*input ndarray. - i:
[in] int64_tdimension index.
int64_tstdlib_ndarray_dimension( conststructndarray*arr, constint64_ti );Notes:
- The function does perform bounds checking for the dimension index.
- If an input ndarray is zero-dimensional, the function always returns
-1.
Disables specified ndarray flags.
#include"stdlib/ndarray/ctor.h"#include<stdint.h>#include<stdlib.h>#include<stdio.h>// ...// Create an ndarray:structndarray*x=stdlib_ndarray_allocate( ... );
if ( x==NULL ) {
fprintf( stderr, "Error allocating memory.\n" );
exit( 1 );
}
// ...// Disables specified ndarray flags:int8_tstatus=stdlib_ndarray_disable_flags( x, STDLIB_NDARRAY_ROW_MAJOR_CONTIGUOUS_FLAG );
// ...// Free allocated memory:stdlib_ndarray_free( x );The function accepts the following arguments:
- arr:
[in] struct ndarray*input ndarray. - flags:
[in] int64_tbit mask to disable flags.
The function returns a status code of 0 if able to successfully disable flags.
int8_tstdlib_ndarray_disable_flags( conststructndarray*arr, constint64_tflags );Notes:
- The function does not perform any sanity checks and assumes the user knows what s/he is doing.
Returns the data type of an ndarray.
#include"stdlib/ndarray/ctor.h"#include"stdlib/ndarray/dtypes.h"#include<stdlib.h>#include<stdio.h>// ...// Create an ndarray:structndarray*x=stdlib_ndarray_allocate( ... );
if ( x==NULL ) {
fprintf( stderr, "Error allocating memory.\n" );
exit( 1 );
}
// ...// Retrieve the dtype:enumSTDLIB_NDARRAY_DTYPEdtype=stdlib_ndarray_dtype( x );
// ...// Free allocated memory:stdlib_ndarray_free( x );The function accepts the following arguments:
- arr:
[in] struct ndarray*input ndarray.
int16_tstdlib_ndarray_dtype( conststructndarray*arr );Enables specified ndarray flags.
#include"stdlib/ndarray/ctor.h"#include<stdint.h>#include<stdlib.h>#include<stdio.h>// ...// Create an ndarray:structndarray*x=stdlib_ndarray_allocate( ... );
if ( x==NULL ) {
fprintf( stderr, "Error allocating memory.\n" );
exit( 1 );
}
// ...// Enables specified ndarray flags:int8_tstatus=stdlib_ndarray_enable_flags( x, STDLIB_NDARRAY_ROW_MAJOR_CONTIGUOUS_FLAG );
// ...// Free allocated memory:stdlib_ndarray_free( x );The function accepts the following arguments:
- arr:
[in] struct ndarray*input ndarray. - flags:
[in] int64_tbit mask to enable flags.
The function returns a status code of 0 if able to successfully enable flags.
int8_tstdlib_ndarray_enable_flags( conststructndarray*arr, constint64_tflags );Notes:
- The function does not perform any sanity checks and assumes the user knows what s/he is doing.
Returns ndarray flags as a single integer value.
#include"stdlib/ndarray/ctor.h"#include<stdint.h>#include<stdlib.h>#include<stdio.h>// ...// Create an ndarray:structndarray*x=stdlib_ndarray_allocate( ... );
if ( x==NULL ) {
fprintf( stderr, "Error allocating memory.\n" );
exit( 1 );
}
// ...// Retrieve the ndarray flags:int64_tflags=stdlib_ndarray_flags( x );
// ...// Free allocated memory:stdlib_ndarray_free( x );The function accepts the following arguments:
- arr:
[in] struct ndarray*input ndarray.
int64_tstdlib_ndarray_flags( conststructndarray*arr );Frees an ndarray's allocated memory.
#include"stdlib/ndarray/ctor.h"#include<stdlib.h>#include<stdio.h>// ...// Create an ndarray:structndarray*x=stdlib_ndarray_allocate( ... );
if ( x==NULL ) {
fprintf( stderr, "Error allocating memory.\n" );
exit( 1 );
}
// ...// Free allocated memory:stdlib_ndarray_free( x );The function accepts the following arguments:
- arr:
[in] struct ndarray*input ndarray.
voidstdlib_ndarray_free( structndarray*arr );Tests whether an ndarray has specified flags enabled.
#include"stdlib/ndarray/ctor.h"#include<stdint.h>#include<stdlib.h>#include<stdio.h>// ...// Create an ndarray:structndarray*x=stdlib_ndarray_allocate( ... );
if ( x==NULL ) {
fprintf( stderr, "Error allocating memory.\n" );
exit( 1 );
}
// ...// Test whether an ndarray is row-major contiguous:int8_tout=stdlib_ndarray_flags( x, STDLIB_NDARRAY_ROW_MAJOR_CONTIGUOUS_FLAG );
// ...// Free allocated memory:stdlib_ndarray_free( x );The function accepts the following arguments:
- arr:
[in] struct ndarray*input ndarray. - flags:
[in] int64_tbit mask specifying flags to test against.
The function returns 1 if flags are set and 0 otherwise.
int8_tstdlib_ndarray_has_flags( conststructndarray*arr, constint64_tflags );Returns the index mode of an ndarray.
#include"stdlib/ndarray/ctor.h"#include"stdlib/ndarray/index_modes.h"#include<stdlib.h>#include<stdio.h>// ...// Create an ndarray:structndarray*x=stdlib_ndarray_allocate( ... );
if ( x==NULL ) {
fprintf( stderr, "Error allocating memory.\n" );
exit( 1 );
}
// ...// Retrieve the index mode:enumSTDLIB_NDARRAY_INDEX_MODEimode=stdlib_ndarray_index_mode( x );
// ...// Free allocated memory:stdlib_ndarray_free( x );The function accepts the following arguments:
- arr:
[in] struct ndarray*input ndarray.
int8_tstdlib_ndarray_index_mode( conststructndarray*arr );Returns the number of elements in an ndarray.
#include"stdlib/ndarray/ctor.h"#include<stdint.h>#include<stdlib.h>#include<stdio.h>// ...// Create an ndarray:structndarray*x=stdlib_ndarray_allocate( ... );
if ( x==NULL ) {
fprintf( stderr, "Error allocating memory.\n" );
exit( 1 );
}
// ...// Retrieve the number of elements:int64_tN=stdlib_ndarray_length( x );
// ...// Free allocated memory:stdlib_ndarray_free( x );The function accepts the following arguments:
- arr:
[in] struct ndarray*input ndarray.
int64_tstdlib_ndarray_length( conststructndarray*arr );Returns the number of ndarray dimensions.
#include"stdlib/ndarray/ctor.h"#include<stdint.h>#include<stdlib.h>#include<stdio.h>// ...// Create an ndarray:structndarray*x=stdlib_ndarray_allocate( ... );
if ( x==NULL ) {
fprintf( stderr, "Error allocating memory.\n" );
exit( 1 );
}
// ...// Retrieve the number of dimensions:int64_tndims=stdlib_ndarray_ndims( x );
// ...// Free allocated memory:stdlib_ndarray_free( x );The function accepts the following arguments:
- arr:
[in] struct ndarray*input ndarray.
int64_tstdlib_ndarray_ndims( conststructndarray*arr );Returns the number of ndarray subscript modes.
#include"stdlib/ndarray/ctor.h"#include<stdint.h>#include<stdlib.h>#include<stdio.h>// ...// Create an ndarray:structndarray*x=stdlib_ndarray_allocate( ... );
if ( x==NULL ) {
fprintf( stderr, "Error allocating memory.\n" );
exit( 1 );
}
// ...// Retrieve the number of index modes:int64_tn=stdlib_ndarray_nsubmodes( x );
// ...// Free allocated memory:stdlib_ndarray_free( x );The function accepts the following arguments:
- arr:
[in] struct ndarray*input ndarray.
int64_tstdlib_ndarray_nsubmodes( conststructndarray*arr );Returns an ndarray index offset (in bytes).
#include"stdlib/ndarray/ctor.h"#include<stdint.h>#include<stdlib.h>#include<stdio.h>// ...// Create an ndarray:structndarray*x=stdlib_ndarray_allocate( ... );
if ( x==NULL ) {
fprintf( stderr, "Error allocating memory.\n" );
exit( 1 );
}
// ...// Retrieve the index offset:int64_toffset=stdlib_ndarray_offset( x );
// ...// Free allocated memory:stdlib_ndarray_free( x );The function accepts the following arguments:
- arr:
[in] struct ndarray*input ndarray.
int64_tstdlib_ndarray_offset( conststructndarray*arr );Returns an ndarray index offset (in elements).
#include"stdlib/ndarray/ctor.h"#include<stdint.h>#include<stdlib.h>#include<stdio.h>// ...// Create an ndarray:structndarray*x=stdlib_ndarray_allocate( ... );
if ( x==NULL ) {
fprintf( stderr, "Error allocating memory.\n" );
exit( 1 );
}
// ...// Retrieve the index offset:int64_toffset=stdlib_ndarray_offset_elements( x );
// ...// Free allocated memory:stdlib_ndarray_free( x );The function accepts the following arguments:
- arr:
[in] struct ndarray*input ndarray.
int64_tstdlib_ndarray_offset_elements( conststructndarray*arr );Notes:
- The function assumes that the ndarray is aligned (i.e., the index offset in bytes is a multiple of the number of bytes per ndarray element).
Returns the order of an ndarray.
#include"stdlib/ndarray/ctor.h"#include"stdlib/ndarray/orders.h"#include<stdlib.h>#include<stdio.h>// ...// Create an ndarray:structndarray*x=stdlib_ndarray_allocate( ... );
if ( x==NULL ) {
fprintf( stderr, "Error allocating memory.\n" );
exit( 1 );
}
// ...// Retrieve the order:enumSTDLIB_NDARRAY_ORDERorder=stdlib_ndarray_order( x );
// ...// Free allocated memory:stdlib_ndarray_free( x );The function accepts the following arguments:
- arr:
[in] struct ndarray*input ndarray.
int8_tstdlib_ndarray_order( conststructndarray*arr );Returns a pointer to an array containing an ndarray shape (dimensions).
#include"stdlib/ndarray/ctor.h"#include<stdint.h>#include<stdlib.h>#include<stdio.h>// ...// Create an ndarray:structndarray*x=stdlib_ndarray_allocate( ... );
if ( x==NULL ) {
fprintf( stderr, "Error allocating memory.\n" );
exit( 1 );
}
// ...// Retrieve the shape:int64_t*shape=stdlib_ndarray_shape( x );
// ...// Free allocated memory:stdlib_ndarray_free( x );The function accepts the following arguments:
- arr:
[in] struct ndarray*input ndarray.
int64_t*stdlib_ndarray_shape( conststructndarray*arr );Notes:
- If an input ndarray is zero-dimensional, the function returns a null pointer.
Returns an ndarray stride (in bytes).
#include"stdlib/ndarray/ctor.h"#include<stdint.h>#include<stdlib.h>#include<stdio.h>// ...// Create an ndarray:structndarray*x=stdlib_ndarray_allocate( ... );
if ( x==NULL ) {
fprintf( stderr, "Error allocating memory.\n" );
exit( 1 );
}
// ...// Retrieve a stride:int64_ts=stdlib_ndarray_stride( x, 0 );
// ...// Free allocated memory:stdlib_ndarray_free( x );The function accepts the following arguments:
- arr:
[in] struct ndarray*input ndarray. - i:
[in] int64_tdimension index.
int64_tstdlib_ndarray_stride( conststructndarray*arr, constint64_ti );Notes:
- The function does not perform bounds checking for the dimension index.
Returns an ndarray stride (in elements).
#include"stdlib/ndarray/ctor.h"#include<stdint.h>#include<stdlib.h>#include<stdio.h>// ...// Create an ndarray:structndarray*x=stdlib_ndarray_allocate( ... );
if ( x==NULL ) {
fprintf( stderr, "Error allocating memory.\n" );
exit( 1 );
}
// ...// Retrieve a stride:int64_ts=stdlib_ndarray_stride_elements( x, 0 );
// ...// Free allocated memory:stdlib_ndarray_free( x );The function accepts the following arguments:
- arr:
[in] struct ndarray*input ndarray. - i:
[in] int64_tdimension index.
int64_tstdlib_ndarray_stride_elements( conststructndarray*arr, constint64_ti );Notes:
- The function does not perform bounds checking for the dimension index.
- The function assumes that the ndarray is aligned (i.e., the stride in bytes is a multiple of the number of bytes per ndarray element).
Returns a pointer to an array containing ndarray strides (in bytes).
#include"stdlib/ndarray/ctor.h"#include<stdint.h>#include<stdlib.h>#include<stdio.h>// ...// Create an ndarray:structndarray*x=stdlib_ndarray_allocate( ... );
if ( x==NULL ) {
fprintf( stderr, "Error allocating memory.\n" );
exit( 1 );
}
// ...// Retrieve the strides:int64_t*strides=stdlib_ndarray_strides( x );
// ...// Free allocated memory:stdlib_ndarray_free( x );The function accepts the following arguments:
- arr:
[in] struct ndarray*input ndarray.
int64_t*stdlib_ndarray_strides( conststructndarray*arr );Returns an ndarray subscript mode.
#include"stdlib/ndarray/ctor.h"#include"stdlib/ndarray/index_modes.h"#include<stdlib.h>#include<stdio.h>// ...// Create an ndarray:structndarray*x=stdlib_ndarray_allocate( ... );
if ( x==NULL ) {
fprintf( stderr, "Error allocating memory.\n" );
exit( 1 );
}
// ...// Retrieve an index mode:enumSTDLIB_NDARRAY_INDEX_MODEmode=stdlib_ndarray_submode( x, 0 );
// ...// Free allocated memory:stdlib_ndarray_free( x );The function accepts the following arguments:
- arr:
[in] struct ndarray*input ndarray. - i:
[in] int64_tdimension index.
int8_tstdlib_ndarray_submode( conststructndarray*arr, constint64_ti );Notes:
- If an ndarray has fewer subscript modes than dimensions, modes are recycled using modulo arithmetic.
- The function does not perform bounds checking for the dimension index.
Returns ndarray subscript modes.
#include"stdlib/ndarray/ctor.h"#include"stdlib/ndarray/index_modes.h"#include<stdlib.h>#include<stdio.h>// ...// Create an ndarray:structndarray*x=stdlib_ndarray_allocate( ... );
if ( x==NULL ) {
fprintf( stderr, "Error allocating memory.\n" );
exit( 1 );
}
// ...// Retrieve the index subscript modes:int8_t*modes=stdlib_ndarray_submodes( x );
// ...// Free allocated memory:stdlib_ndarray_free( x );The function accepts the following arguments:
- arr:
[in] struct ndarray*input ndarray.
int8_t*stdlib_ndarray_submodes( conststructndarray*arr );Returns an ndarray data element.
int8_tstdlib_ndarray_get( conststructndarray*arr, constint64_t*sub, void*out );The function accepts the following arguments:
- arr:
[in] struct ndarray *input ndarray. - sub:
[in] int64_t *ndarray subscripts. - out:
[out] void *output address.
Notes:
- The function returns
-1if unable to get an element and0otherwise. - The function requires a
voidpointer for the output addressoutin order to provide a generic API supporting ndarrays having different data types.
Returns a double-precision floating-point ndarray data element.
int8_tstdlib_ndarray_get_float64( conststructndarray*arr, constint64_t*sub, double*out );The function accepts the following arguments:
- arr:
[in] struct ndarray *input ndarray. - sub:
[in] int64_t *ndarray subscripts. - out:
[out] double *output address.
Notes:
- The function returns
-1if unable to get an element and0otherwise. - The function does not verify that the output address type matches the underlying input ndarray data type and assumes that you know what you are doing.
Returns a single-precision floating-point ndarray data element.
int8_tstdlib_ndarray_get_float32( conststructndarray*arr, constint64_t*sub, float*out );The function accepts the following arguments:
- arr:
[in] struct ndarray *input ndarray. - sub:
[in] int64_t *ndarray subscripts. - out:
[out] float *output address.
Notes:
- The function returns
-1if unable to get an element and0otherwise. - The function does not verify that the output address type matches the underlying input ndarray data type and assumes that you know what you are doing.
Returns an unsigned 64-bit integer ndarray data element.
int8_tstdlib_ndarray_get_uint64( conststructndarray*arr, constint64_t*sub, uint64_t*out );The function accepts the following arguments:
- arr:
[in] struct ndarray *input ndarray. - sub:
[in] int64_t *ndarray subscripts. - out:
[out] uint64_t *output address.
Notes:
- The function returns
-1if unable to get an element and0otherwise. - The function does not verify that the output address type matches the underlying input ndarray data type and assumes that you know what you are doing.
Returns a signed 64-bit integer ndarray data element.
int8_tstdlib_ndarray_get_int64( conststructndarray*arr, constint64_t*sub, int64_t*out );The function accepts the following arguments:
- arr:
[in] struct ndarray *input ndarray. - sub:
[in] int64_t *ndarray subscripts. - out:
[out] int64_t *output address.
Notes:
- The function returns
-1if unable to get an element and0otherwise. - The function does not verify that the output address type matches the underlying input ndarray data type and assumes that you know what you are doing.
Returns an unsigned 32-bit integer ndarray data element.
int8_tstdlib_ndarray_get_uint32( conststructndarray*arr, constint64_t*sub, uint32_t*out );The function accepts the following arguments:
- arr:
[in] struct ndarray *input ndarray. - sub:
[in] int64_t *ndarray subscripts. - out:
[out] uint32_t *output address.
Notes:
- The function returns
-1if unable to get an element and0otherwise. - The function does not verify that the output address type matches the underlying input ndarray data type and assumes that you know what you are doing.
Returns a signed 32-bit integer ndarray data element.
int8_tstdlib_ndarray_get_int32( conststructndarray*arr, constint64_t*sub, int32_t*out );The function accepts the following arguments:
- arr:
[in] struct ndarray *input ndarray. - sub:
[in] int64_t *ndarray subscripts. - out:
[out] int32_t *output address.
Notes:
- The function returns
-1if unable to get an element and0otherwise. - The function does not verify that the output address type matches the underlying input ndarray data type and assumes that you know what you are doing.
Returns an unsigned 16-bit integer ndarray data element.
int8_tstdlib_ndarray_get_uint16( conststructndarray*arr, constint64_t*sub, uint16_t*out );The function accepts the following arguments:
- arr:
[in] struct ndarray *input ndarray. - sub:
[in] int64_t *ndarray subscripts. - out:
[out] uint16_t *output address.
Notes:
- The function returns
-1if unable to get an element and0otherwise. - The function does not verify that the output address type matches the underlying input ndarray data type and assumes that you know what you are doing.
Returns a signed 16-bit integer ndarray data element.
int8_tstdlib_ndarray_get_int16( conststructndarray*arr, constint64_t*sub, int16_t*out );The function accepts the following arguments:
- arr:
[in] struct ndarray *input ndarray. - sub:
[in] int64_t *ndarray subscripts. - out:
[out] int16_t *output address.
Notes:
- The function returns
-1if unable to get an element and0otherwise. - The function does not verify that the output address type matches the underlying input ndarray data type and assumes that you know what you are doing.
Returns an unsigned 8-bit integer ndarray data element.
int8_tstdlib_ndarray_get_uint8( conststructndarray*arr, constint64_t*sub, uint8_t*out );The function accepts the following arguments:
- arr:
[in] struct ndarray *input ndarray. - sub:
[in] int64_t *ndarray subscripts. - out:
[out] uint8_t *output address.
Notes:
- The function returns
-1if unable to get an element and0otherwise. - The function does not verify that the output address type matches the underlying input ndarray data type and assumes that you know what you are doing.
Returns a signed 8-bit integer ndarray data element.
int8_tstdlib_ndarray_get_int8( conststructndarray*arr, constint64_t*sub, int8_t*out );The function accepts the following arguments:
- arr:
[in] struct ndarray *input ndarray. - sub:
[in] int64_t *ndarray subscripts. - out:
[out] int8_t *output address.
Notes:
- The function returns
-1if unable to get an element and0otherwise. - The function does not verify that the output address type matches the underlying input ndarray data type and assumes that you know what you are doing.
Returns a double-precision complex floating-point ndarray data element.
int8_tstdlib_ndarray_get_complex128( conststructndarray*arr, constint64_t*sub, stdlib_complex128_t*out );The function accepts the following arguments:
- arr:
[in] struct ndarray *input ndarray. - sub:
[in] int64_t *ndarray subscripts. - out:
[out] stdlib_complex128_t *output address.
Notes:
- The function returns
-1if unable to get an element and0otherwise. - The function does not verify that the output address type matches the underlying input ndarray data type and assumes that you know what you are doing.
Returns a single-precision complex floating-point ndarray data element.
int8_tstdlib_ndarray_get_complex64( conststructndarray*arr, constint64_t*sub, stdlib_complex64_t*out );The function accepts the following arguments:
- arr:
[in] struct ndarray *input ndarray. - sub:
[in] int64_t *ndarray subscripts. - out:
[out] stdlib_complex64_t *output address.
Notes:
- The function returns
-1if unable to get an element and0otherwise. - The function does not verify that the output address type matches the underlying input ndarray data type and assumes that you know what you are doing.
Returns a boolean ndarray data element.
int8_tstdlib_ndarray_get_bool( conststructndarray*arr, constint64_t*sub, bool*out );The function accepts the following arguments:
- arr:
[in] struct ndarray *input ndarray. - sub:
[in] int64_t *ndarray subscripts. - out:
[out] bool *output address.
Notes:
- The function returns
-1if unable to get an element and0otherwise. - The function does not verify that the output address type matches the underlying input ndarray data type and assumes that you know what you are doing.
Returns a pointer to an ndarray data element in the underlying byte array.
uint8_t*stdlib_ndarray_get_ptr( conststructndarray*arr, constint64_t*sub );The function accepts the following arguments:
- arr:
[in] struct ndarray *input ndarray. - sub:
[in] int64_t *ndarray subscripts.
Returns an ndarray data element specified by a byte array pointer.
int8_tstdlib_ndarray_get_ptr_value( conststructndarray*arr, constuint8_t*idx, void*out );The function accepts the following arguments:
- arr:
[in] struct ndarray *input ndarray. - idx:
[in] uint8_t *byte array pointer to an ndarray data element. - out:
[out] void *output address.
Notes:
- The function does not perform bounds checking and assumes you know what you are doing.
- The function returns
-1if unable to get an element and0otherwise. - The function requires a
voidpointer for the output addressoutin 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.
int8_tstdlib_ndarray_get_ptr_float64( constuint8_t*idx, double*out );The function accepts the following arguments:
- idx:
[in] uint8_t *byte array pointer to an ndarray data element. - out:
[out] double *output address.
Notes:
- The function has no way of determining whether
idxactually points to a compatible memory address. Accordingly, accessing unowned memory is possible, and this function assumes you know what you are doing. - The function always returns
0.
Returns a single-precision floating-point ndarray data element specified by a byte array pointer.
int8_tstdlib_ndarray_get_ptr_float32( constuint8_t*idx, float*out );The function accepts the following arguments:
- idx:
[in] uint8_t *byte array pointer to an ndarray data element. - out:
[out] float *output address.
Notes:
- The function has no way of determining whether
idxactually points to a compatible memory address. Accordingly, accessing unowned memory is possible, and this function assumes you know what you are doing. - The function always returns
0.
Returns an unsigned 64-bit integer ndarray data element specified by a byte array pointer.
int8_tstdlib_ndarray_get_ptr_uint64( constuint8_t*idx, uint64_t*out );The function accepts the following arguments:
- idx:
[in] uint8_t *byte array pointer to an ndarray data element. - out:
[out] uint64_t *output address.
Notes:
- The function has no way of determining whether
idxactually points to a compatible memory address. Accordingly, accessing unowned memory is possible, and this function assumes you know what you are doing. - The function always returns
0.
Returns a signed 64-bit integer ndarray data element specified by a byte array pointer.
int8_tstdlib_ndarray_get_ptr_int64( constuint8_t*idx, int64_t*out );The function accepts the following arguments:
- idx:
[in] uint8_t *byte array pointer to an ndarray data element. - out:
[out] int64_t *output address.
Notes:
- The function has no way of determining whether
idxactually points to a compatible memory address. Accordingly, accessing unowned memory is possible, and this function assumes you know what you are doing. - The function always returns
0.
Returns an unsigned 32-bit integer ndarray data element specified by a byte array pointer.
int8_tstdlib_ndarray_get_ptr_uint32( constuint8_t*idx, uint32_t*out );The function accepts the following arguments:
- idx:
[in] uint8_t *byte array pointer to an ndarray data element. - out:
[out] uint32_t *output address.
Notes:
- The function has no way of determining whether
idxactually points to a compatible memory address. Accordingly, accessing unowned memory is possible, and this function assumes you know what you are doing. - The function always returns
0.
Returns a signed 32-bit integer ndarray data element specified by a byte array pointer.
int8_tstdlib_ndarray_get_ptr_int32( constuint8_t*idx, int32_t*out );The function accepts the following arguments:
- idx:
[in] uint8_t *byte array pointer to an ndarray data element. - out:
[out] int32_t *output address.
Notes:
- The function has no way of determining whether
idxactually points to a compatible memory address. Accordingly, accessing unowned memory is possible, and this function assumes you know what you are doing. - The function always returns
0.
Returns an unsigned 16-bit integer ndarray data element specified by a byte array pointer.
int8_tstdlib_ndarray_get_ptr_uint16( constuint8_t*idx, uint16_t*out );The function accepts the following arguments:
- idx:
[in] uint8_t *byte array pointer to an ndarray data element. - out:
[out] uint16_t *output address.
Notes:
- The function has no way of determining whether
idxactually points to a compatible memory address. Accordingly, accessing unowned memory is possible, and this function assumes you know what you are doing. - The function always returns
0.
Returns a signed 16-bit integer ndarray data element specified by a byte array pointer.
int8_tstdlib_ndarray_get_ptr_int16( constuint8_t*idx, int16_t*out );The function accepts the following arguments:
- idx:
[in] uint8_t *byte array pointer to an ndarray data element. - out:
[out] int16_t *output address.
Notes:
- The function has no way of determining whether
idxactually points to a compatible memory address. Accordingly, accessing unowned memory is possible, and this function assumes you know what you are doing. - The function always returns
0.
Returns an unsigned 8-bit integer ndarray data element specified by a byte array pointer.
int8_tstdlib_ndarray_get_ptr_uint8( constuint8_t*idx, uint8_t*out );The function accepts the following arguments:
- idx:
[in] uint8_t *byte array pointer to an ndarray data element. - out:
[out] uint8_t *output address.
Notes:
- The function always returns
0.
Returns a signed 8-bit integer ndarray data element specified by a byte array pointer.
int8_tstdlib_ndarray_get_ptr_int8( constuint8_t*idx, int8_t*out );The function accepts the following arguments:
- idx:
[in] uint8_t *byte array pointer to an ndarray data element. - out:
[out] int8_t *output address.
Notes:
- The function always returns
0.
Returns a double-precision complex floating-point ndarray data element specified by a byte array pointer.
int8_tstdlib_ndarray_get_ptr_complex128( constuint8_t*idx, stdlib_complex128_t*out );The function accepts the following arguments:
- idx:
[in] uint8_t *byte array pointer to an ndarray data element. - out:
[out] stdlib_complex128_t *output address.
Notes:
- The function has no way of determining whether
idxactually points to a compatible memory address. Accordingly, accessing unowned memory is possible, and this function assumes you know what you are doing. - The function always returns
0.
Returns a single-precision complex floating-point ndarray data element specified by a byte array pointer.
int8_tstdlib_ndarray_get_ptr_complex64( constuint8_t*idx, stdlib_complex64_t*out );The function accepts the following arguments:
- idx:
[in] uint8_t *byte array pointer to an ndarray data element. - out:
[out] stdlib_complex64_t *output address.
Notes:
- The function has no way of determining whether
idxactually points to a compatible memory address. Accordingly, accessing unowned memory is possible, and this function assumes you know what you are doing. - The function always returns
0.
Returns a boolean ndarray data element specified by a byte array pointer.
int8_tstdlib_ndarray_get_ptr_bool( constuint8_t*idx, bool*out );The function accepts the following arguments:
- idx:
[in] uint8_t *byte array pointer to an ndarray data element. - out:
[out] bool *output address.
Notes:
- The function has no way of determining whether
idxactually points to a compatible memory address. Accordingly, accessing unowned memory is possible, and this function assumes you know what you are doing. - The function always returns
0.
Returns an ndarray data element located at a specified linear index.
int8_tstdlib_ndarray_iget( conststructndarray*arr, constint64_tidx, void*out );The function accepts the following arguments:
- arr:
[in] struct ndarray*input ndarray. - idx:
[in] int64_tlinear view index. - out:
[out] void *output address.
Notes:
- The function returns
-1if unable to get an element and0otherwise. - The function requires a
voidpointer for the output addressoutin order to provide a generic API supporting ndarrays having different data types. - The function places the burden on the user to ensure that the output address is compatible with the data type of input ndarray data elements.
- For zero-dimensional arrays, the function returns the first (and only) indexed element, regardless of the value of
idx.
Returns a double-precision floating-point ndarray data element located at a specified linear index.
int8_tstdlib_ndarray_iget_float64( conststructndarray*arr, constint64_tidx, double*out );The function accepts the following arguments:
- arr:
[in] struct ndarray*input ndarray. - idx:
[in] int64_tlinear view index. - out:
[out] double *output address.
Notes:
- The function does not verify that the output address type matches the underlying input ndarray data type and assumes that you know what you are doing.
- The function returns
-1if unable to get an element and0otherwise. - For zero-dimensional arrays, the function returns the first (and only) indexed element, regardless of the value of
idx.
Returns a single-precision floating-point ndarray data element located at a specified linear index.
int8_tstdlib_ndarray_iget_float32( conststructndarray*arr, constint64_tidx, float*out );The function accepts the following arguments:
- arr:
[in] struct ndarray*input ndarray. - idx:
[in] int64_tlinear view index. - out:
[out] float *output address.
Notes:
- The function does not verify that the output address type matches the underlying input ndarray data type and assumes that you know what you are doing.
- The function returns
-1if unable to get an element and0otherwise. - For zero-dimensional arrays, the function returns the first (and only) indexed element, regardless of the value of
idx.
Returns an unsigned 64-bit integer ndarray data element located at a specified linear index.
int8_tstdlib_ndarray_iget_uint64( conststructndarray*arr, constint64_tidx, uint64_t*out );The function accepts the following arguments:
- arr:
[in] struct ndarray*input ndarray. - idx:
[in] int64_tlinear view index. - out:
[out] uint64_t *output address.
Notes:
- The function does not verify that the output address type matches the underlying input ndarray data type and assumes that you know what you are doing.
- The function returns
-1if unable to get an element and0otherwise. - For zero-dimensional arrays, the function returns the first (and only) indexed element, regardless of the value of
idx.
Returns a signed 64-bit integer ndarray data element located at a specified linear index.
int8_tstdlib_ndarray_iget_int64( conststructndarray*arr, constint64_tidx, int64_t*out );The function accepts the following arguments:
- arr:
[in] struct ndarray*input ndarray. - idx:
[in] int64_tlinear view index. - out:
[out] int64_t *output address.
Notes:
- The function does not verify that the output address type matches the underlying input ndarray data type and assumes that you know what you are doing.
- The function returns
-1if unable to get an element and0otherwise. - For zero-dimensional arrays, the function returns the first (and only) indexed element, regardless of the value of
idx.
Returns an unsigned 32-bit integer ndarray data element located at a specified linear index.
int8_tstdlib_ndarray_iget_uint32( conststructndarray*arr, constint64_tidx, uint32_t*out );The function accepts the following arguments:
- arr:
[in] struct ndarray*input ndarray. - idx:
[in] int64_tlinear view index. - out:
[out] uint32_t *output address.
Notes:
- The function does not verify that the output address type matches the underlying input ndarray data type and assumes that you know what you are doing.
- The function returns
-1if unable to get an element and0otherwise. - For zero-dimensional arrays, the function returns the first (and only) indexed element, regardless of the value of
idx.
Returns a signed 32-bit integer ndarray data element located at a specified linear index.
int8_tstdlib_ndarray_iget_int32( conststructndarray*arr, constint64_tidx, int32_t*out );The function accepts the following arguments:
- arr:
[in] struct ndarray*input ndarray. - idx:
[in] int64_tlinear view index. - out:
[out] int32_t *output address.
Notes:
- The function does not verify that the output address type matches the underlying input ndarray data type and assumes that you know what you are doing.
- The function returns
-1if unable to get an element and0otherwise. - For zero-dimensional arrays, the function returns the first (and only) indexed element, regardless of the value of
idx.
Returns an unsigned 16-bit integer ndarray data element located at a specified linear index.
int8_tstdlib_ndarray_iget_uint16( conststructndarray*arr, constint64_tidx, uint16_t*out );The function accepts the following arguments:
- arr:
[in] struct ndarray*input ndarray. - idx:
[in] int64_tlinear view index. - out:
[out] uint16_t *output address.
Notes:
- The function does not verify that the output address type matches the underlying input ndarray data type and assumes that you know what you are doing.
- The function returns
-1if unable to get an element and0otherwise. - For zero-dimensional arrays, the function returns the first (and only) indexed element, regardless of the value of
idx.
Returns a signed 16-bit integer ndarray data element located at a specified linear index.
int8_tstdlib_ndarray_iget_int16( conststructndarray*arr, constint64_tidx, int16_t*out );The function accepts the following arguments:
- arr:
[in] struct ndarray*input ndarray. - idx:
[in] int64_tlinear view index. - out:
[out] int16_t *output address.
Notes:
- The function does not verify that the output address type matches the underlying input ndarray data type and assumes that you know what you are doing.
- The function returns
-1if unable to get an element and0otherwise. - For zero-dimensional arrays, the function returns the first (and only) indexed element, regardless of the value of
idx.
Returns an unsigned 8-bit integer ndarray data element located at a specified linear index.
int8_tstdlib_ndarray_iget_uint8( conststructndarray*arr, constint64_tidx, uint8_t*out );The function accepts the following arguments:
- arr:
[in] struct ndarray*input ndarray. - idx:
[in] int64_tlinear view index. - out:
[out] uint8_t *output address.
Notes:
- The function does not verify that the output address type matches the underlying input ndarray data type and assumes that you know what you are doing.
- The function returns
-1if unable to get an element and0otherwise. - For zero-dimensional arrays, the function returns the first (and only) indexed element, regardless of the value of
idx.
Returns a signed 8-bit integer ndarray data element located at a specified linear index.
int8_tstdlib_ndarray_iget_int8( conststructndarray*arr, constint64_tidx, int8_t*out );The function accepts the following arguments:
- arr:
[in] struct ndarray*input ndarray. - idx:
[in] int64_tlinear view index. - out:
[out] int8_t *output address.
Notes:
- The function does not verify that the output address type matches the underlying input ndarray data type and assumes that you know what you are doing.
- The function returns
-1if unable to get an element and0otherwise. - For zero-dimensional arrays, the function returns the first (and only) indexed element, regardless of the value of
idx.
Returns a double-precision complex floating-point ndarray data element located at a specified linear index.
int8_tstdlib_ndarray_iget_complex128( conststructndarray*arr, constint64_tidx, stdlib_complex128_t*out );The function accepts the following arguments:
- arr:
[in] struct ndarray*input ndarray. - idx:
[in] int64_tlinear view index. - out:
[out] stdlib_complex128_t *output address.
Notes:
- The function does not verify that the output address type matches the underlying input ndarray data type and assumes that you know what you are doing.
- The function returns
-1if unable to get an element and0otherwise. - For zero-dimensional arrays, the function returns the first (and only) indexed element, regardless of the value of
idx.
Returns a single-precision complex floating-point ndarray data element located at a specified linear index.
int8_tstdlib_ndarray_iget_complex64( conststructndarray*arr, constint64_tidx, stdlib_complex64_t*out );The function accepts the following arguments:
- arr:
[in] struct ndarray*input ndarray. - idx:
[in] int64_tlinear view index. - out:
[out] stdlib_complex64_t *output address.
Notes:
- The function does not verify that the output address type matches the underlying input ndarray data type and assumes that you know what you are doing.
- The function returns
-1if unable to get an element and0otherwise. - For zero-dimensional arrays, the function returns the first (and only) indexed element, regardless of the value of
idx.
Returns a boolean ndarray data element located at a specified linear index.
int8_tstdlib_ndarray_iget_bool( conststructndarray*arr, constint64_tidx, bool*out );The function accepts the following arguments:
- arr:
[in] struct ndarray*input ndarray. - idx:
[in] int64_tlinear view index. - out:
[out] bool *output address.
Notes:
- The function does not verify that the output address type matches the underlying input ndarray data type and assumes that you know what you are doing.
- The function returns
-1if unable to get an element and0otherwise. - For zero-dimensional arrays, the function returns the first (and only) indexed element, regardless of the value of
idx.
Returns a pointer in the underlying byte array for an ndarray data element located at a specified linear index.
uint8_t*stdlib_ndarray_iget_ptr( conststructndarray*arr, constint64_tidx );The function accepts the following arguments:
- arr:
[in] struct ndarray*input ndarray. - idx:
[in] int64_tlinear 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.
int8_tstdlib_ndarray_iset( conststructndarray*arr, constint64_tidx, constvoid*v );The function accepts the following arguments:
- arr:
[in] struct ndarray*input ndarray. - idx:
[in] int64_tlinear view index. - v:
[in] void*value to set.
Notes:
- The function returns
-1if unable to set an element and0otherwise. - The function requires a pointer to a data value
vin order to provide a generic API supporting ndarrays having different data types. - The function has no way of determining whether
vactually 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. - For zero-dimensional arrays, the function sets the first (and only) indexed element, regardless of the value of
idx.
Sets a double-precision floating-point ndarray data element located at a specified linear index.
int8_tstdlib_ndarray_iset_float64( conststructndarray*arr, constint64_tidx, constdoublev );The function accepts the following arguments:
- arr:
[in] struct ndarray*input ndarray. - idx:
[in] int64_tlinear view index. - v:
[in] doublevalue to set.
Notes:
- The function does not verify that the type of
vmatches the underlying input ndarray data type, and, thus, overwriting unowned memory is possible. The function assumes that you know what you are doing. - The function returns
-1if unable to set an element and0otherwise. - For zero-dimensional arrays, the function sets the first (and only) indexed element, regardless of the value of
idx.
Sets a single-precision floating-point ndarray data element located at a specified linear index.
int8_tstdlib_ndarray_iset_float32( conststructndarray*arr, constint64_tidx, constfloatv );The function accepts the following arguments:
- arr:
[in] struct ndarray*input ndarray. - idx:
[in] int64_tlinear view index. - v:
[in] floatvalue to set.
Notes:
- The function does not verify that the type of
vmatches the underlying input ndarray data type, and, thus, overwriting unowned memory is possible. The function assumes that you know what you are doing. - The function returns
-1if unable to set an element and0otherwise. - For zero-dimensional arrays, the function sets the first (and only) indexed element, regardless of the value of
idx.
Sets an unsigned 64-bit integer ndarray data element located at a specified linear index.
int8_tstdlib_ndarray_iset_uint64( conststructndarray*arr, constint64_tidx, constuint64_tv );The function accepts the following arguments:
- arr:
[in] struct ndarray*input ndarray. - idx:
[in] int64_tlinear view index. - v:
[in] uint64_tvalue to set.
Notes:
- The function does not verify that the type of
vmatches the underlying input ndarray data type, and, thus, overwriting unowned memory is possible. The function assumes that you know what you are doing. - The function returns
-1if unable to set an element and0otherwise. - For zero-dimensional arrays, the function sets the first (and only) indexed element, regardless of the value of
idx.
Sets a signed 64-bit integer ndarray data element located at a specified linear index.
int8_tstdlib_ndarray_iset_int64( conststructndarray*arr, constint64_tidx, constint64_tv );The function accepts the following arguments:
- arr:
[in] struct ndarray*input ndarray. - idx:
[in] int64_tlinear view index. - v:
[in] int64_tvalue to set.
Notes:
- The function does not verify that the type of
vmatches the underlying input ndarray data type, and, thus, overwriting unowned memory is possible. The function assumes that you know what you are doing. - The function returns
-1if unable to set an element and0otherwise. - For zero-dimensional arrays, the function sets the first (and only) indexed element, regardless of the value of
idx.
Sets an unsigned 32-bit integer ndarray data element located at a specified linear index.
int8_tstdlib_ndarray_iset_uint32( conststructndarray*arr, constint64_tidx, constuint32_tv );The function accepts the following arguments:
- arr:
[in] struct ndarray*input ndarray. - idx:
[in] int64_tlinear view index. - v:
[in] uint32_tvalue to set.
Notes:
- The function does not verify that the type of
vmatches the underlying input ndarray data type, and, thus, overwriting unowned memory is possible. The function assumes that you know what you are doing. - The function returns
-1if unable to set an element and0otherwise. - For zero-dimensional arrays, the function sets the first (and only) indexed element, regardless of the value of
idx.
Sets a signed 32-bit integer ndarray data element located at a specified linear index.
int8_tstdlib_ndarray_iset_int32( conststructndarray*arr, constint64_tidx, constint32_tv );The function accepts the following arguments:
- arr:
[in] struct ndarray*input ndarray. - idx:
[in] int64_tlinear view index. - v:
[in] int32_tvalue to set.
Notes:
- The function does not verify that the type of
vmatches the underlying input ndarray data type, and, thus, overwriting unowned memory is possible. The function assumes that you know what you are doing. - The function returns
-1if unable to set an element and0otherwise. - For zero-dimensional arrays, the function sets the first (and only) indexed element, regardless of the value of
idx.
Sets an unsigned 16-bit integer ndarray data element located at a specified linear index.
int8_tstdlib_ndarray_iset_uint16( conststructndarray*arr, constint64_tidx, constuint16_tv );The function accepts the following arguments:
- arr:
[in] struct ndarray*input ndarray. - idx:
[in] int64_tlinear view index. - v:
[in] uint16_tvalue to set.
Notes:
- The function does not verify that the type of
vmatches the underlying input ndarray data type, and, thus, overwriting unowned memory is possible. The function assumes that you know what you are doing. - The function returns
-1if unable to set an element and0otherwise. - For zero-dimensional arrays, the function sets the first (and only) indexed element, regardless of the value of
idx.
Sets a signed 16-bit integer ndarray data element located at a specified linear index.
int8_tstdlib_ndarray_iset_int16( conststructndarray*arr, constint64_tidx, constint16_tv );The function accepts the following arguments:
- arr:
[in] struct ndarray*input ndarray. - idx:
[in] int64_tlinear view index. - v:
[in] int16_tvalue to set.
Notes:
- The function does not verify that the type of
vmatches the underlying input ndarray data type, and, thus, overwriting unowned memory is possible. The function assumes that you know what you are doing. - The function returns
-1if unable to set an element and0otherwise. - For zero-dimensional arrays, the function sets the first (and only) indexed element, regardless of the value of
idx.
Sets an unsigned 8-bit integer ndarray data element located at a specified linear index.
int8_tstdlib_ndarray_iset_uint8( conststructndarray*arr, constint64_tidx, constuint8_tv );The function accepts the following arguments:
- arr:
[in] struct ndarray*input ndarray. - idx:
[in] int64_tlinear view index. - v:
[in] uint8_tvalue to set.
Notes:
- The function returns
-1if unable to set an element and0otherwise. - For zero-dimensional arrays, the function sets the first (and only) indexed element, regardless of the value of
idx.
Sets a signed 8-bit integer ndarray data element located at a specified linear index.
int8_tstdlib_ndarray_iset_int8( conststructndarray*arr, constint64_tidx, constint8_tv );The function accepts the following arguments:
- arr:
[in] struct ndarray*input ndarray. - idx:
[in] int64_tlinear view index. - v:
[in] int8_tvalue to set.
Notes:
- The function returns
-1if unable to set an element and0otherwise. - For zero-dimensional arrays, the function sets the first (and only) indexed element, regardless of the value of
idx.
Sets a double-precision complex floating-point ndarray data element located at a specified linear index.
int8_tstdlib_ndarray_iset_complex128( conststructndarray*arr, constint64_tidx, conststdlib_complex128_tv );The function accepts the following arguments:
- arr:
[in] struct ndarray*input ndarray. - idx:
[in] int64_tlinear view index. - v:
[in] stdlib_complex128_tvalue to set.
Notes:
- The function does not verify that the type of
vmatches the underlying input ndarray data type, and, thus, overwriting unowned memory is possible. The function assumes that you know what you are doing. - The function returns
-1if unable to set an element and0otherwise. - For zero-dimensional arrays, the function sets the first (and only) indexed element, regardless of the value of
idx.
Sets a single-precision complex floating-point ndarray data element located at a specified linear index.
int8_tstdlib_ndarray_iset_complex64( conststructndarray*arr, constint64_tidx, conststdlib_complex64_tv );The function accepts the following arguments:
- arr:
[in] struct ndarray*input ndarray. - idx:
[in] int64_tlinear view index. - v:
[in] stdlib_complex64_tvalue to set.
Notes:
- The function does not verify that the type of
vmatches the underlying input ndarray data type, and, thus, overwriting unowned memory is possible. The function assumes that you know what you are doing. - The function returns
-1if unable to set an element and0otherwise. - For zero-dimensional arrays, the function sets the first (and only) indexed element, regardless of the value of
idx.
Sets a boolean ndarray data element located at a specified linear index.
int8_tstdlib_ndarray_iset_bool( conststructndarray*arr, constint64_tidx, constboolv );The function accepts the following arguments:
- arr:
[in] struct ndarray*input ndarray. - idx:
[in] int64_tlinear view index. - v:
[in] boolvalue to set.
Notes:
- The function does not verify that the type of
vmatches the underlying input ndarray data type, and, thus, overwriting unowned memory is possible. The function assumes that you know what you are doing. - The function returns
-1if unable to set an element and0otherwise. - For zero-dimensional arrays, the function sets the first (and only) indexed element, regardless of the value of
idx.
Sets an ndarray data element.
int8_tstdlib_ndarray_set( conststructndarray*arr, constint64_t*sub, constvoid*v );The function accepts the following arguments:
- arr:
[in] struct ndarray*input ndarray. - sub:
[in] int64_t*ndarray subscripts. - v:
[in] void*value to set.
Notes
- The function returns
-1if unable to set an element and0otherwise. - The function requires a pointer to a data value
vin order to provide a generic API supporting ndarrays having different data types. - The function has no way of determining whether
vactually 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.
int8_tstdlib_ndarray_set_float64( conststructndarray*arr, constint64_t*sub, constdoublev );The function accepts the following arguments:
- arr:
[in] struct ndarray*input ndarray. - sub:
[in] int64_t*ndarray subscripts. - v:
[in] doublevalue to set.
Notes
- The function does not verify that the type of
vmatches the underlying input ndarray data type, and, thus, overwriting unowned memory is possible. The function assumes that you know what you are doing. - The function returns
-1if unable to set an element and0otherwise.
Sets a single-precision floating-point ndarray data element.
int8_tstdlib_ndarray_set_float32( conststructndarray*arr, constint64_t*sub, constfloatv );The function accepts the following arguments:
- arr:
[in] struct ndarray*input ndarray. - sub:
[in] int64_t*ndarray subscripts. - v:
[in] floatvalue to set.
Notes
- The function does not verify that the type of
vmatches the underlying input ndarray data type, and, thus, overwriting unowned memory is possible. The function assumes that you know what you are doing. - The function returns
-1if unable to set an element and0otherwise.
Sets an unsigned 64-bit integer ndarray data element.
int8_tstdlib_ndarray_set_uint64( conststructndarray*arr, constint64_t*sub, constuint64_tv );The function accepts the following arguments:
- arr:
[in] struct ndarray*input ndarray. - sub:
[in] int64_t*ndarray subscripts. - v:
[in] uint64_tvalue to set.
Notes
- The function does not verify that the type of
vmatches the underlying input ndarray data type, and, thus, overwriting unowned memory is possible. The function assumes that you know what you are doing. - The function returns
-1if unable to set an element and0otherwise.
Sets a signed 64-bit integer ndarray data element.
int8_tstdlib_ndarray_set_int64( conststructndarray*arr, constint64_t*sub, constint64_tv );The function accepts the following arguments:
- arr:
[in] struct ndarray*input ndarray. - sub:
[in] int64_t*ndarray subscripts. - v:
[in] int64_tvalue to set.
Notes
- The function does not verify that the type of
vmatches the underlying input ndarray data type, and, thus, overwriting unowned memory is possible. The function assumes that you know what you are doing. - The function returns
-1if unable to set an element and0otherwise.
Sets an unsigned 32-bit integer ndarray data element.
int8_tstdlib_ndarray_set_uint32( conststructndarray*arr, constint64_t*sub, constuint32_tv );The function accepts the following arguments:
- arr:
[in] struct ndarray*input ndarray. - sub:
[in] int64_t*ndarray subscripts. - v:
[in] uint32_tvalue to set.
Notes
- The function does not verify that the type of
vmatches the underlying input ndarray data type, and, thus, overwriting unowned memory is possible. The function assumes that you know what you are doing. - The function returns
-1if unable to set an element and0otherwise.
Sets a signed 32-bit integer ndarray data element.
int8_tstdlib_ndarray_set_int32( conststructndarray*arr, constint64_t*sub, constint32_tv );The function accepts the following arguments:
- arr:
[in] struct ndarray*input ndarray. - sub:
[in] int64_t*ndarray subscripts. - v:
[in] int32_tvalue to set.
Notes
- The function does not verify that the type of
vmatches the underlying input ndarray data type, and, thus, overwriting unowned memory is possible. The function assumes that you know what you are doing. - The function returns
-1if unable to set an element and0otherwise.
Sets an unsigned 16-bit integer ndarray data element.
int8_tstdlib_ndarray_set_uint16( conststructndarray*arr, constint64_t*sub, constuint16_tv );The function accepts the following arguments:
- arr:
[in] struct ndarray*input ndarray. - sub:
[in] int64_t*ndarray subscripts. - v:
[in] uint16_tvalue to set.
Notes
- The function does not verify that the type of
vmatches the underlying input ndarray data type, and, thus, overwriting unowned memory is possible. The function assumes that you know what you are doing. - The function returns
-1if unable to set an element and0otherwise.
Sets a signed 16-bit integer ndarray data element.
int8_tstdlib_ndarray_set_int16( conststructndarray*arr, constint64_t*sub, constint16_tv );The function accepts the following arguments:
- arr:
[in] struct ndarray*input ndarray. - sub:
[in] int64_t*ndarray subscripts. - v:
[in] int16_tvalue to set.
Notes
- The function does not verify that the type of
vmatches the underlying input ndarray data type, and, thus, overwriting unowned memory is possible. The function assumes that you know what you are doing. - The function returns
-1if unable to set an element and0otherwise.
Sets an unsigned 8-bit integer ndarray data element.
int8_tstdlib_ndarray_set_uint8( conststructndarray*arr, constint64_t*sub, constuint8_tv );The function accepts the following arguments:
- arr:
[in] struct ndarray*input ndarray. - sub:
[in] int64_t*ndarray subscripts. - v:
[in] uint8_tvalue to set.
Notes
- The function returns
-1if unable to set an element and0otherwise.
Sets a signed 8-bit integer ndarray data element.
int8_tstdlib_ndarray_set_int8( conststructndarray*arr, constint64_t*sub, constint8_tv );The function accepts the following arguments:
- arr:
[in] struct ndarray*input ndarray. - sub:
[in] int64_t*ndarray subscripts. - v:
[in] int8_tvalue to set.
Notes
- The function returns
-1if unable to set an element and0otherwise.
Sets a double-precision complex floating-point ndarray data element.
int8_tstdlib_ndarray_set_complex128( conststructndarray*arr, constint64_t*sub, conststdlib_complex128_tv );The function accepts the following arguments:
- arr:
[in] struct ndarray*input ndarray. - sub:
[in] int64_t*ndarray subscripts. - v:
[in] stdlib_complex128_tvalue to set.
Notes
- The function does not verify that the type of
vmatches the underlying input ndarray data type, and, thus, overwriting unowned memory is possible. The function assumes that you know what you are doing. - The function returns
-1if unable to set an element and0otherwise.
Sets a single-precision complex floating-point ndarray data element.
int8_tstdlib_ndarray_set_complex64( conststructndarray*arr, constint64_t*sub, conststdlib_complex64_tv );The function accepts the following arguments:
- arr:
[in] struct ndarray*input ndarray. - sub:
[in] int64_t*ndarray subscripts. - v:
[in] stdlib_complex64_tvalue to set.
Notes
- The function does not verify that the type of
vmatches the underlying input ndarray data type, and, thus, overwriting unowned memory is possible. The function assumes that you know what you are doing. - The function returns
-1if unable to set an element and0otherwise.
Sets a boolean ndarray data element.
int8_tstdlib_ndarray_set_bool( conststructndarray*arr, constint64_t*sub, constboolv );The function accepts the following arguments:
- arr:
[in] struct ndarray*input ndarray. - sub:
[in] int64_t*ndarray subscripts. - v:
[in] boolvalue to set.
Notes
- The function does not verify that the type of
vmatches the underlying input ndarray data type, and, thus, overwriting unowned memory is possible. The function assumes that you know what you are doing. - The function returns
-1if unable to set an element and0otherwise.
Sets an ndarray data element specified by a byte array pointer.
int8_tstdlib_ndarray_set_ptr_value( conststructndarray*arr, uint8_t*idx, constvoid*v );The function accepts the following arguments:
- arr:
[in] struct ndarray*input ndarray. - idx:
[in] uint8_t*byte array pointer to an ndarray data element. - v:
[in] void*value to set.
Notes:
- The function does not perform bounds checking, and, thus, the function does not prevent you from overwriting unowned memory. Accordingly, the function assumes you know what you are doing.
- The function returns
-1if unable to set an element and0otherwise. - The function requires a pointer to a data value
vin 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.
int8_tstdlib_ndarray_set_ptr_float64( uint8_t*idx, constdoublev );The function accepts the following arguments:
- idx:
[in] uint8_t*byte array pointer to an ndarray data element. - v:
[in] doublevalue to set.
Notes:
- The function has no way of determining whether
idxactually points to a compatible memory address. Accordingly, overwriting unowned memory is possible, and this function assumes you know what you are doing. - The function always returns
0.
Sets a single-precision floating-point ndarray data element specified by a byte array pointer.
int8_tstdlib_ndarray_set_ptr_float32( uint8_t*idx, constfloatv );The function accepts the following arguments:
- idx:
[in] uint8_t*byte array pointer to an ndarray data element. - v:
[in] floatvalue to set.
Notes:
- The function has no way of determining whether
idxactually points to a compatible memory address. Accordingly, overwriting unowned memory is possible, and this function assumes you know what you are doing. - The function always returns
0.
Sets an unsigned 64-bit integer ndarray data element specified by a byte array pointer.
int8_tstdlib_ndarray_set_ptr_uint64( uint8_t*idx, constuint64_tv );The function accepts the following arguments:
- idx:
[in] uint8_t*byte array pointer to an ndarray data element. - v:
[in] uint64_tvalue to set.
Notes:
- The function has no way of determining whether
idxactually points to a compatible memory address. Accordingly, overwriting unowned memory is possible, and this function assumes you know what you are doing. - The function always returns
0.
Sets a signed 64-bit integer ndarray data element specified by a byte array pointer.
int8_tstdlib_ndarray_set_ptr_int64( uint8_t*idx, constint64_tv );The function accepts the following arguments:
- idx:
[in] uint8_t*byte array pointer to an ndarray data element. - v:
[in] int64_tvalue to set.
Notes:
- The function has no way of determining whether
idxactually points to a compatible memory address. Accordingly, overwriting unowned memory is possible, and this function assumes you know what you are doing. - The function always returns
0.
Sets an unsigned 32-bit integer ndarray data element specified by a byte array pointer.
int8_tstdlib_ndarray_set_ptr_uint32( uint8_t*idx, constuint32_tv );The function accepts the following arguments:
- idx:
[in] uint8_t*byte array pointer to an ndarray data element. - v:
[in] uint32_tvalue to set.
Notes:
- The function has no way of determining whether
idxactually points to a compatible memory address. Accordingly, overwriting unowned memory is possible, and this function assumes you know what you are doing. - The function always returns
0.
Sets a signed 32-bit integer ndarray data element specified by a byte array pointer.
int8_tstdlib_ndarray_set_ptr_int32( uint8_t*idx, constint32_tv );The function accepts the following arguments:
- idx:
[in] uint8_t*byte array pointer to an ndarray data element. - v:
[in] int32_tvalue to set.
Notes:
- The function has no way of determining whether
idxactually points to a compatible memory address. Accordingly, overwriting unowned memory is possible, and this function assumes you know what you are doing. - The function always returns
0.
Sets an unsigned 16-bit integer ndarray data element specified by a byte array pointer.
int8_tstdlib_ndarray_set_ptr_uint16( uint8_t*idx, constuint16_tv );The function accepts the following arguments:
- idx:
[in] uint8_t*byte array pointer to an ndarray data element. - v:
[in] uint16_tvalue to set.
Notes:
- The function has no way of determining whether
idxactually points to a compatible memory address. Accordingly, overwriting unowned memory is possible, and this function assumes you know what you are doing. - The function always returns
0.
Sets a signed 16-bit integer ndarray data element specified by a byte array pointer.
int8_tstdlib_ndarray_set_ptr_int16( uint8_t*idx, constint16_tv );The function accepts the following arguments:
- idx:
[in] uint8_t*byte array pointer to an ndarray data element. - v:
[in] int16_tvalue to set.
Notes:
- The function has no way of determining whether
idxactually points to a compatible memory address. Accordingly, overwriting unowned memory is possible, and this function assumes you know what you are doing. - The function always returns
0.
Sets an unsigned 8-bit integer ndarray data element specified by a byte array pointer.
int8_tstdlib_ndarray_set_ptr_uint8( uint8_t*idx, constuint8_tv );The function accepts the following arguments:
- idx:
[in] uint8_t*byte array pointer to an ndarray data element. - v:
[in] uint8_tvalue to set.
Notes:
- The function always returns
0.
Sets a signed 8-bit integer ndarray data element specified by a byte array pointer.
int8_tstdlib_ndarray_set_ptr_int8( uint8_t*idx, constint8_tv );The function accepts the following arguments:
- idx:
[in] uint8_t*byte array pointer to an ndarray data element. - v:
[in] int8_tvalue to set.
Notes:
- The function always returns
0.
Sets a double-precision complex floating-point ndarray data element specified by a byte array pointer.
int8_tstdlib_ndarray_set_ptr_complex128( uint8_t*idx, conststdlib_complex128_tv );The function accepts the following arguments:
- idx:
[in] uint8_t*byte array pointer to an ndarray data element. - v:
[in] stdlib_complex128_tvalue to set.
Notes:
- The function has no way of determining whether
idxactually points to a compatible memory address. Accordingly, overwriting unowned memory is possible, and this function assumes you know what you are doing. - The function always returns
0.
Sets a single-precision complex floating-point ndarray data element specified by a byte array pointer.
int8_tstdlib_ndarray_set_ptr_complex64( uint8_t*idx, conststdlib_complex64_tv );The function accepts the following arguments:
- idx:
[in] uint8_t*byte array pointer to an ndarray data element. - v:
[in] stdlib_complex64_tvalue to set.
Notes:
- The function has no way of determining whether
idxactually points to a compatible memory address. Accordingly, overwriting unowned memory is possible, and this function assumes you know what you are doing. - The function always returns
0.
Sets a boolean ndarray data element specified by a byte array pointer.
int8_tstdlib_ndarray_set_ptr_bool( uint8_t*idx, constboolv );The function accepts the following arguments:
- idx:
[in] uint8_t*byte array pointer to an ndarray data element. - v:
[in] boolvalue to set.
Notes:
- The function has no way of determining whether
idxactually points to a compatible memory address. Accordingly, overwriting unowned memory is possible, and this function assumes you know what you are doing. - The function always returns
0.
#include"stdlib/ndarray/ctor.h"#include"stdlib/ndarray/dtypes.h"#include"stdlib/ndarray/index_modes.h"#include"stdlib/ndarray/orders.h"#include"stdlib/ndarray/base/bytes_per_element.h"#include"stdlib/ndarray/base/dtype_char.h"#include<stdlib.h>#include<stdio.h>#include<stdint.h>#include<inttypes.h>voidprint_ndarray_contents( conststructndarray*x ) {
int64_ti;
doublev;
int8_ts;
for ( i=0; i<stdlib_ndarray_length( x ); i++ ) {
s=stdlib_ndarray_iget_float64( x, i, &v ); // WARNING: assumes `x->dtype` is float64if ( s!=0 ) {
printf( "Unable to resolve data element.\n" );
exit( 1 );
}
printf( "data[%"PRId64"] = %f\n", i, v );
}
}
intmain( void ) {
// 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)...structndarray*x1=malloc( sizeof( structndarray ) );
if ( x1==NULL ) {
printf( "Error allocating memory.\n" );
exit( 1 );
}
// Specify the underlying data type:enumSTDLIB_NDARRAY_DTYPEdtype=STDLIB_NDARRAY_FLOAT64;
x1->dtype=dtype;
// Create an underlying byte array:uint8_tbuffer[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
x1->data=buffer;
// Explicitly specify the number of bytes per element:x1->BYTES_PER_ELEMENT=STDLIB_NDARRAY_FLOAT64_BYTES_PER_ELEMENT;
// Specify the array shape:int64_tshape[] = { 3 }; // vector consisting of 3 doublesx1->shape=shape;
// Specify the array strides:int64_tstrides[] = { x1->BYTES_PER_ELEMENT };
x1->strides=strides;
// Specify the byte offset:x1->offset=0;
// Specify the array order (note: this does not matter for a 1-dimensional array):enumSTDLIB_NDARRAY_ORDERorder=STDLIB_NDARRAY_ROW_MAJOR;
x1->order=order;
// Specify the index mode:enumSTDLIB_NDARRAY_INDEX_MODEimode=STDLIB_NDARRAY_INDEX_ERROR;
x1->imode=imode;
// Specify the subscript index modes:int8_tsubmodes[] = { imode };
x1->submodes=submodes;
x1->nsubmodes=1;
// Explicitly specify the number of array dimensions:x1->ndims=1; // vector// Explicitly specify the number of array elements (doubles):x1->length=x1->shape[ 0 ];
// Explicitly specify the number of bytes:x1->byteLength= (x1->length) * (x1->BYTES_PER_ELEMENT);
// Explicitly set the array flags:x1->flags=stdlib_ndarray_flags( x1 );
printf( "dtype = %u\n", stdlib_ndarray_dtype( x1 ) );
printf( "length = %"PRId64"\n", stdlib_ndarray_length( x1 ) );
printf( "byteLength = %"PRId64"\n", stdlib_ndarray_byte_length( x1 ) );
printf( "ltr = %u\n", stdlib_ndarray_dtype_char( stdlib_ndarray_dtype( x1 ) ) );
printf( "\n" );
// Use the function interface to create an ndarray (NOTE: for future ABI compatibility, using the following function interface should be preferred)...structndarray*x2=stdlib_ndarray_allocate( dtype, buffer, 1, shape, strides, 0, order, imode, 1, submodes );
if ( x2==NULL ) {
printf( "Error allocating memory.\n" );
exit( 1 );
}
printf( "dtype = %u\n", stdlib_ndarray_dtype( x2 ) );
printf( "length = %"PRId64"\n", stdlib_ndarray_length( x2 ) );
printf( "byteLength = %"PRId64"\n", stdlib_ndarray_byte_length( x2 ) );
printf( "ltr = %u\n", stdlib_ndarray_dtype_char( stdlib_ndarray_dtype( x2 ) ) );
printf( "\n" );
// Set values in the underlying byte array using pointers:int64_tsub[] = { 0 };
uint8_t*ptr=stdlib_ndarray_get_ptr( x2, sub );
if ( ptr==NULL ) {
printf( "Unable to resolve data pointer.\n" );
exit( 1 );
}
*(double*)ptr=1.0;
sub[ 0 ] =1;
ptr=stdlib_ndarray_get_ptr( x2, sub );
if ( ptr==NULL ) {
printf( "Unable to resolve data pointer.\n" );
exit( 1 );
}
*(double*)ptr=2.0;
sub[ 0 ] =2;
ptr=stdlib_ndarray_get_ptr( x2, sub );
if ( ptr==NULL ) {
printf( "Unable to resolve data pointer.\n" );
exit( 1 );
}
*(double*)ptr=3.0;
// Print out the current ndarray elements:print_ndarray_contents( x2 );
printf( "\n" );
// Set values in the underlying byte array using a "generic" function:sub[ 0 ] =0;
doublev=4.0;
int8_tstatus=stdlib_ndarray_set( x2, sub, (void*)&v );
if ( status!=0 ) {
printf( "Unable to set data element.\n" );
exit( 1 );
}
sub[ 0 ] =1;
v=5.0;
status=stdlib_ndarray_set( x2, sub, (void*)&v );
if ( status!=0 ) {
printf( "Unable to set data element.\n" );
exit( 1 );
}
sub[ 0 ] =2;
v=6.0;
status=stdlib_ndarray_set( x2, sub, (void*)&v );
if ( status!=0 ) {
printf( "Unable to set data element.\n" );
exit( 1 );
}
// Print out the current ndarray elements:print_ndarray_contents( x2 );
printf( "\n" );
// Set values in the underlying byte array using a specialized function:sub[ 0 ] =0;
status=stdlib_ndarray_set_float64( x2, sub, 7.0 );
if ( status!=0 ) {
printf( "Unable to set data element.\n" );
exit( 1 );
}
sub[ 0 ] =1;
status=stdlib_ndarray_set_float64( x2, sub, 8.0 );
if ( status!=0 ) {
printf( "Unable to set data element.\n" );
exit( 1 );
}
sub[ 0 ] =2;
status=stdlib_ndarray_set_float64( x2, sub, 9.0 );
if ( status!=0 ) {
printf( "Unable to set data element.\n" );
exit( 1 );
}
// Print out the current ndarray elements:print_ndarray_contents( x2 );
printf( "\n" );
// Free allocated memory:stdlib_ndarray_free( x1 );
stdlib_ndarray_free( x2 );
}@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-2026. The Stdlib Authors.