From 3918d3a9b893ab5a2147dcae990f3f89805595a0 Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Thu, 21 Mar 2019 17:40:02 +0000 Subject: [PATCH] function sampling method --- lib/Functional/Function.cpp | 20 ++++++++++++++++++++ lib/Functional/Function.hpp | 2 ++ 2 files changed, 22 insertions(+) diff --git a/lib/Functional/Function.cpp b/lib/Functional/Function.cpp index f83fef2..6b31feb 100644 --- a/lib/Functional/Function.cpp +++ b/lib/Functional/Function.cpp @@ -179,6 +179,26 @@ DoubleFunction DoubleFunction::bind(const Index argIndex, return bindFunc; } +// sample ////////////////////////////////////////////////////////////////////// +DVec DoubleFunction::sample(const DMat &x) +{ + if (x.cols() != getNArg()) + { + LATAN_ERROR(Size, "sampling point matrix and number of arguments " + "mismatch (matrix has " + strFrom(x.cols()) + + ", number of arguments is " + strFrom(getNArg()) + ")"); + } + + DVec res(x.rows()); + + for (Index i = 0; i < res.size(); ++i) + { + res(i) = (*this)(x.row(i)); + } + + return res; +} + // arithmetic operators //////////////////////////////////////////////////////// DoubleFunction DoubleFunction::operator-(void) const { diff --git a/lib/Functional/Function.hpp b/lib/Functional/Function.hpp index 2afdda7..859c705 100644 --- a/lib/Functional/Function.hpp +++ b/lib/Functional/Function.hpp @@ -56,6 +56,8 @@ public: // bind DoubleFunction bind(const Index argIndex, const double val) const; DoubleFunction bind(const Index argIndex, const DVec &x) const; + // sample + DVec sample(const DMat &x); // arithmetic operators DoubleFunction operator-(void) const; DoubleFunction & operator+=(const DoubleFunction &f);