From 857742b71c7daf93579c1ba1e18dffba842b8df4 Mon Sep 17 00:00:00 2001 From: Phillip Weinberg Date: Sun, 25 Feb 2024 13:35:20 -0500 Subject: [PATCH] Constructor to convert. (#77) Some types can't call the constructor directly so overloading convert is preferable here. --- src/IMatrix.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/IMatrix.jl b/src/IMatrix.jl index 80c6a97..7325fc8 100644 --- a/src/IMatrix.jl +++ b/src/IMatrix.jl @@ -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 @@ -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)) \ No newline at end of file +findnz(M::IMatrix{T}) where {T} = (collect(1:M.n), collect(1:M.n), ones(T, M.n))