diff --git a/MParT/BasisEvaluator.h b/MParT/BasisEvaluator.h index 66bd731c..fcd859f7 100644 --- a/MParT/BasisEvaluator.h +++ b/MParT/BasisEvaluator.h @@ -234,7 +234,7 @@ class BasisEvaluator struct CompFactoryImpl{ - typedef std::tuple OptionsKeyType; + typedef std::tuple OptionsKeyType; typedef std::function>(FixedMultiIndexSet const&, MapOptions options)> FactoryFunctionType; typedef std::map FactoryMapType; static FactoryFunctionType GetFactoryFunction(MapOptions opts) { bool isLinearized = (!isinf(opts.basisLB)) ||(!isinf(opts.basisUB)); - OptionsKeyType optionsKey(opts.basisType, isLinearized, opts.posFuncType, opts.quadType); + bool isCompact = opts.isCompact; + OptionsKeyType optionsKey(opts.basisType, isLinearized, opts.posFuncType, opts.quadType, isCompact); auto factoryMap = GetFactoryMap(); diff --git a/MParT/MapOptions.h b/MParT/MapOptions.h index 08f2640d..66de5f17 100644 --- a/MParT/MapOptions.h +++ b/MParT/MapOptions.h @@ -12,7 +12,8 @@ namespace mpart{ { ProbabilistHermite, PhysicistHermite, - HermiteFunctions + HermiteFunctions, + Legendre }; enum class PosFuncTypes @@ -76,6 +77,8 @@ namespace mpart{ double basisLB = -std::numeric_limits::infinity(); double basisUB = std::numeric_limits::infinity(); + /** Whether the map should be compactly supported (cannot be linearized, only works with certain other map options */ + bool isCompact = false; /** The type of positive bijector used inside the monotonicity-guaranteeing integral formulation. diff --git a/MParT/MonotoneComponent.h b/MParT/MonotoneComponent.h index 65097100..3db3da06 100644 --- a/MParT/MonotoneComponent.h +++ b/MParT/MonotoneComponent.h @@ -44,7 +44,7 @@ T(x_1, x_2, ..., x_D) = f(x_1,x_2,..., x_{D-1}, 0) + \int_0^{x_D} g\left( \part @tparam PosFuncType A class defining the function \f$g\f$. This class must have `Evaluate` and `Derivative` functions accepting a double and returning a double. The MParT::SoftPlus and MParT::Exp classes in PositiveBijectors.h are examples of classes defining this interface. @tparam QuadratureType A class defining the integration scheme used to approximate \f$\int_0^{x_N} g\left( \frac{\partial f}{\partial x_d}(x_1,x_2,..., x_{N-1}, t) \right) dt\f$. The type must have a function `Integrate(f,lb,ub)` that accepts a functor `f`, a double lower bound `lb`, a double upper bound `ub`, and returns a double with an estimate of the integral. The MParT::AdaptiveSimpson and MParT::RecursiveQuadrature classes provide this interface. */ -template +template class MonotoneComponent : public ConditionalMapBase { @@ -70,8 +70,6 @@ class MonotoneComponent : public ConditionalMapBase useContDeriv_(useContDeriv), nugget_(nugget){}; - - MonotoneComponent(ExpansionType const& expansion, QuadratureType const& quad, bool useContDeriv, @@ -215,9 +213,6 @@ class MonotoneComponent : public ConditionalMapBase ContinuousMixedInputJacobian(pts,this->savedCoeffs, output); ContinuousDerivative(pts, this->savedCoeffs, derivs); }else{ - // Kokkos::View evals("Evaluations", pts.extent(1)); - // DiscreteMixedJacobian(pts,this->savedCoeffs, output); - // DiscreteDerivative(pts, this->savedCoeffs, evals, derivs); std::stringstream msg; msg << "Discrete derivative version is not implemented yet (To Do)"; throw std::invalid_argument(msg.str()); @@ -285,10 +280,13 @@ class MonotoneComponent : public ConditionalMapBase // Fill in entries in the cache that are independent of x_d. By passing DerivativeFlags::None, we are telling the expansion that no derivatives with wrt x_1,...x_{d-1} will be needed. expansion_.FillCache1(cache.data(), pt, DerivativeFlags::None); output(ptInd) = EvaluateSingle(cache.data(), workspace.data(), pt, pt(dim_-1), coeffs, quad_, expansion_); + if constexpr(isCompact) { + double denom_eval = EvaluateSingle(cache.data(), workspace.data(), pt, 1., coeffs, quad_, expansion_); + output(ptInd) /= denom_eval; + } } }; - // Create a policy with enough scratch memory to cache the polynomial evaluations unsigned int cacheBytes = Kokkos::View::shmem_size(cacheSize+workspaceSize); auto policy = GetCachedRangePolicy(numPts, cacheBytes,functor); @@ -298,21 +296,6 @@ class MonotoneComponent : public ConditionalMapBase } - - // template< typename ExecutionSpace=typename MemoryToExecution::Space> - // void InverseImpl(StridedMatrix const& xs, - // StridedVector const& ys, - // StridedVector const& coeffs, - // StridedVector output, - // std::map options=std::map()) - // { - // StridedMatrix constXs = xs; - // StridedVector constYs = ys; - // StridedVector constCoeffs = coeffs; - - // InverseImpl(constXs,constYs,constCoeffs,output,options); - // } - /** @brief Evaluates the inverse of the diagonal of the monotone component. @details This function solve the nonlinear equation \f$y_D = T(x_1,\ldots,x_D)\f$ for \f$x_D\f$ given \f$N\f$ different @@ -432,7 +415,13 @@ class MonotoneComponent : public ConditionalMapBase // Compute the inverse Kokkos::View workspace(team_member.thread_scratch(1), workspaceSize); auto eval = SingleEvaluator(workspace.data(), cache.data(), pt, coeffs, quad_, expansion_, nugget_); - output(ptInd) = RootFinding::InverseSingleBracket(ys(ptInd), eval, pt(pt.extent(0)-1), xtol, ytol, info); + double y_scale = ys(ptInd); + if constexpr(isCompact) y_scale *= eval(1.); + output(ptInd) = RootFinding::InverseSingleBracket(y_scale, eval, pt(pt.extent(0)-1), xtol, ytol, info); + if constexpr(isCompact) { + if(output(ptInd) < xtol) output(ptInd) = 0.; + else if(output(ptInd) > 1-xtol) output(ptInd) = 1.; + } } }; @@ -442,7 +431,6 @@ class MonotoneComponent : public ConditionalMapBase Kokkos::parallel_for(policy, functor); } - /** @brief Approximates the "continuous derivative" \f$\frac{\partial T}{\partial x_D}\f$ derived from the exact integral form of the transport map. @details See the mathematical background section for more details on discrete and continuous map derivatives. @@ -463,16 +451,6 @@ class MonotoneComponent : public ConditionalMapBase return derivs; } - // template::Space> - // Kokkos::View ContinuousDerivative(StridedMatrix const& pts, - // StridedVector const& coeffs) - // { - // StridedMatrix pts2 = pts; - // StridedVector coeffs2 = coeffs; - // return ContinuousDerivative(pts2,coeffs2); - // } - - /** @brief Approximates the "continuous derivative" \f$\frac{\partial T}{\partial x_D}\f$ derived from the exact integral form of the transport map. @@ -492,11 +470,13 @@ class MonotoneComponent : public ConditionalMapBase const unsigned int numPts = pts.extent(1); const unsigned int dim = pts.extent(0); - // Ask the expansion how much memory it would like for it's one-point cache + // Ask the expansion how much memory it would like for its one-point cache + quad_.SetDim(1); + const unsigned int workspaceSize = quad_.WorkspaceSize(); const unsigned int cacheSize = expansion_.CacheSize(); // Create a policy with enough scratch memory to cache the polynomial evaluations - auto cacheBytes = Kokkos::View::shmem_size(cacheSize); + auto cacheBytes = Kokkos::View::shmem_size(cacheSize + isCompact*(workspaceSize)); auto functor = KOKKOS_CLASS_LAMBDA (typename Kokkos::TeamPolicy::member_type team_member) { @@ -521,6 +501,12 @@ class MonotoneComponent : public ConditionalMapBase // Compute g(df/dx) derivs(ptInd) = PosFuncType::Evaluate(derivs(ptInd)); + + // If compact, normalize by part independent of x_d + if constexpr(isCompact) { + Kokkos::View workspace(team_member.thread_scratch(1), workspaceSize); + derivs(ptInd) /= EvaluateSingle(cache.data(), workspace.data(), pt, 1., coeffs, quad_, expansion_); + } } }; @@ -530,16 +516,6 @@ class MonotoneComponent : public ConditionalMapBase Kokkos::parallel_for(policy, functor); } - // template::Space> - // void ContinuousDerivative(StridedMatrix const& pts, - // StridedVector const& coeffs, - // StridedVector derivs) - // { - // StridedMatrix pts2 = pts; - // StridedVector coeffs2 = coeffs; - // ContinuousDerivative(pts2,coeffs2, derivs); - // } - /** @brief Approximates the "discrete derivative" of the quadrature-based approximation \f$\tilde{T}\f$. @details See the mathematical background section for more details on discrete and continuous map derivatives. @@ -562,16 +538,6 @@ class MonotoneComponent : public ConditionalMapBase return derivs; } - // template::Space> - // Kokkos::View DiscreteDerivative(StridedMatrix const& pts, - // StridedVector const& coeffs) - // { - // StridedMatrix pts2 = pts; - // StridedVector coeffs2 = coeffs; - // return DiscreteDerivative(pts2,coeffs2); - // } - - /** @brief Approximates the "discrete derivative" of the quadrature-based approximation \f$\tilde{T}\f$. @details See the mathematical background section for more details on discrete and continuous map derivatives. @@ -588,6 +554,9 @@ class MonotoneComponent : public ConditionalMapBase StridedVector evals, StridedVector derivs) { + if constexpr(isCompact) { + throw std::invalid_argument("Cannot use discrete derivatives with compact monotone component at this time"); + } const unsigned int numPts = pts.extent(1); const unsigned int numTerms = coeffs.extent(0); @@ -629,6 +598,9 @@ class MonotoneComponent : public ConditionalMapBase // Add f(x_1,x_2,...,x_{d-1},0) to the evaluation output expansion_.FillCache2(cache.data(), pt, 0.0, DerivativeFlags::None); evals(ptInd) += expansion_.Evaluate(cache.data(), coeffs); + if constexpr(isCompact) { + ProcAgnosticError("Discrete derivative not supported for compact map"); + } } }; @@ -637,17 +609,6 @@ class MonotoneComponent : public ConditionalMapBase Kokkos::parallel_for(policy, functor); } - // template::Space> - // void DiscreteDerivative(StridedMatrix const& pts, - // StridedVector const& coeffs, - // StridedVector evals, - // StridedVector derivs) - // { - // StridedMatrix pts2 = pts; - // StridedVector coeffs2 = coeffs; - // DiscreteDerivative(pts2, coeffs2, evals, derivs); - // } - bool isJacobianInputValid(int jacRows, int jacCols, int evalRows, int expectJacRows, int expectJacCols, int expectEvalRows) { bool isJacRowsCorrect = jacRows == expectJacRows; bool isJacColsCorrect = jacCols == expectJacCols; @@ -671,7 +632,7 @@ class MonotoneComponent : public ConditionalMapBase @details Consider \f$N\f$ points \f$\{\mathbf{x}^{(1)},\ldots,\mathbf{x}^{(N)}\}\f$ and let - \f$y_d^{(i)} = T_d(\mathbf{x}^{(i)}; \mathbf{w})\f$. This function computes \f$\nabla_{\mathbf{w}} y_d^{(i)}\f$ + \f$y_d^{(i)} = T_d(\mathbf{x}^{(i)}; \mathbf{w})\f$. This function computes \f$\nabla_{\mathbf{w}} y_d^{(i)}\f$ for each output \f$y_d^{(i)}\f$. @param[in] pts A \f$D\times N\f$ matrix containing the points \f$x^{(1)},\ldots,x^{(N)}\f$. Each column is a point. @@ -697,8 +658,10 @@ class MonotoneComponent : public ConditionalMapBase quad_.SetDim(numTerms+1); const unsigned int workspaceSize = quad_.WorkspaceSize(); + unsigned int integral_space = (numTerms + 1)*(1+isCompact); + // Create a policy with enough scratch memory to cache the polynomial evaluations - auto cacheBytes = Kokkos::View::shmem_size(cacheSize+workspaceSize+numTerms+1); + auto cacheBytes = Kokkos::View::shmem_size(cacheSize+workspaceSize+integral_space); auto functor = KOKKOS_CLASS_LAMBDA (typename Kokkos::TeamPolicy::member_type team_member) { @@ -713,24 +676,50 @@ class MonotoneComponent : public ConditionalMapBase Kokkos::View cache(team_member.thread_scratch(1), cacheSize); Kokkos::View workspace(team_member.thread_scratch(1), workspaceSize); Kokkos::View integral(team_member.thread_scratch(1), numTerms+1); + Kokkos::View integral_denom; // Fill in the cache with anything that doesn't depend on x_d - expansion_.FillCache1(cache.data(), pt, DerivativeFlags::None); + expansion_.FillCache1(cache.data(), pt, DerivativeFlags::Parameters); // Create the integrand g( \partial_D f(x_1,...,x_{D-1},t)) - MonotoneIntegrand integrand(cache.data(), expansion_, pt, coeffs, DerivativeFlags::Parameters, nugget_); + MonotoneIntegrand integrand(cache.data(), expansion_, pt, pt(pt.extent(0)- 1), coeffs, DerivativeFlags::Parameters, nugget_); // Compute \int_0^x g( \partial_D f(x_1,...,x_{D-1},t)) dt as well as the gradient of this term wrt the coefficients of f quad_.Integrate(workspace.data(), integrand, 0, 1, integral.data()); + + // Do the same work for the denominator if needed + if constexpr(isCompact) { + integral_denom = Kokkos::View(team_member.thread_scratch(1), numTerms+1); + MonotoneIntegrand integrand_denom(cache.data(), expansion_, pt, 1., coeffs, DerivativeFlags::Parameters, nugget_); + quad_.Integrate(workspace.data(), integrand_denom, 0, 1, integral_denom.data()); + } + + expansion_.FillCache2(cache.data(), pt, 0.0, DerivativeFlags::Parameters); - evaluations(ptInd) = integral(0); + // Evaluates the offdiagonal basis and stores the coeffgrad of it into jacView + double offdiag_eval = expansion_.CoeffDerivative(cache.data(), coeffs, jacView); - expansion_.FillCache2(cache.data(), pt, 0.0, DerivativeFlags::None); - evaluations(ptInd) += expansion_.CoeffDerivative(cache.data(), coeffs, jacView); + double numer_eval, denom_eval, denom_eval_sq; + if constexpr(isCompact) { + numer_eval = integral(0); + denom_eval = integral_denom(0); + evaluations(ptInd) = numer_eval / denom_eval; + denom_eval_sq = denom_eval*denom_eval; + } else { + evaluations(ptInd) = integral(0) + offdiag_eval; + } // Add the Integral to the coefficient gradient - for(unsigned int termInd=0; termInd const unsigned int cacheSize = expansion_.CacheSize(); quad_.SetDim(dim_+1); const unsigned int workspaceSize = quad_.WorkspaceSize(); - + unsigned int integral_size = dim_+1; + if constexpr(isCompact) integral_size *= 2; // Create a policy with enough scratch memory to cache the polynomial evaluations - auto cacheBytes = Kokkos::View::shmem_size(cacheSize+workspaceSize+dim_+1); + auto cacheBytes = Kokkos::View::shmem_size(cacheSize+workspaceSize+integral_size); auto functor = KOKKOS_CLASS_LAMBDA (typename Kokkos::TeamPolicy::member_type team_member) { @@ -786,6 +776,7 @@ class MonotoneComponent : public ConditionalMapBase Kokkos::View cache(team_member.thread_scratch(1), cacheSize); Kokkos::View workspace(team_member.thread_scratch(1), workspaceSize); Kokkos::View integral(team_member.thread_scratch(1), dim_+1); + Kokkos::View integral_denom; // Fill in the cache with anything that doesn't depend on x_d expansion_.FillCache1(cache.data(), pt, DerivativeFlags::Input); @@ -796,17 +787,42 @@ class MonotoneComponent : public ConditionalMapBase // Compute \int_0^x g( \partial_D f(x_1,...,x_{D-1},t)) dt as well as the gradient of this term wrt the map input quad_.Integrate(workspace.data(), integrand, 0, 1, integral.data()); - evaluations(ptInd) = integral(0); + double numer_diag_eval = integral(0); + + expansion_.FillCache2(cache.data(), pt, 0.0, DerivativeFlags::Input); + double offdiag_eval = expansion_.InputDerivative(cache.data(), coeffs, jacView); + + double numer_eval, denom_eval, denom_eval_sq; + if constexpr(isCompact) { + numer_eval = numer_diag_eval; - expansion_.FillCache2(cache.data(), pt, 0.0, DerivativeFlags::Input); - evaluations(ptInd) += expansion_.InputDerivative(cache.data(), coeffs, jacView); + integral_denom = Kokkos::View(team_member.thread_scratch(1), dim_+1); + // Create the integrand g( \partial_D f(x_1,...,x_{D-1},1)) + MonotoneIntegrand integrand_denom(cache.data(), expansion_, pt, 1., coeffs, DerivativeFlags::Input, nugget_); + // Compute \int_0^1 g( \partial_D f(x_1,...,x_{D-1},t)) dt as well as the gradient of this term wrt the map input + quad_.Integrate(workspace.data(), integrand_denom, 0, 1, integral_denom.data()); + + denom_eval = integral_denom(0); + denom_eval_sq = denom_eval*denom_eval; + evaluations(ptInd) = numer_eval/denom_eval; + } else evaluations(ptInd) = numer_diag_eval + offdiag_eval; // Add the Integral to the coefficient gradient for(unsigned int d=0; d checkMixedJacobianInput("ContinuousMixedJacobian", jacobian.extent(0), jacobian.extent(1), numTerms, numPts); // Ask the expansion how much memory it would like for it's one-point cache + if constexpr(isCompact) quad_.SetDim(numTerms+1); + const unsigned int workspaceSize = quad_.WorkspaceSize(); const unsigned int cacheSize = expansion_.CacheSize(); // Create a policy with enough scratch memory to cache the polynomial evaluations - auto cacheBytes = Kokkos::View::shmem_size(cacheSize); + auto cacheBytes = Kokkos::View::shmem_size(cacheSize + isCompact*(numTerms+1+workspaceSize)); auto functor = KOKKOS_CLASS_LAMBDA (typename Kokkos::TeamPolicy::member_type team_member) { @@ -848,24 +866,47 @@ class MonotoneComponent : public ConditionalMapBase auto pt = Kokkos::subview(pts, Kokkos::ALL(), ptInd); auto jacView = Kokkos::subview(jacobian, Kokkos::ALL(), ptInd); - // Evaluate the orthgonal polynomials in each direction (except the last) for all possible orders - Kokkos::View cache(team_member.thread_scratch(1), cacheSize); + Kokkos::View integral_denom; + Kokkos::View workspace; + Kokkos::View jac_denom; - // Precompute anything that does not depend on x_d. The DerivativeFlags::None arguments specifies that we won't want to derivative wrt to x_i for i cache(team_member.thread_scratch(1), cacheSize); + // Precompute anything that does not depend on x_d. The DerivativeFlags::MixedCoeff arguments specifies that we won't want to derivative wrt to x_i for i(team_member.thread_scratch(1), numTerms+1); + workspace = Kokkos::View(team_member.thread_scratch(1), workspaceSize); + + MonotoneIntegrand integrand_denom(cache.data(), expansion_, pt, 1., coeffs, DerivativeFlags::Parameters, nugget_); + quad_.Integrate(workspace.data(), integrand_denom, 0, 1, integral_denom.data()); + + numer_diag_deriv = PosFuncType::Evaluate(df); + denom_eval = integral_denom(0); + denom_eval_sq = denom_eval*denom_eval; + } + // Scale the jacobian by dg(df) - for(unsigned int i=0; i checkMixedJacobianInput("ContinuousMixedInputJacobian", jacobian.extent(0), jacobian.extent(1), dim, numPts); // Ask the expansion how much memory it would like for it's one-point cache + if constexpr(isCompact) quad_.SetDim(dim_+1); + const unsigned int workspaceSize = quad_.WorkspaceSize(); const unsigned int cacheSize = expansion_.CacheSize(); // Create a policy with enough scratch memory to cache the polynomial evaluations - auto cacheBytes = Kokkos::View::shmem_size(cacheSize); + auto cacheBytes = Kokkos::View::shmem_size(cacheSize + isCompact*(workspaceSize + dim_ + 1)); auto functor = KOKKOS_CLASS_LAMBDA (typename Kokkos::TeamPolicy::member_type team_member) { @@ -898,8 +941,11 @@ class MonotoneComponent : public ConditionalMapBase // Create a subview containing only the current point auto pt = Kokkos::subview(pts, Kokkos::ALL(), ptInd); auto jacView = Kokkos::subview(jacobian, Kokkos::ALL(), ptInd); + + Kokkos::View integral_denom; + Kokkos::View workspace; - // Evaluate the orthgonal polynomials in each direction (except the last) for all possible orders + // Evaluate the orthogonal polynomials in each direction (except the last) for all possible orders Kokkos::View cache(team_member.thread_scratch(1), cacheSize); // Precompute anything that does not depend on x_d. The DerivativeFlags::None arguments specifies that we won't want to derivative wrt to x_i for i double df = expansion_.MixedInputDerivative(cache.data(), coeffs, jacView); double dgdf = PosFuncType::Derivative(df); + double numer_diag_deriv, denom_eval, denom_eval_sq; + if constexpr(isCompact) { + integral_denom = Kokkos::View(team_member.thread_scratch(1), dim_+1); + workspace = Kokkos::View(team_member.thread_scratch(1), workspaceSize); - // Scale the jacobian by dg(df) - for(unsigned int i=0; i integrand_denom(cache.data(), expansion_, pt, 1., coeffs, DerivativeFlags::Input, nugget_); + quad_.Integrate(workspace.data(), integrand_denom, 0, 1, integral_denom.data()); + + numer_diag_deriv = PosFuncType::Evaluate(df); + denom_eval = integral_denom(0); + denom_eval_sq = denom_eval*denom_eval; + } + + for(unsigned int i=0; i StridedVector const& coeffs, StridedMatrix jacobian) { + if constexpr(isCompact) { + throw std::runtime_error("Cannot use discrete derivatives with compact basis"); + } const unsigned int numPts = pts.extent(1); const unsigned int numTerms = coeffs.extent(0); @@ -1010,8 +1081,10 @@ class MonotoneComponent : public ConditionalMapBase nugget); quad.Integrate(workspace, integrand, 0, 1, &output); - expansion.FillCache2(cache, pt, 0.0, DerivativeFlags::None); - output += expansion.Evaluate(cache, coeffs); + if constexpr(!isCompact) { + expansion.FillCache2(cache, pt, 0.0, DerivativeFlags::None); + output += expansion.Evaluate(cache, coeffs); + } return output; } @@ -1043,17 +1116,16 @@ class MonotoneComponent : public ConditionalMapBase } template - static void load_and_construct( Archive & ar, cereal::construct> & construct ) + static void load_and_construct( Archive & ar, cereal::construct> & construct ) { ExpansionType expansion; QuadratureType quad; bool useContDeriv; double nugget; - ar(expansion, quad, useContDeriv, nugget); + ar(expansion, quad, useContDeriv, nugget); Kokkos::View coeffs; ar( coeffs ); - if(coeffs.size() == expansion.NumCoeffs()){ construct( expansion, quad, useContDeriv, nugget, coeffs); }else{ @@ -1071,7 +1143,6 @@ class MonotoneComponent : public ConditionalMapBase bool useContDeriv_; double nugget_; - template struct SingleEvaluator { double* workspace; diff --git a/MParT/MultivariateExpansionWorker.h b/MParT/MultivariateExpansionWorker.h index d2dde344..aa76070e 100644 --- a/MParT/MultivariateExpansionWorker.h +++ b/MParT/MultivariateExpansionWorker.h @@ -129,6 +129,27 @@ class MultivariateExpansionWorker */ KOKKOS_INLINE_FUNCTION unsigned int InputSize() const {return multiSet_.Length();}; + /** + @brief Fills cache to evaluate f(0) + @details + @param polyCache A pointer to the start of the cache. This memory must be allocated before calling this function. + @param derivType + + @see FillCache1, FillCache2 + */ + KOKKOS_FUNCTION void FillCache0(double* polyCache, + DerivativeFlags::DerivativeType derivType) const + { + // Only allowed to evaluate, fail if you want derivatives; while possible this is a safety precaution + if(derivType == DerivativeFlags::None || derivType == DerivativeFlags::Parameters){ + for(unsigned int d=0; d("Cannot get derivatives for FillCache0"); + } + } + /** @brief Precomputes parts of the cache using all but the last component of the point, i.e., using only \f$x_1,x_2,\ldots,x_{d-1}\f$, not \f$x_d\f$. @details diff --git a/MParT/OrthogonalPolynomial.h b/MParT/OrthogonalPolynomial.h index bc81d80f..33bf7212 100644 --- a/MParT/OrthogonalPolynomial.h +++ b/MParT/OrthogonalPolynomial.h @@ -1,5 +1,5 @@ -#ifndef ORTHOGONALPOLYNOMIAL_H -#define ORTHOGONALPOLYNOMIAL_H +#ifndef MPART_ORTHOGONALPOLYNOMIAL_H +#define MPART_ORTHOGONALPOLYNOMIAL_H #include #include @@ -327,6 +327,21 @@ class PhysicistHermiteMixer{ typedef OrthogonalPolynomial PhysicistHermite; +class ShiftedLegendreMixer{ // Polynomials orthogonal on U[0,1] +public: + KOKKOS_INLINE_FUNCTION double Normalization(unsigned int polyOrder) const { return 1./(2*polyOrder+1);} +protected: + // \f[ p_{k}(x) = (a_k x + b_k) p_{k-1}(x) - c_k p_{k-2}(x) \f] + KOKKOS_INLINE_FUNCTION double ak(unsigned int k) const {return 2. * (2. * k - 1)/k;} + KOKKOS_INLINE_FUNCTION double bk(unsigned int k) const {return -(2. * k - 1)/k;} + KOKKOS_INLINE_FUNCTION double ck(unsigned int k) const {return (k-1.)/k;} + KOKKOS_INLINE_FUNCTION double phi0(double) const {return 1.0;} + KOKKOS_INLINE_FUNCTION double phi1(double x) const {return 2*x-1;} + KOKKOS_INLINE_FUNCTION double phi1_deriv(double) const{return 2.0;}; +}; + +using ShiftedLegendre = OrthogonalPolynomial; + } // namespace mpart #endif \ No newline at end of file diff --git a/MParT/UnivariateBases.h b/MParT/UnivariateBases.h new file mode 100644 index 00000000..c2814c34 --- /dev/null +++ b/MParT/UnivariateBases.h @@ -0,0 +1,155 @@ +#ifndef MPART_UNIVARIATEBASES_H +#define MPART_UNIVARIATEBASES_H + +#include +#include + +#include + +#include "MParT/Utilities/MathFunctions.h" + +namespace mpart{ + +/** + * @brief Generic class to represent functions + * \f[p_0(x)\equiv 1,p_k(x)=sin(2\pi k x)\f] + */ +class SineBasis +{ +public: + static constexpr double PI2 = 2*M_PI; + + /* Evaluates all polynomials up to a specified order. */ + KOKKOS_FUNCTION void EvaluateAll(double* output, + unsigned int maxOrder, + double x) const + { + output[0] = 1.; + + double sin_x, cos_x, cos_kx; + + if(maxOrder>0) { + sin_x = sin(PI2*x); + cos_x = cos(PI2*x); + cos_kx = cos_x; + output[1] = sin_x; + } + + for(unsigned int order=2; order<=maxOrder; ++order) { + output[order] = output[order-1]*cos_x + cos_kx*sin_x; + cos_kx = cos_kx*cos_x - output[order-1]*sin_x; + } + } + + /** Evaluates the derivative of every polynomial in this family up to degree maxOrder (inclusive). + The results are stored in the memory pointed to by the derivs pointer. + */ + KOKKOS_FUNCTION void EvaluateDerivatives(double* derivs, + unsigned int maxOrder, + double x) const + { + derivs[0] = 0.; + + double sin_x, cos_x, sin_kx; + + if(maxOrder>0) { + sin_x = sin(PI2*x); + cos_x = cos(PI2*x); + sin_kx = sin_x; + derivs[1] = cos_x; + } + + // d_x sin(2pi k x) = 2pi k cos(2pi k x) + for(unsigned int order=2; order<=maxOrder; ++order) { + derivs[order] = derivs[order-1]*cos_x - sin_kx*sin_x; + sin_kx = sin_kx*cos_x + derivs[order-1]*sin_x; + derivs[order-2] *= PI2*(order-2); + } + if(maxOrder>0) derivs[maxOrder-1] *= PI2*(maxOrder-1); + derivs[maxOrder] *= PI2*(maxOrder); + } + + /** Evaluates the value and derivative of every polynomial in this family up to degree maxOrder (inclusive). + The results are stored in the memory pointed to by the derivs pointer. + */ + KOKKOS_FUNCTION void EvaluateDerivatives(double* vals, + double* derivs, + unsigned int maxOrder, + double x) const + { + vals[0] = 1.; + derivs[0] = 0.; + + double sin_x, cos_x; + + if(maxOrder>0) { + sin_x = sin(PI2*x); + cos_x = cos(PI2*x); + vals[1] = sin_x; + derivs[1] = cos_x; + } + + for(unsigned int order=2; order<=maxOrder; ++order) { + vals[order] = vals[order-1]*cos_x + derivs[order-1]*sin_x; + derivs[order] = derivs[order-1]*cos_x - vals[order-1]*sin_x; + derivs[order-2] *= PI2*(order-2); + } + if(maxOrder>0) derivs[maxOrder-1] *= PI2*(maxOrder-1); + derivs[maxOrder] *= PI2*(maxOrder); + } + + KOKKOS_FUNCTION void EvaluateSecondDerivatives(double* vals, + double* derivs, + double* secondDerivs, + unsigned int maxOrder, + double x) const + { + vals[0] = 1.; + derivs[0] = 0.; + secondDerivs[0] = 0.; + + double sin_x, cos_x; + + if(maxOrder>0) { + sin_x = sin(PI2*x); + cos_x = cos(PI2*x); + vals[1] = sin_x; + derivs[1] = cos_x; + secondDerivs[1] = -PI2*PI2*vals[1]; + } + + for(unsigned int order=2; order<=maxOrder; ++order) { + vals[order] = vals[order-1]*cos_x + derivs[order-1]*sin_x; + derivs[order] = derivs[order-1]*cos_x - vals[order-1]*sin_x; + derivs[order-2] *= PI2*(order-2); + secondDerivs[order] = -(PI2*order)*(PI2*order)*vals[order]; + } + if(maxOrder > 0) derivs[maxOrder-1] *= PI2*(maxOrder-1); + derivs[maxOrder] *= PI2*(maxOrder); + } + + + + KOKKOS_FUNCTION double Evaluate(unsigned int const order, + double const x) const + { + return order == 0 ? 1. : sin(PI2*order*x); + } + + KOKKOS_FUNCTION double Derivative(unsigned int const order, + double const x) const + { + return order == 0 ? 0. : PI2*order*cos(PI2*order*x); + } + + KOKKOS_FUNCTION double SecondDerivative(unsigned int const order, + double const x) const + { + return -(PI2*order)*(PI2*order)*sin(PI2*order*x); + } + +}; + +} // namespace mpart + +#endif \ No newline at end of file diff --git a/MParT/Utilities/Serialization.h b/MParT/Utilities/Serialization.h index 8c945e10..a98a62ee 100644 --- a/MParT/Utilities/Serialization.h +++ b/MParT/Utilities/Serialization.h @@ -11,8 +11,10 @@ // A macro that can be used for registering the various MonotoneComponent classes with CEREAL // This macro is used in the MapFactoryImpl*.cpp files -#define REGISTER_MONO_COMP(BASIS_HOMOGENEITY, BASIS_TYPE, POS_TYPE, QUAD_TYPE, MEMORY_SPACE) \ - CEREAL_REGISTER_TYPE(mpart::MonotoneComponent, MEMORY_SPACE>, mpart::POS_TYPE, mpart::QUAD_TYPE, MEMORY_SPACE>) +#define REGISTER_HOMOGENEOUS_MONO_COMP(BASIS_TYPE, POS_TYPE, QUAD_TYPE, MEMORY_SPACE, IS_COMPACT) \ + CEREAL_REGISTER_TYPE(mpart::MonotoneComponent, MEMORY_SPACE>, mpart::POS_TYPE, mpart::QUAD_TYPE, MEMORY_SPACE, IS_COMPACT>) +#define REGISTER_OFFDIAGHOMOGENEOUS_MONO_COMP(BASIS_TYPE_1, BASIS_TYPE_2, RECTIFIER, POS_TYPE, QUAD_TYPE, MEMORY_SPACE, IS_COMPACT) \ + CEREAL_REGISTER_TYPE(mpart::MonotoneComponent, RECTIFIER>, MEMORY_SPACE>, mpart::POS_TYPE, mpart::QUAD_TYPE, MEMORY_SPACE, IS_COMPACT>) namespace cereal { diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index d3fcd002..827949b4 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -54,6 +54,7 @@ target_sources(mpart MapFactoryImpl16.cpp MapFactoryImpl17.cpp MapFactoryImpl18.cpp + MapFactoryImpl19.cpp ${MPART_OPT_FILES} Initialization.cpp diff --git a/src/MapFactoryImpl1.cpp b/src/MapFactoryImpl1.cpp index dc6ed1d6..9ab8f06f 100644 --- a/src/MapFactoryImpl1.cpp +++ b/src/MapFactoryImpl1.cpp @@ -13,7 +13,7 @@ using namespace mpart; -template +template std::shared_ptr> CreateComponentImpl_Phys_ACC(FixedMultiIndexSet const& mset, MapOptions opts) { BasisEvaluator basis1d(opts.basisNorm); @@ -24,27 +24,38 @@ std::shared_ptr> CreateComponentImpl_Phys_ACC(Fi MultivariateExpansionWorker,MemorySpace> expansion(mset, basis1d); std::shared_ptr> output; - output = std::make_shared>(expansion, quad, opts.contDeriv, opts.nugget); + output = std::make_shared>(expansion, quad, opts.contDeriv, opts.nugget); Kokkos::View coeffs = Kokkos::View("Component Coefficients", mset.Size()); output->SetCoeffs(coeffs); return output; } -static auto reg_host_phys_acc_exp = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::PhysicistHermite, false, PosFuncTypes::Exp, QuadTypes::AdaptiveClenshawCurtis), CreateComponentImpl_Phys_ACC)); -static auto reg_host_phys_acc_splus = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::PhysicistHermite, false, PosFuncTypes::SoftPlus, QuadTypes::AdaptiveClenshawCurtis), CreateComponentImpl_Phys_ACC)); +static auto reg_host_phys_acc_exp = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::PhysicistHermite, false, PosFuncTypes::Exp, QuadTypes::AdaptiveClenshawCurtis, false), CreateComponentImpl_Phys_ACC)); +static auto reg_host_phys_acc_splus = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::PhysicistHermite, false, PosFuncTypes::SoftPlus, QuadTypes::AdaptiveClenshawCurtis, false), CreateComponentImpl_Phys_ACC)); #if defined(MPART_ENABLE_GPU) - static auto reg_device_phys_acc_exp = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::PhysicistHermite, false, PosFuncTypes::Exp, QuadTypes::AdaptiveClenshawCurtis), CreateComponentImpl_Phys_ACC)); - static auto reg_device_phys_acc_splus = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::PhysicistHermite, false, PosFuncTypes::SoftPlus, QuadTypes::AdaptiveClenshawCurtis), CreateComponentImpl_Phys_ACC)); + static auto reg_device_phys_acc_exp = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::PhysicistHermite, false, PosFuncTypes::Exp, QuadTypes::AdaptiveClenshawCurtis, false), CreateComponentImpl_Phys_ACC)); + static auto reg_device_phys_acc_splus = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::PhysicistHermite, false, PosFuncTypes::SoftPlus, QuadTypes::AdaptiveClenshawCurtis, false), CreateComponentImpl_Phys_ACC)); +#endif + +static auto reg_host_phys_acc_exp_compact = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::PhysicistHermite, false, PosFuncTypes::Exp, QuadTypes::AdaptiveClenshawCurtis, true), CreateComponentImpl_Phys_ACC)); +static auto reg_host_phys_acc_splus_compact = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::PhysicistHermite, false, PosFuncTypes::SoftPlus, QuadTypes::AdaptiveClenshawCurtis, true), CreateComponentImpl_Phys_ACC)); +#if defined(MPART_ENABLE_GPU) + static auto reg_device_phys_acc_exp_compact = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::PhysicistHermite, false, PosFuncTypes::Exp, QuadTypes::AdaptiveClenshawCurtis, true), CreateComponentImpl_Phys_ACC)); + static auto reg_device_phys_acc_splus_compact = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::PhysicistHermite, false, PosFuncTypes::SoftPlus, QuadTypes::AdaptiveClenshawCurtis, true), CreateComponentImpl_Phys_ACC)); #endif #if defined(MPART_HAS_CEREAL) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, PhysicistHermite, Exp, AdaptiveClenshawCurtis, Kokkos::HostSpace) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, PhysicistHermite, SoftPlus, AdaptiveClenshawCurtis, Kokkos::HostSpace) +REGISTER_HOMOGENEOUS_MONO_COMP(PhysicistHermite, Exp, AdaptiveClenshawCurtis, Kokkos::HostSpace, false) +REGISTER_HOMOGENEOUS_MONO_COMP(PhysicistHermite, SoftPlus, AdaptiveClenshawCurtis, Kokkos::HostSpace, false) +REGISTER_HOMOGENEOUS_MONO_COMP(PhysicistHermite, Exp, AdaptiveClenshawCurtis, Kokkos::HostSpace, true) +REGISTER_HOMOGENEOUS_MONO_COMP(PhysicistHermite, SoftPlus, AdaptiveClenshawCurtis, Kokkos::HostSpace, true) #if defined(MPART_ENABLE_GPU) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, PhysicistHermite, Exp, AdaptiveClenshawCurtis, mpart::DeviceSpace) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, PhysicistHermite, SoftPlus, AdaptiveClenshawCurtis, mpart::DeviceSpace) -#endif +REGISTER_HOMOGENEOUS_MONO_COMP(PhysicistHermite, Exp, AdaptiveClenshawCurtis, mpart::DeviceSpace, false) +REGISTER_HOMOGENEOUS_MONO_COMP(PhysicistHermite, SoftPlus, AdaptiveClenshawCurtis, mpart::DeviceSpace, false) +REGISTER_HOMOGENEOUS_MONO_COMP(PhysicistHermite, Exp, AdaptiveClenshawCurtis, mpart::DeviceSpace, true) +REGISTER_HOMOGENEOUS_MONO_COMP(PhysicistHermite, SoftPlus, AdaptiveClenshawCurtis, mpart::DeviceSpace, true) +#endif CEREAL_REGISTER_DYNAMIC_INIT(mpartInitMapFactory1) #endif diff --git a/src/MapFactoryImpl10.cpp b/src/MapFactoryImpl10.cpp index c7e2e8a8..676c0cd3 100644 --- a/src/MapFactoryImpl10.cpp +++ b/src/MapFactoryImpl10.cpp @@ -24,7 +24,7 @@ std::shared_ptr> CreateComponentImpl_LinPhys_ACC MultivariateExpansionWorker expansion(mset, basis1d); std::shared_ptr> output; - output = std::make_shared>(expansion, quad, opts.contDeriv, opts.nugget); + output = std::make_shared>(expansion, quad, opts.contDeriv, opts.nugget); Kokkos::View coeffs = Kokkos::View("Component Coefficients", mset.Size()); output->SetCoeffs(coeffs); @@ -32,19 +32,19 @@ std::shared_ptr> CreateComponentImpl_LinPhys_ACC return output; } -static auto reg_host_linphys_acc_exp = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::PhysicistHermite, true, PosFuncTypes::Exp, QuadTypes::AdaptiveClenshawCurtis), CreateComponentImpl_LinPhys_ACC)); -static auto reg_host_linphys_acc_splus = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::PhysicistHermite, true, PosFuncTypes::SoftPlus, QuadTypes::AdaptiveClenshawCurtis), CreateComponentImpl_LinPhys_ACC)); +static auto reg_host_linphys_acc_exp = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::PhysicistHermite, true, PosFuncTypes::Exp, QuadTypes::AdaptiveClenshawCurtis, false), CreateComponentImpl_LinPhys_ACC)); +static auto reg_host_linphys_acc_splus = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::PhysicistHermite, true, PosFuncTypes::SoftPlus, QuadTypes::AdaptiveClenshawCurtis, false), CreateComponentImpl_LinPhys_ACC)); #if defined(MPART_ENABLE_GPU) - static auto reg_device_linphys_acc_exp = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::PhysicistHermite, true, PosFuncTypes::Exp, QuadTypes::AdaptiveClenshawCurtis), CreateComponentImpl_LinPhys_ACC)); - static auto reg_device_linphys_acc_splus = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::PhysicistHermite, true, PosFuncTypes::SoftPlus, QuadTypes::AdaptiveClenshawCurtis), CreateComponentImpl_LinPhys_ACC)); + static auto reg_device_linphys_acc_exp = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::PhysicistHermite, true, PosFuncTypes::Exp, QuadTypes::AdaptiveClenshawCurtis, false), CreateComponentImpl_LinPhys_ACC)); + static auto reg_device_linphys_acc_splus = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::PhysicistHermite, true, PosFuncTypes::SoftPlus, QuadTypes::AdaptiveClenshawCurtis, false), CreateComponentImpl_LinPhys_ACC)); #endif #if defined(MPART_HAS_CEREAL) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, LinearizedBasis, Exp, AdaptiveClenshawCurtis, Kokkos::HostSpace) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, LinearizedBasis, SoftPlus, AdaptiveClenshawCurtis, Kokkos::HostSpace) +REGISTER_HOMOGENEOUS_MONO_COMP(LinearizedBasis, Exp, AdaptiveClenshawCurtis, Kokkos::HostSpace, false) +REGISTER_HOMOGENEOUS_MONO_COMP(LinearizedBasis, SoftPlus, AdaptiveClenshawCurtis, Kokkos::HostSpace, false) #if defined(MPART_ENABLE_GPU) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, LinearizedBasis, Exp, AdaptiveClenshawCurtis, mpart::DeviceSpace) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, LinearizedBasis, SoftPlus, AdaptiveClenshawCurtis, mpart::DeviceSpace) +REGISTER_HOMOGENEOUS_MONO_COMP(LinearizedBasis, Exp, AdaptiveClenshawCurtis, mpart::DeviceSpace, false) +REGISTER_HOMOGENEOUS_MONO_COMP(LinearizedBasis, SoftPlus, AdaptiveClenshawCurtis, mpart::DeviceSpace, false) #endif CEREAL_REGISTER_DYNAMIC_INIT(mpartInitMapFactory10) #endif diff --git a/src/MapFactoryImpl11.cpp b/src/MapFactoryImpl11.cpp index c4e0299d..39c6d235 100644 --- a/src/MapFactoryImpl11.cpp +++ b/src/MapFactoryImpl11.cpp @@ -22,7 +22,7 @@ std::shared_ptr> CreateComponentImpl_LinPhys_CC( MultivariateExpansionWorker expansion(mset, basis1d); std::shared_ptr> output; - output = std::make_shared>(expansion, quad, opts.contDeriv, opts.nugget); + output = std::make_shared>(expansion, quad, opts.contDeriv, opts.nugget); Kokkos::View coeffs = Kokkos::View("Component Coefficients", mset.Size()); output->SetCoeffs(coeffs); @@ -30,19 +30,19 @@ std::shared_ptr> CreateComponentImpl_LinPhys_CC( return output; } -static auto reg_host_linphys_cc_exp = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::PhysicistHermite, true, PosFuncTypes::Exp, QuadTypes::ClenshawCurtis), CreateComponentImpl_LinPhys_CC)); -static auto reg_host_linphys_cc_splus = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::PhysicistHermite, true, PosFuncTypes::SoftPlus, QuadTypes::ClenshawCurtis), CreateComponentImpl_LinPhys_CC)); +static auto reg_host_linphys_cc_exp = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::PhysicistHermite, true, PosFuncTypes::Exp, QuadTypes::ClenshawCurtis, false), CreateComponentImpl_LinPhys_CC)); +static auto reg_host_linphys_cc_splus = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::PhysicistHermite, true, PosFuncTypes::SoftPlus, QuadTypes::ClenshawCurtis, false), CreateComponentImpl_LinPhys_CC)); #if defined(MPART_ENABLE_GPU) - static auto reg_device_linphys_cc_exp = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::PhysicistHermite, true, PosFuncTypes::Exp, QuadTypes::ClenshawCurtis), CreateComponentImpl_LinPhys_CC)); - static auto reg_device_linphys_cc_splus = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::PhysicistHermite, true, PosFuncTypes::SoftPlus, QuadTypes::ClenshawCurtis), CreateComponentImpl_LinPhys_CC)); + static auto reg_device_linphys_cc_exp = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::PhysicistHermite, true, PosFuncTypes::Exp, QuadTypes::ClenshawCurtis, false), CreateComponentImpl_LinPhys_CC)); + static auto reg_device_linphys_cc_splus = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::PhysicistHermite, true, PosFuncTypes::SoftPlus, QuadTypes::ClenshawCurtis, false), CreateComponentImpl_LinPhys_CC)); #endif #if defined(MPART_HAS_CEREAL) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, LinearizedBasis, Exp, ClenshawCurtisQuadrature, Kokkos::HostSpace) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, LinearizedBasis, SoftPlus, ClenshawCurtisQuadrature, Kokkos::HostSpace) +REGISTER_HOMOGENEOUS_MONO_COMP(LinearizedBasis, Exp, ClenshawCurtisQuadrature, Kokkos::HostSpace, false) +REGISTER_HOMOGENEOUS_MONO_COMP(LinearizedBasis, SoftPlus, ClenshawCurtisQuadrature, Kokkos::HostSpace, false) #if defined(MPART_ENABLE_GPU) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, LinearizedBasis, Exp, ClenshawCurtisQuadrature, mpart::DeviceSpace) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, LinearizedBasis, SoftPlus, ClenshawCurtisQuadrature, mpart::DeviceSpace) +REGISTER_HOMOGENEOUS_MONO_COMP(LinearizedBasis, Exp, ClenshawCurtisQuadrature, mpart::DeviceSpace, false) +REGISTER_HOMOGENEOUS_MONO_COMP(LinearizedBasis, SoftPlus, ClenshawCurtisQuadrature, mpart::DeviceSpace, false) #endif CEREAL_REGISTER_DYNAMIC_INIT(mpartInitMapFactory11) #endif diff --git a/src/MapFactoryImpl12.cpp b/src/MapFactoryImpl12.cpp index 8723ce92..dfc0f036 100644 --- a/src/MapFactoryImpl12.cpp +++ b/src/MapFactoryImpl12.cpp @@ -21,7 +21,7 @@ std::shared_ptr> CreateComponentImpl_LinPhys_AS( MultivariateExpansionWorker expansion(mset, basis1d); std::shared_ptr> output; - output = std::make_shared>(expansion, quad, opts.contDeriv, opts.nugget); + output = std::make_shared>(expansion, quad, opts.contDeriv, opts.nugget); Kokkos::View coeffs = Kokkos::View("Component Coefficients", mset.Size()); output->SetCoeffs(coeffs); @@ -29,19 +29,19 @@ std::shared_ptr> CreateComponentImpl_LinPhys_AS( return output; } -static auto reg_host_linphys_as_exp = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::PhysicistHermite, true, PosFuncTypes::Exp, QuadTypes::AdaptiveSimpson), CreateComponentImpl_LinPhys_AS)); -static auto reg_host_linphys_as_splus = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::PhysicistHermite, true, PosFuncTypes::SoftPlus, QuadTypes::AdaptiveSimpson), CreateComponentImpl_LinPhys_AS)); +static auto reg_host_linphys_as_exp = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::PhysicistHermite, true, PosFuncTypes::Exp, QuadTypes::AdaptiveSimpson, false), CreateComponentImpl_LinPhys_AS)); +static auto reg_host_linphys_as_splus = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::PhysicistHermite, true, PosFuncTypes::SoftPlus, QuadTypes::AdaptiveSimpson, false), CreateComponentImpl_LinPhys_AS)); #if defined(MPART_ENABLE_GPU) - static auto reg_device_linphys_as_exp = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::PhysicistHermite, true, PosFuncTypes::Exp, QuadTypes::AdaptiveSimpson), CreateComponentImpl_LinPhys_AS)); - static auto reg_device_linphys_as_splus = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::PhysicistHermite, true, PosFuncTypes::SoftPlus, QuadTypes::AdaptiveSimpson), CreateComponentImpl_LinPhys_AS)); + static auto reg_device_linphys_as_exp = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::PhysicistHermite, true, PosFuncTypes::Exp, QuadTypes::AdaptiveSimpson, false), CreateComponentImpl_LinPhys_AS)); + static auto reg_device_linphys_as_splus = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::PhysicistHermite, true, PosFuncTypes::SoftPlus, QuadTypes::AdaptiveSimpson, false), CreateComponentImpl_LinPhys_AS)); #endif #if defined(MPART_HAS_CEREAL) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, LinearizedBasis, Exp, AdaptiveSimpson, Kokkos::HostSpace) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, LinearizedBasis, SoftPlus, AdaptiveSimpson, Kokkos::HostSpace) +REGISTER_HOMOGENEOUS_MONO_COMP(LinearizedBasis, Exp, AdaptiveSimpson, Kokkos::HostSpace, false) +REGISTER_HOMOGENEOUS_MONO_COMP(LinearizedBasis, SoftPlus, AdaptiveSimpson, Kokkos::HostSpace, false) #if defined(MPART_ENABLE_GPU) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, LinearizedBasis, Exp, AdaptiveSimpson, mpart::DeviceSpace) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, LinearizedBasis, SoftPlus, AdaptiveSimpson, mpart::DeviceSpace) +REGISTER_HOMOGENEOUS_MONO_COMP(LinearizedBasis, Exp, AdaptiveSimpson, mpart::DeviceSpace, false) +REGISTER_HOMOGENEOUS_MONO_COMP(LinearizedBasis, SoftPlus, AdaptiveSimpson, mpart::DeviceSpace, false) #endif CEREAL_REGISTER_DYNAMIC_INIT(mpartInitMapFactory12) #endif diff --git a/src/MapFactoryImpl13.cpp b/src/MapFactoryImpl13.cpp index 757d9fb4..b1899974 100644 --- a/src/MapFactoryImpl13.cpp +++ b/src/MapFactoryImpl13.cpp @@ -23,7 +23,7 @@ std::shared_ptr> CreateComponentImpl_LinProb_ACC MultivariateExpansionWorker expansion(mset, basis1d); std::shared_ptr> output; - output = std::make_shared>(expansion, quad, opts.contDeriv, opts.nugget); + output = std::make_shared>(expansion, quad, opts.contDeriv, opts.nugget); Kokkos::View coeffs = Kokkos::View("Component Coefficients", mset.Size()); output->SetCoeffs(coeffs); @@ -31,19 +31,19 @@ std::shared_ptr> CreateComponentImpl_LinProb_ACC return output; } -static auto reg_host_linprob_acc_exp = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::ProbabilistHermite, true, PosFuncTypes::Exp, QuadTypes::AdaptiveClenshawCurtis), CreateComponentImpl_LinProb_ACC)); -static auto reg_host_linprob_acc_splus = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::ProbabilistHermite, true, PosFuncTypes::SoftPlus, QuadTypes::AdaptiveClenshawCurtis), CreateComponentImpl_LinProb_ACC)); +static auto reg_host_linprob_acc_exp = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::ProbabilistHermite, true, PosFuncTypes::Exp, QuadTypes::AdaptiveClenshawCurtis, false), CreateComponentImpl_LinProb_ACC)); +static auto reg_host_linprob_acc_splus = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::ProbabilistHermite, true, PosFuncTypes::SoftPlus, QuadTypes::AdaptiveClenshawCurtis, false), CreateComponentImpl_LinProb_ACC)); #if defined(MPART_ENABLE_GPU) - static auto reg_device_linprob_acc_exp = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::ProbabilistHermite, true, PosFuncTypes::Exp, QuadTypes::AdaptiveClenshawCurtis), CreateComponentImpl_LinProb_ACC)); - static auto reg_device_linprob_acc_splus = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::ProbabilistHermite, true, PosFuncTypes::SoftPlus, QuadTypes::AdaptiveClenshawCurtis), CreateComponentImpl_LinProb_ACC)); + static auto reg_device_linprob_acc_exp = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::ProbabilistHermite, true, PosFuncTypes::Exp, QuadTypes::AdaptiveClenshawCurtis, false), CreateComponentImpl_LinProb_ACC)); + static auto reg_device_linprob_acc_splus = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::ProbabilistHermite, true, PosFuncTypes::SoftPlus, QuadTypes::AdaptiveClenshawCurtis, false), CreateComponentImpl_LinProb_ACC)); #endif #if defined(MPART_HAS_CEREAL) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, LinearizedBasis, Exp, AdaptiveClenshawCurtis, Kokkos::HostSpace) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, LinearizedBasis, SoftPlus, AdaptiveClenshawCurtis, Kokkos::HostSpace) +REGISTER_HOMOGENEOUS_MONO_COMP(LinearizedBasis, Exp, AdaptiveClenshawCurtis, Kokkos::HostSpace, false) +REGISTER_HOMOGENEOUS_MONO_COMP(LinearizedBasis, SoftPlus, AdaptiveClenshawCurtis, Kokkos::HostSpace, false) #if defined(MPART_ENABLE_GPU) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, LinearizedBasis, Exp, AdaptiveClenshawCurtis, mpart::DeviceSpace) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, LinearizedBasis, SoftPlus, AdaptiveClenshawCurtis, mpart::DeviceSpace) +REGISTER_HOMOGENEOUS_MONO_COMP(LinearizedBasis, Exp, AdaptiveClenshawCurtis, mpart::DeviceSpace, false) +REGISTER_HOMOGENEOUS_MONO_COMP(LinearizedBasis, SoftPlus, AdaptiveClenshawCurtis, mpart::DeviceSpace, false) #endif CEREAL_REGISTER_DYNAMIC_INIT(mpartInitMapFactory13) #endif diff --git a/src/MapFactoryImpl14.cpp b/src/MapFactoryImpl14.cpp index 794b70b9..96c79f18 100644 --- a/src/MapFactoryImpl14.cpp +++ b/src/MapFactoryImpl14.cpp @@ -21,7 +21,7 @@ std::shared_ptr> CreateComponentImpl_LinProb_CC( MultivariateExpansionWorker expansion(mset, basis1d); std::shared_ptr> output; - output = std::make_shared>(expansion, quad, opts.contDeriv, opts.nugget); + output = std::make_shared>(expansion, quad, opts.contDeriv, opts.nugget); Kokkos::View coeffs = Kokkos::View("Component Coefficients", mset.Size()); output->SetCoeffs(coeffs); @@ -29,19 +29,19 @@ std::shared_ptr> CreateComponentImpl_LinProb_CC( return output; } -static auto reg_host_linprob_cc_exp = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::ProbabilistHermite, true, PosFuncTypes::Exp, QuadTypes::ClenshawCurtis), CreateComponentImpl_LinProb_CC)); -static auto reg_host_linprob_cc_splus = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::ProbabilistHermite, true, PosFuncTypes::SoftPlus, QuadTypes::ClenshawCurtis), CreateComponentImpl_LinProb_CC)); +static auto reg_host_linprob_cc_exp = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::ProbabilistHermite, true, PosFuncTypes::Exp, QuadTypes::ClenshawCurtis, false), CreateComponentImpl_LinProb_CC)); +static auto reg_host_linprob_cc_splus = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::ProbabilistHermite, true, PosFuncTypes::SoftPlus, QuadTypes::ClenshawCurtis, false), CreateComponentImpl_LinProb_CC)); #if defined(MPART_ENABLE_GPU) - static auto reg_device_linprob_cc_exp = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::ProbabilistHermite, true, PosFuncTypes::Exp, QuadTypes::ClenshawCurtis), CreateComponentImpl_LinProb_CC)); - static auto reg_device_linprob_cc_splus = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::ProbabilistHermite, true, PosFuncTypes::SoftPlus, QuadTypes::ClenshawCurtis), CreateComponentImpl_LinProb_CC)); + static auto reg_device_linprob_cc_exp = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::ProbabilistHermite, true, PosFuncTypes::Exp, QuadTypes::ClenshawCurtis, false), CreateComponentImpl_LinProb_CC)); + static auto reg_device_linprob_cc_splus = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::ProbabilistHermite, true, PosFuncTypes::SoftPlus, QuadTypes::ClenshawCurtis, false), CreateComponentImpl_LinProb_CC)); #endif #if defined(MPART_HAS_CEREAL) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, LinearizedBasis, Exp, ClenshawCurtisQuadrature, Kokkos::HostSpace) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, LinearizedBasis, SoftPlus, ClenshawCurtisQuadrature, Kokkos::HostSpace) +REGISTER_HOMOGENEOUS_MONO_COMP(LinearizedBasis, Exp, ClenshawCurtisQuadrature, Kokkos::HostSpace, false) +REGISTER_HOMOGENEOUS_MONO_COMP(LinearizedBasis, SoftPlus, ClenshawCurtisQuadrature, Kokkos::HostSpace, false) #if defined(MPART_ENABLE_GPU) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, LinearizedBasis, Exp, ClenshawCurtisQuadrature, mpart::DeviceSpace) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, LinearizedBasis, SoftPlus, ClenshawCurtisQuadrature, mpart::DeviceSpace) +REGISTER_HOMOGENEOUS_MONO_COMP(LinearizedBasis, Exp, ClenshawCurtisQuadrature, mpart::DeviceSpace, false) +REGISTER_HOMOGENEOUS_MONO_COMP(LinearizedBasis, SoftPlus, ClenshawCurtisQuadrature, mpart::DeviceSpace, false) #endif CEREAL_REGISTER_DYNAMIC_INIT(mpartInitMapFactory14) #endif diff --git a/src/MapFactoryImpl15.cpp b/src/MapFactoryImpl15.cpp index f5ae8513..749113b0 100644 --- a/src/MapFactoryImpl15.cpp +++ b/src/MapFactoryImpl15.cpp @@ -21,7 +21,7 @@ std::shared_ptr> CreateComponentImpl_LinProb_AS( MultivariateExpansionWorker expansion(mset, basis1d); std::shared_ptr> output; - output = std::make_shared>(expansion, quad, opts.contDeriv, opts.nugget); + output = std::make_shared>(expansion, quad, opts.contDeriv, opts.nugget); Kokkos::View coeffs = Kokkos::View("Component Coefficients", mset.Size()); output->SetCoeffs(coeffs); @@ -29,19 +29,19 @@ std::shared_ptr> CreateComponentImpl_LinProb_AS( return output; } -static auto reg_host_linprob_as_exp = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::ProbabilistHermite, true, PosFuncTypes::Exp, QuadTypes::AdaptiveSimpson), CreateComponentImpl_LinProb_AS)); -static auto reg_host_linprob_as_splus = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::ProbabilistHermite, true, PosFuncTypes::SoftPlus, QuadTypes::AdaptiveSimpson), CreateComponentImpl_LinProb_AS)); +static auto reg_host_linprob_as_exp = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::ProbabilistHermite, true, PosFuncTypes::Exp, QuadTypes::AdaptiveSimpson, false), CreateComponentImpl_LinProb_AS)); +static auto reg_host_linprob_as_splus = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::ProbabilistHermite, true, PosFuncTypes::SoftPlus, QuadTypes::AdaptiveSimpson, false), CreateComponentImpl_LinProb_AS)); #if defined(MPART_ENABLE_GPU) - static auto reg_device_linprob_as_exp = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::ProbabilistHermite, true, PosFuncTypes::Exp, QuadTypes::AdaptiveSimpson), CreateComponentImpl_LinProb_AS)); - static auto reg_device_linprob_as_splus = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::ProbabilistHermite, true, PosFuncTypes::SoftPlus, QuadTypes::AdaptiveSimpson), CreateComponentImpl_LinProb_AS)); + static auto reg_device_linprob_as_exp = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::ProbabilistHermite, true, PosFuncTypes::Exp, QuadTypes::AdaptiveSimpson, false), CreateComponentImpl_LinProb_AS)); + static auto reg_device_linprob_as_splus = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::ProbabilistHermite, true, PosFuncTypes::SoftPlus, QuadTypes::AdaptiveSimpson, false), CreateComponentImpl_LinProb_AS)); #endif #if defined(MPART_HAS_CEREAL) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, LinearizedBasis, Exp, AdaptiveSimpson, Kokkos::HostSpace) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, LinearizedBasis, SoftPlus, AdaptiveSimpson, Kokkos::HostSpace) +REGISTER_HOMOGENEOUS_MONO_COMP(LinearizedBasis, Exp, AdaptiveSimpson, Kokkos::HostSpace, false) +REGISTER_HOMOGENEOUS_MONO_COMP(LinearizedBasis, SoftPlus, AdaptiveSimpson, Kokkos::HostSpace, false) #if defined(MPART_ENABLE_GPU) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, LinearizedBasis, Exp, AdaptiveSimpson, mpart::DeviceSpace) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, LinearizedBasis, SoftPlus, AdaptiveSimpson, mpart::DeviceSpace) +REGISTER_HOMOGENEOUS_MONO_COMP(LinearizedBasis, Exp, AdaptiveSimpson, mpart::DeviceSpace, false) +REGISTER_HOMOGENEOUS_MONO_COMP(LinearizedBasis, SoftPlus, AdaptiveSimpson, mpart::DeviceSpace, false) #endif CEREAL_REGISTER_DYNAMIC_INIT(mpartInitMapFactory15) #endif diff --git a/src/MapFactoryImpl16.cpp b/src/MapFactoryImpl16.cpp index 40f9c109..c582f684 100644 --- a/src/MapFactoryImpl16.cpp +++ b/src/MapFactoryImpl16.cpp @@ -21,7 +21,7 @@ std::shared_ptr> CreateComponentImpl_LinHF_AS(Fi MultivariateExpansionWorker expansion(mset, basis1d); std::shared_ptr> output; - output = std::make_shared>(expansion, quad, opts.contDeriv, opts.nugget); + output = std::make_shared>(expansion, quad, opts.contDeriv, opts.nugget); Kokkos::View coeffs = Kokkos::View("Component Coefficients", mset.Size()); output->SetCoeffs(coeffs); @@ -29,19 +29,19 @@ std::shared_ptr> CreateComponentImpl_LinHF_AS(Fi return output; } -static auto reg_host_linhf_as_exp = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::HermiteFunctions, true, PosFuncTypes::Exp, QuadTypes::AdaptiveSimpson), CreateComponentImpl_LinHF_AS)); -static auto reg_host_linhf_as_splus = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::HermiteFunctions, true, PosFuncTypes::SoftPlus, QuadTypes::AdaptiveSimpson), CreateComponentImpl_LinHF_AS)); +static auto reg_host_linhf_as_exp = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::HermiteFunctions, true, PosFuncTypes::Exp, QuadTypes::AdaptiveSimpson, false), CreateComponentImpl_LinHF_AS)); +static auto reg_host_linhf_as_splus = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::HermiteFunctions, true, PosFuncTypes::SoftPlus, QuadTypes::AdaptiveSimpson, false), CreateComponentImpl_LinHF_AS)); #if defined(MPART_ENABLE_GPU) - static auto reg_device_linhf_as_exp = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::HermiteFunctions, true, PosFuncTypes::Exp, QuadTypes::AdaptiveSimpson), CreateComponentImpl_LinHF_AS)); - static auto reg_device_linhf_as_splus = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::HermiteFunctions, true, PosFuncTypes::SoftPlus, QuadTypes::AdaptiveSimpson), CreateComponentImpl_LinHF_AS)); + static auto reg_device_linhf_as_exp = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::HermiteFunctions, true, PosFuncTypes::Exp, QuadTypes::AdaptiveSimpson, false), CreateComponentImpl_LinHF_AS)); + static auto reg_device_linhf_as_splus = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::HermiteFunctions, true, PosFuncTypes::SoftPlus, QuadTypes::AdaptiveSimpson, false), CreateComponentImpl_LinHF_AS)); #endif #if defined(MPART_HAS_CEREAL) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, LinearizedBasis, Exp, AdaptiveSimpson, Kokkos::HostSpace) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, LinearizedBasis, SoftPlus, AdaptiveSimpson, Kokkos::HostSpace) +REGISTER_HOMOGENEOUS_MONO_COMP(LinearizedBasis, Exp, AdaptiveSimpson, Kokkos::HostSpace, false) +REGISTER_HOMOGENEOUS_MONO_COMP(LinearizedBasis, SoftPlus, AdaptiveSimpson, Kokkos::HostSpace, false) #if defined(MPART_ENABLE_GPU) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, LinearizedBasis, Exp, AdaptiveSimpson, mpart::DeviceSpace) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, LinearizedBasis, SoftPlus, AdaptiveSimpson, mpart::DeviceSpace) +REGISTER_HOMOGENEOUS_MONO_COMP(LinearizedBasis, Exp, AdaptiveSimpson, mpart::DeviceSpace, false) +REGISTER_HOMOGENEOUS_MONO_COMP(LinearizedBasis, SoftPlus, AdaptiveSimpson, mpart::DeviceSpace, false) #endif CEREAL_REGISTER_DYNAMIC_INIT(mpartInitMapFactory16) #endif diff --git a/src/MapFactoryImpl17.cpp b/src/MapFactoryImpl17.cpp index f14fae97..3c80fb03 100644 --- a/src/MapFactoryImpl17.cpp +++ b/src/MapFactoryImpl17.cpp @@ -21,7 +21,7 @@ std::shared_ptr> CreateComponentImpl_LinHF_CC(Fi MultivariateExpansionWorker expansion(mset, basis1d); std::shared_ptr> output; - output = std::make_shared>(expansion, quad, opts.contDeriv, opts.nugget); + output = std::make_shared>(expansion, quad, opts.contDeriv, opts.nugget); Kokkos::View coeffs = Kokkos::View("Component Coefficients", mset.Size()); output->SetCoeffs(coeffs); @@ -29,19 +29,19 @@ std::shared_ptr> CreateComponentImpl_LinHF_CC(Fi return output; } -static auto reg_host_linhf_cc_exp = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::HermiteFunctions, true, PosFuncTypes::Exp, QuadTypes::ClenshawCurtis), CreateComponentImpl_LinHF_CC)); -static auto reg_host_linhf_cc_splus = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::HermiteFunctions, true, PosFuncTypes::SoftPlus, QuadTypes::ClenshawCurtis), CreateComponentImpl_LinHF_CC)); +static auto reg_host_linhf_cc_exp = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::HermiteFunctions, true, PosFuncTypes::Exp, QuadTypes::ClenshawCurtis, false), CreateComponentImpl_LinHF_CC)); +static auto reg_host_linhf_cc_splus = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::HermiteFunctions, true, PosFuncTypes::SoftPlus, QuadTypes::ClenshawCurtis, false), CreateComponentImpl_LinHF_CC)); #if defined(MPART_ENABLE_GPU) - static auto reg_device_linhf_cc_exp = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::HermiteFunctions, true, PosFuncTypes::Exp, QuadTypes::ClenshawCurtis), CreateComponentImpl_LinHF_CC)); - static auto reg_device_linhf_cc_splus = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::HermiteFunctions, true, PosFuncTypes::SoftPlus, QuadTypes::ClenshawCurtis), CreateComponentImpl_LinHF_CC)); + static auto reg_device_linhf_cc_exp = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::HermiteFunctions, true, PosFuncTypes::Exp, QuadTypes::ClenshawCurtis, false), CreateComponentImpl_LinHF_CC)); + static auto reg_device_linhf_cc_splus = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::HermiteFunctions, true, PosFuncTypes::SoftPlus, QuadTypes::ClenshawCurtis, false), CreateComponentImpl_LinHF_CC)); #endif #if defined(MPART_HAS_CEREAL) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, LinearizedBasis, Exp, ClenshawCurtisQuadrature, Kokkos::HostSpace) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, LinearizedBasis, SoftPlus, ClenshawCurtisQuadrature, Kokkos::HostSpace) +REGISTER_HOMOGENEOUS_MONO_COMP(LinearizedBasis, Exp, ClenshawCurtisQuadrature, Kokkos::HostSpace, false) +REGISTER_HOMOGENEOUS_MONO_COMP(LinearizedBasis, SoftPlus, ClenshawCurtisQuadrature, Kokkos::HostSpace, false) #if defined(MPART_ENABLE_GPU) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, LinearizedBasis, Exp, ClenshawCurtisQuadrature, mpart::DeviceSpace) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, LinearizedBasis, SoftPlus, ClenshawCurtisQuadrature, mpart::DeviceSpace) +REGISTER_HOMOGENEOUS_MONO_COMP(LinearizedBasis, Exp, ClenshawCurtisQuadrature, mpart::DeviceSpace, false) +REGISTER_HOMOGENEOUS_MONO_COMP(LinearizedBasis, SoftPlus, ClenshawCurtisQuadrature, mpart::DeviceSpace, false) #endif CEREAL_REGISTER_DYNAMIC_INIT(mpartInitMapFactory17) #endif diff --git a/src/MapFactoryImpl18.cpp b/src/MapFactoryImpl18.cpp index f135404a..1c3d0616 100644 --- a/src/MapFactoryImpl18.cpp +++ b/src/MapFactoryImpl18.cpp @@ -22,7 +22,7 @@ std::shared_ptr> CreateComponentImpl_LinHF_ACC(F MultivariateExpansionWorker expansion(mset, basis1d); std::shared_ptr> output; - output = std::make_shared>(expansion, quad, opts.contDeriv, opts.nugget); + output = std::make_shared>(expansion, quad, opts.contDeriv, opts.nugget); Kokkos::View coeffs = Kokkos::View("Component Coefficients", mset.Size()); output->SetCoeffs(coeffs); @@ -30,19 +30,19 @@ std::shared_ptr> CreateComponentImpl_LinHF_ACC(F return output; } -static auto reg_host_linhf_acc_exp = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::HermiteFunctions, true, PosFuncTypes::Exp, QuadTypes::AdaptiveClenshawCurtis), CreateComponentImpl_LinHF_ACC)); -static auto reg_host_linhf_acc_splus = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::HermiteFunctions, true, PosFuncTypes::SoftPlus, QuadTypes::AdaptiveClenshawCurtis), CreateComponentImpl_LinHF_ACC)); +static auto reg_host_linhf_acc_exp = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::HermiteFunctions, true, PosFuncTypes::Exp, QuadTypes::AdaptiveClenshawCurtis, false), CreateComponentImpl_LinHF_ACC)); +static auto reg_host_linhf_acc_splus = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::HermiteFunctions, true, PosFuncTypes::SoftPlus, QuadTypes::AdaptiveClenshawCurtis, false), CreateComponentImpl_LinHF_ACC)); #if defined(MPART_ENABLE_GPU) - static auto reg_device_linhf_acc_exp = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::HermiteFunctions, true, PosFuncTypes::Exp, QuadTypes::AdaptiveClenshawCurtis), CreateComponentImpl_LinHF_ACC)); - static auto reg_device_linhf_acc_splus = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::HermiteFunctions, true, PosFuncTypes::SoftPlus, QuadTypes::AdaptiveClenshawCurtis), CreateComponentImpl_LinHF_ACC)); + static auto reg_device_linhf_acc_exp = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::HermiteFunctions, true, PosFuncTypes::Exp, QuadTypes::AdaptiveClenshawCurtis, false), CreateComponentImpl_LinHF_ACC)); + static auto reg_device_linhf_acc_splus = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::HermiteFunctions, true, PosFuncTypes::SoftPlus, QuadTypes::AdaptiveClenshawCurtis, false), CreateComponentImpl_LinHF_ACC)); #endif #if defined(MPART_HAS_CEREAL) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, LinearizedBasis, Exp, AdaptiveClenshawCurtis, Kokkos::HostSpace) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, LinearizedBasis, SoftPlus, AdaptiveClenshawCurtis, Kokkos::HostSpace) +REGISTER_HOMOGENEOUS_MONO_COMP(LinearizedBasis, Exp, AdaptiveClenshawCurtis, Kokkos::HostSpace, false) +REGISTER_HOMOGENEOUS_MONO_COMP(LinearizedBasis, SoftPlus, AdaptiveClenshawCurtis, Kokkos::HostSpace, false) #if defined(MPART_ENABLE_GPU) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, LinearizedBasis, Exp, AdaptiveClenshawCurtis, mpart::DeviceSpace) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, LinearizedBasis, SoftPlus, AdaptiveClenshawCurtis, mpart::DeviceSpace) +REGISTER_HOMOGENEOUS_MONO_COMP(LinearizedBasis, Exp, AdaptiveClenshawCurtis, mpart::DeviceSpace, false) +REGISTER_HOMOGENEOUS_MONO_COMP(LinearizedBasis, SoftPlus, AdaptiveClenshawCurtis, mpart::DeviceSpace, false) #endif CEREAL_REGISTER_DYNAMIC_INIT(mpartInitMapFactory18) #endif diff --git a/src/MapFactoryImpl19.cpp b/src/MapFactoryImpl19.cpp new file mode 100644 index 00000000..70273c47 --- /dev/null +++ b/src/MapFactoryImpl19.cpp @@ -0,0 +1,47 @@ +#include "MParT/MapFactory.h" + +#include "MParT/MonotoneComponent.h" +#include "MParT/TriangularMap.h" +#include "MParT/Quadrature.h" + +#include "MParT/UnivariateBases.h" +#include "MParT/OrthogonalPolynomial.h" +#include "MParT/MultivariateExpansionWorker.h" +#include "MParT/PositiveBijectors.h" + +using namespace mpart; + +template +std::shared_ptr> CreateComponentImpl_LEG_ACC(FixedMultiIndexSet const& mset, MapOptions opts) +{ + BasisEvaluator basis1d(mset.Length()); + unsigned int level = std::log2(opts.quadPts-2); + AdaptiveClenshawCurtis quad(level, opts.quadMaxSub, 1, nullptr, opts.quadAbsTol, opts.quadRelTol, QuadError::First, opts.quadMinSub); + + MultivariateExpansionWorker expansion(mset, basis1d); + std::shared_ptr> output; + + output = std::make_shared>(expansion, quad, opts.contDeriv, opts.nugget); + + Kokkos::View coeffs = Kokkos::View("Component Coefficients", mset.Size()); + output->SetCoeffs(coeffs); + + return output; +} + +static auto reg_host_leg_acc_exp_compact = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::Legendre, false, PosFuncTypes::Exp, QuadTypes::AdaptiveClenshawCurtis, true), CreateComponentImpl_LEG_ACC)); +static auto reg_host_leg_acc_splus_compact = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::Legendre, false, PosFuncTypes::SoftPlus, QuadTypes::AdaptiveClenshawCurtis, true), CreateComponentImpl_LEG_ACC)); +#if defined(MPART_ENABLE_GPU) + static auto reg_device_leg_acc_exp_compact = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::Legendre, false, PosFuncTypes::Exp, QuadTypes::AdaptiveClenshawCurtis, true), CreateComponentImpl_LEG_ACC)); + static auto reg_device_leg_acc_splus_compact = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::Legendre, false, PosFuncTypes::SoftPlus, QuadTypes::AdaptiveClenshawCurtis, true), CreateComponentImpl_LEG_ACC)); +#endif + +#if defined(MPART_HAS_CEREAL) +REGISTER_HOMOGENEOUS_MONO_COMP(ShiftedLegendre, Exp, AdaptiveClenshawCurtis, Kokkos::HostSpace, true) +REGISTER_HOMOGENEOUS_MONO_COMP(ShiftedLegendre, SoftPlus, AdaptiveClenshawCurtis, Kokkos::HostSpace, true) +#if defined(MPART_ENABLE_GPU) +REGISTER_HOMOGENEOUS_MONO_COMP(ShiftedLegendre, Exp, AdaptiveClenshawCurtis, mpart::DeviceSpace, true) +REGISTER_HOMOGENEOUS_MONO_COMP(ShiftedLegendre, SoftPlus, AdaptiveClenshawCurtis, mpart::DeviceSpace, true) +#endif +CEREAL_REGISTER_DYNAMIC_INIT(mpartInitMapFactory19) +#endif \ No newline at end of file diff --git a/src/MapFactoryImpl2.cpp b/src/MapFactoryImpl2.cpp index 67ebc2bc..c297f7d4 100644 --- a/src/MapFactoryImpl2.cpp +++ b/src/MapFactoryImpl2.cpp @@ -11,7 +11,7 @@ using namespace mpart; -template +template std::shared_ptr> CreateComponentImpl_Phys_CC(FixedMultiIndexSet const& mset, MapOptions opts) { BasisEvaluator basis1d(opts.basisNorm); @@ -20,26 +20,37 @@ std::shared_ptr> CreateComponentImpl_Phys_CC(Fix MultivariateExpansionWorker expansion(mset, basis1d); std::shared_ptr> output; - output = std::make_shared>(expansion, quad, opts.contDeriv, opts.nugget); + output = std::make_shared>(expansion, quad, opts.contDeriv, opts.nugget); Kokkos::View coeffs = Kokkos::View("Component Coefficients", mset.Size()); output->SetCoeffs(coeffs); return output; } -static auto reg_host_phys_cc_exp = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::PhysicistHermite, false, PosFuncTypes::Exp, QuadTypes::ClenshawCurtis), CreateComponentImpl_Phys_CC)); -static auto reg_host_phys_cc_splus = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::PhysicistHermite, false, PosFuncTypes::SoftPlus, QuadTypes::ClenshawCurtis), CreateComponentImpl_Phys_CC)); +static auto reg_host_phys_cc_exp = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::PhysicistHermite, false, PosFuncTypes::Exp, QuadTypes::ClenshawCurtis, false), CreateComponentImpl_Phys_CC)); +static auto reg_host_phys_cc_splus = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::PhysicistHermite, false, PosFuncTypes::SoftPlus, QuadTypes::ClenshawCurtis, false), CreateComponentImpl_Phys_CC)); #if defined(MPART_ENABLE_GPU) - static auto reg_device_phys_cc_exp = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::PhysicistHermite, false, PosFuncTypes::Exp, QuadTypes::ClenshawCurtis), CreateComponentImpl_Phys_CC)); - static auto reg_device_phys_cc_splus = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::PhysicistHermite, false, PosFuncTypes::SoftPlus, QuadTypes::ClenshawCurtis), CreateComponentImpl_Phys_CC)); + static auto reg_device_phys_cc_exp = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::PhysicistHermite, false, PosFuncTypes::Exp, QuadTypes::ClenshawCurtis, false), CreateComponentImpl_Phys_CC)); + static auto reg_device_phys_cc_splus = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::PhysicistHermite, false, PosFuncTypes::SoftPlus, QuadTypes::ClenshawCurtis, false), CreateComponentImpl_Phys_CC)); +#endif + +static auto reg_host_phys_cc_exp_compact = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::PhysicistHermite, false, PosFuncTypes::Exp, QuadTypes::ClenshawCurtis, true), CreateComponentImpl_Phys_CC)); +static auto reg_host_phys_cc_splus_compact = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::PhysicistHermite, false, PosFuncTypes::SoftPlus, QuadTypes::ClenshawCurtis, true), CreateComponentImpl_Phys_CC)); +#if defined(MPART_ENABLE_GPU) + static auto reg_device_phys_cc_exp_compact = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::PhysicistHermite, false, PosFuncTypes::Exp, QuadTypes::ClenshawCurtis, true), CreateComponentImpl_Phys_CC)); + static auto reg_device_phys_cc_splus_compact = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::PhysicistHermite, false, PosFuncTypes::SoftPlus, QuadTypes::ClenshawCurtis, true), CreateComponentImpl_Phys_CC)); #endif #if defined(MPART_HAS_CEREAL) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, PhysicistHermite, Exp, ClenshawCurtisQuadrature, Kokkos::HostSpace) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, PhysicistHermite, SoftPlus, ClenshawCurtisQuadrature, Kokkos::HostSpace) +REGISTER_HOMOGENEOUS_MONO_COMP(PhysicistHermite, Exp, ClenshawCurtisQuadrature, Kokkos::HostSpace, false) +REGISTER_HOMOGENEOUS_MONO_COMP(PhysicistHermite, SoftPlus, ClenshawCurtisQuadrature, Kokkos::HostSpace, false) +REGISTER_HOMOGENEOUS_MONO_COMP(PhysicistHermite, Exp, ClenshawCurtisQuadrature, Kokkos::HostSpace, true) +REGISTER_HOMOGENEOUS_MONO_COMP(PhysicistHermite, SoftPlus, ClenshawCurtisQuadrature, Kokkos::HostSpace, true) #if defined(MPART_ENABLE_GPU) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, PhysicistHermite, Exp, ClenshawCurtisQuadrature, mpart::DeviceSpace) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, PhysicistHermite, SoftPlus, ClenshawCurtisQuadrature, mpart::DeviceSpace) +REGISTER_HOMOGENEOUS_MONO_COMP(PhysicistHermite, Exp, ClenshawCurtisQuadrature, mpart::DeviceSpace, false) +REGISTER_HOMOGENEOUS_MONO_COMP(PhysicistHermite, SoftPlus, ClenshawCurtisQuadrature, mpart::DeviceSpace, false) +REGISTER_HOMOGENEOUS_MONO_COMP(PhysicistHermite, Exp, ClenshawCurtisQuadrature, mpart::DeviceSpace, true) +REGISTER_HOMOGENEOUS_MONO_COMP(PhysicistHermite, SoftPlus, ClenshawCurtisQuadrature, mpart::DeviceSpace, true) #endif CEREAL_REGISTER_DYNAMIC_INIT(mpartInitMapFactory2) #endif diff --git a/src/MapFactoryImpl3.cpp b/src/MapFactoryImpl3.cpp index b7b19289..12ccdcfe 100644 --- a/src/MapFactoryImpl3.cpp +++ b/src/MapFactoryImpl3.cpp @@ -10,7 +10,7 @@ using namespace mpart; -template +template std::shared_ptr> CreateComponentImpl_Phys_AS(FixedMultiIndexSet const& mset, MapOptions opts) { BasisEvaluator basis1d(opts.basisNorm); @@ -19,7 +19,7 @@ std::shared_ptr> CreateComponentImpl_Phys_AS(Fix MultivariateExpansionWorker expansion(mset, basis1d); std::shared_ptr> output; - output = std::make_shared>(expansion, quad, opts.contDeriv, opts.nugget); + output = std::make_shared>(expansion, quad, opts.contDeriv, opts.nugget); Kokkos::View coeffs = Kokkos::View("Component Coefficients", mset.Size()); output->SetCoeffs(coeffs); @@ -27,19 +27,30 @@ std::shared_ptr> CreateComponentImpl_Phys_AS(Fix return output; } -static auto reg_host_phys_as_exp = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::PhysicistHermite, false, PosFuncTypes::Exp, QuadTypes::AdaptiveSimpson), CreateComponentImpl_Phys_AS)); -static auto reg_host_phys_as_splus = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::PhysicistHermite, false, PosFuncTypes::SoftPlus, QuadTypes::AdaptiveSimpson), CreateComponentImpl_Phys_AS)); +static auto reg_host_phys_as_exp = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::PhysicistHermite, false, PosFuncTypes::Exp, QuadTypes::AdaptiveSimpson, false), CreateComponentImpl_Phys_AS)); +static auto reg_host_phys_as_splus = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::PhysicistHermite, false, PosFuncTypes::SoftPlus, QuadTypes::AdaptiveSimpson, false), CreateComponentImpl_Phys_AS)); #if defined(MPART_ENABLE_GPU) - static auto reg_device_phys_as_exp = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::PhysicistHermite, false, PosFuncTypes::Exp, QuadTypes::AdaptiveSimpson), CreateComponentImpl_Phys_AS)); - static auto reg_device_phys_as_splus = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::PhysicistHermite, false, PosFuncTypes::SoftPlus, QuadTypes::AdaptiveSimpson), CreateComponentImpl_Phys_AS)); + static auto reg_device_phys_as_exp = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::PhysicistHermite, false, PosFuncTypes::Exp, QuadTypes::AdaptiveSimpson, false), CreateComponentImpl_Phys_AS)); + static auto reg_device_phys_as_splus = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::PhysicistHermite, false, PosFuncTypes::SoftPlus, QuadTypes::AdaptiveSimpson, false), CreateComponentImpl_Phys_AS)); +#endif + +static auto reg_host_phys_as_exp_compact = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::PhysicistHermite, false, PosFuncTypes::Exp, QuadTypes::AdaptiveSimpson, true), CreateComponentImpl_Phys_AS)); +static auto reg_host_phys_as_splus_compact = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::PhysicistHermite, false, PosFuncTypes::SoftPlus, QuadTypes::AdaptiveSimpson, true), CreateComponentImpl_Phys_AS)); +#if defined(MPART_ENABLE_GPU) + static auto reg_device_phys_as_exp_compact = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::PhysicistHermite, false, PosFuncTypes::Exp, QuadTypes::AdaptiveSimpson, true), CreateComponentImpl_Phys_AS)); + static auto reg_device_phys_as_splus_compact = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::PhysicistHermite, false, PosFuncTypes::SoftPlus, QuadTypes::AdaptiveSimpson, true), CreateComponentImpl_Phys_AS)); #endif #if defined(MPART_HAS_CEREAL) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, PhysicistHermite, Exp, AdaptiveSimpson, Kokkos::HostSpace) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, PhysicistHermite, SoftPlus, AdaptiveSimpson, Kokkos::HostSpace) +REGISTER_HOMOGENEOUS_MONO_COMP(PhysicistHermite, Exp, AdaptiveSimpson, Kokkos::HostSpace, false) +REGISTER_HOMOGENEOUS_MONO_COMP(PhysicistHermite, SoftPlus, AdaptiveSimpson, Kokkos::HostSpace, false) +REGISTER_HOMOGENEOUS_MONO_COMP(PhysicistHermite, Exp, AdaptiveSimpson, Kokkos::HostSpace, true) +REGISTER_HOMOGENEOUS_MONO_COMP(PhysicistHermite, SoftPlus, AdaptiveSimpson, Kokkos::HostSpace, true) #if defined(MPART_ENABLE_GPU) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, PhysicistHermite, Exp, AdaptiveSimpson, mpart::DeviceSpace) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, PhysicistHermite, SoftPlus, AdaptiveSimpson, mpart::DeviceSpace) +REGISTER_HOMOGENEOUS_MONO_COMP(PhysicistHermite, Exp, AdaptiveSimpson, mpart::DeviceSpace, false) +REGISTER_HOMOGENEOUS_MONO_COMP(PhysicistHermite, SoftPlus, AdaptiveSimpson, mpart::DeviceSpace, false) +REGISTER_HOMOGENEOUS_MONO_COMP(PhysicistHermite, Exp, AdaptiveSimpson, mpart::DeviceSpace, true) +REGISTER_HOMOGENEOUS_MONO_COMP(PhysicistHermite, SoftPlus, AdaptiveSimpson, mpart::DeviceSpace, true) #endif CEREAL_REGISTER_DYNAMIC_INIT(mpartInitMapFactory3) #endif diff --git a/src/MapFactoryImpl4.cpp b/src/MapFactoryImpl4.cpp index e1f8edc7..b30238ef 100644 --- a/src/MapFactoryImpl4.cpp +++ b/src/MapFactoryImpl4.cpp @@ -10,7 +10,7 @@ using namespace mpart; -template +template std::shared_ptr> CreateComponentImpl_Prob_ACC(FixedMultiIndexSet const& mset, MapOptions opts) { BasisEvaluator basis1d(opts.basisNorm); @@ -21,7 +21,7 @@ std::shared_ptr> CreateComponentImpl_Prob_ACC(Fi MultivariateExpansionWorker expansion(mset, basis1d); std::shared_ptr> output; - output = std::make_shared>(expansion, quad, opts.contDeriv, opts.nugget); + output = std::make_shared>(expansion, quad, opts.contDeriv, opts.nugget); Kokkos::View coeffs = Kokkos::View("Component Coefficients", mset.Size()); output->SetCoeffs(coeffs); @@ -29,19 +29,30 @@ std::shared_ptr> CreateComponentImpl_Prob_ACC(Fi return output; } -static auto reg_host_prob_acc_exp = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::ProbabilistHermite, false, PosFuncTypes::Exp, QuadTypes::AdaptiveClenshawCurtis), CreateComponentImpl_Prob_ACC)); -static auto reg_host_prob_acc_splus = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::ProbabilistHermite, false, PosFuncTypes::SoftPlus, QuadTypes::AdaptiveClenshawCurtis), CreateComponentImpl_Prob_ACC)); +static auto reg_host_prob_acc_exp = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::ProbabilistHermite, false, PosFuncTypes::Exp, QuadTypes::AdaptiveClenshawCurtis, false), CreateComponentImpl_Prob_ACC)); +static auto reg_host_prob_acc_splus = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::ProbabilistHermite, false, PosFuncTypes::SoftPlus, QuadTypes::AdaptiveClenshawCurtis, false), CreateComponentImpl_Prob_ACC)); #if defined(MPART_ENABLE_GPU) - static auto reg_device_prob_acc_exp = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::ProbabilistHermite, false, PosFuncTypes::Exp, QuadTypes::AdaptiveClenshawCurtis), CreateComponentImpl_Prob_ACC)); - static auto reg_device_prob_acc_splus = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::ProbabilistHermite, false, PosFuncTypes::SoftPlus, QuadTypes::AdaptiveClenshawCurtis), CreateComponentImpl_Prob_ACC)); + static auto reg_device_prob_acc_exp = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::ProbabilistHermite, false, PosFuncTypes::Exp, QuadTypes::AdaptiveClenshawCurtis, false), CreateComponentImpl_Prob_ACC)); + static auto reg_device_prob_acc_splus = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::ProbabilistHermite, false, PosFuncTypes::SoftPlus, QuadTypes::AdaptiveClenshawCurtis, false), CreateComponentImpl_Prob_ACC)); +#endif + +static auto reg_host_prob_acc_exp_compact = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::ProbabilistHermite, false, PosFuncTypes::Exp, QuadTypes::AdaptiveClenshawCurtis, true), CreateComponentImpl_Prob_ACC)); +static auto reg_host_prob_acc_splus_compact = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::ProbabilistHermite, false, PosFuncTypes::SoftPlus, QuadTypes::AdaptiveClenshawCurtis, true), CreateComponentImpl_Prob_ACC)); +#if defined(MPART_ENABLE_GPU) + static auto reg_device_prob_acc_exp_compact = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::ProbabilistHermite, false, PosFuncTypes::Exp, QuadTypes::AdaptiveClenshawCurtis, true), CreateComponentImpl_Prob_ACC)); + static auto reg_device_prob_acc_splus_compact = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::ProbabilistHermite, false, PosFuncTypes::SoftPlus, QuadTypes::AdaptiveClenshawCurtis, true), CreateComponentImpl_Prob_ACC)); #endif #if defined(MPART_HAS_CEREAL) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, ProbabilistHermite, Exp, AdaptiveClenshawCurtis, Kokkos::HostSpace) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, ProbabilistHermite, SoftPlus, AdaptiveClenshawCurtis, Kokkos::HostSpace) +REGISTER_HOMOGENEOUS_MONO_COMP(ProbabilistHermite, Exp, AdaptiveClenshawCurtis, Kokkos::HostSpace, false) +REGISTER_HOMOGENEOUS_MONO_COMP(ProbabilistHermite, SoftPlus, AdaptiveClenshawCurtis, Kokkos::HostSpace, false) +REGISTER_HOMOGENEOUS_MONO_COMP(ProbabilistHermite, Exp, AdaptiveClenshawCurtis, Kokkos::HostSpace, true) +REGISTER_HOMOGENEOUS_MONO_COMP(ProbabilistHermite, SoftPlus, AdaptiveClenshawCurtis, Kokkos::HostSpace, true) #if defined(MPART_ENABLE_GPU) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, ProbabilistHermite, Exp, AdaptiveClenshawCurtis, mpart::DeviceSpace) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, ProbabilistHermite, SoftPlus, AdaptiveClenshawCurtis, mpart::DeviceSpace) +REGISTER_HOMOGENEOUS_MONO_COMP(ProbabilistHermite, Exp, AdaptiveClenshawCurtis, mpart::DeviceSpace, false) +REGISTER_HOMOGENEOUS_MONO_COMP(ProbabilistHermite, SoftPlus, AdaptiveClenshawCurtis, mpart::DeviceSpace, false) +REGISTER_HOMOGENEOUS_MONO_COMP(ProbabilistHermite, Exp, AdaptiveClenshawCurtis, mpart::DeviceSpace, true) +REGISTER_HOMOGENEOUS_MONO_COMP(ProbabilistHermite, SoftPlus, AdaptiveClenshawCurtis, mpart::DeviceSpace, true) #endif CEREAL_REGISTER_DYNAMIC_INIT(mpartInitMapFactory4) #endif diff --git a/src/MapFactoryImpl5.cpp b/src/MapFactoryImpl5.cpp index 4bc9a03a..82031fe8 100644 --- a/src/MapFactoryImpl5.cpp +++ b/src/MapFactoryImpl5.cpp @@ -10,7 +10,7 @@ using namespace mpart; -template +template std::shared_ptr> CreateComponentImpl_Prob_CC(FixedMultiIndexSet const& mset, MapOptions opts) { BasisEvaluator basis1d(opts.basisNorm); @@ -19,7 +19,7 @@ std::shared_ptr> CreateComponentImpl_Prob_CC(Fix MultivariateExpansionWorker expansion(mset, basis1d); std::shared_ptr> output; - output = std::make_shared>(expansion, quad, opts.contDeriv, opts.nugget); + output = std::make_shared>(expansion, quad, opts.contDeriv, opts.nugget); Kokkos::View coeffs = Kokkos::View("Component Coefficients", mset.Size()); output->SetCoeffs(coeffs); @@ -27,19 +27,30 @@ std::shared_ptr> CreateComponentImpl_Prob_CC(Fix return output; } -static auto reg_host_prob_cc_exp = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::ProbabilistHermite, false, PosFuncTypes::Exp, QuadTypes::ClenshawCurtis), CreateComponentImpl_Prob_CC)); -static auto reg_host_prob_cc_splus = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::ProbabilistHermite, false, PosFuncTypes::SoftPlus, QuadTypes::ClenshawCurtis), CreateComponentImpl_Prob_CC)); +static auto reg_host_prob_cc_exp = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::ProbabilistHermite, false, PosFuncTypes::Exp, QuadTypes::ClenshawCurtis, false), CreateComponentImpl_Prob_CC)); +static auto reg_host_prob_cc_splus = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::ProbabilistHermite, false, PosFuncTypes::SoftPlus, QuadTypes::ClenshawCurtis, false), CreateComponentImpl_Prob_CC)); #if defined(MPART_ENABLE_GPU) - static auto reg_device_prob_cc_exp = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::ProbabilistHermite, false, PosFuncTypes::Exp, QuadTypes::ClenshawCurtis), CreateComponentImpl_Prob_CC)); - static auto reg_device_prob_cc_splus = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::ProbabilistHermite, false, PosFuncTypes::SoftPlus, QuadTypes::ClenshawCurtis), CreateComponentImpl_Prob_CC)); + static auto reg_device_prob_cc_exp = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::ProbabilistHermite, false, PosFuncTypes::Exp, QuadTypes::ClenshawCurtis, false), CreateComponentImpl_Prob_CC)); + static auto reg_device_prob_cc_splus = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::ProbabilistHermite, false, PosFuncTypes::SoftPlus, QuadTypes::ClenshawCurtis, false), CreateComponentImpl_Prob_CC)); +#endif + +static auto reg_host_prob_cc_exp_compact = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::ProbabilistHermite, false, PosFuncTypes::Exp, QuadTypes::ClenshawCurtis, true), CreateComponentImpl_Prob_CC)); +static auto reg_host_prob_cc_splus_compact = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::ProbabilistHermite, false, PosFuncTypes::SoftPlus, QuadTypes::ClenshawCurtis, true), CreateComponentImpl_Prob_CC)); +#if defined(MPART_ENABLE_GPU) + static auto reg_device_prob_cc_exp_compact = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::ProbabilistHermite, false, PosFuncTypes::Exp, QuadTypes::ClenshawCurtis, true), CreateComponentImpl_Prob_CC)); + static auto reg_device_prob_cc_splus_compact = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::ProbabilistHermite, false, PosFuncTypes::SoftPlus, QuadTypes::ClenshawCurtis, true), CreateComponentImpl_Prob_CC)); #endif #if defined(MPART_HAS_CEREAL) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, ProbabilistHermite, Exp, ClenshawCurtisQuadrature, Kokkos::HostSpace) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, ProbabilistHermite, SoftPlus, ClenshawCurtisQuadrature, Kokkos::HostSpace) +REGISTER_HOMOGENEOUS_MONO_COMP(ProbabilistHermite, Exp, ClenshawCurtisQuadrature, Kokkos::HostSpace, false) +REGISTER_HOMOGENEOUS_MONO_COMP(ProbabilistHermite, SoftPlus, ClenshawCurtisQuadrature, Kokkos::HostSpace, false) +REGISTER_HOMOGENEOUS_MONO_COMP(ProbabilistHermite, Exp, ClenshawCurtisQuadrature, Kokkos::HostSpace, true) +REGISTER_HOMOGENEOUS_MONO_COMP(ProbabilistHermite, SoftPlus, ClenshawCurtisQuadrature, Kokkos::HostSpace, true) #if defined(MPART_ENABLE_GPU) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, ProbabilistHermite, Exp, ClenshawCurtisQuadrature, mpart::DeviceSpace) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, ProbabilistHermite, SoftPlus, ClenshawCurtisQuadrature, mpart::DeviceSpace) +REGISTER_HOMOGENEOUS_MONO_COMP(ProbabilistHermite, Exp, ClenshawCurtisQuadrature, mpart::DeviceSpace, false) +REGISTER_HOMOGENEOUS_MONO_COMP(ProbabilistHermite, SoftPlus, ClenshawCurtisQuadrature, mpart::DeviceSpace, false) +REGISTER_HOMOGENEOUS_MONO_COMP(ProbabilistHermite, Exp, ClenshawCurtisQuadrature, mpart::DeviceSpace, true) +REGISTER_HOMOGENEOUS_MONO_COMP(ProbabilistHermite, SoftPlus, ClenshawCurtisQuadrature, mpart::DeviceSpace, true) #endif CEREAL_REGISTER_DYNAMIC_INIT(mpartInitMapFactory5) #endif diff --git a/src/MapFactoryImpl6.cpp b/src/MapFactoryImpl6.cpp index 0e51786e..5589a30b 100644 --- a/src/MapFactoryImpl6.cpp +++ b/src/MapFactoryImpl6.cpp @@ -10,7 +10,7 @@ using namespace mpart; -template +template std::shared_ptr> CreateComponentImpl_Prob_AS(FixedMultiIndexSet const& mset, MapOptions opts) { BasisEvaluator basis1d(opts.basisNorm); @@ -19,7 +19,7 @@ std::shared_ptr> CreateComponentImpl_Prob_AS(Fix MultivariateExpansionWorker expansion(mset, basis1d); std::shared_ptr> output; - output = std::make_shared>(expansion, quad, opts.contDeriv, opts.nugget); + output = std::make_shared>(expansion, quad, opts.contDeriv, opts.nugget); Kokkos::View coeffs = Kokkos::View("Component Coefficients", mset.Size()); output->SetCoeffs(coeffs); @@ -27,20 +27,30 @@ std::shared_ptr> CreateComponentImpl_Prob_AS(Fix return output; } -static auto reg_host_prob_as_exp = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::ProbabilistHermite, false, PosFuncTypes::Exp, QuadTypes::AdaptiveSimpson), CreateComponentImpl_Prob_AS)); -static auto reg_host_prob_as_splus = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::ProbabilistHermite, false, PosFuncTypes::SoftPlus, QuadTypes::AdaptiveSimpson), CreateComponentImpl_Prob_AS)); +static auto reg_host_prob_as_exp = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::ProbabilistHermite, false, PosFuncTypes::Exp, QuadTypes::AdaptiveSimpson, false), CreateComponentImpl_Prob_AS)); +static auto reg_host_prob_as_splus = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::ProbabilistHermite, false, PosFuncTypes::SoftPlus, QuadTypes::AdaptiveSimpson, false), CreateComponentImpl_Prob_AS)); #if defined(MPART_ENABLE_GPU) - static auto reg_device_prob_as_exp = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::ProbabilistHermite, false, PosFuncTypes::Exp, QuadTypes::AdaptiveSimpson), CreateComponentImpl_Prob_AS)); - static auto reg_device_prob_as_splus = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::ProbabilistHermite, false, PosFuncTypes::SoftPlus, QuadTypes::AdaptiveSimpson), CreateComponentImpl_Prob_AS)); + static auto reg_device_prob_as_exp = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::ProbabilistHermite, false, PosFuncTypes::Exp, QuadTypes::AdaptiveSimpson, false), CreateComponentImpl_Prob_AS)); + static auto reg_device_prob_as_splus = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::ProbabilistHermite, false, PosFuncTypes::SoftPlus, QuadTypes::AdaptiveSimpson, false), CreateComponentImpl_Prob_AS)); #endif +static auto reg_host_prob_as_exp_compact = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::ProbabilistHermite, false, PosFuncTypes::Exp, QuadTypes::AdaptiveSimpson, true), CreateComponentImpl_Prob_AS)); +static auto reg_host_prob_as_splus_compact = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::ProbabilistHermite, false, PosFuncTypes::SoftPlus, QuadTypes::AdaptiveSimpson, true), CreateComponentImpl_Prob_AS)); +#if defined(MPART_ENABLE_GPU) + static auto reg_device_prob_as_exp_compact = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::ProbabilistHermite, false, PosFuncTypes::Exp, QuadTypes::AdaptiveSimpson, true), CreateComponentImpl_Prob_AS)); + static auto reg_device_prob_as_splus_compact = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::ProbabilistHermite, false, PosFuncTypes::SoftPlus, QuadTypes::AdaptiveSimpson, true), CreateComponentImpl_Prob_AS)); +#endif #if defined(MPART_HAS_CEREAL) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, ProbabilistHermite, Exp, AdaptiveSimpson, Kokkos::HostSpace) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, ProbabilistHermite, SoftPlus, AdaptiveSimpson, Kokkos::HostSpace) +REGISTER_HOMOGENEOUS_MONO_COMP(ProbabilistHermite, Exp, AdaptiveSimpson, Kokkos::HostSpace, false) +REGISTER_HOMOGENEOUS_MONO_COMP(ProbabilistHermite, SoftPlus, AdaptiveSimpson, Kokkos::HostSpace, false) +REGISTER_HOMOGENEOUS_MONO_COMP(ProbabilistHermite, Exp, AdaptiveSimpson, Kokkos::HostSpace, true) +REGISTER_HOMOGENEOUS_MONO_COMP(ProbabilistHermite, SoftPlus, AdaptiveSimpson, Kokkos::HostSpace, true) #if defined(MPART_ENABLE_GPU) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, ProbabilistHermite, Exp, AdaptiveSimpson, mpart::DeviceSpace) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, ProbabilistHermite, SoftPlus, AdaptiveSimpson, mpart::DeviceSpace) +REGISTER_HOMOGENEOUS_MONO_COMP(ProbabilistHermite, Exp, AdaptiveSimpson, mpart::DeviceSpace, false) +REGISTER_HOMOGENEOUS_MONO_COMP(ProbabilistHermite, SoftPlus, AdaptiveSimpson, mpart::DeviceSpace, false) +REGISTER_HOMOGENEOUS_MONO_COMP(ProbabilistHermite, Exp, AdaptiveSimpson, mpart::DeviceSpace, true) +REGISTER_HOMOGENEOUS_MONO_COMP(ProbabilistHermite, SoftPlus, AdaptiveSimpson, mpart::DeviceSpace, true) #endif CEREAL_REGISTER_DYNAMIC_INIT(mpartInitMapFactory6) #endif diff --git a/src/MapFactoryImpl7.cpp b/src/MapFactoryImpl7.cpp index 6a29d336..cc5ae0c3 100644 --- a/src/MapFactoryImpl7.cpp +++ b/src/MapFactoryImpl7.cpp @@ -10,7 +10,7 @@ using namespace mpart; -template +template std::shared_ptr> CreateComponentImpl_HF_ACC(FixedMultiIndexSet const& mset, MapOptions opts) { BasisEvaluator basis1d; @@ -21,7 +21,7 @@ std::shared_ptr> CreateComponentImpl_HF_ACC(Fixe MultivariateExpansionWorker expansion(mset, basis1d); std::shared_ptr> output; - output = std::make_shared>(expansion, quad, opts.contDeriv, opts.nugget); + output = std::make_shared>(expansion, quad, opts.contDeriv, opts.nugget); Kokkos::View coeffs = Kokkos::View("Component Coefficients", mset.Size()); output->SetCoeffs(coeffs); @@ -29,20 +29,31 @@ std::shared_ptr> CreateComponentImpl_HF_ACC(Fixe return output; } -static auto reg_host_hf_acc_exp = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::HermiteFunctions, false, PosFuncTypes::Exp, QuadTypes::AdaptiveClenshawCurtis), CreateComponentImpl_HF_ACC)); -static auto reg_host_hf_acc_splus = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::HermiteFunctions, false, PosFuncTypes::SoftPlus, QuadTypes::AdaptiveClenshawCurtis), CreateComponentImpl_HF_ACC)); +static auto reg_host_hf_acc_exp = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::HermiteFunctions, false, PosFuncTypes::Exp, QuadTypes::AdaptiveClenshawCurtis, false), CreateComponentImpl_HF_ACC)); +static auto reg_host_hf_acc_splus = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::HermiteFunctions, false, PosFuncTypes::SoftPlus, QuadTypes::AdaptiveClenshawCurtis, false), CreateComponentImpl_HF_ACC)); #if defined(MPART_ENABLE_GPU) - static auto reg_device_hf_acc_exp = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::HermiteFunctions, false, PosFuncTypes::Exp, QuadTypes::AdaptiveClenshawCurtis), CreateComponentImpl_HF_ACC)); - static auto reg_device_hf_acc_splus = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::HermiteFunctions, false, PosFuncTypes::SoftPlus, QuadTypes::AdaptiveClenshawCurtis), CreateComponentImpl_HF_ACC)); + static auto reg_device_hf_acc_exp = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::HermiteFunctions, false, PosFuncTypes::Exp, QuadTypes::AdaptiveClenshawCurtis, false), CreateComponentImpl_HF_ACC)); + static auto reg_device_hf_acc_splus = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::HermiteFunctions, false, PosFuncTypes::SoftPlus, QuadTypes::AdaptiveClenshawCurtis, false), CreateComponentImpl_HF_ACC)); #endif +static auto reg_host_hf_acc_exp_compact = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::HermiteFunctions, false, PosFuncTypes::Exp, QuadTypes::AdaptiveClenshawCurtis, true), CreateComponentImpl_HF_ACC)); +static auto reg_host_hf_acc_splus_compact = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::HermiteFunctions, false, PosFuncTypes::SoftPlus, QuadTypes::AdaptiveClenshawCurtis, true), CreateComponentImpl_HF_ACC)); +#if defined(MPART_ENABLE_GPU) + static auto reg_device_hf_acc_exp_compact = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::HermiteFunctions, false, PosFuncTypes::Exp, QuadTypes::AdaptiveClenshawCurtis, true), CreateComponentImpl_HF_ACC)); + static auto reg_device_hf_acc_splus_compact = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::HermiteFunctions, false, PosFuncTypes::SoftPlus, QuadTypes::AdaptiveClenshawCurtis, true), CreateComponentImpl_HF_ACC)); +#endif #if defined(MPART_HAS_CEREAL) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, HermiteFunction, Exp, AdaptiveClenshawCurtis, Kokkos::HostSpace) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, HermiteFunction, SoftPlus, AdaptiveClenshawCurtis, Kokkos::HostSpace) +REGISTER_HOMOGENEOUS_MONO_COMP(HermiteFunction, Exp, AdaptiveClenshawCurtis, Kokkos::HostSpace, false) +REGISTER_HOMOGENEOUS_MONO_COMP(HermiteFunction, SoftPlus, AdaptiveClenshawCurtis, Kokkos::HostSpace, false) +REGISTER_HOMOGENEOUS_MONO_COMP(HermiteFunction, Exp, AdaptiveClenshawCurtis, Kokkos::HostSpace, true) +REGISTER_HOMOGENEOUS_MONO_COMP(HermiteFunction, SoftPlus, AdaptiveClenshawCurtis, Kokkos::HostSpace, true) #if defined(MPART_ENABLE_GPU) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, HermiteFunction, Exp, AdaptiveClenshawCurtis, mpart::DeviceSpace) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, HermiteFunction, SoftPlus, AdaptiveClenshawCurtis, mpart::DeviceSpace) +REGISTER_HOMOGENEOUS_MONO_COMP(HermiteFunction, Exp, AdaptiveClenshawCurtis, mpart::DeviceSpace, false) +REGISTER_HOMOGENEOUS_MONO_COMP(HermiteFunction, SoftPlus, AdaptiveClenshawCurtis, mpart::DeviceSpace, false) +REGISTER_HOMOGENEOUS_MONO_COMP(HermiteFunction, Exp, AdaptiveClenshawCurtis, mpart::DeviceSpace, true) +REGISTER_HOMOGENEOUS_MONO_COMP(HermiteFunction, SoftPlus, AdaptiveClenshawCurtis, mpart::DeviceSpace, true) #endif + CEREAL_REGISTER_DYNAMIC_INIT(mpartInitMapFactory7) #endif diff --git a/src/MapFactoryImpl8.cpp b/src/MapFactoryImpl8.cpp index 04a91cc5..a2c49cd2 100644 --- a/src/MapFactoryImpl8.cpp +++ b/src/MapFactoryImpl8.cpp @@ -10,7 +10,7 @@ using namespace mpart; -template +template std::shared_ptr> CreateComponentImpl_HF_CC(FixedMultiIndexSet const& mset, MapOptions opts) { BasisEvaluator basis1d; @@ -19,7 +19,7 @@ std::shared_ptr> CreateComponentImpl_HF_CC(Fixed MultivariateExpansionWorker expansion(mset, basis1d); std::shared_ptr> output; - output = std::make_shared>(expansion, quad, opts.contDeriv, opts.nugget); + output = std::make_shared>(expansion, quad, opts.contDeriv, opts.nugget); Kokkos::View coeffs = Kokkos::View("Component Coefficients", mset.Size()); output->SetCoeffs(coeffs); @@ -27,19 +27,30 @@ std::shared_ptr> CreateComponentImpl_HF_CC(Fixed return output; } -static auto reg_host_hf_cc_exp = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::HermiteFunctions, false, PosFuncTypes::Exp, QuadTypes::ClenshawCurtis), CreateComponentImpl_HF_CC)); -static auto reg_host_hf_cc_splus = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::HermiteFunctions, false, PosFuncTypes::SoftPlus, QuadTypes::ClenshawCurtis), CreateComponentImpl_HF_CC)); +static auto reg_host_hf_cc_exp = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::HermiteFunctions, false, PosFuncTypes::Exp, QuadTypes::ClenshawCurtis, false), CreateComponentImpl_HF_CC)); +static auto reg_host_hf_cc_splus = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::HermiteFunctions, false, PosFuncTypes::SoftPlus, QuadTypes::ClenshawCurtis, false), CreateComponentImpl_HF_CC)); #if defined(MPART_ENABLE_GPU) - static auto reg_device_hf_cc_exp = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::HermiteFunctions, false, PosFuncTypes::Exp, QuadTypes::ClenshawCurtis), CreateComponentImpl_HF_CC)); - static auto reg_device_hf_cc_splus = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::HermiteFunctions, false, PosFuncTypes::SoftPlus, QuadTypes::ClenshawCurtis), CreateComponentImpl_HF_CC)); + static auto reg_device_hf_cc_exp = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::HermiteFunctions, false, PosFuncTypes::Exp, QuadTypes::ClenshawCurtis, false), CreateComponentImpl_HF_CC)); + static auto reg_device_hf_cc_splus = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::HermiteFunctions, false, PosFuncTypes::SoftPlus, QuadTypes::ClenshawCurtis, false), CreateComponentImpl_HF_CC)); +#endif + +static auto reg_host_hf_cc_exp_compact = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::HermiteFunctions, false, PosFuncTypes::Exp, QuadTypes::ClenshawCurtis, true), CreateComponentImpl_HF_CC)); +static auto reg_host_hf_cc_splus_compact = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::HermiteFunctions, false, PosFuncTypes::SoftPlus, QuadTypes::ClenshawCurtis, true), CreateComponentImpl_HF_CC)); +#if defined(MPART_ENABLE_GPU) + static auto reg_device_hf_cc_exp_compact = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::HermiteFunctions, false, PosFuncTypes::Exp, QuadTypes::ClenshawCurtis, true), CreateComponentImpl_HF_CC)); + static auto reg_device_hf_cc_splus_compact = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::HermiteFunctions, false, PosFuncTypes::SoftPlus, QuadTypes::ClenshawCurtis, true), CreateComponentImpl_HF_CC)); #endif #if defined(MPART_HAS_CEREAL) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, HermiteFunction, Exp, ClenshawCurtisQuadrature, Kokkos::HostSpace) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, HermiteFunction, SoftPlus, ClenshawCurtisQuadrature, Kokkos::HostSpace) +REGISTER_HOMOGENEOUS_MONO_COMP(HermiteFunction, Exp, ClenshawCurtisQuadrature, Kokkos::HostSpace, false) +REGISTER_HOMOGENEOUS_MONO_COMP(HermiteFunction, SoftPlus, ClenshawCurtisQuadrature, Kokkos::HostSpace, false) +REGISTER_HOMOGENEOUS_MONO_COMP(HermiteFunction, Exp, ClenshawCurtisQuadrature, Kokkos::HostSpace, true) +REGISTER_HOMOGENEOUS_MONO_COMP(HermiteFunction, SoftPlus, ClenshawCurtisQuadrature, Kokkos::HostSpace, true) #if defined(MPART_ENABLE_GPU) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, HermiteFunction, Exp, ClenshawCurtisQuadrature, mpart::DeviceSpace) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, HermiteFunction, SoftPlus, ClenshawCurtisQuadrature, mpart::DeviceSpace) -#endif -CEREAL_REGISTER_DYNAMIC_INIT(mpartInitMapFactory8) +REGISTER_HOMOGENEOUS_MONO_COMP(HermiteFunction, Exp, ClenshawCurtisQuadrature, mpart::DeviceSpace, false) +REGISTER_HOMOGENEOUS_MONO_COMP(HermiteFunction, SoftPlus, ClenshawCurtisQuadrature, mpart::DeviceSpace, false) +REGISTER_HOMOGENEOUS_MONO_COMP(HermiteFunction, Exp, ClenshawCurtisQuadrature, mpart::DeviceSpace, true) +REGISTER_HOMOGENEOUS_MONO_COMP(HermiteFunction, SoftPlus, ClenshawCurtisQuadrature, mpart::DeviceSpace, true) #endif +CEREAL_REGISTER_DYNAMIC_INIT(mpartInitMapFactory8) +#endif \ No newline at end of file diff --git a/src/MapFactoryImpl9.cpp b/src/MapFactoryImpl9.cpp index 11313bfc..2a4b4cb4 100644 --- a/src/MapFactoryImpl9.cpp +++ b/src/MapFactoryImpl9.cpp @@ -10,7 +10,7 @@ using namespace mpart; -template +template std::shared_ptr> CreateComponentImpl_HF_AS(FixedMultiIndexSet const& mset, MapOptions opts) { BasisEvaluator basis1d; @@ -19,7 +19,7 @@ std::shared_ptr> CreateComponentImpl_HF_AS(Fixed MultivariateExpansionWorker expansion(mset, basis1d); std::shared_ptr> output; - output = std::make_shared>(expansion, quad, opts.contDeriv, opts.nugget); + output = std::make_shared>(expansion, quad, opts.contDeriv, opts.nugget); Kokkos::View coeffs = Kokkos::View("Component Coefficients", mset.Size()); output->SetCoeffs(coeffs); @@ -27,19 +27,30 @@ std::shared_ptr> CreateComponentImpl_HF_AS(Fixed return output; } -static auto reg_host_hf_as_exp = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::HermiteFunctions, false, PosFuncTypes::Exp, QuadTypes::AdaptiveSimpson), CreateComponentImpl_HF_AS)); -static auto reg_host_hf_as_splus = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::HermiteFunctions, false, PosFuncTypes::SoftPlus, QuadTypes::AdaptiveSimpson), CreateComponentImpl_HF_AS)); +static auto reg_host_hf_as_exp = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::HermiteFunctions, false, PosFuncTypes::Exp, QuadTypes::AdaptiveSimpson, false), CreateComponentImpl_HF_AS)); +static auto reg_host_hf_as_splus = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::HermiteFunctions, false, PosFuncTypes::SoftPlus, QuadTypes::AdaptiveSimpson, false), CreateComponentImpl_HF_AS)); #if defined(MPART_ENABLE_GPU) - static auto reg_device_hf_as_exp = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::HermiteFunctions, false, PosFuncTypes::Exp, QuadTypes::AdaptiveSimpson), CreateComponentImpl_HF_AS)); - static auto reg_device_hf_as_splus = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::HermiteFunctions, false, PosFuncTypes::SoftPlus, QuadTypes::AdaptiveSimpson), CreateComponentImpl_HF_AS)); + static auto reg_device_hf_as_exp = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::HermiteFunctions, false, PosFuncTypes::Exp, QuadTypes::AdaptiveSimpson, false), CreateComponentImpl_HF_AS)); + static auto reg_device_hf_as_splus = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::HermiteFunctions, false, PosFuncTypes::SoftPlus, QuadTypes::AdaptiveSimpson, false), CreateComponentImpl_HF_AS)); +#endif + +static auto reg_host_hf_as_exp_compact = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::HermiteFunctions, false, PosFuncTypes::Exp, QuadTypes::AdaptiveSimpson, true), CreateComponentImpl_HF_AS)); +static auto reg_host_hf_as_splus_compact = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::HermiteFunctions, false, PosFuncTypes::SoftPlus, QuadTypes::AdaptiveSimpson, true), CreateComponentImpl_HF_AS)); +#if defined(MPART_ENABLE_GPU) + static auto reg_device_hf_as_exp_compact = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::HermiteFunctions, false, PosFuncTypes::Exp, QuadTypes::AdaptiveSimpson, true), CreateComponentImpl_HF_AS)); + static auto reg_device_hf_as_splus_compact = mpart::MapFactory::CompFactoryImpl::GetFactoryMap()->insert(std::make_pair(std::make_tuple(BasisTypes::HermiteFunctions, false, PosFuncTypes::SoftPlus, QuadTypes::AdaptiveSimpson, true), CreateComponentImpl_HF_AS)); #endif #if defined(MPART_HAS_CEREAL) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, HermiteFunction, Exp, AdaptiveSimpson, Kokkos::HostSpace) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, HermiteFunction, SoftPlus, AdaptiveSimpson, Kokkos::HostSpace) +REGISTER_HOMOGENEOUS_MONO_COMP(HermiteFunction, Exp, AdaptiveSimpson, Kokkos::HostSpace, false) +REGISTER_HOMOGENEOUS_MONO_COMP(HermiteFunction, SoftPlus, AdaptiveSimpson, Kokkos::HostSpace, false) +REGISTER_HOMOGENEOUS_MONO_COMP(HermiteFunction, Exp, AdaptiveSimpson, Kokkos::HostSpace, true) +REGISTER_HOMOGENEOUS_MONO_COMP(HermiteFunction, SoftPlus, AdaptiveSimpson, Kokkos::HostSpace, true) #if defined(MPART_ENABLE_GPU) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, HermiteFunction, Exp, AdaptiveSimpson, mpart::DeviceSpace) -REGISTER_MONO_COMP(BasisHomogeneity::Homogeneous, HermiteFunction, SoftPlus, AdaptiveSimpson, mpart::DeviceSpace) +REGISTER_HOMOGENEOUS_MONO_COMP(HermiteFunction, Exp, AdaptiveSimpson, mpart::DeviceSpace, false) +REGISTER_HOMOGENEOUS_MONO_COMP(HermiteFunction, SoftPlus, AdaptiveSimpson, mpart::DeviceSpace, false) +REGISTER_HOMOGENEOUS_MONO_COMP(HermiteFunction, Exp, AdaptiveSimpson, mpart::DeviceSpace, true) +REGISTER_HOMOGENEOUS_MONO_COMP(HermiteFunction, SoftPlus, AdaptiveSimpson, mpart::DeviceSpace, true) #endif CEREAL_REGISTER_DYNAMIC_INIT(mpartInitMapFactory9) #endif diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index f3e9486f..4bd159da 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -29,12 +29,14 @@ set (TEST_SOURCES tests/Distributions/Test_TransportSampler.cpp tests/Test_OrthogonalPolynomials.cpp + tests/Test_UnivariateBases.cpp tests/Test_RootFinding.cpp tests/Test_HermiteFunctions.cpp tests/Test_Sigmoid.cpp tests/Test_PositiveBijectors.cpp tests/Test_Quadrature.cpp tests/Test_MonotoneComponent.cpp + tests/Test_MonotoneComponent_compact.cpp tests/Test_MultivariateExpansion.cpp tests/Test_BasisEvaluator.cpp tests/Test_MultivariateExpansionWorker.cpp diff --git a/tests/Test_MapFactory.cpp b/tests/Test_MapFactory.cpp index 85c93aa4..3dc7c011 100644 --- a/tests/Test_MapFactory.cpp +++ b/tests/Test_MapFactory.cpp @@ -14,153 +14,255 @@ using namespace mpart; using namespace Catch; using MemorySpace = Kokkos::HostSpace; -TEST_CASE( "Testing map component factory", "[MapFactoryComponent]" ) { +TEST_CASE("Testing map component factory", "[MapFactoryComponent]") +{ - MapOptions options; options.basisType = BasisTypes::ProbabilistHermite; options.basisNorm = false; unsigned int dim = 3; unsigned int maxDegree = 5; - FixedMultiIndexSet mset(dim,maxDegree); + FixedMultiIndexSet mset(dim, maxDegree); - SECTION("AdaptiveSimpson"){ + SECTION("AdaptiveSimpson") + { options.quadType = QuadTypes::AdaptiveSimpson; std::shared_ptr> map = MapFactory::CreateComponent(mset, options); - REQUIRE(map!=nullptr); + REQUIRE(map != nullptr); unsigned int numPts = 100; - Kokkos::View pts("Points", dim, numPts); - for(unsigned int i=0; i pts("Points", dim, numPts); + for (unsigned int i = 0; i < numPts; ++i) + pts(dim - 1, i) = double(i) / double(numPts - 1); - Kokkos::View eval = map->Evaluate(pts); + Kokkos::View eval = map->Evaluate(pts); } - SECTION("ClenshawCurtis"){ + SECTION("ClenshawCurtis") + { options.quadType = QuadTypes::ClenshawCurtis; - + std::shared_ptr> map = MapFactory::CreateComponent(mset, options); - REQUIRE(map!=nullptr); + REQUIRE(map != nullptr); unsigned int numPts = 100; - Kokkos::View pts("Points", dim, numPts); - for(unsigned int i=0; i pts("Points", dim, numPts); + for (unsigned int i = 0; i < numPts; ++i) + pts(dim - 1, i) = double(i) / double(numPts - 1); - Kokkos::View eval = map->Evaluate(pts); + Kokkos::View eval = map->Evaluate(pts); } - SECTION("AdaptiveClenshawCurtis"){ + SECTION("AdaptiveClenshawCurtis") + { options.quadType = QuadTypes::AdaptiveClenshawCurtis; - + std::shared_ptr> map = MapFactory::CreateComponent(mset, options); - REQUIRE(map!=nullptr); + REQUIRE(map != nullptr); unsigned int numPts = 100; - Kokkos::View pts("Points", dim, numPts); - for(unsigned int i=0; i pts("Points", dim, numPts); + for (unsigned int i = 0; i < numPts; ++i) + pts(dim - 1, i) = double(i) / double(numPts - 1); - Kokkos::View eval = map->Evaluate(pts); + Kokkos::View eval = map->Evaluate(pts); } } +TEST_CASE("Testing map component factory with linearized basis", "[MapFactoryLinearizedComponent]") +{ -TEST_CASE( "Testing map component factory with linearized basis", "[MapFactoryLinearizedComponent]" ) { - - MapOptions options; options.basisType = BasisTypes::ProbabilistHermite; options.basisLB = -5; options.basisUB = 4; options.basisNorm = false; - - + MapOptions options2; options2.basisType = BasisTypes::ProbabilistHermite; options2.basisNorm = false; - + unsigned int dim = 1; unsigned int maxDegree = 7; - FixedMultiIndexSet mset(dim,maxDegree); + FixedMultiIndexSet mset(dim, maxDegree); - SECTION("AdaptiveSimpson"){ + SECTION("AdaptiveSimpson") + { options.quadType = QuadTypes::AdaptiveSimpson; std::shared_ptr> linearized_map = MapFactory::CreateComponent(mset, options); - + std::shared_ptr> map = MapFactory::CreateComponent(mset, options2); - REQUIRE(linearized_map!=nullptr); - REQUIRE(map!=nullptr); + REQUIRE(linearized_map != nullptr); + REQUIRE(map != nullptr); - Kokkos::View coeffs("Coefficients", map->numCoeffs); - for(unsigned int i=0; inumCoeffs; ++i) + Kokkos::View coeffs("Coefficients", map->numCoeffs); + for (unsigned int i = 0; i < map->numCoeffs; ++i) coeffs(i) = 1.0; map->SetCoeffs(coeffs); linearized_map->SetCoeffs(coeffs); unsigned int numPts = 5; - Kokkos::View pts("Points", dim, numPts); - pts(0,0) = -6; - pts(0,1) = -4.5; - pts(0,2) = 0; - pts(0,3) = 3.5; - pts(0,4) = 4.5; - - - Kokkos::View linearized_evals = linearized_map->Evaluate(pts); - Kokkos::View evals = map->Evaluate(pts); - - for(unsigned int i=0; ioptions.basisUB)){ - CHECK( std::abs(linearized_evals(0,i) - evals(0,i))>1e-13); - }else{ - CHECK( linearized_evals(0,i) == Approx(evals(0,i)).epsilon(1e-15)); + Kokkos::View pts("Points", dim, numPts); + pts(0, 0) = -6; + pts(0, 1) = -4.5; + pts(0, 2) = 0; + pts(0, 3) = 3.5; + pts(0, 4) = 4.5; + + Kokkos::View linearized_evals = linearized_map->Evaluate(pts); + Kokkos::View evals = map->Evaluate(pts); + + for (unsigned int i = 0; i < numPts; ++i) + { + if ((pts(0, i) < options.basisLB) || (pts(0, i) > options.basisUB)) + { + CHECK(std::abs(linearized_evals(0, i) - evals(0, i)) > 1e-13); + } + else + { + CHECK(linearized_evals(0, i) == Approx(evals(0, i)).epsilon(1e-15)); } } } +} + +TEST_CASE("Testing compact map component factory", "[MapFactoryCompactComponent]") +{ + + MapOptions options; + options.basisType = BasisTypes::ProbabilistHermite; + options.isCompact = true; + options.basisNorm = false; + + unsigned int dim = 2; + unsigned int maxDegree = 7; + MultiIndexSet mset_h = MultiIndexSet::CreateTotalOrder(dim, maxDegree, [](MultiIndex m) + { return m.HasNonzeroEnd() || m.Max() == 0; }); + FixedMultiIndexSet mset = mset_h.Fix(true); + + SECTION("AdaptiveSimpson") + { + options.quadType = QuadTypes::AdaptiveSimpson; + + std::shared_ptr> map = MapFactory::CreateComponent(mset, options); + REQUIRE(map != nullptr); + + Kokkos::View coeffs("Coefficients", map->numCoeffs); + for (unsigned int i = 0; i < map->numCoeffs; ++i) + coeffs(i) = 1.0; + map->SetCoeffs(coeffs); + unsigned int numPts = 5; + Kokkos::View pts("Points", dim, numPts); + pts(0, 0) = 0.0; + pts(0, 1) = 0.2; + pts(0, 2) = 0.5; + pts(0, 3) = 0.94; + pts(0, 4) = 1.0; + pts(1, 0) = 0.0; + pts(1, 1) = 0.0; + pts(1, 2) = 0.4; + pts(1, 3) = 1.0; + pts(1, 4) = 1.0; + + Kokkos::View evals = map->Evaluate(pts); + + for (unsigned int i = 0; i < numPts; ++i) + { + CHECK(evals(0, i) >= 0.); + CHECK(evals(0, i) <= 1.); + } + } } +TEST_CASE("Testing compact map component factory, legendre basis", "[MapFactoryCompactComponent_Legendre]") +{ -TEST_CASE( "Testing multivariate expansion factory", "[MapFactoryExpansion]" ) { + MapOptions options; + options.basisType = BasisTypes::Legendre; + options.isCompact = true; + options.basisNorm = false; + + unsigned int dim = 2; + unsigned int maxDegree = 7; + MultiIndexSet mset_h = MultiIndexSet::CreateTotalOrder(dim, maxDegree); + FixedMultiIndexSet mset = mset_h.Fix(true); + + SECTION("AdaptiveClenshawCurtis") + { + options.quadType = QuadTypes::AdaptiveClenshawCurtis; + + std::shared_ptr> map = MapFactory::CreateComponent(mset, options); + REQUIRE(map != nullptr); + + Kokkos::View coeffs("Coefficients", map->numCoeffs); + for (unsigned int i = 0; i < map->numCoeffs; ++i) + coeffs(i) = i * cos(0.5 + i * M_PI * 2 / map->numCoeffs); + map->SetCoeffs(coeffs); + + unsigned int numPts = 5; + Kokkos::View pts("Points", dim, numPts); + pts(0, 0) = 0.0; + pts(0, 1) = 0.2; + pts(0, 2) = 0.5; + pts(0, 3) = 0.94; + pts(0, 4) = 1.0; + pts(1, 0) = 0.0; + pts(1, 1) = 0.0; + pts(1, 2) = 0.4; + pts(1, 3) = 1.0; + pts(1, 4) = 1.0; + + Kokkos::View evals = map->Evaluate(pts); + + for (unsigned int i = 0; i < numPts; ++i) + { + CHECK(evals(0, i) >= 0.); + CHECK(evals(0, i) <= 1.); + } + } +} + +TEST_CASE("Testing multivariate expansion factory", "[MapFactoryExpansion]") +{ MapOptions options; options.basisType = BasisTypes::ProbabilistHermite; - + unsigned int outDim = 5; unsigned int inDim = 3; unsigned int maxDegree = 5; - FixedMultiIndexSet mset(inDim,maxDegree); + FixedMultiIndexSet mset(inDim, maxDegree); std::shared_ptr> func = MapFactory::CreateExpansion(outDim, mset, options); - REQUIRE(func!=nullptr); + REQUIRE(func != nullptr); unsigned int numPts = 100; - Kokkos::View pts("Points", inDim, numPts); - for(unsigned int i=0; i pts("Points", inDim, numPts); + for (unsigned int i = 0; i < numPts; ++i) + pts(inDim - 1, i) = double(i) / double(numPts - 1); - Kokkos::View eval = func->Evaluate(pts); - CHECK(eval.extent(0)==outDim); - CHECK(eval.extent(1)==numPts); + Kokkos::View eval = func->Evaluate(pts); + CHECK(eval.extent(0) == outDim); + CHECK(eval.extent(1) == numPts); } - -TEST_CASE( "Testing factory method for triangular map", "[MapFactoryTriangular]" ) { +TEST_CASE("Testing factory method for triangular map", "[MapFactoryTriangular]") +{ MapOptions options; options.basisType = BasisTypes::ProbabilistHermite; - std::shared_ptr> map = MapFactory::CreateTriangular(4,3,5, options); + std::shared_ptr> map = MapFactory::CreateTriangular(4, 3, 5, options); REQUIRE(map != nullptr); } -TEST_CASE( "Testing factory method for single entry map, activeInd = 1", "[MapFactorySingleEntryMap 1]" ) { +TEST_CASE("Testing factory method for single entry map, activeInd = 1", "[MapFactorySingleEntryMap 1]") +{ MapOptions options; options.basisType = BasisTypes::ProbabilistHermite; @@ -175,7 +277,8 @@ TEST_CASE( "Testing factory method for single entry map, activeInd = 1", "[MapFa REQUIRE(map != nullptr); } -TEST_CASE( "Testing factory method for single entry map, activeInd = dim", "[MapFactorySingleEntryMap 2]" ) { +TEST_CASE("Testing factory method for single entry map, activeInd = dim", "[MapFactorySingleEntryMap 2]") +{ MapOptions options; options.basisType = BasisTypes::ProbabilistHermite; @@ -190,7 +293,8 @@ TEST_CASE( "Testing factory method for single entry map, activeInd = dim", "[Map REQUIRE(map != nullptr); } -TEST_CASE( "Testing factory method for single entry map, 1 < activeInd < dim", "[MapFactorySingleEntryMap 3]" ) { +TEST_CASE("Testing factory method for single entry map, 1 < activeInd < dim", "[MapFactorySingleEntryMap 3]") +{ MapOptions options; options.basisType = BasisTypes::ProbabilistHermite; @@ -204,83 +308,91 @@ TEST_CASE( "Testing factory method for single entry map, 1 < activeInd < dim", " REQUIRE(map != nullptr); } -TEST_CASE( "Testing factory method for Sigmoid Component", "[MapFactorySigmoidComponent]" ) { +TEST_CASE("Testing factory method for Sigmoid Component", "[MapFactorySigmoidComponent]") +{ MapOptions options; unsigned int inputDim = 7; unsigned int maxDegree = 3; unsigned int num_sigmoids = 5; - unsigned int numCenters = 2 + num_sigmoids*(num_sigmoids+1)/2; + unsigned int numCenters = 2 + num_sigmoids * (num_sigmoids + 1) / 2; options.basisType = BasisTypes::HermiteFunctions; - Kokkos::View centers("Centers", numCenters); + Kokkos::View centers("Centers", numCenters); double bound = 3.; - centers(0) = -bound; centers(1) = bound; + centers(0) = -bound; + centers(1) = bound; unsigned int center_idx = 2; - for(int j = 0; j < num_sigmoids; j++){ - for(int i = 0; i <= j; i++){ - centers(center_idx) = -bound + (2*bound)*(i+1)/(j+2); + for (int j = 0; j < num_sigmoids; j++) + { + for (int i = 0; i <= j; i++) + { + centers(center_idx) = -bound + (2 * bound) * (i + 1) / (j + 2); center_idx++; } } std::shared_ptr> func = MapFactory::CreateSigmoidComponent(inputDim, maxDegree, centers, options); REQUIRE(func != nullptr); unsigned int numPts = 100; - Kokkos::View pts("Points", inputDim, numPts); - Kokkos::MDRangePolicy, typename MemoryToExecution::Space> policy({0,0}, {inputDim, numPts}); - Kokkos::parallel_for("Fill points", policy, KOKKOS_LAMBDA(const int i, const int j){ - pts(i,j) = double(j*i)/double((inputDim)*(numPts-1)); - }); + Kokkos::View pts("Points", inputDim, numPts); + Kokkos::MDRangePolicy, typename MemoryToExecution::Space> policy({0, 0}, {inputDim, numPts}); + Kokkos::parallel_for("Fill points", policy, KOKKOS_LAMBDA(const int i, const int j) { pts(i, j) = double(j * i) / double((inputDim) * (numPts - 1)); }); Kokkos::fence(); // Checking example of Gradient StridedVector coeffs = func->Coeffs(); Kokkos::deep_copy(coeffs, 1.0); - Kokkos::View eval = func->Evaluate(pts); - CHECK(eval.extent(0)==1); - SECTION("Check Gradient") { - Kokkos::View sens ( "Sensitivities", 1, numPts); - Kokkos::RangePolicy::Space> policy_pts {0, numPts}; - Kokkos::parallel_for("fill sensitivities", policy_pts, KOKKOS_LAMBDA(const int i){ - sens(0,i) = 1.0; - }); - Kokkos::View grad = func->Gradient(pts, sens); - CHECK(grad.extent(0)==inputDim); - CHECK(grad.extent(1)==numPts); + Kokkos::View eval = func->Evaluate(pts); + CHECK(eval.extent(0) == 1); + SECTION("Check Gradient") + { + Kokkos::View sens("Sensitivities", 1, numPts); + Kokkos::RangePolicy::Space> policy_pts{0, numPts}; + Kokkos::parallel_for("fill sensitivities", policy_pts, KOKKOS_LAMBDA(const int i) { sens(0, i) = 1.0; }); + Kokkos::View grad = func->Gradient(pts, sens); + CHECK(grad.extent(0) == inputDim); + CHECK(grad.extent(1) == numPts); double fd_step = 1e-6; - for(int i = 0; i < inputDim; i++){ - Kokkos::parallel_for(policy_pts, KOKKOS_LAMBDA(const int j){ + for (int i = 0; i < inputDim; i++) + { + Kokkos::parallel_for(policy_pts, KOKKOS_LAMBDA(const int j) { if(i > 0) pts(i-1,j) -= fd_step; - pts(i,j) += fd_step; - }); + pts(i,j) += fd_step; }); Kokkos::fence(); - Kokkos::View eval2 = func->Evaluate(pts); - for(int j = 0; j < numPts; j++){ - double fd = (eval2(0,j) - eval(0,j))/(fd_step); - CHECK(grad(i,j) == Approx(fd).epsilon(20*fd_step)); + Kokkos::View eval2 = func->Evaluate(pts); + for (int j = 0; j < numPts; j++) + { + double fd = (eval2(0, j) - eval(0, j)) / (fd_step); + CHECK(grad(i, j) == Approx(fd).epsilon(20 * fd_step)); } } } - SECTION("Create Sigmoid Component from fixed msets") { + SECTION("Create Sigmoid Component from fixed msets") + { // Make some arbitrary limiter - auto limiter = [maxDegree](MultiIndex const& index){ - return index.Get(index.Length()-1) != 0 && index.Sum() == maxDegree; + auto limiter = [maxDegree](MultiIndex const &index) + { + return index.Get(index.Length() - 1) != 0 && index.Sum() == maxDegree; }; - FixedMultiIndexSet mset= MultiIndexSet::CreateTotalOrder(inputDim, maxDegree, limiter).Fix(true); + FixedMultiIndexSet mset = MultiIndexSet::CreateTotalOrder(inputDim, maxDegree, limiter).Fix(true); std::shared_ptr> map = MapFactory::CreateSigmoidComponent(mset, centers, options); REQUIRE(map != nullptr); REQUIRE(map->numCoeffs == mset.Size()); } - SECTION("Create Triangular Sigmoid Map From Components") { + SECTION("Create Triangular Sigmoid Map From Components") + { std::vector>> maps; - for(int i = 1; i <= inputDim; i++){ + for (int i = 1; i <= inputDim; i++) + { maps.push_back(MapFactory::CreateSigmoidComponent(i, 0, centers, options)); } auto map = std::make_shared>(maps); REQUIRE(map != nullptr); } - SECTION("CreateSigmoidTriangular") { + SECTION("CreateSigmoidTriangular") + { std::vector> centers_vec; unsigned int outputDim = 3; - for(int i = 0; i < outputDim; i++){ + for (int i = 0; i < outputDim; i++) + { centers_vec.push_back(centers); } std::shared_ptr> map = MapFactory::CreateSigmoidTriangular(inputDim, outputDim, 0, centers_vec, options); diff --git a/tests/Test_MonotoneComponent.cpp b/tests/Test_MonotoneComponent.cpp index 87700998..b94a51a1 100644 --- a/tests/Test_MonotoneComponent.cpp +++ b/tests/Test_MonotoneComponent.cpp @@ -11,10 +11,6 @@ #include -// TO REMOVE -#include -#include - using namespace mpart; using namespace Catch; using HostSpace = Kokkos::HostSpace; @@ -108,8 +104,6 @@ TEST_CASE( "MonotoneIntegrand1d", "[MonotoneIntegrand1d]") { } } - - TEST_CASE( "MonotoneIntegrand1d With Nugget", "[MonotoneIntegrand1d]") { const double testTol = 1e-7; @@ -355,8 +349,6 @@ TEST_CASE( "MonotoneIntegrand2d", "[MonotoneIntegrand2d]") { } } - - TEST_CASE( "Testing monotone component evaluation in 1d", "[MonotoneComponent1d]" ) { const double testTol = 1e-7; @@ -439,7 +431,6 @@ TEST_CASE( "Testing monotone component evaluation in 1d", "[MonotoneComponent1d] } } - TEST_CASE( "Testing bracket-based inversion of monotone component", "[MonotoneBracketInverse]" ) { const double testTol = 1e-6; @@ -556,8 +547,6 @@ TEST_CASE( "Testing bracket-based inversion of monotone component", "[MonotoneBr } } - - TEST_CASE( "Testing monotone component derivative", "[MonotoneComponentDerivative]" ) { const double testTol = 1e-4; diff --git a/tests/Test_MonotoneComponent_compact.cpp b/tests/Test_MonotoneComponent_compact.cpp new file mode 100644 index 00000000..114039c9 --- /dev/null +++ b/tests/Test_MonotoneComponent_compact.cpp @@ -0,0 +1,612 @@ +#include + +#include "MParT/MonotoneComponent.h" +#include "MParT/PositiveBijectors.h" +#include "MParT/Quadrature.h" +#include "MParT/OrthogonalPolynomial.h" +#include "MParT/MultivariateExpansionWorker.h" +#include "MParT/MonotoneIntegrand.h" + +#include "MParT/Utilities/ArrayConversions.h" + +#include + +using namespace mpart; +using namespace Catch::Matchers; +using HostSpace = Kokkos::HostSpace; + +TEST_CASE("Testing compact monotone component evaluation in 1d", "[MonotoneComponentCompact1d]") +{ + + const double testTol = 1e-7; + unsigned int dim = 1; + + // Create points evently space on [lb,ub] + unsigned int numPts = 20; + + Kokkos::View evalPts("Evaluate Points", dim, numPts); + for (unsigned int i = 0; i < numPts; ++i) + evalPts(0, i) = (i / double(numPts - 0.5)); + + /* Create and evaluate an affine map + - Set coefficients so that f(x) = 1.0 + x + - (int_0^x exp( d f(t) ) dt)/(int_0^1 exp( d f(t) ) dt ) = x*exp(-1) + 1 + */ + SECTION("Affine Map") + { + unsigned int maxDegree = 1; + // This only will be okay for compact map since dim = 1 + MultiIndexSet mset = MultiIndexSet::CreateTotalOrder(dim, maxDegree); + + MultivariateExpansionWorker, HostSpace> expansion(mset); + + Kokkos::View coeffs("Expansion coefficients", mset.Size()); + coeffs(0) = 1.0; // Constant term + coeffs(1) = 1.0; // Linear term + + unsigned int maxSub = 3; + double relTol = 1e-7; + double absTol = 1e-7; + AdaptiveSimpson quad(maxSub, 1, nullptr, absTol, relTol, QuadError::First); + + MonotoneComponent, HostSpace>, Exp, AdaptiveSimpson, HostSpace, true> comp(expansion, quad); + + Kokkos::View output("output", numPts); + comp.EvaluateImpl(evalPts, coeffs, output); + + for (unsigned int i = 0; i < numPts; ++i) + { + CHECK_THAT(output(i), WithinRel(evalPts(0, i), testTol)); + bool isInbounds = output(i) <= 1. && output(i) >= 0.; + CHECK(isInbounds); + } + } + + /* Create and evaluate a quadratic map + - Set coefficients so that f(x) = 1.0 + x + 0.5*x^2 + - df/dt = 1.0 + t + - int_0^x exp( df/dt ) dt = int_0^x exp(1+t) = exp(1+x)-exp(1) => (exp(1+x)-exp(1))/(exp(2)-exp(1)) + */ + SECTION("Quadratic Map") + { + unsigned int maxDegree = 2; + MultiIndexSet mset = MultiIndexSet::CreateTotalOrder(dim, maxDegree); + + MultivariateExpansionWorker, HostSpace> expansion(mset); + + Kokkos::View coeffs("Expansion coefficients", mset.Size()); + coeffs(1) = 1.0; // Linear term = x ^1 + coeffs(2) = 0.5; // Quadratic term = x^2 - 1.0 + coeffs(0) = 1.0 + coeffs(2); // Constant term = x^0 + + unsigned int maxSub = 30; + double relTol = 1e-7; + double absTol = 1e-7; + AdaptiveSimpson quad(maxSub, 1, nullptr, absTol, relTol, QuadError::First); + + MonotoneComponent, HostSpace>, Exp, AdaptiveSimpson, HostSpace, true> comp(expansion, quad); + + Kokkos::View output("Output", numPts); + comp.EvaluateImpl(evalPts, coeffs, output); + + for (unsigned int i = 0; i < numPts; ++i) + { + double x = evalPts(0, i); + CHECK_THAT(output(i), WithinRel((exp(1 + x) - exp(1)) / (exp(2) - exp(1)), testTol)); + } + } +} + +TEST_CASE("Testing bracket-based inversion of compact monotone component", "[CompactMonotoneBracketInverse]") +{ + + const double testTol = 2e-6; + unsigned int dim = 1; + + // Create points evently space on [lb,ub] + unsigned int numPts = 20; + + Kokkos::View evalPts("Evaluate Points", dim, numPts); + for (unsigned int i = 0; i < numPts; ++i) + evalPts(0, i) = (i / double(numPts - 1)); + + /* Create and evaluate an affine map + - Set coefficients so that f(x) = 1.0 + x + - ( f(0) + int_0^x exp( d f(t) ) dt ) / ( f(0) + int_0^1 exp( d f(t) ) dt )= (1 + x * exp(1))/(1 + exp(1)) + */ + SECTION("Affine Map") + { + unsigned int maxDegree = 1; + MultiIndexSet mset = MultiIndexSet::CreateTotalOrder(dim, maxDegree); + + MultivariateExpansionWorker, HostSpace> expansion(mset); + + Kokkos::View coeffs("Expansion coefficients", mset.Size()); + coeffs(0) = 1.0; // Constant term + coeffs(1) = 1.0; // Linear term + + unsigned int maxSub = 30; + double relTol = 1e-7; + double absTol = 1e-7; + AdaptiveSimpson quad(maxSub, 1, nullptr, absTol, relTol, QuadError::First); + + MonotoneComponent, HostSpace, true> comp(expansion, quad); + + Kokkos::View ys("ys", numPts); + comp.EvaluateImpl(evalPts, coeffs, ys); + + Kokkos::View testInverse("Test output", numPts); + for (int i = 0; i < 100; i++) + comp.InverseImpl(evalPts, ys, coeffs, testInverse); + + for (unsigned int i = 0; i < numPts; ++i) + { + CHECK_THAT(testInverse(i), WithinRel(evalPts(0, i), testTol)); + } + } + + /* Create and evaluate a quadratic map + - Set coefficients so that f(x) = 1.0 + x + 0.5*x^2 + - df/dt = 1.0 + t + - f(0) + int_0^x exp( df/dt ) dt = 1.0 + int_0^x exp(1+t) dt = 1+exp(1+x) + */ + SECTION("Quadratic Map") + { + unsigned int maxDegree = 2; + MultiIndexSet mset = MultiIndexSet::CreateTotalOrder(dim, maxDegree); + + MultivariateExpansionWorker, HostSpace> expansion(mset); + + Kokkos::View coeffs("Expansion coefficients", mset.Size()); + coeffs(1) = 1.0; // Linear term = x ^1 + coeffs(2) = 0.5; // Quadratic term = x^2 - 1.0 + coeffs(0) = 1.0 + coeffs(2); // Constant term = x^0 + + unsigned int maxSub = 30; + double relTol = 1e-7; + double absTol = 1e-7; + AdaptiveSimpson quad(maxSub, 1, nullptr, absTol, relTol, QuadError::First); + + MonotoneComponent, HostSpace, true> comp(expansion, quad); + + Kokkos::View ys("ys", numPts); + comp.EvaluateImpl(evalPts, coeffs, ys); + + Kokkos::View testInverse("inverse", numPts); + comp.InverseImpl(evalPts, ys, coeffs, testInverse); + + for (unsigned int i = 0; i < numPts; ++i) + { + CHECK_THAT(testInverse(i), WithinAbs(evalPts(0, i), testTol)); + } + } + + SECTION("Same x, multiple ys") + { + + Kokkos::View x("Evaluate Points", dim, 1); + x(0, 0) = 0.5; + + unsigned int maxDegree = 2; + MultiIndexSet mset = MultiIndexSet::CreateTotalOrder(dim, maxDegree); + MultivariateExpansionWorker, HostSpace> expansion(mset); + + Kokkos::View coeffs("Expansion coefficients", mset.Size()); + coeffs(1) = 1.0; // Linear term = x ^1 + coeffs(2) = 0.5; // Quadratic term = x^2 - 1.0 + coeffs(0) = 1.0 + coeffs(2); // Constant term = x^0 + + unsigned int maxSub = 30; + double relTol = 1e-7; + double absTol = 1e-7; + AdaptiveSimpson quad(maxSub, 1, nullptr, absTol, relTol, QuadError::First); + + MonotoneComponent, HostSpace, true> comp(expansion, quad); + + Kokkos::View ys("ys", numPts); + comp.EvaluateImpl(evalPts, coeffs, ys); + + Kokkos::View testInverse("inverse", numPts); + comp.InverseImpl(x, ys, coeffs, testInverse); + + for (unsigned int i = 0; i < numPts; ++i) + { + CHECK_THAT(testInverse(i), WithinAbs(evalPts(0, i), testTol)); + } + } +} + +TEST_CASE("Testing compact monotone component derivative", "[CompactMonotoneComponentDerivative]") +{ + + const double testTol = 1e-4; + unsigned int dim = 2; + const double fdStep = 1e-4; + + // Create points evently spaced on [lb,ub] + unsigned int numPts = 20; + double lb = 0.; + double ub = 1. - fdStep; + + Kokkos::View evalPts("Evaluate Points", dim, numPts); + for (unsigned int i = 0; i < numPts; ++i) + { + evalPts(0, i) = (i / double(numPts - 1)) * (ub - lb) + lb; + evalPts(1, i) = evalPts(0, i); + } + + Kokkos::View rightEvalPts("Finite difference points", dim, numPts); + for (unsigned int i = 0; i < numPts; ++i) + { + rightEvalPts(0, i) = evalPts(0, i); + rightEvalPts(1, i) = evalPts(1, i) + fdStep; + } + + unsigned int maxDegree = 4; + + MultiIndexSet mset = MultiIndexSet::CreateTotalOrder(dim, maxDegree); + MultivariateExpansionWorker, HostSpace> expansion(mset); + + unsigned int numTerms = mset.Size(); + + unsigned int maxSub = 30; + double relTol = 1e-7; + double absTol = 1e-7; + AdaptiveSimpson quad(maxSub, 1, nullptr, absTol, relTol, QuadError::First); + + MonotoneComponent, HostSpace, true> comp(expansion, quad); + + // Create some arbitrary coefficients + Kokkos::View coeffs("Expansion coefficients", mset.Size()); + for (unsigned int i = 0; i < coeffs.extent(0); ++i) + coeffs(i) = 0.1 * std::cos(2 * i + 0.5); + + Kokkos::View evals("evals", numPts); + comp.EvaluateImpl(evalPts, coeffs, evals); + Kokkos::View rightEvals("revals", numPts); + comp.EvaluateImpl(rightEvalPts, coeffs, rightEvals); + Kokkos::View contDerivs = comp.ContinuousDerivative(evalPts, coeffs); + + SECTION("Continuous derivatives") + { + for (unsigned int i = 0; i < numPts; ++i) + { + double fdDeriv = (rightEvals(i) - evals(i)) / fdStep; + CHECK_THAT(contDerivs(i), WithinRel(fdDeriv, testTol)); + } + } + + SECTION("Coefficient Jacobian") + { + + Kokkos::View evals2("FD Evals", numPts); + Kokkos::View jac("Jacobian", numTerms, numPts); + + comp.CoeffJacobian(evalPts, coeffs, evals2, jac); + + for (unsigned int i = 0; i < numPts; ++i) + CHECK_THAT(evals2(i), WithinAbs(evals(i), 1e-12)); + + const double fdStep = 1e-4; + + for (unsigned j = 0; j < numTerms; ++j) + { + coeffs(j) += fdStep; + comp.EvaluateImpl(evalPts, coeffs, evals2); + + for (unsigned int i = 0; i < numPts; ++i) + { + // TODO: Why is jacobian zero for midx (k_1,k_2) k_2<=1 ?? + double fd_deriv = (evals2(i) - evals(i)) / fdStep; + CHECK_THAT(jac(j, i), WithinRel(fd_deriv, 5 * fdStep) || WithinAbs(fd_deriv, 1e-10)); + } + + coeffs(j) -= fdStep; + } + } + + SECTION("Mixed Continuous Jacobian") + { + + const double fdStep = 1e-5; + + Kokkos::View derivs("Derivatives", numPts); + Kokkos::View derivs2("Derivatives2", numPts); + + Kokkos::View jac("Jacobian", numTerms, numPts); + + comp.ContinuousMixedJacobian(evalPts, coeffs, jac); + derivs = comp.ContinuousDerivative(evalPts, coeffs); + + // Perturb the coefficients and recompute + Kokkos::View coeffs2("Coefficients2", numTerms); + Kokkos::deep_copy(coeffs2, coeffs); + + for (unsigned int j = 0; j < coeffs.extent(0); ++j) + { + coeffs2(j) += fdStep; + derivs2 = comp.ContinuousDerivative(evalPts, coeffs2); + + for (unsigned int i = 0; i < derivs2.extent(0); ++i) + { + // TODO: Why is jacobian zero for midx (k_1,k_2) k_2<=1 ?? + double fd_deriv = (derivs2(i) - derivs(i)) / fdStep; + CHECK_THAT(jac(j, i), WithinRel(fd_deriv, 20 * fdStep) || WithinAbs(fd_deriv, 1e-10)); + } + + coeffs2(j) = coeffs(j); + } + } + + SECTION("Input Jacobian") + { + + const double fdStep = 1e-4; + + Kokkos::View evals("Evaluations", numPts); + Kokkos::View evals2("Evaluations 2", numPts); + + Kokkos::View jac("Jacobian", dim, numPts); + + comp.InputJacobian(evalPts, coeffs, evals, jac); + + Kokkos::View evalPts2("Points2", evalPts.extent(0), evalPts.extent(1)); + Kokkos::deep_copy(evalPts2, evalPts); + + for (unsigned int j = 0; j < dim; ++j) + { + for (unsigned int ptInd = 0; ptInd < numPts; ++ptInd) + evalPts2(j, ptInd) += fdStep; + + comp.EvaluateImpl(evalPts2, coeffs, evals2); + + for (unsigned int ptInd = 0; ptInd < numPts; ++ptInd) + { + double fd_deriv = (evals2(ptInd) - evals(ptInd)) / fdStep; + CHECK_THAT(jac(j, ptInd), WithinRel(fd_deriv, 10 * fdStep) || WithinAbs(fd_deriv, 1e-10)); + } + + for (unsigned int ptInd = 0; ptInd < numPts; ++ptInd) + evalPts2(j, ptInd) = evalPts(j, ptInd); + } + } + + SECTION("DiscreteDerivative") + { + REQUIRE_THROWS_AS(comp.DiscreteDerivative(evalPts, coeffs), std::invalid_argument); + } + SECTION("GradientImpl") + { + + Kokkos::View evals("Evaluations", 1, numPts); + + Kokkos::View sens("Jacobian", dim + 1, numPts); + REQUIRE_THROWS_AS(comp.GradientImpl(evalPts, sens, evals), std::invalid_argument); + } +} + +TEST_CASE("Compact component input gradients", "[CompactInputGrad]") { + + // const double testTol = 1e-4; + unsigned int dim = 2; + + // Create points evently spaced on [lb,ub] + unsigned int numPts = 20; + double fd_step = 1e-7; + + Kokkos::View evalPts("Evaluate Points", dim, numPts); + for (unsigned int i = 0; i < numPts; ++i) + { + evalPts(0, i) = i / double(numPts + 2); + evalPts(1, i) = i / double(numPts + 1); + } + + unsigned int maxDegree = 3; + MultiIndexSet mset = MultiIndexSet::CreateTotalOrder(dim, maxDegree); + MultivariateExpansionWorker, HostSpace> expansion(mset); + + unsigned int maxSub = 20; + double relTol = 1e-7; + double absTol = 1e-7; + AdaptiveSimpson quad(maxSub, 1, nullptr, absTol, relTol, QuadError::First); + + MonotoneComponent, HostSpace, true> comp(expansion, quad); + + Kokkos::View coeffs("Expansion coefficients", mset.Size()); + for (unsigned int i = 0; i < coeffs.extent(0); ++i) + coeffs(i) = 1. + 0.1 * std::cos(2 * i + 0.5); + + comp.SetCoeffs(coeffs); + + + SECTION("Gradient") { + Kokkos::View evals = comp.Evaluate(evalPts); + Kokkos::View evals_fd("Finite Difference Eval space", 1, numPts); + Kokkos::View sens("sensitivities", 1, numPts); + double sens_constant = 2.; + Kokkos::deep_copy(sens, sens_constant); + Kokkos::View grads = comp.Gradient(evalPts, sens); + REQUIRE(grads.extent(0) == comp.inputDim); + REQUIRE(grads.extent(1) == numPts); + for(int i = 0; i < dim; i++) { + for(int j = 0; j < numPts; j++) + evalPts(i,j) += fd_step; + comp.EvaluateImpl(evalPts, evals_fd); + for(int j = 0; j < numPts; j++) { + double fd_grad = (evals_fd(0, j) - evals(0,j))/fd_step; + CHECK_THAT(grads(i,j), WithinRel(sens_constant*fd_grad, 1e-3) || WithinAbs(sens_constant*fd_grad, 1e-3)); + evalPts(i,j) -= fd_step; + } + } + } + + SECTION("LogDeterminantInputGrad") { + Kokkos::View logdets = comp.LogDeterminant(evalPts); + Kokkos::View logdets_fd("Finite Difference LogDeterminant space", numPts); + Kokkos::View grads = comp.LogDeterminantInputGrad(evalPts); + REQUIRE(grads.extent(0) == comp.inputDim); + REQUIRE(grads.extent(1) == numPts); + for(int i = 0; i < dim; i++) { + for(int j = 0; j < numPts; j++) evalPts(i,j) += fd_step; + comp.LogDeterminantImpl(evalPts, logdets_fd); + for(int j = 0; j < numPts; j++) { + double fd_grad = (logdets_fd(j) - logdets(j))/fd_step; + CHECK_THAT(grads(i,j), WithinRel(fd_grad, 1e-3) || WithinAbs(fd_grad, 1e-3)); + evalPts(i,j) -= fd_step; + } + } + } +} + +TEST_CASE("Compact least squares test", "[CompactMonotoneComponentRegression]") +{ + + unsigned int numPts = 100; + Kokkos::View pts("Training Points", 1, numPts); + for (unsigned int i = 0; i < numPts; ++i) + pts(0, i) = i / (numPts - 1.0); + + Kokkos::View fvals("Training Values", numPts); + for (unsigned int i = 0; i < numPts; ++i) + fvals(i) = (pts(0, i) * pts(0, i) + pts(0, i)) / 2; // Bijection on [0,1] + + // Don't need limiter for compact in one dimension + MultiIndexSet mset = MultiIndexSet::CreateTotalOrder(1, 6); + MultivariateExpansionWorker, HostSpace> expansion(mset); + + unsigned int maxSub = 30; + double relTol = 1e-3; + double absTol = 1e-3; + AdaptiveSimpson quad(maxSub, 1, nullptr, absTol, relTol, QuadError::First); + + MonotoneComponent, HostSpace, true> comp(expansion, quad); + + unsigned int numTerms = mset.Size(); + Kokkos::View coeffs("Coefficients", numTerms); + Kokkos::View jac("Gradient", numTerms, numPts); + Kokkos::View preds("Predictions", numPts); + + double objective; + + Eigen::Map> jacMat(&jac(0, 0), numTerms, numPts); + + Eigen::Map predVec(&preds(0), numPts); + Eigen::Map obsVec(&fvals(0), numPts); + Eigen::Map coeffVec(&coeffs(0), numTerms); + + Eigen::VectorXd objGrad; + + for (unsigned int optIt = 0; optIt < 5; ++optIt) + { + + comp.CoeffJacobian(pts, coeffs, preds, jac); + + objGrad = predVec - obsVec; + + objective = 0.5 * objGrad.squaredNorm(); + coeffVec -= jacMat.transpose().colPivHouseholderQr().solve(objGrad); + } + + CHECK(objective < 1e-3); +} + +TEST_CASE("Testing CompactMonotoneComponent CoeffGrad and LogDeterminantCoeffGrad", "[CompactMonotoneComponent_CoeffGrad]") +{ + // const double testTol = 1e-4; + unsigned int dim = 2; + + // Create points evently spaced on [lb,ub] + unsigned int numPts = 20; + // double lb = -0.5; + // double ub = 0.5; + + Kokkos::View evalPts("Evaluate Points", dim, numPts); + for (unsigned int i = 0; i < numPts; ++i) + { + evalPts(0, i) = i / double(numPts + 2); + evalPts(1, i) = i / double(numPts); + } + + unsigned int maxDegree = 3; + MultiIndexSet mset = MultiIndexSet::CreateTotalOrder(dim, maxDegree); + MultivariateExpansionWorker, HostSpace> expansion(mset); + + unsigned int maxSub = 20; + double relTol = 1e-7; + double absTol = 1e-7; + AdaptiveSimpson quad(maxSub, 1, nullptr, absTol, relTol, QuadError::First); + + MonotoneComponent, HostSpace, true> comp(expansion, quad); + + Kokkos::View coeffs("Expansion coefficients", mset.Size()); + for (unsigned int i = 0; i < coeffs.extent(0); ++i) + coeffs(i) = 1. + 0.1 * std::cos(2 * i + 0.5); + + comp.SetCoeffs(coeffs); + + SECTION("CoeffGrad") + { + Kokkos::View sens("sensitivities", 1, numPts); + Kokkos::deep_copy(sens, 1.); + Kokkos::View evals = comp.Evaluate(evalPts); + Kokkos::View evals2; + Kokkos::View grads = comp.CoeffGrad(evalPts, sens); + REQUIRE(grads.extent(0) == comp.numCoeffs); + REQUIRE(grads.extent(1) == numPts); + + // Compare with finite difference derivatives + const double fdstep = 1e-5; + + for (unsigned int i = 0; i < coeffs.extent(0); ++i) + { + coeffs(i) += fdstep; + + comp.SetCoeffs(coeffs); + evals2 = comp.Evaluate(evalPts); + for (unsigned int ptInd = 0; ptInd < numPts; ++ptInd) + { + double fd_grad = (evals2(0, ptInd) - evals(0, ptInd)) / fdstep; + if (i == 0 || (ptInd == 0 && !mset[i].HasNonzeroEnd())) + { + CHECK_THAT(grads(i, ptInd), WithinAbs(0., 1e-10)); + } + else + CHECK_THAT(grads(i, ptInd), WithinRel(fd_grad, 1e-3) || WithinAbs(fd_grad, 1e-5)); + } + + coeffs(i) -= fdstep; + } + } + + SECTION("LogDeterminantCoeffGrad") + { + + Kokkos::View logDets = comp.LogDeterminant(evalPts); + Kokkos::View logDets2; + Kokkos::View grads = comp.LogDeterminantCoeffGrad(evalPts); + REQUIRE(grads.extent(0) == comp.numCoeffs); + REQUIRE(grads.extent(1) == numPts); + + // Compare with finite difference derivatives + const double fdstep = 1e-5; + + for (unsigned int i = 0; i < coeffs.extent(0); ++i) + { + coeffs(i) += fdstep; + + comp.SetCoeffs(coeffs); + logDets2 = comp.LogDeterminant(evalPts); + for (unsigned int ptInd = 0; ptInd < numPts; ++ptInd) + { + if (i == 0 || (ptInd == 0 && !mset[i].HasNonzeroEnd())) + { + CHECK_THAT(grads(i, ptInd), WithinAbs(0., 1e-10)); + } + else + CHECK_THAT(grads(i, ptInd), WithinRel((logDets2(ptInd) - logDets(ptInd)) / fdstep, 1e-3)); + } + + coeffs(i) -= fdstep; + } + } +} \ No newline at end of file diff --git a/tests/Test_OrthogonalPolynomials.cpp b/tests/Test_OrthogonalPolynomials.cpp index 2e8d7e73..7ce8a0c1 100644 --- a/tests/Test_OrthogonalPolynomials.cpp +++ b/tests/Test_OrthogonalPolynomials.cpp @@ -146,8 +146,6 @@ TEST_CASE( "Testing Probabilist Hermite polynomials", "[ProbabilistHermite]" ) { } - - TEST_CASE( "Testing Physicist Hermite normalization", "[PhysicistHermiteNorm]" ) { PhysicistHermite poly(false); @@ -202,7 +200,6 @@ TEST_CASE( "Testing Physicist Hermite normalization", "[PhysicistHermiteNorm]" ) } - TEST_CASE( "Testing Physicist Hermite polynomials", "[PhysicistHermite]" ) { const double floatTol = 1e-15; @@ -229,6 +226,116 @@ TEST_CASE( "Testing Physicist Hermite polynomials", "[PhysicistHermite]" ) { } } +TEST_CASE( "Testing Shifted Legendre polynomials", "[ShiftedLegendre]" ) { + + const double floatTol = 1e-14; + + ShiftedLegendre poly; + + std::vector xs{0.0, 0.1, 0.5, 0.75, 1.0}; + std::vector allvals(5); + std::vector allderivs(5); + std::vector allderivs2(5); + auto shifted_legendre_eval = [](double x){return std::vector { + 1.0, + 2.0*x-1.0, + 6.0*x*x - 6.0*x + 1.0, + 20.0*x*x*x - 30.0*x*x + 12.0*x - 1.0, + 70.0*x*x*x*x - 140.0*x*x*x + 90.0*x*x - 20.0*x + 1.0 + }; + }; + // Check the evaluation + for(auto& x : xs){ + auto shifted_eval = shifted_legendre_eval(x); + CHECK( poly.Evaluate(0, x) == shifted_eval[0] ); + CHECK( poly.Evaluate(1, x) == Approx(shifted_eval[1]).epsilon(floatTol) ); + CHECK( poly.Evaluate(2, x) == Approx(shifted_eval[2]).epsilon(floatTol) ); + CHECK( poly.Evaluate(3, x) == Approx(shifted_eval[3]).epsilon(floatTol) ); + CHECK( poly.Evaluate(4, x) == Approx(shifted_eval[4]).epsilon(floatTol) ); + + poly.EvaluateAll(&allvals[0], 4, x); + CHECK( allvals[0] == shifted_eval[0]); + CHECK( allvals[1] == Approx(shifted_eval[1]).epsilon(floatTol) ); + CHECK( allvals[2] == Approx(shifted_eval[2]).epsilon(floatTol) ); + CHECK( allvals[3] == Approx(shifted_eval[3]).epsilon(floatTol) ); + CHECK( allvals[4] == Approx(shifted_eval[4]).epsilon(floatTol) ); + } + + auto shifted_legendre_deriv = [](double x){return std::vector { + 0.0, + 2.0, + 12.0*x - 6.0, + 60.0*x*x - 60.0*x + 12.0, + 280.0*x*x*x - 420.0*x*x + 180.0*x - 20.0 + }; + }; + // Check the derivative + for(auto& x : xs){ + auto shifted_deriv = shifted_legendre_deriv(x); + CHECK( poly.Derivative(0, x) == shifted_deriv[0] ); + CHECK( poly.Derivative(1, x) == shifted_deriv[1] ); + CHECK( poly.Derivative(2, x) == Approx(shifted_deriv[2]).epsilon(floatTol) ); + CHECK( poly.Derivative(3, x) == Approx(shifted_deriv[3]).epsilon(floatTol) ); + CHECK( poly.Derivative(4, x) == Approx(shifted_deriv[4]).epsilon(floatTol) ); + + auto shifted_eval = shifted_legendre_eval(x); + poly.EvaluateDerivatives(&allvals[0], &allderivs[0], 4, x); + CHECK( allvals[0] == shifted_eval[0] ); + CHECK( allvals[1] == Approx(shifted_eval[1]).epsilon(floatTol) ); + CHECK( allvals[2] == Approx(shifted_eval[2]).epsilon(floatTol) ); + CHECK( allvals[3] == Approx(shifted_eval[3]).epsilon(floatTol) ); + CHECK( allvals[4] == Approx(shifted_eval[4]).epsilon(floatTol) ); + CHECK( allderivs[0] == shifted_deriv[0] ); + CHECK( allderivs[1] == shifted_deriv[1] ); + CHECK( allderivs[2] == Approx(shifted_deriv[2]).epsilon(floatTol) ); + CHECK( allderivs[3] == Approx(shifted_deriv[3]).epsilon(floatTol) ); + CHECK( allderivs[4] == Approx(shifted_deriv[4]).epsilon(floatTol) ); + + poly.EvaluateDerivatives(&allderivs[0], 4, x); + CHECK( allderivs[0] == shifted_deriv[0] ); + CHECK( allderivs[1] == shifted_deriv[1] ); + CHECK( allderivs[2] == Approx(shifted_deriv[2]).epsilon(floatTol) ); + CHECK( allderivs[3] == Approx(shifted_deriv[3]).epsilon(floatTol) ); + CHECK( allderivs[4] == Approx(shifted_deriv[4]).epsilon(floatTol) ); + } + + auto shifted_legendre_deriv2 = [](double x){return std::vector { + 0.0, + 0.0, + 12.0, + 120.0*x - 60.0, + 840.0*x*x - 840.0*x + 180.0 + }; + }; + // Check the second derivatives + for(auto& x : xs){ + auto shifted_deriv2 = shifted_legendre_deriv2(x); + CHECK( poly.SecondDerivative(0, x) == shifted_deriv2[0] ); + CHECK( poly.SecondDerivative(1, x) == shifted_deriv2[1] ); + CHECK( poly.SecondDerivative(2, x) == Approx(shifted_deriv2[2]).epsilon(floatTol) ); + CHECK( poly.SecondDerivative(3, x) == Approx(shifted_deriv2[3]).epsilon(floatTol) ); + CHECK( poly.SecondDerivative(4, x) == Approx(shifted_deriv2[4]).epsilon(floatTol) ); + + auto shifted_eval = shifted_legendre_eval(x); + auto shifted_deriv = shifted_legendre_deriv(x); + poly.EvaluateSecondDerivatives(&allvals[0], &allderivs[0], &allderivs2[0], 4, x); + CHECK( allvals[0] == shifted_eval[0] ); + CHECK( allvals[1] == Approx(shifted_eval[1]).epsilon(floatTol) ); + CHECK( allvals[2] == Approx(shifted_eval[2]).epsilon(floatTol) ); + CHECK( allvals[3] == Approx(shifted_eval[3]).epsilon(floatTol) ); + CHECK( allvals[4] == Approx(shifted_eval[4]).epsilon(floatTol) ); + CHECK( allderivs[0] == shifted_deriv[0]); + CHECK( allderivs[1] == shifted_deriv[1]); + CHECK( allderivs[2] == Approx(shifted_deriv[2]).epsilon(floatTol) ); + CHECK( allderivs[3] == Approx(shifted_deriv[3]).epsilon(floatTol) ); + CHECK( allderivs[4] == Approx(shifted_deriv[4]).epsilon(floatTol) ); + CHECK( allderivs2[0] == shifted_deriv2[0]); + CHECK( allderivs2[1] == shifted_deriv2[1]); + CHECK( allderivs2[2] == Approx(shifted_deriv2[2]).epsilon(floatTol) ); + CHECK( allderivs2[3] == Approx(shifted_deriv2[3]).epsilon(floatTol) ); + CHECK( allderivs2[4] == Approx(shifted_deriv2[4]).epsilon(floatTol) ); + } +} #if defined(KOKKOS_ENABLE_CUDA ) || defined(KOKKOS_ENABLE_SYCL) diff --git a/tests/Test_UnivariateBases.cpp b/tests/Test_UnivariateBases.cpp new file mode 100644 index 00000000..ef7c9646 --- /dev/null +++ b/tests/Test_UnivariateBases.cpp @@ -0,0 +1,118 @@ +#include + +#include "MParT/UnivariateBases.h" +using namespace mpart; + +using namespace Catch::Matchers; + +TEST_CASE( "Testing Sine basis", "[SineBasis]" ) { + + const double floatTol = 1e-12; + + SineBasis sine; + + std::vector xs{0.0, 0.1, 0.5, 0.75, 1.0}; + std::vector allvals(5); + std::vector allderivs(5); + std::vector allderivs2(5); + auto sine_evaluation = [](double x){return std::vector { + 1.0, + sin(2*M_PI*x), + sin(2*M_PI*2*x), + sin(2*M_PI*3*x), + sin(2*M_PI*4*x) + }; + }; + // Check the evaluation + for(auto& x : xs){ + auto sine_eval = sine_evaluation(x); + // CHECK_THAT(inv(0, i), WithinAbs(points(0, i), 1e-10)); + CHECK ( sine.Evaluate(0, x) == sine_eval[0] ); + CHECK_THAT( sine.Evaluate(1, x), WithinAbs(sine_eval[1], floatTol) ); + CHECK_THAT( sine.Evaluate(2, x), WithinAbs(sine_eval[2], floatTol) ); + CHECK_THAT( sine.Evaluate(3, x), WithinAbs(sine_eval[3], floatTol) ); + CHECK_THAT( sine.Evaluate(4, x), WithinAbs(sine_eval[4], floatTol) ); + + sine.EvaluateAll(&allvals[0], 4, x); + CHECK ( allvals[0] == sine_eval[0] ); + CHECK_THAT( allvals[1], WithinAbs(sine_eval[1], floatTol) ); + CHECK_THAT( allvals[2], WithinAbs(sine_eval[2], floatTol) ); + CHECK_THAT( allvals[3], WithinAbs(sine_eval[3], floatTol) ); + CHECK_THAT( allvals[4], WithinAbs(sine_eval[4], floatTol) ); + } + + auto sine_derivative = [](double x){return std::vector { + 0.0, + 1*2*M_PI*cos(1*2*M_PI*x), + 2*2*M_PI*cos(2*2*M_PI*x), + 3*2*M_PI*cos(3*2*M_PI*x), + 4*2*M_PI*cos(4*2*M_PI*x) + }; + }; + // CHECK_THAT the derivative + for(auto& x : xs){ + auto sine_deriv = sine_derivative(x); + CHECK ( sine.Derivative(0, x) == sine_deriv[0] ); + CHECK ( sine.Derivative(1, x) == sine_deriv[1] ); + CHECK_THAT( sine.Derivative(2, x), WithinAbs(sine_deriv[2], floatTol) ); + CHECK_THAT( sine.Derivative(3, x), WithinAbs(sine_deriv[3], floatTol) ); + CHECK_THAT( sine.Derivative(4, x), WithinAbs(sine_deriv[4], floatTol) ); + + auto sine_eval = sine_evaluation(x); + sine.EvaluateDerivatives(&allvals[0], &allderivs[0], 4, x); + CHECK ( allvals[0] == sine_eval[0] ); + CHECK_THAT( allvals[1], WithinAbs(sine_eval[1], floatTol) ); + CHECK_THAT( allvals[2], WithinAbs(sine_eval[2], floatTol) ); + CHECK_THAT( allvals[3], WithinAbs(sine_eval[3], floatTol) ); + CHECK_THAT( allvals[4], WithinAbs(sine_eval[4], floatTol) ); + CHECK ( allderivs[0] == sine_deriv[0] ); + CHECK ( allderivs[1] == sine_deriv[1] ); + CHECK_THAT( allderivs[2], WithinAbs(sine_deriv[2], floatTol) ); + CHECK_THAT( allderivs[3], WithinAbs(sine_deriv[3], floatTol) ); + CHECK_THAT( allderivs[4], WithinAbs(sine_deriv[4], floatTol) ); + + sine.EvaluateDerivatives(&allderivs[0], 4, x); + CHECK ( allderivs[0] == sine_deriv[0] ); + CHECK ( allderivs[1] == sine_deriv[1] ); + CHECK_THAT( allderivs[2], WithinAbs(sine_deriv[2], floatTol) ); + CHECK_THAT( allderivs[3], WithinAbs(sine_deriv[3], floatTol) ); + CHECK_THAT( allderivs[4], WithinAbs(sine_deriv[4], floatTol) ); + } + + auto sine_derivative2 = [](double x){return std::vector { + 0.0, + -(1*2*M_PI)*(1*2*M_PI)*sin(1*2*M_PI*x), + -(2*2*M_PI)*(2*2*M_PI)*sin(2*2*M_PI*x), + -(3*2*M_PI)*(3*2*M_PI)*sin(3*2*M_PI*x), + -(4*2*M_PI)*(4*2*M_PI)*sin(4*2*M_PI*x) + }; + }; + // CHECK_THAT the second derivatives + for(auto& x : xs){ + auto sine_deriv2 = sine_derivative2(x); + CHECK ( sine.SecondDerivative(0, x) == sine_deriv2[0] ); + CHECK ( sine.SecondDerivative(1, x) == sine_deriv2[1] ); + CHECK_THAT( sine.SecondDerivative(2, x), WithinAbs(sine_deriv2[2], floatTol) ); + CHECK_THAT( sine.SecondDerivative(3, x), WithinAbs(sine_deriv2[3], floatTol) ); + CHECK_THAT( sine.SecondDerivative(4, x), WithinAbs(sine_deriv2[4], floatTol) ); + + auto sine_eval = sine_evaluation(x); + auto sine_deriv = sine_derivative(x); + sine.EvaluateSecondDerivatives(&allvals[0], &allderivs[0], &allderivs2[0], 4, x); + CHECK ( allvals[0] == sine_eval[0] ); + CHECK_THAT( allvals[1], WithinAbs(sine_eval[1], floatTol) ); + CHECK_THAT( allvals[2], WithinAbs(sine_eval[2], floatTol) ); + CHECK_THAT( allvals[3], WithinAbs(sine_eval[3], floatTol) ); + CHECK_THAT( allvals[4], WithinAbs(sine_eval[4], floatTol) ); + CHECK ( allderivs[0] == sine_deriv[0] ); + CHECK ( allderivs[1] == sine_deriv[1] ); + CHECK_THAT( allderivs[2], WithinAbs(sine_deriv[2], floatTol) ); + CHECK_THAT( allderivs[3], WithinAbs(sine_deriv[3], floatTol) ); + CHECK_THAT( allderivs[4], WithinAbs(sine_deriv[4], floatTol) ); + CHECK ( allderivs2[0] == sine_deriv2[0] ); + CHECK ( allderivs2[1] == sine_deriv2[1] ); + CHECK_THAT( allderivs2[2], WithinAbs(sine_deriv2[2], floatTol) ); + CHECK_THAT( allderivs2[3], WithinAbs(sine_deriv2[3], floatTol) ); + CHECK_THAT( allderivs2[4], WithinAbs(sine_deriv2[4], floatTol) ); + } +} \ No newline at end of file