Skip to content

Commit

Permalink
Redesign (#2)
Browse files Browse the repository at this point in the history
Cleaned up several things + more tests
  • Loading branch information
colinxs authored May 7, 2020
1 parent 00cd6cf commit f7c3682
Show file tree
Hide file tree
Showing 24 changed files with 847 additions and 1,733 deletions.
5 changes: 2 additions & 3 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@ version = "0.1.1"

[deps]
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
Compat = "34da2185-b29b-5c13-b0c7-acf172513d20"
DocStringExtensions = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae"
MacroTools = "1914dd2f-81c6-5fcd-8719-6d5c9610ff09"
Requires = "ae029012-a4dd-5104-9daa-d747884805df"
Shapes = "175de200-b73b-11e9-28b7-9b5b306cec37"
StaticNumbers = "c5e4b96a-f99f-5557-8ed2-dc63ef9b5131"
UnsafeArrays = "c4a57d5a-5b31-53a6-b365-19f8c011fbd6"
Zygote = "e88e6eb3-aa80-5325-afca-941959d7151f"

[compat]
Compat = "3.9"
julia = "1.3"
22 changes: 8 additions & 14 deletions src/SpecialArrays.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,30 @@ module SpecialArrays

using Adapt

using Base: @propagate_inbounds, @pure, @_inline_meta, require_one_based_indexing
using Base.MultiplicativeInverses: SignedMultiplicativeInverse
using Base: @propagate_inbounds, @pure, @_inline_meta
using Base: require_one_based_indexing, tail, unsafe_length

using Compat
using DocStringExtensions
using MacroTools: @forward
using Requires: @require
using Shapes
using StaticNumbers
using UnsafeArrays


const Idx = Union{Colon,Real,AbstractArray}
const NestedArray{V,M,N} = AbstractArray{<:AbstractArray{V,M},N}


include("tuple.jl")
include("util.jl")
include("viewtype.jl")
include("cartesianindexer.jl")
include("typedbool.jl")

export innereltype, innerndims, inneraxes, innersize, innerlength
export inner_eltype, inner_ndims, inner_axes, inner_size, inner_length
include("functions.jl")

export SlicedArray, slice
export SlicedArray, slice, align
include("slicedarray.jl")

export FlattenedArray, flatview, flatten
include("flattenedarray.jl")

export ElasticArray
include("elasticarray.jl")

export BatchedVector, batch, batchlike
include("batchedvector.jl")

Expand Down
16 changes: 8 additions & 8 deletions src/batchedvector.jl
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
struct BatchedVector{T,P<:AbsVec} <: AbsVec{T} # TODO T<:AbsVec
struct BatchedVector{T,P<:AbstractVector} <: AbstractVector{T} # TODO T<:AbstractVector
parent::P
offsets::Vector{Int}
@inline function BatchedVector{T,P}(parent, offsets) where {T,P<:AbsVec}
@inline function BatchedVector{T,P}(parent, offsets) where {T,P<:AbstractVector}
check_offsets(parent, offsets)
new(parent, offsets)
end
end

@inline function BatchedVector(parent::AbsVec, offsets::AbsVec{<:Integer})
T = viewtype(parent, firstindex(parent):firstindex(parent))
@inline function BatchedVector(parent::AbstractVector, offsets::AbstractVector{<:Integer})
T = @inbounds typeof(view(parent, firstindex(parent):firstindex(parent)))
BatchedVector{T,typeof(parent)}(parent, offsets)
end

Expand Down Expand Up @@ -59,7 +59,7 @@ Base.parent(A::BatchedVector) = A.parent
View `A` as a vector of batches where `batch(parent, batch_lengths)[i]` has
length `batch_lengths[i]`.
"""
@inline function batch(parent::AbsVec, batch_lengths)
@inline function batch(parent::AbstractVector, batch_lengths)
offsets = Vector{Int}(undef, length(batch_lengths) + 1)
offsets[1] = cumsum = 0
for (i, l) in enumerate(batch_lengths)
Expand All @@ -73,7 +73,7 @@ end
$(SIGNATURES)
View `A` as a vector of batches using the same batch lengths as `B`.
"""
@inline function batchlike(A::AbsVec, B::BatchedVector)
@inline function batchlike(A::AbstractVector, B::BatchedVector)
length(A) == length(B.parent) || throw(ArgumentError("length(A) != length(parent(B))"))
BatchedVector(A, copy(B.offsets))
end
Expand Down Expand Up @@ -101,7 +101,7 @@ end

check_offsets(A::BatchedVector) = check_offsets(A.parent, A.offsets)

function check_offsets(parent::AbsVec, offsets::AbsVec{<:Integer})
function check_offsets(parent::AbstractVector, offsets::AbstractVector{<:Integer})
length(offsets) >= 1 || throw(ArgumentError("offsets cannot be empty"))
first(offsets) == 0 || throw(ArgumentError("First offset is non-zero"))
len = 0
Expand All @@ -115,4 +115,4 @@ function check_offsets(parent::AbsVec, offsets::AbsVec{<:Integer})
throw(ArgumentError("Length computed from offsets is not equal to length(parent)"))
end
return nothing
end
end
23 changes: 0 additions & 23 deletions src/cartesianindexer.jl

This file was deleted.

Loading

0 comments on commit f7c3682

Please sign in to comment.