Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert SQRT2 definition to v0.31.0 #479

Merged
merged 8 commits into from
Aug 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@

### Bug fixes

* Do no import `sqrt2_v` from `<numbers>` in `Util.hpp` to resolve issue with Lightning-GPU builds.
[(#479)](https://github.com/PennyLaneAI/pennylane-lightning/pull/479)

* Update the CMake internal references to enable sub-project compilation with affecting the parent package.
[(#478)](https://github.com/PennyLaneAI/pennylane-lightning/pull/478)

Expand Down
2 changes: 1 addition & 1 deletion pennylane_lightning/core/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@
Version number (major.minor.patch[-label])
"""

__version__ = "0.32.0-dev9"
__version__ = "0.32.0-dev10"
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include <algorithm>
#include <numbers>
#include <random>
#include <span>
#include <vector>
Expand Down
20 changes: 18 additions & 2 deletions pennylane_lightning/core/src/utils/Util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

#include <cmath>
#include <complex>
#include <numbers> // sqrt2_v
#include <numbers>
#include <numeric> // transform_reduce
#include <set>
#include <type_traits> // is_same_v
Expand Down Expand Up @@ -175,7 +175,15 @@ inline static constexpr auto IMAG() -> ComplexT<T> {
* @return constexpr T sqrt(2)
*/
template <class T> inline static constexpr auto SQRT2() -> T {
mlxd marked this conversation as resolved.
Show resolved Hide resolved
#if __cpp_lib_math_constants >= 201907L
return std::numbers::sqrt2_v<T>;
#else
if constexpr (std::is_same_v<T, float>) {
return 0x1.6a09e6p+0F; // NOLINT: To be replaced in C++20
} else {
return 0x1.6a09e667f3bcdp+0; // NOLINT: To be replaced in C++20
}
#endif
}

/**
Expand All @@ -187,7 +195,15 @@ template <class T> inline static constexpr auto SQRT2() -> T {
*/
template <template <class> class ComplexT, class T>
inline static constexpr auto SQRT2() -> ComplexT<T> {
#if __cpp_lib_math_constants >= 201907L
return std::numbers::sqrt2_v<T>;
#else
if constexpr (std::is_same_v<T, float>) {
return 0x1.6a09e6p+0F; // NOLINT: To be replaced in C++20
} else {
return 0x1.6a09e667f3bcdp+0; // NOLINT: To be replaced in C++20
}
#endif
}

/**
Expand All @@ -209,7 +225,7 @@ template <class T> inline static constexpr auto INVSQRT2() -> T {
*/
template <template <class> class ComplexT, class T>
inline static constexpr auto INVSQRT2() -> ComplexT<T> {
return {1 / SQRT2<T>()};
return static_cast<ComplexT<T>>(INVSQRT2<T>());
}

/**
Expand Down
Loading