Skip to content

Commit

Permalink
No commit message
Browse files Browse the repository at this point in the history
  • Loading branch information
paulxshen committed Dec 22, 2024
1 parent 2454abd commit f63c5fe
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "ArrayPadding"
uuid = "fe5ef43c-4912-423d-9170-4bd5cb6a013a"
authors = ["Paul Shen <[email protected]>"]
version = "0.1.30"
version = "1.0.0"

[deps]
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
Expand Down
16 changes: 4 additions & 12 deletions src/pad.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@ Pads arrays of any dimension with various border options including constants, pe
- any other value `v`: a b c | v
"""
function pad(a, b, l::Union{AbstractVector,Tuple}, r::Base.AbstractVecOrTuple=l)
if all(iszero, l) && all(iszero, r)
return a
end
all(iszero, l) && all(iszero, r) && return a

if eltype(a) <: Number && eltype(b) <: Number
b = convert(eltype(a), b)
end
Expand All @@ -40,12 +39,10 @@ function pad(a, b, l::Union{AbstractVector,Tuple}, r::Base.AbstractVecOrTuple=l)
end
a
end
# function pad!(a::PaddedArray, b, l::Union{AbstractVector,Tuple}, r=l)
# y = pad!(a.a, b, l, r)
# PaddedArray(y, Int.(l .+ left(a)), Int.(r .+ right(a)))
# end

function pad!(a, b, l, r=l, ol=0, or=ol)
all(iszero, l) && all(iszero, r) && return a

d = ndims(a)
l, r, ol, or = vec.((l, r, ol, or), d)
for (i, l, r, ol, or) in zip(1:d, l, r, ol, or)
Expand Down Expand Up @@ -73,8 +70,3 @@ function pad(a::AbstractArray, b, l::Int=1, r::Int=l; dims=1:ndims(a))
sel = in.(1:ndims(a), (dims,))
pad(a, b, l * sel, r * sel)
end

# function pad(a::PaddedArray, b, l=1, r=l; kw...)
# y = pad(a.a, b, l, r; kw...)
# PaddedArray(y, Int.(l .+ left(a)), Int.(r .+ right(a)))
# end

0 comments on commit f63c5fe

Please sign in to comment.