Skip to content

Commit 7be43b1

Browse files
[linalg] improve documentation (#360)
1 parent c24aa29 commit 7be43b1

14 files changed

+522
-50
lines changed

benchmark/CMakeLists.txt

+9-3
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,13 @@ foreach(BENCHMARK "baseline.cpp" "predict_1x1x0.cpp" "predict_1x1x1.cpp"
7171
"--benchmark_out=${NAME}.json")
7272
endforeach()
7373

74-
foreach(BACKEND IN ITEMS "eigen" "naive")
75-
foreach(STATE_SIZE RANGE 1 2)
74+
foreach(
75+
BACKEND IN
76+
ITEMS # "eigen"
77+
"lazy"
78+
# "naive"
79+
)
80+
foreach(STATE_SIZE RANGE 1 1)
7681
foreach(INPUT_SIZE RANGE 1 2)
7782
configure_file(predict_linalg_x1x.cpp
7883
predict_${BACKEND}_${STATE_SIZE}x1x${INPUT_SIZE}.cpp)
@@ -99,7 +104,8 @@ foreach(BACKEND IN ITEMS "eigen" "naive")
99104
endforeach()
100105
endforeach()
101106

102-
foreach(BACKEND IN ITEMS "eigen")
107+
foreach(BACKEND IN ITEMS # "eigen"
108+
)
103109
foreach(STATE_SIZE RANGE 1 2)
104110
foreach(OUTPUT_SIZE RANGE 1 2)
105111
configure_file(update_linalg_xx0.cpp

include/fcarouge/internal/utility.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ struct transpose final {
144144
//! @todo Is there a better, simpler, canonical, standard way of doing this type
145145
//! deduction? For example, by doing it directly from the operation itself?
146146
//! There could be simplicity and performance benefits?
147+
//! @todo Really need to fix this and either have it done automatically or moved out. Need to find a better way.
147148
struct deducer final {
148149
// Built-in, arithmetic, standard division support.
149150
template <arithmetic Lhs, arithmetic Rhs>

linalg/CMakeLists.txt

+3-17
Original file line numberDiff line numberDiff line change
@@ -36,20 +36,6 @@ OTHER DEALINGS IN THE SOFTWARE.
3636
3737
For more information, please refer to <https://unlicense.org> ]]
3838

39-
FetchContent_Declare(
40-
eigen
41-
GIT_REPOSITORY "https://gitlab.com/libeigen/eigen"
42-
FIND_PACKAGE_ARGS NAMES Eigen3)
43-
FetchContent_MakeAvailable(eigen)
44-
45-
add_library(kalman_linalg_eigen INTERFACE)
46-
target_include_directories(kalman_linalg_eigen INTERFACE "eigen")
47-
target_link_libraries(kalman_linalg_eigen INTERFACE Eigen3::Eigen kalman)
48-
49-
add_library(kalman_linalg_lazy INTERFACE)
50-
target_include_directories(kalman_linalg_lazy INTERFACE "lazy")
51-
target_link_libraries(kalman_linalg_lazy INTERFACE kalman kalman_generator)
52-
53-
add_library(kalman_linalg_naive INTERFACE)
54-
target_include_directories(kalman_linalg_naive INTERFACE "naive")
55-
target_link_libraries(kalman_linalg_naive INTERFACE kalman)
39+
add_subdirectory("eigen")
40+
add_subdirectory("lazy")
41+
add_subdirectory("naive")

linalg/eigen/CMakeLists.txt

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#[[ __ _ __ __ _ _
2+
| |/ / /\ | | | \/ | /\ | \ | |
3+
| ' / / \ | | | \ / | / \ | \| |
4+
| < / /\ \ | | | |\/| | / /\ \ | . ` |
5+
| . \ / ____ \| |____| | | |/ ____ \| |\ |
6+
|_|\_\/_/ \_\______|_| |_/_/ \_\_| \_|
7+
8+
Kalman Filter
9+
Version 0.2.0
10+
https://github.com/FrancoisCarouge/Kalman
11+
12+
SPDX-License-Identifier: Unlicense
13+
14+
This is free and unencumbered software released into the public domain.
15+
16+
Anyone is free to copy, modify, publish, use, compile, sell, or
17+
distribute this software, either in source code form or as a compiled
18+
binary, for any purpose, commercial or non-commercial, and by any
19+
means.
20+
21+
In jurisdictions that recognize copyright laws, the author or authors
22+
of this software dedicate any and all copyright interest in the
23+
software to the public domain. We make this dedication for the benefit
24+
of the public at large and to the detriment of our heirs and
25+
successors. We intend this dedication to be an overt act of
26+
relinquishment in perpetuity of all present and future rights to this
27+
software under copyright law.
28+
29+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
30+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
31+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
32+
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
33+
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
34+
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
35+
OTHER DEALINGS IN THE SOFTWARE.
36+
37+
For more information, please refer to <https://unlicense.org> ]]
38+
39+
FetchContent_Declare(
40+
eigen
41+
GIT_REPOSITORY "https://gitlab.com/libeigen/eigen"
42+
FIND_PACKAGE_ARGS NAMES Eigen3)
43+
FetchContent_MakeAvailable(eigen)
44+
45+
add_library(kalman_linalg_eigen INTERFACE)
46+
target_include_directories(kalman_linalg_eigen INTERFACE ".")
47+
target_link_libraries(kalman_linalg_eigen INTERFACE Eigen3::Eigen kalman)

linalg/lazy/CMakeLists.txt

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#[[ __ _ __ __ _ _
2+
| |/ / /\ | | | \/ | /\ | \ | |
3+
| ' / / \ | | | \ / | / \ | \| |
4+
| < / /\ \ | | | |\/| | / /\ \ | . ` |
5+
| . \ / ____ \| |____| | | |/ ____ \| |\ |
6+
|_|\_\/_/ \_\______|_| |_/_/ \_\_| \_|
7+
8+
Kalman Filter
9+
Version 0.2.0
10+
https://github.com/FrancoisCarouge/Kalman
11+
12+
SPDX-License-Identifier: Unlicense
13+
14+
This is free and unencumbered software released into the public domain.
15+
16+
Anyone is free to copy, modify, publish, use, compile, sell, or
17+
distribute this software, either in source code form or as a compiled
18+
binary, for any purpose, commercial or non-commercial, and by any
19+
means.
20+
21+
In jurisdictions that recognize copyright laws, the author or authors
22+
of this software dedicate any and all copyright interest in the
23+
software to the public domain. We make this dedication for the benefit
24+
of the public at large and to the detriment of our heirs and
25+
successors. We intend this dedication to be an overt act of
26+
relinquishment in perpetuity of all present and future rights to this
27+
software under copyright law.
28+
29+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
30+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
31+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
32+
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
33+
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
34+
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
35+
OTHER DEALINGS IN THE SOFTWARE.
36+
37+
For more information, please refer to <https://unlicense.org> ]]
38+
39+
# FetchContent_Declare( range-v3 GIT_REPOSITORY
40+
# "https://github.com/ericniebler/range-v3" FIND_PACKAGE_ARGS NAMES range-v3)
41+
# FetchContent_MakeAvailable(range-v3)
42+
43+
add_library(kalman_linalg_lazy INTERFACE)
44+
target_include_directories(kalman_linalg_lazy INTERFACE ".")
45+
target_link_libraries(
46+
kalman_linalg_lazy INTERFACE kalman kalman_generator # range-v3::range-v3
47+
# $<$<NOT:$<BOOL:${WIN32}>>:kalman_format>
48+
)

linalg/lazy/fcarouge/linalg.hpp

+66-19
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,13 @@ For more information, please refer to <https://unlicense.org> */
4949

5050
#include "fcarouge/utility.hpp"
5151

52+
// #include <range/v3/range.hpp>
53+
5254
#include <algorithm>
5355
#include <array>
5456
#include <concepts>
5557
#include <coroutine>
58+
#include <format>
5659
#include <generator>
5760
#include <ranges>
5861
#include <type_traits>
@@ -101,11 +104,13 @@ inline constexpr auto make_generator(Type element) -> std::generator<Type> {
101104
//! @note A design decision for the composed generator to be mutable, traded
102105
//! off for const member function API. Similar to the mutable mutex member
103106
//! practice.
104-
//! @note Why genie? Because genies generate on demand.
107+
//! @note Why genie? Because genies generate on demand...
105108
//!
106109
//! @todo Explore and compare performance.
107110
//! @todo Explore optimization of heap allocations?
108111
//! @todo Explore constexpr support?
112+
//! @todo Explore an implementation where each element is a generator?
113+
//! @todo Explore cyclic generator to keep moving forward and not track results?
109114
//! @todo Explore verification of lazy evaluation?
110115
//! @todo Remove unecessary empty paramaters when MSVC supports lambda without
111116
//! them.
@@ -155,7 +160,8 @@ struct matrix {
155160
return *this;
156161
}
157162

158-
inline constexpr explicit matrix(const std::same_as<Type> auto &...elements)
163+
inline constexpr explicit(false)
164+
matrix(const std::same_as<Type> auto &...elements)
159165
requires(sizeof...(elements) == Row * Column)
160166
: genie{[](auto... elements_copy) -> std::generator<Type> {
161167
(co_yield elements_copy, ...);
@@ -322,27 +328,27 @@ auto make_zero_generator{[]() -> std::generator<Type> {
322328
//! @name Algebraic Named Values
323329
//! @{
324330
//! @brief The identity matrix lazy specialization.
325-
template <typename Type, auto Row, auto Column>
326-
auto identity_v<matrix<Type, Row, Column>>{[](auto... args) {
331+
template <typename Type, auto Row, auto Column, bool CopyableOrNot>
332+
auto identity_v<matrix<Type, Row, Column, CopyableOrNot>>{[](auto... args) {
327333
matrix<Type, Row, Column, true> m{
328334
make_identity_generator<Type, Row, Column>()};
329335
if constexpr (sizeof...(args)) {
330336
return m(args...);
331337
} else {
332338
return m;
333339
}
334-
}};
340+
}()};
335341

336342
//! @brief The zero matrix lazy specialization.
337-
template <typename Type, auto Row, auto Column>
338-
auto zero_v<matrix<Type, Row, Column>>{[](auto... args) {
343+
template <typename Type, auto Row, auto Column, bool CopyableOrNot>
344+
auto zero_v<matrix<Type, Row, Column, CopyableOrNot>>{[](auto... args) {
339345
matrix<Type, Row, Column, true> m{make_zero_generator<Type, Row, Column>()};
340346
if constexpr (sizeof...(args)) {
341347
return m(args...);
342348
} else {
343349
return m;
344350
}
345-
}};
351+
}()};
346352

347353
//! @}
348354

@@ -370,9 +376,20 @@ operator==(matrix<Type, Row, Column, CopyableOrNot1> lhs,
370376
return lhs_elements == rhs_elements;
371377
}
372378

373-
template <typename Type, auto Row, auto Size>
374-
[[nodiscard]] inline matrix<Type, Row, 1> operator*(matrix<Type, Row, Size> lhs,
375-
matrix<Type, Size, 1> rhs) {
379+
template <typename Type, auto Row, auto Column>
380+
[[nodiscard]] inline matrix<Type, Row, Column>
381+
operator*(matrix<Type, Row, Column> lhs, arithmetic auto rhs) {
382+
auto next{lhs.begin()};
383+
for (auto k{Row * Column}; k > 0; --k, ++next) {
384+
co_yield *next *rhs;
385+
}
386+
}
387+
388+
template <typename Type, auto Row, auto Size, bool CopyableOrNot1,
389+
bool CopyableOrNot2>
390+
[[nodiscard]] inline matrix<Type, Row, 1>
391+
operator*(matrix<Type, Row, Size, CopyableOrNot1> lhs,
392+
matrix<Type, Size, 1, CopyableOrNot2> rhs) {
376393
// fix me?
377394
auto next1{lhs.begin()};
378395
for (decltype(Row) i{0}; i < Row; ++i) { // chunk_by_rows
@@ -386,14 +403,16 @@ template <typename Type, auto Row, auto Size>
386403
}
387404
}
388405

389-
template <typename Type, auto Row, auto Column>
390-
[[nodiscard]] inline matrix<Type, Row, Column>
391-
operator*(matrix<Type, Row, Column> lhs, arithmetic auto rhs) {
392-
auto next{lhs.begin()};
393-
for (auto k{Row * Column}; k > 0; --k, ++next) {
394-
co_yield *next *rhs;
395-
}
396-
}
406+
// //! @todo Implement me.
407+
// template <typename Type, auto Row, auto Size, auto Column>
408+
// [[nodiscard]] inline matrix<Type, Row, Column>
409+
// operator*(matrix<Type, Row, Size> lhs, matrix<Type, Size, Column> rhs) {
410+
// static_cast<void>(lhs);
411+
// static_cast<void>(rhs);
412+
// for (auto k{Row * Column}; k > 0; --k) {
413+
// co_yield Type{};
414+
// }
415+
// }
397416

398417
template <typename Type>
399418
[[nodiscard]] inline matrix<Type, 1, 1> operator+(Type lhs,
@@ -410,6 +429,34 @@ operator+(matrix<Type, Row, Column> lhs, matrix<Type, Row, Column> rhs) {
410429
co_yield *next1 + *next2;
411430
}
412431
}
432+
433+
// //! @todo Implement me.
434+
// template <typename Type, auto Row, auto Column>
435+
// [[nodiscard]] inline matrix<Type, Column, Row>
436+
// transpose(matrix<Type, Row, Column> other) {
437+
// static_cast<void>(other);
438+
// for (auto k{Row * Column}; k > 0; --k) {
439+
// co_yield Type{};
440+
// }
441+
// }
413442
} // namespace fcarouge
414443

444+
// template <typename Type, auto Row, auto Column, typename Char>
445+
// struct std::formatter<fcarouge::matrix<Type, Row, Column>, Char>
446+
// : public std::formatter<Type, Char> {
447+
// constexpr auto parse(std::basic_format_parse_context<Char> &parse_context)
448+
// {
449+
// return parse_context.begin();
450+
// }
451+
452+
// //! @todo P2585 may be useful in simplifying and standardizing the support.
453+
// template <typename OutputIt>
454+
// auto format(const fcarouge::matrix<Type, Row, Column> &other,
455+
// std::basic_format_context<OutputIt, Char> &format_context)
456+
// -> OutputIt {
457+
458+
// return format_context.out();
459+
// }
460+
// };
461+
415462
#endif // FCAROUGE_LINALG_HPP

linalg/naive/CMakeLists.txt

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#[[ __ _ __ __ _ _
2+
| |/ / /\ | | | \/ | /\ | \ | |
3+
| ' / / \ | | | \ / | / \ | \| |
4+
| < / /\ \ | | | |\/| | / /\ \ | . ` |
5+
| . \ / ____ \| |____| | | |/ ____ \| |\ |
6+
|_|\_\/_/ \_\______|_| |_/_/ \_\_| \_|
7+
8+
Kalman Filter
9+
Version 0.2.0
10+
https://github.com/FrancoisCarouge/Kalman
11+
12+
SPDX-License-Identifier: Unlicense
13+
14+
This is free and unencumbered software released into the public domain.
15+
16+
Anyone is free to copy, modify, publish, use, compile, sell, or
17+
distribute this software, either in source code form or as a compiled
18+
binary, for any purpose, commercial or non-commercial, and by any
19+
means.
20+
21+
In jurisdictions that recognize copyright laws, the author or authors
22+
of this software dedicate any and all copyright interest in the
23+
software to the public domain. We make this dedication for the benefit
24+
of the public at large and to the detriment of our heirs and
25+
successors. We intend this dedication to be an overt act of
26+
relinquishment in perpetuity of all present and future rights to this
27+
software under copyright law.
28+
29+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
30+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
31+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
32+
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
33+
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
34+
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
35+
OTHER DEALINGS IN THE SOFTWARE.
36+
37+
For more information, please refer to <https://unlicense.org> ]]
38+
39+
add_library(kalman_linalg_naive INTERFACE)
40+
target_include_directories(kalman_linalg_naive INTERFACE ".")
41+
target_link_libraries(kalman_linalg_naive INTERFACE kalman)

test/CMakeLists.txt

+23
Original file line numberDiff line numberDiff line change
@@ -126,11 +126,13 @@ foreach(BACKEND IN ITEMS "eigen" "lazy" "naive")
126126
"linalg_constructor_nx1_array.cpp"
127127
"linalg_constructor_nx1.cpp"
128128
"linalg_copy.cpp"
129+
"linalg_identity_1x1.cpp"
129130
"linalg_identity_default.cpp"
130131
"linalg_identity.cpp"
131132
"linalg_multiplication_arithmetic.cpp"
132133
"linalg_multiplication_rxc.cpp"
133134
"linalg_multiplication_sxc.cpp"
135+
# "linalg_multiplication_mxn.cpp"
134136
"linalg_operator_bracket.cpp"
135137
"linalg_operator_equality.cpp"
136138
"linalg_zero_default.cpp"
@@ -152,3 +154,24 @@ foreach(BACKEND IN ITEMS "eigen" "lazy" "naive")
152154
$<TARGET_FILE:kalman_test_${BACKEND}_${NAME}_driver>)
153155
endforeach()
154156
endforeach()
157+
158+
foreach(BACKEND IN ITEMS "lazy")
159+
foreach(TEST "linalg_constructor_default.cpp"
160+
# "linalg_transpose.cpp"
161+
)
162+
get_filename_component(NAME ${TEST} NAME_WE)
163+
add_executable(kalman_test_${BACKEND}_${NAME}_driver ${TEST})
164+
set_target_properties(kalman_test_${BACKEND}_${NAME}_driver
165+
PROPERTIES CXX_STANDARD 23)
166+
set_target_properties(kalman_test_${BACKEND}_${NAME}_driver
167+
PROPERTIES CXX_EXTENSIONS OFF)
168+
target_link_libraries(kalman_test_${BACKEND}_${NAME}_driver
169+
PRIVATE kalman kalman_main kalman_linalg_${BACKEND})
170+
add_test(kalman_test_${BACKEND}_${NAME}
171+
kalman_test_${BACKEND}_${NAME}_driver)
172+
add_test(
173+
NAME kalman_${BACKEND}_valgrind_${NAME}
174+
COMMAND valgrind --error-exitcode=1 --leak-check=full --track-origins=yes
175+
$<TARGET_FILE:kalman_test_${BACKEND}_${NAME}_driver>)
176+
endforeach()
177+
endforeach()

0 commit comments

Comments
 (0)