Skip to content

Commit 78bfa6e

Browse files
[linalg] cleanup and hygiene
1 parent ed89b71 commit 78bfa6e

File tree

1 file changed

+29
-34
lines changed

1 file changed

+29
-34
lines changed

linalg/naive/fcarouge/linalg.hpp

+29-34
Original file line numberDiff line numberDiff line change
@@ -70,46 +70,31 @@ template <typename Type = double, auto Row = 1, auto Column = 1> struct matrix {
7070

7171
inline constexpr matrix &operator=(matrix &&other) = default;
7272

73-
inline constexpr explicit(false) matrix(Type element)
74-
requires(Row == 1 && Column == 1)
75-
{
76-
data[0][0] = element;
77-
}
78-
79-
inline constexpr explicit matrix(Type(element)[1])
80-
requires(Row == 1 && Column == 1)
81-
{
82-
data[0][0] = element[0];
83-
}
73+
inline constexpr matrix(const std::same_as<Type> auto &...elements)
74+
requires(Row == 1 && sizeof...(elements) == Column)
75+
: data{{elements...}} {}
8476

85-
inline constexpr explicit matrix(Type(column)[Row])
86-
requires(Row != 1 && Column == 1)
77+
inline constexpr matrix(const std::same_as<Type> auto &...elements)
78+
requires(Row != 1 && Column == 1 && sizeof...(elements) == Row)
8779
{
88-
for (decltype(Row) i{0}; i < Row; ++i) {
89-
data[i][0] = column[i];
90-
}
80+
decltype(Row) i{0};
81+
([&] { data[i++][0] = elements; }(), ...);
9182
}
9283

93-
inline constexpr explicit matrix(Type(row)[Column])
94-
requires(Row == 1 && Column != 1)
84+
inline constexpr explicit matrix(Type (&elements)[Column])
85+
requires(Row == 1)
9586
{
9687
for (decltype(Column) j{0}; j < Column; ++j) {
97-
data[0][j] = row[j];
88+
data[0][j] = elements[j];
9889
}
9990
}
10091

101-
inline constexpr matrix(const auto &...elements)
102-
requires(Row != 1 && Column == 1 && sizeof...(elements) == Row)
103-
{
104-
decltype(Row) i{0};
105-
([&] { data[i++][0] = elements; }(), ...);
106-
}
107-
108-
inline constexpr matrix(const auto &...elements)
109-
requires(Row == 1 && Column != 1 && sizeof...(elements) == Column)
92+
inline constexpr explicit matrix(Type (&elements)[Row])
93+
requires(Row != 1 && Column == 1)
11094
{
111-
decltype(Column) j{0};
112-
([&] { data[0][j++] = elements; }(), ...);
95+
for (decltype(Row) i{0}; i < Row; ++i) {
96+
data[i][0] = elements[i];
97+
}
11398
}
11499

115100
inline constexpr explicit matrix(
@@ -158,10 +143,6 @@ template <typename Type = double, auto Row = 1, auto Column = 1> struct matrix {
158143
return data[row][column];
159144
}
160145

161-
[[nodiscard]] inline constexpr bool operator==(const matrix &other) const
162-
requires(Row != 1 || Column != 1)
163-
= default;
164-
165146
[[no_unique_address]] Type data[Row][Column]{};
166147
};
167148

@@ -219,6 +200,20 @@ template <typename Type, auto Row, auto Column>
219200
inline constexpr matrix<Type, Row, Column> zero_v<matrix<Type, Row, Column>>{};
220201
//! @}
221202

203+
template <typename Type, auto Row, auto Column>
204+
[[nodiscard]] inline constexpr bool
205+
operator==(const matrix<Type, Row, Column> &lhs,
206+
const matrix<Type, Row, Column> &rhs) {
207+
for (decltype(Row) i{0}; i < Row; ++i) {
208+
for (decltype(Column) j{0}; j < Column; ++j) {
209+
if (lhs.data[i][j] != rhs.data[i][j]) {
210+
return false;
211+
}
212+
}
213+
}
214+
return true;
215+
}
216+
222217
template <typename Type, auto Row, auto Column, auto Size>
223218
[[nodiscard]] inline constexpr auto
224219
operator*(const matrix<Type, Row, Size> &lhs,

0 commit comments

Comments
 (0)