Skip to content
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: 2 additions & 1 deletion include/Mathter/Common/Functional.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include "TypeTraits.hpp"

#include <algorithm>
#include <cmath>
#include <type_traits>

Expand Down Expand Up @@ -332,4 +333,4 @@ struct sqrt<void> {
}
};

} // namespace mathter
} // namespace mathter
20 changes: 11 additions & 9 deletions include/Mathter/Decompositions/DecomposeLU.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ struct DecompositionLU {


template <class T, int Dim, eMatrixOrder Order, eMatrixLayout Layout, bool Packed>
DecompositionLU(const Matrix<T, Dim, Dim, Order, Layout, Packed>&,
const Matrix<T, Dim, Dim, Order, Layout, Packed>&) -> DecompositionLU<T, Dim, Order, Layout, Packed>;
DecompositionLU(Matrix<T, Dim, Dim, Order, Layout, Packed>,
Matrix<T, Dim, Dim, Order, Layout, Packed>) -> DecompositionLU<T, Dim, Order, Layout, Packed>;


template <class T, int Dim, eMatrixOrder Order, eMatrixLayout Layout, bool Packed>
Expand Down Expand Up @@ -73,7 +73,7 @@ auto DecompositionLU<T, Dim, Order, Layout, Packed>::Solve(const Vector<T2, Dim,


template <class T, int Dim, eMatrixOrder Order, eMatrixLayout Layout, bool Packed>
auto mathter::DecompositionLU<T, Dim, Order, Layout, Packed>::Inverse() const -> Matrix<T, Dim, Dim, Order, Layout, Packed> {
auto DecompositionLU<T, Dim, Order, Layout, Packed>::Inverse() const -> Matrix<T, Dim, Dim, Order, Layout, Packed> {
return Solve(Mat(Identity()));
}

Expand Down Expand Up @@ -117,19 +117,21 @@ struct DecompositionLUP {


template <class T, int Dim, eMatrixOrder Order, eMatrixLayout Layout, bool Packed, class Int>
DecompositionLUP(const Matrix<T, Dim, Dim, Order, Layout, Packed>&,
const Matrix<T, Dim, Dim, Order, Layout, Packed>&,
const Vector<Int, Dim, Packed>&) -> DecompositionLUP<T, Dim, Order, Layout, Packed>;
DecompositionLUP(Matrix<T, Dim, Dim, Order, Layout, Packed>,
Matrix<T, Dim, Dim, Order, Layout, Packed>,
Vector<Int, Dim, Packed>) -> DecompositionLUP<T, Dim, Order, Layout, Packed>;


template <class T, int Dim, eMatrixOrder Order, eMatrixLayout Layout, bool Packed>
template <class T2, int Rows2, int Columns2, eMatrixLayout Layout2, bool Packed2>
auto DecompositionLUP<T, Dim, Order, Layout, Packed>::Solve(const Matrix<T2, Rows2, Columns2, Order, Layout2, Packed2>& b) const {
if constexpr (Order == eMatrixOrder::PRECEDE_VECTOR) {
return DecompositionLU{ L, U }.Solve(Permute(b));
const auto lu = DecompositionLU{ L, U };
return lu.Solve(Permute(b));
}
else {
return InversePermute(DecompositionLU{ L, U }.Solve(b));
const auto lu = DecompositionLU{ L, U };
return InversePermute(lu.Solve(b));
}
}

Expand Down Expand Up @@ -269,4 +271,4 @@ auto DecomposeLUP(const Matrix<T, Dim, Dim, Order, Layout, Packed>& m) {
return DecompositionLUP{ L, MatResult(U), P };
}

} // namespace mathter
} // namespace mathter
11 changes: 6 additions & 5 deletions include/Mathter/Decompositions/DecomposeQR.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,23 +154,24 @@ template <class T, int Rows, int Columns, eMatrixOrder Order, eMatrixLayout Layo
template <class T2, int Rows2, eMatrixLayout Layout2, bool Packed2>
auto DecompositionLQ<T, Rows, Columns, Order, Layout, Packed>::Solve(const Matrix<T2, Rows2, Rows, Order, Layout2, Packed2>& b) const {
static_assert(Order == eMatrixOrder::FOLLOW_VECTOR, MATHTER_LQ_SOLVE_ORDER_ERROR);
return FlipLayoutAndOrder(DecompositionQR{ FlipLayoutAndOrder(Q), FlipLayoutAndOrder(L) }
.Solve(FlipLayoutAndOrder(b)));
const auto qr = DecompositionQR{ FlipLayoutAndOrder(Q), FlipLayoutAndOrder(L) };
return FlipLayoutAndOrder(qr.Solve(FlipLayoutAndOrder(b)));
}


template <class T, int Rows, int Columns, eMatrixOrder Order, eMatrixLayout Layout, bool Packed>
template <class T2, bool Packed2>
auto DecompositionLQ<T, Rows, Columns, Order, Layout, Packed>::Solve(const Vector<T2, Columns, Packed2>& b) const {
static_assert(Order == eMatrixOrder::FOLLOW_VECTOR, MATHTER_LQ_SOLVE_ORDER_ERROR);
return DecompositionQR{ FlipLayoutAndOrder(Q), FlipLayoutAndOrder(L) }.Solve(b);
const auto qr = DecompositionQR{ FlipLayoutAndOrder(Q), FlipLayoutAndOrder(L) };
return qr.Solve(b);
}


template <class T, int Rows, int Columns, eMatrixOrder Order, eMatrixLayout Layout, bool Packed>
auto DecompositionLQ<T, Rows, Columns, Order, Layout, Packed>::Inverse() const -> Matrix<T, Columns, Rows, Order, Layout, Packed> {
return FlipLayoutAndOrder(DecompositionQR{ FlipLayoutAndOrder(Q), FlipLayoutAndOrder(L) }
.Inverse());
const auto qr = DecompositionQR{ FlipLayoutAndOrder(Q), FlipLayoutAndOrder(L) };
return FlipLayoutAndOrder(qr.Inverse());
}


Expand Down
1 change: 1 addition & 0 deletions include/Mathter/IoStream.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

#include <iostream>
#include <type_traits>
#include <vector>

namespace mathter {

Expand Down
6 changes: 3 additions & 3 deletions include/Mathter/Vector/Math.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ namespace impl {
std::array<std::optional<std::reference_wrapper<const Vec>>, Dim - 1> vectors;
auto [argIt, outIt] = std::tuple(first, vectors.begin());
for (; argIt != last && outIt != vectors.end(); ++argIt, ++outIt) {
*outIt = std::ref(*argIt);
*outIt = { std::ref(*argIt) };
}
if (outIt != vectors.end()) {
throw std::invalid_argument("not enough arguments for cross product");
Expand Down Expand Up @@ -376,7 +376,7 @@ auto Cross(IterFirst first, IterLast last) -> std::enable_if_t<is_vector_v<Vec>,
throw std::invalid_argument("not enough arguments for cross product");
}
const auto& b = *first++;
return FMTA(Vector(a.yzx), Vector(b.zxy), -Vector(a.zxy), Vector(b.yzx));
return FMTA(Vector(a.yzx), Vector(b.zxy), -std::move(Vector(a.zxy)), Vector(b.yzx)); // std::move due to CTAD bug in Clang 11.
}
else {
return impl::CrossND(first, last);
Expand All @@ -389,4 +389,4 @@ auto Cross(IterFirst first, IterLast last) -> std::enable_if_t<is_vector_v<Vec>,
#if defined(MATHTER_MINMAX)
#pragma pop_macro("min")
#pragma pop_macro("max")
#endif
#endif
3 changes: 3 additions & 0 deletions include/Mathter/Vector/SIMDUtil.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@


#if MATHTER_ENABLE_SIMD
// clang-format off
#include <utility> // Include tuple for XSimd.
// clang-format on
#include <xsimd/xsimd.hpp>
#endif

Expand Down
1 change: 1 addition & 0 deletions test/Cases.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <Mathter/Common/Types.hpp>

#include <complex>
#include <tuple>
#include <type_traits>


Expand Down
Loading