Commit 0cce0e45edda3d1bbc7d7f6a9e6258a91f2685b4
1 parent
36ed4440
Adapt numerical unit test to new GFunctions interface
Showing
2 changed files
with
29 additions
and
29 deletions
test/test_GNumerics.cpp
... | ... | @@ -523,29 +523,29 @@ void TestGNumerics::test_function(void) |
523 | 523 | void TestGNumerics::test_functions(void) |
524 | 524 | { |
525 | 525 | // Set sigma array |
526 | - GNdarray sigma(1,3); | |
527 | - sigma(0,0) = 1.0; | |
528 | - sigma(0,1) = 2.0; | |
529 | - sigma(0,2) = 4.0; | |
526 | + GVector sigma(3); | |
527 | + sigma[0] = 1.0; | |
528 | + sigma[1] = 2.0; | |
529 | + sigma[2] = 4.0; | |
530 | 530 | |
531 | 531 | // Allocate functions |
532 | 532 | GaussArray functions(sigma); |
533 | 533 | |
534 | 534 | // Evaluate functions for x=0 |
535 | - GNdarray result = functions.eval(0.0); | |
535 | + GVector result = functions.eval(0.0); | |
536 | 536 | |
537 | 537 | // Test function values |
538 | - test_value(result(0,0), 0.39894228, "Check function[0] value at x=0"); | |
539 | - test_value(result(0,1), 0.19947114, "Check function[1] value at x=0"); | |
540 | - test_value(result(0,2), 0.09973557, "Check function[2] value at x=0"); | |
538 | + test_value(result[0], 0.39894228, "Check function[0] value at x=0"); | |
539 | + test_value(result[1], 0.19947114, "Check function[1] value at x=0"); | |
540 | + test_value(result[2], 0.09973557, "Check function[2] value at x=0"); | |
541 | 541 | |
542 | 542 | // Evaluate functions for x=1 |
543 | 543 | result = functions.eval(1.0); |
544 | 544 | |
545 | 545 | // Test function values |
546 | - test_value(result(0,0), 0.24197072, "Check function[0] value at x=1"); | |
547 | - test_value(result(0,1), 0.17603266, "Check function[1] value at x=1"); | |
548 | - test_value(result(0,2), 0.09666703, "Check function[2] value at x=1"); | |
546 | + test_value(result[0], 0.24197072, "Check function[0] value at x=1"); | |
547 | + test_value(result[1], 0.17603266, "Check function[1] value at x=1"); | |
548 | + test_value(result[2], 0.09666703, "Check function[2] value at x=1"); | |
549 | 549 | |
550 | 550 | // Exit test |
551 | 551 | return; |
... | ... | @@ -571,10 +571,10 @@ void TestGNumerics::test_integral(void) |
571 | 571 | void TestGNumerics::test_integrals(void) |
572 | 572 | { |
573 | 573 | // Set sigma array |
574 | - GNdarray sigma(1,3); | |
575 | - sigma(0,0) = 1.0; | |
576 | - sigma(0,1) = 2.0; | |
577 | - sigma(0,2) = 4.0; | |
574 | + GVector sigma(3); | |
575 | + sigma[0] = 1.0; | |
576 | + sigma[1] = 2.0; | |
577 | + sigma[2] = 4.0; | |
578 | 578 | |
579 | 579 | // Test kernels and integrals allocation |
580 | 580 | GaussArray kernels(sigma); |
... | ... | @@ -583,18 +583,18 @@ void TestGNumerics::test_integrals(void) |
583 | 583 | test_value(integrals.calls(), 0, "Check initial calls"); |
584 | 584 | |
585 | 585 | // Integrate over the entire Gaussian |
586 | - GNdarray result = integrals.romberg(-40.0, 40.0); | |
587 | - test_value(result(0,0), 1.0, 1.0e-6, "Check full integration result for (0,0)"); | |
588 | - test_value(result(0,1), 1.0, 1.0e-6, "Check full integration result for (0,1)"); | |
589 | - test_value(result(0,2), 1.0, 1.0e-6, "Check full integration result for (0,2)"); | |
586 | + GVector result = integrals.romberg(-40.0, 40.0); | |
587 | + test_value(result[0], 1.0, 1.0e-6, "Check full integration result for (0,0)"); | |
588 | + test_value(result[1], 1.0, 1.0e-6, "Check full integration result for (0,1)"); | |
589 | + test_value(result[2], 1.0, 1.0e-6, "Check full integration result for (0,2)"); | |
590 | 590 | |
591 | 591 | // Test [-1,1] integration |
592 | 592 | result = integrals.romberg(-1.0, 1.0); |
593 | - test_value(result(0,0), 0.68268948, 1.0e-6, | |
593 | + test_value(result[0], 0.68268948, 1.0e-6, | |
594 | 594 | "Check [-1,1] integration result for (0,0)"); |
595 | - test_value(result(0,1), 0.38292492, 1.0e-6, | |
595 | + test_value(result[1], 0.38292492, 1.0e-6, | |
596 | 596 | "Check [-1,1] integration result for (0,1)"); |
597 | - test_value(result(0,2), 0.19741265, 1.0e-6, | |
597 | + test_value(result[2], 0.19741265, 1.0e-6, | |
598 | 598 | "Check [-1,1] integration result for (0,2)"); |
599 | 599 | |
600 | 600 | // Exit test | ... | ... |
test/test_GNumerics.hpp
... | ... | @@ -59,19 +59,19 @@ protected: |
59 | 59 | ***************************************************************************/ |
60 | 60 | class GaussArray : public GFunctions { |
61 | 61 | public: |
62 | - GaussArray(const GNdarray& sigma) : m_sigma(sigma) { return; } | |
62 | + GaussArray(const GVector& sigma) : m_sigma(sigma) { return; } | |
63 | 63 | virtual ~GaussArray(void) { return; } |
64 | - const GNdarray& array(void) const { return m_sigma; } | |
65 | - GNdarray eval(const double& x) { | |
66 | - GNdarray val(m_sigma.shape()); | |
64 | + int size(void) const { return m_sigma.size(); } | |
65 | + GVector eval(const double& x) { | |
66 | + GVector val(m_sigma.size()); | |
67 | 67 | for (int i = 0; i < m_sigma.size(); ++i) { |
68 | - double arg = -0.5*x*x/m_sigma(i)/m_sigma(i); | |
69 | - val(i) = 1.0/std::sqrt(gammalib::twopi)/m_sigma(i) * std::exp(arg); | |
68 | + double arg = -0.5*x*x/m_sigma[i]/m_sigma[i]; | |
69 | + val[i] = 1.0/std::sqrt(gammalib::twopi)/m_sigma[i] * std::exp(arg); | |
70 | 70 | } |
71 | 71 | return val; |
72 | 72 | } |
73 | 73 | protected: |
74 | - GNdarray m_sigma; | |
74 | + GVector m_sigma; | |
75 | 75 | }; |
76 | 76 | |
77 | 77 | ... | ... |