Skip to content

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

Description

@yOyOeK1

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationImprovements or additions to documentationotcppRelated to python otcpp wrapper

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions