Grafeo  0.0.2
Library for graph problems in C and Python
array.h
1 /* ===================================================================
2 # Copyright (C) 2015-2015
3 # Anderson Tavares <nocturne.pe at gmail.com> PK 0x38e7bfc5c2def8ff
4 # Lucy Mansilla <lucyacm at gmail.com>
5 # Caio de Braz <caiobraz at gmail.com>
6 # Hans Harley <hansbecc at gmail.com>
7 # Paulo Miranda <pavmbr at yahoo.com.br>
8 #
9 # Institute of Mathematics and Statistics - IME
10 # University of Sao Paulo - USP
11 #
12 # This file is part of Grafeo.
13 #
14 # Grafeo is free software: you can redistribute it and/or
15 # modify it under the terms of the GNU General Public License
16 # as published by the Free Software Foundation, either version
17 # 3 of the License, or (at your option) any later version.
18 #
19 # Grafeo is distributed in the hope that it will be useful,
20 # but WITHOUT ANY WARRANTY; without even the implied warranty
21 # of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
22 # See the GNU General Public License for more details.
23 #
24 # You should have received a copy of the GNU General Public
25 # License along with Grafeo. If not, see
26 # <http://www.gnu.org/licenses/>.
27 # ===================================================================*/
28 #ifndef GRAFEO_ARRAY_H
29 #define GRAFEO_ARRAY_H
30 
31 #include <grafeo/type.h>
32 #include <stdlib.h>
33 #include <string.h>
34 
42 typedef struct
43 _Array{
44  uint16_t dim;
45  uint32_t* size;
46  uint64_t num_elements;
47  size_t num_bytes;
48  DataType type;
49  union{
50  void* data;
51  unsigned char* data_uint8;
52  uint16_t* data_uint16;
53  uint32_t* data_uint32;
54  uint64_t* data_uint64;
55  char* data_int8;
56  int16_t* data_int16;
57  int32_t* data_int32;
58  int64_t* data_int64;
59  float* data_float;
60  double* data_double;
61  unsigned int* data_int;
62  };
63 }Array;
64 /*-----------------------------------
65  * ARRAY CREATION FUNCTIONS
66  *-----------------------------------*/
73 Array* array_new();
79 Array* array_new_with_dim(uint16_t dim);
85 Array* array_new_with_size(uint16_t dim, uint32_t* size);
91 Array* array_new_with_size_type(uint16_t dim, uint32_t* size, DataType type);
96 Array* array_new_1D(uint32_t size1);
101 Array* array_new_2D(uint32_t size1, uint32_t size2);
106 Array* array_new_3D(uint32_t size1, uint32_t size2, uint32_t size3);
111 Array* array_new_4D(uint32_t size1, uint32_t size2, uint32_t size3, uint32_t size4);
116 Array* array_new_1D_type(uint32_t size1, DataType type);
121 Array* array_new_2D_type(uint32_t size1, uint32_t size2, DataType type);
126 Array* array_new_3D_type(uint32_t size1, uint32_t size2, uint32_t size3, DataType type);
131 Array* array_new_4D_type(uint32_t size1, uint32_t size2, uint32_t size3, uint32_t size4, DataType type);
140 Array* array_zeros(uint16_t dim, uint32_t* sizes, DataType type);
149 Array* array_ones(uint16_t dim, uint32_t* sizes, DataType type);
150 /*-----------------------------------
151  * ARRAY OPERATIONS FUNCTIONS
152  *-----------------------------------*/
157 void array_fill(Array* array, double value);
162 void array_free(Array* array);
163 /*-----------------------------------
164  * ARRAY ACCESSOR FUNCTIONS
165  *-----------------------------------*/
170 uint64_t array_get_num_elements(Array* array);
175 DataType array_get_type(Array* array);
180 uint16_t array_get_dim(Array* array);
186 uint32_t* array_get_size(Array* array);
191 void* array_get_data(Array* array);
192 
193 #endif
uint16_t dim
Definition: array.h:44
Array * array_new_3D_type(uint32_t size1, uint32_t size2, uint32_t size3, DataType type)
Create a 3D array (each elem: sizeof(elementsize) bytes)
size_t num_bytes
Definition: array.h:47
void array_fill(Array *array, double value)
uint16_t array_get_dim(Array *array)
Get number of dimensions of an array.
uint64_t num_elements
Definition: array.h:46
Array * array_new_with_dim(uint16_t dim)
Create a new array: structure and space for size, without allocating data and defining sizes...
Array * array_new_4D(uint32_t size1, uint32_t size2, uint32_t size3, uint32_t size4)
Create a 4D array.
Array * array_new_with_size_type(uint16_t dim, uint32_t *size, DataType type)
Create a new array with size and allocated data, without value.
Array * array_new_2D_type(uint32_t size1, uint32_t size2, DataType type)
Create a 2D array (each elem: sizeof(elementsize) bytes)
Array * array_new_1D(uint32_t size1)
Create a 1D array.
uint32_t * size
Definition: array.h:45
uint32_t * array_get_size(Array *array)
Get vector of sizes of each dimension of the array.
Array * array_new_2D(uint32_t size1, uint32_t size2)
Create a 2D array.
Array * array_new_4D_type(uint32_t size1, uint32_t size2, uint32_t size3, uint32_t size4, DataType type)
Create a 4D array (each elem: sizeof(elementsize) bytes)
Definition: array.h:42
DataType array_get_type(Array *array)
Get data type of the array.
Array * array_new_1D_type(uint32_t size1, DataType type)
Create a 1D array (each elem: sizeof(elementsize) bytes)
void array_free(Array *array)
Free array memory.
Array * array_new_3D(uint32_t size1, uint32_t size2, uint32_t size3)
Create a 3D array.
Array * array_new_with_size(uint16_t dim, uint32_t *size)
Create a new array with size (sizeof(char) bytes) and allocated data, without value.
Array * array_new()
Create a new array: just the structure, without allocating data and size.
void * array_get_data(Array *array)
Get data vector of array.
uint64_t array_get_num_elements(Array *array)
Get total number of elements of an array.
DataType type
Definition: array.h:48