diff options
author | Alberto Ruiz <aruiz@um.es> | 2015-06-08 10:09:39 +0200 |
---|---|---|
committer | Alberto Ruiz <aruiz@um.es> | 2015-06-08 10:09:39 +0200 |
commit | e2cb1eff0a954a83e0661ea1e7f70a47ed54e893 (patch) | |
tree | f1b214ba3cb8f29f1b17156e7bb5ef72d3f53d39 /packages/base/src/Internal/C/vector-aux.c | |
parent | ccb56d051ce92879a54fcd218bfeac48523b0de0 (diff) |
modular C matrix product
Diffstat (limited to 'packages/base/src/Internal/C/vector-aux.c')
-rw-r--r-- | packages/base/src/Internal/C/vector-aux.c | 32 |
1 files changed, 24 insertions, 8 deletions
diff --git a/packages/base/src/Internal/C/vector-aux.c b/packages/base/src/Internal/C/vector-aux.c index 70e46bc..580aa1c 100644 --- a/packages/base/src/Internal/C/vector-aux.c +++ b/packages/base/src/Internal/C/vector-aux.c | |||
@@ -58,20 +58,28 @@ int sumR(KDVEC(x),DVEC(r)) { | |||
58 | OK | 58 | OK |
59 | } | 59 | } |
60 | 60 | ||
61 | int sumI(KIVEC(x),IVEC(r)) { | 61 | int sumI(int m, KIVEC(x),IVEC(r)) { |
62 | REQUIRES(rn==1,BAD_SIZE); | 62 | REQUIRES(rn==1,BAD_SIZE); |
63 | int i; | 63 | int i; |
64 | int res = 0; | 64 | int res = 0; |
65 | for (i = 0; i < xn; i++) res += xp[i]; | 65 | if (m==1) { |
66 | for (i = 0; i < xn; i++) res += xp[i]; | ||
67 | } else { | ||
68 | for (i = 0; i < xn; i++) res = (res + xp[i]) % m; | ||
69 | } | ||
66 | rp[0] = res; | 70 | rp[0] = res; |
67 | OK | 71 | OK |
68 | } | 72 | } |
69 | 73 | ||
70 | int sumL(KLVEC(x),LVEC(r)) { | 74 | int sumL(int32_t m, KLVEC(x),LVEC(r)) { |
71 | REQUIRES(rn==1,BAD_SIZE); | 75 | REQUIRES(rn==1,BAD_SIZE); |
72 | int i; | 76 | int i; |
73 | int res = 0; | 77 | int res = 0; |
74 | for (i = 0; i < xn; i++) res += xp[i]; | 78 | if (m==1) { |
79 | for (i = 0; i < xn; i++) res += xp[i]; | ||
80 | } else { | ||
81 | for (i = 0; i < xn; i++) res = (res + xp[i]) % m; | ||
82 | } | ||
75 | rp[0] = res; | 83 | rp[0] = res; |
76 | OK | 84 | OK |
77 | } | 85 | } |
@@ -127,20 +135,28 @@ int prodR(KDVEC(x),DVEC(r)) { | |||
127 | OK | 135 | OK |
128 | } | 136 | } |
129 | 137 | ||
130 | int prodI(KIVEC(x),IVEC(r)) { | 138 | int prodI(int m, KIVEC(x),IVEC(r)) { |
131 | REQUIRES(rn==1,BAD_SIZE); | 139 | REQUIRES(rn==1,BAD_SIZE); |
132 | int i; | 140 | int i; |
133 | int res = 1; | 141 | int res = 1; |
134 | for (i = 0; i < xn; i++) res *= xp[i]; | 142 | if (m==1) { |
143 | for (i = 0; i < xn; i++) res *= xp[i]; | ||
144 | } else { | ||
145 | for (i = 0; i < xn; i++) res = (res * xp[i]) % m; | ||
146 | } | ||
135 | rp[0] = res; | 147 | rp[0] = res; |
136 | OK | 148 | OK |
137 | } | 149 | } |
138 | 150 | ||
139 | int prodL(KLVEC(x),LVEC(r)) { | 151 | int prodL(int32_t m, KLVEC(x),LVEC(r)) { |
140 | REQUIRES(rn==1,BAD_SIZE); | 152 | REQUIRES(rn==1,BAD_SIZE); |
141 | int i; | 153 | int i; |
142 | int res = 1; | 154 | int res = 1; |
143 | for (i = 0; i < xn; i++) res *= xp[i]; | 155 | if (m==1) { |
156 | for (i = 0; i < xn; i++) res *= xp[i]; | ||
157 | } else { | ||
158 | for (i = 0; i < xn; i++) res = (res * xp[i]) % m; | ||
159 | } | ||
144 | rp[0] = res; | 160 | rp[0] = res; |
145 | OK | 161 | OK |
146 | } | 162 | } |