Skip to content

Commit f20670b

Browse files
authored
support Vcat with matrix pad (#198)
* support Vcat with matrix mad * Fix pad with colon * increase coverage
1 parent 2414cbf commit f20670b

File tree

3 files changed

+19
-7
lines changed

3 files changed

+19
-7
lines changed

Project.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "InfiniteLinearAlgebra"
22
uuid = "cde9dba0-b1de-11e9-2c62-0bab9446c55c"
3-
version = "0.10"
3+
version = "0.10.1"
44

55
[deps]
66
ArrayLayouts = "4c555306-a7a7-4459-81d9-ec55ddd5c99a"
@@ -26,7 +26,7 @@ FillArrays = "1.0"
2626
InfiniteArrays = "0.15"
2727
InfiniteRandomArrays = "0.2"
2828
Infinities = "0.1"
29-
LazyArrays = "2.6"
29+
LazyArrays = "2.7"
3030
LazyBandedMatrices = "0.11"
3131
LinearAlgebra = "1"
3232
MatrixFactorizations = "3.0"

src/InfiniteLinearAlgebra.jl

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import Base: *, +, -, /, \, ^, AbstractArray, AbstractMatrix, AbstractVector, Ar
88
axes, copy, copymutable, copyto!, getindex, getproperty, inv,
99
length, map, oneto, promote_op, require_one_based_indexing, show,
1010
similar, size, transpose, adjoint, copymutable, transpose,
11-
adjoint, copymutable, transpose
11+
adjoint, copymutable, transpose, tail
1212

1313
import Base.Broadcast: BroadcastStyle, Broadcasted, broadcasted
1414

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

117-
pad(c::AbstractVector{T}, ax::Union{OneTo,OneToInf}) where T = [c; Zeros{T}(length(ax)-length(c))]
118-
pad(c, ax...) = PaddedArray(c, ax)
117+
pad(c::AbstractVector{T}, ax::Union{OneTo,OneToInf}) where T = Vcat(c, Zeros{T}(length(ax)-length(c)))
118+
pad(c::AbstractVector{T}, n::Int) where T = Vcat(c, Zeros{T}(n-length(c)))
119+
120+
_colon2axes(::Tuple{}, bx::Tuple{}) = ()
121+
_colon2axes(ax::Tuple, bx::Tuple{Colon, Vararg{Any}}) = (first(ax), _colon2axes(tail(ax), tail(bx))...)
122+
_colon2axes(ax::Tuple, bx::Tuple{Union{Integer,Infinity}, Vararg{Any}}) = (oneto(first(bx)), _colon2axes(tail(ax), tail(bx))...)
123+
_colon2axes(ax::Tuple, bx::Tuple) = (first(bx), _colon2axes(tail(ax), tail(bx))...)
124+
pad(c, ax...) = PaddedArray(c, _colon2axes(axes(c), ax))
125+
pad(c, ax::Colon...) = c
119126

120127
pad(c::Transpose, ax, bx) = transpose(pad(parent(c), bx, ax))
121128
pad(c::Adjoint, ax, bx) = adjoint(pad(parent(c), bx, ax))

test/runtests.jl

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,14 @@ end
3838

3939
@test pad(1:3, 5) == [1:3; 0; 0]
4040
@test pad(1:3, oneto(∞)) isa Vcat
41+
@test pad(1:3, :) 1:3
4142
X = Matrix(reshape(1:6, 3, 2))
42-
P = pad(X, oneto(3), oneto(∞))
43-
@test P isa PaddedArray
43+
# TODO: replace ≈ with ==
44+
@test pad(X, oneto(3), ∞) pad(X, oneto(3), oneto(∞)) pad(X, 3, oneto(∞)) pad(X, 3, ∞) pad(X, :, ∞)
45+
@test pad(X, oneto(3), oneto(∞)) isa PaddedArray
46+
@test pad(X, :, oneto(∞)) isa PaddedArray
47+
@test pad(X, :, :) isa Matrix
48+
@test pad(X, oneto(10), :) isa PaddedArray
4449
P = pad(BlockVec(X), blockedrange(Fill(3,∞)))
4550
@test P isa BlockVec
4651
@test MemoryLayout(P) isa PaddedColumns

0 commit comments

Comments
 (0)