source: git/kernel/summator.cc @ 690e21e

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