diff options
author | Jaron Kent-Dobias <jaron@kent-dobias.com> | 2018-07-19 18:22:15 -0400 |
---|---|---|
committer | Jaron Kent-Dobias <jaron@kent-dobias.com> | 2018-07-19 18:22:15 -0400 |
commit | 72301b3d5c3a91ff2e7fc6eedcad7bce8e647efa (patch) | |
tree | 0927a2de8f92970b1499250e6cae4335a989b70f /lib/vector.h | |
parent | d63eaab6d7c414d6a66e00e061919220d5b039e0 (diff) | |
download | c++-72301b3d5c3a91ff2e7fc6eedcad7bce8e647efa.tar.gz c++-72301b3d5c3a91ff2e7fc6eedcad7bce8e647efa.tar.bz2 c++-72301b3d5c3a91ff2e7fc6eedcad7bce8e647efa.zip |
efficient computation of the smallest fourier mode by doing a magnetization-style update anytime a bond with the external field changes
Diffstat (limited to 'lib/vector.h')
-rw-r--r-- | lib/vector.h | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/lib/vector.h b/lib/vector.h index 2099d28..a1084e2 100644 --- a/lib/vector.h +++ b/lib/vector.h @@ -37,6 +37,20 @@ void add (vector_t <q, T> *v1, vector_t <q, T> v2) { } template <q_t q, class T> +void scalar_add (vector_t <q, T> *v1, T a, vector_t <q, T> v2) { + for (q_t i = 0; i < q; i++) { + v1->x[i] += a * v2.x[i]; + } +} + +template <q_t q, class T> +void scalar_subtract (vector_t <q, T> *v1, T a, vector_t <q, T> v2) { + for (q_t i = 0; i < q; i++) { + v1->x[i] -= a * v2.x[i]; + } +} + +template <q_t q, class T> void subtract (vector_t <q, T> *v1, vector_t <q, T> v2) { for (q_t i = 0; i < q; i++) { v1->x[i] -= v2.x[i]; @@ -44,6 +58,16 @@ void subtract (vector_t <q, T> *v1, vector_t <q, T> v2) { } template <q_t q, class T> +T norm_squared (vector_t <q, T> v) { + T tmp = 0; + for (q_t i = 0; i < q; i++) { + tmp += v.x[i] * v.x[i]; + } + + return tmp; +} + +template <q_t q, class T> vector_t <q, T> scalar_multiple(v_t a, vector_t <q, T> v) { vector_t <q, T> multiple; multiple.x = (T *)malloc(q * sizeof(T)); |