Skip to content

Commit

Permalink
Fix indexing (#37)
Browse files Browse the repository at this point in the history
* Fix indexing bug

* Restore testing
  • Loading branch information
willtebbutt authored and andreasnoack committed Jul 15, 2018
1 parent 2610b68 commit b3d97fc
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/ToeplitzMatrices.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ include("iterativeLinearSolvers.jl")
abstract type AbstractToeplitz{T<:Number} <: AbstractMatrix{T} end

size(A::AbstractToeplitz) = (size(A, 1), size(A, 2))
getindex(A::AbstractToeplitz, i::Integer) = A[mod(i, size(A,1)), div(i, size(A,1)) + 1]
function getindex(A::AbstractToeplitz, i::Integer)
return A[mod(i - 1, size(A, 1)) + 1, div(i - 1, size(A, 1)) + 1]
end

convert(::Type{AbstractMatrix{T}}, S::AbstractToeplitz) where {T} = convert(AbstractToeplitz{T}, S)
convert(::Type{AbstractArray{T}}, S::AbstractToeplitz) where {T} = convert(AbstractToeplitz{T}, S)
Expand Down
2 changes: 2 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ xl = randn(nl, 5)

@test As * xs Matrix(As) * xs
@test Al * xl Matrix(Al) * xl
@test [As[n] for n in 1:length(As)] == vec(As)
@test [Al[n] for n in 1:length(Al)] == vec(Al)
@test ldiv!(As, Compat.LinearAlgebra.copy_oftype(xs, eltype(As))) Matrix(As) \ xs
@test ldiv!(Al, Compat.LinearAlgebra.copy_oftype(xl, eltype(Al))) Matrix(Al) \ xl
end
Expand Down

0 comments on commit b3d97fc

Please sign in to comment.