dot (Linear Algebra)


Import

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

Synopsis

 float archr_algebra_dot_f32(const float *x, size_t nbelem, const float *y);
(1)
 double archr_algebra_dot_f64(const double *x, size_t nbelem, const double *y);
(2)
 void archr_algebra_dot_zf32(void *z, const void *x, size_t nbelem, const void *y);
(3)
 void archr_algebra_dot_zf64(void *z, const void *x, size_t nbelem, const void *y);
(4)
 float archr_algebra_dotr_f32(const float *first, const float *last, const float *y);
(5)
 double archr_algebra_dotr_f64(const double *first, const double *last, const double *y);
(6)
 void archr_algebra_dotr_zf32(void *z, const void *first, const void *last, const void *y);
(7)
 void archr_algebra_dotr_zf64(void *z, const void *first, const void *last, const void *y);
(8)
 float dot(const float *x, size_t nbelem, const float *y);
(1)
 double dot(const double *x, size_t nbelem, const double *y);
(2)
 std::complex<float> dot(const std::complex<float>*x, size_t nbelem, const std::complex<float>*y);
(3)
 std::complex<double> dot(const std::complex<double>*x, size_t nbelem, const std::complex<double>*y);
(4)
 float dot(const float *first, const float *last, const float *y);
(5)
 double dot(const double *first, const double *last, const double *y);
(6)
 std::complex<float> dot(const std::complex<float>*first, const std::complex<float>*last, const std::complex<float>*y);
(7)
 std::complex<double> dot(const std::complex<double>*first, const std::complex<double>*last, const std::complex<double>*y);
(8)
template <typename Range> typename Range::value_type dot(const Range& x, const Range& y);
(9)
subroutine archr_algebra_dot_f32(real(4) :: r, real(4), dimension(*), parameter :: x, integer(4) :: nbelem, real(4), dimension(*), parameter :: y)
(1)
subroutine archr_algebra_dot_f64(real(8) :: r, real(8), dimension(*), parameter :: x, integer(4) :: nbelem, real(8), dimension(*), parameter :: y)
(2)
subroutine archr_algebra_dot_zf32(complex(4) :: r, complex(4), dimension(*), parameter :: x, integer(4) :: nbelem, complex(4), dimension(*), parameter :: y)
(3)
subroutine archr_algebra_dot_zf64(complex(8) :: r, complex(8), dimension(*), parameter :: x, integer(4) :: nbelem, complex(8), dimension(*), parameter :: y)
(4)
function r = archr_algebra_dot(x, y)
(1)

Description

This function computes the dot product between the elements of two data ranges stored in:

$$\sum_{i=0}^{nbelem} X[i] Y[i]$$

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

Parameters

x, first

the beginning of the first dot product range.

last

the end of the first dot product range.

y

the beginning of the second dot product range.

nbelem

the number of elements to process.

Return value

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

Example

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

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

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

  return 0;
}

Possible Output

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

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

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

  return 0;
}

Possible Output

dot({1,3,5,7}, {2,4,6,8}) = 100
dot({1,3,5}  , {2,4,6}  ) = 44
dot({1,3}    , {2,4}    ) = 14
program dot
  integer(4), parameter     :: sz = 1337
  real(8)   , dimension(sz) :: i1f64, i2f64
  real(8)                   :: rf64

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

  call archr_algebra_dot_f64(rf64, i1f64, size(i1f64), i2f64)

  print *, rf64

end program

Possible Output

   894453.00000000000