Skip to content

Commit

Permalink
feat(matrices): add logdet(::Hilbert)
Browse files Browse the repository at this point in the history
  • Loading branch information
mfasi committed Jan 20, 2025
1 parent af59f14 commit c17e3b8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/matrices/hilbert.jl
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ LinearAlgebra.issymmetric(A::Hilbert) = A.m == A.n
return T(one(T) / (i + j - 1))
end

logc(x) = sum([sum(log.(1:i)) for i = 2:(x-1)])
function LinearAlgebra.logdet(A::Hilbert)
LinearAlgebra.checksquare(A)
return (4 * logc(A.n) - logc(2 * A.n))

Check warning on line 58 in src/matrices/hilbert.jl

View check run for this annotation

Codecov / codecov/patch

src/matrices/hilbert.jl#L55-L58

Added lines #L55 - L58 were not covered by tests
end
LinearAlgebra.det(A::Hilbert) = inv(det(inv(A)))

function inv(A::Hilbert{T}) where {T}
Expand Down
2 changes: 1 addition & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function test_linear_algebra_functions(A::AbstractMatrix)
@try_catch results[func] = func(A) == func(matrix)
end

computation_functions = [adjoint, transpose, det, eigvals]
computation_functions = [adjoint, transpose, det, logdet, eigvals]
if determinant != 0
append!(computation_functions, [inv])
end
Expand Down

0 comments on commit c17e3b8

Please sign in to comment.