KokkosBlas::abs¶
Defined in header: KokkosBlas1_abs.hpp
template <class execution_space, class RMV, class XMV>
void abs(const execution_space& space, const RMV& R, const XMV& X);
template <class RMV, class XMV>
void abs(const RMV& R, const XMV& X);
Replaces the entries of R by the absolute value of the corresponding entries in X.
Overwrites the entries of R with the magnitude of the corresponding entries in X and fences the
spaceinstance.Overwrites the entries of R with the magnitude of the corresponding entries in X and fences the default instance of
typename RMV::execution_space.
The function will throw a runtime exception if R.extent(0) != X.extent(0) || R.extent(1) != X.extent(1)
Parameters¶
- space:
execution space instance
- R:
output vector(s) storing the magnitude of the entries of
X- X:
input vector(s)
Type Requirements¶
execution_space must be a Kokkos execution space
RMV must be a Kokkos View of rank 1 or 2 that satisfies
Kokkos::SpaceAccessibility<execution_space, typename XMV::memory_space>::accessiblestd::is_same_v<typename RMV::value_type, typename RMV::non_const_value_type> == true
XMV must be a Kokkos View that satisfies
Kokkos::SpaceAccessibility<execution_space, typename XMV::memory_space>::accessibleXMV::rank == RMV::rank
Example¶
#include <iostream>
#include <Kokkos_Core.hpp>
#include <KokkosBlas1_abs.hpp>
int main(void) {
Kokkos::initialize();
{
Kokkos::View<double*> x("x", 5), y("y", 5);
auto h_x = Kokkos::create_mirror_view(x);
h_x(0) = 0.0;
h_x(1) = -1.0;
h_x(2) = -2.0;
h_x(3) = 3.0;
h_x(4) = -4.0;
std::cout << "orignal values:\n"
<< " x: {" << h_x(0) << ", " << h_x(1) << ", " << h_x(2) << ", " << h_x(3) << ", " << h_x(4) << "}"
<< std::endl;
Kokkos::deep_copy(x, h_x);
KokkosBlas::abs(y, x);
auto h_y = Kokkos::create_mirror_view(y);
Kokkos::deep_copy(h_y, y);
std::cout << "final values:\n"
<< " y: {" << h_y(0) << ", " << h_y(1) << ", " << h_y(2) << ", " << h_y(3) << ", " << h_y(4) << "}"
<< std::endl;
}
Kokkos::finalize();
}
output:
orignal values:
x: {0, -1, -2, 3, -4}
final values:
y: {0, 1, 2, 3, 4}