MimIR
MimIR is my Intermediate Representation
Loading...
Searching...
No Matches
mim::Shape Class Reference

The extents of a Seq's axes: a plain Nat for a single axis, an aggregate of them for several. More...

#include <mim/tuple.h>

Public Member Functions

constexpr Shape () noexcept=default
constexpr Shape (const Def *def) noexcept
 Shape (World &, Defs shape)
Getters
constexpr const Def * operator* () const noexcept
constexpr const Def * operator-> () const noexcept
constexpr operator bool () const noexcept
Transform

Each of these needs Shape::rank and yields a null Shape without it.

Shape slice (nat_t begin, nat_t end) const
 The axes [begin, end).
Shape take (nat_t n) const
 The leading n axes.
Shape drop (nat_t n) const
 All but the leading n axes.
Shape operator+ (Shape) const
 Concatenation - what fuses «a; «b; T»» into «a, b; T».
Shape zonk () const
 Wraps Def::zonk();.
Shape filter (auto keep) const
 This Shape with only the axes keep accepts; *this, if it accepts all of them or the rank is dynamic.
Shape fold () const
 Drops every literal size-1 axis, mirroring «1; T» ≡ T; all of them folded away leaves rank 0.
Shape fold (Shape shape) const
 As above but driven by shape: drops the axes it has as literal 1, whatever this one's own extents are - a broadcast reads a size-1 input axis at the output's loop index.

Static Public Member Functions

Type Checking
static bool isa_extents (const Def *)
 Is type Nat - or an aggregate of Nats, i.e. a shape?
static bool isa_indices (const Def *)
 Is type Idx - or an aggregate of Idxs, i.e. a fused index?

Axes

bool is_dim () const
 Is this a single axis - a Nat/Idx rather than an aggregate of them?
bool is_fused () const
 Does this span several axes? Also true for a dynamic rank.
std::optional< nat_t > rank () const
 Number of axes; std::nullopt if not statically known.
const Def * operator[] (nat_t i) const
 The i th axis.
const Def * front () const
 The outermost axis - the Def::arity of the Seq this shape describes; null for a null Shape.
static std::optional< nat_t > extent (const Def *axis)
 The extent of axis: the axis itself for a shape, its Idx size for an index.

Detailed Description

The extents of a Seq's axes: a plain Nat for a single axis, an aggregate of them for several.

A multi-dimensional index into a Seq has the very same structure - one component per axis, Idx instead of Nat - so it uses this view as well.

Note
A Shape is a non-owning view over a Def and may be null; Shape::operator* hands the Def back.

Definition at line 194 of file tuple.h.

Constructor & Destructor Documentation

◆ Shape() [1/3]

◆ Shape() [2/3]

mim::Shape::Shape ( const Def * def)
inlineconstexprnoexcept

Definition at line 197 of file tuple.h.

References Shape().

◆ Shape() [3/3]

mim::Shape::Shape ( World & w,
Defs shape )

Definition at line 13 of file tuple.cpp.

References Shape().

Member Function Documentation

◆ drop()

Shape mim::Shape::drop ( nat_t n) const

All but the leading n axes.

Definition at line 61 of file tuple.cpp.

References rank(), Shape(), and slice().

◆ extent()

std::optional< nat_t > mim::Shape::extent ( const Def * axis)
static

The extent of axis: the axis itself for a shape, its Idx size for an index.

Definition at line 33 of file tuple.cpp.

References mim::Idx::isa(), mim::Lit::isa(), and mim::Def::unfold_type().

Referenced by fold(), fold(), and mim::World::seq().

◆ filter()

Shape mim::Shape::filter ( auto keep) const
inline

This Shape with only the axes keep accepts; *this, if it accepts all of them or the rank is dynamic.

Definition at line 242 of file tuple.h.

References rank(), and Shape().

Referenced by fold(), and fold().

◆ fold() [1/2]

Shape mim::Shape::fold ( ) const

Drops every literal size-1 axis, mirroring «1; T» ≡ T; all of them folded away leaves rank 0.

Definition at line 71 of file tuple.cpp.

References extent(), filter(), is_dim(), and Shape().

◆ fold() [2/2]

Shape mim::Shape::fold ( Shape shape) const

As above but driven by shape: drops the axes it has as literal 1, whatever this one's own extents are - a broadcast reads a size-1 input axis at the output's loop index.

Definition at line 76 of file tuple.cpp.

References extent(), filter(), rank(), and Shape().

◆ front()

const Def * mim::Shape::front ( ) const

The outermost axis - the Def::arity of the Seq this shape describes; null for a null Shape.

Definition at line 25 of file tuple.cpp.

References is_dim(), mim::Def::proj(), and rank().

◆ is_dim()

bool mim::Shape::is_dim ( ) const

Is this a single axis - a Nat/Idx rather than an aggregate of them?

Definition at line 16 of file tuple.cpp.

References mim::Idx::isa().

Referenced by fold(), front(), and is_fused().

◆ is_fused()

bool mim::Shape::is_fused ( ) const
inline

Does this span several axes? Also true for a dynamic rank.

Definition at line 211 of file tuple.h.

References is_dim().

Referenced by mim::Seq::elem(), mim::plug::ll::is_simd(), and mim::Rewriter::rewrite_mut_Seq().

◆ isa_extents()

bool mim::Shape::isa_extents ( const Def * type)
static

Is type Nat - or an aggregate of Nats, i.e. a shape?

Definition at line 46 of file tuple.cpp.

References mim::isa_axes().

Referenced by mim::World::seq().

◆ isa_indices()

bool mim::Shape::isa_indices ( const Def * type)
static

Is type Idx - or an aggregate of Idxs, i.e. a fused index?

Definition at line 50 of file tuple.cpp.

References mim::Idx::isa(), and mim::isa_axes().

◆ operator bool()

mim::Shape::operator bool ( ) const
inlineexplicitconstexprnoexcept

Definition at line 205 of file tuple.h.

◆ operator*()

const Def * mim::Shape::operator* ( ) const
inlineconstexprnoexcept

Definition at line 203 of file tuple.h.

◆ operator+()

Shape mim::Shape::operator+ ( Shape other) const

Concatenation - what fuses «a; «b; T»» into «a, b; T».

Definition at line 66 of file tuple.cpp.

References mim::Tuple::cat(), and Shape().

◆ operator->()

const Def * mim::Shape::operator-> ( ) const
inlineconstexprnoexcept

Definition at line 204 of file tuple.h.

◆ operator[]()

const Def * mim::Shape::operator[] ( nat_t i) const
inline

The i th axis.

Note
Needs Shape::rank: Def::num_projs would silently read a dynamic rank as 1 and hand back the Shape.

Definition at line 215 of file tuple.h.

References rank().

◆ rank()

std::optional< nat_t > mim::Shape::rank ( ) const

Number of axes; std::nullopt if not statically known.

Definition at line 23 of file tuple.cpp.

References mim::Lit::isa().

Referenced by drop(), filter(), fold(), front(), operator[](), and slice().

◆ slice()

Shape mim::Shape::slice ( nat_t begin,
nat_t end ) const

The axes [begin, end).

Definition at line 54 of file tuple.cpp.

References rank(), and Shape().

Referenced by drop(), and take().

◆ take()

Shape mim::Shape::take ( nat_t n) const
inline

The leading n axes.

Definition at line 236 of file tuple.h.

References Shape(), and slice().

◆ zonk()

Shape mim::Shape::zonk ( ) const
inline

Wraps Def::zonk();.

Definition at line 239 of file tuple.h.

References Shape().


The documentation for this class was generated from the following files: