FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
cpp-extension-for-python/superfastcode/module.cpp at master · neptune46/cpp-extension-for-python · GitHub
neptune46
/
cpp-extension-for-python
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
cpp-extension-for-python
/
superfastcode
/
module.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
41 lines (32 loc) · 1.21 KB
Breadcrumbs
cpp-extension-for-python
/
superfastcode
/
module.cpp
Copy path
File metadata and controls
41 lines (32 loc) · 1.21 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#
include
<
Windows.h
>
#
include
<
cmath
>
#
include
<
Python.h
>
const
double
e =
2.7182818284590452353602874713527
;
double
sinh_impl
(
double
x) {
return
(
1
-
pow
(e, (-
2
* x))) / (
2
*
pow
(e, -x));
}
double
cosh_impl
(
double
x) {
return
(
1
+
pow
(e, (-
2
* x))) / (
2
*
pow
(e, -x));
}
PyObject*
tanh_impl
(PyObject *, PyObject* o) {
double
x =
PyFloat_AsDouble
(o);
double
tanh_x =
sinh_impl
(x) /
cosh_impl
(x);
return
PyFloat_FromDouble
(tanh_x);
}
static
PyMethodDef superfastcode_methods[] = {
//
The first property is the name exposed to Python, fast_tanh, the second is the C++
//
function name that contains the implementation.
{
"
fast_tanh
"
, (PyCFunction)tanh_impl,
METH_O
,
nullptr
},
//
Terminate the array with an object containing nulls.
{
nullptr
,
nullptr
,
0
,
nullptr
}
};
static
PyModuleDef superfastcode_module = {
PyModuleDef_HEAD_INIT,
"
superfastcode
"
,
//
Module name to use with Python import statements
"
Provides some functions, but faster
"
,
//
Module description
0
,
superfastcode_methods
//
Structure that defines the methods of the module
};
PyMODINIT_FUNC
PyInit_superfastcode
() {
return
PyModule_Create
(&superfastcode_module);
}
Back
|
FazBrowse Home
|
New Git URL