├── .gitattributes
├── .gitignore
├── CppAndPython.sln
├── CppAndPython
├── CppAndPython.py
└── CppAndPython.pyproj
├── LICENSE
├── README.md
├── SECURITY.md
├── superfastcode
├── module.cpp
├── setup.py
└── superfastcode.vcxproj
└── superfastcode2
├── module.cpp
├── setup.py
└── superfastcode2.vcxproj
/.gitattributes:
--------------------------------------------------------------------------------
1 | ###############################################################################
2 | # Set default behavior to automatically normalize line endings.
3 | ###############################################################################
4 | * text=auto
5 |
6 | ###############################################################################
7 | # Set default behavior for command prompt diff.
8 | #
9 | # This is need for earlier builds of msysgit that does not have it on by
10 | # default for csharp files.
11 | # Note: This is only used by command line
12 | ###############################################################################
13 | #*.cs diff=csharp
14 |
15 | ###############################################################################
16 | # Set the merge driver for project and solution files
17 | #
18 | # Merging from the command prompt will add diff markers to the files if there
19 | # are conflicts (Merging from VS is not affected by the settings below, in VS
20 | # the diff markers are never inserted). Diff markers may cause the following
21 | # file extensions to fail to load in VS. An alternative would be to treat
22 | # these files as binary and thus will always conflict and require user
23 | # intervention with every merge. To do so, just uncomment the entries below
24 | ###############################################################################
25 | #*.sln merge=binary
26 | #*.csproj merge=binary
27 | #*.vbproj merge=binary
28 | #*.vcxproj merge=binary
29 | #*.vcproj merge=binary
30 | #*.dbproj merge=binary
31 | #*.fsproj merge=binary
32 | #*.lsproj merge=binary
33 | #*.wixproj merge=binary
34 | #*.modelproj merge=binary
35 | #*.sqlproj merge=binary
36 | #*.wwaproj merge=binary
37 |
38 | ###############################################################################
39 | # behavior for image files
40 | #
41 | # image files are treated as binary by default.
42 | ###############################################################################
43 | #*.jpg binary
44 | #*.png binary
45 | #*.gif binary
46 |
47 | ###############################################################################
48 | # diff behavior for common document formats
49 | #
50 | # Convert binary document formats to text before diffing them. This feature
51 | # is only available from the command line. Turn it on by uncommenting the
52 | # entries below.
53 | ###############################################################################
54 | #*.doc diff=astextplain
55 | #*.DOC diff=astextplain
56 | #*.docx diff=astextplain
57 | #*.DOCX diff=astextplain
58 | #*.dot diff=astextplain
59 | #*.DOT diff=astextplain
60 | #*.pdf diff=astextplain
61 | #*.PDF diff=astextplain
62 | #*.rtf diff=astextplain
63 | #*.RTF diff=astextplain
64 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | ## Ignore Visual Studio temporary files, build results, and
2 | ## files generated by popular Visual Studio add-ons.
3 | ##
4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
5 |
6 | # User-specific files
7 | *.suo
8 | *.user
9 | *.userosscache
10 | *.sln.docstates
11 |
12 | # User-specific files (MonoDevelop/Xamarin Studio)
13 | *.userprefs
14 |
15 | # Build results
16 | [Dd]ebug/
17 | [Dd]ebugPublic/
18 | [Rr]elease/
19 | [Rr]eleases/
20 | x64/
21 | x86/
22 | bld/
23 | [Bb]in/
24 | [Oo]bj/
25 | [Ll]og/
26 |
27 | # Visual Studio 2015 cache/options directory
28 | .vs/
29 | # Uncomment if you have tasks that create the project's static files in wwwroot
30 | #wwwroot/
31 |
32 | # MSTest test Results
33 | [Tt]est[Rr]esult*/
34 | [Bb]uild[Ll]og.*
35 |
36 | # NUNIT
37 | *.VisualState.xml
38 | TestResult.xml
39 |
40 | # Build Results of an ATL Project
41 | [Dd]ebugPS/
42 | [Rr]eleasePS/
43 | dlldata.c
44 |
45 | # .NET Core
46 | project.lock.json
47 | project.fragment.lock.json
48 | artifacts/
49 | **/Properties/launchSettings.json
50 |
51 | *_i.c
52 | *_p.c
53 | *_i.h
54 | *.ilk
55 | *.meta
56 | *.obj
57 | *.pch
58 | *.pdb
59 | *.pgc
60 | *.pgd
61 | *.rsp
62 | *.sbr
63 | *.tlb
64 | *.tli
65 | *.tlh
66 | *.tmp
67 | *.tmp_proj
68 | *.log
69 | *.vspscc
70 | *.vssscc
71 | .builds
72 | *.pidb
73 | *.svclog
74 | *.scc
75 |
76 | # Chutzpah Test files
77 | _Chutzpah*
78 |
79 | # Visual C++ cache files
80 | ipch/
81 | *.aps
82 | *.ncb
83 | *.opendb
84 | *.opensdf
85 | *.sdf
86 | *.cachefile
87 | *.VC.db
88 | *.VC.VC.opendb
89 |
90 | # Visual Studio profiler
91 | *.psess
92 | *.vsp
93 | *.vspx
94 | *.sap
95 |
96 | # TFS 2012 Local Workspace
97 | $tf/
98 |
99 | # Guidance Automation Toolkit
100 | *.gpState
101 |
102 | # ReSharper is a .NET coding add-in
103 | _ReSharper*/
104 | *.[Rr]e[Ss]harper
105 | *.DotSettings.user
106 |
107 | # JustCode is a .NET coding add-in
108 | .JustCode
109 |
110 | # TeamCity is a build add-in
111 | _TeamCity*
112 |
113 | # DotCover is a Code Coverage Tool
114 | *.dotCover
115 |
116 | # Visual Studio code coverage results
117 | *.coverage
118 | *.coveragexml
119 |
120 | # NCrunch
121 | _NCrunch_*
122 | .*crunch*.local.xml
123 | nCrunchTemp_*
124 |
125 | # MightyMoose
126 | *.mm.*
127 | AutoTest.Net/
128 |
129 | # Web workbench (sass)
130 | .sass-cache/
131 |
132 | # Installshield output folder
133 | [Ee]xpress/
134 |
135 | # DocProject is a documentation generator add-in
136 | DocProject/buildhelp/
137 | DocProject/Help/*.HxT
138 | DocProject/Help/*.HxC
139 | DocProject/Help/*.hhc
140 | DocProject/Help/*.hhk
141 | DocProject/Help/*.hhp
142 | DocProject/Help/Html2
143 | DocProject/Help/html
144 |
145 | # Click-Once directory
146 | publish/
147 |
148 | # Publish Web Output
149 | *.[Pp]ublish.xml
150 | *.azurePubxml
151 | # TODO: Comment the next line if you want to checkin your web deploy settings
152 | # but database connection strings (with potential passwords) will be unencrypted
153 | *.pubxml
154 | *.publishproj
155 |
156 | # Microsoft Azure Web App publish settings. Comment the next line if you want to
157 | # checkin your Azure Web App publish settings, but sensitive information contained
158 | # in these scripts will be unencrypted
159 | PublishScripts/
160 |
161 | # NuGet Packages
162 | *.nupkg
163 | # The packages folder can be ignored because of Package Restore
164 | **/packages/*
165 | # except build/, which is used as an MSBuild target.
166 | !**/packages/build/
167 | # Uncomment if necessary however generally it will be regenerated when needed
168 | #!**/packages/repositories.config
169 | # NuGet v3's project.json files produces more ignorable files
170 | *.nuget.props
171 | *.nuget.targets
172 |
173 | # Microsoft Azure Build Output
174 | csx/
175 | *.build.csdef
176 |
177 | # Microsoft Azure Emulator
178 | ecf/
179 | rcf/
180 |
181 | # Windows Store app package directories and files
182 | AppPackages/
183 | BundleArtifacts/
184 | Package.StoreAssociation.xml
185 | _pkginfo.txt
186 |
187 | # Visual Studio cache files
188 | # files ending in .cache can be ignored
189 | *.[Cc]ache
190 | # but keep track of directories ending in .cache
191 | !*.[Cc]ache/
192 |
193 | # Others
194 | ClientBin/
195 | ~$*
196 | *~
197 | *.dbmdl
198 | *.dbproj.schemaview
199 | *.jfm
200 | *.pfx
201 | *.publishsettings
202 | orleans.codegen.cs
203 |
204 | # Since there are multiple workflows, uncomment next line to ignore bower_components
205 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
206 | #bower_components/
207 |
208 | # RIA/Silverlight projects
209 | Generated_Code/
210 |
211 | # Backup & report files from converting an old project file
212 | # to a newer Visual Studio version. Backup files are not needed,
213 | # because we have git ;-)
214 | _UpgradeReport_Files/
215 | Backup*/
216 | UpgradeLog*.XML
217 | UpgradeLog*.htm
218 |
219 | # SQL Server files
220 | *.mdf
221 | *.ldf
222 | *.ndf
223 |
224 | # Business Intelligence projects
225 | *.rdl.data
226 | *.bim.layout
227 | *.bim_*.settings
228 |
229 | # Microsoft Fakes
230 | FakesAssemblies/
231 |
232 | # GhostDoc plugin setting file
233 | *.GhostDoc.xml
234 |
235 | # Node.js Tools for Visual Studio
236 | .ntvs_analysis.dat
237 | node_modules/
238 |
239 | # Typescript v1 declaration files
240 | typings/
241 |
242 | # Visual Studio 6 build log
243 | *.plg
244 |
245 | # Visual Studio 6 workspace options file
246 | *.opt
247 |
248 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
249 | *.vbw
250 |
251 | # Visual Studio LightSwitch build output
252 | **/*.HTMLClient/GeneratedArtifacts
253 | **/*.DesktopClient/GeneratedArtifacts
254 | **/*.DesktopClient/ModelManifest.xml
255 | **/*.Server/GeneratedArtifacts
256 | **/*.Server/ModelManifest.xml
257 | _Pvt_Extensions
258 |
259 | # Paket dependency manager
260 | .paket/paket.exe
261 | paket-files/
262 |
263 | # FAKE - F# Make
264 | .fake/
265 |
266 | # JetBrains Rider
267 | .idea/
268 | *.sln.iml
269 |
270 | # CodeRush
271 | .cr/
272 |
273 | # Python Tools for Visual Studio (PTVS)
274 | __pycache__/
275 | *.pyc
276 |
277 | # Cake - Uncomment if you are using it
278 | # tools/**
279 | # !tools/packages.config
280 |
281 | # Telerik's JustMock configuration file
282 | *.jmconfig
283 |
284 | # BizTalk build output
285 | *.btp.cs
286 | *.btm.cs
287 | *.odx.cs
288 | *.xsd.cs
289 |
--------------------------------------------------------------------------------
/CppAndPython.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 15
4 | VisualStudioVersion = 15.0.26923.0
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{888888A0-9F3D-457C-B088-3A5042F75D52}") = "CppAndPython", "CppAndPython\CppAndPython.pyproj", "{2B5C8505-3D84-4E5D-9A30-42D81BE799D5}"
7 | EndProject
8 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "superfastcode", "superfastcode\superfastcode.vcxproj", "{28F6146F-9862-4C07-A931-F3DE0A093BB7}"
9 | EndProject
10 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{1825A8FB-C772-4A0E-B84C-F33A83DBE839}"
11 | ProjectSection(SolutionItems) = preProject
12 | README.md = README.md
13 | EndProjectSection
14 | EndProject
15 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "superfastcode2", "superfastcode2\superfastcode2.vcxproj", "{98D5E983-CE8C-4AE5-9DA2-0374C81BFB86}"
16 | EndProject
17 | Global
18 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
19 | Debug|Any CPU = Debug|Any CPU
20 | Debug|x64 = Debug|x64
21 | Debug|x86 = Debug|x86
22 | Release|Any CPU = Release|Any CPU
23 | Release|x64 = Release|x64
24 | Release|x86 = Release|x86
25 | EndGlobalSection
26 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
27 | {2B5C8505-3D84-4E5D-9A30-42D81BE799D5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
28 | {2B5C8505-3D84-4E5D-9A30-42D81BE799D5}.Debug|x64.ActiveCfg = Debug|Any CPU
29 | {2B5C8505-3D84-4E5D-9A30-42D81BE799D5}.Debug|x86.ActiveCfg = Debug|Any CPU
30 | {2B5C8505-3D84-4E5D-9A30-42D81BE799D5}.Release|Any CPU.ActiveCfg = Release|Any CPU
31 | {2B5C8505-3D84-4E5D-9A30-42D81BE799D5}.Release|x64.ActiveCfg = Release|Any CPU
32 | {2B5C8505-3D84-4E5D-9A30-42D81BE799D5}.Release|x86.ActiveCfg = Release|Any CPU
33 | {28F6146F-9862-4C07-A931-F3DE0A093BB7}.Debug|Any CPU.ActiveCfg = Debug|Win32
34 | {28F6146F-9862-4C07-A931-F3DE0A093BB7}.Debug|x64.ActiveCfg = Debug|x64
35 | {28F6146F-9862-4C07-A931-F3DE0A093BB7}.Debug|x64.Build.0 = Debug|x64
36 | {28F6146F-9862-4C07-A931-F3DE0A093BB7}.Debug|x86.ActiveCfg = Debug|Win32
37 | {28F6146F-9862-4C07-A931-F3DE0A093BB7}.Debug|x86.Build.0 = Debug|Win32
38 | {28F6146F-9862-4C07-A931-F3DE0A093BB7}.Release|Any CPU.ActiveCfg = Release|Win32
39 | {28F6146F-9862-4C07-A931-F3DE0A093BB7}.Release|x64.ActiveCfg = Release|x64
40 | {28F6146F-9862-4C07-A931-F3DE0A093BB7}.Release|x64.Build.0 = Release|x64
41 | {28F6146F-9862-4C07-A931-F3DE0A093BB7}.Release|x86.ActiveCfg = Release|Win32
42 | {28F6146F-9862-4C07-A931-F3DE0A093BB7}.Release|x86.Build.0 = Release|Win32
43 | {98D5E983-CE8C-4AE5-9DA2-0374C81BFB86}.Debug|Any CPU.ActiveCfg = Debug|Win32
44 | {98D5E983-CE8C-4AE5-9DA2-0374C81BFB86}.Debug|x64.ActiveCfg = Debug|x64
45 | {98D5E983-CE8C-4AE5-9DA2-0374C81BFB86}.Debug|x64.Build.0 = Debug|x64
46 | {98D5E983-CE8C-4AE5-9DA2-0374C81BFB86}.Debug|x86.ActiveCfg = Debug|Win32
47 | {98D5E983-CE8C-4AE5-9DA2-0374C81BFB86}.Debug|x86.Build.0 = Debug|Win32
48 | {98D5E983-CE8C-4AE5-9DA2-0374C81BFB86}.Release|Any CPU.ActiveCfg = Release|Win32
49 | {98D5E983-CE8C-4AE5-9DA2-0374C81BFB86}.Release|x64.ActiveCfg = Release|x64
50 | {98D5E983-CE8C-4AE5-9DA2-0374C81BFB86}.Release|x64.Build.0 = Release|x64
51 | {98D5E983-CE8C-4AE5-9DA2-0374C81BFB86}.Release|x86.ActiveCfg = Release|Win32
52 | {98D5E983-CE8C-4AE5-9DA2-0374C81BFB86}.Release|x86.Build.0 = Release|Win32
53 | EndGlobalSection
54 | GlobalSection(SolutionProperties) = preSolution
55 | HideSolutionNode = FALSE
56 | EndGlobalSection
57 | GlobalSection(ExtensibilityGlobals) = postSolution
58 | SolutionGuid = {7EF010AA-A899-42BC-9102-EC94C2D9C7B8}
59 | EndGlobalSection
60 | EndGlobal
61 |
--------------------------------------------------------------------------------
/CppAndPython/CppAndPython.py:
--------------------------------------------------------------------------------
1 | from itertools import islice
2 | from random import random
3 | from time import perf_counter
4 |
5 | COUNT = 500000 # Change this value depending on the speed of your computer
6 | DATA = list(islice(iter(lambda: (random() - 0.5) * 3.0, None), COUNT))
7 |
8 | e = 2.7182818284590452353602874713527
9 |
10 |
11 | def sinh(x):
12 | return (1 - (e ** (-2 * x))) / (2 * (e ** -x))
13 |
14 |
15 | def cosh(x):
16 | return (1 + (e ** (-2 * x))) / (2 * (e ** -x))
17 |
18 |
19 | def tanh(x):
20 | tanh_x = sinh(x) / cosh(x)
21 | return tanh_x
22 |
23 |
24 | def test(fn, name):
25 |
26 | start = perf_counter()
27 | result = fn(DATA)
28 | duration = perf_counter() - start
29 | print('{} took {:.3f} seconds\n\n'.format(name, duration))
30 |
31 | for d in result:
32 | assert -1 <= d <= 1, " incorrect values"
33 |
34 |
35 | if __name__ == "__main__":
36 | print('Running benchmarks with COUNT = {}'.format(COUNT))
37 |
38 | test(lambda d: [tanh(x) for x in d], '[tanh(x) for x in d] (Python implementation)')
39 |
40 | from superfastcode import fast_tanh
41 | test(lambda d: [fast_tanh(x) for x in d], '[fast_tanh(x) for x in d] (CPython C++ extension)')
42 |
43 | from superfastcode2 import fast_tanh2
44 | test(lambda d: [fast_tanh2(x) for x in d], '[fast_tanh2(x) for x in d] (PyBind11 C++ extension)')
45 |
--------------------------------------------------------------------------------
/CppAndPython/CppAndPython.pyproj:
--------------------------------------------------------------------------------
1 |
2 |
3 | Debug
4 | 2.0
5 | 2b5c8505-3d84-4e5d-9a30-42d81be799d5
6 | .
7 | CppAndPython.py
8 |
9 |
10 | .
11 | .
12 | CppAndPython
13 | CppAndPython
14 | Standard Python launcher
15 | -i
16 | True
17 |
18 |
19 | true
20 | false
21 |
22 |
23 | true
24 | false
25 |
26 |
27 |
28 |
29 |
30 |
31 | superfastcode2
32 | {98d5e983-ce8c-4ae5-9da2-0374c81bfb86}
33 | True
34 |
35 |
36 | superfastcode
37 | {28f6146f-9862-4c07-a931-f3de0a093bb7}
38 | True
39 |
40 |
41 |
42 |
45 |
46 |
47 |
48 |
49 |
50 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) Microsoft Corporation. All rights reserved.
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # python-sample-vs-cpp-extension
2 |
3 | This sample is the end product for the walkthrough on https://docs.microsoft.com/en-us/visualstudio/python/working-with-c-cpp-python-in-visual-studio.
4 | You must have the "Python native development tools" option selected for the Python development workload in the Visual Studio 2017 installer.
5 |
6 | The superfastcode and superfastcode2 projects contain identical implementations of a hyperbolic tangent function. In the superfastcode project, the
7 | module is exposed to Python using the extension methods for CPython. In the superfastcode2 project, the module is exposed using PyBind11.
8 |
9 | The CppAndPython project contains a little Python code that implements the same function using straight Python, then runs all three implementations
10 | to provide comparative results. Note that you may need to update the selected environment under the **Python Environments** node. The sample was
11 | written for Python 3.6 (32-bit). Make sure a suitable environment is selected here.
12 |
13 | Because the superfastcode and superfastcode2 C++ projects contain a few hard-coded pathnames and is also configured to compile using the Visual Studio 2017
14 | toolset, you may need to change a few project properties as described in the table below to make them work on your computer. For the latter two properties,
15 | just set the PYTHONPATH environment variable accordingly, which is the only change needed for Visual Studio 2017.
16 |
17 | | Project Property | Value in the example | Notes |
18 | | --- | --- | --- |
19 | | Configuration Properties > General > Configuration Toolset | Visual Studio 2017 (v141) | If using Visual Studio 2015, change to *Visual Studio 2015 (v140)*. In the VS 2015 installer, also make sure that you have the **Programming Languages** > **Visual C++** > **Common Tools for Visual C++ 2015** option selected, which includes the toolset. |
20 | | C++ > General > Additional Include Directories | %PYTHONPATH%\include | Property must point to the "include" folder of your Python installation. |
21 | | Linker > General > Additional Library Directories | %PYTHONPATH%\libs| Property must point to the "libs" folder of your Python installation. |
22 |
23 |
24 | # Contributing
25 |
26 | This project welcomes contributions and suggestions. Most contributions require you to agree to a
27 | Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us
28 | the rights to use your contribution. For details, visit https://cla.microsoft.com.
29 |
30 | When you submit a pull request, a CLA-bot will automatically determine whether you need to provide
31 | a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions
32 | provided by the bot. You will only need to do this once across all repos using our CLA.
33 |
34 | This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
35 | For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or
36 | contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.
37 |
--------------------------------------------------------------------------------
/SECURITY.md:
--------------------------------------------------------------------------------
1 |
2 |
3 | ## Security
4 |
5 | Microsoft takes the security of our software products and services seriously, which includes all source code repositories managed through our GitHub organizations, which include [Microsoft](https://github.com/microsoft), [Azure](https://github.com/Azure), [DotNet](https://github.com/dotnet), [AspNet](https://github.com/aspnet), [Xamarin](https://github.com/xamarin), and [our GitHub organizations](https://opensource.microsoft.com/).
6 |
7 | If you believe you have found a security vulnerability in any Microsoft-owned repository that meets [Microsoft's definition of a security vulnerability](https://aka.ms/opensource/security/definition), please report it to us as described below.
8 |
9 | ## Reporting Security Issues
10 |
11 | **Please do not report security vulnerabilities through public GitHub issues.**
12 |
13 | Instead, please report them to the Microsoft Security Response Center (MSRC) at [https://msrc.microsoft.com/create-report](https://aka.ms/opensource/security/create-report).
14 |
15 | If you prefer to submit without logging in, send email to [secure@microsoft.com](mailto:secure@microsoft.com). If possible, encrypt your message with our PGP key; please download it from the [Microsoft Security Response Center PGP Key page](https://aka.ms/opensource/security/pgpkey).
16 |
17 | You should receive a response within 24 hours. If for some reason you do not, please follow up via email to ensure we received your original message. Additional information can be found at [microsoft.com/msrc](https://aka.ms/opensource/security/msrc).
18 |
19 | Please include the requested information listed below (as much as you can provide) to help us better understand the nature and scope of the possible issue:
20 |
21 | * Type of issue (e.g. buffer overflow, SQL injection, cross-site scripting, etc.)
22 | * Full paths of source file(s) related to the manifestation of the issue
23 | * The location of the affected source code (tag/branch/commit or direct URL)
24 | * Any special configuration required to reproduce the issue
25 | * Step-by-step instructions to reproduce the issue
26 | * Proof-of-concept or exploit code (if possible)
27 | * Impact of the issue, including how an attacker might exploit the issue
28 |
29 | This information will help us triage your report more quickly.
30 |
31 | If you are reporting for a bug bounty, more complete reports can contribute to a higher bounty award. Please visit our [Microsoft Bug Bounty Program](https://aka.ms/opensource/security/bounty) page for more details about our active programs.
32 |
33 | ## Preferred Languages
34 |
35 | We prefer all communications to be in English.
36 |
37 | ## Policy
38 |
39 | Microsoft follows the principle of [Coordinated Vulnerability Disclosure](https://aka.ms/opensource/security/cvd).
40 |
41 |
42 |
--------------------------------------------------------------------------------
/superfastcode/module.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 |
5 | const double e = 2.7182818284590452353602874713527;
6 |
7 | double sinh_impl(double x) {
8 | return (1 - pow(e, (-2 * x))) / (2 * pow(e, -x));
9 | }
10 |
11 | double cosh_impl(double x) {
12 | return (1 + pow(e, (-2 * x))) / (2 * pow(e, -x));
13 | }
14 |
15 | PyObject* tanh_impl(PyObject *, PyObject* o) {
16 | double x = PyFloat_AsDouble(o);
17 | double tanh_x = sinh_impl(x) / cosh_impl(x);
18 | return PyFloat_FromDouble(tanh_x);
19 | }
20 |
21 | static PyMethodDef superfastcode_methods[] = {
22 | // The first property is the name exposed to Python, fast_tanh, the second is the C++
23 | // function name that contains the implementation.
24 | { "fast_tanh", (PyCFunction)tanh_impl, METH_O, nullptr },
25 |
26 | // Terminate the array with an object containing nulls.
27 | { nullptr, nullptr, 0, nullptr }
28 | };
29 |
30 | static PyModuleDef superfastcode_module = {
31 | PyModuleDef_HEAD_INIT,
32 | "superfastcode", // Module name to use with Python import statements
33 | "Provides some functions, but faster", // Module description
34 | 0,
35 | superfastcode_methods // Structure that defines the methods of the module
36 | };
37 |
38 | PyMODINIT_FUNC PyInit_superfastcode() {
39 | return PyModule_Create(&superfastcode_module);
40 | }
--------------------------------------------------------------------------------
/superfastcode/setup.py:
--------------------------------------------------------------------------------
1 | from distutils.core import setup, Extension
2 |
3 |
4 | sfc_module = Extension('superfastcode', sources=['module.cpp'])
5 |
6 | setup(name='superfastcode', version='1.0',
7 | description='Python Package with superfastcode C++ extension',
8 | ext_modules=[sfc_module]
9 | )
10 |
--------------------------------------------------------------------------------
/superfastcode/superfastcode.vcxproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | Win32
7 |
8 |
9 | Release
10 | Win32
11 |
12 |
13 | Debug
14 | x64
15 |
16 |
17 | Release
18 | x64
19 |
20 |
21 |
22 | 15.0
23 | {28F6146F-9862-4C07-A931-F3DE0A093BB7}
24 | superfastcode
25 | 10.0.17134.0
26 |
27 |
28 |
29 | DynamicLibrary
30 | true
31 | v141
32 | MultiByte
33 |
34 |
35 | DynamicLibrary
36 | false
37 | v141
38 | true
39 | MultiByte
40 |
41 |
42 | DynamicLibrary
43 | true
44 | v141
45 | MultiByte
46 |
47 |
48 | DynamicLibrary
49 | false
50 | v141
51 | true
52 | MultiByte
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 | .pyd
74 |
75 |
76 | .pyd
77 |
78 |
79 | .pyd
80 |
81 |
82 | .pyd
83 |
84 |
85 |
86 | Level3
87 | Disabled
88 | true
89 | true
90 | %PYTHONPATH%\include
91 | Py_LIMITED_API;_WINDLL;%(PreprocessorDefinitions)
92 | MultiThreadedDLL
93 |
94 |
95 | %PYTHONPATH%\libs
96 |
97 |
98 |
99 |
100 | Level3
101 | Disabled
102 | true
103 | true
104 | %PYTHONPATH%\include
105 |
106 |
107 | %PYTHONPATH%\libs
108 |
109 |
110 |
111 |
112 | Level3
113 | MaxSpeed
114 | true
115 | true
116 | true
117 | true
118 | %PYTHONPATH%\include
119 | Py_LIMITED_API;_WINDLL;%(PreprocessorDefinitions)
120 | MultiThreadedDLL
121 |
122 |
123 | true
124 | true
125 | %PYTHONPATH%\libs
126 |
127 |
128 |
129 |
130 | Level3
131 | MaxSpeed
132 | true
133 | true
134 | true
135 | true
136 | %PYTHONPATH%\include
137 |
138 |
139 | true
140 | true
141 | %PYTHONPATH%\libs
142 |
143 |
144 |
145 |
146 |
147 |
148 |
149 |
150 |
151 |
152 |
153 |
--------------------------------------------------------------------------------
/superfastcode2/module.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 |
5 | const double e = 2.7182818284590452353602874713527;
6 |
7 | double sinh_impl(double x) {
8 | return (1 - pow(e, (-2 * x))) / (2 * pow(e, -x));
9 | }
10 |
11 | double cosh_impl(double x) {
12 | return (1 + pow(e, (-2 * x))) / (2 * pow(e, -x));
13 | }
14 |
15 | double tanh_impl(double x) {
16 | return sinh_impl(x) / cosh_impl(x);
17 | }
18 |
19 | namespace py = pybind11;
20 |
21 | PYBIND11_MODULE(superfastcode2, m) {
22 | m.def("fast_tanh2", &tanh_impl, R"pbdoc(
23 | Compute a hyperbolic tangent of a single argument expressed in radians.
24 | )pbdoc");
25 |
26 |
27 | #ifdef VERSION_INFO
28 | m.attr("__version__") = VERSION_INFO;
29 | #else
30 | m.attr("__version__") = "dev";
31 | #endif
32 | }
--------------------------------------------------------------------------------
/superfastcode2/setup.py:
--------------------------------------------------------------------------------
1 | import os, sys
2 |
3 | from distutils.core import setup, Extension
4 | from distutils import sysconfig
5 |
6 | cpp_args = ['-std=c++11', '-stdlib=libc++', '-mmacosx-version-min=10.7']
7 |
8 | sfc_module = Extension(
9 | 'superfastcode2', sources=['module.cpp'],
10 | include_dirs=['pybind11/include'],
11 | language='c++',
12 | extra_compile_args=cpp_args,
13 | )
14 |
15 | setup(
16 | name='superfastcode2',
17 | version='1.0',
18 | description='Python package with superfastcode2 C++ extension (PyBind11)',
19 | ext_modules=[sfc_module],
20 | )
21 |
--------------------------------------------------------------------------------
/superfastcode2/superfastcode2.vcxproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | Win32
7 |
8 |
9 | Release
10 | Win32
11 |
12 |
13 | Debug
14 | x64
15 |
16 |
17 | Release
18 | x64
19 |
20 |
21 |
22 | {98D5E983-CE8C-4AE5-9DA2-0374C81BFB86}
23 | superfastcode
24 | 3.6
25 | 10.0.17134.0
26 | superfastcode2
27 |
28 |
29 |
30 | DynamicLibrary
31 | true
32 | v141
33 | Unicode
34 |
35 |
36 | DynamicLibrary
37 | false
38 | v141
39 | true
40 | Unicode
41 |
42 |
43 | DynamicLibrary
44 | true
45 | v141
46 | Unicode
47 |
48 |
49 | DynamicLibrary
50 | false
51 | v141
52 | true
53 | Unicode
54 |
55 |
56 | RegistryView.Registry32
57 | RegistryView.Registry64
58 | $(PythonVersion)-32
59 | $(PythonVersion)
60 | $([MSBuild]::GetRegistryValueFromView('HKEY_CURRENT_USER\SOFTWARE\Python\PythonCore\$(PythonTag)\InstallPath', null, null, $(RegistryView)))
61 | $([MSBuild]::GetRegistryValueFromView('HKEY_LOCAL_MACHINE\SOFTWARE\Python\PythonCore\$(PythonTag)\InstallPath', null, null, $(RegistryView)))
62 | $([MSBuild]::GetRegistryValueFromView('HKEY_CURRENT_USER\SOFTWARE\Python\PythonCore\$(PythonTag)\InstallPath', 'ExecutablePath', null, $(RegistryView)))
63 | $([MSBuild]::GetRegistryValueFromView('HKEY_LOCAL_MACHINE\SOFTWARE\Python\PythonCore\$(PythonTag)\InstallPath', 'ExecutablePath', null, $(RegistryView)))
64 | $(PythonHome)python.exe
65 | $([MSBuild]::GetRegistryValueFromView('HKEY_CURRENT_USER\SOFTWARE\Python\PythonCore\$(PythonTag)\InstalledFeatures', 'dev', null, $(RegistryView)))
66 | $([MSBuild]::GetRegistryValueFromView('HKEY_LOCAL_MACHINE\SOFTWARE\Python\PythonCore\$(PythonTag)\InstalledFeatures', 'dev', null, $(RegistryView)))
67 | $([MSBuild]::GetRegistryValueFromView('HKEY_CURRENT_USER\SOFTWARE\Python\PythonCore\$(PythonTag)\InstalledFeatures', 'core_pdb', null, $(RegistryView)))
68 | $([MSBuild]::GetRegistryValueFromView('HKEY_LOCAL_MACHINE\SOFTWARE\Python\PythonCore\$(PythonTag)\InstalledFeatures', 'core_pdb', null, $(RegistryView)))
69 | $([MSBuild]::GetRegistryValueFromView('HKEY_CURRENT_USER\SOFTWARE\Python\PythonCore\$(PythonTag)\InstalledFeatures', 'core_d', null, $(RegistryView)))
70 | $([MSBuild]::GetRegistryValueFromView('HKEY_LOCAL_MACHINE\SOFTWARE\Python\PythonCore\$(PythonTag)\InstalledFeatures', 'core_d', null, $(RegistryView)))
71 | _d
72 | $([System.IO.Path]::GetDirectoryName($(PythonExe)))\python$(PythonDebugSuffix).exe
73 | $(PythonExe)
74 |
75 |
76 |
77 | WindowsLocalDebugger
78 | PythonDebugLaunchProvider
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 | superfastcode$(PythonDebugSuffix)
99 | .pyd
100 | $(PythonDExe)
101 | -i -c "print('>>> import superfastcode'); import superfastcode"
102 | PYTHONPATH=$(OutDir)
103 | $(DefaultDebuggerFlavor)
104 |
105 |
106 | superfastcode2
107 | .pyd
108 | $(PythonExe)
109 | -i -c "print('>>> import superfastcode'); import superfastcode"
110 | PYTHONPATH=$(OutDir)
111 | $(DefaultDebuggerFlavor)
112 |
113 |
114 | superfastcode$(PythonDebugSuffix)
115 | .pyd
116 | $(PythonDExe)
117 | -i -c "print('>>> import superfastcode'); import superfastcode"
118 | PYTHONPATH=$(OutDir)
119 | $(DefaultDebuggerFlavor)
120 |
121 |
122 | superfastcode
123 | .pyd
124 | $(PythonExe)
125 | -i -c "print('>>> import superfastcode'); import superfastcode"
126 | PYTHONPATH=$(OutDir)
127 | $(DefaultDebuggerFlavor)
128 |
129 |
130 |
131 | Level3
132 | Disabled
133 | MultithreadedDLL
134 | $(PythonHome)Include;%(AdditionalIncludeDirectories)
135 | true
136 |
137 |
138 | true
139 | $(PythonHome)libs;%(AdditionalLibraryDirectories)
140 |
141 |
142 |
143 |
144 | Level3
145 | Disabled
146 | MultithreadedDLL
147 | $(PythonHome)Include;%(AdditionalIncludeDirectories)
148 | true
149 |
150 |
151 | true
152 | $(PythonHome)libs;%(AdditionalLibraryDirectories)
153 |
154 |
155 |
156 |
157 | Level3
158 | MaxSpeed
159 | true
160 | true
161 | Multithreaded
162 | $(PythonHome)/Include;%(AdditionalIncludeDirectories)
163 | true
164 |
165 |
166 | true
167 | true
168 | true
169 | libucrt.lib;%(IgnoreSpecificDefaultLibraries)
170 | ucrt.lib;%(AdditionalDependencies)
171 | $(PythonHome)libs;%(AdditionalLibraryDirectories)
172 |
173 |
174 |
175 |
176 | Level3
177 | MaxSpeed
178 | true
179 | true
180 | Multithreaded
181 | $(PythonHome)Include;%(AdditionalIncludeDirectories)
182 | true
183 |
184 |
185 | true
186 | true
187 | true
188 | libucrt.lib;%(IgnoreSpecificDefaultLibraries)
189 | ucrt.lib;%(AdditionalDependencies)
190 | $(PythonHome)libs;%(AdditionalLibraryDirectories)
191 |
192 |
193 |
194 |
195 |
196 |
197 |
198 |
199 |
200 |
201 |
202 |
203 |
204 |
205 |
206 |
207 |
--------------------------------------------------------------------------------