diff --git a/mat.cc b/mat.cc index a5f315c..976e7e7 100644 --- a/mat.cc +++ b/mat.cc @@ -550,6 +550,7 @@ template const NRMat NRMat::operator&(const NRMat &b) const { SAME_LOC(*this, b); NRMat result((T)0, nn + b.nn, mm + b.mm, getlocation()); + if(!LA_traits::is_plaindata()) laerror("only implemented for plain data"); #ifdef CUDALA if(location == cpu){ #endif @@ -738,6 +739,7 @@ const NRMat NRMat::submatrix(const int fromrow, const int torow, const int const int n = torow - fromrow + 1; const int m = tocol - fromcol + 1; NRMat r(n, m, getlocation()); + if(!LA_traits::is_plaindata()) laerror("only implemented for plain data"); #ifdef CUDALA if(location == cpu){ @@ -775,6 +777,7 @@ void NRMat::storesubmatrix(const int fromrow, const int fromcol, const NRMat if(fromrow<0 || fromrow>=nn || torow>=nn || fromcol<0 || fromcol>=mm || tocol>=mm) laerror("bad indices in storesubmatrix"); #endif SAME_LOC(*this, rhs); + if(!LA_traits::is_plaindata()) laerror("only implemented for plain data"); const int m = tocol - fromcol + 1; for(register int i = fromrow; i <= torow; ++i){ diff --git a/mat.h b/mat.h index e7d6017..4391179 100644 --- a/mat.h +++ b/mat.h @@ -478,7 +478,7 @@ NRMat::NRMat(const T &a, const int n, const int m, const GPUID loc) : nn(n), #else p = v = new T[nm]; #endif - if (a != (T)0){ + if (!LA_traits::is_plaindata() || a != (T)0){ for (register int i=0; i::NRMat(const T &a, const int n, const int m, const GPUID loc) : nn(n), if(sizeof(T)%sizeof(float) != 0)laerror("memory alignment error"); v = (T*)gpualloc(nm*sizeof(T)); + if(!LA_traits::is_plaindata()) laerror("only implemented for plain data"); smart_gpu_set(nm, a, v); } #endif @@ -522,7 +523,7 @@ inline NRMat::NRMat(const T (&a)[R][C]) : count(new int) { #endif #ifdef CUDALA }else{ - if!LA_traits::is_plaindata()) laerror("only implemented for plain data"); + if(!LA_traits::is_plaindata()) laerror("only implemented for plain data"); v = (T*) gpualloc(nn*mm*sizeof(T)); cublasSetVector(nm, sizeof(T), a, 1, v, 1); } @@ -554,13 +555,14 @@ NRMat::NRMat(const T &a, const int n, const int m) : nn(n), mm(m), count(new #else p = v = new T[nm]; #endif - if (a != (T)0) + if (!LA_traits::is_plaindata() || a != (T)0) for (register int i=0; i::is_plaindata()) laerror("only implemented for plain data"); smart_gpu_set(nm, a, v); } #endif @@ -588,14 +590,17 @@ NRMat::NRMat(const T *a, const int n, const int m) : nn(n), mm(m), count(new v = new T*[n]; v[0] = new T[nm]; for (register int i=1; i::is_plaindata()) memcpy(v[0], a, nm*sizeof(T)); + else for(int i=0; i::is_plaindata()) memcpy(v, a, nm*sizeof(T)); + else for(int i=0; i::is_plaindata()) laerror("only implemented for plain data"); cublasSetVector(nm, sizeof(T), a, 1, v, 1); } #endif diff --git a/smat.h b/smat.h index 052c7a1..c2c74e2 100644 --- a/smat.h +++ b/smat.h @@ -230,12 +230,13 @@ inline NRSMat::NRSMat(const T& a, const int n) : nn(n), count(new int(1)) { if(location == cpu){ #endif v = new T[NN2]; - if(a != (T)0) for(register size_t i = 0; i::is_plaindata() || a != (T)0) for(register size_t i = 0; i::is_plaindata()) laerror("only implemented for plain data"); cublasSetVector(NN2, sizeof(T), &a, 0, v, 1); } #endif @@ -253,10 +254,12 @@ inline NRSMat::NRSMat(const T *a, const int n) : nn(n), count(new int(1)) { location = DEFAULT_LOC; if(location == cpu){ #endif - memcpy(v, a, NN2*sizeof(T)); + if(LA_traits::is_plaindata()) memcpy(v, a, NN2*sizeof(T)); + else for( int i=0; i::is_plaindata()) laerror("only implemented for plain data"); cublasSetVector(NN2, sizeof(T), a, 1, v, 1); } #endif diff --git a/vec.cc b/vec.cc index 7fe3348..fc121ce 100644 --- a/vec.cc +++ b/vec.cc @@ -443,7 +443,7 @@ NRVec& NRVec::operator=(const T &a){ NOT_GPU(*this); copyonwrite(); - if(a != (T)0){ + if(!LA_traits::is_plaindata() || a != (T)0){ for(register int i=0; i +const int NRVec::find(const T &val) const +{ +for(int i=0; i +const int NRVec::findthr(const T &val, const typename LA_traits::normtype &thr) const +{ +for(int i=0; i::normtype &thr=0) const; + //! determine the maximal element (in the absolute value) of this vector inline const T amax() const; //! determine the minimal element (in the absolute value) of this vector @@ -570,14 +574,15 @@ inline NRVec::NRVec(const T& a, const int n): nn(n), count(new int) { if(location == cpu){ #endif v = new T[n]; - if(a != (T)0){ - for(register int i=0; i::is_plaindata() || a != (T)0){ + for(register int i=0; i::is_plaindata()) laerror("only implemented for plain data"); smart_gpu_set(n, a, v); } #endif @@ -602,7 +607,7 @@ inline NRVec::NRVec(const T (&a)[SIZE]) : count(new int) { #ifdef CUDALA }else{ v = (T*) gpualloc(nn*sizeof(T)); - if!LA_traits::is_plaindata()) laerror("only implemented for plain data"); + if(!LA_traits::is_plaindata()) laerror("only implemented for plain data"); cublasSetVector(nn, sizeof(T), a, 1, v, 1); TEST_CUBLAS("cublasSetVector"); } @@ -626,10 +631,12 @@ inline NRVec::NRVec(const T *a, const int n): nn(n), count(new int) { #endif v = new T[n]; *count = 1; - memcpy(v, a, n*sizeof(T)); + if(LA_traits::is_plaindata()) memcpy(v, a, n*sizeof(T)); + else for( int i=0; i::is_plaindata()) laerror("only implemented for plain data"); cublasSetVector(n, sizeof(T), a, 1, v, 1); TEST_CUBLAS("cublasSetVector"); } @@ -653,10 +660,12 @@ inline NRVec::NRVec(T *a, const int n, bool skeleton) : nn(n), count(new int) #endif v = new T[n]; *count = 1; - memcpy(v, a, n*sizeof(T)); + if(LA_traits::is_plaindata()) memcpy(v, a, n*sizeof(T)); + else for( int i=0; i::is_plaindata()) laerror("only implemented for plain data"); cublasSetVector(n, sizeof(T), a, 1, v, 1); TEST_CUBLAS("cublasSetVector"); }