Skip to content

Commit

Permalink
follow Julia style guide
Browse files Browse the repository at this point in the history
  • Loading branch information
dkarrasch committed Aug 28, 2019
1 parent b6f5f4e commit 668edee
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
8 changes: 3 additions & 5 deletions src/composition.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ struct CompositeMap{T, As<:Tuple{Vararg{LinearMap}}} <: LinearMap{T}
maps::As # stored in order of application to vector
function CompositeMap{T, As}(maps::As) where {T, As}
N = length(maps)
for n = 2:N
for n in 2:N
size(maps[n], 2) == size(maps[n-1], 1) || throw(DimensionMismatch("CompositeMap"))
end
for n = 1:N
for n in 1:N
promote_type(T, eltype(maps[n])) == T || throw(InexactError())
end
new{T, As}(maps)
Expand Down Expand Up @@ -91,9 +91,7 @@ function Base.:(*)(A₁::LinearMap, A₂::LinearMap)
return CompositeMap{T}(tuple(A₂, A₁))
end
Base.:(*)(A₁::LinearMap, A₂::UniformScaling) = A₁ * A₂.λ
Base.:(*)(A₁::LinearMap, A₂::UniformScaling{Bool}) = A₂.λ ? A₁ : A₁ * A₂.λ
Base.:(*)(A₁::UniformScaling, A₂::LinearMap) = A₁.λ * A₂
Base.:(*)(A₁::UniformScaling{Bool}, A₂::LinearMap) = A₁.λ ? A₂ : A₁.λ * A₂

# special transposition behavior
LinearAlgebra.transpose(A::CompositeMap{T}) where {T} = CompositeMap{T}(map(transpose, reverse(A.maps)))
Expand All @@ -116,7 +114,7 @@ function A_mul_B!(y::AbstractVector, A::CompositeMap, x::AbstractVector)
if N>2
dest = Array{T}(undef, size(A.maps[2], 1))
end
for n=2:N-1
for n in 2:N-1
try
resize!(dest, size(A.maps[n], 1))
catch err
Expand Down
4 changes: 2 additions & 2 deletions src/linearcombination.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ struct LinearCombination{T, As<:Tuple{Vararg{LinearMap}}} <: LinearMap{T}
function LinearCombination{T, As}(maps::As) where {T, As}
N = length(maps)
sz = size(maps[1])
for n = 1:N
for n in 1:N
size(maps[n]) == sz || throw(DimensionMismatch("LinearCombination"))
promote_type(T, eltype(maps[n])) == T || throw(InexactError())
end
Expand Down Expand Up @@ -52,7 +52,7 @@ function A_mul_B!(y::AbstractVector, A::LinearCombination, x::AbstractVector)
l = length(A.maps)
if l>1
z = similar(y)
for n=2:l
for n in 2:l
A_mul_B!(z, A.maps[n], x)
y .+= z
end
Expand Down

0 comments on commit 668edee

Please sign in to comment.