rename
This commit is contained in:
parent
8e019e0f30
commit
ce6c96c2be
@ -3,7 +3,7 @@ module Batches
|
|||||||
using Juno, Lazy
|
using Juno, Lazy
|
||||||
using Juno: Tree, Row
|
using Juno: Tree, Row
|
||||||
|
|
||||||
export CatMat, rawbatch,
|
export Storage, rawbatch,
|
||||||
Batch, Batched, batchone, tobatch, rebatch,
|
Batch, Batched, batchone, tobatch, rebatch,
|
||||||
Seq, BatchSeq, rebatchseq
|
Seq, BatchSeq, rebatchseq
|
||||||
|
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
# Batches
|
# Batches
|
||||||
|
|
||||||
struct Batch{T,S} <: ABatch{T}
|
struct Batch{T,S} <: BatchLike{T,S}
|
||||||
data::CatMat{T,S}
|
data::Storage{T,S}
|
||||||
end
|
end
|
||||||
|
|
||||||
@forward Batch.data size, eltype, getindex, setindex!, rawbatch
|
@forward Batch.data size, eltype, getindex, setindex!, rawbatch
|
||||||
|
|
||||||
Batch(xs) = Batch(CatMat(xs))
|
Batch(xs) = Batch(Storage(xs))
|
||||||
|
|
||||||
convert{T,S}(::Type{Batch{T,S}},storage::S) =
|
convert{T,S}(::Type{Batch{T,S}},storage::S) =
|
||||||
Batch{T,S}(storage)
|
Batch{T,S}(storage)
|
||||||
@ -37,13 +37,13 @@ tobatch(xs) = tobatch(batchone(xs))
|
|||||||
|
|
||||||
# Sequences
|
# Sequences
|
||||||
|
|
||||||
struct Seq{T,S} <: ABatch{T}
|
struct Seq{T,S} <: BatchLike{T,S}
|
||||||
data::CatMat{T,S}
|
data::Storage{T,S}
|
||||||
end
|
end
|
||||||
|
|
||||||
@forward Seq.data size, eltype, getindex, setindex!, rawbatch
|
@forward Seq.data size, eltype, getindex, setindex!, rawbatch
|
||||||
|
|
||||||
Seq(xs) = Seq(CatMat(xs))
|
Seq(xs) = Seq(Storage(xs))
|
||||||
|
|
||||||
convert{T,S}(::Type{Seq{T,S}},storage::S) =
|
convert{T,S}(::Type{Seq{T,S}},storage::S) =
|
||||||
Seq{T,S}(storage)
|
Seq{T,S}(storage)
|
||||||
|
@ -1,24 +1,24 @@
|
|||||||
import Base: eltype, size, getindex, setindex!, convert
|
import Base: eltype, size, getindex, setindex!, convert
|
||||||
|
|
||||||
abstract type ABatch{T} <: AbstractVector{T}
|
abstract type BatchLike{T,S} <: AbstractVector{T}
|
||||||
end
|
end
|
||||||
|
|
||||||
struct CatMat{T,S} <: ABatch{T}
|
struct Storage{T,S} <: BatchLike{T,S}
|
||||||
data::S
|
data::S
|
||||||
end
|
end
|
||||||
|
|
||||||
convert{T,S}(::Type{CatMat{T,S}},storage::S) =
|
convert{T,S}(::Type{Storage{T,S}},storage::S) =
|
||||||
CatMat{T,S}(storage)
|
Storage{T,S}(storage)
|
||||||
|
|
||||||
eltype{T}(::CatMat{T}) = T
|
eltype{T}(::Storage{T}) = T
|
||||||
|
|
||||||
size(b::CatMat) = (size(b.data, 1),)
|
size(b::Storage) = (size(b.data, 1),)
|
||||||
|
|
||||||
getindex(b::CatMat, i)::eltype(b) = slicedim(b.data, 1, i)
|
getindex(b::Storage, i)::eltype(b) = slicedim(b.data, 1, i)
|
||||||
|
|
||||||
setindex!(b::CatMat, v, i::Integer) = b.data[i, :] = v
|
setindex!(b::Storage, v, i::Integer) = b.data[i, :] = v
|
||||||
|
|
||||||
function setindex!(b::CatMat, xs, ::Colon)
|
function setindex!(b::Storage, xs, ::Colon)
|
||||||
for (i, x) in enumerate(xs)
|
for (i, x) in enumerate(xs)
|
||||||
b[i] = x
|
b[i] = x
|
||||||
end
|
end
|
||||||
@ -26,32 +26,32 @@ end
|
|||||||
|
|
||||||
allequal(xs) = all(x -> x == first(xs), xs)
|
allequal(xs) = all(x -> x == first(xs), xs)
|
||||||
|
|
||||||
function (::Type{CatMat{T,S}}){T,S}(xs, storage::S)
|
function (::Type{Storage{T,S}}){T,S}(xs, storage::S)
|
||||||
@assert allequal(map(size, xs))
|
@assert allequal(map(size, xs))
|
||||||
@assert size(storage) == (length(xs), size(first(xs))...)
|
@assert size(storage) == (length(xs), size(first(xs))...)
|
||||||
for i = 1:length(xs)
|
for i = 1:length(xs)
|
||||||
storage[i, :] = xs[i]
|
storage[i, :] = xs[i]
|
||||||
end
|
end
|
||||||
return CatMat{T,S}(storage)
|
return Storage{T,S}(storage)
|
||||||
end
|
end
|
||||||
|
|
||||||
function (::Type{CatMat{T}}){T}(xs)
|
function (::Type{Storage{T}}){T}(xs)
|
||||||
xs′ = map(rawbatch, xs)
|
xs′ = map(rawbatch, xs)
|
||||||
storage = similar(first(xs′), (length(xs′), size(first(xs′))...))
|
storage = similar(first(xs′), (length(xs′), size(first(xs′))...))
|
||||||
CatMat{T,typeof(storage)}(xs′, storage)
|
Storage{T,typeof(storage)}(xs′, storage)
|
||||||
end
|
end
|
||||||
|
|
||||||
function CatMat(xs)
|
function Storage(xs)
|
||||||
xs = promote(xs...)
|
xs = promote(xs...)
|
||||||
CatMat{eltype(xs)}(xs)
|
Storage{eltype(xs)}(xs)
|
||||||
end
|
end
|
||||||
|
|
||||||
@render Juno.Inline b::CatMat begin
|
@render Juno.Inline b::Storage begin
|
||||||
Tree(Row(Text("CatMat of "), eltype(b),
|
Tree(Row(Text("Storage of "), eltype(b),
|
||||||
Juno.fade("[$(length(b))]")),
|
Juno.fade("[$(length(b))]")),
|
||||||
Juno.trim(collect(b)))
|
Juno.trim(collect(b)))
|
||||||
end
|
end
|
||||||
|
|
||||||
rawbatch(xs) = xs
|
rawbatch(xs) = xs
|
||||||
|
|
||||||
rawbatch(xs::CatMat) = xs.data
|
rawbatch(xs::Storage) = xs.data
|
||||||
|
Loading…
Reference in New Issue
Block a user