Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand All @@ -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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
*.jl.*.cov
*.jl.mem
deps/deps.jl
Manifest.toml
Manifest-v*.*.toml
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
name = "FactoredMatrices"
uuid = "13d07ad6-c0d4-11e8-35b1-91a532e61cc8"
authors = ["Tim Holy <tim.holy@gmail.com>"]
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"
Expand Down
11 changes: 9 additions & 2 deletions src/FactoredMatrices.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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.
"""
Expand Down Expand Up @@ -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
20 changes: 11 additions & 9 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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
Loading