source: git/kernel/summator.cc @ 6bde67

spielwiese
Last change on this file since 6bde67 was 6bde67, checked in by Motsak Oleksandr <motsak@…>, 15 years ago
*motsak: new CSummator class for transparent sBucket/poly summation git-svn-id: file:///usr/local/Singular/svn/trunk@10836 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 3.2 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: summator.cc,v 1.1 2008-07-04 14:19:38 motsak Exp $
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
23#include <summator.h> // for CPolynomialSummator class
24#include <ring.h>
25#include <p_polys.h>
26#include <sbuckets.h>
27
28
29CPolynomialSummator::CPolynomialSummator(ring rBaseRing, bool bUsePolynomial):
30    m_basering(rBaseRing), m_bUsePolynomial(bUsePolynomial)
31{
32#ifdef RDEBUG
33  rTest(rBaseRing);
34#endif
35
36  if(bUsePolynomial)
37    m_temp.m_poly = NULL;
38  else
39  {
40    assume(!TEST_OPT_NOT_BUCKETS);
41    m_temp.m_bucket = sBucketCreate(rBaseRing);
42  }
43};
44
45/*
46// no sBucketInit defined :(((
47CPolynomialSummator::CPolynomialSummator(ring rBaseRing, poly pInitialSum, int iLength, bool bUsePolynomial):
48    m_basering(rBaseRing), m_bUsePolynomial(bUsePolynomial)
49{
50#ifdef PDEBUG
51  p_Test(pInitialSum, rBaseRing);
52#endif   
53
54  if(bUsePolynomial)
55  {
56    m_temp.m_poly = pInitialSum;
57  }
58  else
59  {
60    assume(!TEST_OPT_NOT_BUCKETS);
61    m_temp.m_bucket = sBucketInit(pInitialSum, iLength, rBaseRing);
62  }
63}
64*/
65
66CPolynomialSummator::~CPolynomialSummator()
67{
68  if(!m_bUsePolynomial)
69  {
70    sBucketDestroy(&m_temp.m_bucket);
71//    m_temp.m_bucket = NULL;
72  }
73  else
74    if(m_temp.m_poly!=NULL)
75    {
76#ifdef PDEBUG
77      p_Test(m_temp.m_poly, m_basering);
78#endif   
79     
80      p_Delete(&m_temp.m_poly, m_basering);
81//      m_temp.m_poly = NULL;
82    }
83}
84
85void CPolynomialSummator::AddAndDelete(poly pSummand, int iLength)
86{
87#ifdef PDEBUG
88  p_Test(pSummand, m_basering);
89#endif   
90 
91  if(m_bUsePolynomial)
92    m_temp.m_poly = p_Add_q(m_temp.m_poly, pSummand, m_basering);
93  else
94    sBucket_Add_p(m_temp.m_bucket, pSummand, iLength);
95}
96
97void CPolynomialSummator::AddAndDelete(poly pSummand)
98{
99#ifdef PDEBUG
100  p_Test(pSummand, m_basering);
101#endif   
102
103  if(m_bUsePolynomial)
104    m_temp.m_poly = p_Add_q(m_temp.m_poly, pSummand, m_basering);
105  else
106    sBucket_Add_p(m_temp.m_bucket, pSummand, 0);
107}
108
109poly CPolynomialSummator::AddUpAndClear()
110{
111  poly out = NULL;
112 
113  if(m_bUsePolynomial)
114  {
115    out = m_temp.m_poly;
116    m_temp.m_poly = NULL;
117  } else
118  {
119    int pLength;
120    sBucketClearAdd(m_temp.m_bucket, &out, &pLength);
121  }
122
123#ifdef PDEBUG
124  p_Test(out, m_basering);
125#endif   
126 
127  return out;
128}
129
130
131poly CPolynomialSummator::AddUpAndClear(int *piLength)
132{
133  poly out = NULL;
134 
135  if(m_bUsePolynomial)
136  {
137    out = m_temp.m_poly;
138    m_temp.m_poly = NULL;
139    *piLength = pLength(out);
140  } else
141  {
142    *piLength = 0;
143    sBucketClearAdd(m_temp.m_bucket, &out, piLength);
144  }
145
146#ifdef PDEBUG
147  p_Test(out, m_basering);
148  assume(pLength(out) == *piLength);
149#endif   
150 
151  return out;
152}
153
154
155
156void CPolynomialSummator::Add(poly pSummand, int iLength)
157{
158  AddAndDelete(p_Copy(pSummand, m_basering), iLength);
159};
160
161void CPolynomialSummator::Add(poly pSummand)
162{
163  AddAndDelete(p_Copy(pSummand, m_basering));
164};
165
166
Note: See TracBrowser for help on using the repository browser.