Dhairya Malhotra 7 年之前
父節點
當前提交
ebeba0b405
共有 2 個文件被更改,包括 30 次插入15 次删除
  1. 22 7
      include/sctl/fft_wrapper.hpp
  2. 8 8
      include/sctl/mem_mgr.hpp

+ 22 - 7
include/sctl/fft_wrapper.hpp

@@ -20,49 +20,64 @@ namespace SCTL_NAMESPACE {
 
 template <class ValueType> class Complex {
   public:
+    Complex<ValueType>(ValueType r=0, ValueType i=0) : real(r), imag(i) {}
 
-    Complex<ValueType> operator*(const Complex<ValueType>& x){
+    Complex<ValueType> operator*(const Complex<ValueType>& x) const {
       Complex<ValueType> z;
       z.real = real * x.real - imag * x.imag;
-      z.imag = imag * x.real - real * x.imag;
+      z.imag = imag * x.real + real * x.imag;
       return z;
     }
 
-    Complex<ValueType> operator*(const ValueType& x){
+    Complex<ValueType> operator*(const ValueType& x) const {
       Complex<ValueType> z;
       z.real = real * x;
       z.imag = imag * x;
       return z;
     }
 
-    Complex<ValueType> operator+(const Complex<ValueType>& x){
+    Complex<ValueType> operator+(const Complex<ValueType>& x) const {
       Complex<ValueType> z;
       z.real = real + x.real;
       z.imag = imag + x.imag;
       return z;
     }
 
-    Complex<ValueType> operator+(const ValueType& x){
+    Complex<ValueType> operator+(const ValueType& x) const {
       Complex<ValueType> z;
       z.real = real + x;
       z.imag = imag;
       return z;
     }
 
-    Complex<ValueType> operator-(const Complex<ValueType>& x){
+    Complex<ValueType> operator-(const Complex<ValueType>& x) const {
       Complex<ValueType> z;
       z.real = real - x.real;
       z.imag = imag - x.imag;
       return z;
     }
 
-    Complex<ValueType> operator-(const ValueType& x){
+    Complex<ValueType> operator-(const ValueType& x) const {
       Complex<ValueType> z;
       z.real = real - x;
       z.imag = imag;
       return z;
     }
 
+    Complex<ValueType> operator-() const {
+      Complex<ValueType> z;
+      z.real = -real;
+      z.imag = -imag;
+      return z;
+    }
+
+    Complex<ValueType> conj() const {
+      Complex<ValueType> z;
+      z.real = real;
+      z.imag = -imag;
+      return z;
+    }
+
     ValueType real;
     ValueType imag;
 };

+ 8 - 8
include/sctl/mem_mgr.hpp

@@ -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 { // 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
+template <class ValueType, Long DIM> class StaticArray {
   typedef Long difference_type;
 
  public:
@@ -254,19 +254,19 @@ template <class ValueType, Long DIM> class StaticArray { // Warning: objects are
   ~StaticArray() = default;
 
   // value_type* like operators
-  const ValueType& operator*() const { return *arr_; }
+  const ValueType& operator*() const { return *(ConstIterator<ValueType>)*this; }
 
-  ValueType& operator*() { return *arr_; }
+  ValueType& operator*() { return *(Iterator<ValueType>)*this; }
 
-  const ValueType* operator->() const { return arr_; }
+  const ValueType* operator->() const { return (ConstIterator<ValueType>)*this; }
 
-  ValueType* operator->() { return arr_; }
+  ValueType* operator->() { return (Iterator<ValueType>)*this; }
 
-  const ValueType& operator[](difference_type off) const { return arr_[off]; }
+  const ValueType& operator[](difference_type off) const { return ((ConstIterator<ValueType>)*this)[off]; }
 
-  ValueType& operator[](difference_type off) { return arr_[off]; }
+  ValueType& operator[](difference_type off) { return ((Iterator<ValueType>)*this)[off]; }
 
-  operator ConstIterator<ValueType>() const { return Iterator<ValueType>(arr_, DIM); }
+  operator ConstIterator<ValueType>() const { return ConstIterator<ValueType>(arr_, DIM); }
 
   operator Iterator<ValueType>() { return Iterator<ValueType>(arr_, DIM); }