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