Multivariate.h
1 //-*-C++-*-
2 /***************************************************************************
3  *
4  * Copyright (C) 2022 by Willem van Straten
5  * Licensed under the Academic Free License version 2.1
6  *
7  ***************************************************************************/
8 
9 // psrchive/More/MEAL/MEAL/Multivariate.h
10 
11 #ifndef __MEAL_Multivariate_H
12 #define __MEAL_Multivariate_H
13 
14 #include "MEAL/MultivariatePolicy.h"
15 #include "Reference.h"
16 
17 namespace MEAL {
18 
20 
21  template<class T>
22  class Multivariate : public T
23  {
24  unsigned ndim;
25 
26  public:
27 
29  Multivariate (unsigned _ndim)
30  { ndim = _ndim;
31  set_multivariate_policy ( new MultivariatePolicy (ndim, this) ); }
32 
34  Multivariate (const Multivariate& copy) : T (copy) { ndim = copy.ndim; }
35 
38 
40  Multivariate<T>* clone () const
41  { throw Error (InvalidState, "Multivariate<T>::clone", "not implemented"); }
42 
44  virtual void set_abscissa (unsigned idim, double value)
45  { multivariate_policy->set_abscissa (idim, value); }
46 
48  double get_abscissa (unsigned idim) const
49  { return multivariate_policy->get_abscissa (idim); }
50 
51  protected:
52 
53  template <class U>
54  friend class FunctionPolicyTraits;
55 
56  void set_multivariate_policy (MultivariatePolicy* policy)
57  { this->argument_policy = multivariate_policy = policy; }
58 
59  MultivariatePolicy* get_multivariate_policy () const
60  { return multivariate_policy; }
61 
63  void copy_multivariate_policy (const Multivariate* other)
64  { set_multivariate_policy (other->get_multivariate_policy()); }
65 
66  private:
67 
69  Reference::To<MultivariatePolicy> multivariate_policy;
70 
71  };
72 
73  template<class T>
74  class FunctionPolicyTraits< Multivariate<T> >
75  {
76  public:
77  static void composite_component (Multivariate<T>* composite,
78  Multivariate<T>* component)
79  {
80  component->copy_multivariate_policy (composite);
81  }
82  };
83 }
84 
85 template<class T>
87 {
88  if (&copy == this)
89  return this;
90 
91  for (unsigned idim=0; idim < ndim; idim++)
92  set_abscissa( idim, copy.get_abscissa(idim) );
93 
94  T::operator=( copy );
95 
96  return *this;
97 }
98 
99 #endif
100 
Multivariate(unsigned _ndim)
Construct with number of dimensions (independent abscissae)
Definition: Multivariate.h:39
void copy_multivariate_policy(const Multivariate *other)
Copy the parameter policy of another instance.
Definition: Multivariate.h:73
Multivariate< T > * clone() const
Clone.
Definition: Multivariate.h:50
double get_abscissa(unsigned idim) const
Get the abscissa value for the specified dimension.
Definition: Multivariate.h:58
virtual void set_abscissa(unsigned idim, double value)
Set the abscissa value for the specified dimension.
Definition: Multivariate.h:54
Multivariate & operator=(const Multivariate &copy)
Assignment operator.
Definition: Multivariate.h:86
Abstract template base class of multivariate Function implementations.
Definition: Multivariate.h:27
Namespace in which all modeling and calibration related code is declared.
Definition: ExampleComplex2.h:16
A function of one or more scalar variables.
Definition: MultivariatePolicy.h:24

Generated using doxygen 1.8.17