feat(math): add transpose operation and fill_random

This commit is contained in:
2026-11-01 13:06:34 +01:00
parent 795915d100
commit c96d31a378
4 changed files with 59 additions and 0 deletions
+29
View File
@@ -171,6 +171,35 @@ struct apply {
}
};
struct transpose {
template <typename E>
static constexpr bool compatible(const E& expr) {
return true;
}
template <typename E>
static constexpr auto shape(const E& expr) {
if (!compatible(expr)) throw std::runtime_error("uncompatible operands");
using shape_type = remove_cvref_t<decltype(expr.shape())>;
constexpr std::size_t rows = shape_type::template sget<0>();
constexpr std::size_t cols = shape_type::template sget<1>();
if constexpr (rows == dynamic_extent || cols == dynamic_extent) {
return dynamic_shape<cols, rows>{ shape_type::template get<1>(), shape_type::template get<0>() };
} else {
return static_shape<cols, rows>{};
}
}
template <typename E>
constexpr auto operator()(std::size_t index, const E& expr) const {
const std::size_t cols = expr.shape().template get<1>();
return expr.coeff(((index % cols) * cols) + (index / cols));
}
};
} // namespace ops
} // namespace math
} // namespace cenet