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

python otcpp one line from def to .so - do I need it or is there something better? #11

Open
4 of 7 tasks
yOyOeK1 opened this issue May 5, 2023 · 0 comments
Open
4 of 7 tasks
Labels
documentation Improvements or additions to documentation otcpp Related to python otcpp wrapper

Comments

@yOyOeK1
Copy link
Owner

yOyOeK1 commented May 5, 2023

Readme is needed for now.

otdm-cpp-wrapper aks otcpp

It's my fix for making c / cpp code functions injections in one way to python. By using decorators from python it's wrapping def then look for it content. In example you can see its' raff!

what is working now

  • proof of koncept
  • simple wrapper / decorator
  • can get argument __type__:
    • _int_ directly from python
    • _array_ / _vector_ of _ctypes.c_*_ directly from python
  • unwrap / redecorate def build and imported
  • checker if it's need to update / rebuild .so (code change)

why to use it

As one line solution for native python .so file builder it's fast to make a function moved to native c / cpp where all the power is in your hands. Really good in situations where performance of your code in computing high / math

how to use it [ manual installation ]

  • get otcppwrapper.py file to your project
  • in your python
    from otcpwrapper import *
  • wrap a MyDiv function for example
    @otcpp
    def MyDiv( a: int = 0, b: int = 1 ) -> int:
      '''
      int MyDiv( int a, int b ){
        return a/b;
      }
      '''
    It gets it's c/cpp code as comment in the def it can by any function you want. It this example it's division of two integers.
  • use it as normally you use def by
    print( MyDiv( 6, 2 ) ) 
    or
    after invoking it once it's in cache then you can use
    f = otDynoWith( 'MyDiv' )
    print( f( 6, 2 ) )

It's making in background a .c files then it compiles it and in dynamic way import those files as .so library

example

https://github.com/yOyOeK1/oiyshTerminal/blob/main/otdm-cpp-wrapper/otcpp.py

it running

one of first runs
This shows that light function are ok if not faster in python but if the amount of math is higher / more data to process it's ~15x faster in execution.

@yOyOeK1 yOyOeK1 added documentation Improvements or additions to documentation otcpp Related to python otcpp wrapper labels May 5, 2023
@yOyOeK1 yOyOeK1 changed the title otcpp need REDME otcpp do I need it or is there something beter? May 5, 2023
@yOyOeK1 yOyOeK1 changed the title otcpp do I need it or is there something beter? otcpp do I need it or is there something better? May 5, 2023
@yOyOeK1 yOyOeK1 changed the title otcpp do I need it or is there something better? python otcpp one line from def to .so - do I need it or is there something better? May 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation otcpp Related to python otcpp wrapper
Projects
None yet
Development

No branches or pull requests

1 participant