8#ifndef EXTEMP_SPARSE_double_H
9#define EXTEMP_SPARSE_double_H
10#include "../sgrid/sparseGrid.h"
11#include "../indices/index.h"
19 inline operator const A&()
const {
20 return *
static_cast<const A*
> ( this );
31class ExpressionDescription {
33 ExpressionDescription(
bool needsIndex_) : needsIndex(needsIndex_) {};
34 ExpressionDescription(
const ExpressionDescription& a,
const ExpressionDescription& b) {
35 needsIndex = a.needsIndex || b.needsIndex; };
36 bool isIndexNeeded() {
return needsIndex; };
42template <
class A,
class B>
43class AddSparseG :
public ExprSparseG<AddSparseG<A, B> > {
48 inline AddSparseG (
const A& a,
const B& b ) : a_ ( a ), b_ ( b ) {};
55 inline double getValue(
int i,
const IndexDimension& I)
const {
56 return (a_.getValue(i,I) + b_.getValue(i,I));
61 ExpressionDescription getDescription()
const {
62 return ExpressionDescription(a_.getDescription(),b_.getDescription());
68template <
class A,
class B>
69inline AddSparseG<A, B> operator+ (
const ExprSparseG<A>& a,
const ExprSparseG<B>& b ) {
70 return AddSparseG<A, B> ( a, b );
80class CAddSparseG :
public ExprSparseG<CAddSparseG<A> > {
85 inline CAddSparseG(
const A& a,
double b ) : a_ ( a ), b_ ( b ) {}
88 inline double getValue(
int i,
const IndexDimension& I)
const {
89 return a_.getValue(i,I) + b_;
95 ExpressionDescription getDescription()
const {
96 return a_.getDescription();
104operator+(
const ExprSparseG<A>& a,
double b ) {
105 return CAddSparseG<A> ( a, b );
111operator+(
double b, ExprSparseG<A>& a ) {
112 return CAddSparseG<A> ( a, b );
118operator-(ExprSparseG<A>& a,
double b ) {
119 return CAddSparseG<A> ( a, -1.0*b );
124template <
class A,
class B>
126class SubSparseG :
public ExprSparseG<SubSparseG<A, B> > {
131 inline SubSparseG (
const A& a,
const B& b ) : a_ ( a ), b_ ( b ) {}
133 inline double getValue(
int i,
const IndexDimension& I)
const {
134 return a_.getValue(i,I) - b_.getValue(i,I);
138 ExpressionDescription getDescription()
const {
139 return ExpressionDescription(a_.getDescription(),b_.getDescription());
145template <
class A,
class B>
146inline SubSparseG<A, B> operator- (
const ExprSparseG<A>& a,
const ExprSparseG<B>& b ) {
147 return SubSparseG<A, B> ( a, b );
152class CSubSparseG :
public ExprSparseG<CSubSparseG< B> > {
157 inline CSubSparseG (
double a,
const B& b ) : a_ ( a ), b_ ( b ) {}
159 inline double getValue(
int i,
const IndexDimension& I)
const {
160 return a_ - b_.getValue(i,I); }
162 ExpressionDescription getDescription()
const {
163 return b_.getDescription();
170inline CSubSparseG< B> operator- (
double a,
const ExprSparseG<B>& b ) {
171 return CSubSparseG< B> ( a, b );
178class MinusSparseG :
public ExprSparseG<MinusSparseG<A> > {
182 inline MinusSparseG (
const A& a ) : a_ ( a ) {}
185 inline double getValue(
int i,
const IndexDimension& I)
const {
186 return -1.0*a_.getValue(i,I);
189 ExpressionDescription getDescription()
const {
190 return a_.getDescription();
197inline MinusSparseG<A> operator- (
const ExprSparseG<A>& a ) {
198 return MinusSparseG<A> ( a );
205class TimesSparseG :
public ExprSparseG<TimesSparseG<A> > {
210 inline TimesSparseG (
const A& a,
const double& b ) : a_ ( a ), b_ ( b ) {}
213 inline double getValue(
int i,
const IndexDimension& I)
const {
214 return a_.getValue(i,I) * b_;
218 ExpressionDescription getDescription()
const {
219 return a_.getDescription();
227inline TimesSparseG<A>
228operator* (
const ExprSparseG<A>& a,
double b ) {
229 return TimesSparseG<A> ( a, b );
234inline TimesSparseG<A>
235operator* (
double b,
const ExprSparseG<A>& a ) {
236 return TimesSparseG<A> ( a, b );
243class DivSparseG :
public ExprSparseG<DivSparseG< B> > {
248 inline DivSparseG (
const double& a,
const B& b ) : a_ ( a ), b_ ( b ) {}
250 inline double getValue(
int i,
const IndexDimension& I)
const {
251 return a_ / b_.getValue(i,I);
255 ExpressionDescription getDescription()
const {
256 return b_.getDescription();
263inline TimesSparseG<A> operator/ (
const ExprSparseG<A>& a,
double b ) {
264 return TimesSparseG<A> ( a, 1.0 / b );
270inline DivSparseG< B> operator/ (
double a,
const ExprSparseG<B>& b ) {
271 return DivSparseG< B> ( a, b );
276template <
class A,
class B>
278class VTimesSparseG :
public ExprSparseG<VTimesSparseG<A, B> > {
283 inline VTimesSparseG(
const A &a,
const B &b) : a_(a), b_(b) {}
285 inline double getValue(
int i,
const IndexDimension &I)
const {
286 if (a_.getValue(i, I) == 0 || b_.getValue(i, I) == 0)
return 0.0;
287 return a_.getValue(i, I) * b_.getValue(i, I);
291 ExpressionDescription getDescription()
const {
292 return ExpressionDescription(a_.getDescription(), b_.getDescription());
300template <
class A,
class B>
301inline VTimesSparseG<A, B> operator* (
const ExprSparseG<A>& a,
const ExprSparseG<B>& b ) {
302 return VTimesSparseG<A, B> ( a, b );
307template <
class A,
class B>
309class VDivSparseG :
public ExprSparseG<VDivSparseG<A, B> > {
314 inline VDivSparseG (
const A& a,
const B& b ) : a_ ( a ), b_ ( b ) {}
316 inline double getValue(
int i,
const IndexDimension& I)
const {
317 return a_.getValue(i,I) / b_.getValue(i,I);
321 ExpressionDescription getDescription()
const {
322 return ExpressionDescription(a_.getDescription(),b_.getDescription());
328template <
class A,
class B>
329inline VDivSparseG<A, B> operator/ (
const ExprSparseG<A>& a,
const ExprSparseG<B>& b ) {
330 return VDivSparseG<A, B> ( a, b );
Definition sparseGrid.h:277