KokkosBlas::axpy ################ Defined in header: :code:`KokkosBlas1_axpby.hpp` .. code:: c++ template void axpy(const execution_space& space, const AV& a, const XMV& X, const YMV& Y) template void axpy(const AV& a, const XMV& X, const YMV& Y) Add entries of :code:`X` scaled by coeffecient :code:`a` to entries of :code:`Y`: ``Y += a*X`` 1. iterate over the entries of ``Y`` and add the corresponding entries of ``X`` scaled by ``a`` using the resources of ``space`` 2. iterate over the entries of ``Y`` and add the corresponding entries of ``X`` scaled by ``a`` using the resources of the default instance of ``typename XMV::execution_space`` The function will throw a runtime exception if any of the following conditions are **not** met: - ``Y.extent(0) == X.extent(0) && Y.extent(1) == X.extent(1)`` - ``Kokkos::is_view_v && (a.extent(0) == 1 || a.extent(0) == X.extent(1)`` Parameters ========== :space: execution space instance :a: scaling factor :X, Y: vector(s) of input and output values respectively Type Requirements ----------------- - `execution_space` must be a Kokkos `execution space `_ - `XMV` must be a Kokkos `View `_ of rank 1 or 2 that satisfies - ``Kokkos::SpaceAccessibility::accessible == true`` - `YMV` must be a Kokkos `View `_ that satisfies - ``YMV::rank == XMV::rank`` - ``std::is_same_v == true`` - ``Kokkos::SpaceAccessibility::accessible == true`` - `AV` must be a scalar or a Kokkos `View `_ that satisfies - ``(AV::rank == XMV::rank - 1) || (AV::rank == 0)`` - ``Kokkos::SpaceAccessibility::accessible == true`` Example ======= .. code:: c++ #include #include int main(int argc, char* argv[]) { Kokkos::initialize(); { int N = atoi(argv[1]); Kokkos::View x("X",N); Kokkos::View y("Y",N); Kokkos::deep_copy(x,3.0); Kokkos::deep_copy(y,2.0); double alpha = 1.5; KokkosBlas::axpy(alpha,x,y); double sum = 0.0; Kokkos::parallel_reduce("CheckValue", N, KOKKOS_LAMBDA (const int& i, double& lsum) { lsum += y(i); },sum); printf("Sum: %lf Expected: %lf Diff: %e\n",sum,1.0*N*(2.0+1.5*3.0),sum-1.0*N); } Kokkos::finalize(); }