@@ -49,10 +49,13 @@ For more information, please refer to <https://unlicense.org> */
49
49
50
50
#include " fcarouge/utility.hpp"
51
51
52
+ // #include <range/v3/range.hpp>
53
+
52
54
#include < algorithm>
53
55
#include < array>
54
56
#include < concepts>
55
57
#include < coroutine>
58
+ #include < format>
56
59
#include < generator>
57
60
#include < ranges>
58
61
#include < type_traits>
@@ -101,11 +104,13 @@ inline constexpr auto make_generator(Type element) -> std::generator<Type> {
101
104
// ! @note A design decision for the composed generator to be mutable, traded
102
105
// ! off for const member function API. Similar to the mutable mutex member
103
106
// ! practice.
104
- // ! @note Why genie? Because genies generate on demand.
107
+ // ! @note Why genie? Because genies generate on demand...
105
108
// !
106
109
// ! @todo Explore and compare performance.
107
110
// ! @todo Explore optimization of heap allocations?
108
111
// ! @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?
109
114
// ! @todo Explore verification of lazy evaluation?
110
115
// ! @todo Remove unecessary empty paramaters when MSVC supports lambda without
111
116
// ! them.
@@ -155,7 +160,8 @@ struct matrix {
155
160
return *this ;
156
161
}
157
162
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)
159
165
requires(sizeof ...(elements) == Row * Column)
160
166
: genie{[](auto ... elements_copy) -> std::generator<Type> {
161
167
(co_yield elements_copy, ...);
@@ -322,27 +328,27 @@ auto make_zero_generator{[]() -> std::generator<Type> {
322
328
// ! @name Algebraic Named Values
323
329
// ! @{
324
330
// ! @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) {
327
333
matrix<Type, Row, Column, true > m{
328
334
make_identity_generator<Type, Row, Column>()};
329
335
if constexpr (sizeof ...(args)) {
330
336
return m (args...);
331
337
} else {
332
338
return m;
333
339
}
334
- }};
340
+ }() };
335
341
336
342
// ! @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) {
339
345
matrix<Type, Row, Column, true > m{make_zero_generator<Type, Row, Column>()};
340
346
if constexpr (sizeof ...(args)) {
341
347
return m (args...);
342
348
} else {
343
349
return m;
344
350
}
345
- }};
351
+ }() };
346
352
347
353
// ! @}
348
354
@@ -370,9 +376,20 @@ operator==(matrix<Type, Row, Column, CopyableOrNot1> lhs,
370
376
return lhs_elements == rhs_elements;
371
377
}
372
378
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) {
376
393
// fix me?
377
394
auto next1{lhs.begin ()};
378
395
for (decltype (Row) i{0 }; i < Row; ++i) { // chunk_by_rows
@@ -386,14 +403,16 @@ template <typename Type, auto Row, auto Size>
386
403
}
387
404
}
388
405
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
+ // }
397
416
398
417
template <typename Type>
399
418
[[nodiscard]] inline matrix<Type, 1 , 1 > operator +(Type lhs,
@@ -410,6 +429,34 @@ operator+(matrix<Type, Row, Column> lhs, matrix<Type, Row, Column> rhs) {
410
429
co_yield *next1 + *next2;
411
430
}
412
431
}
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
+ // }
413
442
} // namespace fcarouge
414
443
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
+
415
462
#endif // FCAROUGE_LINALG_HPP
0 commit comments