Annex v0.2.0 Annex.Shape View Source

The Shape module encapsulates helper functions for use in determining the shapes and validity of shapes between Layers and Layers; Data and Data; and Data and Layers.

Link to this section Summary

Functions

Given a valid shape checks the content of the shape to determine whether the shape is a :concrete kind or an :abstract kind of shape.

Returns the product of a concrete shape. Given an abstract shape product/1 will raise an ArithmeticError. The closest related function to product/1 is factor/1. If you need the product of the integers without the :any in the shape use factor/2.

Link to this section Types

Link to this type

abstract() View Source
abstract() :: [abstract_dimension(), ...]

Link to this type

abstract_dimension() View Source
abstract_dimension() :: concrete_dimension() | shape_any()

Link to this type

concrete() View Source
concrete() :: [concrete_dimension(), ...]

Link to this type

concrete_dimension() View Source
concrete_dimension() :: pos_integer()

Link to this type

shape_any() View Source
shape_any() :: :any

Link to this section Functions

Link to this function

convert_abstract_to_concrete(abstract, concrete) View Source
convert_abstract_to_concrete(abstract(), concrete()) :: concrete() | no_return()

Link to this function

is_factor_of?(num, factor) View Source
is_factor_of?(integer() | t(), integer()) :: boolean()

Link to this function

is_shape?(shape) View Source
is_shape?(any()) :: boolean()

Link to this function

is_shape_value?(n) View Source
is_shape_value?(any()) :: boolean()

Link to this function

kind(shape) View Source
kind(t()) :: :abstract | :concrete

Given a valid shape checks the content of the shape to determine whether the shape is a :concrete kind or an :abstract kind of shape.

A :concrete shape contains only positive integers and represents a known, exact shape. For example, the shape [3, 4] represents a two dimensional matrix that has 3 rows and 4 columns. Data always has a :concrete shape; the elements of a Data can be counted.

An :abstract shape contains both positive integers and/or :any. An :abstract shape represents a partially unknown shape. For example, the shape [3, :any] represents a two dimensional shape that has 3 rows and any positive integer n number of columns.

Some operations on Data can express shape requirements in an :abstract way.

The :abstract shape idea is particularly useful for describing the possible valid shapes for casting data for a shaped Layer. For example, during feedfoward a Dense layer requires that input has the same number of rows as the Dense layer has columns so that it can perform a matrix dot operation. For a Dense layer with 2 rows and 3 columns the shape it demands for casting would be [3, :any].

Returns the product of a concrete shape. Given an abstract shape product/1 will raise an ArithmeticError. The closest related function to product/1 is factor/1. If you need the product of the integers without the :any in the shape use factor/2.

For more info about concrete vs abstract shapes see Shape.kind/1.