source: git/libpolys/polys/nc/summator.cc @ 975db18

spielwiese
Last change on this file since 975db18 was d6a97c3, checked in by Oleksandr Motsak <motsak@…>, 13 years ago
FIX: the rest of NC-related stuff can be compiled in now
  • Property mode set to 100644
File size: 3.6 KB
Line 
1/****************************************
2*  Computer Algebra System SINGULAR     *
3****************************************/
4/***************************************************************
5 *  File:    summator.cc
6 *  Purpose: simple Summator usecase implementation
7 *  Author:  motsak
8 *  Created:
9 *  Version: $Id$
10 *******************************************************************/
11
12
13#define MYTEST 0
14#define OUTPUT 0
15
16#if MYTEST
17#define OM_CHECK 4
18#define OM_TRACK 5
19#endif
20
21#include "config.h"
22#include <misc/auxiliary.h>
23
24#ifdef HAVE_PLURAL
25#include <misc/options.h>
26
27#include "nc/summator.h"
28#include "monomials/ring.h"
29#include "monomials/p_polys.h"
30
31#include "sbuckets.h"
32
33
34CPolynomialSummator::CPolynomialSummator(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 :(((
52CPolynomialSummator::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
71CPolynomialSummator::~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    if(out != NULL)
82      p_Delete(&out, m_basering);
83//    m_temp.m_bucket = NULL;
84  }
85  else
86    if(m_temp.m_poly!=NULL)
87    {
88#ifdef PDEBUG
89      p_Test(m_temp.m_poly, m_basering);
90#endif
91      p_Delete(&m_temp.m_poly, m_basering);
92//      m_temp.m_poly = NULL;
93    }
94}
95
96void CPolynomialSummator::AddAndDelete(poly pSummand, int iLength)
97{
98#ifdef PDEBUG
99  p_Test(pSummand, m_basering);
100#endif
101
102  if(m_bUsePolynomial)
103    m_temp.m_poly = p_Add_q(m_temp.m_poly, pSummand, m_basering);
104  else
105    sBucket_Add_p(m_temp.m_bucket, pSummand, iLength);
106}
107
108void CPolynomialSummator::AddAndDelete(poly pSummand)
109{
110#ifdef PDEBUG
111  p_Test(pSummand, m_basering);
112#endif
113
114  if(m_bUsePolynomial)
115    m_temp.m_poly = p_Add_q(m_temp.m_poly, pSummand, m_basering);
116  else
117    sBucket_Add_p(m_temp.m_bucket, pSummand, 0);
118}
119
120poly CPolynomialSummator::AddUpAndClear()
121{
122  poly out = NULL;
123
124  if(m_bUsePolynomial)
125  {
126    out = m_temp.m_poly;
127    m_temp.m_poly = NULL;
128  }
129  else
130  {
131    int pLength;
132    sBucketClearAdd(m_temp.m_bucket, &out, &pLength);
133  }
134
135#ifdef PDEBUG
136  p_Test(out, m_basering);
137#endif
138
139  return out;
140}
141
142
143poly CPolynomialSummator::AddUpAndClear(int *piLength)
144{
145  poly out = NULL;
146
147  if(m_bUsePolynomial)
148  {
149    out = m_temp.m_poly;
150    m_temp.m_poly = NULL;
151    *piLength = pLength(out);
152  }
153  else
154  {
155    *piLength = 0;
156    sBucketClearAdd(m_temp.m_bucket, &out, piLength);
157  }
158
159#ifdef PDEBUG
160  p_Test(out, m_basering);
161  assume(pLength(out) == *piLength);
162#endif
163
164  return out;
165}
166
167
168
169void CPolynomialSummator::Add(poly pSummand, int iLength)
170{
171  AddAndDelete(p_Copy(pSummand, m_basering), iLength);
172}
173
174void CPolynomialSummator::Add(poly pSummand)
175{
176  AddAndDelete(p_Copy(pSummand, m_basering));
177}
178
179
180
181CPolynomialSummator::CPolynomialSummator(const CPolynomialSummator& b): m_bUsePolynomial(b.m_bUsePolynomial), m_basering(b.m_basering)
182{
183//  try{
184    if(m_bUsePolynomial)
185      m_temp.m_poly = p_Copy( b.m_temp.m_poly, m_basering);
186    else
187      m_temp.m_bucket = sBucketCopy(b.m_temp.m_bucket);
188//  }
189//  catch(...)
190//  {
191//    assume(false);
192//  }
193}
194
195
196#endif
Note: See TracBrowser for help on using the repository browser.