Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
pleroy committed Mar 16, 2024
1 parent e25b153 commit c1fd187
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 8 deletions.
75 changes: 68 additions & 7 deletions geometry/hilbert.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,16 @@ template<typename T1, typename T2 = T1>
struct Hilbert;

template<typename T1, typename T2>
requires quantity<T1> && quantity<T2> && (!std::is_same_v<T1, T2>)
requires quantity<T1> && quantity<T2>
struct Hilbert<T1, T2> : not_constructible {
static constexpr int dimension = 1;

using InnerProductType = Product<T1, T2>;
static InnerProductType InnerProduct(T1 const& t1, T2 const& t2);
};

template<typename T> requires quantity<T>
template<typename T>
requires quantity<T>
struct Hilbert<T, T> : not_constructible {
static constexpr int dimension = 1;

Expand All @@ -52,14 +53,29 @@ struct Hilbert<T, T> : not_constructible {
};

template<typename T1, typename T2>
requires hilbert<T1, T2> && (!std::is_same_v<T1, T2>)
requires hilbert<T1, T2>
struct Hilbert<T1, T2> : not_constructible {
static_assert(T1::dimension == T2::dimension);
static constexpr int dimension = T1::dimension;

using InnerProductType =
decltype(InnerProduct(std::declval<T1>(), std::declval<T2>()));
static InnerProductType InnerProduct(T1 const& t1, T2 const& t2);
static InnerProductType InnerProduct(T1 const& t1, T2 const& t2)
#if _MSC_FULL_VER == 193'431'937 || \
_MSC_FULL_VER == 193'431'942 || \
_MSC_FULL_VER == 193'431'944 || \
_MSC_FULL_VER == 193'532'216 || \
_MSC_FULL_VER == 193'532'217 || \
_MSC_FULL_VER == 193'632'532 || \
_MSC_FULL_VER == 193'632'535 || \
_MSC_FULL_VER == 193'732'822 || \
_MSC_FULL_VER == 193'833'135
{ // NOLINT
return _grassmann::internal::InnerProduct(t1, t2);
}
#else
; // NOLINT
#endif
};

template<typename T>
Expand All @@ -69,13 +85,58 @@ struct Hilbert<T, T> : not_constructible {

using InnerProductType =
decltype(InnerProduct(std::declval<T>(), std::declval<T>()));
static InnerProductType InnerProduct(T const& t1, T const& t2);
static InnerProductType InnerProduct(T const& t1, T const& t2)
#if _MSC_FULL_VER == 193'431'937 || \
_MSC_FULL_VER == 193'431'942 || \
_MSC_FULL_VER == 193'431'944 || \
_MSC_FULL_VER == 193'532'216 || \
_MSC_FULL_VER == 193'532'217 || \
_MSC_FULL_VER == 193'632'532 || \
_MSC_FULL_VER == 193'632'535 || \
_MSC_FULL_VER == 193'732'822 || \
_MSC_FULL_VER == 193'833'135
{ // NOLINT
return _grassmann::internal::InnerProduct(t1, t2);
}
#else
; // NOLINT
#endif

using Norm²Type = InnerProductType;
static Norm²Type Norm²(T const& t);
static Norm²Type Norm²(T const& t)
#if _MSC_FULL_VER == 193'431'937 || \
_MSC_FULL_VER == 193'431'942 || \
_MSC_FULL_VER == 193'431'944 || \
_MSC_FULL_VER == 193'532'216 || \
_MSC_FULL_VER == 193'532'217 || \
_MSC_FULL_VER == 193'632'532 || \
_MSC_FULL_VER == 193'632'535 || \
_MSC_FULL_VER == 193'732'822 || \
_MSC_FULL_VER == 193'833'135
{ // NOLINT
return t.Norm²();
}
#else
; // NOLINT
#endif

using NormType = decltype(std::declval<T>().Norm());
static NormType Norm(T const& t);
static NormType Norm(T const& t)
#if _MSC_FULL_VER == 193'431'937 || \
_MSC_FULL_VER == 193'431'942 || \
_MSC_FULL_VER == 193'431'944 || \
_MSC_FULL_VER == 193'532'216 || \
_MSC_FULL_VER == 193'532'217 || \
_MSC_FULL_VER == 193'632'532 || \
_MSC_FULL_VER == 193'632'535 || \
_MSC_FULL_VER == 193'732'822 || \
_MSC_FULL_VER == 193'833'135
{ // NOLINT
return t.Norm();
}
#else
; // NOLINT
#endif

using NormalizedType = Quotient<T, NormType>;
};
Expand Down
12 changes: 11 additions & 1 deletion geometry/hilbert_body.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace internal {
using namespace principia::quantities::_elementary_functions;

template<typename T1, typename T2>
requires quantity<T1> && quantity<T2> && (!std::is_same_v<T1, T2>)
requires quantity<T1> && quantity<T2>
auto Hilbert<T1, T2>::InnerProduct(T1 const& t1, T2 const& t2)
-> InnerProductType {
return t1 * t2;
Expand All @@ -36,6 +36,15 @@ auto Hilbert<T, T>::Norm(T const& t) -> NormType {
return Abs(t);
}

#if !(_MSC_FULL_VER == 193'431'937 || \
_MSC_FULL_VER == 193'431'942 || \
_MSC_FULL_VER == 193'431'944 || \
_MSC_FULL_VER == 193'532'216 || \
_MSC_FULL_VER == 193'532'217 || \
_MSC_FULL_VER == 193'632'532 || \
_MSC_FULL_VER == 193'632'535 || \
_MSC_FULL_VER == 193'732'822 || \
_MSC_FULL_VER == 193'833'135)
template<typename T1, typename T2>
requires hilbert<T1, T2>
auto Hilbert<T1, T2>::InnerProduct(T1 const& t1, T2 const& t2)
Expand Down Expand Up @@ -64,6 +73,7 @@ template<typename T>
auto Hilbert<T, T>::Norm(T const& t) -> NormType {
return t.Norm();
}
#endif

} // namespace internal
} // namespace _hilbert
Expand Down

0 comments on commit c1fd187

Please sign in to comment.