From 31f4244352b5e68eed770090419541d469f7f999 Mon Sep 17 00:00:00 2001 From: Jaron Kent-Dobias Date: Fri, 6 Jul 2018 14:51:29 -0400 Subject: split up some files --- lib/vector.h | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 lib/vector.h (limited to 'lib/vector.h') diff --git a/lib/vector.h b/lib/vector.h new file mode 100644 index 0000000..c7f459c --- /dev/null +++ b/lib/vector.h @@ -0,0 +1,72 @@ + +#pragma once + +#include +#include + +#include "types.h" + +template +struct vector_t { T *x; }; + +template +void init(vector_t *ptr) { + ptr->x = (T *)calloc(q, sizeof(T)); + + ptr->x[0] = (T)1; +} + +template +vector_t copy (vector_t v) { + vector_t v_copy; + + v_copy.x = (T *)calloc(q, sizeof(T)); + + for (q_t i = 0; i < q; i++) { + v_copy.x[i] = v.x[i]; + } + + return v_copy; +} + +template +void add (vector_t v1, vector_t v2) { + for (q_t i = 0; i < q; i++) { + v1.x[i] += v2.x[i]; + } +} + +template +void subtract (vector_t v1, vector_t v2) { + for (q_t i = 0; i < q; i++) { + v1.x[i] -= v2.x[i]; + } +} + +template +vector_t scalar_multiple(v_t a, vector_t v) { + vector_t multiple; + multiple.x = (T *)malloc(q * sizeof(T)); + for (q_t i = 0; i < q; i++) { + multiple.x[i] = a * v.x[i]; + } + + return multiple; +} + +template +T dot(vector_t v1, vector_t v2) { + T prod = 0; + + for (q_t i = 0; i < q; i++) { + prod += v1.x[i] * v2.x[i]; + } + + return prod; +} + +template +void free_spin (vector_t v) { + free(v.x); +} + -- cgit v1.2.3-70-g09d2 From 1810103bc9ac4c9a8d432d113f5ca6eae6560fb4 Mon Sep 17 00:00:00 2001 From: Jaron Kent-Dobias Date: Tue, 10 Jul 2018 11:17:03 -0400 Subject: minor reorganizing --- lib/orthogonal.h | 13 ------------- lib/vector.h | 13 +++++++++++++ 2 files changed, 13 insertions(+), 13 deletions(-) (limited to 'lib/vector.h') diff --git a/lib/orthogonal.h b/lib/orthogonal.h index 2d0e1a1..85f7a20 100644 --- a/lib/orthogonal.h +++ b/lib/orthogonal.h @@ -161,16 +161,3 @@ void generate_rotation (gsl_rng *r, orthogonal_t *ptr) { } } -template -void write_magnetization(vector_t M, FILE *outfile) { - fwrite(M.x, sizeof(double), q, outfile); -} - -template // save some space and don't write whole doubles -void write_magnetization(vector_t M, FILE *outfile) { - for (q_t i = 0; i < q; i++) { - float M_tmp = (float)M.x[i]; - fwrite(&M_tmp, sizeof(float), 1, outfile); - } -} - diff --git a/lib/vector.h b/lib/vector.h index c7f459c..62ce59e 100644 --- a/lib/vector.h +++ b/lib/vector.h @@ -70,3 +70,16 @@ void free_spin (vector_t v) { free(v.x); } +template +void write_magnetization(vector_t M, FILE *outfile) { + fwrite(M.x, sizeof(double), q, outfile); +} + +template // save some space and don't write whole doubles +void write_magnetization(vector_t M, FILE *outfile) { + for (q_t i = 0; i < q; i++) { + float M_tmp = (float)M.x[i]; + fwrite(&M_tmp, sizeof(float), 1, outfile); + } +} + -- cgit v1.2.3-70-g09d2