tan (Core Functions)


Import

#include <archr/core/tan.h>
#include <archr/core/tan.hpp>
import archr.core
atomsLoads('archr')

Synopsis

 float archr_core_tan_1f32(const float i1);
(1)
 double archr_core_tan_1f64(const double i1);
(2)
 void archr_core_tan_f32(float *o0, const float *i1, size_t sz);
(3)
 void archr_core_tan_f64(double *o0, const double *i1, size_t sz);
(4)
 float tan(const float i1);
(1)
 double tan(const double i1);
(2)
 void tan(const float *i1, size_t sz, float *o0);
(3)
 void tan(const double *i1, size_t sz, double *o0);
(4)
template <typename Range> void tan(const Range& i1, Range& o0);
(5)
subroutine archr_core_tan_1f32(real(4) :: r, real(4), parameter :: i1)
(1)
subroutine archr_core_tan_1f64(real(8) :: r, real(8), parameter :: i1)
(2)
subroutine archr_core_tan_f32(real(4), dimension(*), parameter :: i1, integer(4) :: sz, real(4), dimension(*) :: o0)
(3)
subroutine archr_core_tan_f64(real(8), dimension(*), parameter :: i1, integer(4) :: sz, real(8), dimension(*) :: o0)
(4)
def tan(i1):
    return o0
(1)
function o0 = archr_core_tan(i1)
(1)

Description

Computes the tan:

Parameters

i1_first, i1_last

The range of input elements

o0

The beginning of the destination range, may be equal to i1

i1

The scalar/contiguous data input element

Example


#include <time.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <stddef.h>
#include <archr/core/tan.h>

double rand_in(double min, double max) {
  return min + ((double)(max - min) * ((double)rand() / RAND_MAX));
}

int main() {
  time_t t;
  size_t i;
  size_t sz = 10;
  float* i1 = (float*)malloc(sz * sizeof(float));
  float* o1 = (float*)malloc(sz * sizeof(float));

  srand((unsigned int)time(&t));
  for (i = 0; i < sz; ++i) {
    i1[i] = (float)rand_in((float)-10, (float)10);
  }
  archr_core_tan_f32(o1, i1, sz);
  for (i = 0; i < sz; ++i) {
    printf("%4lu: tan(%f) = %f\n", i, (double)i1[i], (double)o1[i]);
  }
}

Possible Output

   0: tan(9.422858) = -0.001920
   1: tan(1.837882) = -3.654663
   2: tan(-3.262253) = -0.121249
   3: tan(-7.822172) = -31.426107
   4: tan(-5.006380) = 3.302897
   5: tan(-8.051063) = 5.008193
   6: tan(4.945784) = -4.206506
   7: tan(9.347142) = -0.077792
   8: tan(5.106514) = -2.404507
   9: tan(6.345078) = 0.061972

#include <ctime>
#include <cstdio>
#include <cstdlib>
#include <cstdint>
#include <cstddef>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <archr/core/tan.hpp>

double rand_in(double min, double max) {
  return min + (double(max - min) * (double(std::rand()) / RAND_MAX));
}

int main() {
  std::size_t i;
  std::size_t sz = 10;
  std::vector<float> i1(sz);
  std::vector<float> o1(sz);

  std::srand(std::time(0));
  std::generate(i1.begin(), i1.end(), []() { return rand_in(float(-10), float(10)); });
  archr::core::tan(i1.data(), sz, o1.data());
  for (i = 0; i < sz; ++i) {
    std::cout << std::setw(4) << i << ": " << "tan" << "(" << i1[i] << ")" << " = " << o1[i] << std::endl;
  }
}

Possible Output

   0: tan(9.42286) = -0.00191972
   1: tan(1.83788) = -3.65466
   2: tan(-3.26225) = -0.121249
   3: tan(-7.82217) = -31.4261
   4: tan(-5.00638) = 3.3029
   5: tan(-8.05106) = 5.00819
   6: tan(4.94578) = -4.20651
   7: tan(9.34714) = -0.0777921
   8: tan(5.10651) = -2.40451
   9: tan(6.34508) = 0.0619723

program main
  integer(4), parameter  :: sz = 10
  real(4), dimension(sz) :: o0
  real(4), dimension(sz) :: i0
  real(8)                :: r0, r1
  real(8)                :: min0, max0
  real(8)                :: min1, max1
  real(8)                :: min2, max2
  ! Init:
    min0 = -10
    max0 = 10
  do i=1,sz
    r0 = random_in(min0, max0)
    i0(i) = r0
  end do
  ! Example:
  call archr_core_tan_f32(o0, i0, size(i0))
  ! Output:
  do i=1,sz
    print *, i, ": ", o0(i)
  end do
contains
  ! Generate a random number within a range
  function random_in(mn, mx) result(r)
    real(8) :: r
    real(8), intent(in) :: mn, mx
    r = mn + (rand() * (mx - mn))
  end function random_in
end program

Possible Output

           1 :  -0.648144066    
           2 :   -1.89881480    
           3 :   -2.36710024    
           4 :   -1.08686280    
           5 :   0.768666685    
           6 :   0.779904902    
           7 :   0.382888108    
           8 :   0.465534329    
           9 :   0.476084054    
          10 :  -0.896577120    
atomsLoad('archr');

// Increase the stacksize
v = getversion('scilab');
if v(1) < 6 stacksize('max'); end

// The number of internal iterations
iter = 2000;

//
sizes = [];
times = [];
speed = [];

// Main loop
for n = 10:17
    sz = 2^n;
    I  = rand(1, sz);
    timer();
    for j = 1:iter
        R1 = tan(I);
    end
    T1 = timer();
    
    timer();
    for j = 1:iter
        R2 = archr_core_tan(I);
    end
    T2 = timer();

    sizes = [sizes n];
    times = [times; T1 T2];
    speed = [speed; 1 (T1 / T2)];

    printf("\n");
    printf("============================\n");
    printf("Size is: %d (2^%d)\n", sz, n);
    printf("\n");
    printf("Raw timing:\n");
    printf("  SciLab: %f\n", T1);
    printf("  Arch-R: %f\n", T2);
    printf("----------------------------\n");
    printf("Speedup:\n");
    printf("  x%f\n", T1 / T2);
    printf("============================\n");
end

// Plot timings
scf(0);
bar(sizes, times);
xlabel("Size (power-of-2)");
ylabel("Time (s)");
legend(["SciLab"; "Archr-R"], 'in_upper_left');
title("Raw timings between Archr-R and SciLab");

// Plot speedup
scf(1);
bar(sizes, speed);
xlabel("Size (power-of-2)");
ylabel("Factor of speed (n times faster than)");
legend(["SciLab"; "Archr-R"], 'in_upper_left');
title("Speedup factor betweeb Archr-R and SciLab");

Possible Output

Start Toolbox archr
	Load macros
	Load gateways


============================
Size is: 1024 (2^10)

Raw timing:
  SciLab: 0.064000
  Arch-R: 0.024000
----------------------------
Speedup:
  x2.666667
============================

============================
Size is: 2048 (2^11)

Raw timing:
  SciLab: 0.152000
  Arch-R: 0.036000
----------------------------
Speedup:
  x4.222222
============================

============================
Size is: 4096 (2^12)

Raw timing:
  SciLab: 0.324000
  Arch-R: 0.064000
----------------------------
Speedup:
  x5.062500
============================

============================
Size is: 8192 (2^13)

Raw timing:
  SciLab: 0.728000
  Arch-R: 0.120000
----------------------------
Speedup:
  x6.066667
============================

============================
Size is: 16384 (2^14)

Raw timing:
  SciLab: 1.440000
  Arch-R: 0.224000
----------------------------
Speedup:
  x6.428571
============================

============================
Size is: 32768 (2^15)

Raw timing:
  SciLab: 2.880000
  Arch-R: 0.460000
----------------------------
Speedup:
  x6.260870
============================

============================
Size is: 65536 (2^16)

Raw timing:
  SciLab: 5.784000
  Arch-R: 0.908000
----------------------------
Speedup:
  x6.370044
============================

============================
Size is: 131072 (2^17)

Raw timing:
  SciLab: 11.536000
  Arch-R: 2.552000
----------------------------
Speedup:
  x4.520376
============================