Added the copy and sqrt operator to SpectrumFunction

This commit is contained in:
Guilhem Lavaux 2012-11-12 10:02:22 -05:00
parent 7ad4911872
commit 60c6d789e3
3 changed files with 44 additions and 1 deletions

View File

@ -25,10 +25,15 @@ namespace CosmoTool
typedef Eigen::Map<VecType const, Eigen::Aligned> ConstMapType; typedef Eigen::Map<VecType const, Eigen::Aligned> ConstMapType;
typedef FourierMap<std::complex<T> > FourierMapType; typedef FourierMap<std::complex<T> > FourierMapType;
typedef boost::shared_ptr<FourierMapType> FourierMapPtr; typedef boost::shared_ptr<FourierMapType> FourierMapPtr;
typedef boost::shared_ptr<SpectrumFunction<T> > SpectrumFunctionPtr;
virtual void virtual void
newRandomFourier(gsl_rng *rng, FourierMapType& out_map) const = 0; newRandomFourier(gsl_rng *rng, FourierMapType& out_map) const = 0;
virtual SpectrumFunctionPtr copy() const = 0;
virtual void sqrt() = 0;
virtual void mul(FourierMapType& m) const = 0; virtual void mul(FourierMapType& m) const = 0;
virtual void mul_sqrt(FourierMapType& m) const = 0; virtual void mul_sqrt(FourierMapType& m) const = 0;
virtual void mul_inv(FourierMapType& m) const = 0; virtual void mul_inv(FourierMapType& m) const = 0;

View File

@ -1,6 +1,7 @@
#ifndef __COSMOTOOL_FOURIER_EUCLIDIAN_HPP #ifndef __COSMOTOOL_FOURIER_EUCLIDIAN_HPP
#define __COSMOTOOL_FOURIER_EUCLIDIAN_HPP #define __COSMOTOOL_FOURIER_EUCLIDIAN_HPP
#include <cmath>
#include <boost/function.hpp> #include <boost/function.hpp>
#include <vector> #include <vector>
#include <boost/shared_ptr.hpp> #include <boost/shared_ptr.hpp>
@ -11,6 +12,18 @@
namespace CosmoTool namespace CosmoTool
{ {
template<typename T>
class EuclidianOperator
{
public:
typedef boost::function1<T, T> Function;
Function base, op;
T operator()(T k) {
return op(base(k));
}
};
template<typename T> template<typename T>
class EuclidianSpectrum_1D: public SpectrumFunction<T> class EuclidianSpectrum_1D: public SpectrumFunction<T>
{ {
@ -18,8 +31,11 @@ namespace CosmoTool
typedef boost::function1<T, T> Function; typedef boost::function1<T, T> Function;
protected: protected:
Function f; Function f;
static T msqrt(T a) { return std::sqrt(a); }
public: public:
typedef typename SpectrumFunction<T>::FourierMapType FourierMapType; typedef typename SpectrumFunction<T>::FourierMapType FourierMapType;
typedef typename SpectrumFunction<T>::SpectrumFunctionPtr SpectrumFunctionPtr;
typedef boost::shared_ptr<FourierMapType> ptr_map; typedef boost::shared_ptr<FourierMapType> ptr_map;
EuclidianSpectrum_1D(Function P) EuclidianSpectrum_1D(Function P)
@ -29,6 +45,17 @@ namespace CosmoTool
void newRandomFourier(gsl_rng *rng, FourierMapType& out_map) const; void newRandomFourier(gsl_rng *rng, FourierMapType& out_map) const;
SpectrumFunctionPtr copy() const {
return SpectrumFunctionPtr(new EuclidianSpectrum_1D(f));
}
void sqrt() {
EuclidianOperator<T> o;
o.base = f;
o.op = &EuclidianSpectrum_1D<T>::msqrt;
f = (Function(o));
}
void mul(FourierMapType& m) const; void mul(FourierMapType& m) const;
void mul_sqrt(FourierMapType& m) const; void mul_sqrt(FourierMapType& m) const;
void mul_inv(FourierMapType& m) const; void mul_inv(FourierMapType& m) const;

View File

@ -12,6 +12,8 @@
#include <sharp_lowlevel.h> #include <sharp_lowlevel.h>
#include <sharp_geomhelpers.h> #include <sharp_geomhelpers.h>
#include <sharp_almhelpers.h> #include <sharp_almhelpers.h>
#include <algorithm>
#include <functional>
namespace CosmoTool namespace CosmoTool
{ {
@ -23,7 +25,7 @@ namespace CosmoTool
public: public:
typedef typename SpectrumFunction<T>::FourierMapType FourierMapType; typedef typename SpectrumFunction<T>::FourierMapType FourierMapType;
typedef boost::shared_ptr<FourierMapType> ptr_map; typedef boost::shared_ptr<FourierMapType> ptr_map;
typedef typename SpectrumFunction<T>::SpectrumFunctionPtr SpectrumFunctionPtr;
HealpixSpectrum(long Lmax) HealpixSpectrum(long Lmax)
: cls(Lmax+1) {} : cls(Lmax+1) {}
@ -33,6 +35,15 @@ namespace CosmoTool
long size() const { return cls.size(); } long size() const { return cls.size(); }
void newRandomFourier(gsl_rng *rng, FourierMapType& like_map) const; void newRandomFourier(gsl_rng *rng, FourierMapType& like_map) const;
SpectrumFunctionPtr copy() const {
HealpixSpectrum *s = new HealpixSpectrum(cls.size()-1);
s->cls = cls;
return SpectrumFunctionPtr(s);
}
void sqrt() {
std::transform(cls.begin(), cls.end(), cls.begin(), std::ptr_fun<T,T>(std::sqrt));
}
void mul(FourierMapType& m) const; void mul(FourierMapType& m) const;
void mul_sqrt(FourierMapType& m) const; void mul_sqrt(FourierMapType& m) const;