Skip to content

Commit 90972a6

Browse files
committed
Adding operator* method
Signed-off-by: Sachin Pisal <[email protected]>
1 parent 3d8b598 commit 90972a6

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

runtime/cudaq/cudm_state.h

+4
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,10 @@ class cudm_state {
9999
/// @return The new state after multiplying scalar with the current state.
100100
cudm_state &operator*=(const std::complex<double> &scalar);
101101

102+
cudm_state operator*(double scalar) &&;
103+
104+
double norm() const;
105+
102106
private:
103107
std::vector<std::complex<double>> rawData_;
104108
std::complex<double> *gpuData_;

runtime/cudaq/dynamics/cudm_state.cpp

+15
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,21 @@ cudm_state &cudm_state::operator*=(const std::complex<double> &scalar) {
181181
return *this;
182182
}
183183

184+
cudm_state cudm_state::operator*(double scalar) && {
185+
this->operator*=(scalar);
186+
return std::move(*this);
187+
}
188+
189+
double cudm_state::norm() const {
190+
std::vector<std::complex<double>> rawData = this->get_raw_data();
191+
192+
double norm = 0.0;
193+
for (const auto &val : rawData) {
194+
norm += std::norm(val);
195+
}
196+
return std::sqrt(norm);
197+
}
198+
184199
std::string cudm_state::dump() const {
185200
if (!is_initialized()) {
186201
throw std::runtime_error("State is not initialized.");

0 commit comments

Comments
 (0)