Skip to content

Commit

Permalink
Add quality assurance tests, fix ambiguity (#135)
Browse files Browse the repository at this point in the history
  • Loading branch information
dkarrasch authored Feb 24, 2021
1 parent a87d647 commit f49e91b
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 16 deletions.
5 changes: 3 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "LinearMaps"
uuid = "7a12625a-238d-50fd-b39a-03d52299707e"
version = "3.2.0"
version = "3.2.1"

[deps]
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Expand All @@ -10,6 +10,7 @@ SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
julia = "1"

[extras]
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
BenchmarkTools = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf"
InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Expand All @@ -18,4 +19,4 @@ SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["LinearAlgebra", "SparseArrays", "Test", "BenchmarkTools", "InteractiveUtils", "Quaternions"]
test = ["Aqua", "BenchmarkTools", "InteractiveUtils", "LinearAlgebra", "Quaternions", "SparseArrays", "Test"]
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ The only requirement for a `LinearMap` is that it can act on a vector (by multip

| **Documentation** | **Build Status** |
|:-------------------------------------------------------------------------------:|:-----------------------------------------------------------------------------------------------:|
| [![stable docs][docs-stable-img]][docs-stable-url] [![dev docs][docs-dev-img]][docs-dev-url] | [![build status][build-img]][build-url] [![coverage][codecov-img]][codecov-url] [![license][license-img]][license-url] |
| [![stable docs][docs-stable-img]][docs-stable-url] [![dev docs][docs-dev-img]][docs-dev-url] | [![build status][build-img]][build-url] [![coverage][codecov-img]][codecov-url] [![Aqua QA][aqua-img]][aqua-url] [![license][license-img]][license-url] |

## Installation

Expand Down Expand Up @@ -38,3 +38,6 @@ julia> import Pkg; Pkg.add("LinearMaps")

[license-img]: http://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat
[license-url]: LICENSE.md

[aqua-img]: https://img.shields.io/badge/Aqua.jl-%F0%9F%8C%A2-aqua.svg
[aqua-url]: https://github.com/JuliaTesting/Aqua.jl
2 changes: 0 additions & 2 deletions src/LinearMaps.jl
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,6 @@ include("show.jl") # show methods for LinearMap objects
LinearMap(A::LinearMap; kwargs...)::WrappedMap
LinearMap(A::AbstractMatrix; kwargs...)::WrappedMap
LinearMap(J::UniformScaling, M::Int)::UniformScalingMap
LinearMap(λ::Number, M::Int, N::Int) = FillMap(λ, (M, N))::FillMap
LinearMap(λ::Number, dims::Dims{2}) = FillMap(λ, dims)::FillMap
LinearMap{T=Float64}(f, [fc,], M::Int, N::Int = M; kwargs...)::FunctionMap
Construct a linear map object, either from an existing `LinearMap` or `AbstractMatrix` `A`,
Expand Down
3 changes: 3 additions & 0 deletions src/composition.jl
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ function Base.:(*)(A₁::CompositeMap, A₂::CompositeMap)
T = promote_type(eltype(A₁), eltype(A₂))
return CompositeMap{T}(tuple(A₂.maps..., A₁.maps...))
end
# needed for disambiguation
Base.:(*)(A₁::ScaledMap, A₂::CompositeMap) = A₁.λ * (A₁.lmap * A₂)
Base.:(*)(A₁::CompositeMap, A₂::ScaledMap) = (A₁ * A₂.lmap) * A₂.λ

# special transposition behavior
LinearAlgebra.transpose(A::CompositeMap{T}) where {T} =
Expand Down
24 changes: 14 additions & 10 deletions test/composition.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ using Test, LinearMaps, LinearAlgebra, SparseArrays
M = @inferred 1 * LinearMap(A)
N = @inferred LinearMap(B)
v = rand(ComplexF64, 10)
α = rand(ComplexF64)
@test FCM * v == F * v
@test @inferred (F * F) * v == @inferred F * (F * v)
@test @inferred (F * A) * v == @inferred F * (A * v)
Expand Down Expand Up @@ -52,17 +53,20 @@ using Test, LinearMaps, LinearAlgebra, SparseArrays
R1 = rand(ComplexF64, 10, 10); L1 = LinearMap(R1)
R2 = rand(ComplexF64, 10, 10); L2 = LinearMap(R2)
R3 = rand(ComplexF64, 10, 10); L3 = LinearMap(R3)
CompositeR = prod(LinearMap, [R1, R2, R3])
@test @inferred L1 * L2 * L3 == CompositeR
CompositeR = *(R1, R2, R3)
CompositeL = prod(LinearMap, [R1, R2, R3])
@test @inferred L1 * L2 * L3 == CompositeL
@test Matrix(L1 * L2) sparse(L1 * L2) R1 * R2
@test @inferred transpose(CompositeR) == transpose(L3) * transpose(L2) * transpose(L1)
@test @inferred adjoint(CompositeR) == L3' * L2' * L1'
@test @inferred adjoint(adjoint((CompositeR))) == CompositeR
@test transpose(transpose((CompositeR))) == CompositeR
Lt = @inferred transpose(LinearMap(CompositeR))
@test Lt * v transpose(R3) * transpose(R2) * transpose(R1) * v
Lc = @inferred adjoint(LinearMap(CompositeR))
@test Lc * v R3' * R2' * R1' * v
@test Matrix(@inferred((α * L1) * (L2 * L3))::LinearMaps.ScaledMap) α * CompositeR
@test Matrix(@inferred((L1 * L2) * (L3 * α))::LinearMaps.ScaledMap) α * CompositeR
@test @inferred transpose(CompositeL) == transpose(L3) * transpose(L2) * transpose(L1)
@test @inferred adjoint(CompositeL) == L3' * L2' * L1'
@test @inferred adjoint(adjoint((CompositeL))) == CompositeL
@test transpose(transpose((CompositeL))) == CompositeL
Lt = @inferred transpose(LinearMap(CompositeL))
@test Lt * v transpose(CompositeR) * v
Lc = @inferred adjoint(LinearMap(CompositeL))
@test Lc * v adjoint(CompositeR) * v

# convert to AbstractMatrix
for A in (LinearMap(sprandn(10, 10, 0.3)), LinearMap(rand()*I, 10))
Expand Down
4 changes: 3 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
using Test, LinearMaps
using Test, LinearMaps, Aqua
import LinearMaps: FiveArg, ThreeArg

const matrixstyle = VERSION v"1.3.0-alpha.115" ? FiveArg() : ThreeArg()

const testallocs = VERSION v"1.4-"

Aqua.test_all(LinearMaps)

include("linearmaps.jl")

include("transpose.jl")
Expand Down

2 comments on commit f49e91b

@dkarrasch
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/30748

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v3.2.1 -m "<description of version>" f49e91b9b88b437991cb0c1d286c3ce37629ad27
git push origin v3.2.1

Please sign in to comment.