Suzhou-Tongyuan / jnumpy

Writing Python C extensions in Julia within 5 minutes.
MIT License
234 stars 8 forks source link

Define class JuliaBase and JuliaRaw for julia #41

Closed songjhaha closed 1 year ago

songjhaha commented 2 years ago

WIP

codecov-commenter commented 2 years ago

Codecov Report

Merging #41 (2d9e1aa) into main (bbfddd4) will increase coverage by 5.79%. The diff coverage is 80.16%.

@@            Coverage Diff             @@
##             main      #41      +/-   ##
==========================================
+ Coverage   60.97%   66.77%   +5.79%     
==========================================
  Files          11       13       +2     
  Lines         920     1279     +359     
==========================================
+ Hits          561      854     +293     
- Misses        359      425      +66     
Impacted Files Coverage Δ
TyPython/src/CPython.APIs.jl 52.54% <ø> (ø)
TyPython/src/CPython.jl 55.26% <ø> (ø)
TyPython/src/JuliaWrap/JuliaRaw.jl 75.82% <75.82%> (ø)
TyPython/src/JuliaWrap/JuliaBase.jl 80.55% <80.55%> (ø)
TyPython/src/CPython.Boot.jl 78.46% <100.00%> (+5.38%) :arrow_up:
TyPython/src/CPython.Defs.jl 22.91% <100.00%> (+5.13%) :arrow_up:
TyPython/src/CPython.Dev.jl 63.82% <0.00%> (+1.06%) :arrow_up:
TyPython/src/Utils.jl 100.00% <0.00%> (+44.44%) :arrow_up:

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

thautwarm commented 2 years ago

Besides, changes for credits are needed as this PR uses code from PythonCall.

songjhaha commented 2 years ago

Small example for test:

import TyPython.CPython
import TyPython.CPython: py_coerce, py_cast, Py
CPython.init()
CPython.init_jlwrap()
struct Point
    x
    y
end
a = Point(1,2)
pya = py_cast(Py, a)
# Py(<jl p(1, 2)>)
pya.x
# Py(1)
pya.x = py_cast(Py, nothing)
# Py(None)

function f(x, y, z; a, b, c)
    @show x, y, z
    @show a, b, c
    return 1
end
pyf = py_cast(Py, f)
pyf([py_cast(Py,i) for i in (1, true, nothing)]...; a=py_cast(Py, "a"), b=py_cast(Py,0.0), c=py_cast(Py, rand(2,3)))
# (x, y, z) = (1, true, nothing)
# (a, b, c) = ("a", 0.0, [0.8484332315447124 0.9791275442163967 0.7543573420348929; 0.6921301635292861 0.2314489986814141 0.5471932798687941])
# Py(1)

Todo:

songjhaha commented 1 year ago

Would finish this work in another repo.