strided_copy (Linear Algebra)


Import

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

Synopsis

 void archr_algebra_strided_copy_f32(float *dst, const float *src, size_t nbstride, ptrdiff_t incs, ptrdiff_t incd);
(1)
 void archr_algebra_strided_copy_f64(double *dst, const double *src, size_t nbstride, ptrdiff_t incs, ptrdiff_t incd);
(2)
 void archr_algebra_strided_copy_zf32(void *dst, const void *src, size_t nbstride, ptrdiff_t incs, ptrdiff_t incd);
(3)
 void archr_algebra_strided_copy_zf64(void *dst, const void *src, size_t nbstride, ptrdiff_t incs, ptrdiff_t incd);
(4)
 void archr_algebra_strided_copyr_f32(float *dst, const float *first, const float *last, ptrdiff_t incs, ptrdiff_t incd);
(5)
 void archr_algebra_strided_copyr_f64(double *dst, const double *first, const double *last, ptrdiff_t incs, ptrdiff_t incd);
(6)
 void archr_algebra_strided_copyr_zf32(void *dst, const void *first, const void *last, ptrdiff_t incs, ptrdiff_t incd);
(7)
 void archr_algebra_strided_copyr_zf64(void *dst, const void *first, const void *last, ptrdiff_t incs, ptrdiff_t incd);
(8)
 void strided_copy(const float *src, size_t nbstride, float *dst, ptrdiff_t incs, ptrdiff_t incd);
(1)
 void strided_copy(const double *src, size_t nbstride, double *dst, ptrdiff_t incs, ptrdiff_t incd);
(2)
 void strided_copy(const std::complex<float>*src, size_t nbstride, std::complex<float>*dst, ptrdiff_t incs, ptrdiff_t incd);
(3)
 void strided_copy(const std::complex<double>*src, size_t nbstride, std::complex<double>*dst, ptrdiff_t incs, ptrdiff_t incd);
(4)
 void strided_copy(const float *first, const float *last, float *dst, ptrdiff_t incs, ptrdiff_t incd);
(5)
 void strided_copy(const double *first, const double *last, double *dst, ptrdiff_t incs, ptrdiff_t incd);
(6)
 void strided_copy(const std::complex<float>*first, const std::complex<float>*last, std::complex<float>*dst, ptrdiff_t incs, ptrdiff_t incd);
(7)
 void strided_copy(const std::complex<double>*first, const std::complex<double>*last, std::complex<double>*dst, ptrdiff_t incs, ptrdiff_t incd);
(8)
subroutine archr_algebra_strided_copy_f32(real(4), dimension(*), parameter :: src, integer(4) :: nbstride, real(4), dimension(*) :: dst, ptrdiff_t :: incs, ptrdiff_t :: incd)
(1)
subroutine archr_algebra_strided_copy_f64(real(8), dimension(*), parameter :: src, integer(4) :: nbstride, real(8), dimension(*) :: dst, ptrdiff_t :: incs, ptrdiff_t :: incd)
(2)
subroutine archr_algebra_strided_copy_zf32(complex(4), dimension(*), parameter :: src, integer(4) :: nbstride, complex(4), dimension(*) :: dst, ptrdiff_t :: incs, ptrdiff_t :: incd)
(3)
subroutine archr_algebra_strided_copy_zf64(complex(8), dimension(*), parameter :: src, integer(4) :: nbstride, complex(8), dimension(*) :: dst, ptrdiff_t :: incs, ptrdiff_t :: incd)
(4)

Description

This function copy every elements of the source range into the destination stored in:

$$\forall i \in [0, nbstride[\: ,\ dst[i \times incd] = src[i \times incs]$$

Parameters

src, first

the beginning of the source range.

last

the end of the source range.

dst

the beginning of the destination range.

nbstride

the number of strides to process.

incs

the stride between element of src to process.

incd

the stride between element of dst to process.

Example

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

int main()
{
  int i, ok = 1;
  float v[6];
  float w[] = {2,4,6,8,10,12};

  printf("{");
  for(i=0;i<6;++i) printf("%f ",w[i]);
  puts("}");

  archr_algebra_strided_copy_f32(&v[0], &w[0], 3, 2, 2);

  printf("{");
  for(i=0;i<6;++i) printf("%f ",v[i]);
  puts("}");

  return 0;
}

Possible Output

{2.000000 4.000000 6.000000 8.000000 10.000000 12.000000 }
{2.000000 0.000000 6.000000 0.000000 10.000000 0.000000 }
#include <archr/algebra/strided_copy.hpp>
#include <iostream>
#include <vector>

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

  std::cout << "{";
  for(auto e : v) std::cout << e << " ";
  std::cout << "}\n";

  std::cout << "{";
  for(auto e : w) std::cout << e << " ";
  std::cout << "}\n\n";

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

  std::cout << "{";
  for(auto e : v) std::cout << e << " ";
  std::cout << "}\n";

  std::cout << "{";
  for(auto e : w) std::cout << e << " ";
  std::cout << "}\n";

  return 0;
}

Possible Output

{1 3 5 7 }
{2 4 6 8 }

{1 3 5 7 }
{1 4 5 8 }
program strided_copy
  integer(4), parameter     :: sz = 7
  real(8)   , dimension(sz) :: dstf64, srcf64

  do i=1,sz
    srcf64(i) = i
    dstf64(i) = 0
  end do

  print *, srcf64

  call archr_algebra_strided_copy_f64(dstf64, srcf64, 3, 2, 2)

  print *, dstf64

end program

Possible Output

   1.0000000000000000        2.0000000000000000        3.0000000000000000        4.0000000000000000        5.0000000000000000        6.0000000000000000        7.0000000000000000
   1.0000000000000000        0.0000000000000000        3.0000000000000000        0.0000000000000000        5.0000000000000000        0.0000000000000000        0.0000000000000000