strided_swap (Linear Algebra)


Import

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

Synopsis

 void archr_algebra_strided_swap_f32(float *lhs, float *rhs, size_t nbstride, ptrdiff_t incr, ptrdiff_t incl);
(1)
 void archr_algebra_strided_swap_f64(double *lhs, double *rhs, size_t nbstride, ptrdiff_t incr, ptrdiff_t incl);
(2)
 void archr_algebra_strided_swap_zf32(void *lhs, void *rhs, size_t nbstride, ptrdiff_t incr, ptrdiff_t incl);
(3)
 void archr_algebra_strided_swap_zf64(void *lhs, void *rhs, size_t nbstride, ptrdiff_t incr, ptrdiff_t incl);
(4)
 void archr_algebra_strided_swapr_f32(float *lhs, float *first, float *last, ptrdiff_t incr, ptrdiff_t incl);
(5)
 void archr_algebra_strided_swapr_f64(double *lhs, double *first, double *last, ptrdiff_t incr, ptrdiff_t incl);
(6)
 void archr_algebra_strided_swapr_zf32(void *lhs, void *first, void *last, ptrdiff_t incr, ptrdiff_t incl);
(7)
 void archr_algebra_strided_swapr_zf64(void *lhs, void *first, void *last, ptrdiff_t incr, ptrdiff_t incl);
(8)
 void strided_swap(float *rhs, size_t nbstride, float *lhs, ptrdiff_t incr, ptrdiff_t incl);
(1)
 void strided_swap(double *rhs, size_t nbstride, double *lhs, ptrdiff_t incr, ptrdiff_t incl);
(2)
 void strided_swap(std::complex<float>*rhs, size_t nbstride, std::complex<float>*lhs, ptrdiff_t incr, ptrdiff_t incl);
(3)
 void strided_swap(std::complex<double>*rhs, size_t nbstride, std::complex<double>*lhs, ptrdiff_t incr, ptrdiff_t incl);
(4)
 void strided_swap(float *first, float *last, float *lhs, ptrdiff_t incr, ptrdiff_t incl);
(5)
 void strided_swap(double *first, double *last, double *lhs, ptrdiff_t incr, ptrdiff_t incl);
(6)
 void strided_swap(std::complex<float>*first, std::complex<float>*last, std::complex<float>*lhs, ptrdiff_t incr, ptrdiff_t incl);
(7)
 void strided_swap(std::complex<double>*first, std::complex<double>*last, std::complex<double>*lhs, ptrdiff_t incr, ptrdiff_t incl);
(8)
subroutine archr_algebra_strided_swap_f32(real(4), dimension(*) :: rhs, integer(4) :: nbstride, real(4), dimension(*) :: lhs, ptrdiff_t :: incr, ptrdiff_t :: incl)
(1)
subroutine archr_algebra_strided_swap_f64(real(8), dimension(*) :: rhs, integer(4) :: nbstride, real(8), dimension(*) :: lhs, ptrdiff_t :: incr, ptrdiff_t :: incl)
(2)
subroutine archr_algebra_strided_swap_zf32(complex(4), dimension(*) :: rhs, integer(4) :: nbstride, complex(4), dimension(*) :: lhs, ptrdiff_t :: incr, ptrdiff_t :: incl)
(3)
subroutine archr_algebra_strided_swap_zf64(complex(8), dimension(*) :: rhs, integer(4) :: nbstride, complex(8), dimension(*) :: lhs, ptrdiff_t :: incr, ptrdiff_t :: incl)
(4)

Description

This function swaps every element of the input strided ranges stored in:

Parameters

lhs, first

the beginning of the first range.

last

the end of the first range.

rhs

the beginning of the second range.

nbstride

the number of strides to process.

incl

the stride between element of lhs to process.

incr

the stride between element of rhs to process.

Example

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

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

  printf("v {%f %f %f %f}\n", v[0], v[1], v[2], v[3]);
  printf("w {%f %f %f %f}\n\n", w[0], w[1], w[2], w[3]);

  archr_algebra_strided_swap_f32(&v[0], &w[0], 2, 2, 2);

  printf("v {%f %f %f %f}\n", v[0], v[1], v[2], v[3]);
  printf("w {%f %f %f %f}\n", w[0], w[1], w[2], w[3]);

  return 0;
}

Possible Output

v {1.000000 3.000000 5.000000 7.000000}
w {2.000000 4.000000 6.000000 8.000000}

v {2.000000 3.000000 6.000000 7.000000}
w {1.000000 4.000000 5.000000 8.000000}
#include <archr/algebra/strided_swap.hpp>
#include <iostream>
#include <vector>

void print(std::vector<float> const& v)
{
  std::cout << "{ ";
  for(auto e : v) std::cout << e << " ";
  std::cout << "}";
}

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

  std::cout << "v = ";
  print(v);
  std::cout << "\n";

  std::cout << "w = ";
  print(w);
  std::cout << "\n\n";

  archr::algebra::strided_swap(v.data(),2,w.data(),2,2);

  std::cout << "v = ";
  print(v);
  std::cout << "\n";

  std::cout << "w = ";
  print(w);
  std::cout << "\n";

  return 0;
}

Possible Output

v = { 1 3 5 7 }
w = { 2 4 6 8 }

v = { 2 3 6 7 }
w = { 1 4 5 8 }
program strided_swap
  integer(4), parameter     :: sz = 7
  real(4)   , dimension(sz) :: dstf32, srcf32

  do i=1,sz
    srcf32(i) =  i
    dstf32(i) = -i
  end do

  print *, dstf32
  print *, srcf32

  call archr_algebra_strided_swap_f32(dstf32, srcf32, 3, 2, 2)

  print *, dstf32
  print *, srcf32

end program

Possible Output

  -1.00000000      -2.00000000      -3.00000000      -4.00000000      -5.00000000      -6.00000000      -7.00000000
   1.00000000       2.00000000       3.00000000       4.00000000       5.00000000       6.00000000       7.00000000
   1.00000000      -2.00000000       3.00000000      -4.00000000       5.00000000      -6.00000000      -7.00000000
  -1.00000000       2.00000000      -3.00000000       4.00000000      -5.00000000       6.00000000       7.00000000