source: git/libpolys/polys/nc/summator.cc @ 6ce030f

spielwiese
Last change on this file since 6ce030f was 6ce030f, checked in by Oleksandr Motsak <motsak@…>, 11 years ago
removal of the $Id$ svn tag from everywhere NOTE: the git SHA1 may be used instead (only on special places) NOTE: the libraries Singular/LIB/*.lib still contain the marker due to our current use of svn
  • 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 *******************************************************************/
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 "config.h"
21#include <misc/auxiliary.h>
22
23#ifdef HAVE_PLURAL
24#include <misc/options.h>
25
26#include "nc/summator.h"
27#include "monomials/ring.h"
28#include "monomials/p_polys.h"
29
30#include "sbuckets.h"
31
32
33CPolynomialSummator::CPolynomialSummator(ring rBaseRing, bool bUsePolynomial):
34    m_basering(rBaseRing), m_bUsePolynomial(bUsePolynomial)
35{
36#ifdef RDEBUG
37  rTest(rBaseRing);
38#endif
39
40  if(bUsePolynomial)
41    m_temp.m_poly = NULL;
42  else
43  {
44    assume(!TEST_OPT_NOT_BUCKETS);
45    m_temp.m_bucket = sBucketCreate(rBaseRing);
46  }
47}
48
49/*
50// no sBucketInit defined :(((
51CPolynomialSummator::CPolynomialSummator(ring rBaseRing, poly pInitialSum, int iLength, bool bUsePolynomial):
52    m_basering(rBaseRing), m_bUsePolynomial(bUsePolynomial)
53{
54#ifdef PDEBUG
55  p_Test(pInitialSum, rBaseRing);
56#endif
57
58  if(bUsePolynomial)
59  {
60    m_temp.m_poly = pInitialSum;
61  }
62  else
63  {
64    assume(!TEST_OPT_NOT_BUCKETS);
65    m_temp.m_bucket = sBucketInit(pInitialSum, iLength, rBaseRing);
66  }
67}
68*/
69
70CPolynomialSummator::~CPolynomialSummator()
71{
72  if(!m_bUsePolynomial)
73  {
74    poly out;
75    int pLength;
76
77    sBucketClearAdd(m_temp.m_bucket, &out, &pLength);
78    sBucketDestroy(&m_temp.m_bucket);
79
80    if(out != NULL)
81      p_Delete(&out, m_basering);
82//    m_temp.m_bucket = NULL;
83  }
84  else
85    if(m_temp.m_poly!=NULL)
86    {
87#ifdef PDEBUG
88      p_Test(m_temp.m_poly, m_basering);
89#endif
90      p_Delete(&m_temp.m_poly, m_basering);
91//      m_temp.m_poly = NULL;
92    }
93}
94
95void CPolynomialSummator::AddAndDelete(poly pSummand, int iLength)
96{
97#ifdef PDEBUG
98  p_Test(pSummand, m_basering);
99#endif
100
101  if(m_bUsePolynomial)
102    m_temp.m_poly = p_Add_q(m_temp.m_poly, pSummand, m_basering);
103  else
104    sBucket_Add_p(m_temp.m_bucket, pSummand, iLength);
105}
106
107void CPolynomialSummator::AddAndDelete(poly pSummand)
108{
109#ifdef PDEBUG
110  p_Test(pSummand, m_basering);
111#endif
112
113  if(m_bUsePolynomial)
114    m_temp.m_poly = p_Add_q(m_temp.m_poly, pSummand, m_basering);
115  else
116    sBucket_Add_p(m_temp.m_bucket, pSummand, 0);
117}
118
119poly CPolynomialSummator::AddUpAndClear()
120{
121  poly out = NULL;
122
123  if(m_bUsePolynomial)
124  {
125    out = m_temp.m_poly;
126    m_temp.m_poly = NULL;
127  }
128  else
129  {
130    int pLength;
131    sBucketClearAdd(m_temp.m_bucket, &out, &pLength);
132  }
133
134#ifdef PDEBUG
135  p_Test(out, m_basering);
136#endif
137
138  return out;
139}
140
141
142poly CPolynomialSummator::AddUpAndClear(int *piLength)
143{
144  poly out = NULL;
145
146  if(m_bUsePolynomial)
147  {
148    out = m_temp.m_poly;
149    m_temp.m_poly = NULL;
150    *piLength = pLength(out);
151  }
152  else
153  {
154    *piLength = 0;
155    sBucketClearAdd(m_temp.m_bucket, &out, piLength);
156  }
157
158#ifdef PDEBUG
159  p_Test(out, m_basering);
160  assume(pLength(out) == *piLength);
161#endif
162
163  return out;
164}
165
166
167
168void CPolynomialSummator::Add(poly pSummand, int iLength)
169{
170  AddAndDelete(p_Copy(pSummand, m_basering), iLength);
171}
172
173void CPolynomialSummator::Add(poly pSummand)
174{
175  AddAndDelete(p_Copy(pSummand, m_basering));
176}
177
178
179
180CPolynomialSummator::CPolynomialSummator(const CPolynomialSummator& b): m_bUsePolynomial(b.m_bUsePolynomial), m_basering(b.m_basering)
181{
182//  try{
183    if(m_bUsePolynomial)
184      m_temp.m_poly = p_Copy( b.m_temp.m_poly, m_basering);
185    else
186      m_temp.m_bucket = sBucketCopy(b.m_temp.m_bucket);
187//  }
188//  catch(...)
189//  {
190//    assume(false);
191//  }
192}
193
194
195#endif
Note: See TracBrowser for help on using the repository browser.