Skip to content

Commit 9023567

Browse files
committed
Update one-liners
1 parent 8b64d8d commit 9023567

File tree

1 file changed

+7
-19
lines changed

1 file changed

+7
-19
lines changed

pennylane_lightning/src/Gates.cpp

+7-19
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,7 @@ const vector<CplxType> Pennylane::SGate::matrix{
188188
0, IMAG };
189189

190190
void Pennylane::SGate::applyKernel(const StateVector& state, const std::vector<size_t>& indices, const std::vector<size_t>& externalIndices, bool inverse) {
191-
CplxType shift = IMAG;
192-
if (inverse == true) {shift *= -1;}
191+
CplxType shift = (inverse == true) ? -IMAG : IMAG;
193192

194193
for (const size_t& externalIndex : externalIndices) {
195194
CplxType* shiftedState = state.arr + externalIndex;
@@ -213,8 +212,7 @@ const vector<CplxType> Pennylane::TGate::matrix{
213212
0, Pennylane::TGate::shift };
214213

215214
void Pennylane::TGate::applyKernel(const StateVector& state, const std::vector<size_t>& indices, const std::vector<size_t>& externalIndices, bool inverse) {
216-
CplxType shift = Pennylane::TGate::shift;
217-
if (inverse == true) {shift = conj(Pennylane::TGate::shift);}
215+
CplxType shift = (inverse == true) ? conj(Pennylane::TGate::shift) : Pennylane::TGate::shift;
218216

219217
for (const size_t& externalIndex : externalIndices) {
220218
CplxType* shiftedState = state.arr + externalIndex;
@@ -240,9 +238,7 @@ Pennylane::RotationXGate::RotationXGate(double rotationAngle)
240238
{}
241239

242240
void Pennylane::RotationXGate::applyKernel(const StateVector& state, const std::vector<size_t>& indices, const std::vector<size_t>& externalIndices, bool inverse) {
243-
CplxType js_ = js;
244-
245-
if (inverse == true) {js_ *= -1;}
241+
CplxType js_ = (inverse == true) ? -js : js;
246242

247243
for (const size_t& externalIndex : externalIndices) {
248244
CplxType* shiftedState = state.arr + externalIndex;
@@ -271,9 +267,7 @@ Pennylane::RotationYGate::RotationYGate(double rotationAngle)
271267
{}
272268

273269
void Pennylane::RotationYGate::applyKernel(const StateVector& state, const std::vector<size_t>& indices, const std::vector<size_t>& externalIndices, bool inverse) {
274-
CplxType s_ = s;
275-
276-
if (inverse == true) {s_ *= -1;}
270+
CplxType s_ = (inverse == true) ? -s : s;
277271

278272
for (const size_t& externalIndex : externalIndices) {
279273
CplxType* shiftedState = state.arr + externalIndex;
@@ -334,9 +328,7 @@ Pennylane::PhaseShiftGate::PhaseShiftGate(double rotationAngle)
334328
{}
335329

336330
void Pennylane::PhaseShiftGate::applyKernel(const StateVector& state, const std::vector<size_t>& indices, const std::vector<size_t>& externalIndices, bool inverse) {
337-
CplxType s = shift;
338-
339-
if (inverse == true){s = conj(shift);}
331+
CplxType s = (inverse == true) ? conj(shift) : shift;
340332

341333
for (const size_t& externalIndex : externalIndices) {
342334
CplxType* shiftedState = state.arr + externalIndex;
@@ -482,9 +474,7 @@ Pennylane::CRotationXGate::CRotationXGate(double rotationAngle)
482474
{}
483475

484476
void Pennylane::CRotationXGate::applyKernel(const StateVector& state, const std::vector<size_t>& indices, const std::vector<size_t>& externalIndices, bool inverse) {
485-
CplxType js_ = js;
486-
487-
if (inverse == true) {js_ *= -1;}
477+
CplxType js_ = (inverse == true) ? -js : js;
488478

489479
for (const size_t& externalIndex : externalIndices) {
490480
CplxType* shiftedState = state.arr + externalIndex;
@@ -515,9 +505,7 @@ Pennylane::CRotationYGate::CRotationYGate(double rotationAngle)
515505
{}
516506

517507
void Pennylane::CRotationYGate::applyKernel(const StateVector& state, const std::vector<size_t>& indices, const std::vector<size_t>& externalIndices, bool inverse) {
518-
CplxType s_ = s;
519-
520-
if (inverse == true) {s_ *= -1;}
508+
CplxType s_ = (inverse == true) ? -s : s;
521509

522510
for (const size_t& externalIndex : externalIndices) {
523511
CplxType* shiftedState = state.arr + externalIndex;

0 commit comments

Comments
 (0)