Skip to content

Commit 7cf2a82

Browse files
authored
Using RecursiveArrayTools (#8)
resolving #5 #7 #9
1 parent 087f8cc commit 7cf2a82

26 files changed

+726
-779
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
*.bbl
1010
*.blg
1111
*.log
12+
*.DS_Store
1213

1314

1415
docs/build/
1516
docs/site/
17+
docs/Manifest.toml

.travis.yml

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ os:
44
- linux
55
- osx
66
julia:
7-
- 0.7
87
- 1.0
8+
- 1.1
99
- nightly
1010
matrix:
1111
allow_failures:
@@ -17,5 +17,14 @@ notifications:
1717
after_success:
1818
- julia -e 'using Pkg; cd(Pkg.dir("AbstractOperators")); Pkg.add("Coverage"); using Coverage; Coveralls.submit(process_folder())'
1919
- julia -e 'using Pkg; cd(Pkg.dir("AbstractOperators")); Pkg.add("Coverage"); using Coverage; Codecov.submit(Codecov.process_folder())'
20-
- julia -e 'using Pkg; Pkg.add("Documenter")'
21-
- julia -e 'using Pkg; cd(Pkg.dir("AbstractOperators")); include(joinpath("docs", "make.jl"))'
20+
21+
jobs:
22+
include:
23+
- stage: "Documentation"
24+
julia: 1.1
25+
os: linux
26+
script:
27+
- julia --project=docs/ -e 'using Pkg; Pkg.develop(PackageSpec(path=pwd()));
28+
Pkg.instantiate()'
29+
- julia --project=docs/ docs/make.jl
30+
after_success: skip

README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,17 +73,19 @@ julia> H = [A B]
7373

7474
In this case `H` has a domain of dimensions `size(H,2) = ((3, 4), (3, 4))` and type `domainType(H) = (Float64, Complex{Float64})`.
7575

76-
When an `AbstractOperators` have multiple domains, this must be multiplied using a `Tuple`s of `AbstractArray`s with corresponding `size(H,2)` and `domainType(H)`, for example:
76+
When an `AbstractOperators` have multiple domains, this must be multiplied using an `ArrayPartition` (see [RecursiveArrayTools](https://github.com/JuliaDiffEq/RecursiveArrayTools.jl/]) with corresponding size and domain, for example:
7777

7878
```julia
79-
julia> H*(x, complex(x))
79+
julia> using RecursiveArrayTools
80+
81+
julia> H*ArrayPartition(x, complex(x))
8082
3×4 Array{Complex{Float64},2}:
8183
-16.3603+0.0im 52.4946-8.69342im -129.014+0.0im 44.6712+8.69342im
8284
-22.051+23.8135im 16.5309-10.9601im -22.5719+39.5599im 13.8174+3.81678im
8385
-5.81874-23.8135im 9.70679-3.81678im -2.21552-39.5599im 11.5502+10.9601im
8486
```
8587

86-
Similarly, when an `AbstractOperators` have multiple codomains, this will return a `Tuple` of `AbstractArray`s with corresponding `size(H,1)` and `codomainType(H)`, for example:
88+
Similarly, when an `AbstractOperators` have multiple codomains, this will return an `ArrayPartition`, for example:
8789
```julia
8890
julia> V = VCAT(Eye(3,3),FiniteDiff((3,3)))
8991
[I;δx] ℝ^(3, 3) ->^(3, 3) ℝ^(2, 3)

REQUIRE

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
julia 0.7
2-
AbstractFFTs v0.3.2
3-
FFTW 0.2.4
4-
DSP 0.5.1
1+
julia 1.0
2+
AbstractFFTs v0.3
3+
FFTW 0.2
4+
DSP 0.5
5+
RecursiveArrayTools 0.18

appveyor.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
environment:
22
matrix:
3-
- julia_version: 0.7
4-
- julia_version: 1
3+
- julia_version: 1.0
4+
- julia_version: 1.1
55
- julia_version: nightly
66

77
platform:
@@ -10,7 +10,6 @@ platform:
1010

1111
matrix:
1212
allow_failures:
13-
- julia_version: 1
1413
- julia_version: nightly
1514

1615
branches:

docs/Project.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[deps]
2+
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"

docs/make.jl

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ using Documenter, AbstractOperators
22

33
makedocs(
44
modules = [AbstractOperators],
5-
format = :html,
5+
format = Documenter.HTML(),
66
sitename = "AbstractOperators.jl",
77
authors = "Niccolò Antonello and Lorenzo Stella",
8-
pages = Any[
8+
pages = [
99
"Home" => "index.md",
1010
"Abstract Operators" => "operators.md",
1111
"Calculus rules" => "calculus.md",
@@ -15,9 +15,5 @@ makedocs(
1515

1616
deploydocs(
1717
repo = "github.com/kul-forbes/AbstractOperators.jl.git",
18-
julia = "0.6",
19-
osname = "linux",
2018
target = "build",
21-
deps = nothing,
22-
make = nothing,
2319
)

docs/src/index.md

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# AbstractOperators.jl
22

3+
[![Build Status](https://travis-ci.org/kul-forbes/AbstractOperators.jl.svg?branch=master)](https://travis-ci.org/kul-forbes/AbstractOperators.jl)
4+
[![Build status](https://ci.appveyor.com/api/projects/status/lfrmkg2s1awyxtk8/branch/master?svg=true)](https://ci.appveyor.com/project/nantonel/abstractoperators-jl/branch/master)
5+
[![codecov](https://codecov.io/gh/kul-forbes/AbstractOperators.jl/branch/master/graph/badge.svg)](https://codecov.io/gh/kul-forbes/AbstractOperators.jl)
6+
7+
[![](https://img.shields.io/badge/docs-stable-blue.svg)](https://kul-forbes.github.io/AbstractOperators.jl/stable)
8+
[![](https://img.shields.io/badge/docs-latest-blue.svg)](https://kul-forbes.github.io/AbstractOperators.jl/latest)
9+
310
## Description
411

512
Abstract operators extend the syntax typically used for matrices to linear mappings of arbitrary dimensions and nonlinear functions. Unlike matrices however, abstract operators apply the mappings with specific efficient algorithms that minimize memory requirements.
@@ -66,17 +73,19 @@ julia> H = [A B]
6673

6774
In this case `H` has a domain of dimensions `size(H,2) = ((3, 4), (3, 4))` and type `domainType(H) = (Float64, Complex{Float64})`.
6875

69-
When an `AbstractOperators` have multiple domains, this must be multiplied using a `Tuple`s of `AbstractArray`s with corresponding `size(H,2)` and `domainType(H)`, for example:
76+
When an `AbstractOperators` have multiple domains, this must be multiplied using an `ArrayPartition` (see [RecursiveArrayTools](https://github.com/JuliaDiffEq/RecursiveArrayTools.jl/]) with corresponding size and domain, for example:
7077

7178
```julia
72-
julia> H*(x, complex(x))
79+
julia> using RecursiveArrayTools
80+
81+
julia> H*ArrayPartition(x, complex(x))
7382
3×4 Array{Complex{Float64},2}:
7483
-16.3603+0.0im 52.4946-8.69342im -129.014+0.0im 44.6712+8.69342im
7584
-22.051+23.8135im 16.5309-10.9601im -22.5719+39.5599im 13.8174+3.81678im
7685
-5.81874-23.8135im 9.70679-3.81678im -2.21552-39.5599im 11.5502+10.9601im
7786
```
7887

79-
Similarly, when an `AbstractOperators` have multiple codomains, this will return a `Tuple` of `AbstractArray`s with corresponding `size(H,1)` and `codomainType(H)`, for example:
88+
Similarly, when an `AbstractOperators` have multiple codomains, this will return an `ArrayPartition`, for example:
8089
```julia
8190
julia> V = VCAT(Eye(3,3),FiniteDiff((3,3)))
8291
[I;δx] ℝ^(3, 3) ->^(3, 3) ℝ^(2, 3)

src/AbstractOperators.jl

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,10 @@ __precompile__()
22

33
module AbstractOperators
44

5-
using LinearAlgebra, AbstractFFTs, DSP, FFTW
5+
using LinearAlgebra, AbstractFFTs, DSP, FFTW, RecursiveArrayTools
66

7-
# Block stuff
8-
include("utilities/block.jl")
9-
using AbstractOperators.BlockArrays
107

8+
const RealOrComplex{R} = Union{R, Complex{R}}
119
abstract type AbstractOperator end
1210

1311
abstract type LinearOperator <: AbstractOperator end
@@ -18,11 +16,11 @@ import LinearAlgebra: mul!
1816
export LinearOperator,
1917
NonLinearOperator,
2018
AbstractOperator
19+
export mul!
2120

2221
# Predicates and properties
2322

2423
include("properties.jl")
25-
2624
include("calculus/AdjointOperator.jl")
2725

2826
## Linear operators

src/calculus/DCAT.jl

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ DCAT ℝ^10 ℝ^10 ℝ^(4, 4) -> ℝ^10 ℝ^10 ℝ^(3, 4)
1616
To evaluate `DCAT` operators multiply them with a `Tuple` of `AbstractArray` of the correct domain size and type. The output will consist as well of a `Tuple` with the codomain type and size of the `DCAT`.
1717
1818
```julia
19-
julia> D*(ones(2),ones(2),ones(3))
19+
julia> D*ArrayPartition(ones(2),ones(2),ones(3))
2020
([2.0, 2.0], Complex{Float64}[3.0+0.0im, 0.0+0.0im, 0.0+0.0im])
2121
2222
```
@@ -62,9 +62,12 @@ function DCAT(A::Vararg{AbstractOperator})
6262
end
6363

6464
# Mappings
65-
@generated function mul!(y, H::DCAT{N,L,P1,P2}, b) where {N,L,P1,P2}
65+
@generated function mul!(yy::ArrayPartition,
66+
H::DCAT{N,L,P1,P2},
67+
bb::ArrayPartition) where {N,L,P1,P2}
6668

67-
ex = :()
69+
# extract stuff
70+
ex = :(y = yy.x; b = bb.x )
6871

6972
for i = 1:N
7073

@@ -76,7 +79,7 @@ end
7679
# stacked operator
7780
# build mul!(( y[H.idxC[i][1]], y[H.idxC[i][2]] ... ), H.A[i], b)
7881
yy = [ :(y[H.idxC[$i][$ii]]) for ii in eachindex(fieldnames(fieldtype(P2,i)))]
79-
yy = :( tuple( $(yy...) ) )
82+
yy = :( ArrayPartition( $(yy...) ) )
8083
end
8184

8285
if fieldtype(P1,i) <: Int
@@ -87,7 +90,7 @@ end
8790
# stacked operator
8891
# build mul!(H.buf, H.A[i],( b[H.idxD[i][1]], b[H.idxD[i][2]] ... ))
8992
bb = [ :(b[H.idxD[$i][$ii]]) for ii in eachindex(fieldnames(fieldtype(P1,i))) ]
90-
bb = :( tuple( $(bb...) ) )
93+
bb = :( ArrayPartition( $(bb...) ) )
9194
end
9295

9396
ex = :($ex; mul!($yy,H.A[$i],$bb))
@@ -98,9 +101,12 @@ end
98101

99102
end
100103

101-
@generated function mul!(y, A::AdjointOperator{DCAT{N,L,P1,P2}}, b) where {N,L,P1,P2}
104+
@generated function mul!(yy::ArrayPartition,
105+
A::AdjointOperator{DCAT{N,L,P1,P2}},
106+
bb::ArrayPartition) where {N,L,P1,P2}
102107

103-
ex = :(H = A.A)
108+
# extract stuff
109+
ex = :(H = A.A; y = yy.x; b = bb.x )
104110

105111
for i = 1:N
106112

@@ -112,7 +118,7 @@ end
112118
# stacked operator
113119
# build mul!(( y[H.idxD[i][1]], y[H.idxD[i][2]] ... ), H.A[i]', b)
114120
yy = [ :(y[H.idxD[$i][$ii]]) for ii in eachindex(fieldnames(fieldtype(P1,i)))]
115-
yy = :( tuple( $(yy...) ))
121+
yy = :( ArrayPartition( $(yy...) ))
116122
end
117123

118124
if fieldtype(P2,i) <: Int
@@ -123,7 +129,7 @@ end
123129
# stacked operator
124130
# build mul!(H.buf, H.A[i]',( b[H.idxC[i][1]], b[H.idxC[i][2]] ... ))
125131
bb = [ :(b[H.idxC[$i][$ii]]) for ii in eachindex(fieldnames(fieldtype(P2,i)))]
126-
bb = :( tuple( $(bb...) ) )
132+
bb = :( ArrayPartition( $(bb...) ) )
127133
end
128134

129135
ex = :($ex; mul!($yy,H.A[$i]',$bb))
@@ -196,7 +202,7 @@ remove_displacement(D::DCAT) = DCAT(remove_displacement.(D.A), D.idxD, D.idxC)
196202

197203
# special cases
198204
# Eye constructor
199-
Eye(x::A) where {N, A <: NTuple{N,AbstractArray}} = DCAT(Eye.(x)...)
205+
Eye(x::ArrayPartition) = DCAT(Eye.(x.x)...)
200206
diag(L::DCAT{N,NTuple{N,E}}) where {N, E <: Eye} = 1.
201207
diag_AAc(L::DCAT{N,NTuple{N,E}}) where {N, E <: Eye} = 1.
202208
diag_AcA(L::DCAT{N,NTuple{N,E}}) where {N, E <: Eye} = 1.

0 commit comments

Comments
 (0)