ReFRACtor
polynomial_eval.cc
Go to the documentation of this file.
1 #include "polynomial_eval.h"
2 
3 using namespace FullPhysics;
4 using namespace blitz;
5 
6 double Poly1d::operator()(double Value) const
7 {
8  double res = 0;
9  Array<int,1> eidx(eval_indexes());
10  for(int coeff_idx = 0; coeff_idx < coeffs_.rows(); coeff_idx++) {
11  res = coeffs_(eidx(coeff_idx)).value() + res * Value;
12  }
13 
14  return res;
15 }
16 
18 {
19 
21  Array<int,1> eidx(eval_indexes());
22  for(int coeff_idx = 0; coeff_idx < coeffs_.rows(); coeff_idx++) {
23  res = coeffs_(eidx(coeff_idx)) + res * Value;
24  }
25 
26  return res;
27 }
28 
30 {
31  ArrayAd<double, 1> res(Arr.rows(), Arr.number_variable());
32  for(int arr_idx = 0; arr_idx < res.rows(); arr_idx++)
33  res(arr_idx) = (*this)(Arr(arr_idx));
34  return res;
35 }
36 
37 Array<double,1> Poly1d::operator()(const blitz::Array<double,1>& Arr) const
38 {
39  Array<double, 1> res(Arr.rows());
40  for(int arr_idx = 0; arr_idx < res.rows(); arr_idx++)
41  res(arr_idx) = (*this)(Arr(arr_idx));
42  return res;
43 }
44 
45 blitz::Array<int,1> Poly1d::eval_indexes() const
46 {
47  Array<int, 1> res(coeffs_.rows());
48  for(int idx = 0; idx < coeffs_.rows(); idx++) {
49  if(decreasing_order_)
50  res(idx) = idx;
51  else
52  res(idx) = coeffs_.rows() - idx - 1;
53  }
54  return res;
55 }
56 
57 void Poly1d::print(std::ostream& Os) const
58 {
59  Os << "Poly1d : Polynomial: ";
60  int ncoeffs = coeffs_.rows();
61  Array<int,1> eidx(eval_indexes());
62  for(int coeff_idx = 0; coeff_idx < ncoeffs; coeff_idx++) {
63  double coeff = coeffs_(eidx(coeff_idx)).value();
64  int power = ncoeffs - coeff_idx - 1;
65  if(coeff_idx > 0) {
66  coeff < 0.0 ? Os << " - " : Os << " + ";
67  Os << abs(coeff);
68  } else {
69  Os << coeff;
70  }
71  if(power > 0) Os << "x";
72  if(power > 1) Os << "^" << power;
73  }
74 }
Apply value function to a blitz array.
double operator()(double Value) const
Evaluate polynomial for a value.
int number_variable() const
Definition: array_ad.h:376
Contains classes to abstract away details in various Spurr Radiative Transfer software.
Definition: doxygen_python.h:1
virtual void print(std::ostream &Os) const
int rows() const
Definition: array_ad.h:368

Copyright © 2017, California Institute of Technology.
ALL RIGHTS RESERVED.
U.S. Government Sponsorship acknowledged.
Generated Fri Aug 24 2018 15:44:11