Skip to content

Commit

Permalink
Change size_t to ptrdiff_t (tensorflow#219)
Browse files Browse the repository at this point in the history
  • Loading branch information
jaeyoo authored Apr 23, 2020
1 parent 856e198 commit 6efc39a
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions tensorflow_quantum/core/ops/tfq_calculate_unitary_op.cc
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ class TfqSimulateStateOp : public tensorflow::OpKernel {
auto DoWork = [&](int start, int end) {
std::unique_ptr<UnitarySpace> state = GetUnitarySpace(1, 1);
int old_num_qubits = -1;
auto pad = std::complex<float>(-2, 0);
for (int i = start; i < end; i++) {
Program program = programs[i];
const int num = num_qubits[i];
Expand All @@ -106,24 +107,24 @@ class TfqSimulateStateOp : public tensorflow::OpKernel {
// Cast to size_t to keep windows compiler happy.
// We run less of a risk of overflowing size_t since
// this is a unitary and not a state.
output_tensor(static_cast<size_t>(i), static_cast<size_t>(j),
static_cast<size_t>(k)) = state->GetEntry(j, k);
output_tensor(static_cast<ptrdiff_t>(i), static_cast<ptrdiff_t>(j),
static_cast<ptrdiff_t>(k)) = state->GetEntry(j, k);
}
}
// -2 padding for lower portion.
for (uint64_t j = state_size; j < (uint64_t(1) << max_num_qubits);
j++) {
for (uint64_t k = 0; k < (uint64_t(1) << max_num_qubits); k++) {
output_tensor(static_cast<size_t>(i), static_cast<size_t>(j),
static_cast<size_t>(k)) = std::complex<float>(-2, 0);
output_tensor(static_cast<ptrdiff_t>(i), static_cast<ptrdiff_t>(j),
static_cast<ptrdiff_t>(k)) = pad;
}
}
// -2 padding for right portion.
for (uint64_t j = 0; j < state_size; j++) {
for (uint64_t k = state_size; k < (uint64_t(1) << max_num_qubits);
k++) {
output_tensor(static_cast<size_t>(i), static_cast<size_t>(j),
static_cast<size_t>(k)) = std::complex<float>(-2, 0);
output_tensor(static_cast<ptrdiff_t>(i), static_cast<ptrdiff_t>(j),
static_cast<ptrdiff_t>(k)) = pad;
}
}
old_num_qubits = num;
Expand Down

0 comments on commit 6efc39a

Please sign in to comment.