axpy (Linear Algebra)


Import

#include <archr/algebra/axpy.h>
#include <archr/algebra/axpy.hpp>

Synopsis

 void archr_algebra_axpy_f32(float *y, const float *x, size_t nbelem, float alpha);
(1)
 void archr_algebra_axpy_f64(double *y, const double *x, size_t nbelem, double alpha);
(2)
 void archr_algebra_axpy_zf32(void *y, const void *x, size_t nbelem, const void *alpha);
(3)
 void archr_algebra_axpy_zf64(void *y, const void *x, size_t nbelem, const void *alpha);
(4)
 void archr_algebra_axpyr_f32(float *y, const float *first, const float *last, float alpha);
(5)
 void archr_algebra_axpyr_f64(double *y, const double *first, const double *last, double alpha);
(6)
 void archr_algebra_axpyr_zf32(void *y, const void *first, const void *last, const void *alpha);
(7)
 void archr_algebra_axpyr_zf64(void *y, const void *first, const void *last, const void *alpha);
(8)
 void axpy(const float *x, size_t nbelem, float *y, float alpha);
(1)
 void axpy(const double *x, size_t nbelem, double *y, double alpha);
(2)
 void axpy(const std::complex<float>*x, size_t nbelem, std::complex<float>*y, const std::complex<float>& alpha);
(3)
 void axpy(const std::complex<double>*x, size_t nbelem, std::complex<double>*y, const std::complex<double>& alpha);
(4)
 void axpy(const float *first, const float *last, float *y, float alpha);
(5)
 void axpy(const double *first, const double *last, double *y, double alpha);
(6)
 void axpy(const std::complex<float>*first, const std::complex<float>*last, std::complex<float>*y, const std::complex<float>& alpha);
(7)
 void axpy(const std::complex<double>*first, const std::complex<double>*last, std::complex<double>*y, const std::complex<double>& alpha);
(8)
template <typename Range> void axpy(const Range& x, Range& y, float alpha);
(9)
template <typename Range> void axpy(const Range& x, Range& y, double alpha);
(10)
template <typename Range> void axpy(const Range& x, Range& y, const std::complex<float>& alpha);
(11)
template <typename Range> void axpy(const Range& x, Range& y, const std::complex<double>& alpha);
(12)
subroutine archr_algebra_axpy_f32(real(4), dimension(*), parameter :: x, integer(4) :: nbelem, real(4), dimension(*) :: y, real(4) :: alpha)
(1)
subroutine archr_algebra_axpy_f64(real(8), dimension(*), parameter :: x, integer(4) :: nbelem, real(8), dimension(*) :: y, real(8) :: alpha)
(2)
subroutine archr_algebra_axpy_zf32(complex(4), dimension(*), parameter :: x, integer(4) :: nbelem, complex(4), dimension(*) :: y, complex(4), parameter :: alpha)
(3)
subroutine archr_algebra_axpy_zf64(complex(8), dimension(*), parameter :: x, integer(4) :: nbelem, complex(8), dimension(*) :: y, complex(8), parameter :: alpha)
(4)
function r = archr_algebra_axpy(x, y, alpha)
(1)

Description

This function apply the AXPY kernel over the data stored in:

$$\forall i \in [0, nbelem[\: ,\ Y[i] = Y[i] + \alpha \times X[i]$$

where X is the vector stored in the x and Y is the vector stored in y.

If language permits, results are stored in-place inside y. Otherwise, a new Range containing the result is returned.

Parameters

x, first

the beginning of the X range.

last

the end of the X range.

y

the beginning of the Y range.

nbelem

the number of elements to process.

alpha

the scaling factor to apply to X

Example

#include <archr/algebra/axpy.h>
#include <stdio.h>


int main()
{
  int i;
  float vx[] = {1,3,5,7};
  float vy[] = {2,4,6,8};

  archr_algebra_axpy_f32(&vy[0],&vx[0],4,0.1f);
  printf("{");
  for(i=0;i<4;++i) printf("%f ",vy[i]);
  puts("}");

  archr_algebra_axpy_f32(&vy[0],&vx[0],2,3.f);
  printf("{");
  for(i=0;i<4;++i) printf("%f ",vy[i]);
  puts("}");

  return 0;
}

Possible Output

{2.100000 4.300000 6.500000 8.700000 }
{5.100000 13.300000 6.500000 8.700000 }
#include <archr/algebra/axpy.hpp>
#include <iostream>
#include <vector>

int main()
{
  std::vector<float> vx{1,3,5,7}, vy{2,4,6,8};

  archr::algebra::axpy(vx,vy,0.1f);
  std::cout << "{";
  for(auto e : vy) std::cout << e << " ";
  std::cout << "}\n";

  archr::algebra::axpy(vx.data(),2,vy.data(),3.f);
  std::cout << "{";
  for(auto e : vy) std::cout << e << " ";
  std::cout << "}\n";

  archr::algebra::axpy(vx.data(),vx.data() + 3, vy.data(),1.f);
  std::cout << "{";
  for(auto e : vy) std::cout << e << " ";
  std::cout << "}\n";

  return 0;
}

Possible Output

{2.1 4.3 6.5 8.7 }
{5.1 13.3 6.5 8.7 }
{6.1 16.3 11.5 8.7 }
program axpy
  real(4)   , parameter     :: alpha = 3.5
  real(4)   , dimension(5) :: vx, vy

  do i=1,size(vy)
    vx(i) = 3
    vy(i) = i
  end do

  call archr_algebra_axpy_f32 (vy, vx, size(vy), alpha)

  print *, vy

end program

Possible Output

   11.5000000       12.5000000       13.5000000       14.5000000       15.5000000