source: git/ntl/src/vec_GF2E.c @ eb5966

fieker-DuValspielwiese
Last change on this file since eb5966 was eb5966, checked in by Hans Schönemann <hannes@…>, 20 years ago
*hannes: 5.3.2 git-svn-id: file:///usr/local/Singular/svn/trunk@7473 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 3.1 KB
Line 
1
2
3#include <NTL/vec_GF2E.h>
4
5#include <NTL/new.h>
6
7NTL_START_IMPL
8
9
10
11
12
13
14void BlockConstruct(GF2E* x, long n)
15{
16   if (n <= 0) return; 
17
18   if (!GF2EInfo)
19      Error("GF2E constructor called while modulus undefined");
20
21   long d = GF2E::WordLength();
22
23   long m, j;
24 
25   long i = 0;
26 
27   while (i < n) {
28      m = WV_BlockConstructAlloc(x[i]._GF2E__rep.xrep, d, n-i);
29      for (j = 1; j < m; j++)
30         WV_BlockConstructSet(x[i]._GF2E__rep.xrep, x[i+j]._GF2E__rep.xrep, j);
31      i += m;
32   }
33}
34
35
36void BlockDestroy(GF2E* x, long n)
37{
38   if (n <= 0) return;
39 
40   long i = 0;
41   long m;
42 
43   while (i < n) {
44      m = WV_BlockDestroy(x[i]._GF2E__rep.xrep);
45      i += m;
46   }
47}
48
49
50
51NTL_vector_impl_plain(GF2E,vec_GF2E)
52
53NTL_io_vector_impl(GF2E,vec_GF2E)
54
55NTL_eq_vector_impl(GF2E,vec_GF2E)
56
57
58void InnerProduct(GF2E& x, const vec_GF2E& a, const vec_GF2E& b)
59{
60   long n = min(a.length(), b.length());
61   long i;
62   GF2X accum, t;
63
64   clear(accum);
65   for (i = 0; i < n; i++) {
66      mul(t, rep(a[i]), rep(b[i]));
67      add(accum, accum, t);
68   }
69
70   conv(x, accum);
71}
72
73void InnerProduct(GF2E& x, const vec_GF2E& a, const vec_GF2E& b,
74                  long offset)
75{
76   if (offset < 0) Error("InnerProduct: negative offset");
77   if (NTL_OVERFLOW(offset, 1, 0)) Error("InnerProduct: offset too big");
78
79   long n = min(a.length(), b.length()+offset);
80   long i;
81   GF2X accum, t;
82
83   clear(accum);
84   for (i = offset; i < n; i++) {
85      mul(t, rep(a[i]), rep(b[i-offset]));
86      add(accum, accum, t);
87   }
88
89   conv(x, accum);
90}
91
92void mul(vec_GF2E& x, const vec_GF2E& a, const GF2E& b_in)
93{
94   GF2E b = b_in;
95   long n = a.length();
96   x.SetLength(n);
97   long i;
98   for (i = 0; i < n; i++)
99      mul(x[i], a[i], b);
100}
101
102void mul(vec_GF2E& x, const vec_GF2E& a, GF2 b)
103{
104   x = a;
105   if (b == 0)
106      clear(x);
107}
108
109
110void add(vec_GF2E& x, const vec_GF2E& a, const vec_GF2E& b)
111{
112   long n = a.length();
113   if (b.length() != n) Error("vector add: dimension mismatch");
114
115   x.SetLength(n);
116   long i;
117   for (i = 0; i < n; i++)
118      add(x[i], a[i], b[i]);
119}
120
121
122void clear(vec_GF2E& x)
123{
124   long n = x.length();
125   long i;
126   for (i = 0; i < n; i++)
127      clear(x[i]);
128}
129
130
131
132long IsZero(const vec_GF2E& a)
133{
134   long n = a.length();
135   long i;
136
137   for (i = 0; i < n; i++)
138      if (!IsZero(a[i]))
139         return 0;
140
141   return 1;
142}
143
144vec_GF2E operator+(const vec_GF2E& a, const vec_GF2E& b)
145{
146   vec_GF2E res;
147   add(res, a, b);
148   NTL_OPT_RETURN(vec_GF2E, res);
149}
150
151vec_GF2E operator-(const vec_GF2E& a, const vec_GF2E& b)
152{
153   vec_GF2E res;
154   sub(res, a, b);
155   NTL_OPT_RETURN(vec_GF2E, res);
156}
157
158
159vec_GF2E operator-(const vec_GF2E& a)
160{
161   vec_GF2E res;
162   negate(res, a);
163   NTL_OPT_RETURN(vec_GF2E, res);
164}
165
166
167GF2E operator*(const vec_GF2E& a, const vec_GF2E& b)
168{
169   GF2E res;
170   InnerProduct(res, a, b);
171   return res;
172}
173
174
175void VectorCopy(vec_GF2E& x, const vec_GF2E& a, long n)
176{
177   if (n < 0) Error("VectorCopy: negative length");
178   if (NTL_OVERFLOW(n, 1, 0)) Error("overflow in VectorCopy");
179
180   long m = min(n, a.length());
181
182   x.SetLength(n);
183
184   long i;
185
186   for (i = 0; i < m; i++)
187      x[i] = a[i];
188
189   for (i = m; i < n; i++)
190      clear(x[i]);
191}
192
193
194
195NTL_END_IMPL
Note: See TracBrowser for help on using the repository browser.