scale (Linear Algebra)


Import

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

Synopsis

 void archr_algebra_scale_f32(float *x, size_t nbelem, float factor);
(1)
 void archr_algebra_scale_f64(double *x, size_t nbelem, double factor);
(2)
 void archr_algebra_scale_zf32(void *x, size_t nbelem, const void *factor);
(3)
 void archr_algebra_scale_zf64(void *x, size_t nbelem, const void *factor);
(4)
 void archr_algebra_scaler_f32(float *first, float *last, float factor);
(5)
 void archr_algebra_scaler_f64(double *first, double *last, double factor);
(6)
 void archr_algebra_scaler_zf32(void *first, void *last, const void *factor);
(7)
 void archr_algebra_scaler_zf64(void *first, void *last, const void *factor);
(8)
 void scale(float *x, size_t nbelem, float factor);
(1)
 void scale(double *x, size_t nbelem, double factor);
(2)
 void scale(std::complex<float>*x, size_t nbelem, const std::complex<float>& factor);
(3)
 void scale(std::complex<double>*x, size_t nbelem, const std::complex<double>& factor);
(4)
 void scale(float *first, float *last, float factor);
(5)
 void scale(double *first, double *last, double factor);
(6)
 void scale(std::complex<float>*first, std::complex<float>*last, const std::complex<float>& factor);
(7)
 void scale(std::complex<double>*first, std::complex<double>*last, const std::complex<double>& factor);
(8)
template <typename Range> void scale(Range& x, float factor);
(9)
template <typename Range> void scale(Range& x, double factor);
(10)
template <typename Range> void scale(Range& x, const std::complex<float>& factor);
(11)
template <typename Range> void scale(Range& x, const std::complex<double>& factor);
(12)
subroutine archr_algebra_scale_f32(real(4), dimension(*) :: x, integer(4) :: nbelem, real(4) :: factor)
(1)
subroutine archr_algebra_scale_f64(real(8), dimension(*) :: x, integer(4) :: nbelem, real(8) :: factor)
(2)
subroutine archr_algebra_scale_zf32(complex(4), dimension(*) :: x, integer(4) :: nbelem, complex(4), parameter :: factor)
(3)
subroutine archr_algebra_scale_zf64(complex(8), dimension(*) :: x, integer(4) :: nbelem, complex(8), parameter :: factor)
(4)
function r = archr_algebra_scale(x, factor)
(1)

Description

This function scale the elements of data range stored in:

Parameters

x, first

the beginning of the X range.

last

the end of the X range.

y

the beginning of the Y range.

nbelem

the number of elements to process.

factor

the scaling factor to apply

Example

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


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

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

  archr_algebra_scale_f32(&v[0],2,5.f);
  printf("{");
  for(i=0;i<4;++i) printf("%f ",v[i]);
  puts("}");

  return 0;
}

Possible Output

{2.000000 6.000000 10.000000 14.000000 }
{10.000000 30.000000 10.000000 14.000000 }
#include <archr/algebra/scale.hpp>
#include <iostream>
#include <vector>

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

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

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

  archr::algebra::scale(v.data(),v.data() + 2,0.f);
  std::cout << "{";
  for(auto e : v) std::cout << e << " ";
  std::cout << "}\n";

  return 0;
}

Possible Output

{2 6 10 14 }
{10 30 50 14 }
{0 0 50 14 }
program 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_scale_f64(srcf64, size(srcf64), f64)

  print *, srcf64

end program

Possible Output

  0.25000000000000000       0.50000000000000000       0.75000000000000000        1.0000000000000000        1.2500000000000000        1.5000000000000000        1.7500000000000000        2.0000000000000000