strided_dot (Linear Algebra)


Import

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

Synopsis

 float archr_algebra_strided_dot_f32(const float *x, size_t nbstride, const float *y, ptrdiff_t incx, ptrdiff_t incy);
(1)
 double archr_algebra_strided_dot_f64(const double *x, size_t nbstride, const double *y, ptrdiff_t incx, ptrdiff_t incy);
(2)
 void archr_algebra_strided_dot_zf32(void *z, const void *x, size_t nbstride, const void *y, ptrdiff_t incx, ptrdiff_t incy);
(3)
 void archr_algebra_strided_dot_zf64(void *z, const void *x, size_t nbstride, const void *y, ptrdiff_t incx, ptrdiff_t incy);
(4)
 float archr_algebra_strided_dotr_f32(const float *first, const float *last, const float *y, ptrdiff_t incx, ptrdiff_t incy);
(5)
 double archr_algebra_strided_dotr_f64(const double *first, const double *last, const double *y, ptrdiff_t incx, ptrdiff_t incy);
(6)
 void archr_algebra_strided_dotr_zf32(void *z, const void *first, const void *last, const void *y, ptrdiff_t incx, ptrdiff_t incy);
(7)
 void archr_algebra_strided_dotr_zf64(void *z, const void *first, const void *last, const void *y, ptrdiff_t incx, ptrdiff_t incy);
(8)
 float strided_dot(const float *x, size_t nbstride, const float *y, ptrdiff_t incx, ptrdiff_t incy);
(1)
 double strided_dot(const double *x, size_t nbstride, const double *y, ptrdiff_t incx, ptrdiff_t incy);
(2)
 std::complex<float> strided_dot(const std::complex<float>*x, size_t nbstride, const std::complex<float>*y, ptrdiff_t incx, ptrdiff_t incy);
(3)
 std::complex<double> strided_dot(const std::complex<double>*x, size_t nbstride, const std::complex<double>*y, ptrdiff_t incx, ptrdiff_t incy);
(4)
 float strided_dot(const float *first, const float *last, const float *y, ptrdiff_t incx, ptrdiff_t incy);
(5)
 double strided_dot(const double *first, const double *last, const double *y, ptrdiff_t incx, ptrdiff_t incy);
(6)
 std::complex<float> strided_dot(const std::complex<float>*first, const std::complex<float>*last, const std::complex<float>*y, ptrdiff_t incx, ptrdiff_t incy);
(7)
 std::complex<double> strided_dot(const std::complex<double>*first, const std::complex<double>*last, const std::complex<double>*y, ptrdiff_t incx, ptrdiff_t incy);
(8)
subroutine archr_algebra_strided_dot_f32(real(4) :: r, real(4), dimension(*), parameter :: x, integer(4) :: nbstride, real(4), dimension(*), parameter :: y, ptrdiff_t :: incx, ptrdiff_t :: incy)
(1)
subroutine archr_algebra_strided_dot_f64(real(8) :: r, real(8), dimension(*), parameter :: x, integer(4) :: nbstride, real(8), dimension(*), parameter :: y, ptrdiff_t :: incx, ptrdiff_t :: incy)
(2)
subroutine archr_algebra_strided_dot_zf32(complex(4) :: r, complex(4), dimension(*), parameter :: x, integer(4) :: nbstride, complex(4), dimension(*), parameter :: y, ptrdiff_t :: incx, ptrdiff_t :: incy)
(3)
subroutine archr_algebra_strided_dot_zf64(complex(8) :: r, complex(8), dimension(*), parameter :: x, integer(4) :: nbstride, complex(8), dimension(*), parameter :: y, ptrdiff_t :: incx, ptrdiff_t :: incy)
(4)

Description

This function computes the norm2 of a given strided data ranges stored in:

$$\sum_{i=0}^{nbstride} X[i \times incx] Y[i \times incy]$$

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

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.

incx

the stride between element of X to process.

incy

the stride between element of Y to process.

Return value

The strided_dot product between the elements of the two given ranges.

Example

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

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

  printf("strided_dot({1,3,5,7},{2,4,6,8}) = %f\n", archr_algebra_strided_dot_f32(&v[0], 2, &w[0],2,2) );

  return 0;
}

Possible Output

strided_dot({1,3,5,7},{2,4,6,8}) = 32.000000
#include <archr/algebra/strided_dot.hpp>
#include <iostream>
#include <vector>

int main()
{
 std::vector<float> v{1,3,5,7,9,11}, w{2,4,6,8,10,12};

 std::cout  << "strided_dot({1,3,5,7,9,11}, {2,4,6,8,10,12},2, 2 ) = "
            << archr::algebra::strided_dot(v.data(), 3, w.data(),2,2) << "\n";

  return 0;
}

Possible Output

strided_dot({1,3,5,7,9,11}, {2,4,6,8,10,12},2, 2 ) = 122
program strided_dot
  integer(4), parameter     :: sz = 9
  real(8)   , dimension(sz) :: i1f64, i2f64
  real(8)                   :: rf64

  do i=1,sz
    i1f64(i) = 1
    i2f64(i) = i
  end do

  call archr_algebra_strided_dot_f64(rf64, i1f64, 4, i2f64,2, 2)

  print *, rf64

end program

Possible Output

   16.000000000000000