Skip to content

Commit b9aabdc

Browse files
committed
refactor(cudensitymat): use dimension directly in overlap()
Remove redundant local `size` alias and pass `dimension` directly to cudaMemcpy.
1 parent 83e5f39 commit b9aabdc

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

runtime/nvqir/cudensitymat/CuDensityMatState.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,13 @@ CuDensityMatState::overlap(const cudaq::SimulationState &other) {
3939

4040
if (!isDensityMatrix) {
4141
Eigen::VectorXcd state(dimension);
42-
const auto size = dimension;
4342
HANDLE_CUDA_ERROR(cudaMemcpy(state.data(), devicePtr,
44-
size * sizeof(std::complex<double>),
43+
dimension * sizeof(std::complex<double>),
4544
cudaMemcpyDeviceToHost));
4645

4746
Eigen::VectorXcd otherState(dimension);
4847
HANDLE_CUDA_ERROR(cudaMemcpy(otherState.data(), other.getTensor().data,
49-
size * sizeof(std::complex<double>),
48+
dimension * sizeof(std::complex<double>),
5049
cudaMemcpyDeviceToHost));
5150
return std::abs(std::inner_product(
5251
state.begin(), state.end(), otherState.begin(),
@@ -59,14 +58,13 @@ CuDensityMatState::overlap(const cudaq::SimulationState &other) {
5958
// The matrix side length is sqrt(dimension).
6059
const std::size_t matDim = static_cast<std::size_t>(std::sqrt(dimension));
6160
Eigen::MatrixXcd state(matDim, matDim);
62-
const auto size = dimension;
6361
HANDLE_CUDA_ERROR(cudaMemcpy(state.data(), devicePtr,
64-
size * sizeof(std::complex<double>),
62+
dimension * sizeof(std::complex<double>),
6563
cudaMemcpyDeviceToHost));
6664

6765
Eigen::MatrixXcd otherState(matDim, matDim);
6866
HANDLE_CUDA_ERROR(cudaMemcpy(otherState.data(), other.getTensor().data,
69-
size * sizeof(std::complex<double>),
67+
dimension * sizeof(std::complex<double>),
7068
cudaMemcpyDeviceToHost));
7169

7270
return (state.adjoint() * otherState).trace();

0 commit comments

Comments
 (0)