1 | /**************************************** |
---|
2 | * Computer Algebra System SINGULAR * |
---|
3 | ****************************************/ |
---|
4 | /*************************************************************** |
---|
5 | * File: summator.cc |
---|
6 | * Purpose: simple Summator usecase implementation |
---|
7 | * Author: motsak |
---|
8 | * Created: |
---|
9 | *******************************************************************/ |
---|
10 | |
---|
11 | |
---|
12 | #define MYTEST 0 |
---|
13 | #define OUTPUT 0 |
---|
14 | |
---|
15 | #if MYTEST |
---|
16 | #define OM_CHECK 4 |
---|
17 | #define OM_TRACK 5 |
---|
18 | #endif |
---|
19 | |
---|
20 | #include "summator.h" |
---|
21 | |
---|
22 | #ifdef HAVE_SUMMATOR |
---|
23 | |
---|
24 | |
---|
25 | |
---|
26 | |
---|
27 | #include <misc/auxiliary.h> |
---|
28 | #include <misc/options.h> |
---|
29 | |
---|
30 | #include <polys/monomials/ring.h> |
---|
31 | #include <polys/monomials/p_polys.h> |
---|
32 | #include <polys/sbuckets.h> |
---|
33 | |
---|
34 | |
---|
35 | |
---|
36 | CPolynomialSummator::CPolynomialSummator(const ring& rBaseRing, bool bUsePolynomial): |
---|
37 | m_basering(rBaseRing), m_bUsePolynomial(bUsePolynomial) |
---|
38 | { |
---|
39 | #ifdef RDEBUG |
---|
40 | rTest(rBaseRing); |
---|
41 | #endif |
---|
42 | |
---|
43 | if(bUsePolynomial) |
---|
44 | m_temp.m_poly = NULL; |
---|
45 | else |
---|
46 | { |
---|
47 | assume(!TEST_OPT_NOT_BUCKETS); |
---|
48 | m_temp.m_bucket = sBucketCreate(rBaseRing); |
---|
49 | } |
---|
50 | } |
---|
51 | |
---|
52 | /* |
---|
53 | // no sBucketInit defined :((( |
---|
54 | CPolynomialSummator::CPolynomialSummator(ring rBaseRing, poly pInitialSum, int iLength, bool bUsePolynomial): |
---|
55 | m_basering(rBaseRing), m_bUsePolynomial(bUsePolynomial) |
---|
56 | { |
---|
57 | #ifdef PDEBUG |
---|
58 | p_Test(pInitialSum, rBaseRing); |
---|
59 | #endif |
---|
60 | |
---|
61 | if(bUsePolynomial) |
---|
62 | { |
---|
63 | m_temp.m_poly = pInitialSum; |
---|
64 | } |
---|
65 | else |
---|
66 | { |
---|
67 | assume(!TEST_OPT_NOT_BUCKETS); |
---|
68 | m_temp.m_bucket = sBucketInit(pInitialSum, iLength, rBaseRing); |
---|
69 | } |
---|
70 | } |
---|
71 | */ |
---|
72 | |
---|
73 | CPolynomialSummator::~CPolynomialSummator() |
---|
74 | { |
---|
75 | if(!m_bUsePolynomial) |
---|
76 | { |
---|
77 | poly out; |
---|
78 | int pLength; |
---|
79 | |
---|
80 | sBucketClearAdd(m_temp.m_bucket, &out, &pLength); |
---|
81 | sBucketDestroy(&m_temp.m_bucket); |
---|
82 | |
---|
83 | assume(out == NULL); // otherwise wrong usage pattern! |
---|
84 | if(out != NULL) |
---|
85 | p_Delete(&out, m_basering); |
---|
86 | // m_temp.m_bucket = NULL; |
---|
87 | } |
---|
88 | else |
---|
89 | { |
---|
90 | assume(m_temp.m_poly == NULL); // otherwise wrong usage pattern! |
---|
91 | if(m_temp.m_poly!=NULL) |
---|
92 | { |
---|
93 | #ifdef PDEBUG |
---|
94 | p_Test(m_temp.m_poly, m_basering); |
---|
95 | #endif |
---|
96 | p_Delete(&m_temp.m_poly, m_basering); |
---|
97 | // m_temp.m_poly = NULL; |
---|
98 | } |
---|
99 | } |
---|
100 | } |
---|
101 | |
---|
102 | void CPolynomialSummator::AddAndDelete(poly pSummand, int iLength) |
---|
103 | { |
---|
104 | #ifdef PDEBUG |
---|
105 | p_Test(pSummand, m_basering); |
---|
106 | #endif |
---|
107 | |
---|
108 | if(m_bUsePolynomial) |
---|
109 | m_temp.m_poly = p_Add_q(m_temp.m_poly, pSummand, m_basering); |
---|
110 | else |
---|
111 | sBucket_Add_p(m_temp.m_bucket, pSummand, iLength); // sBucket_Merge_p??? |
---|
112 | } |
---|
113 | |
---|
114 | void CPolynomialSummator::AddAndDelete(poly pSummand) |
---|
115 | { |
---|
116 | #ifdef PDEBUG |
---|
117 | p_Test(pSummand, m_basering); |
---|
118 | #endif |
---|
119 | |
---|
120 | if(m_bUsePolynomial) |
---|
121 | m_temp.m_poly = p_Add_q(m_temp.m_poly, pSummand, m_basering); |
---|
122 | else |
---|
123 | sBucket_Add_p(m_temp.m_bucket, pSummand, 0); // sBucket_Merge_p??? |
---|
124 | } |
---|
125 | |
---|
126 | poly CPolynomialSummator::AddUpAndClear() |
---|
127 | { |
---|
128 | poly out = NULL; |
---|
129 | |
---|
130 | if(m_bUsePolynomial) |
---|
131 | { |
---|
132 | out = m_temp.m_poly; |
---|
133 | m_temp.m_poly = NULL; |
---|
134 | } |
---|
135 | else |
---|
136 | { |
---|
137 | int pLength; |
---|
138 | sBucketClearAdd(m_temp.m_bucket, &out, &pLength); |
---|
139 | } |
---|
140 | |
---|
141 | #ifdef PDEBUG |
---|
142 | p_Test(out, m_basering); |
---|
143 | #endif |
---|
144 | |
---|
145 | return out; |
---|
146 | } |
---|
147 | |
---|
148 | |
---|
149 | poly CPolynomialSummator::AddUpAndClear(int *piLength) |
---|
150 | { |
---|
151 | poly out = NULL; |
---|
152 | |
---|
153 | if(m_bUsePolynomial) |
---|
154 | { |
---|
155 | out = m_temp.m_poly; |
---|
156 | m_temp.m_poly = NULL; |
---|
157 | *piLength = pLength(out); |
---|
158 | } |
---|
159 | else |
---|
160 | { |
---|
161 | *piLength = 0; |
---|
162 | sBucketClearAdd(m_temp.m_bucket, &out, piLength); |
---|
163 | } |
---|
164 | |
---|
165 | #ifdef PDEBUG |
---|
166 | p_Test(out, m_basering); |
---|
167 | assume(pLength(out) == *piLength); |
---|
168 | #endif |
---|
169 | |
---|
170 | return out; |
---|
171 | } |
---|
172 | |
---|
173 | |
---|
174 | |
---|
175 | void CPolynomialSummator::Add(poly pSummand, int iLength) |
---|
176 | { |
---|
177 | AddAndDelete(p_Copy(pSummand, m_basering), iLength); |
---|
178 | } |
---|
179 | |
---|
180 | void CPolynomialSummator::Add(poly pSummand) |
---|
181 | { |
---|
182 | AddAndDelete(p_Copy(pSummand, m_basering)); |
---|
183 | } |
---|
184 | |
---|
185 | |
---|
186 | |
---|
187 | CPolynomialSummator::CPolynomialSummator(const CPolynomialSummator& b): |
---|
188 | m_basering(b.m_basering), m_bUsePolynomial(b.m_bUsePolynomial) |
---|
189 | { |
---|
190 | // try{ |
---|
191 | if(m_bUsePolynomial) |
---|
192 | m_temp.m_poly = p_Copy( b.m_temp.m_poly, m_basering); |
---|
193 | else |
---|
194 | m_temp.m_bucket = sBucketCopy(b.m_temp.m_bucket); |
---|
195 | // } |
---|
196 | // catch(...) |
---|
197 | // { |
---|
198 | // assume(false); |
---|
199 | // } |
---|
200 | } |
---|
201 | |
---|
202 | |
---|
203 | #endif // ifdef HAVE_SUMMATOR |
---|