Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/20/19 10:31:37 (5 years ago)
Author:
bburlacu
Message:

#2866: Support hyperbolic tangent in native interpreter.

Location:
trunk/HeuristicLab.ExtLibs/HeuristicLab.NativeInterpreter/0.1/NativeInterpreter-0.1
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/HeuristicLab.ExtLibs/HeuristicLab.NativeInterpreter/0.1/NativeInterpreter-0.1

    • Property svn:global-ignores set to
      build
      mingw
  • trunk/HeuristicLab.ExtLibs/HeuristicLab.NativeInterpreter/0.1/NativeInterpreter-0.1/src/instruction.h

    r16356 r16701  
    99{
    1010    // same values as in OpCodes.cs
    11     Add = 1,
    12     Sub = 2,
    13     Mul = 3,
    14     Div = 4,
    15     Sin = 5,
    16     Cos = 6,
    17     Tan = 7,
    18     Log = 8,
    19     Exp = 9,
    20     Var = 18,
    21     Const = 20,
    22     Power = 22,
    23     Root = 23,
    24     Square = 28,
    25     Sqrt = 29,
    26     Absolute = 48,
     11    Add                = 1,
     12    Sub                = 2,
     13    Mul                = 3,
     14    Div                = 4,
     15    Sin                = 5,
     16    Cos                = 6,
     17    Tan                = 7,
     18    Log                = 8,
     19    Exp                = 9,
     20    Var                = 18,
     21    Const              = 20,
     22    Power              = 22,
     23    Root               = 23,
     24    Square             = 28,
     25    Sqrt               = 29,
     26    Absolute           = 48,
    2727    AnalyticalQuotient = 49,
    28     Cube = 50,
    29     CubeRoot = 51
     28    Cube               = 50,
     29    CubeRoot           = 51,
     30    Tanh               = 52
    3031};
    3132
  • trunk/HeuristicLab.ExtLibs/HeuristicLab.NativeInterpreter/0.1/NativeInterpreter-0.1/src/interpreter.h

    r16356 r16701  
    6464            case OpCodes::Exp:
    6565                {
    66                     in.value = std::exp(code[in.childIndex].value);
     66                    in.value = hl_exp(code[in.childIndex].value);
    6767                    break;
    6868                }
    6969            case OpCodes::Log:
    7070                {
    71                     in.value = std::log(code[in.childIndex].value);
     71                    in.value = hl_log(code[in.childIndex].value);
    7272                    break;
    7373                }
    7474            case OpCodes::Sin:
    7575                {
    76                     in.value = std::sin(code[in.childIndex].value);
     76                    in.value = hl_sin(code[in.childIndex].value);
    7777                    break;
    7878                }
    7979            case OpCodes::Cos:
    8080                {
    81                     in.value = std::cos(code[in.childIndex].value);
     81                    in.value = hl_cos(code[in.childIndex].value);
    8282                    break;
    8383                }
    8484            case OpCodes::Tan:
    8585                {
    86                     in.value = std::tan(code[in.childIndex].value);
     86                    in.value = hl_tan(code[in.childIndex].value);
     87                    break;
     88                }
     89            case OpCodes::Tanh:
     90                {
     91                    in.value = hl_tanh(code[in.childIndex].value);
    8792                    break;
    8893                }
     
    9095                {
    9196                    double x = code[in.childIndex].value;
    92                     double y = std::round(code[in.childIndex + 1].value);
    93                     in.value = std::pow(x, y);
     97                    double y = hl_round(code[in.childIndex + 1].value);
     98                    in.value = hl_pow(x, y);
    9499                    break;
    95100                }
     
    97102                {
    98103                    double x = code[in.childIndex].value;
    99                     double y = std::round(code[in.childIndex + 1].value);
    100                     in.value = std::pow(x, 1 / y);
     104                    double y = hl_round(code[in.childIndex + 1].value);
     105                    in.value = hl_pow(x, 1 / y);
    101106                    break;
    102107                }
    103108            case OpCodes::Sqrt:
    104109                {
    105                     in.value = std::pow(code[in.childIndex].value, 1./2.);
     110                    in.value = hl_pow(code[in.childIndex].value, 1./2.);
    106111                    break;
    107112                }
    108113            case OpCodes::Square:
    109114                {
    110                     in.value = std::pow(code[in.childIndex].value, 2.);
     115                    in.value = hl_pow(code[in.childIndex].value, 2.);
    111116                    break;
    112117                }
    113118            case OpCodes::CubeRoot:
    114119                {
    115                     in.value = std::pow(code[in.childIndex].value, 1./3.);
     120                    in.value = hl_pow(code[in.childIndex].value, 1./3.);
    116121                    break;
    117122                }
    118123            case OpCodes::Cube:
    119124                {
    120                     in.value = std::pow(code[in.childIndex].value, 3.);
     125                    in.value = hl_pow(code[in.childIndex].value, 3.);
    121126                    break;
    122127                }
     
    130135                    double x = code[in.childIndex].value;
    131136                    double y = code[in.childIndex + 1].value;
    132                     in.value = x / std::sqrt(1 + y*y);
     137                    in.value = x / hl_sqrt(1 + y*y);
    133138                    break;
    134139                }
     
    228233                    break;
    229234                }
     235            case OpCodes::Tanh:
     236                {
     237                    tanh(in.buf, code[in.childIndex].buf);
     238                    break;
     239                }
    230240            case OpCodes::Log:
    231241                {
  • trunk/HeuristicLab.ExtLibs/HeuristicLab.NativeInterpreter/0.1/NativeInterpreter-0.1/src/vector_operations.h

    r16356 r16701  
    1414#define hl_cos vdt::fast_cos
    1515#define hl_tan vdt::fast_tan
     16#define hl_tanh vdt::fast_tanh
    1617#define hl_sqrt vdt::fast_sqrt
    1718#define hl_pow vdt::fast_pow
    1819#define hl_round vdt::fast_round
     20#define hl_inv vdt::fast_inv
    1921#else
    2022#define hl_exp std::exp
     
    2325#define hl_cos std::cos
    2426#define hl_tan std::tan
     27#define hl_tanh std::tanh
    2528#define hl_sqrt std::sqrt
    2629#define hl_pow std::pow
    2730#define hl_round std::round
     31#define hl_inv(x) 1. / x;
     32
    2833#endif
    2934
     
    4752inline void cos(double* __restrict a, double const * __restrict b) noexcept { FOR(i) a[i] = hl_cos(b[i]); }
    4853inline void tan(double* __restrict a, double const * __restrict b) noexcept { FOR(i) a[i] = hl_tan(b[i]); }
     54inline void tanh(double* __restrict a, double const * __restrict b) noexcept { FOR(i) a[i] = hl_tanh(b[i]); }
    4955inline void sqrt(double* __restrict a, double const * __restrict b) noexcept { FOR(i) a[i] = hl_sqrt(b[i]); }
    5056inline void pow(double* __restrict a, double const * __restrict b) noexcept { FOR(i) a[i] = hl_pow(a[i], hl_round(b[i])); };
    5157inline void root(double* __restrict a, double const * __restrict b) noexcept { FOR(i) a[i] = hl_pow(a[i], 1. / hl_round(b[i])); };
    5258inline void square(double* __restrict a, double const * __restrict b) noexcept { FOR(i) a[i] = hl_pow(b[i], 2.); };
    53 inline void inv(double* __restrict a, double const * __restrict b) noexcept { FOR(i) a[i] = 1. / b[i]; }
     59inline void inv(double* __restrict a, double const * __restrict b) noexcept { FOR(i) a[i] = hl_inv(b[i]); }
    5460inline void neg(double* __restrict a, double const * __restrict b) noexcept { FOR(i) a[i] = -b[i]; }
    5561inline void abs(double* __restrict a, double const * __restrict b) noexcept { FOR(i) a[i] = std::fabs(b[i]); }
     
    6672// vector operations
    6773inline void neg(double* __restrict a) noexcept { FOR(i) a[i] = -a[i]; }
    68 inline void inv(double* __restrict a) noexcept { FOR(i) a[i] = 1. / a[i]; }
     74inline void inv(double* __restrict a) noexcept { FOR(i) a[i] = hl_inv(a[i]); }
    6975inline void exp(double* __restrict a) noexcept { FOR(i) a[i] = hl_exp(a[i]); }
    7076inline void log(double* __restrict a) noexcept { FOR(i) a[i] = hl_log(a[i]); }
    7177inline void sin(double* __restrict a) noexcept { FOR(i) a[i] = hl_sin(a[i]); }
    7278inline void cos(double* __restrict a) noexcept { FOR(i) a[i] = hl_cos(a[i]); }
     79inline void tan(double* __restrict a) noexcept { FOR(i) a[i] = hl_tan(a[i]); }
     80inline void tanh(double* __restrict a) noexcept { FOR(i) a[i] = hl_tanh(a[i]); }
    7381inline void round(double* __restrict a) noexcept { FOR(i) a[i] = hl_round(a[i]); }
    7482inline void square(double* __restrict a) noexcept { FOR(i) a[i] = hl_pow(a[i], 2.); }
Note: See TracChangeset for help on using the changeset viewer.