strided_scale (Linear Algebra)


Import

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

Synopsis

 void archr_algebra_strided_scale_f32(float *x, size_t nbstride, float factor, ptrdiff_t inc);
(1)
 void archr_algebra_strided_scale_f64(double *x, size_t nbstride, double factor, ptrdiff_t inc);
(2)
 void archr_algebra_strided_scale_zf32(void *x, size_t nbstride, const void *factor, ptrdiff_t inc);
(3)
 void archr_algebra_strided_scale_zf64(void *x, size_t nbstride, const void *factor, ptrdiff_t inc);
(4)
 void archr_algebra_strided_scaler_f32(float *first, float *last, float factor, ptrdiff_t inc);
(5)
 void archr_algebra_strided_scaler_f64(double *first, double *last, double factor, ptrdiff_t inc);
(6)
 void archr_algebra_strided_scaler_zf32(void *first, void *last, const void *factor, ptrdiff_t inc);
(7)
 void archr_algebra_strided_scaler_zf64(void *first, void *last, const void *factor, ptrdiff_t inc);
(8)
 void strided_scale(float *x, size_t nbstride, float factor, ptrdiff_t inc);
(1)
 void strided_scale(double *x, size_t nbstride, double factor, ptrdiff_t inc);
(2)
 void strided_scale(std::complex<float>*x, size_t nbstride, const std::complex<float>& factor, ptrdiff_t inc);
(3)
 void strided_scale(std::complex<double>*x, size_t nbstride, const std::complex<double>& factor, ptrdiff_t inc);
(4)
 void strided_scale(float *first, float *last, float factor, ptrdiff_t inc);
(5)
 void strided_scale(double *first, double *last, double factor, ptrdiff_t inc);
(6)
 void strided_scale(std::complex<float>*first, std::complex<float>*last, const std::complex<float>& factor, ptrdiff_t inc);
(7)
 void strided_scale(std::complex<double>*first, std::complex<double>*last, const std::complex<double>& factor, ptrdiff_t inc);
(8)
subroutine archr_algebra_strided_scale_f32(real(4), dimension(*) :: x, integer(4) :: nbstride, real(4) :: factor, ptrdiff_t :: inc)
(1)
subroutine archr_algebra_strided_scale_f64(real(8), dimension(*) :: x, integer(4) :: nbstride, real(8) :: factor, ptrdiff_t :: inc)
(2)
subroutine archr_algebra_strided_scale_zf32(complex(4), dimension(*) :: x, integer(4) :: nbstride, complex(4), parameter :: factor, ptrdiff_t :: inc)
(3)
subroutine archr_algebra_strided_scale_zf64(complex(8), dimension(*) :: x, integer(4) :: nbstride, complex(8), parameter :: factor, ptrdiff_t :: inc)
(4)

Description

This function strided_scale the elements of data range stored in:

$$\forall i \in [0, nbstride[\: ,\ X[i \times inc] = factor \times X[i \times inc]$$

where X is the vector stored in the x range.

If language permits, results are stored in-place inside x. 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.

nbstride

the number of elements to process.

factor

the scaling factor to apply

inc

the stride between element of X to process.

Example

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


int main()
{
  int i;
  float v[] = {1,3,5,7,9,11};

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

  return 0;
}

Possible Output

{2.000000 3.000000 5.000000 14.000000 9.000000 11.000000 }
#include <archr/algebra/strided_scale.hpp>
#include <iostream>
#include <vector>

int main()
{
  std::vector<float> v{1,3,5,7,9,11};

  archr::algebra::strided_scale(v.data(),3,5.f,2);
  std::cout << "{";
  for(auto e : v) std::cout << e << " ";
  std::cout << "}\n";

  return 0;
}

Possible Output

{5 3 25 7 45 11 }
program strided_scale
  integer(4), parameter     :: sz = 8
  real(8)   , dimension(sz) :: srcf64
  real(8)                   :: f64

  f64 = 0.25

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

  call archr_algebra_strided_scale_f64(srcf64, 4, f64, 2)

  print *, srcf64

end program

Possible Output

  0.25000000000000000        2.0000000000000000       0.75000000000000000        4.0000000000000000        1.2500000000000000        6.0000000000000000        1.7500000000000000        8.0000000000000000