Added const keyword to functions, when possible.

This commit is contained in:
2023-02-24 19:17:31 +01:00
parent 7cce34a3e1
commit fdfe67d83e
2 changed files with 6 additions and 6 deletions

View File

@@ -15,7 +15,7 @@ void tensor_destroy(tensor t)
} }
} }
int tensor_is_empty(tensor t){ int tensor_is_empty(const tensor t){
return t->elements == NULL || t->size == NULL; return t->elements == NULL || t->size == NULL;
} }
@@ -80,7 +80,7 @@ int tensor_set(tensor t, const int *index, t_type val)
return 1; return 1;
} }
t_type tensor_get(tensor t, const int *index, int *success) t_type tensor_get(const tensor t, const int *index, int *success)
{ {
int i, offset = 0; int i, offset = 0;
if(tensor_is_empty(t)) return 0; if(tensor_is_empty(t)) return 0;
@@ -141,7 +141,7 @@ void tensor_for_each_elem(tensor t, t_type (*func)(t_type))
} }
} }
void tensor_print(tensor t) void tensor_print(const tensor t)
{ {
int i, j; int i, j;
int *indx; int *indx;

View File

@@ -21,20 +21,20 @@ typedef struct _tensor {
tensor tensor_new(void); tensor tensor_new(void);
void tensor_destroy(tensor t); void tensor_destroy(tensor t);
int tensor_is_empty(tensor t); int tensor_is_empty(const tensor t);
int _tensor_check_size(const int *size, int dim); int _tensor_check_size(const int *size, int dim);
int _tensor_set_size(tensor t, const int *size, int dim); int _tensor_set_size(tensor t, const int *size, int dim);
int tensor_set(tensor t, const int *index, t_type val); int tensor_set(tensor t, const int *index, t_type val);
t_type tensor_get(tensor t, const int *index, int *success); t_type tensor_get(const tensor t, const int *index, int *success);
int tensor_init_one(tensor t, int dimension, const int *size); int tensor_init_one(tensor t, int dimension, const int *size);
int tensor_init_zero(tensor t, int dimension, const int *size); int tensor_init_zero(tensor t, int dimension, const int *size);
int tensor_init_rand(tensor t, int dimension, const int *size); int tensor_init_rand(tensor t, int dimension, const int *size);
void tensor_for_each_elem(tensor t, t_type (*func)(t_type)); void tensor_for_each_elem(tensor t, t_type (*func)(t_type));
void tensor_print(tensor t); void tensor_print(const tensor t);
#endif #endif