[math] Generic dense matrix implementation using BLAS calls for matrix-matrix multiplication if available

This commit is contained in:
Al
2016-08-06 00:40:01 -04:00
parent d4a792f33c
commit 46cd725c13
19 changed files with 469 additions and 425 deletions

View File

@@ -132,6 +132,48 @@ bool file_write_double(FILE *file, double value) {
return file_write_uint64(file, ud.u);
}
typedef union {
uint32_t u;
float f;
} uint32_float_t;
bool file_read_float(FILE *file, float *value) {
uint32_float_t uf;
if (!file_read_uint32(file, &uf.u)) {
return false;
}
*value = uf.f;
return true;
}
bool file_read_float_array(FILE *file, float *value, size_t n) {
unsigned char *buf = malloc(n * sizeof(uint32_t));
if (buf == NULL) return false;
bool ret = false;
if (fread(buf, sizeof(uint32_t), n, file) == n) {
uint32_float_t uf;
for (size_t i = 0, byte_offset = 0; i < n; i++, byte_offset += sizeof(uint32_t)) {
unsigned char *ptr = buf + byte_offset;
uf.u = file_deserialize_uint32(ptr);
value[i] = uf.f;
}
ret = true;
}
free(buf);
return ret;
}
bool file_write_float(FILE *file, float value) {
uint32_float_t uf;
uf.f = value;
return file_write_uint32(file, uf.u);
}
inline uint32_t file_deserialize_uint32(unsigned char *buf) {
return (buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3];