diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index f70b749..1163d78 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -13,14 +13,15 @@ jobs: fail-fast: false matrix: version: - - '1.1' + - 'min' + - '1' os: - ubuntu-latest arch: - x64 steps: - uses: actions/checkout@v2 - - uses: julia-actions/setup-julia@v1 + - uses: julia-actions/setup-julia@v3 with: version: ${{ matrix.version }} arch: ${{ matrix.arch }} @@ -37,6 +38,6 @@ jobs: - uses: julia-actions/julia-buildpkg@v1 - uses: julia-actions/julia-runtest@v1 - uses: julia-actions/julia-processcoverage@v1 - - uses: codecov/codecov-action@v1 + - uses: codecov/codecov-action@v6 with: file: lcov.info diff --git a/.gitignore b/.gitignore index 381e0b6..c47558d 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,5 @@ *.jl.*.cov *.jl.mem deps/deps.jl +Manifest.toml +Manifest-v*.*.toml diff --git a/Project.toml b/Project.toml index db99704..a94b37f 100644 --- a/Project.toml +++ b/Project.toml @@ -1,13 +1,13 @@ name = "FactoredMatrices" uuid = "13d07ad6-c0d4-11e8-35b1-91a532e61cc8" authors = ["Tim Holy "] -version = "0.1.1" +version = "0.1.2" [deps] LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" [compat] -julia = "1" +julia = "1.10" [extras] Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" diff --git a/src/FactoredMatrices.jl b/src/FactoredMatrices.jl index 81d6e9f..2301c53 100644 --- a/src/FactoredMatrices.jl +++ b/src/FactoredMatrices.jl @@ -14,7 +14,7 @@ it maintains temporary buffers to avoid the need to allocate intermediate storag when exploiting the factored representation. Constructor syntax: - FactoredMatrix(U, V, J) + FactoredMatrix(U, V, J::Integer) where you expect to compute `M*C` for `C` with `J` columns, `D*M` with `J` rows, or any similar conjugate/transpose operations. """ @@ -90,6 +90,13 @@ function dot(A::FactoredMatrix, B::FactoredMatrix) sum(M1.*conj(M2)) end +""" + ssd(A::FactoredMatrix, B::FactoredMatrix) + +Compute the sum of squared differences between `A` and `B` without forming the full matrices. +""" ssd(A::FactoredMatrix, B::FactoredMatrix) = dot(A, A) - 2*real(dot(A, B)) + dot(B, B) -end +Base.any(f::Union{typeof(isinf),typeof(isnan)}, A::FactoredMatrix) = any(f, A.U) || any(f, A.V) + +end # module diff --git a/test/runtests.jl b/test/runtests.jl index 4804873..2c09d99 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,24 +1,24 @@ using Test, LinearAlgebra -import FactoredMatrices +using FactoredMatrices myrand(::Type{T}, m, n) where {T<:Real} = rand(T, m, n) myrand(::Type{Complex{T}}, m, n) where {T<:Real} = rand(T, m, n) + im*rand(T, m, n) @testset "FactoredMatrices" begin for T in (Float32, Float64, ComplexF32, ComplexF64) - global U = myrand(T, 15, 3) - global V = myrand(T, 3, 10) - global Mf = FactoredMatrices.FactoredMatrix(U, V, 5) - global M = Array(Mf) + U = myrand(T, 15, 3) + V = myrand(T, 3, 10) + Mf = FactoredMatrix(U, V, 5) + M = Array(Mf) @test M == U*V - global C = myrand(T, 10, 5) + C = myrand(T, 10, 5) @test M*C ≈ Mf*C - global D = myrand(T, 15, 5) + D = myrand(T, 15, 5) @test M'*D ≈ Mf'*D @test transpose(M)*D ≈ transpose(Mf)*D @test D'*M ≈ D'*Mf @test transpose(D)*M ≈ transpose(D)*Mf - global E = myrand(T, 5, 10) + E = myrand(T, 5, 10) @test M*adjoint(E) ≈ Mf*E' @test M*transpose(E) ≈ Mf*transpose(E) @test E*adjoint(M) ≈ E*Mf' @@ -27,11 +27,13 @@ myrand(::Type{Complex{T}}, m, n) where {T<:Real} = rand(T, m, n) + im*rand(T, m, @test D'*M ≈ D'*Mf @test M*E' ≈ Mf*E' @test E*M' ≈ E*Mf' + @test !any(isnan, Mf) + @test !any(isinf, Mf) U1 = myrand(T, 15, 4) V1 = myrand(T, 4, 10) M1 = U1*V1 - M1f = FactoredMatrices.FactoredMatrix(U1, V1, 5) + M1f = FactoredMatrix(U1, V1, 5) @test sum(abs2, M-M1) ≈ FactoredMatrices.ssd(Mf, M1f) end end