Skip to content

Commit 7d5eb4f

Browse files
committed
switch to pythoncall
1 parent 2207389 commit 7d5eb4f

File tree

9 files changed

+38
-38
lines changed

9 files changed

+38
-38
lines changed

Diff for: .github/workflows/ci-joli.yaml

+2-17
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
fail-fast: false
2020

2121
matrix:
22-
version: ['1.6', '1.7', '1']
22+
version: ['lts', '1.10', '1']
2323
os:
2424
- ubuntu-latest
2525
- macos-latest
@@ -31,29 +31,14 @@ jobs:
3131
uses: actions/checkout@v2
3232

3333
- name: Setup julia
34-
uses: julia-actions/setup-julia@v1
34+
uses: julia-actions/setup-julia@v2
3535
with:
3636
version: ${{ matrix.version }}
3737
arch: ${{ matrix.arch }}
38-
39-
- name: Set up Python 3.7
40-
uses: actions/setup-python@v1
41-
with:
42-
python-version: 3.7
43-
44-
- name: Install wavelets
45-
run: |
46-
python -m pip install --upgrade pip
47-
pip install PyWavelets
4838

4939
- name: Build JOLI
5040
uses: julia-actions/julia-buildpkg@latest
5141

52-
- name: Rebuild PyCall with system python
53-
run: |
54-
export PYTHON=$(which python)
55-
julia --color=yes --check-bounds=yes --project -e 'using Pkg; Pkg.build("PyCall")'
56-
5742
- name: Run tests
5843
uses: julia-actions/julia-runtest@latest
5944

Diff for: CondaPkg.toml

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[deps]
2+
python = ""
3+
pywavelets = ""

Diff for: Project.toml

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "JOLI"
22
uuid = "bb331ad6-a1cf-11e9-23da-9bcb53c69f6f"
33
authors = ["Henryk Modzelewski <[email protected]>"]
4-
version = "0.8.5"
4+
version = "0.9.0"
55

66
[deps]
77
ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"
@@ -16,7 +16,7 @@ LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
1616
NFFT = "efe261a4-0d2b-5849-be55-fc731d526b0d"
1717
Nullables = "4d1e1d77-625e-5b40-9113-a560ec7a8ecd"
1818
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
19-
PyCall = "438e738f-606a-5dbb-bf0a-cddfbfd45ab0"
19+
PythonCall = "6099a3de-0909-46bc-b1f4-468b9a2dfc0d"
2020
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
2121
SharedArrays = "1a1011a3-84de-559e-8e89-a11a2f7dc383"
2222
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
@@ -27,12 +27,12 @@ Wavelets = "29a6e085-ba6d-5f35-a997-948ac2efa89a"
2727
ChainRulesCore = "1"
2828
DistributedArrays = "0.5, 0.6"
2929
FFTW = "1"
30-
Flux = "0.12, 0.13"
30+
Flux = "0.12, 0.13, 0.14"
3131
InplaceOps = "0.3.0"
3232
IterativeSolvers = "0.8, 0.9"
3333
NFFT = "0.6 - 0.13"
3434
Nullables = "1"
35-
PyCall = "1.18, 1.90, 1.91, 1.62"
35+
PythonCall = "0.9"
3636
SpecialFunctions = "1.2, 2"
3737
Wavelets = "0.8, 0.9"
3838
julia = "1"

Diff for: README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ JOLI is registered and can be added like any standard julia package with the com
5353

5454
- **CurveLab**: In order to use `joCurvelet2D` or `joCurvelet2DnoFFT` operators, you need to obtain *CurveLab-2.1.2-SLIM*, a SLIM extension to *CurveLab-2.1.2*. The tarball of this extension is available from [curvelet.org](http://www.curvelet.org) under [Software](http://www.curvelet.org/software.html) tab. The installation instructions are included in the tarball of *CurveLab-2.1.2-SLIM*. Note, that CurveLab is free only for academic use and requires registration.
5555

56-
- **PyWavelets**: In order to use `joSWT` that implements 1D stationary/shift invariant wavelet transform, the [PyWavelets](https://github.com/PyWavelets/pywt) package needs to be installed within the python environement used by [PyCall.jl](https://github.com/JuliaPy/PyCall.jl). By default, it will use [Conda.jl](https://github.com/JuliaPy/Conda.jl) and you should follow its directiv to install a package within it. If you have configured `PyCall` with your own python environment you can install `PyWavelets` via `pip install --upgrade PyWavelets`.
56+
- **PyWavelets**: In order to use `joSWT` that implements 1D stationary/shift invariant wavelet transform, the [PyWavelets](https://github.com/PyWavelets/pywt) package needs to be installed within the python environment used by [PythonCall.jl](https://github.com/JuliaPy/PythonCall.jl). By default, it will use [CondaPkg.jl](https://github.com/JuliaPy/CondaPkg.jl) and you should follow its directiv to install a package within it. If you have configured `PythonCall` with your own python environment you can install `PyWavelets` via `pip install --upgrade PyWavelets`.
5757

5858
## Documentation (more to come)
5959

Diff for: src/JOLI.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,10 @@ using DistributedArrays.SPMD
5151
using LinearAlgebra
5252
using InplaceOps
5353
using IterativeSolvers
54+
using PythonCall
5455
using FFTW
5556
using NFFT
5657
using Wavelets
57-
using PyCall
5858
using SpecialFunctions
5959
using ChainRulesCore
6060

Diff for: src/joLinearFunctionConstructors/joSWT.jl

+15-6
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,32 @@
33
## helper module
44
module joSWT_etc
55
using JOLI: jo_convert
6-
using PyCall
6+
using PythonCall
7+
8+
const pywt = PythonCall.pynew()
9+
10+
function __init__()
11+
PythonCall.pycopy!(pywt, pyimport("pywt"))
12+
end
13+
714
# 1D
815
function apply_swt(v::Vector{vdt}, wt::String, L::Integer,rdt::DataType,pad::Integer) where vdt<:Union{AbstractFloat,Complex}
9-
pywt = pyimport("pywt")
1016
v = [v;zeros(vdt, pad)]
1117
rv = pywt.swt(v, wt, level=L, start_level=0, norm=true, trim_approx=true)
12-
rv = vcat(rv...)
18+
rv = vcat([PyArray(r) for r in rv]...)
1319
rv = jo_convert(rdt, rv, false)
1420
return rv
1521
end
22+
1623
function apply_iswt(v::Vector{vdt},wt::String,L::Integer,rdt::DataType,pad::Integer) where vdt<:Union{AbstractFloat,Complex}
17-
pywt = pyimport("pywt")
1824
v = reshape(v, :, L+1)
1925
v = [v[:, i] for i=1:L+1]
20-
rv = pywt.iswt(v, wt, norm=true)
26+
rv = PyArray(pywt.iswt(v, wt, norm=true))
2127
# Convert and remove pad
2228
rv = jo_convert(rdt, rv[1:end-pad], false)
2329
return rv
2430
end
31+
2532
end
2633
using .joSWT_etc
2734

@@ -68,7 +75,7 @@ examples with DDT/RDT
6875
joDWT(m,"sym5"; DDT=Float32,RDT=Float64)
6976
7077
"""
71-
function joSWT(m::Integer,wt::String="db20";
78+
function joSWT(m::Integer, wt::String="db20";
7279
L::Integer=maxtransformlevels(m + m%2),
7380
DDT::DataType=joFloat,RDT::DataType=DDT,
7481
name::String="joSWT")
@@ -84,3 +91,5 @@ function joSWT(m::Integer,wt::String="db20";
8491
DDT,RDT;
8592
name=name)
8693
end
94+
95+
joSWT(m::Integer, wt::Py; kwargs...) = joSWT(m, string(wt); kwargs...)

Diff for: src/joMixedConstructors/joGaussian.jl

+9-6
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ module joGaussian_etc
55
using JOLI: jo_convert, LocalVector
66
using Random
77
using LinearAlgebra
8-
function fI(v::LocalVector{vdt},m::Integer,n::Integer,rng::AbstractRNG,rns::Array{UInt32,1},rdt::DataType) where vdt<:Number
8+
9+
const rngT = Union{Vector{UInt32}, UInt128}
10+
11+
function fI(v::LocalVector{vdt},m::Integer,n::Integer,rng::AbstractRNG,rns::rngT,rdt::DataType) where vdt<:Number
912
rv = zeros(rdt,m)
1013
lrng=Random.seed!(rng,rns)
1114
for i=1:n
@@ -15,7 +18,7 @@ module joGaussian_etc
1518
rv = jo_convert(rdt,rv,false)
1619
return rv
1720
end
18-
function aI(v::LocalVector{vdt},m::Integer,n::Integer,rng::AbstractRNG,rns::Array{UInt32,1},rdt::DataType) where vdt<:Number
21+
function aI(v::LocalVector{vdt},m::Integer,n::Integer,rng::AbstractRNG,rns::rngT,rdt::DataType) where vdt<:Number
1922
rv = Vector{rdt}(undef,n)
2023
lrng=Random.seed!(rng,rns)
2124
for i=1:n
@@ -25,7 +28,7 @@ module joGaussian_etc
2528
rv = jo_convert(rdt,rv,false)
2629
return rv
2730
end
28-
function scale(m::Integer,n::Integer,rng::AbstractRNG,rns::Array{UInt32,1},rdt::DataType)
31+
function scale(m::Integer,n::Integer,rng::AbstractRNG,rns::rngT,rdt::DataType)
2932
rv = Vector{rdt}(undef,n)
3033
lrng=Random.seed!(rng,rns)
3134
for i=1:n
@@ -37,7 +40,7 @@ module joGaussian_etc
3740
rv = jo_convert(rdt,rv,false)
3841
return rv
3942
end
40-
function fIN(v::LocalVector{vdt},m::Integer,n::Integer,scale::LocalVector{<:Number},rng::AbstractRNG,rns::Array{UInt32,1},rdt::DataType) where vdt<:Number
43+
function fIN(v::LocalVector{vdt},m::Integer,n::Integer,scale::LocalVector{<:Number},rng::AbstractRNG,rns::rngT,rdt::DataType) where vdt<:Number
4144
rv = zeros(rdt,m)
4245
lrng=Random.seed!(rng,rns)
4346
for i=1:n
@@ -47,7 +50,7 @@ module joGaussian_etc
4750
rv = jo_convert(rdt,rv,false)
4851
return rv
4952
end
50-
function aIN(v::LocalVector{vdt},m::Integer,n::Integer,scale::LocalVector{<:Number},rng::AbstractRNG,rns::Array{UInt32,1},rdt::DataType) where vdt<:Number
53+
function aIN(v::LocalVector{vdt},m::Integer,n::Integer,scale::LocalVector{<:Number},rng::AbstractRNG,rns::rngT,rdt::DataType) where vdt<:Number
5154
rv = Vector{rdt}(undef,n)
5255
lrng=Random.seed!(rng,rns)
5356
for i=1:n
@@ -134,7 +137,7 @@ function joGaussian(M::Integer,N::Integer=M;
134137
return joMatrix(a;DDT=DDT,RDT=RDT,name=name*"_o")
135138
else
136139
if implicit
137-
rngs=copy(RNG.seed)
140+
rngs = copy(RNG.seed)
138141
if normalized
139142
fscale = joGaussian_etc.scale(M,N,RNG,rngs,DDT)
140143
ascale = joGaussian_etc.scale(M,N,RNG,rngs,RDT)

Diff for: test/runtests.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ using SparseArrays
55
using InplaceOps
66
using FFTW
77
using Wavelets
8-
using PyCall
8+
using PythonCall
99
using JOLI
1010

1111
jo_type_mismatch_error_set(false)

Diff for: test/test_joSWT.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ try
44
global swt = pywt.swt
55
global pywavelet = true
66
catch
7-
@warn "Skipping joSWTtests - PyCall clouldn't import PyWavelets"
7+
@warn "Skipping joSWTtests - PythonCall clouldn't import PyWavelets"
88
end
99

1010
families = ("haar", "db", "sym", "coif")
11-
pywavelet ? wavelets = vcat([pywt.wavelist(name) for name in families]...) : wavelets = []
11+
pywavelet ? wavelets = vcat([pyconvert(Vector{String}, pywt.wavelist(name)) for name in families]...) : wavelets = []
1212

1313
tsname="joSWT"
1414
@testset "$tsname" begin

0 commit comments

Comments
 (0)