dasi.utils.region

Classes

Direction

EmptySpan(a, b, length[, cyclic, index, …])

Constructs a new Span.

Region(start, end, length[, cyclic, index, …])

A direction span.

Span(a, b, length[, cyclic, index, …])

Span maps the provided positions onto a context.

Exceptions

SpanError

Classes

EmptySpan(a, b, length[, cyclic, index, …])

Constructs a new Span.

Region(start, end, length[, cyclic, index, …])

A direction span.

Span(a, b, length[, cyclic, index, …])

Span maps the provided positions onto a context.

Exceptions

SpanError

class dasi.utils.region.EmptySpan(a, b, length, cyclic=False, index=0, ignore_wrap=False, strict=False, abs_wrap=False)[source]

Bases: dasi.utils.region.Span

Constructs a new Span. There are several options to customize the initialization procedure.

strict=True

When strict, any index outside the valid bounds of the context raises an IndexError.

Span(1, 10, 10, cyclic=True, strict=True) # no raise
Span(1, 11, 10, cyclic=True, strict=True) # raises IndexError
Span(0, 11, 10, index=1, cyclic=True, strict=True) # raises IndexError

Attributes

a

Return the inclusive mapped startpoint.

b

Return the exclusive mapped endpoint.

c

Return the exclusive un-mapped endpoint.

context_length

Return the length of the context.

cyclic

Return whether the context is cyclic/circular.

index

Return the starting index of the context.

Methods

bounds()

Return the context bounds (end exclusive)

connecting_span(other)

Return the span that connects the two spans.

consecutive(other)

Returns True if other span is immediately consecutive with this span.

contains_pos(pos)

Checks if this span contains a specified position.

contains_span(other)

Checks if this span encompasses another span.

differences(other)

Return a tuple of differences between this span and the other span.

force_context(other)

Raise error if another Span has different context.

get_slice(x[, infer_type, as_type, …])

Use the region to slice the iterable, returning a iterable of the same type as ‘x’.

get_slice_iter(x)

Use the region to slice the iterable, returning another generator.

i(p)

Find index of position.

intersection(other)

Return the span inersection between this span and the other span.

invert()

Invert the region, returning a tuple of the remaining spans from the context.

new(a, b[, ignore_wrap, index, strict, abs_wrap])

Create a new span using the same context.

overlaps_with(other)

Returns True if other span has an overlap with this span.

ranges(*args)

Return the valid ranges for this span.

reindex(i[, strict, ignore_wrap])

Return a new span with positions reindexed.

same_context(other)

Return if another Span as an equivalent context.

slices()

Return list of slices.

sub(a, b)

Create a sub region starting from a to b.

t(p[, throw_error])

Translates a position ‘p’ to an index within the context bounds.

ignore_wrap=True

When wrapping is ignored, indices are simply mapped to the context with no consideration of the number of times the absolute position would wrap around the context.

# all of the following are equivalent with ignore_wrap == True
Span(1, 10, 10, cyclic=True, ignore_wrap=True)
Span(1+10, 10, 10, cyclic=True, ignore_wrap=True)
Span(1, 10-100, 10, cyclic=True, ignore_wrap=True)
Span(1+20, 10-100, 10, cyclic=True, ignore_wrap=True)

abs_wrap=True

When absolute wrapping is used, the absolute difference between starting and ending index wrappings is calculated, the starting index is to the context while the ending index is adjusted such that the length will reflect the abs difference between starting and ending index wrappings. This can be unintuitive is best shown with the following example:

# all of the following initializations result in equivalent spans

# starts at 1, wraps around one full time, ends at 5.
# Length is 15 - 1
s1 = Span(1, 15, 10, cyclic=True, abs_wrap=True)
assert len(s1) == 14

# starts at 11, wraps around one full time, ends at 15.
# Then positions are mapped back to context at 1 and 5.
# Length is still 25 - 11 == 14
s2 = Span(11, 25, 10, cyclic=True, abs_wrap=True)
assert len(s2) == 14

# starts at 11, wraps around one full time, ends at 15.
# Then positions are mapped back to context at 1 and 5.
# Length is now 11 + 5 = 14
s3 = Span(11, 5, 10, cyclic=True, abs_wrap=True)
assert len(s3) == 14

# the lengths change with the abs diff in number of times wrapped
_s = Span(21, 5, 10, cyclic=True, abs_wrap=True)
assert len(_s) == 24

_s = Span(21, 15, 10, cyclic=True, abs_wrap=True)
assert len(_s) == 14

# all
assert s1 == s2
assert s2 == s3
Parameters
  • a (int) – start of the span (inclusive)

  • b (int) – end of the span (exclusive)

  • length (int) – context length of the region

  • cyclic (bool) – whether the underlying context is cyclic

  • index (int) – the starting index of the region

  • strict (bool) – if True, positions outside of context bounds are disallowed.

  • ignore_wrap (bool) – if True (default False), initialization indicies that wrap around multiple times will simply be mapped directly to the context (no wrapping used).

  • abs_wrap – if True, the abs difference between start and end wrappings are used. Starting wraps that are greater than ending wraps are valid. If False and the starting wrap is greater than the ending wrap, an IndexError is thrown.

property a

Return the inclusive mapped startpoint.

property b

Return the exclusive mapped endpoint.

bounds()

Return the context bounds (end exclusive)

Return type

tuple

property c

Return the exclusive un-mapped endpoint.

connecting_span(other)

Return the span that connects the two spans. Returns None.

Parameters

other (Span) –

Return type

Optional[Span]

Returns

consecutive(other)

Returns True if other span is immediately consecutive with this span.

Return type

bool

contains_pos(pos)

Checks if this span contains a specified position.

Parameters

pos (int) – index position

Return type

bool

Returns

bool

contains_span(other)

Checks if this span encompasses another span.

Parameters

other (Span) – other span

Return type

bool

Returns

bool

property context_length

Return the length of the context.

property cyclic

Return whether the context is cyclic/circular.

differences(other)

Return a tuple of differences between this span and the other span.

Return type

Union[Tuple[Span], Tuple[Span, Span]]

force_context(other)

Raise error if another Span has different context.

Parameters

other (Span) – The other span

Return type

None

Returns

None

Raises

SpanError

get_slice(x, infer_type=False, as_type=None, summary_func=None, reduce_op=<built-in function add>)

Use the region to slice the iterable, returning a iterable of the same type as ‘x’. If as_type is provided, the iterable will be typecast.

Parameters
  • x (List) – the iterable to slice

  • as_type (Optional[Any]) – type to convert the iterable into

  • summary_func (Optional[Callable]) – summary function that takes in an interable. If none, uses itertools.reduce(operator.add, arr)

Return type

Any

Returns

Any

get_slice_iter(x)

Use the region to slice the iterable, returning another generator.

Parameters

x (List) – the iterable to slice

Returns

iterable

i(p)

Find index of position.

Parameters

p (int) –

Return type

int

Returns

property index

Return the starting index of the context.

intersection(other)

Return the span inersection between this span and the other span.

Return type

Span

invert()

Invert the region, returning a tuple of the remaining spans from the context. If cyclic, a tuple (span, None) tuple is returned. If linear, a (span, span) is returned.

Returns

inverted regions

Return type

tuple

new(a, b, ignore_wrap=None, index=None, strict=None, abs_wrap=None)

Create a new span using the same context.

Return type

Span

overlaps_with(other)

Returns True if other span has an overlap with this span.

Parameters

other (Span) – The other span

Return type

bool

Returns

True if the two spans overlap.

ranges(*args)[source]

Return the valid ranges for this span.

Parameters

ignore_wraps – if True, multiple wrappings will be ignored.

Return type

List[Tuple[int, int]]

Returns

List[Tuple[int, int]]

reindex(i, strict=None, ignore_wrap=None)

Return a new span with positions reindexed.

Parameters
  • i – new index

  • strict – initialize with ‘strict’

  • ignore_wrap – whether to ignore wrapping indices

Returns

same_context(other)

Return if another Span as an equivalent context.

Return type

bool

slices()

Return list of slices.

Returns

Return type

sub(a, b)

Create a sub region starting from a to b.

Parameters
  • a (int) – starting pos

  • b (int) – ending pos

Return type

Span

Returns

a new Span.

t(p, throw_error=True)

Translates a position ‘p’ to an index within the context bounds.

Parameters
  • p (int) –

  • throw_error

Returns

Return type

class dasi.utils.region.Region(start, end, length, cyclic=False, index=0, direction=1, name=None, region_id=None, ignore_wrap=False, abs_wrap=True, strict=None)[source]

Bases: dasi.utils.region.Span

A direction span.

Initialize a new Region.

Parameters
  • start (int) – start position

  • end (int) – end position (exclusive)

  • length (int) – length of context

  • cyclic (bool) – topology of context

  • index (int) – starting index of context

  • direction (int) – direction of the region

  • name (Optional[str]) – name of the region

  • region_id (Optional[str]) – id of the region

  • strict (bool) – if True, positions outside of context bounds are disallowed.

  • ignore_wrap (bool) – if True (default False), initialization indicies that wrap around multiple times will simply be mapped directly to the context (no wrapping used).

  • abs_wrap (bool) – if True, the abs difference between start and end wrappings are used. Starting wraps that are greater than ending wraps are valid. If False and the starting wrap is greater than the ending wrap, an IndexError is thrown.

Attributes

a

Return the inclusive mapped startpoint.

b

Return the exclusive mapped endpoint.

c

Return the exclusive un-mapped endpoint.

context_length

Return the length of the context.

cyclic

Return whether the context is cyclic/circular.

index

Return the starting index of the context.

Methods

bounds()

Return the context bounds (end exclusive)

connecting_span(other)

Return the span that connects the two spans.

consecutive(other)

Returns True if other span is immediately consecutive with this span.

contains_pos(pos)

Checks if this span contains a specified position.

contains_span(other)

Checks if this span encompasses another span.

differences(other)

Return a tuple of differences between this span and the other span.

flip()

Flip the indices of the region.

force_context(other)

Raise error if another Span has different context.

get_slice(x[, infer_type, as_type, …])

Use the region to slice the iterable, returning a iterable of the same type as ‘x’.

get_slice_iter(x)

Use the region to slice the iterable, returning another generator.

i(p)

Find index of position.

intersection(other)

Return the span inersection between this span and the other span.

invert()

Invert the region, returning a tuple of the remaining spans from the context.

new(a, b)

Create a new span using the same context.

overlaps_with(other)

Returns True if other span has an overlap with this span.

ranges([ignore_wraps])

Return the valid ranges for this span.

reindex(i[, strict, ignore_wrap])

Return a new span with positions reindexed.

same_context(other)

Return if another Span as an equivalent context.

slices()

Return list of slices.

sub(a, b)

Create a sub region starting from a to b.

t(p[, throw_error])

Translates a position ‘p’ to an index within the context bounds.

property a

Return the inclusive mapped startpoint.

property b

Return the exclusive mapped endpoint.

bounds()

Return the context bounds (end exclusive)

Return type

tuple

property c

Return the exclusive un-mapped endpoint.

connecting_span(other)

Return the span that connects the two spans. Returns None.

Parameters

other (Span) –

Return type

Optional[Span]

Returns

consecutive(other)

Returns True if other span is immediately consecutive with this span.

Return type

bool

contains_pos(pos)

Checks if this span contains a specified position.

Parameters

pos (int) – index position

Return type

bool

Returns

bool

contains_span(other)

Checks if this span encompasses another span.

Parameters

other (Span) – other span

Return type

bool

Returns

bool

property context_length

Return the length of the context.

property cyclic

Return whether the context is cyclic/circular.

differences(other)

Return a tuple of differences between this span and the other span.

Return type

Union[Tuple[Span], Tuple[Span, Span]]

flip()[source]

Flip the indices of the region.

Return type

Region

force_context(other)

Raise error if another Span has different context.

Parameters

other (Span) – The other span

Return type

None

Returns

None

Raises

SpanError

get_slice(x, infer_type=False, as_type=None, summary_func=None, reduce_op=<built-in function add>)

Use the region to slice the iterable, returning a iterable of the same type as ‘x’. If as_type is provided, the iterable will be typecast.

Parameters
  • x (List) – the iterable to slice

  • as_type (Optional[Any]) – type to convert the iterable into

  • summary_func (Optional[Callable]) – summary function that takes in an interable. If none, uses itertools.reduce(operator.add, arr)

Return type

Any

Returns

Any

get_slice_iter(x)

Use the region to slice the iterable, returning another generator.

Parameters

x (List) – the iterable to slice

Returns

iterable

i(p)

Find index of position.

Parameters

p (int) –

Return type

int

Returns

property index

Return the starting index of the context.

intersection(other)

Return the span inersection between this span and the other span.

Return type

Span

invert()

Invert the region, returning a tuple of the remaining spans from the context. If cyclic, a tuple (span, None) tuple is returned. If linear, a (span, span) is returned.

Returns

inverted regions

Return type

tuple

new(a, b)[source]

Create a new span using the same context.

overlaps_with(other)

Returns True if other span has an overlap with this span.

Parameters

other (Span) – The other span

Return type

bool

Returns

True if the two spans overlap.

ranges(ignore_wraps=False)

Return the valid ranges for this span.

Parameters

ignore_wraps – if True, multiple wrappings will be ignored.

Return type

List[Tuple[int, int]]

Returns

List[Tuple[int, int]]

reindex(i, strict=None, ignore_wrap=None)

Return a new span with positions reindexed.

Parameters
  • i – new index

  • strict – initialize with ‘strict’

  • ignore_wrap – whether to ignore wrapping indices

Returns

same_context(other)

Return if another Span as an equivalent context.

Return type

bool

slices()

Return list of slices.

Returns

Return type

sub(a, b)

Create a sub region starting from a to b.

Parameters
  • a (int) – starting pos

  • b (int) – ending pos

Return type

Span

Returns

a new Span.

t(p, throw_error=True)

Translates a position ‘p’ to an index within the context bounds.

Parameters
  • p (int) –

  • throw_error

Returns

Return type

class dasi.utils.region.Span(a, b, length, cyclic=False, index=0, ignore_wrap=False, strict=False, abs_wrap=False)[source]

Bases: collections.abc.Container, collections.abc.Iterable, typing.Generic, collections.abc.Sized

Span maps the provided positions onto a context.

Spans have no direction and have an underlying context that has a certain length, can be linear or cyclic, and has a starting index.

Linear spans For example, a basic linear span can be represented using the following:

s = Span(0, 10, 20)
assert s.a == 0
assert s.b == 10
assert list(s) == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]  # spans are always
                                                  # exclusive at endpoint.

Attributes

a

Return the inclusive mapped startpoint.

b

Return the exclusive mapped endpoint.

c

Return the exclusive un-mapped endpoint.

context_length

Return the length of the context.

cyclic

Return whether the context is cyclic/circular.

index

Return the starting index of the context.

Methods

bounds()

Return the context bounds (end exclusive)

connecting_span(other)

Return the span that connects the two spans.

consecutive(other)

Returns True if other span is immediately consecutive with this span.

contains_pos(pos)

Checks if this span contains a specified position.

contains_span(other)

Checks if this span encompasses another span.

differences(other)

Return a tuple of differences between this span and the other span.

force_context(other)

Raise error if another Span has different context.

get_slice(x[, infer_type, as_type, …])

Use the region to slice the iterable, returning a iterable of the same type as ‘x’.

get_slice_iter(x)

Use the region to slice the iterable, returning another generator.

i(p)

Find index of position.

intersection(other)

Return the span inersection between this span and the other span.

invert()

Invert the region, returning a tuple of the remaining spans from the context.

new(a, b[, ignore_wrap, index, strict, abs_wrap])

Create a new span using the same context.

overlaps_with(other)

Returns True if other span has an overlap with this span.

ranges([ignore_wraps])

Return the valid ranges for this span.

reindex(i[, strict, ignore_wrap])

Return a new span with positions reindexed.

same_context(other)

Return if another Span as an equivalent context.

slices()

Return list of slices.

sub(a, b)

Create a sub region starting from a to b.

t(p[, throw_error])

Translates a position ‘p’ to an index within the context bounds.

Indexing and Slicing

New indexes can be provided to spans.

s = Span(1, 10, 10, index=1)
assert s.a == 1
assert s.b == 10

Positions can be mapped to the span:

s = Span(5, 8, 10, index=5)
assert s.a == 5
assert s.b == 8
assert s[0] == 5    # the 'first' position in the span equivalent to the
                    # starting index
assert s[-1] == 7   # the 'last' position in the span is the last inclusive
                    # index

Positions can be mapped automatically during initialization:

s = Span(-1, 5, 10, cyclic=True, index=0)   # index '-1' is mapped onto last
                                            # available index on the context,
'9'
assert s.a == 9
assert s.b == 5

s = Span(6, -1, 10, cyclic=True, index=0)  # index '-1' is mapped onto last
                                           # available exclusive index on the
 context, '10'
assert s.a == 6
assert s.b == 10

Inclusive positions can be mapped onto the context using t:

s = Span(-1, 5, 10, cyclic=True)
assert s.t(11) == 1
assert s.t(10) == 0

Reindexing

Context starting index can be remapped:

s = Span(0, 5, 10)
s1 = s.reindex(1)
asset s1.a == 1
assert s2.b == 6

Slicing

Spans can be sliced similarly to lists:

s = Span(4, 8, 10)
s1 = s[1:]
assert s1.a == 5
assert s2.b == 8

s2 = s[:-1]
assert s2.a == 4
assert s2.b == 7

s3 = s[2:-1]
assert s3.a == 5
assert s3.b == 7

Cyclic spans A cyclic span can be represented in the following way:

s = Span(18, 2, 20, cyclic=True)
assert s.a == 18
assert s.b == 2
assert list(s) == [18, 19, 0, 1]
assert len(s) == 4

Wrapping cyclic spans Spans the wrap around the context multiple times can be represented as well. The mapped endpoint is found with span.b and the non-mapped endpoint is found using span.c.

s = Span(9, 21, 10, cyclic=True)
assert list(s) == [9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0]
assert len(s) == 12
assert s.a == 9  # start point
assert s.b == 1  # mapped endpoint
assert s.c == 21 # the unmapped endpoint

The indices are reduced to their lowest ‘wrapping’ whenever possible. For example, the following initializations are equivalent:

s1 = Span(1, 5, 10, cyclic=True)
s2 = Span(11, 15, 10, cyclic=True)
s3 = Span(21, 25, 10, cyclic=True)
assert s1 == s2
assert s2 == s3

Iterating through spans

Spans can be treated like iterators:

for i in Span(5, 3, 10, cyclic=True):
    print(i)

Span inversion

Inversion returns two spans that represent everything except the span:

s = Span(4, 8, 10)
s1, s2 = s.invert()  # also s[::-1]
assert s1.a == 0
assert s1.b == 4
assert s2.a == 8
assert s2.b == 10

# inverted cyclic span returns one valid span and None
s = Span(4, 8, 10, cyclic=True)
s1, s2 = s.invert()
assert s1.a == 8
assert s1.b == 4
assert s2 is None

Intersections, differences

s1 = Span(4, 10, 20)
s2 = Span(8, 12, 20)
s3 = s1.intersection(s2)
assert s3.a == 8
assert s3.b == 10
s1 = Span(4, 10, 20)
s2 = Span(8, 12, 20)
s3, s4 = s1.differences(s2)

assert s3.a, s3.b == 4, 8
assert s4,a, s4.b == 10, 12

Gotchas

s2 = Span(8, 2, 10, cyclic=True)
assert s2.ranges() == [(8, 10), (0, 2)]
assert s2.ranges(ignore_wraps=True) == [(8, 10), (0, 2)]

# # TODO: this is a strange behavior?
s2 = Span(8, 12, 10, cyclic=True)
assert s2.ranges() == [(8, 10), (0, 2)]
assert s2.ranges(ignore_wraps=True) == [(8, 10), (0, 2)]

Constructs a new Span. There are several options to customize the initialization procedure.

strict=True

When strict, any index outside the valid bounds of the context raises an IndexError.

Span(1, 10, 10, cyclic=True, strict=True) # no raise
Span(1, 11, 10, cyclic=True, strict=True) # raises IndexError
Span(0, 11, 10, index=1, cyclic=True, strict=True) # raises IndexError

ignore_wrap=True

When wrapping is ignored, indices are simply mapped to the context with no consideration of the number of times the absolute position would wrap around the context.

# all of the following are equivalent with ignore_wrap == True
Span(1, 10, 10, cyclic=True, ignore_wrap=True)
Span(1+10, 10, 10, cyclic=True, ignore_wrap=True)
Span(1, 10-100, 10, cyclic=True, ignore_wrap=True)
Span(1+20, 10-100, 10, cyclic=True, ignore_wrap=True)

abs_wrap=True

When absolute wrapping is used, the absolute difference between starting and ending index wrappings is calculated, the starting index is to the context while the ending index is adjusted such that the length will reflect the abs difference between starting and ending index wrappings. This can be unintuitive is best shown with the following example:

# all of the following initializations result in equivalent spans

# starts at 1, wraps around one full time, ends at 5.
# Length is 15 - 1
s1 = Span(1, 15, 10, cyclic=True, abs_wrap=True)
assert len(s1) == 14

# starts at 11, wraps around one full time, ends at 15.
# Then positions are mapped back to context at 1 and 5.
# Length is still 25 - 11 == 14
s2 = Span(11, 25, 10, cyclic=True, abs_wrap=True)
assert len(s2) == 14

# starts at 11, wraps around one full time, ends at 15.
# Then positions are mapped back to context at 1 and 5.
# Length is now 11 + 5 = 14
s3 = Span(11, 5, 10, cyclic=True, abs_wrap=True)
assert len(s3) == 14

# the lengths change with the abs diff in number of times wrapped
_s = Span(21, 5, 10, cyclic=True, abs_wrap=True)
assert len(_s) == 24

_s = Span(21, 15, 10, cyclic=True, abs_wrap=True)
assert len(_s) == 14

# all
assert s1 == s2
assert s2 == s3
Parameters
  • a (int) – start of the span (inclusive)

  • b (int) – end of the span (exclusive)

  • length (int) – context length of the region

  • cyclic (bool) – whether the underlying context is cyclic

  • index (int) – the starting index of the region

  • strict (bool) – if True, positions outside of context bounds are disallowed.

  • ignore_wrap (bool) – if True (default False), initialization indicies that wrap around multiple times will simply be mapped directly to the context (no wrapping used).

  • abs_wrap – if True, the abs difference between start and end wrappings are used. Starting wraps that are greater than ending wraps are valid. If False and the starting wrap is greater than the ending wrap, an IndexError is thrown.

property a

Return the inclusive mapped startpoint.

property b

Return the exclusive mapped endpoint.

bounds()[source]

Return the context bounds (end exclusive)

Return type

tuple

property c

Return the exclusive un-mapped endpoint.

connecting_span(other)[source]

Return the span that connects the two spans. Returns None.

Parameters

other (Span) –

Return type

Optional[Span]

Returns

consecutive(other)[source]

Returns True if other span is immediately consecutive with this span.

Return type

bool

contains_pos(pos)[source]

Checks if this span contains a specified position.

Parameters

pos (int) – index position

Return type

bool

Returns

bool

contains_span(other)[source]

Checks if this span encompasses another span.

Parameters

other (Span) – other span

Return type

bool

Returns

bool

property context_length

Return the length of the context.

property cyclic

Return whether the context is cyclic/circular.

differences(other)[source]

Return a tuple of differences between this span and the other span.

Return type

Union[Tuple[Span], Tuple[Span, Span]]

force_context(other)[source]

Raise error if another Span has different context.

Parameters

other (Span) – The other span

Return type

None

Returns

None

Raises

SpanError

get_slice(x, infer_type=False, as_type=None, summary_func=None, reduce_op=<built-in function add>)[source]

Use the region to slice the iterable, returning a iterable of the same type as ‘x’. If as_type is provided, the iterable will be typecast.

Parameters
  • x (List) – the iterable to slice

  • as_type (Optional[Any]) – type to convert the iterable into

  • summary_func (Optional[Callable]) – summary function that takes in an interable. If none, uses itertools.reduce(operator.add, arr)

Return type

Any

Returns

Any

get_slice_iter(x)[source]

Use the region to slice the iterable, returning another generator.

Parameters

x (List) – the iterable to slice

Returns

iterable

i(p)[source]

Find index of position.

Parameters

p (int) –

Return type

int

Returns

property index

Return the starting index of the context.

intersection(other)[source]

Return the span inersection between this span and the other span.

Return type

Span

invert()[source]

Invert the region, returning a tuple of the remaining spans from the context. If cyclic, a tuple (span, None) tuple is returned. If linear, a (span, span) is returned.

Returns

inverted regions

Return type

tuple

new(a, b, ignore_wrap=None, index=None, strict=None, abs_wrap=None)[source]

Create a new span using the same context.

Return type

Span

overlaps_with(other)[source]

Returns True if other span has an overlap with this span.

Parameters

other (Span) – The other span

Return type

bool

Returns

True if the two spans overlap.

ranges(ignore_wraps=False)[source]

Return the valid ranges for this span.

Parameters

ignore_wraps – if True, multiple wrappings will be ignored.

Return type

List[Tuple[int, int]]

Returns

List[Tuple[int, int]]

reindex(i, strict=None, ignore_wrap=None)[source]

Return a new span with positions reindexed.

Parameters
  • i – new index

  • strict – initialize with ‘strict’

  • ignore_wrap – whether to ignore wrapping indices

Returns

same_context(other)[source]

Return if another Span as an equivalent context.

Return type

bool

slices()[source]

Return list of slices.

Returns

Return type

sub(a, b)[source]

Create a sub region starting from a to b.

Parameters
  • a (int) – starting pos

  • b (int) – ending pos

Return type

Span

Returns

a new Span.

t(p, throw_error=True)[source]

Translates a position ‘p’ to an index within the context bounds.

Parameters
  • p (int) –

  • throw_error

Returns

Return type

exception dasi.utils.region.SpanError[source]

Bases: Exception

with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.