source: git/kernel/summator.cc @ 61d32c

spielwiese
Last change on this file since 61d32c was f2a4f3f, checked in by Motsak Oleksandr <motsak@…>, 16 years ago
*motsak: optimizations... + components for global multiplicator git-svn-id: file:///usr/local/Singular/svn/trunk@10911 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 3.3 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.4 2008-07-25 16:06:18 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#ifdef HAVE_PLURAL
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    poly out;
71    int pLength;
72   
73    sBucketClearAdd(m_temp.m_bucket, &out, &pLength);
74    sBucketDestroy(&m_temp.m_bucket);
75
76    if(out != NULL)
77      p_Delete(&out, m_basering);   
78//    m_temp.m_bucket = NULL;
79  }
80  else
81    if(m_temp.m_poly!=NULL)
82    {
83#ifdef PDEBUG
84      p_Test(m_temp.m_poly, m_basering);
85#endif
86      p_Delete(&m_temp.m_poly, m_basering);
87//      m_temp.m_poly = NULL;
88    }
89}
90
91void CPolynomialSummator::AddAndDelete(poly pSummand, int iLength)
92{
93#ifdef PDEBUG
94  p_Test(pSummand, m_basering);
95#endif
96
97  if(m_bUsePolynomial)
98    m_temp.m_poly = p_Add_q(m_temp.m_poly, pSummand, m_basering);
99  else
100    sBucket_Add_p(m_temp.m_bucket, pSummand, iLength);
101}
102
103void CPolynomialSummator::AddAndDelete(poly pSummand)
104{
105#ifdef PDEBUG
106  p_Test(pSummand, m_basering);
107#endif
108
109  if(m_bUsePolynomial)
110    m_temp.m_poly = p_Add_q(m_temp.m_poly, pSummand, m_basering);
111  else
112    sBucket_Add_p(m_temp.m_bucket, pSummand, 0);
113}
114
115poly CPolynomialSummator::AddUpAndClear()
116{
117  poly out = NULL;
118
119  if(m_bUsePolynomial)
120  {
121    out = m_temp.m_poly;
122    m_temp.m_poly = NULL;
123  }
124  else
125  {
126    int pLength;
127    sBucketClearAdd(m_temp.m_bucket, &out, &pLength);
128  }
129
130#ifdef PDEBUG
131  p_Test(out, m_basering);
132#endif
133
134  return out;
135}
136
137
138poly CPolynomialSummator::AddUpAndClear(int *piLength)
139{
140  poly out = NULL;
141
142  if(m_bUsePolynomial)
143  {
144    out = m_temp.m_poly;
145    m_temp.m_poly = NULL;
146    *piLength = pLength(out);
147  }
148  else
149  {
150    *piLength = 0;
151    sBucketClearAdd(m_temp.m_bucket, &out, piLength);
152  }
153
154#ifdef PDEBUG
155  p_Test(out, m_basering);
156  assume(pLength(out) == *piLength);
157#endif
158
159  return out;
160}
161
162
163
164void CPolynomialSummator::Add(poly pSummand, int iLength)
165{
166  AddAndDelete(p_Copy(pSummand, m_basering), iLength);
167}
168
169void CPolynomialSummator::Add(poly pSummand)
170{
171  AddAndDelete(p_Copy(pSummand, m_basering));
172}
173
174#endif
Note: See TracBrowser for help on using the repository browser.