source: git/libpolys/polys/nc/summator.cc @ 30664c

spielwiese
Last change on this file since 30664c was 30664c, checked in by Oleksandr Motsak <motsak@…>, 11 years ago
Warning elimination + cosmetics
  • Property mode set to 100644
File size: 3.9 KB
RevLine 
[6bde67]1/****************************************
2*  Computer Algebra System SINGULAR     *
3****************************************/
4/***************************************************************
5 *  File:    summator.cc
6 *  Purpose: simple Summator usecase implementation
7 *  Author:  motsak
[9d0c2b]8 *  Created:
[6bde67]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
[8179468]20#include "summator.h"
21
22#ifdef HAVE_SUMMATOR
23
[d6a97c3]24#include "config.h"
25#include <misc/auxiliary.h>
26#include <misc/options.h>
27
[8179468]28#include <polys/monomials/ring.h>
29#include <polys/monomials/p_polys.h>
30#include <polys/sbuckets.h>
[d6a97c3]31
[6bde67]32
33
[8179468]34CPolynomialSummator::CPolynomialSummator(const ring& rBaseRing, bool bUsePolynomial):
[30664c]35    m_bUsePolynomial(bUsePolynomial), m_basering(rBaseRing)
[6bde67]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  }
[9d0c2b]48}
[6bde67]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);
[9d0c2b]57#endif
[6bde67]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  {
[f2a4f3f]75    poly out;
76    int pLength;
[a795c77]77
[f2a4f3f]78    sBucketClearAdd(m_temp.m_bucket, &out, &pLength);
[6bde67]79    sBucketDestroy(&m_temp.m_bucket);
[f2a4f3f]80
[8179468]81    assume(out == NULL); // otherwise wrong usage pattern!
[f2a4f3f]82    if(out != NULL)
[a795c77]83      p_Delete(&out, m_basering);
[6bde67]84//    m_temp.m_bucket = NULL;
85  }
86  else
[8179468]87  {
88    assume(m_temp.m_poly == NULL); // otherwise wrong usage pattern!   
[6bde67]89    if(m_temp.m_poly!=NULL)
90    {
91#ifdef PDEBUG
92      p_Test(m_temp.m_poly, m_basering);
[9d0c2b]93#endif
[6bde67]94      p_Delete(&m_temp.m_poly, m_basering);
95//      m_temp.m_poly = NULL;
96    }
[8179468]97  }
[6bde67]98}
99
100void CPolynomialSummator::AddAndDelete(poly pSummand, int iLength)
101{
102#ifdef PDEBUG
103  p_Test(pSummand, m_basering);
[9d0c2b]104#endif
105
[6bde67]106  if(m_bUsePolynomial)
107    m_temp.m_poly = p_Add_q(m_temp.m_poly, pSummand, m_basering);
108  else
[8179468]109    sBucket_Add_p(m_temp.m_bucket, pSummand, iLength); // sBucket_Merge_p???
[6bde67]110}
111
112void CPolynomialSummator::AddAndDelete(poly pSummand)
113{
114#ifdef PDEBUG
115  p_Test(pSummand, m_basering);
[9d0c2b]116#endif
[6bde67]117
118  if(m_bUsePolynomial)
119    m_temp.m_poly = p_Add_q(m_temp.m_poly, pSummand, m_basering);
120  else
[8179468]121    sBucket_Add_p(m_temp.m_bucket, pSummand, 0); // sBucket_Merge_p???
[6bde67]122}
123
124poly CPolynomialSummator::AddUpAndClear()
125{
126  poly out = NULL;
[9d0c2b]127
[6bde67]128  if(m_bUsePolynomial)
129  {
130    out = m_temp.m_poly;
131    m_temp.m_poly = NULL;
[9d0c2b]132  }
133  else
[6bde67]134  {
135    int pLength;
136    sBucketClearAdd(m_temp.m_bucket, &out, &pLength);
137  }
138
139#ifdef PDEBUG
140  p_Test(out, m_basering);
[9d0c2b]141#endif
142
[6bde67]143  return out;
144}
145
146
147poly CPolynomialSummator::AddUpAndClear(int *piLength)
148{
149  poly out = NULL;
[9d0c2b]150
[6bde67]151  if(m_bUsePolynomial)
152  {
153    out = m_temp.m_poly;
154    m_temp.m_poly = NULL;
155    *piLength = pLength(out);
[9d0c2b]156  }
157  else
[6bde67]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);
[9d0c2b]166#endif
167
[6bde67]168  return out;
169}
170
171
172
173void CPolynomialSummator::Add(poly pSummand, int iLength)
174{
175  AddAndDelete(p_Copy(pSummand, m_basering), iLength);
[9d0c2b]176}
[6bde67]177
178void CPolynomialSummator::Add(poly pSummand)
179{
180  AddAndDelete(p_Copy(pSummand, m_basering));
[9d0c2b]181}
[6bde67]182
[a795c77]183
184
185CPolynomialSummator::CPolynomialSummator(const CPolynomialSummator& b): m_bUsePolynomial(b.m_bUsePolynomial), m_basering(b.m_basering)
186{
[8528c1]187//  try{
[a795c77]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);
[8528c1]192//  }
193//  catch(...)
194//  {
195//    assume(false);
196//  }
[a795c77]197}
198
199
[8179468]200#endif // ifdef HAVE_SUMMATOR
Note: See TracBrowser for help on using the repository browser.