Skip to content

Commit e34dcc5

Browse files
authored
Merge pull request #32 from mbauman/teh/no_requires
Slim down dependencies
2 parents 08f266d + cb3bb74 commit e34dcc5

File tree

8 files changed

+63
-87
lines changed

8 files changed

+63
-87
lines changed

REQUIRE

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
julia 0.4
2-
Requires
32
Iterators
43
Compat

src/AxisArrays.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module AxisArrays
22

3-
using Requires, Tuples, RangeArrays, Iterators, Compat
3+
using RangeArrays, Iterators, Compat
44
using Compat.view
55

66
export AxisArray, Axis, Interval, axisnames, axisvalues, axisdim, axes, .., atindex
@@ -11,6 +11,5 @@ include("search.jl")
1111
include("indexing.jl")
1212
include("sortedvector.jl")
1313
include("combine.jl")
14-
include("utils.jl")
1514

1615
end

src/core.jl

Lines changed: 43 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# Core types and definitions
22

3+
if VERSION < v"0.5.0-dev"
4+
macro pure(ex)
5+
esc(ex)
6+
end
7+
else
8+
using Base: @pure
9+
end
10+
311
@doc """
412
Type-stable axis-specific indexing and identification with a
513
parametric type.
@@ -148,8 +156,9 @@ _defaultdimname(i) = i == 1 ? (:row) : i == 2 ? (:col) : i == 3 ? (:page) : Symb
148156
AxisArray(A::AbstractArray, axs::Axis...) = AxisArray(A, axs)
149157
@generated function AxisArray{T,N,L}(A::AbstractArray{T,N}, axs::NTuple{L,Axis})
150158
ax = Expr(:tuple)
151-
Ax = Tuples.concatenate(axs, NTuple(i->Axis{_defaultdimname(i+L),UnitRange{Int64}},N-L))
152-
if !isa(axisnames(Tuples.collect(axs)...), Tuple{Vararg{Symbol}})
159+
Ax = Tuple{axs.parameters...,
160+
ntuple(i->Axis{_defaultdimname(i+L),UnitRange{Int64}},N-L)...}
161+
if !all(x->isa(axisname(x),Symbol), axs.parameters)
153162
return :(throw(ArgumentError("the Axis names must be Symbols")))
154163
end
155164
for i=1:L
@@ -194,7 +203,7 @@ end
194203
axisdim{T,N,D,Ax,name,S}(A::Type{AxisArray{T,N,D,Ax}}, ::Type{Axis{name,S}}) = axisdim(A, Axis{name})
195204
function axisdim{T,N,D,Ax,name}(::Type{AxisArray{T,N,D,Ax}}, ::Type{Axis{name}})
196205
isa(name, Int) && return name <= N ? name : error("axis $name greater than array dimensionality $N")
197-
names = axisnames(Tuples.collect(Ax)...)
206+
names = axisnames(Ax)
198207
idx = findfirst(names, name)
199208
idx == 0 && error("axis $name not found in array axes $names")
200209
idx
@@ -230,8 +239,8 @@ Base.similar{T}(A::AxisArray{T}, S::Type, axs::Axis...) = similar(A, S, axs)
230239
push!(ax.args, :(axes(A, Axis{$d})))
231240
end
232241
to_delete = Int[]
233-
for i=1:Tuples.length(axs)
234-
a = Tuples.getindex(axs, i)
242+
for i=1:length(axs.parameters)
243+
a = axs.parameters[i]
235244
d = axisdim(A, a)
236245
axistype(a) <: Tuple{} && push!(to_delete, d)
237246
sz.args[d] = :(length(axs[$i].val))
@@ -248,15 +257,28 @@ end
248257
# A simple display method to include axis information. It might be nice to
249258
# eventually display the axis labels alongside the data array, but that is
250259
# much more difficult.
251-
@compat function Base.show{T,N}(io::IO, m::MIME"text/plain", A::AxisArray{T,N})
252-
println(io, "$N-dimensional AxisArray{$T,$N,...} with axes:")
253-
for (name, val) in zip(axisnames(A), axisvalues(A))
254-
print(io, " :$name, ")
255-
show(IOContext(io, :limit=>true), val)
256-
println(io)
260+
if VERSION < v"0.5.0-dev"
261+
function Base.writemime{T,N}(io::IO, m::MIME"text/plain", A::AxisArray{T,N})
262+
println(io, "$N-dimensional AxisArray{$T,$N,...} with axes:")
263+
for (name, val) in zip(axisnames(A), axisvalues(A))
264+
print(io, " :$name, ")
265+
Base.showlimited(io, val)
266+
println(io)
267+
end
268+
print(io, "And data, a ")
269+
writemime(io, m, A.data)
270+
end
271+
else
272+
function Base.show{T,N}(io::IO, m::MIME"text/plain", A::AxisArray{T,N})
273+
println(io, "$N-dimensional AxisArray{$T,$N,...} with axes:")
274+
for (name, val) in zip(axisnames(A), axisvalues(A))
275+
print(io, " :$name, ")
276+
show(IOContext(io, :limit=>true), val)
277+
println(io)
278+
end
279+
print(io, "And data, a ")
280+
show(io, m, A.data)
257281
end
258-
print(io, "And data, a ")
259-
show(io, m, A.data)
260282
end
261283

262284
# Custom methods specific to AxisArrays
@@ -268,13 +290,19 @@ end
268290
269291
Returns the axis names of an AxisArray or list of Axises as a tuple of Symbols.
270292
""" ->
271-
axisnames{T,N,D,Ax}(::AxisArray{T,N,D,Ax}) = axisnames(Tuples.collect(Ax)...)
272-
axisnames{T,N,D,Ax}(::Type{AxisArray{T,N,D,Ax}}) = axisnames(Tuples.collect(Ax)...)
293+
axisnames{T,N,D,Ax}(::AxisArray{T,N,D,Ax}) = _axisnames(Ax)
294+
axisnames{T,N,D,Ax}(::Type{AxisArray{T,N,D,Ax}}) = _axisnames(Ax)
295+
axisnames{Ax<:Tuple{Vararg{Axis}}}(::Type{Ax}) = _axisnames(Ax)
296+
@pure _axisnames(Ax) = axisnames(Ax.parameters...)
273297
axisnames() = ()
274298
axisnames{name }(::Axis{name}, B::Axis...) = tuple(name, axisnames(B...)...)
275299
axisnames{name }(::Type{Axis{name}}, B::Type...) = tuple(name, axisnames(B...)...)
276300
axisnames{name,T}(::Type{Axis{name,T}}, B::Type...) = tuple(name, axisnames(B...)...)
277301

302+
axisname{name,T}(::Type{Axis{name,T}}) = name
303+
axisname{name }(::Type{Axis{name }}) = name
304+
axisname(ax::Axis) = axisname(typeof(ax))
305+
278306
@doc """
279307
axisvalues(A::AxisArray) -> (AbstractVector...)
280308
axisvalues(ax::Axis...) -> (AbstractVector...)

src/indexing.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ end
198198
push!(ex.args, :(I[$i]))
199199
elseif I[i] <: AbstractArray{Bool}
200200
push!(ex.args, :(find(I[$i])))
201-
elseif i <= Tuples.length(Ax)
201+
elseif i <= length(Ax.parameters)
202202
push!(ex.args, :(axisindexes(A.axes[$i], I[$i])))
203203
else
204204
push!(ex.args, :(error("dimension ", $i, " does not have an axis to index")))

src/search.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,16 @@ function Base.searchsorted(a::Range, I::Interval)
3636
searchsortedfirst(a, I.lo):searchsortedlast(a, I.hi)
3737
end
3838

39+
if VERSION > v"0.5.0-dev+4557"
40+
# When running with "--check-bounds=yes" (like on Travis), the bounds-check isn't elided
41+
@inline function Base.unsafe_getindex{T}(r::FloatRange{T}, i::Integer)
42+
convert(T, (r.start + (i-1)*r.step)/r.divisor)
43+
end
44+
@inline function Base.unsafe_getindex(r::FloatRange, s::OrdinalRange)
45+
FloatRange(r.start + (first(s)-1)*r.step, step(s)*r.step, length(s), r.divisor)
46+
end
47+
end
48+
3949
function unsafe_searchsortedlast{T<:Number}(a::Range{T}, x::Number)
4050
step(a) == 0 && throw(ArgumentError("ranges with a zero step are unsupported"))
4151
n = round(Integer,(x-first(a))/step(a))+1

src/utils.jl

Lines changed: 0 additions & 68 deletions
This file was deleted.

test/core.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,28 +58,34 @@ H = similar(A, Float64, 1,1,1)
5858
A = AxisArray(1:3)
5959
@test A.data == 1:3
6060
@test axisnames(A) == (:row,)
61+
VERSION >= v"0.5.0-dev" && @inferred(axisnames(A))
6162
@test axisvalues(A) == (1:3,)
6263
A = AxisArray(reshape(1:16, 2,2,2,2))
6364
@test A.data == reshape(1:16, 2,2,2,2)
6465
@test axisnames(A) == (:row,:col,:page,:dim_4)
66+
VERSION >= v"0.5.0-dev" && @inferred(axisnames(A))
6567
@test axisvalues(A) == (1:2, 1:2, 1:2, 1:2)
6668
# Just axis names
6769
A = AxisArray(1:3, :a)
6870
@test A.data == 1:3
6971
@test axisnames(A) == (:a,)
72+
VERSION >= v"0.5.0-dev" && @inferred(axisnames(A))
7073
@test axisvalues(A) == (1:3,)
7174
A = AxisArray([1 3; 2 4], :a)
7275
@test A.data == [1 3; 2 4]
7376
@test axisnames(A) == (:a, :col)
77+
VERSION >= v"0.5.0-dev" && @inferred(axisnames(A))
7478
@test axisvalues(A) == (1:2, 1:2)
7579
# Just axis values
7680
A = AxisArray(1:3, .1:.1:.3)
7781
@test A.data == 1:3
7882
@test axisnames(A) == (:row,)
83+
VERSION >= v"0.5.0-dev" && @inferred(axisnames(A))
7984
@test axisvalues(A) == (.1:.1:.3,)
8085
A = AxisArray(reshape(1:16, 2,2,2,2), .5:.5:1)
8186
@test A.data == reshape(1:16, 2,2,2,2)
8287
@test axisnames(A) == (:row,:col,:page,:dim_4)
88+
VERSION >= v"0.5.0-dev" && @inferred(axisnames(A))
8389
@test axisvalues(A) == (.5:.5:1, 1:2, 1:2, 1:2)
8490

8591
# Test axisdim

test/runtests.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,5 @@ include("indexing.jl")
77
include("sortedvector.jl")
88
include("search.jl")
99
include("combine.jl")
10+
11+
nothing

0 commit comments

Comments
 (0)