Commit 59d123e4 authored by Martin Reinecke's avatar Martin Reinecke
Browse files

cleanup

parent ff5022ef
...@@ -99,6 +99,9 @@ template<typename T> class membuf ...@@ -99,6 +99,9 @@ template<typename T> class membuf
const T *d; const T *d;
bool rw; bool rw;
membuf(T *d_, const Tsp &p, bool rw_)
: ptr(p), d(d_), rw(rw_) {}
public: public:
membuf(T *d_, bool rw_=false) membuf(T *d_, bool rw_=false)
: d(d_), rw(rw_) {} : d(d_), rw(rw_) {}
...@@ -110,9 +113,6 @@ template<typename T> class membuf ...@@ -110,9 +113,6 @@ template<typename T> class membuf
: ptr(other.ptr), d(other.d), rw(false) {} : ptr(other.ptr), d(other.d), rw(false) {}
membuf(membuf &other) = default; membuf(membuf &other) = default;
membuf(membuf &&other) = default; membuf(membuf &&other) = default;
// Not for public use!
membuf(T *d_, const Tsp &p, bool rw_)
: ptr(p), d(d_), rw(rw_) {}
template<typename I> T &vraw(I i) template<typename I> T &vraw(I i)
{ {
...@@ -134,9 +134,6 @@ template<typename T> class membuf ...@@ -134,9 +134,6 @@ template<typename T> class membuf
// "mav" stands for "multidimensional array view" // "mav" stands for "multidimensional array view"
template<typename T> class fmav: public fmav_info, public membuf<T> template<typename T> class fmav: public fmav_info, public membuf<T>
{ {
protected:
using typename membuf<T>::Tsp;
public: public:
fmav(const T *d_, const shape_t &shp_, const stride_t &str_) fmav(const T *d_, const shape_t &shp_, const stride_t &str_)
: fmav_info(shp_, str_), membuf<T>(d_) {} : fmav_info(shp_, str_), membuf<T>(d_) {}
...@@ -155,9 +152,10 @@ template<typename T> class fmav: public fmav_info, public membuf<T> ...@@ -155,9 +152,10 @@ template<typename T> class fmav: public fmav_info, public membuf<T>
fmav(const fmav &other) = default; fmav(const fmav &other) = default;
fmav(fmav &other) = default; fmav(fmav &other) = default;
fmav(fmav &&other) = default; fmav(fmav &&other) = default;
// Not for public use!
fmav(membuf<T> &buf, const shape_t &shp_, const stride_t &str_) fmav(membuf<T> &buf, const shape_t &shp_, const stride_t &str_)
: fmav_info(shp_, str_), membuf<T>(buf) {} : fmav_info(shp_, str_), membuf<T>(buf) {}
fmav(const membuf<T> &buf, const shape_t &shp_, const stride_t &str_)
: fmav_info(shp_, str_), membuf<T>(buf) {}
}; };
template<size_t ndim> class mav_info template<size_t ndim> class mav_info
...@@ -262,7 +260,7 @@ template<typename T, size_t ndim> class mav: public mav_info<ndim>, public membu ...@@ -262,7 +260,7 @@ template<typename T, size_t ndim> class mav: public mav_info<ndim>, public membu
mav(mav &&other) = default; mav(mav &&other) = default;
operator fmav<T>() const operator fmav<T>() const
{ {
return fmav<T>(data(), {shp.begin(), shp.end()}, {str.begin(), str.end()}); return fmav<T>(*this, {shp.begin(), shp.end()}, {str.begin(), str.end()});
} }
operator fmav<T>() operator fmav<T>()
{ {
...@@ -280,23 +278,25 @@ template<typename T, size_t ndim> class mav: public mav_info<ndim>, public membu ...@@ -280,23 +278,25 @@ template<typename T, size_t ndim> class mav: public mav_info<ndim>, public membu
{ return vraw(idx(i,j)); } { return vraw(idx(i,j)); }
T &v(size_t i, size_t j, size_t k) T &v(size_t i, size_t j, size_t k)
{ return vraw(idx(i,j,k)); } { return vraw(idx(i,j,k)); }
void fill(const T &val) template<typename Func> void apply(Func func)
{ {
T *d2 = vdata(); T *d2 = vdata();
// FIXME: special cases for contiguous arrays and/or zeroing? // FIXME: special cases for contiguous arrays and/or zeroing?
if (ndim==1) if (ndim==1)
for (size_t i=0; i<shp[0]; ++i) for (size_t i=0; i<shp[0]; ++i)
d2[str[0]*i]=val; func(d2[str[0]*i]);
else if (ndim==2) else if (ndim==2)
for (size_t i=0; i<shp[0]; ++i) for (size_t i=0; i<shp[0]; ++i)
for (size_t j=0; j<shp[1]; ++j) for (size_t j=0; j<shp[1]; ++j)
d2[str[0]*i + str[1]*j] = val; func(d2[str[0]*i + str[1]*j]);
else if (ndim==3) else if (ndim==3)
for (size_t i=0; i<shp[0]; ++i) for (size_t i=0; i<shp[0]; ++i)
for (size_t j=0; j<shp[1]; ++j) for (size_t j=0; j<shp[1]; ++j)
for (size_t k=0; k<shp[2]; ++k) for (size_t k=0; k<shp[2]; ++k)
d2[str[0]*i + str[1]*j + str[2]*k] = val; func(d2[str[0]*i + str[1]*j + str[2]*k]);
} }
void fill(const T &val)
{ apply([val](T &v){v=val;}); }
}; };
template<typename T, size_t ndim> class MavIter template<typename T, size_t ndim> class MavIter
......
...@@ -39,7 +39,6 @@ using namespace std; ...@@ -39,7 +39,6 @@ using namespace std;
class ES_Kernel class ES_Kernel
{ {
private: private:
static constexpr double pi = 3.141592653589793238462643383279502884197;
double beta; double beta;
int p; int p;
vector<double> x, wgt, psi; vector<double> x, wgt, psi;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment