Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Myshrimp #4941

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ option(NCNN_PYTHON "build python api" OFF)
option(NCNN_INT8 "int8 inference" ON)
option(NCNN_BF16 "bf16 inference" ON)
option(NCNN_FORCE_INLINE "force inline some function" ON)
option(NCNN_SIMPLEMATH "minimal math library emulation" OFF)

if(ANDROID OR IOS OR NCNN_SIMPLESTL OR CMAKE_CROSSCOMPILING)
option(NCNN_DISABLE_RTTI "disable rtti" ON)
Expand Down
2 changes: 2 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ set(ncnn_SRCS
simpleocv.cpp
simpleomp.cpp
simplestl.cpp
simplemath.cpp
)

if(ANDROID)
Expand Down Expand Up @@ -576,6 +577,7 @@ if(NCNN_INSTALL_SDK)
simpleocv.h
simpleomp.h
simplestl.h
simplemath.h
vulkan_header_fix.h
${CMAKE_CURRENT_BINARY_DIR}/ncnn_export.h
${CMAKE_CURRENT_BINARY_DIR}/layer_shader_type_enum.h
Expand Down
1 change: 1 addition & 0 deletions src/platform.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
#cmakedefine01 NCNN_INT8
#cmakedefine01 NCNN_BF16
#cmakedefine01 NCNN_FORCE_INLINE
#cmakedefine01 NCNN_SIMPLEMATH

#cmakedefine NCNN_VERSION_STRING "@NCNN_VERSION_STRING@"

Expand Down
78 changes: 78 additions & 0 deletions src/simplemath.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#include "platform.h"
#ifdef NCNN_SIMPLEMATH
#include"simplemath.h"
#include <stdlib.h>
#include<stdio.h>
float absolute(float x)//returns the absolute value of a number
{
if (x < 0)x = -x;
return x;
}

float Factorial(int x)//returns the factorial of a number
{
if (x == 1 || x == 0)return 1;
else
return 1.0 * x * Factorial(x - 1);
}


float nth(float x, int n)//returns the value of a number(x) to the power of n
{
if (n > 0)
{
return x * nth(x, n - 1);
}
if (n == 0)
{
return 1;
}
if (n < 0)
{
return (1 / x) * nth(x, n + 1);
}
}
float Bernoulli(int x)//Bernoulli numbers
{
int k = x;
float B = 0;
if (x == 0)
return 1;
else
if (x > 1 && x % 2 == 1)
{
return 0;
}
else
{
while (k)
{
k--;
B += -1.0 * (Factorial(x) * Bernoulli(k)) / (Factorial(x - k) * Factorial(k) * (x - k + 1));
}
return B;
}
}
float tan(float x)//the accuracy remains 0.000001
{
int i = 1;
float e = 1, sum = 0;
while (x < (PI / 2))x += PI;
while (x > (PI / 2))x -= PI;
if (x == (PI/ 2))
{
printf("\tNaN\n");
return 0;
}
while (absolute(e) > accuracy && i <= 24)//adjust Bernoulli in consideration of calculating speed.
{
e = 1.0 * (nth(-1, i - 1) * nth(2, 2 * i) * (nth(2, 2 * i) - 1.0) * Bernoulli(2 * i) * nth(x, 2 * i - 1)) / (Factorial(2 * i));
sum += e;
i++;
}
return sum;
}
#endif



7 changes: 7 additions & 0 deletions src/simplemath.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#ifndef TAN_H
#define TAN_H
#include<stdio.h>
#define PI 3.14159265
#define accuracy 0.000001
float tan(float x);
#endif