11#include < cassert>
2- #include < cstring >
2+ #include < utility >
33
4+ #include < GridKit/AutomaticDifferentiation/DependencyTracking/Variable.hpp>
45#include < GridKit/LinearAlgebra/Vector/Vector.hpp>
56#include < GridKit/Utilities/Logger/Logger.hpp>
67
@@ -39,8 +40,8 @@ namespace GridKit
3940 : n_capacity_(n),
4041 k_ (k),
4142 n_size_(n),
42- gpu_updated_(new bool [k ]),
43- cpu_updated_(new bool [k ])
43+ gpu_updated_(new bool [static_cast <std:: size_t >(k) ]),
44+ cpu_updated_(new bool [static_cast <std:: size_t >(k) ])
4445 {
4546 setHostUpdated (false );
4647 setDeviceUpdated (false );
@@ -52,13 +53,64 @@ namespace GridKit
5253 */
5354 template <typename ScalarT, typename IdxT>
5455 Vector<ScalarT, IdxT>::~Vector ()
56+ {
57+ release ();
58+ }
59+
60+ template <typename ScalarT, typename IdxT>
61+ Vector<ScalarT, IdxT>::Vector(Vector&& other) noexcept
62+ {
63+ *this = std::move (other);
64+ }
65+
66+ template <typename ScalarT, typename IdxT>
67+ Vector<ScalarT, IdxT>& Vector<ScalarT, IdxT>::operator =(Vector&& other) noexcept
68+ {
69+ if (this != &other)
70+ {
71+ release ();
72+
73+ n_capacity_ = other.n_capacity_ ;
74+ k_ = other.k_ ;
75+ n_size_ = other.n_size_ ;
76+ d_data_ = other.d_data_ ;
77+ h_data_ = other.h_data_ ;
78+ gpu_updated_ = other.gpu_updated_ ;
79+ cpu_updated_ = other.cpu_updated_ ;
80+ owns_gpu_data_ = other.owns_gpu_data_ ;
81+ owns_cpu_data_ = other.owns_cpu_data_ ;
82+ mem_ = std::move (other.mem_ );
83+
84+ other.n_capacity_ = 0 ;
85+ other.k_ = 0 ;
86+ other.n_size_ = 0 ;
87+ other.d_data_ = nullptr ;
88+ other.h_data_ = nullptr ;
89+ other.gpu_updated_ = nullptr ;
90+ other.cpu_updated_ = nullptr ;
91+ }
92+
93+ return *this ;
94+ }
95+
96+ template <typename ScalarT, typename IdxT>
97+ void Vector<ScalarT, IdxT>::release()
5598 {
5699 if (owns_cpu_data_ && h_data_)
100+ {
57101 mem_.deleteOnHost (h_data_);
102+ }
58103 if (owns_gpu_data_ && d_data_)
104+ {
59105 mem_.deleteOnDevice (d_data_);
106+ }
60107 delete[] gpu_updated_;
61108 delete[] cpu_updated_;
109+
110+ h_data_ = nullptr ;
111+ d_data_ = nullptr ;
112+ gpu_updated_ = nullptr ;
113+ cpu_updated_ = nullptr ;
62114 }
63115
64116 /* *
@@ -999,9 +1051,12 @@ namespace GridKit
9991051 std::fill (gpu_updated_, gpu_updated_ + k_, is_updated);
10001052 }
10011053
1002- // template class Vector<double, long int>;
1054+ template class Vector <double , long int >;
10031055 template class Vector <double , size_t >;
1004- // template class Vector<double, int>;
1056+ template class Vector <double , int >;
1057+ template class Vector <DependencyTracking::Variable, long int >;
1058+ template class Vector <DependencyTracking::Variable, size_t >;
1059+ template class Vector <DependencyTracking::Variable, int >;
10051060
10061061 } // namespace LinearAlgebra
10071062} // namespace GridKit
0 commit comments