Tenncor
Classes | Typedefs | Functions | Variables
teq Namespace Reference

Classes

struct  CoordMap
 
struct  FuncArg
 Coordinate mapper and tensor pair. More...
 
struct  Functor
 Functor of the graph mapping to operators specified by opcode argument. More...
 
struct  GraphStat
 Traveler that maps each tensor to its subtree's maximum depth. More...
 
struct  HeightMatrix
 Leaves set and sets of functors ordered by height (by ascending order) More...
 
struct  iCoordMap
 Interface for transforming coordinates and reversing the coordinate. More...
 
struct  iData
 Interface for unveiling data. More...
 
struct  iFunctor
 Interface of iOperation-defined operation node. More...
 
struct  iGradientBuilder
 
struct  iLeaf
 Leaf of the graph commonly representing the variable in an equation. More...
 
struct  iOperableFunc
 A functor node with direct access to evaluated data. More...
 
struct  iTensor
 Interface of traversible and differentiable nodes with shape information. More...
 
struct  iTraveler
 Interface to travel through graph, treating iLeaf and iFunctor differently. More...
 
struct  OnceTraveler
 Extremely generic traveler that visits every node in the graph once. More...
 
struct  Opcode
 Encoding of operation. More...
 
struct  ParentFinder
 Traveler that for each child tracks the relationship to all parents. More...
 
struct  PathFinder
 
struct  Shape
 

Typedefs

using CoordptrT = std::shared_ptr< iCoordMap >
 Type of iCoordMap smartpointer. More...
 
using ArgsT = std::vector< FuncArg >
 Type of functor arguments. More...
 
using FuncptrT = std::shared_ptr< iFunctor >
 Functor smart pointer. More...
 
using LeafptrT = std::shared_ptr< iLeaf >
 Leaf smart pointer. More...
 
using TensptrT = std::shared_ptr< iTensor >
 Tensor smart pointer. More...
 
using TensrefT = std::weak_ptr< iTensor >
 Tensor weak pointers. More...
 
using TensT = std::vector< iTensor * >
 Vector of raw tensor pointers. More...
 
using TensptrsT = std::vector< TensptrT >
 Vector of tensor smart pointers. More...
 
using TensSetT = std::unordered_set< teq::iTensor * >
 Hash set of raw tensor pointers. More...
 
using TensptrSetT = std::unordered_set< teq::TensptrT >
 Hash set of tensor smart pointers. More...
 
using MatrixT = double[mat_dim][mat_dim]
 Coordinate transformation matrix (using homogeneous) More...
 
using RankT = uint8_t
 Type used for shape rank. More...
 
using DimT = uint16_t
 Type used for shape dimension. More...
 
using CDimT = double
 Type used for coordinate dimensions. More...
 
using NElemT = uint64_t
 
using ShapeT = std::array< DimT, rank_cap >
 Array type used to hold dimension info in Shape. More...
 
using CoordT = std::array< CDimT, rank_cap >
 
using ParentMapT = std::unordered_map< iTensor *, std::vector< size_t > >
 Map tensors to indices of children. More...
 
using OwnerMapT = std::unordered_map< iTensor *, TensrefT >
 Map between tensor and its corresponding smart pointer. More...
 

Functions

bool is_identity (iCoordMap *coorder)
 Checks if the coord mapper is an identity mapper. More...
 
CoordptrT reduce (RankT rank, std::vector< DimT > red)
 
CoordptrT extend (RankT rank, std::vector< DimT > ext)
 
CoordptrT permute (std::vector< RankT > order)
 
CoordptrT flip (RankT dim)
 
Shape apply_shaper (const CoordptrT &shaper, Shape inshape)
 
FuncArg identity_map (TensptrT tensor)
 Return FuncArg that identity maps input tensor. More...
 
FuncArg reduce_1d_map (TensptrT tensor, RankT rank)
 
FuncArg reduce_map (TensptrT tensor, RankT rank, std::vector< DimT > red)
 
FuncArg extend_map (TensptrT tensor, RankT rank, std::vector< DimT > ext)
 
FuncArg permute_map (TensptrT tensor, std::vector< RankT > order)
 
FuncArg flip_map (TensptrT tensor, RankT dim)
 Return FuncArg that flips input tensor along dimension. More...
 
ArgsT to_args (TensptrsT tens)
 Return ArgsT with each tensor in TensptrsT attached to identity mapper. More...
 
std::string to_string (const MatrixT &mat)
 Return the string representation of input matrix. More...
 
double determinant (const MatrixT &mat)
 Return the determinant of matrix. More...
 
void inverse (MatrixT out, const MatrixT &in)
 Inverse in matrix and dump to out matrix. More...
 
void matmul (MatrixT out, const MatrixT &lhs, const MatrixT &rhs)
 Apply matrix multiplication for lhs and rhs to out matrix. More...
 
NElemT index (Shape shape, CoordT coord)
 
CoordT coordinate (Shape shape, NElemT idx)
 
OwnerMapT track_owners (TensptrsT roots)
 

Variables

CoordptrT identity
 Identity matrix instance. More...
 
const RankT mat_dim = rank_cap + 1
 Number of rows and columns for the homogeneous matrix. More...
 
const size_t mat_size = sizeof(double) * mat_dim * mat_dim
 Number of bytes in a homogeneous matrix. More...
 
const RankT rank_cap = 8
 Number of dimsensions in a shape/coordinate. More...
 

Detailed Description

coord.hpp teq

Purpose: Define shape/coordinate transformation functions

funcarg.hpp teq

Purpose: Define functor argument wrapper to carryover shape and coordinate mappers

functor.hpp teq

Purpose: Define functor nodes of an equation graph

grad_def.hpp teq

Purpose: Define gradient builder interface for building derivatives

ileaf.hpp teq

Purpose: Define common interface for node unveiling data information

ileaf.hpp teq

Purpose: Define leafs for tensor equation graph

opfunc.hpp teq

Purpose: Define functor nodes directly hold/manipulate data This differs from Functor which should not directly manipulate data

itensor.hpp teq

Purpose: Define interfaces and building blocks for an equation graph

matops.hpp teq

Purpose: Define matrix operations for coordinate transformation This functions are here to avoid external dependencies in TEQ

shape.hpp teq

Purpose: Define shapes models and coordinate to flattened index mapping

traveler.hpp teq

Purpose: Define common traveler implementations

Typedef Documentation

◆ ArgsT

using teq::ArgsT = typedef std::vector<FuncArg>

Type of functor arguments.

◆ CDimT

using teq::CDimT = typedef double

Type used for coordinate dimensions.

◆ CoordptrT

using teq::CoordptrT = typedef std::shared_ptr<iCoordMap>

Type of iCoordMap smartpointer.

◆ CoordT

using teq::CoordT = typedef std::array<CDimT,rank_cap>

Array type used to hold dimension info when transforming coordinates Coordinates are allowed to be negative, negative dimensions are counted backward from the corresponding shape dimension For example, given shape=[5], coord=[-1] is the same as coord=[4]

◆ DimT

using teq::DimT = typedef uint16_t

Type used for shape dimension.

◆ FuncptrT

using teq::FuncptrT = typedef std::shared_ptr<iFunctor>

Functor smart pointer.

◆ LeafptrT

using teq::LeafptrT = typedef std::shared_ptr<iLeaf>

Leaf smart pointer.

◆ MatrixT

using teq::MatrixT = typedef double[mat_dim][mat_dim]

Coordinate transformation matrix (using homogeneous)

◆ NElemT

using teq::NElemT = typedef uint64_t

Type used for flattened index DimT having 8 bits and shape comprising of 8 DimT values means a maximum flattened index of (2 ^ 8) ^ 8 = 2 ^ 64

◆ OwnerMapT

using teq::OwnerMapT = typedef std::unordered_map<iTensor*,TensrefT>

Map between tensor and its corresponding smart pointer.

◆ ParentMapT

using teq::ParentMapT = typedef std::unordered_map<iTensor*,std::vector<size_t> >

Map tensors to indices of children.

◆ RankT

using teq::RankT = typedef uint8_t

Type used for shape rank.

◆ ShapeT

using teq::ShapeT = typedef std::array<DimT,rank_cap>

Array type used to hold dimension info in Shape.

◆ TensptrSetT

using teq::TensptrSetT = typedef std::unordered_set<teq::TensptrT>

Hash set of tensor smart pointers.

◆ TensptrsT

using teq::TensptrsT = typedef std::vector<TensptrT>

Vector of tensor smart pointers.

◆ TensptrT

using teq::TensptrT = typedef std::shared_ptr<iTensor>

Tensor smart pointer.

◆ TensrefT

using teq::TensrefT = typedef std::weak_ptr<iTensor>

Tensor weak pointers.

◆ TensSetT

using teq::TensSetT = typedef std::unordered_set<teq::iTensor*>

Hash set of raw tensor pointers.

◆ TensT

using teq::TensT = typedef std::vector<iTensor*>

Vector of raw tensor pointers.

Function Documentation

◆ apply_shaper()

Shape teq::apply_shaper ( const CoordptrT shaper,
Shape  inshape 
)

◆ coordinate()

CoordT teq::coordinate ( Shape  shape,
NElemT  idx 
)

Return the coordinate of a flat index according to shape Coordinate dimensions are 0-based For example [0, 0, ..., 0] <-> 0

◆ determinant()

double teq::determinant ( const MatrixT mat)

Return the determinant of matrix.

◆ extend()

CoordptrT teq::extend ( RankT  rank,
std::vector< DimT ext 
)

Return coordinate mapper multiplying dimensions after rank by values in ext vector For example, given coordinate [6, 6, 2, 2], rank=2, and ext=[3, 3], mapper forward transforms to coordinate [6, 6, 6, 6]

◆ extend_map()

FuncArg teq::extend_map ( TensptrT  tensor,
RankT  rank,
std::vector< DimT ext 
)

Return FuncArg that extends input tensor by rank and extension vector E.g.: tensor w/ shape [2, 1, 1], rank = 1, red = [3, 4] gets mapped to [2, 3, 4]

◆ flip()

CoordptrT teq::flip ( RankT  dim)

Return coordinate mapper flipping coordinate value at specified dimension Flipped dimension with original value x is represented as -x-1 (see CoordT definition)

◆ flip_map()

FuncArg teq::flip_map ( TensptrT  tensor,
RankT  dim 
)

Return FuncArg that flips input tensor along dimension.

◆ identity_map()

FuncArg teq::identity_map ( TensptrT  tensor)

Return FuncArg that identity maps input tensor.

◆ index()

NElemT teq::index ( Shape  shape,
CoordT  coord 
)

Return the flat index mapped by coord according to shape For example, 2-D tensor has indices in place of value as follows: [[0, 1, ..., n-1], [n, n+1, ..., 2*n-1]] The index follows the equation: index = coord[0]+coord[1]*shape[0]+... Invalid coordinate where the coordinate value is beyond the dimension for any index will report error

◆ inverse()

void teq::inverse ( MatrixT  out,
const MatrixT in 
)

Inverse in matrix and dump to out matrix.

◆ is_identity()

bool teq::is_identity ( iCoordMap coorder)

Checks if the coord mapper is an identity mapper.

◆ matmul()

void teq::matmul ( MatrixT  out,
const MatrixT lhs,
const MatrixT rhs 
)

Apply matrix multiplication for lhs and rhs to out matrix.

◆ permute()

CoordptrT teq::permute ( std::vector< RankT order)

Return coordinate mapper permuting coordinate according to input order Order is a vector of indices of the dimensions to appear in order Indices not referenced by order but less than rank_cap will be appended by numerical order For example, given coordinate [1, 2, 3, 4], order=[1, 3], mapper forward transforms to coordinate [2, 4, 1, 3] Returned coordinate mapper will be a CoordMap instance, so inversibility requires order indices be unique, otherwise throw fatal error

◆ permute_map()

FuncArg teq::permute_map ( TensptrT  tensor,
std::vector< RankT order 
)

Return FuncArg that permutes input tensor by order E.g.: tensor w/ shape [2, 3, 4], order = [1, 2, 0] gets mapped to [3, 4, 2]

◆ reduce()

CoordptrT teq::reduce ( RankT  rank,
std::vector< DimT red 
)

Return coordinate mapper dividing dimensions after rank by values in red vector For example, given coordinate [2, 2, 6, 6], rank=2, and red=[3, 3], mapper forward transforms to coordinate [2, 2, 2, 2]

◆ reduce_1d_map()

FuncArg teq::reduce_1d_map ( TensptrT  tensor,
RankT  rank 
)

Return FuncArg that reduces input tensor at rank then snip the dimension at rank E.g.: tensor w/ shape [2, 3, 4], rank = 1 gets mapped to [2, 4]

◆ reduce_map()

FuncArg teq::reduce_map ( TensptrT  tensor,
RankT  rank,
std::vector< DimT red 
)

Return FuncArg that reduces input tensor by units in reduction vector after specified rank E.g.: tensor w/ shape [2, 3, 4], rank = 0, red = [2, 3] gets mapped to [1, 1, 4]

◆ to_args()

ArgsT teq::to_args ( TensptrsT  tens)

Return ArgsT with each tensor in TensptrsT attached to identity mapper.

◆ to_string()

std::string teq::to_string ( const MatrixT mat)

Return the string representation of input matrix.

◆ track_owners()

OwnerMapT teq::track_owners ( TensptrsT  roots)

Travelers will lose smart pointer references, This utility function will grab reference maps of root's subtree

Variable Documentation

◆ identity

CoordptrT teq::identity

Identity matrix instance.

◆ mat_dim

const RankT teq::mat_dim = rank_cap + 1

Number of rows and columns for the homogeneous matrix.

◆ mat_size

const size_t teq::mat_size = sizeof(double) * mat_dim * mat_dim

Number of bytes in a homogeneous matrix.

◆ rank_cap

const RankT teq::rank_cap = 8

Number of dimsensions in a shape/coordinate.