libeigen/eigen!2652 Closes #998, #2142, #301, #1822, #1959, #805, #462, #308, #2146, #1335, #634, #81, and #46
22 lines
485 B
C++
22 lines
485 B
C++
// SPDX-FileCopyrightText: The Eigen Authors
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
#include <Eigen/Core>
|
|
#include <iostream>
|
|
|
|
// define function to be applied coefficient-wise
|
|
double ramp(double x) {
|
|
if (x > 0)
|
|
return x;
|
|
else
|
|
return 0;
|
|
}
|
|
|
|
int main(int, char**) {
|
|
Eigen::Matrix4d m1 = Eigen::Matrix4d::Random();
|
|
std::cout << m1 << std::endl
|
|
<< "becomes: " << std::endl
|
|
<< m1.unaryExpr([](double x) { return ramp(x); }) << std::endl;
|
|
return 0;
|
|
}
|