cheshirekow  v0.1.0
Quotient.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012 Josh Bialkowski (jbialk@mit.edu)
3  *
4  * This file is part of mpblocks.
5  *
6  * mpblocks is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * mpblocks is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with mpblocks. If not, see <http://www.gnu.org/licenses/>.
18  */
27 #ifndef MPBLOCKS_CUDA_POLYNOMIAL_QUOTIENT_H_
28 #define MPBLOCKS_CUDA_POLYNOMIAL_QUOTIENT_H_
29 
30 namespace mpblocks {
31 namespace cuda {
32 namespace polynomial {
33 
34 
35 
37 template <typename Scalar,
38  class ExpNum, class SpecNum,
39  class ExpDen, class SpecDen >
41 {
42  const ExpNum& Num;
43  const ExpDen& Den;
44 
46  QuotientSurrogate( const ExpNum& Num,
47  const ExpDen& Den )
48  :
49  Num(Num),
50  Den(Den)
51  {}
52 };
53 
54 
55 
57 template <typename Scalar,
58  class ExpNum, class SpecNum,
59  class ExpDen, class SpecDen >
60 struct Quotient
61 {
62  enum
63  {
69  size_denominator = max_coeff_denominator + 1
70  };
71 
74 
77 
78  template< int size, int min >
79  struct QuotientWork
80  {
84  ExpNum const& N, ExpDen const& D )
85  {
86  // degree of the new term
87  enum{ n = size - size_denominator };
88 
89  // coefficient of the new term
90  Scalar t = get<size-1>(r) /
91  get<max_coeff_denominator>(D);
92 
93  // append the new term to the quotient
94  set<n>(q) = t;
95 
96  // update the remainder
97  r = N - q*D;
98  }
99  };
100 
101  template< int size, int min >
103  {
107  ExpNum const& N, ExpDen const& D )
108  {
109  QuotientWork<size,min>::work( q,r,N,D );
110 
111  // next step
113  }
114  };
115 
116  template< int min >
117  struct QuotientStep<min,min>
118  {
122  ExpNum const& N, ExpDen const& D )
123  {}
124  };
125 
127  void construct( ExpNum const& N, ExpDen const& D )
128  {
129  q.fill(0);
130  r = N;
132  }
133 
136 
138  Quotient( ExpNum const& N, ExpDen const& D )
139  {
140  construct(N,D);
141  }
142 
144  Quotient( const QuotientSurrogate<Scalar,ExpNum,SpecNum
145  ,ExpDen,SpecDen>& surrogate )
146  {
147  construct(surrogate.Num,surrogate.Den);
148  }
149 
151  void operator=( const QuotientSurrogate<Scalar,ExpNum,SpecNum
152  ,ExpDen,SpecDen>& surrogate )
153  {
154  construct(surrogate.Num,surrogate.Den);
155  }
156 };
157 
158 
159 
160 
161 template <typename Scalar,
162  class Exp1, class Spec1,
163  class Exp2, class Spec2 >
166  RValue<Scalar,Exp1,Spec1> const& A,
167  RValue<Scalar,Exp2,Spec2> const& B )
168 {
170  static_cast<Exp1 const&>(A),
171  static_cast<Exp2 const&>(B));
172 }
173 
174 
175 
176 
177 } // namespace polynomial
178 } // namespace cuda
179 } // nampespace mpblocks
180 
181 
182 
183 
184 
185 #endif // QUOTIENT_H_
A sparse, statically sized polynomial.
Definition: Polynomial.h:266
__host__ __device__ Quotient(const QuotientSurrogate< Scalar, ExpNum, SpecNum, ExpDen, SpecDen > &surrogate)
Definition: Quotient.h:144
Polynomial< Scalar, SpecRem > r
Definition: Quotient.h:76
__host__ __device__ void operator=(const QuotientSurrogate< Scalar, ExpNum, SpecNum, ExpDen, SpecDen > &surrogate)
Definition: Quotient.h:151
__host__ __device__ Quotient()
Definition: Quotient.h:135
__host__ static __device__ void step(Polynomial< Scalar, SpecQuot > &q, Polynomial< Scalar, SpecRem > &r, ExpNum const &N, ExpDen const &D)
Definition: Quotient.h:105
expression template for polynomial long division
Definition: Quotient.h:60
expression template for rvalues
Definition: RValue.h:40
__host__ static __device__ void step(Polynomial< Scalar, SpecQuot > &q, Polynomial< Scalar, SpecRem > &r, ExpNum const &N, ExpDen const &D)
Definition: Quotient.h:120
__host__ __device__ Quotient(ExpNum const &N, ExpDen const &D)
Definition: Quotient.h:138
__host__ __device__ void construct(ExpNum const &N, ExpDen const &D)
Definition: Quotient.h:127
intlist::range< 0, max_coeff_remainder >::result SpecRem
Definition: Quotient.h:73
__host__ static __device__ void work(Polynomial< Scalar, SpecQuot > &q, Polynomial< Scalar, SpecRem > &r, ExpNum const &N, ExpDen const &D)
Definition: Quotient.h:82
__host__ __device__ QuotientSurrogate(const ExpNum &Num, const ExpDen &Den)
Definition: Quotient.h:46
surrogate for initialzing with / operator
Definition: Quotient.h:40
#define __device__
Definition: fakecuda.h:34
retrieve the max element of the list (linear without short circut so it works with non-sorted arrays ...
Definition: IntList.h:415
Polynomial< Scalar, SpecQuot > q
Definition: Quotient.h:75
#define __host__
Definition: fakecuda.h:37
__host__ __device__ QuotientSurrogate< Scalar, Exp1, Spec1, Exp2, Spec2 > operator/(RValue< Scalar, Exp1, Spec1 > const &A, RValue< Scalar, Exp2, Spec2 > const &B)
Definition: Quotient.h:165
intlist::range< 0, max_coeff_quotient >::result SpecQuot
Definition: Quotient.h:72