Skip to content
Snippets Groups Projects
Verified Commit b6a843b3 authored by Michiel Cottaar's avatar Michiel Cottaar
Browse files

Only iterate once over infinitely repeating sequence

parent 185b857a
No related branches found
No related tags found
No related merge requests found
......@@ -21,7 +21,7 @@ Sub-types need to implement:
abstract type BaseSequence{N} <: ContainerBlock end
function Base.getindex(bs::BaseSequence{N}, index::Integer) where {N}
if index < 1 || index > length(bs)
if nrepeat(bs) > 0 && (index < 1 || index > length(bs))
throw(BoundsError(bs, index))
end
base_index = ((index - 1) % N) + 1
......@@ -29,7 +29,7 @@ function Base.getindex(bs::BaseSequence{N}, index::Integer) where {N}
end
Base.iterate(bs::BaseSequence) = Base.iterate(bs, 1)
Base.iterate(bs::BaseSequence{N}, index::Integer) where {N} = index > length(bs) ? nothing : (bs[index], index + 1)
Base.length(bs::BaseSequence{N}) where {N} = nrepeat(bs) * N
Base.length(bs::BaseSequence{N}) where {N} = iszero(nrepeat(bs)) ? N : (nrepeat(bs) * N)
Base.eltype(::Type{<:BaseSequence}) = ContainerBlock
function start_time(bs::BaseSequence{N}, index::Integer) where {N}
......
......@@ -20,10 +20,9 @@ Defines an MRI sequence from a vector of building blocks.
struct Sequence{N} <: BaseSequence{N}
blocks :: SVector{N, <:ContainerBlock}
TR :: VariableType
nrepeat :: Int
end
function Sequence(blocks::AbstractVector; TR=:min, nrepeat=0)
function Sequence(blocks::AbstractVector; TR=:min)
if TR == :min
TR = sum(duration, blocks; init=0.)
end
......@@ -36,8 +35,7 @@ end
Sequence(blocks...; kwargs...) = Sequence([blocks...]; kwargs...)
get_index_single_TR(s::Sequence, i::Integer) = s.blocks[i]
Base.IteratorSize(::Type{<:Sequence}) = Base.IsInfinite()
nrepeat(::Sequence) = Inf
nrepeat(::Sequence) = 0
"""
to_block(block_like)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment