@@ -243,6 +243,15 @@ public:
return std::accumulate(data_.begin(), data_.end(), R{});
}
+ template<typename T2>
+ Vector<T2, Rows> cast() const
+ {
+ Vector<T2, Rows> ret;
+ for (unsigned int i = 0; i < Rows; i++)
+ ret[i] = static_cast<T2>(data_[i]);
+ return ret;
+ }
+
private:
template<class BinaryOp>
static constexpr Vector apply(const Vector &lhs, const Vector &rhs, BinaryOp op)
@@ -202,6 +202,16 @@ LOG_DEFINE_CATEGORY(Vector)
* \return The element-wise maximum of this vector and \a scalar
*/
+/**
+ * \fn template<typename T2> Vector<T2, Rows> Vector::cast() const
+ * \brief Cast the vector to a different type
+ *
+ * This function returns a new vector with the same size and values but a
+ * different type.
+ *
+ * \return The new vector
+ */
+
/**
* \fn Vector::dot(const Vector<T, Rows> &other) const
* \brief Compute the dot product
The libcamera code base uses matrices and vectors of type float and double. Add a cast function to easily convert between different underlying types. Signed-off-by: Stefan Klug <stefan.klug@ideasonboard.com> --- include/libcamera/internal/vector.h | 9 +++++++++ src/libcamera/vector.cpp | 10 ++++++++++ 2 files changed, 19 insertions(+)