Research
Recent Trends in Malicious Packages Targeting Discord
The Socket research team breaks down a sampling of malicious packages that download and execute files, among other suspicious behaviors, targeting the popular Discord platform.
@stdlib/ndarray-ctor
Advanced tools
Readme
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-ctor
var ndarray = require( '@stdlib/ndarray-ctor' );
Returns an ndarray
instance.
// Specify the array configuration:
var buffer = [ 1.0, 2.0, 3.0, 4.0 ];
var shape = [ 2, 2 ];
var order = 'row-major';
var strides = [ 2, 1 ];
var offset = 0;
// Create a new ndarray:
var arr = ndarray( 'generic', buffer, shape, strides, offset, order );
// 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.
var opts = {
'mode': 'clamp'
};
// Specify the array configuration:
var buffer = [ 1.0, 2.0, 3.0, 4.0 ];
var shape = [ 2, 2 ];
var order = 'row-major';
var strides = [ 2, 1 ];
var offset = 0;
// Create a new ndarray:
var arr = ndarray( 'generic', buffer, shape, strides, offset, order, opts );
// returns <ndarray>
// Attempt to access an out-of-bounds linear index (clamped):
var v = arr.iget( 10 );
// 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.
var opts = {
'submode': [ 'wrap', 'clamp' ]
};
// Specify the array configuration:
var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ];
var shape = [ 2, 2, 2 ];
var order = 'row-major';
var strides = [ 4, 2, 1 ];
var offset = 0;
// Create a new ndarray:
var arr = ndarray( 'generic', buffer, shape, strides, offset, order, opts );
// returns <ndarray>
// Attempt to access out-of-bounds subscripts:
var v = arr.get( -2, 10, -1 ); // linear index: 3
// returns 4.0
String value of the ndarray constructor name.
var str = ndarray.name;
// returns 'ndarray'
Size (in bytes) of the array (if known).
var Float64Array = require( '@stdlib/array-float64' );
// Specify the array configuration:
var buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] );
var shape = [ 2, 2 ];
var order = 'row-major';
var strides = [ 2, 1 ];
var offset = 0;
// Create a new ndarray:
var arr = ndarray( 'float64', buffer, shape, strides, offset, order );
// Get the byte length:
var nbytes = arr.byteLength;
// returns 32
If unable to determine the size of the array, the property value is null
.
// Specify the array configuration:
var buffer = [ 1.0, 2.0, 3.0, 4.0 ];
var shape = [ 2, 2 ];
var order = 'row-major';
var strides = [ 2, 1 ];
var offset = 0;
// Create a new ndarray:
var arr = ndarray( 'generic', buffer, shape, strides, offset, order );
// Get the byte length:
var nbytes = arr.byteLength;
// returns null
Size (in bytes) of each array element (if known).
var Float32Array = require( '@stdlib/array-float32' );
// Specify the array configuration:
var buffer = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] );
var shape = [ 2, 2 ];
var order = 'row-major';
var strides = [ 2, 1 ];
var offset = 0;
// Create a new ndarray:
var arr = ndarray( 'float32', buffer, shape, strides, offset, order );
// Get the number of bytes per element:
var nbytes = arr.BYTES_PER_ELEMENT;
// returns 4
If size of each array element is unknown, the property value is null
.
// Specify the array configuration:
var buffer = [ 1.0, 2.0, 3.0, 4.0 ];
var shape = [ 2, 2 ];
var order = 'row-major';
var strides = [ 2, 1 ];
var offset = 0;
// Create a new ndarray:
var arr = ndarray( 'generic', buffer, shape, strides, offset, order );
// Get the number of bytes per element:
var nbytes = arr.BYTES_PER_ELEMENT;
// returns null
A reference to the underlying data buffer.
var Int8Array = require( '@stdlib/array-int8' );
// Specify the array configuration:
var buffer = new Int8Array( [ 1, 2, 3, 4 ] );
var shape = [ 2, 2 ];
var order = 'row-major';
var strides = [ 2, 1 ];
var offset = 0;
// Create a new ndarray:
var arr = ndarray( 'int8', buffer, shape, strides, offset, order );
// Get the buffer reference:
var d = arr.data;
// returns <Int8Array>[ 1, 2, 3, 4 ]
var bool = ( d === buffer );
// returns true
Underlying data type.
var Uint8Array = require( '@stdlib/array-uint8' );
// Specify the array configuration:
var buffer = new Uint8Array( [ 1, 2, 3, 4 ] );
var shape = [ 2, 2 ];
var order = 'row-major';
var strides = [ -2, 1 ];
var offset = 2;
// Create a new ndarray:
var arr = ndarray( 'uint8', buffer, shape, strides, offset, order );
// Get the underlying data type:
var dtype = arr.dtype;
// 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]
).
var Int32Array = require( '@stdlib/array-int32' );
// Specify the array configuration:
var buffer = new Int32Array( [ 1, 2, 3, 4 ] );
var shape = [ 2, 2 ];
var order = 'column-major';
var strides = [ 1, 2 ];
var offset = 0;
// Create a new ndarray:
var arr = ndarray( 'int32', buffer, shape, strides, offset, order );
// Get the array flags:
var flg = arr.flags;
// returns {...}
Number of array elements.
var Uint16Array = require( '@stdlib/array-uint16' );
// Specify the array configuration:
var buffer = new Uint16Array( [ 1, 2, 3, 4 ] );
var shape = [ 2, 2 ];
var order = 'column-major';
var strides = [ -1, -2 ];
var offset = 3;
// Create a new ndarray:
var arr = ndarray( 'uint16', buffer, shape, strides, offset, order );
// Get the array length:
var len = arr.length;
// returns 4
Number of dimensions.
var Uint8ClampedArray = require( '@stdlib/array-uint8c' );
// Specify the array configuration:
var buffer = new Uint8ClampedArray( [ 1, 2, 3, 4 ] );
var shape = [ 2, 2 ];
var order = 'row-major';
var strides = [ -2, -1 ];
var offset = 3;
// Create a new ndarray:
var arr = ndarray( 'uint8c', buffer, shape, strides, offset, order );
// Get the number of dimensions:
var ndims = arr.ndims;
// returns 2
Index offset which specifies the buffer
index at which to start iterating over array elements.
var Int16Array = require( '@stdlib/array-int16' );
// Specify the array configuration:
var buffer = new Int16Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] );
var shape = [ 2, 2 ];
var order = 'row-major';
var strides = [ -2, -1 ];
var offset = 10;
// Create a new ndarray:
var arr = ndarray( 'int16', buffer, shape, strides, offset, order );
// Get the index offset:
var o = arr.offset;
// returns 10
Array order. The array order is either row-major (C-style) or column-major (Fortran-style).
var Uint32Array = require( '@stdlib/array-uint32' );
// Specify the array configuration:
var buffer = new Uint32Array( [ 1, 2, 3, 4 ] );
var shape = [ 2, 2 ];
var order = 'row-major';
var strides = [ 2, 1 ];
var offset = 0;
// Create a new ndarray:
var arr = ndarray( 'uint32', buffer, shape, strides, offset, order );
// Get the array order:
var ord = arr.order;
// returns 'row-major'
Returns a copy of the array shape.
// Specify the array configuration:
var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];
var shape = [ 2, 2 ];
var order = 'row-major';
var strides = [ 2, 1 ];
var offset = 2;
// Create a new ndarray:
var arr = ndarray( 'generic', buffer, shape, strides, offset, order );
// Get the array shape:
var dims = 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:
var buffer = [ 1.0, 2.0, 3.0, 4.0 ];
var shape = [ 2, 2 ];
var order = 'column-major';
var strides = [ -1, 2 ];
var offset = 1;
// Create a new ndarray:
var arr = ndarray( 'generic', buffer, shape, strides, offset, order );
// Get the array strides:
var s = 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:
var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ];
var shape = [ 2, 2 ];
var order = 'row-major';
var strides = [ 2, 1 ];
var offset = 2;
// Create a new ndarray:
var arr = ndarray( 'generic', buffer, shape, strides, offset, order );
// Get the element located at (1,1):
var v = arr.get( 1, 1 );
// returns 6.0
Returns an array element located at a specified linear index.
// Specify the array configuration:
var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ];
var shape = [ 2, 2 ];
var order = 'row-major';
var strides = [ 2, 1 ];
var offset = 2;
// Create a new ndarray:
var arr = ndarray( 'generic', buffer, shape, strides, offset, order );
// Get the element located at index 3:
var v = arr.iget( 3 );
// 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.
// Specify the array configuration:
var buffer = [ 1.0, 2.0, 3.0, 4.0 ];
var shape = [ 2, 2 ];
var order = 'row-major';
var strides = [ 2, 1 ];
var offset = 0;
// Create a new ndarray:
var arr = ndarray( 'generic', buffer, shape, strides, offset, order );
// Set the element located at (1,1):
arr.set( 1, 1, 40.0 );
var v = arr.get( 1, 1 );
// returns 40.0
// Get the underlying buffer:
var d = 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:
var buffer = [ 1.0, 2.0, 3.0, 4.0 ];
var shape = [ 2, 2 ];
var order = 'row-major';
var strides = [ 2, 1 ];
var offset = 0;
// Create a new ndarray:
var arr = ndarray( 'generic', buffer, shape, strides, offset, order );
// Set the element located at index 3:
arr.iset( 3, 40.0 );
var v = arr.iget( 3 );
// returns 40.0
// Get the underlying buffer:
var d = 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:
var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ];
var shape = [ 3, 2 ];
var order = 'row-major';
var strides = [ 2, 1 ];
var offset = 2;
// Create a new ndarray:
var arr = ndarray( 'generic', buffer, shape, strides, offset, order );
// Serialize to a string:
var str = 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 JSON object
. JSON.stringify()
implicitly calls this method when stringifying an ndarray
instance.
// Specify the array configuration:
var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ];
var shape = [ 3, 2 ];
var order = 'row-major';
var strides = [ 2, 1 ];
var offset = 2;
// Create a new ndarray:
var arr = ndarray( 'generic', buffer, shape, strides, offset, order );
// Serialize to JSON:
var o = 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 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.
var buffer = [ 1 ];
var shape = [];
var order = 'row-major';
var strides = [ 0 ];
var offset = 0;
// Create a new zero-dimensional array:
var arr = ndarray( 'generic', buffer, shape, strides, offset, order );
// returns <ndarray>
var Float32Array = require( '@stdlib/array-float32' );
var ndarray = require( '@stdlib/ndarray-ctor' );
// Create a data buffer:
var buffer = new Float32Array( (3*3*3*3) + 100 );
// Specify the array shape:
var shape = [ 3, 3, 3, 3 ];
// Specify the array strides:
var strides = [ 27, 9, 3, 1 ];
// Specify the index offset:
var offset = 4;
// Specify the order:
var order = 'row-major'; // C-style
// Create a new ndarray:
var arr = ndarray( 'float32', buffer, shape, strides, offset, order );
// Retrieve an array value:
var v = 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:
var str = 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>
struct ndarray {
// Underlying data type:
int16_t dtype;
// Pointer to the underlying byte array:
uint8_t *data;
// Number of array dimensions:
int64_t ndims;
// 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_t offset;
// Array order (either row-major (C-style) or column-major (Fortran-style)):
int8_t order;
// Mode specifying how to handle indices which exceed array dimensions:
int8_t imode;
// Number of subscript modes:
int64_t nsubmodes;
// Mode(s) specifying how to handle subscripts which exceed array dimensions on a per dimension basis:
int8_t *submodes;
// Number of array elements:
int64_t length;
// Size in bytes:
int64_t byteLength;
// Number of bytes per element (i.e., item size):
int64_t BYTES_PER_ELEMENT;
// Bit mask providing information regarding the memory layout of the array (e.g., see macros):
int64_t flags;
};
Macro defining a flag indicating whether an ndarray is row-major (C-style) contiguous.
#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.
#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.
#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:
enum STDLIB_NDARRAY_DTYPE dtype = STDLIB_NDARRAY_FLOAT64;
// Create an underlying byte array:
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 };
// Specify the number of array dimensions:
int64_t ndims = 1;
// Specify the array shape:
int64_t shape[] = { 3 }; // vector consisting of 3 doubles
// Specify the array strides:
int64_t strides[] = { STDLIB_NDARRAY_FLOAT64_BYTES_PER_ELEMENT };
// Specify the byte offset:
int64_t offset = 0;
// Specify the array order (note: this does not matter for a 1-dimensional array):
enum STDLIB_NDARRAY_ORDER order = STDLIB_NDARRAY_ROW_MAJOR;
// Specify the index mode:
enum STDLIB_NDARRAY_INDEX_MODE imode = STDLIB_NDARRAY_INDEX_ERROR;
// Specify the subscript index modes:
int8_t submodes[] = { STDLIB_NDARRAY_INDEX_ERROR };
int64_t nsubmodes = 1;
// Create an ndarray:
struct ndarray *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:
[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).struct 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).
#include "stdlib/ndarray/ctor.h"
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
// ...
// Create an ndarray:
struct ndarray *x = stdlib_ndarray_allocate( ... );
if ( x == NULL ) {
fprintf( stderr, "Error allocating memory.\n" );
exit( 1 );
}
// ...
// Retrieve the ndarray size:
int64_t N = stdlib_ndarray_bytelength( x );
// ...
// Free allocated memory:
stdlib_ndarray_free( x );
The function accepts the following arguments:
[in] struct ndarray*
input ndarray.int64_t stdlib_ndarray_bytelength( const struct ndarray *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:
struct ndarray *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:
[in] struct ndarray*
input ndarray.uint8_t * stdlib_ndarray_data( const struct ndarray *arr );
Returns an ndarray dimension.
#include "stdlib/ndarray/ctor.h"
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
// ...
// Create an ndarray:
struct ndarray *x = stdlib_ndarray_allocate( ... );
if ( x == NULL ) {
fprintf( stderr, "Error allocating memory.\n" );
exit( 1 );
}
// ...
// Retrieve a dimension:
int64_t dim = stdlib_ndarray_dimension( x, 0 );
// ...
// Free allocated memory:
stdlib_ndarray_free( x );
The function accepts the following arguments:
[in] struct ndarray*
input ndarray.[in] int64_t
dimension index.int64_t stdlib_ndarray_dimension( const struct ndarray *arr, const int64_t i );
Notes:
Disables specified ndarray flags.
#include "stdlib/ndarray/ctor.h"
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
// ...
// Create an ndarray:
struct ndarray *x = stdlib_ndarray_allocate( ... );
if ( x == NULL ) {
fprintf( stderr, "Error allocating memory.\n" );
exit( 1 );
}
// ...
// Disables specified ndarray flags:
int8_t status = stdlib_ndarray_disable_flags( x, STDLIB_NDARRAY_ROW_MAJOR_CONTIGUOUS_FLAG );
// ...
// Free allocated memory:
stdlib_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.
int8_t stdlib_ndarray_disable_flags( const struct ndarray *arr, const int64_t flags );
Notes:
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:
struct ndarray *x = stdlib_ndarray_allocate( ... );
if ( x == NULL ) {
fprintf( stderr, "Error allocating memory.\n" );
exit( 1 );
}
// ...
// Retrieve the dtype:
enum STDLIB_NDARRAY_DTYPE dtype = stdlib_ndarray_dtype( x );
// ...
// Free allocated memory:
stdlib_ndarray_free( x );
The function accepts the following arguments:
[in] struct ndarray*
input ndarray.int16_t stdlib_ndarray_dtype( const struct ndarray *arr );
Enables specified ndarray flags.
#include "stdlib/ndarray/ctor.h"
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
// ...
// Create an ndarray:
struct ndarray *x = stdlib_ndarray_allocate( ... );
if ( x == NULL ) {
fprintf( stderr, "Error allocating memory.\n" );
exit( 1 );
}
// ...
// Enables specified ndarray flags:
int8_t status = stdlib_ndarray_enable_flags( x, STDLIB_NDARRAY_ROW_MAJOR_CONTIGUOUS_FLAG );
// ...
// Free allocated memory:
stdlib_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.
int8_t stdlib_ndarray_enable_flags( const struct ndarray *arr, const int64_t flags );
Notes:
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:
struct ndarray *x = stdlib_ndarray_allocate( ... );
if ( x == NULL ) {
fprintf( stderr, "Error allocating memory.\n" );
exit( 1 );
}
// ...
// Retrieve the ndarray flags:
int64_t flags = stdlib_ndarray_flags( x );
// ...
// Free allocated memory:
stdlib_ndarray_free( x );
The function accepts the following arguments:
[in] struct ndarray*
input ndarray.int64_t stdlib_ndarray_flags( const struct ndarray *arr );
Frees an ndarray's allocated memory.
#include "stdlib/ndarray/ctor.h"
#include <stdlib.h>
#include <stdio.h>
// ...
// Create an ndarray:
struct ndarray *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:
[in] struct ndarray*
input ndarray.void stdlib_ndarray_free( struct ndarray *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:
struct ndarray *x = stdlib_ndarray_allocate( ... );
if ( x == NULL ) {
fprintf( stderr, "Error allocating memory.\n" );
exit( 1 );
}
// ...
// Test whether an ndarray is row-major contiguous:
int8_t out = stdlib_ndarray_flags( x, STDLIB_NDARRAY_ROW_MAJOR_CONTIGUOUS_FLAG );
// ...
// Free allocated memory:
stdlib_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.
int8_t stdlib_ndarray_has_flags( const struct ndarray *arr, const int64_t flags );
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:
struct ndarray *x = stdlib_ndarray_allocate( ... );
if ( x == NULL ) {
fprintf( stderr, "Error allocating memory.\n" );
exit( 1 );
}
// ...
// Retrieve the index mode:
enum STDLIB_NDARRAY_INDEX_MODE imode = stdlib_ndarray_index_mode( x );
// ...
// Free allocated memory:
stdlib_ndarray_free( x );
The function accepts the following arguments:
[in] struct ndarray*
input ndarray.int8_t stdlib_ndarray_index_mode( const struct ndarray *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:
struct ndarray *x = stdlib_ndarray_allocate( ... );
if ( x == NULL ) {
fprintf( stderr, "Error allocating memory.\n" );
exit( 1 );
}
// ...
// Retrieve the number of elements:
int64_t N = stdlib_ndarray_length( x );
// ...
// Free allocated memory:
stdlib_ndarray_free( x );
The function accepts the following arguments:
[in] struct ndarray*
input ndarray.int64_t stdlib_ndarray_length( const struct ndarray *arr );
Returns the number of ndarray dimensions.
#include "stdlib/ndarray/ctor.h"
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
// ...
// Create an ndarray:
struct ndarray *x = stdlib_ndarray_allocate( ... );
if ( x == NULL ) {
fprintf( stderr, "Error allocating memory.\n" );
exit( 1 );
}
// ...
// Retrieve the number of dimensions:
int64_t ndims = stdlib_ndarray_ndims( x );
// ...
// Free allocated memory:
stdlib_ndarray_free( x );
The function accepts the following arguments:
[in] struct ndarray*
input ndarray.int64_t stdlib_ndarray_ndims( const struct ndarray *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:
struct ndarray *x = stdlib_ndarray_allocate( ... );
if ( x == NULL ) {
fprintf( stderr, "Error allocating memory.\n" );
exit( 1 );
}
// ...
// Retrieve the number of index modes:
int64_t n = stdlib_ndarray_nsubmodes( x );
// ...
// Free allocated memory:
stdlib_ndarray_free( x );
The function accepts the following arguments:
[in] struct ndarray*
input ndarray.int64_t stdlib_ndarray_nsubmodes( const struct ndarray *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:
struct ndarray *x = stdlib_ndarray_allocate( ... );
if ( x == NULL ) {
fprintf( stderr, "Error allocating memory.\n" );
exit( 1 );
}
// ...
// Retrieve the index offset:
int64_t offset = stdlib_ndarray_offset( x );
// ...
// Free allocated memory:
stdlib_ndarray_free( x );
The function accepts the following arguments:
[in] struct ndarray*
input ndarray.int64_t stdlib_ndarray_offset( const struct ndarray *arr );
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:
struct ndarray *x = stdlib_ndarray_allocate( ... );
if ( x == NULL ) {
fprintf( stderr, "Error allocating memory.\n" );
exit( 1 );
}
// ...
// Retrieve the order:
enum STDLIB_NDARRAY_ORDER order = stdlib_ndarray_order( x );
// ...
// Free allocated memory:
stdlib_ndarray_free( x );
The function accepts the following arguments:
[in] struct ndarray*
input ndarray.int8_t stdlib_ndarray_order( const struct ndarray *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:
struct ndarray *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:
[in] struct ndarray*
input ndarray.int64_t * stdlib_ndarray_shape( const struct ndarray *arr );
Returns an ndarray stride (in bytes).
#include "stdlib/ndarray/ctor.h"
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
// ...
// Create an ndarray:
struct ndarray *x = stdlib_ndarray_allocate( ... );
if ( x == NULL ) {
fprintf( stderr, "Error allocating memory.\n" );
exit( 1 );
}
// ...
// Retrieve a stride:
int64_t s = stdlib_ndarray_stride( x, 0 );
// ...
// Free allocated memory:
stdlib_ndarray_free( x );
The function accepts the following arguments:
[in] struct ndarray*
input ndarray.[in] int64_t
dimension index.int64_t stdlib_ndarray_stride( const struct ndarray *arr, const int64_t i );
Notes:
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:
struct ndarray *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:
[in] struct ndarray*
input ndarray.int64_t * stdlib_ndarray_strides( const struct ndarray *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:
struct ndarray *x = stdlib_ndarray_allocate( ... );
if ( x == NULL ) {
fprintf( stderr, "Error allocating memory.\n" );
exit( 1 );
}
// ...
// Retrieve an index mode:
enum STDLIB_NDARRAY_INDEX_MODE mode = stdlib_ndarray_submode( x, 0 );
// ...
// Free allocated memory:
stdlib_ndarray_free( x );
The function accepts the following arguments:
[in] struct ndarray*
input ndarray.[in] int64_t
dimension index.int8_t stdlib_ndarray_submode( const struct ndarray *arr, const int64_t i );
Notes:
Returns ndarray subscript modes.
#include "stdlib/ndarray/ctor.h"
#include "stdlib/ndarray/index_modes.h"
#include <stdlib.h>
#include <stdio.h>
// ...
// Create an ndarray:
struct ndarray *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:
[in] struct ndarray*
input ndarray.int8_t * stdlib_ndarray_submodes( const struct ndarray *arr );
Returns an ndarray data element.
int8_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.
int8_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.
int8_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.
int8_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.
int8_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.
int8_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.
int8_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.
int8_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.
int8_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.
int8_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.
int8_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.
int8_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.
int8_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.
int8_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.
uint8_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.
int8_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.
int8_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.
int8_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.
int8_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.
int8_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.
int8_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.
int8_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.
int8_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.
int8_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.
int8_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.
int8_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.
int8_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.
int8_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.
int8_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.
int8_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.
int8_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.
int8_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.
int8_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.
int8_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.
int8_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.
int8_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.
int8_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.
int8_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.
int8_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.
int8_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.
int8_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.
int8_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.
int8_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.
uint8_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.
int8_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.
int8_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.
int8_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.
int8_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.
int8_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.
int8_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.
int8_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.
int8_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.
int8_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.
int8_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.
int8_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.
int8_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.
int8_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.
int8_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.
int8_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.
int8_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.
int8_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.
int8_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.
int8_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.
int8_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.
int8_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.
int8_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.
int8_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.
int8_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.
int8_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.
int8_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.
int8_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.
int8_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.
int8_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.
int8_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.
int8_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.
int8_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.
int8_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.
int8_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.
int8_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.
int8_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.
int8_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.
int8_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.
int8_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.
int8_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.
int8_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.
int8_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
.#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>
void print_ndarray_contents( const struct ndarray *x ) {
int64_t i;
double v;
int8_t s;
for ( i = 0; i < stdlib_ndarray_length( x ); i++ ) {
s = stdlib_ndarray_iget_float64( x, i, &v ); // WARNING: assumes `x->dtype` is float64
if ( s != 0 ) {
printf( "Unable to resolve data element.\n" );
exit( 1 );
}
printf( "data[%"PRId64"] = %f\n", i, v );
}
}
int main( 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)...
struct ndarray *x1 = malloc( sizeof( struct ndarray ) );
if ( x1 == NULL ) {
printf( "Error allocating memory.\n" );
exit( 1 );
}
// Specify the underlying data type:
enum STDLIB_NDARRAY_DTYPE dtype = STDLIB_NDARRAY_FLOAT64;
x1->dtype = dtype;
// Create an underlying byte array:
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 };
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_t shape[] = { 3 }; // vector consisting of 3 doubles
x1->shape = shape;
// Specify the array strides:
int64_t strides[] = { 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):
enum STDLIB_NDARRAY_ORDER order = STDLIB_NDARRAY_ROW_MAJOR;
x1->order = order;
// Specify the index mode:
enum STDLIB_NDARRAY_INDEX_MODE imode = STDLIB_NDARRAY_INDEX_ERROR;
x1->imode = imode;
// Specify the subscript index modes:
int8_t submodes[] = { 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_bytelength( 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)...
struct ndarray *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_bytelength( 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_t sub[] = { 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;
double v = 4.0;
int8_t status = 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-2024. The Stdlib Authors.
FAQs
Multidimensional array constructor.
The npm package @stdlib/ndarray-ctor receives a total of 1,232 weekly downloads. As such, @stdlib/ndarray-ctor popularity was classified as popular.
We found that @stdlib/ndarray-ctor demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 4 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
The Socket research team breaks down a sampling of malicious packages that download and execute files, among other suspicious behaviors, targeting the popular Discord platform.
Security News
Socket CEO Feross Aboukhadijeh joins a16z partners to discuss how modern, sophisticated supply chain attacks require AI-driven defenses and explore the challenges and solutions in leveraging AI for threat detection early in the development life cycle.
Security News
NIST's new AI Risk Management Framework aims to enhance the security and reliability of generative AI systems and address the unique challenges of malicious AI exploits.