[matrix/utils] adding resize_fill_zeros
This commit is contained in:
18
src/matrix.h
18
src/matrix.h
@@ -124,6 +124,24 @@
|
|||||||
return true; \
|
return true; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
|
static inline bool name##_resize_fill_zeros(name##_t *self, size_t m, size_t n) { \
|
||||||
|
size_t old_m = self->m; \
|
||||||
|
bool ret = name##_resize(self, m, n); \
|
||||||
|
if (ret && m > old_m) { \
|
||||||
|
memset(self->values + old_m, 0, (m - old_m) * self->n * sizeof(type)); \
|
||||||
|
} \
|
||||||
|
return ret; \
|
||||||
|
} \
|
||||||
|
\
|
||||||
|
static inline bool name##_resize_aligned_fill_zeros(name##_t *self, size_t m, size_t n, size_t alignment) { \
|
||||||
|
size_t old_m = self->m; \
|
||||||
|
bool ret = name##_resize_aligned(self, m, n, alignment); \
|
||||||
|
if (ret && m > old_m) { \
|
||||||
|
memset(self->values + old_m, 0, (m - old_m) * self->n * sizeof(type)); \
|
||||||
|
} \
|
||||||
|
return ret; \
|
||||||
|
} \
|
||||||
|
\
|
||||||
static inline name##_t *name##_new_copy(name##_t *self) { \
|
static inline name##_t *name##_new_copy(name##_t *self) { \
|
||||||
name##_t *cpy = name##_new(self->m, self->n); \
|
name##_t *cpy = name##_new(self->m, self->n); \
|
||||||
size_t num_values = self->m * self->n; \
|
size_t num_values = self->m * self->n; \
|
||||||
|
|||||||
@@ -65,6 +65,24 @@
|
|||||||
return vector; \
|
return vector; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
|
static inline bool name##_resize_fill_zeros(name *self, size_t n) { \
|
||||||
|
size_t old_n = self->n; \
|
||||||
|
bool ret = name##_resize(self, n); \
|
||||||
|
if (ret && n > old_n) { \
|
||||||
|
memset(self->a + old_n, 0, (n - old_n) * sizeof(type)); \
|
||||||
|
} \
|
||||||
|
return ret; \
|
||||||
|
} \
|
||||||
|
\
|
||||||
|
static inline bool name##_resize_aligned_fill_zeros(name *self, size_t n, size_t alignment) { \
|
||||||
|
size_t old_n = self->n; \
|
||||||
|
bool ret = name##_resize_aligned(self, n, alignment); \
|
||||||
|
if (ret && n > old_n) { \
|
||||||
|
memset(self->a + old_n, 0, (n - old_n) * sizeof(type)); \
|
||||||
|
} \
|
||||||
|
return ret; \
|
||||||
|
} \
|
||||||
|
\
|
||||||
static inline type name##_max(type *array, size_t n) { \
|
static inline type name##_max(type *array, size_t n) { \
|
||||||
if (n < 1) return (type) 0; \
|
if (n < 1) return (type) 0; \
|
||||||
type val = array[0]; \
|
type val = array[0]; \
|
||||||
|
|||||||
Reference in New Issue
Block a user