Commit e17c8b9b authored by Andi Braimllari's avatar Andi Braimllari Committed by Tobias Lasser
Browse files

add cwiseAbs() functionality to DataContainer

parent dd5c3310
Pipeline #645854 passed with stages
in 21 minutes and 49 seconds
......@@ -577,6 +577,19 @@ namespace elsa
}
}
/// Element-wise absolute value operation
template <typename Operand, typename = std::enable_if_t<isDcOrExpr<Operand>>>
auto cwiseAbs(Operand const& operand)
{
auto abs = [](auto const& operand) { return (operand.array().abs()).matrix(); };
#ifdef ELSA_CUDA_VECTOR
auto absGPU = [](auto const& operand, bool) { return quickvec::cwiseAbs(operand); };
return Expression{Callables{abs, absGPU}, operand};
#else
return Expression{abs, operand};
#endif
}
/// Element-wise square operation
template <typename Operand, typename = std::enable_if_t<isDcOrExpr<Operand>>>
auto square(Operand const& operand)
......
......@@ -279,6 +279,10 @@ TEST_CASE_TEMPLATE_DEFINE("DataContainer: Testing element-wise access", TestType
THEN("the element-wise unary operations work as expected")
{
DataContainer dcAbs = cwiseAbs(dc);
for (index_t i = 0; i < dc.getSize(); ++i)
REQUIRE_UNARY(checkApproxEq(dcAbs[i], randVec.array().abs()[i]));
DataContainer dcSquare = square(dc);
for (index_t i = 0; i < dc.getSize(); ++i)
REQUIRE_UNARY(checkApproxEq(dcSquare[i], randVec.array().square()[i]));
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment