Dhairya Malhotra преди 7 години
родител
ревизия
b48ece12a8
променени са 3 файла, в които са добавени 13 реда и са изтрити 26 реда
  1. 7 8
      include/sctl/mem_mgr.hpp
  2. 6 8
      include/sctl/mem_mgr.txx
  3. 0 10
      include/sctl/sph_harm.txx

+ 7 - 8
include/sctl/mem_mgr.hpp

@@ -55,7 +55,7 @@ template <class ValueType> class ConstIterator {
   //   SCTL_ASSERT(false);
   // }
 
-  ConstIterator(const ValueType* base_, difference_type len_, bool dynamic_alloc = false);
+  ConstIterator(pointer base_, difference_type len_, bool dynamic_alloc = false);
 
   template <class AnotherType> explicit ConstIterator(const ConstIterator<AnotherType>& I) {
     this->base = I.base;
@@ -69,7 +69,7 @@ template <class ValueType> class ConstIterator {
   // value_type* like operators
   reference operator*() const;
 
-  const value_type* operator->() const;
+  pointer operator->() const;
 
   reference operator[](difference_type off) const;
 
@@ -123,7 +123,7 @@ template <class ValueType> class ConstIterator {
 
   difference_type operator-(const ConstIterator& I) const {
     // if (base != I.base) SCTL_WARN("comparing two unrelated memory addresses.");
-    Long diff = ((ValueType*)(base + offset)) - ((ValueType*)(I.base + I.offset));
+    Long diff = ((pointer)(base + offset)) - ((pointer)(I.base + I.offset));
     SCTL_ASSERT_MSG(I.base + I.offset + diff * (Long)sizeof(ValueType) == base + offset, "invalid memory address alignment.");
     return diff;
   }
@@ -171,9 +171,9 @@ template <class ValueType> class Iterator : public ConstIterator<ValueType> {
  public:
   Iterator() : ConstIterator<ValueType>() {}
 
-  template <size_t LENGTH> Iterator(ValueType (&base_)[LENGTH]) : ConstIterator<ValueType>(base_) {}
+  //template <size_t LENGTH> Iterator(ValueType (&base_)[LENGTH]) : ConstIterator<ValueType>(base_) {}
 
-  Iterator(ValueType* base_, difference_type len_, bool dynamic_alloc = false) : ConstIterator<ValueType>(base_, len_, dynamic_alloc) {}
+  Iterator(pointer base_, difference_type len_, bool dynamic_alloc = false) : ConstIterator<ValueType>(base_, len_, dynamic_alloc) {}
 
   template <class AnotherType> explicit Iterator(const ConstIterator<AnotherType>& I) : ConstIterator<ValueType>(I) {}
 
@@ -235,7 +235,7 @@ template <class ValueType> class Iterator : public ConstIterator<ValueType> {
   difference_type operator-(const ConstIterator<ValueType>& I) const { return static_cast<const ConstIterator<ValueType>&>(*this) - I; }
 };
 
-template <class ValueType, Long DIM> class StaticArray : public Iterator<ValueType> { // Warning: objects are not byte-copyable
+template <class ValueType, Long DIM> class StaticArray : public Iterator<ValueType> { // Warning: objects are not byte-copyable // TODO: Can be made by copyable by not inheriting Iterator and can also add memory header and padding to detect additional memory errors
 
  public:
   StaticArray();
@@ -249,12 +249,11 @@ template <class ValueType, Long DIM> class StaticArray : public Iterator<ValueTy
   StaticArray(std::initializer_list<ValueType> arr_) : StaticArray() {
     // static_assert(arr_.size() <= DIM, "too many initializer values"); // allowed in C++14
     SCTL_ASSERT_MSG(arr_.size() <= DIM, "too many initializer values");
-    for (Long i = 0; i < (Long)arr_.size(); i++) arr[i] = arr_.begin()[i];
+    for (Long i = 0; i < (Long)arr_.size(); i++) (*this)[i] = arr_.begin()[i];
   }
 
  private:
 
-  Iterator<ValueType> arr;
   ValueType arr_[DIM];
 };
 

+ 6 - 8
include/sctl/mem_mgr.txx

@@ -43,7 +43,7 @@ template <class ValueType> inline typename ConstIterator<ValueType>::reference C
   return *(ValueType*)(base + offset);
 }
 
-template <class ValueType> inline const typename ConstIterator<ValueType>::value_type* ConstIterator<ValueType>::operator->() const {
+template <class ValueType> inline typename ConstIterator<ValueType>::pointer ConstIterator<ValueType>::operator->() const {
   this->IteratorAssertChecks();
   return (ValueType*)(base + offset);
 }
@@ -69,19 +69,17 @@ template <class ValueType> inline typename Iterator<ValueType>::reference Iterat
 }
 
 template <class ValueType, Long DIM> inline StaticArray<ValueType, DIM>::StaticArray() {
-  // arr = aligned_new<ValueType>(DIM);
-  arr = Ptr2Itr<ValueType>(arr_, DIM);
-  Iterator<ValueType>::operator=(arr);
+  //Iterator<ValueType>::operator=(aligned_new<ValueType>(DIM));
+  Iterator<ValueType>::operator=(Ptr2Itr<ValueType>(arr_, DIM));
 }
 
 template <class ValueType, Long DIM> inline StaticArray<ValueType, DIM>::~StaticArray() {
-  // aligned_delete<ValueType>(arr);
+  // aligned_delete<ValueType>(*this);
 }
 
 template <class ValueType, Long DIM> inline StaticArray<ValueType, DIM>::StaticArray(const StaticArray& I) {
-  // arr = aligned_new<ValueType>(DIM);
-  arr = Ptr2Itr<ValueType>(arr_, DIM);
-  Iterator<ValueType>::operator=(arr);
+  //Iterator<ValueType>::operator=(aligned_new<ValueType>(DIM));
+  Iterator<ValueType>::operator=(Ptr2Itr<ValueType>(arr_, DIM));
   for (Long i = 0; i < DIM; i++) (*this)[i] = I[i];
 }
 

+ 0 - 10
include/sctl/sph_harm.txx

@@ -779,7 +779,6 @@ template <class Real> void SphericalHarmonics<Real>::LegPoly(Vector<Real>& poly_
 
 template <class Real> const Vector<Real>& SphericalHarmonics<Real>::LegendreNodes(Long p){
   assert(p<SCTL_SHMAXDEG);
-  assert(MatrixStore().Qx_.size() == SCTL_SHMAXDEG);
   Vector<Real>& Qx=MatrixStore().Qx_[p];
   if(!Qx.Dim()){
     Vector<double> qx1(p+1);
@@ -794,7 +793,6 @@ template <class Real> const Vector<Real>& SphericalHarmonics<Real>::LegendreNode
 
 template <class Real> const Vector<Real>& SphericalHarmonics<Real>::LegendreWeights(Long p){
   assert(p<SCTL_SHMAXDEG);
-  assert(MatrixStore().Qw_.size() == SCTL_SHMAXDEG);
   Vector<Real>& Qw=MatrixStore().Qw_[p];
   if(!Qw.Dim()){
     Vector<double> qx1(p+1);
@@ -809,7 +807,6 @@ template <class Real> const Vector<Real>& SphericalHarmonics<Real>::LegendreWeig
 
 template <class Real> const Vector<Real>& SphericalHarmonics<Real>::SingularWeights(Long p1){
   assert(p1<SCTL_SHMAXDEG);
-  assert(MatrixStore().Sw_.size() == SCTL_SHMAXDEG);
   Vector<Real>& Sw=MatrixStore().Sw_[p1];
   if(!Sw.Dim()){
     const Vector<Real>& qx1 = LegendreNodes(p1);
@@ -841,7 +838,6 @@ template <class Real> const Vector<Real>& SphericalHarmonics<Real>::SingularWeig
 
 template <class Real> const Matrix<Real>& SphericalHarmonics<Real>::MatFourier(Long p0, Long p1){
   assert(p0<SCTL_SHMAXDEG && p1<SCTL_SHMAXDEG);
-  assert(MatrixStore().Mf_ .size() == SCTL_SHMAXDEG*SCTL_SHMAXDEG);
   Matrix<Real>& Mf =MatrixStore().Mf_ [p0*SCTL_SHMAXDEG+p1];
   if(!Mf.Dim(0)){
     const Real SQRT2PI=sqrt(2*M_PI);
@@ -863,7 +859,6 @@ template <class Real> const Matrix<Real>& SphericalHarmonics<Real>::MatFourier(L
 
 template <class Real> const Matrix<Real>& SphericalHarmonics<Real>::MatFourierInv(Long p0, Long p1){
   assert(p0<SCTL_SHMAXDEG && p1<SCTL_SHMAXDEG);
-  assert(MatrixStore().Mfinv_ .size() == SCTL_SHMAXDEG*SCTL_SHMAXDEG);
   Matrix<Real>& Mf =MatrixStore().Mfinv_ [p0*SCTL_SHMAXDEG+p1];
   if(!Mf.Dim(0)){
     const Real INVSQRT2PI=1.0/sqrt(2*M_PI)/p0;
@@ -908,7 +903,6 @@ template <class Real> const FFT<Real>& SphericalHarmonics<Real>::OpFourierInv(Lo
 
 template <class Real> const Matrix<Real>& SphericalHarmonics<Real>::MatFourierGrad(Long p0, Long p1){
   assert(p0<SCTL_SHMAXDEG && p1<SCTL_SHMAXDEG);
-  assert(MatrixStore().Mdf_.size() == SCTL_SHMAXDEG*SCTL_SHMAXDEG);
   Matrix<Real>& Mdf=MatrixStore().Mdf_[p0*SCTL_SHMAXDEG+p1];
   if(!Mdf.Dim(0)){
     const Real SQRT2PI=sqrt(2*M_PI);
@@ -930,7 +924,6 @@ template <class Real> const Matrix<Real>& SphericalHarmonics<Real>::MatFourierGr
 
 template <class Real> const std::vector<Matrix<Real>>& SphericalHarmonics<Real>::MatLegendre(Long p0, Long p1){
   assert(p0<SCTL_SHMAXDEG && p1<SCTL_SHMAXDEG);
-  assert(MatrixStore().Ml_ .size() == SCTL_SHMAXDEG*SCTL_SHMAXDEG);
   std::vector<Matrix<Real>>& Ml =MatrixStore().Ml_ [p0*SCTL_SHMAXDEG+p1];
   if(!Ml.size()){
     const Vector<Real>& qx1 = LegendreNodes(p1);
@@ -949,7 +942,6 @@ template <class Real> const std::vector<Matrix<Real>>& SphericalHarmonics<Real>:
 
 template <class Real> const std::vector<Matrix<Real>>& SphericalHarmonics<Real>::MatLegendreInv(Long p0, Long p1){
   assert(p0<SCTL_SHMAXDEG && p1<SCTL_SHMAXDEG);
-  assert(MatrixStore().Mlinv_ .size() == SCTL_SHMAXDEG*SCTL_SHMAXDEG);
   std::vector<Matrix<Real>>& Ml =MatrixStore().Mlinv_ [p0*SCTL_SHMAXDEG+p1];
   if(!Ml.size()){
     const Vector<Real>& qx1 = LegendreNodes(p0);
@@ -975,7 +967,6 @@ template <class Real> const std::vector<Matrix<Real>>& SphericalHarmonics<Real>:
 
 template <class Real> const std::vector<Matrix<Real>>& SphericalHarmonics<Real>::MatLegendreGrad(Long p0, Long p1){
   assert(p0<SCTL_SHMAXDEG && p1<SCTL_SHMAXDEG);
-  assert(MatrixStore().Mdl_.size() == SCTL_SHMAXDEG*SCTL_SHMAXDEG);
   std::vector<Matrix<Real>>& Mdl=MatrixStore().Mdl_[p0*SCTL_SHMAXDEG+p1];
   if(!Mdl.size()){
     const Vector<Real>& qx1 = LegendreNodes(p1);
@@ -1007,7 +998,6 @@ template <class Real> const std::vector<Matrix<Real>>& SphericalHarmonics<Real>:
   }
 
   assert(p0<SCTL_SHMAXDEG);
-  assert(MatrixStore().Mr_.size() == SCTL_SHMAXDEG);
   std::vector<Matrix<Real>>& Mr=MatrixStore().Mr_[p0];
   if(!Mr.size()){
     const Real SQRT2PI=sqrt(2*M_PI);