source: git/ntl/src/vec_lzz_pE.c @ 6ce030f

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