#include "array.h"#include "helper.h"#include <stdarg.h>#include <string.h>#include <gsl/gsl_rng.h>#include <time.h>Go to the source code of this file.
Functions | |
| void | array_calc_colindex (ulong offset, const uint *size, uint nsize, uint *index) |
| calculate the column-major index-tuple given the offset from element 0. | |
| void | array_calc_rowindex (ulong offset, const uint *size, uint nsize, uint *index) |
| calculate the row-major index-tuple given the offset from element 0. | |
| bool | array_comparable (const Array *a, const Array *b) |
| Compare two array's dimensions and datatype. | |
| Array * | array_concatenate (const Array *a, const Array *b, int dim) |
| concatenate two arrays. | |
| Array * | array_convert_rowcolmajor (Array *a, bool alloc) |
| convert a row-major array to col-major. | |
| Array * | array_copy (const Array *in, bool allocdata) |
| makes a copy of an array. | |
| int | array_dimred (Array *a) |
| Delete unnecessary dimensions (of size 1). | |
| void | array_dtype_to_double (double *out, void *mem, DType dt) |
| cast memory of type dt in location mem to double. | |
| void | array_free (Array *a) |
| free all memory associated with the array. | |
| Array * | array_fromptr (DType dtype, uint ndim, void *data, const uint *size) |
| Initialize new array struct. | |
| Array * | array_fromptr2 (DType dtype, uint ndim, void *data,...) |
| Initialize new array struct. | |
| void * | array_index (const Array *a, uint *idx) |
| Index the array. | |
| void * | array_index2 (const Array *a,...) |
| Index the array. | |
| void * | array_max (const Array *a) |
| Get maximum element from array. | |
| void * | array_min (const Array *a) |
| Get minimum element from array. | |
| Array * | array_new (DType dtype, uint ndim, const uint *dims) |
| Initialize new array struct. | |
| Array * | array_new2 (DType dtype, uint ndim,...) |
| Initialize new array struct. | |
| Array * | array_new_dummy (DType dtype, uint ndim,...) |
| create array that is filled with values from 1 to n over all dimensions. | |
| void | array_print (Array *a, uint nel_per_dim, FILE *out) |
| print an array. | |
| Array * | array_randunif (unsigned long seed, uint ndim,...) |
| create array that is filled with random values from [0, ..., 1]. | |
| void | array_reverse (Array *a) |
| Reverse order of elements in a (in-place). | |
| int | array_scale (Array *a, double x) |
| multiply all entries in array with x. | |
| void | array_shuffle (Array *a, unsigned long seed) |
| shuffle the entries of an array. | |
| Array * | array_slice (const Array *a, const char *slicedesc) |
| Extract sub-arrays from array. | |
| void | array_typecast (Array *a, DType target_type) |
| Array-typecast. | |
concatenate two arrays.
The two arrays must have the same number of elements in all dimensions except in the concatenated dimension.
Example:
[ 1 2 [ 7 8
3 4 9 10
5 6 ] 11 12]
=> [ 1 2
3 4
5 6
7 8
9 10
11 12 ]
| a,b | the two arrays to concatenate (must be 1D/2D arrays of arbitrary type); if one of them is NULL, return a copy of the other one | |
| dim | the dimension along which they are to be concatenated (0-rows, 1-columns) |
| int array_dimred | ( | Array * | a | ) |
| void array_dtype_to_double | ( | double * | out, | |
| void * | mem, | |||
| DType | dt | |||
| ) |
| void array_free | ( | Array * | a | ) |
Initialize new array struct.
Memory for the data is not allocated but set to data.
| dtype | the datatype of the array | |
| ndim | number of dimensions | |
| data | the data for the array | |
| ... | the number of elements in each of the dimensions |
Initialize new array struct.
Memory for the data is not allocated but set to data.
| dtype | the datatype of the array | |
| ndim | number of dimensions | |
| data | the data for the array | |
| ... | the number of elements in each of the dimensions |
Index the array.
You need to provide as many arguments as there are dimensions in the array. A pointer to the corresponding memory in the array is returned. To use it you need to cast it:
uint idx[3]={1,2,3}; float a = *(float*)array_index( arr, idx );
| a | the array | |
| idx | array of size a->ndim giving the indices |
| void* array_index2 | ( | const Array * | a, | |
| ... | ||||
| ) |
Index the array.
You need to provide as many arguments as there are dimensions in the array. A pointer to the corresponding memory in the array is returned. To use it you need to cast it:
float a = *(float*)array_index2( arr, 1, 2 );
| a | the array | |
| ... | a->ndim integers |
| void* array_max | ( | const Array * | a | ) |
Get maximum element from array.
You can easily find the index of this element by doing
Array *a = get_array_from_somewhere(); long idx = (array_max(a)-(a->data))/a->dtype_size; // if you need an index-tuple, you can do uint idxtuple[num_dimension]; array_calc_rowindex( idx, a->size, a->ndim, idxtuple );
| a | the array |
| void* array_min | ( | const Array * | a | ) |
Get minimum element from array.
You can easily find the index of this element by doing
Array *a = get_array_from_somewhere(); long idx = (array_min(a)-(a->data))/a->dtype_size; // if you need an index-tuple, you can do uint idxtuple[num_dimension]; array_calc_rowindex( idx, a->size, a->ndim, idxtuple );
| a | the array |
create array that is filled with random values from [0, ..., 1].
Mainly used for debugging stuff.
| seed | to use for the random numbers; if seed=0, the current time is used | |
| ndim | number of dimensions | |
| ... | the number of elements in each of the dimensions |
| void array_reverse | ( | Array * | a | ) |
| int array_scale | ( | Array * | a, | |
| double | x | |||
| ) |
| void array_shuffle | ( | Array * | a, | |
| unsigned long | seed | |||
| ) |
Extract sub-arrays from array.
This is a function for creating array slices from an existing array. I.e. you can extract sub-arrays similar to interpreted languages like python or MATLAB.
See Slicing Array Objects for the format of the slice string.
| a | the array | |
| slicedesc | the description of the slice as described in Slicing Array Objects |
Array-typecast.
Typecast the whole array.
Warning:
| a | the array | |
| target_type | the target type |
1.7.0