Skip to content

Commit c9aa4e3

Browse files
authored
Merge pull request #12 from alsam/teh/ones_zeros
Deprecate zeros(inds::UnitRange...) and similar `ones`
2 parents 6418ba4 + 2d28b56 commit c9aa4e3

File tree

2 files changed

+7
-10
lines changed

2 files changed

+7
-10
lines changed

src/OffsetArrays.jl

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,6 @@ end
111111

112112
### Convenience functions ###
113113

114-
Base.zeros(T::Type, inds::UnitRange...) = fill!(OffsetArray{T}(inds), zero(T))
115-
Base.zeros(inds::UnitRange...) = zeros(Float64, inds...)
116-
Base.ones(T::Type, inds::UnitRange...) = fill!(OffsetArray{T}(inds), one(T))
117-
Base.ones(inds::UnitRange...) = ones(Float64, inds...)
118114
Base.fill(x, inds::Tuple{UnitRange,Vararg{UnitRange}}) = fill!(OffsetArray{typeof(x)}(inds), x)
119115
@inline Base.fill(x, ind1::UnitRange, inds::UnitRange...) = fill(x, (ind1, inds...))
120116

@@ -161,4 +157,11 @@ end
161157
@inline unsafe_getindex(a::OffsetArray, I...) = unsafe_getindex(a, Base.IteratorsMD.flatten(I)...)
162158
@inline unsafe_setindex!(a::OffsetArray, val, I...) = unsafe_setindex!(a, val, Base.IteratorsMD.flatten(I)...)
163159

160+
# Deprecations
161+
import Base: zeros, ones
162+
@deprecate zeros(T::Type, inds::UnitRange...) fill!(OffsetArray{T}(inds), zero(T))
163+
@deprecate ones(T::Type, inds::UnitRange...) fill!(OffsetArray{T}(inds), one(T))
164+
@deprecate zeros(inds::UnitRange...) fill!(OffsetArray{Float64}(inds), 0)
165+
@deprecate ones(inds::UnitRange...) fill!(OffsetArray{Float64}(inds), 1)
166+
164167
end # module

test/runtests.jl

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -314,12 +314,6 @@ v = OffsetArray(rand(8), (-2,))
314314
@test A+A == OffsetArray(parent(A)+parent(A), A.offsets)
315315
@test A.*A == OffsetArray(parent(A).*parent(A), A.offsets)
316316

317-
B = zeros(1:3, -1:1)
318-
@test indices(B) == (1:3,-1:1)
319-
@test all(B .== 0)
320-
B = ones(1:3, -1:1)
321-
@test indices(B) == (1:3,-1:1)
322-
@test all(B .== 1)
323317
B = fill(5, 1:3, -1:1)
324318
@test indices(B) == (1:3,-1:1)
325319
@test all(B.==5)

0 commit comments

Comments
 (0)