Skip to content

Commit

Permalink
Constructor to convert. (#77)
Browse files Browse the repository at this point in the history
Some types can't call the constructor directly so overloading convert is preferable here.
  • Loading branch information
weinbe58 authored Feb 25, 2024
1 parent 77ff1ed commit 857742b
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/IMatrix.jl
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ IMatrix(n::Integer) = IMatrix{Bool}(n)

Base.size(A::IMatrix, i::Int) = (@assert i == 1 || i == 2; A.n)
Base.size(A::IMatrix) = (A.n, A.n)
Base.getindex(::IMatrix{T}, i::Integer, j::Integer) where {T} = T(i == j)
Base.getindex(::IMatrix{T}, i::Integer, j::Integer) where {T} = convert(T, i == j)

Base.:(==)(d1::IMatrix, d2::IMatrix) = d1.n == d2.n
Base.isapprox(d1::IMatrix, d2::IMatrix; kwargs...) = d1 == d2
Expand All @@ -48,4 +48,4 @@ LinearAlgebra.ishermitian(D::IMatrix) = true

####### sparse matrix ######
nnz(M::IMatrix) = M.n
findnz(M::IMatrix{T}) where {T} = (collect(1:M.n), collect(1:M.n), ones(T, M.n))
findnz(M::IMatrix{T}) where {T} = (collect(1:M.n), collect(1:M.n), ones(T, M.n))

0 comments on commit 857742b

Please sign in to comment.