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
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "InfiniteLinearAlgebra"
uuid = "cde9dba0-b1de-11e9-2c62-0bab9446c55c"
version = "0.10"
version = "0.10.1"

[deps]
ArrayLayouts = "4c555306-a7a7-4459-81d9-ec55ddd5c99a"
Expand All @@ -26,7 +26,7 @@ FillArrays = "1.0"
InfiniteArrays = "0.15"
InfiniteRandomArrays = "0.2"
Infinities = "0.1"
LazyArrays = "2.6"
LazyArrays = "2.7"
LazyBandedMatrices = "0.11"
LinearAlgebra = "1"
MatrixFactorizations = "3.0"
Expand Down
13 changes: 10 additions & 3 deletions src/InfiniteLinearAlgebra.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import Base: *, +, -, /, \, ^, AbstractArray, AbstractMatrix, AbstractVector, Ar
axes, copy, copymutable, copyto!, getindex, getproperty, inv,
length, map, oneto, promote_op, require_one_based_indexing, show,
similar, size, transpose, adjoint, copymutable, transpose,
adjoint, copymutable, transpose
adjoint, copymutable, transpose, tail

import Base.Broadcast: BroadcastStyle, Broadcasted, broadcasted

Expand Down Expand Up @@ -114,8 +114,15 @@ function chop(A::AbstractMatrix{T}, tol::Real=zero(real(T))) where T
return A
end

pad(c::AbstractVector{T}, ax::Union{OneTo,OneToInf}) where T = [c; Zeros{T}(length(ax)-length(c))]
pad(c, ax...) = PaddedArray(c, ax)
pad(c::AbstractVector{T}, ax::Union{OneTo,OneToInf}) where T = Vcat(c, Zeros{T}(length(ax)-length(c)))
pad(c::AbstractVector{T}, n::Int) where T = Vcat(c, Zeros{T}(n-length(c)))

_colon2axes(::Tuple{}, bx::Tuple{}) = ()
_colon2axes(ax::Tuple, bx::Tuple{Colon, Vararg{Any}}) = (first(ax), _colon2axes(tail(ax), tail(bx))...)
_colon2axes(ax::Tuple, bx::Tuple{Union{Integer,Infinity}, Vararg{Any}}) = (oneto(first(bx)), _colon2axes(tail(ax), tail(bx))...)
_colon2axes(ax::Tuple, bx::Tuple) = (first(bx), _colon2axes(tail(ax), tail(bx))...)
pad(c, ax...) = PaddedArray(c, _colon2axes(axes(c), ax))
pad(c, ax::Colon...) = c

pad(c::Transpose, ax, bx) = transpose(pad(parent(c), bx, ax))
pad(c::Adjoint, ax, bx) = adjoint(pad(parent(c), bx, ax))
Expand Down
9 changes: 7 additions & 2 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,14 @@ end

@test pad(1:3, 5) == [1:3; 0; 0]
@test pad(1:3, oneto(∞)) isa Vcat
@test pad(1:3, :) ≡ 1:3
X = Matrix(reshape(1:6, 3, 2))
P = pad(X, oneto(3), oneto(∞))
@test P isa PaddedArray
# TODO: replace ≈ with ==
@test pad(X, oneto(3), ∞) ≈ pad(X, oneto(3), oneto(∞)) ≈ pad(X, 3, oneto(∞)) ≈ pad(X, 3, ∞) ≈ pad(X, :, ∞)
@test pad(X, oneto(3), oneto(∞)) isa PaddedArray
@test pad(X, :, oneto(∞)) isa PaddedArray
@test pad(X, :, :) isa Matrix
@test pad(X, oneto(10), :) isa PaddedArray
P = pad(BlockVec(X), blockedrange(Fill(3,∞)))
@test P isa BlockVec
@test MemoryLayout(P) isa PaddedColumns
Expand Down
Loading