strided_axpy (Linear Algebra)


Import

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

Synopsis

 void archr_algebra_strided_axpy_f32(float *y, const float *x, size_t nbstride, float alpha, ptrdiff_t incx, ptrdiff_t incy);
(1)
 void archr_algebra_strided_axpy_f64(double *y, const double *x, size_t nbstride, double alpha, ptrdiff_t incx, ptrdiff_t incy);
(2)
 void archr_algebra_strided_axpy_zf32(void *y, const void *x, size_t nbstride, const void *alpha, ptrdiff_t incx, ptrdiff_t incy);
(3)
 void archr_algebra_strided_axpy_zf64(void *y, const void *x, size_t nbstride, const void *alpha, ptrdiff_t incx, ptrdiff_t incy);
(4)
 void archr_algebra_strided_axpyr_f32(float *y, const float *first, const float *last, float alpha, ptrdiff_t incx, ptrdiff_t incy);
(5)
 void archr_algebra_strided_axpyr_f64(double *y, const double *first, const double *last, double alpha, ptrdiff_t incx, ptrdiff_t incy);
(6)
 void archr_algebra_strided_axpyr_zf32(void *y, const void *first, const void *last, const void *alpha, ptrdiff_t incx, ptrdiff_t incy);
(7)
 void archr_algebra_strided_axpyr_zf64(void *y, const void *first, const void *last, const void *alpha, ptrdiff_t incx, ptrdiff_t incy);
(8)
 void strided_axpy(const float *x, size_t nbstride, float *y, float alpha, ptrdiff_t incx, ptrdiff_t incy);
(1)
 void strided_axpy(const double *x, size_t nbstride, double *y, double alpha, ptrdiff_t incx, ptrdiff_t incy);
(2)
 void strided_axpy(const std::complex<float>*x, size_t nbstride, std::complex<float>*y, const std::complex<float>& alpha, ptrdiff_t incx, ptrdiff_t incy);
(3)
 void strided_axpy(const std::complex<double>*x, size_t nbstride, std::complex<double>*y, const std::complex<double>& alpha, ptrdiff_t incx, ptrdiff_t incy);
(4)
 void strided_axpy(const float *first, const float *last, float *y, float alpha, ptrdiff_t incx, ptrdiff_t incy);
(5)
 void strided_axpy(const double *first, const double *last, double *y, double alpha, ptrdiff_t incx, ptrdiff_t incy);
(6)
 void strided_axpy(const std::complex<float>*first, const std::complex<float>*last, std::complex<float>*y, const std::complex<float>& alpha, ptrdiff_t incx, ptrdiff_t incy);
(7)
 void strided_axpy(const std::complex<double>*first, const std::complex<double>*last, std::complex<double>*y, const std::complex<double>& alpha, ptrdiff_t incx, ptrdiff_t incy);
(8)
subroutine archr_algebra_strided_axpy_f32(real(4), dimension(*), parameter :: x, integer(4) :: nbstride, real(4), dimension(*) :: y, real(4) :: alpha, ptrdiff_t :: incx, ptrdiff_t :: incy)
(1)
subroutine archr_algebra_strided_axpy_f64(real(8), dimension(*), parameter :: x, integer(4) :: nbstride, real(8), dimension(*) :: y, real(8) :: alpha, ptrdiff_t :: incx, ptrdiff_t :: incy)
(2)
subroutine archr_algebra_strided_axpy_zf32(complex(4), dimension(*), parameter :: x, integer(4) :: nbstride, complex(4), dimension(*) :: y, complex(4), parameter :: alpha, ptrdiff_t :: incx, ptrdiff_t :: incy)
(3)
subroutine archr_algebra_strided_axpy_zf64(complex(8), dimension(*), parameter :: x, integer(4) :: nbstride, complex(8), dimension(*) :: y, complex(8), parameter :: alpha, ptrdiff_t :: incx, ptrdiff_t :: incy)
(4)

Description

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

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

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.

nbstride

the number of elements to process.

alpha

the scaling factor to apply to X.

incx

the stride between element of X to process.

incy

the stride between element of Y to process.

Example

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


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

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

  return 0;
}

Possible Output

{2.100000 4.000000 6.500000 8.000000 }
#include <archr/algebra/strided_axpy.hpp>
#include <iostream>
#include <vector>

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

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

  return 0;
}

Possible Output

{2.1 4 6.5 8 }
program strided_axpy
  real(4)   , parameter     :: alpha = 3.5
  real(4)   , dimension(7)  :: vx, vy
  integer(4), parameter     :: stride = 4, incx = 2, incy = 2

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

  call archr_algebra_strided_axpy_f32 (vy, vx, stride, alpha, incx, incy)

  print *, vy

end program

Possible Output

   11.5000000       2.00000000       13.5000000       4.00000000       15.5000000       6.00000000       17.5000000