Commit 7a3e28514f78dfec31ff4fbc498ec6c751ea9aa2

Authored by Jürgen Knödlseder
1 parent dbe8a50a

GFunctions::eval() returns GNdarray instead of GVector (#3328)

The handling of GNdarray is more universal than the handling of GVector objects.
include/GFunctions.hpp
1 1 /***************************************************************************
2   - * GFunctions.hpp - Single parameter vector function abstract base class *
  2 + * GFunctions.hpp - Single parameter functions abstract base class *
3 3 * ----------------------------------------------------------------------- *
4 4 * copyright (C) 2020 by Juergen Knoedlseder *
5 5 * ----------------------------------------------------------------------- *
... ... @@ -20,7 +20,7 @@
20 20 ***************************************************************************/
21 21 /**
22 22 * @file GFunctions.hpp
23   - * @brief Single parameter vector function abstract base class definition
  23 + * @brief Single parameter functions abstract base class definition
24 24 * @author Juergen Knoedlseder
25 25 */
26 26  
... ... @@ -30,23 +30,22 @@
30 30 /* __ Includes ___________________________________________________________ */
31 31  
32 32 /* __ Forward declarations _______________________________________________ */
33   -class GVector;
  33 +class GNdarray;
34 34  
35 35  
36 36 /***********************************************************************//**
37 37 * @class GFunctions
38 38 *
39   - * @brief Single parameter vector function abstract base class
  39 + * @brief Single parameter functions abstract base class
40 40 *
41   - * This class implements the abstract interface for a one parameter vector
42   - * function. A vector function is a function that returns a vector of values,
43   - * implemented by the GVector class.
  41 + * This class implements the abstract interface for a set of one parameter
  42 + * functions.
44 43 *
45   - * The vector function is for example used for integration or numerical
  44 + * The set of functions is for example used for integration or numerical
46 45 * computation of derivatives. This class has no members. The only pure
47 46 * virtual method that needs to be implemented by the derived class is the
48   - * eval() method that provides vector function evaluation at a given value
49   - * x, e.g. y=eval(x).
  47 + * eval() method that evaluates the functions at a given value x and returns
  48 + * the evaluation result as an GNdarray object.
50 49 ***************************************************************************/
51 50 class GFunctions {
52 51  
... ... @@ -61,7 +60,7 @@ public:
61 60 GFunctions& operator=(const GFunctions& functions);
62 61  
63 62 // Methods
64   - virtual GVector eval(const double& x) = 0;
  63 + virtual GNdarray eval(const double& x) = 0;
65 64  
66 65 protected:
67 66 // Protected methods
... ...
inst/cta/include/GCTABackgroundPerfTable.hpp
1 1 /***************************************************************************
2 2 * GCTABackgroundPerfTable.hpp - CTA performance table background class *
3 3 * ----------------------------------------------------------------------- *
4   - * copyright (C) 2014-2018 by Juergen Knoedlseder *
  4 + * copyright (C) 2014-2020 by Juergen Knoedlseder *
5 5 * ----------------------------------------------------------------------- *
6 6 * *
7 7 * This program is free software: you can redistribute it and/or modify *
... ... @@ -30,6 +30,7 @@
30 30 /* __ Includes ___________________________________________________________ */
31 31 #include <string>
32 32 #include "GFilename.hpp"
  33 +#include "GFunction.hpp"
33 34 #include "GEnergies.hpp"
34 35 #include "GNodeArray.hpp"
35 36 #include "GModelSpectralNodes.hpp"
... ...
pyext/GFunctions.i
1 1 /***************************************************************************
2   - * GFunctions.i - Single parameter vector function abstract base class *
  2 + * GFunctions.i - Single parameter functions abstract base class *
3 3 * ----------------------------------------------------------------------- *
4 4 * copyright (C) 2020 by Juergen Knoedlseder *
5 5 * ----------------------------------------------------------------------- *
... ... @@ -20,13 +20,13 @@
20 20 ***************************************************************************/
21 21 /**
22 22 * @file GFunctions.i
23   - * @brief Single parameter vector function abstract base class interface definition
  23 + * @brief Single parameter functions abstract base class definition
24 24 * @author Juergen Knoedlseder
25 25 */
26 26 %{
27 27 /* Put headers and other declarations here that are needed for compilation */
28 28 #include "GFunctions.hpp"
29   -#include "GVector.hpp"
  29 +#include "GNdarray.hpp"
30 30 %}
31 31  
32 32  
... ... @@ -43,5 +43,5 @@ public:
43 43 virtual ~GFunction(void);
44 44  
45 45 // Methods
46   - virtual GVector eval(const double& x) = 0;
  46 + virtual GNdarray eval(const double& x) = 0;
47 47 };
... ...
src/numerics/GFunctions.cpp
1 1 /***************************************************************************
2   - * GFunctions.cpp - Single parameter vector function abstract base class *
  2 + * GFunctions.cpp - Single parameter functions abstract base class *
3 3 * ----------------------------------------------------------------------- *
4 4 * copyright (C) 2020 by Juergen Knoedlseder *
5 5 * ----------------------------------------------------------------------- *
... ... @@ -20,7 +20,7 @@
20 20 ***************************************************************************/
21 21 /**
22 22 * @file GFunctions.cpp
23   - * @brief Single parameter vector function abstract base class implementation
  23 + * @brief Single parameter functions abstract base class implementation
24 24 * @author Juergen Knoedlseder
25 25 */
26 26  
... ...
test/test_GNumerics.cpp
... ... @@ -520,27 +520,30 @@ void TestGNumerics::test_function(void)
520 520 ***************************************************************************/
521 521 void TestGNumerics::test_functions(void)
522 522 {
523   - // Set vector
524   - GVector sigma(1.0, 2.0, 4.0);
  523 + // Set sigma array
  524 + GNdarray sigma(1,3);
  525 + sigma(0,0) = 1.0;
  526 + sigma(0,1) = 2.0;
  527 + sigma(0,2) = 4.0;
525 528  
526 529 // Allocate functions
527   - GaussVector functions(sigma);
  530 + GaussArray functions(sigma);
528 531  
529 532 // Evaluate functions for x=0
530   - GVector result = functions.eval(0.0);
  533 + GNdarray result = functions.eval(0.0);
531 534  
532 535 // Test function values
533   - test_value(result[0], 0.39894228, "Check function[0] value at x=0");
534   - test_value(result[1], 0.19947114, "Check function[1] value at x=0");
535   - test_value(result[2], 0.09973557, "Check function[2] value at x=0");
  536 + test_value(result(0,0), 0.39894228, "Check function[0] value at x=0");
  537 + test_value(result(0,1), 0.19947114, "Check function[1] value at x=0");
  538 + test_value(result(0,2), 0.09973557, "Check function[2] value at x=0");
536 539  
537 540 // Evaluate functions for x=1
538 541 result = functions.eval(1.0);
539 542  
540 543 // Test function values
541   - test_value(result[0], 0.24197072, "Check function[0] value at x=1");
542   - test_value(result[1], 0.17603266, "Check function[1] value at x=1");
543   - test_value(result[2], 0.09666703, "Check function[2] value at x=1");
  544 + test_value(result(0,0), 0.24197072, "Check function[0] value at x=1");
  545 + test_value(result(0,1), 0.17603266, "Check function[1] value at x=1");
  546 + test_value(result(0,2), 0.09666703, "Check function[2] value at x=1");
544 547  
545 548 // Exit test
546 549 return;
... ...
test/test_GNumerics.hpp
... ... @@ -53,24 +53,24 @@ protected:
53 53  
54 54  
55 55 /***********************************************************************//**
56   - * @class GaussVector
  56 + * @class GaussArray
57 57 *
58   - * @brief Gaussian vector function
  58 + * @brief Gaussian function array
59 59 ***************************************************************************/
60   -class GaussVector : public GFunctions {
  60 +class GaussArray : public GFunctions {
61 61 public:
62   - GaussVector(const GVector& sigma) : m_sigma(sigma) { return; }
63   - virtual ~GaussVector(void) { return; }
64   - GVector eval(const double& x) {
65   - GVector val(m_sigma.size());
  62 + GaussArray(const GNdarray& sigma) : m_sigma(sigma) { return; }
  63 + virtual ~GaussArray(void) { return; }
  64 + GNdarray eval(const double& x) {
  65 + GNdarray val(m_sigma.shape());
66 66 for (int i = 0; i < m_sigma.size(); ++i) {
67   - double arg = -0.5*x*x/m_sigma[i]/m_sigma[i];
68   - val[i] = 1.0/std::sqrt(gammalib::twopi)/m_sigma[i] * std::exp(arg);
  67 + double arg = -0.5*x*x/m_sigma(i)/m_sigma(i);
  68 + val(i) = 1.0/std::sqrt(gammalib::twopi)/m_sigma(i) * std::exp(arg);
69 69 }
70 70 return val;
71 71 }
72 72 protected:
73   - GVector m_sigma;
  73 + GNdarray m_sigma;
74 74 };
75 75  
76 76  
... ...