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

[linalg] avoid auto and deduce type #646

Closed
wants to merge 1 commit into from
Closed
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
12 changes: 6 additions & 6 deletions include/fcarouge/utility.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,15 +249,15 @@ inline constexpr Type identity{internal::not_implemented<Type>{

//! @brief The singleton identity matrix specialization.
template <arithmetic Arithmetic>
inline constexpr Arithmetic identity<Arithmetic>{1};
inline constexpr auto identity<Arithmetic>{Arithmetic{1}};

template <typename Type>
requires requires { Type::Identity(); }
inline auto identity<Type>{Type::Identity()};
inline evaluate<Type> identity<Type>{evaluate<Type>{evaluate<Type>::Identity()}};

template <typename Type>
requires requires { Type::identity(); }
inline auto identity<Type>{Type::identity()};
inline evaluate<Type> identity<Type>{evaluate<Type>{evaluate<Type>::identity()}};

//! @brief The zero matrix.
//!
Expand All @@ -268,15 +268,15 @@ inline constexpr Type zero{internal::not_implemented<Type>{

//! @brief The singleton zero matrix specialization.
template <arithmetic Arithmetic>
inline constexpr Arithmetic zero<Arithmetic>{0};
inline constexpr auto zero<Arithmetic>{Arithmetic{0}};

template <typename Type>
requires requires { Type::Zero(); }
inline auto zero<Type>{Type::Zero()};
inline evaluate<Type> zero<Type>{evaluate<Type>{evaluate<Type>::Zero()}};

template <typename Type>
requires requires { Type::zero(); }
inline auto zero<Type>{Type::zero()};
inline evaluate<Type> zero<Type>{evaluate<Type>{evaluate<Type>::zero()}};

//! @}

Expand Down
2 changes: 1 addition & 1 deletion test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ test(NAME "linalg_multiplication_rxc" BACKENDS "eigen" "naive")
test(NAME "linalg_multiplication_sxc" BACKENDS "eigen" "naive")
test(NAME "linalg_operator_bracket" BACKENDS "eigen" "naive")
test(NAME "linalg_operator_equality" BACKENDS "eigen" "naive")
test(NAME "linalg_zero_default" BACKENDS "eigen" "naive")
test(NAME "linalg_zero" BACKENDS "eigen" "naive")
test(NAME "printer_1x1x0")
test(NAME "printer_2x3x4" BACKENDS "eigen")
test(NAME "units_kf_1x1x0_building_height")
test(NAME "utility_zero_default")
1 change: 0 additions & 1 deletion test/kalman_f_5x4x3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ template <auto Row, auto Column> using matrix = matrix<double, Row, Column>;
[[maybe_unused]] auto test{[] {
const auto i5x5{identity<matrix<5, 5>>};
const auto z5x5{zero<matrix<5, 5>>};
const vector<3> z3{zero<vector<3>>};
kalman filter{state{vector<5>{0., 0., 0., 0., 0.}}, output<vector<4>>,
input<vector<3>>, update_types<double, float, int>,
prediction_types<int, float, double>};
Expand Down
4 changes: 4 additions & 0 deletions test/kalman_format_1x4x3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ For more information, please refer to <https://unlicense.org> */
#include <cassert>
#include <format>

#include <print> //////////////////////////////////////////////////////////////

namespace fcarouge::test {
namespace {
template <auto Size> using vector = column_vector<double, Size>;
Expand All @@ -51,6 +53,8 @@ template <auto Size> using vector = column_vector<double, Size>;
[[maybe_unused]] auto test{[] {
kalman filter{state{vector<1>{0.}}, output<vector<4>>, input<vector<3>>};

std::println("{}", filter); /////////////////////////////////////////////////

assert(std::format("{}", filter) ==
R"({"f": 1,)"
R"( "g": [1, 0, 0],)"
Expand Down
4 changes: 4 additions & 0 deletions test/kalman_format_5x4x3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ For more information, please refer to <https://unlicense.org> */
#include <cassert>
#include <format>

#include <print> /////////////////////////////////////////////////////////////

namespace fcarouge::test {
namespace {
template <auto Size> using vector = column_vector<double, Size>;
Expand All @@ -52,6 +54,8 @@ template <auto Size> using vector = column_vector<double, Size>;
kalman filter{state{vector<5>{0., 0., 0., 0., 0.}}, output<vector<4>>,
input<vector<3>>};

std::println("{}", filter); /////////////////////////////////////////////////

assert(
std::format("{}", filter) ==
R"({"f": [[1, 0, 0, 0, 0], [0, 1, 0, 0, 0], [0, 0, 1, 0, 0], [0, 0, 0, 1, 0], [0, 0, 0, 0, 1]],)"
Expand Down
6 changes: 3 additions & 3 deletions test/linalg_multiplication_sxc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ namespace fcarouge::test {
namespace {
//! @test Verifies the assignment operator.
[[maybe_unused]] auto test{[] {
matrix<double, 2, 2> a{{1.0, 2.0}, {3.0, 4.0}};
matrix<double, 2, 1> b{3.0, 4.0};
auto r{a * b};
const matrix<double, 2, 2> a{{1.0, 2.0}, {3.0, 4.0}};
const matrix<double, 2, 1> b{3.0, 4.0};
const matrix<double, 2, 1> r{a * b};

assert(r(0, 0) == 11.0);
assert(r(1, 0) == 25.0);
Expand Down
6 changes: 3 additions & 3 deletions test/linalg_operator_equality.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ namespace fcarouge::test {
namespace {
//! @test Verifies the equality operator.
[[maybe_unused]] auto test{[] {
auto m{zero<matrix<double, 5, 5>>};
auto i{identity<matrix<double, 5, 5>>};
auto z{zero<matrix<double, 5, 5>>};
const matrix<double, 5, 5> m{zero<matrix<double, 5, 5>>};
const matrix<double, 5, 5> i{identity<matrix<double, 5, 5>>};
const matrix<double, 5, 5> z{zero<matrix<double, 5, 5>>};

assert(m == z);
assert(m != i);
Expand Down
2 changes: 1 addition & 1 deletion test/linalg_zero.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ namespace fcarouge::test {
namespace {
//! @test Verifies the zero matrices values are null.
[[maybe_unused]] auto test{[] {
auto z{zero<matrix<double, 3, 3>>};
const matrix<double, 3, 3> z{zero<matrix<double, 3, 3>>};

assert(z(0, 0) == 0.0);
assert(z(0, 1) == 0.0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ OTHER DEALINGS IN THE SOFTWARE.

For more information, please refer to <https://unlicense.org> */

#include "fcarouge/linalg.hpp"
#include "fcarouge/utility.hpp"

#include <cassert>
#include <type_traits>
Expand All @@ -45,10 +45,11 @@ namespace fcarouge::test {
namespace {
//! @test Verifies the 1x1 zero matrix deduced default value is a null double.
[[maybe_unused]] auto test{[] {
auto z{zero<>};
const double z{zero<>};
const auto a{zero<>};

assert(z == 0.0);
static_assert(std::is_same_v<decltype(z), double>);
static_assert(std::is_same_v<decltype(a), const double>);

return 0;
}()};
Expand Down
Loading