Tannic
A C++ Tensor Library
Loading...
Searching...
No Matches
tannic Namespace Reference

Namespaces

namespace  expression
 
namespace  function
 
namespace  indexing
 
namespace  operation
 
namespace  transformation
 

Classes

class  Buffer
 Managed memory buffer with explicit ownership. More...
 
class  Callback
 
class  Device
 Device memory domain. More...
 
class  Devices
 Device enumeration singleton. More...
 
class  Exception
 A simple generic exception type for the Tannic Tensor Library. More...
 
struct  Header
 
class  Host
 Host memory domain. More...
 
struct  Metadata
 
struct  Metadata< Tensor >
 
struct  Node
 
class  Shape
 Represents the shape (dimensions) of an tensor-like expression. More...
 
class  Strides
 Represents the memory strides associated with a tensor shape. More...
 
class  Tensor
 A multidimensional, strided tensor data structure. More...
 
struct  Trait
 

Concepts

concept  Expression
 Defines the core protocol for all expression-like types in the Tannic Tensor Library.
 
concept  Operator
 Concept defining requirements for tensor operation types.
 
concept  Functional
 Concept for unary mathematical function operations.
 
concept  Iterable
 Requires a type to be iterable via std::begin and std::end.
 
concept  Iterator
 Requires a type to satisfy the C++20 std::input_iterator concept.
 
concept  Integral
 Requires a type to be an integral type (e.g., int, std::size_t).
 
concept  Assignable
 Concept for types that can assign values.
 
concept  Comparable
 Concept for types that can compare their value.
 

Typedefs

using range = indexing::Range
 Convenience alias for tannic::indexing::Range.
 
using Environment = std::variant< Host, Device >
 Memory environment variant type.
 

Functions

Header headerof (Tensor const &tensor)
 
Metadata< Tensormetadataof (Tensor const &tensor)
 
constexpr bool operator== (Shape const &first, Shape const &second)
 Equality comparison operator for shapes.
 
std::ostream & operator<< (std::ostream &os, Shape const &shape)
 
constexpr bool operator== (Strides const &first, Strides const &second)
 Equality comparison for strides.
 
std::ostream & operator<< (std::ostream &os, Strides const &strides)
 
std::ostream & operator<< (std::ostream &ostream, Tensor const &tensor)
 
template<Expression Source>
std::ostream & operator<< (std::ostream &ostream, Source source)
 
template<Expression Multiplicand, Expression Multiplier>
constexpr auto matmul (Multiplicand &&multiplicand, Multiplier &&multiplier, double scale=1.0)
 Matrix multiplication convenience function.
 
constexpr std::size_t dsizeof (type type)
 Returns the size in bytes of a given tensor data type.
 
constexpr std::size_t nbytesof (type dtype, std::size_t nelements)
 Returns the total number of bytes required to store nelements elements of the given data type.
 
constexpr std::string dnameof (type type)
 Returns the string name of a given tensor data type.
 
constexpr uint8_t dcodeof (type type)
 Returns the numeric code used for serialization of a data type.
 
constexpr type dtypeof (uint8_t code)
 Converts a numeric type code back to its corresponding type enum.
 
template<typename T >
constexpr type dtypeof ()
 
std::ostream & operator<< (std::ostream &ostream, type type)
 

Variables

constexpr uint32_t MAGIC = 0x43495245
 

Typedef Documentation

◆ Environment

using tannic::Environment = typedef std::variant<Host, Device>

Memory environment variant type.

Type-safe union of host and device memory environments.

◆ range

Convenience alias for tannic::indexing::Range.

This alias allows using tannic::range directly when declaring slices without fully qualifying the indexing::Range type.

Function Documentation

◆ dcodeof()

constexpr uint8_t tannic::dcodeof ( type  type)
inlineconstexpr

Returns the numeric code used for serialization of a data type.

Parameters
typeThe data type to query
Returns
Unique numeric code (0 for none)
Note
Code values follow simple pattern:
  • Integers: 10-19 (integer dtypes)
  • Floats: 20-29 (floating point dtypes)
  • Complex: 30-39 (complex)

While this grouping is intentional, it's not strictly enforced. When adding new types:

  1. Maintain this pattern where possible
  2. Document any deviations
  3. Keep codes unique across all types

◆ dnameof()

constexpr std::string tannic::dnameof ( type  type)
inlineconstexpr

Returns the string name of a given tensor data type.

Parameters
typeThe data type to query
Returns
Human-readable type name ("none" for invalid types)

Example:

std::cout << dnameof(int32) << std::endl // prints "int32"
std::cout << dnameof(complex128); // prints "complex128"
constexpr std::string dnameof(type type)
Returns the string name of a given tensor data type.
Definition: types.hpp:146

◆ dsizeof()

constexpr std::size_t tannic::dsizeof ( type  type)
inlineconstexpr

Returns the size in bytes of a given tensor data type.

Parameters
typeThe data type to query
Returns
Size of the type in bytes (0 for none)
Note
  • boolean is stored as bit-packed (1 bit per element). Since the size is less than one byte, this function returns 0. To compute the actual storage requirement for N elements, use (N + 7) / 8 bytes.
  • complex64 returns 8 (2 × float32).
  • complex128 returns 16 (2 × float64).

Example:

dsizeof(float32); // returns 4
dsizeof(complex64); // returns 8
constexpr std::size_t dsizeof(type type)
Returns the size in bytes of a given tensor data type.
Definition: types.hpp:93

◆ dtypeof() [1/2]

template<typename T >
constexpr type tannic::dtypeof ( )
inlineconstexpr

◆ dtypeof() [2/2]

constexpr type tannic::dtypeof ( uint8_t  code)
inlineconstexpr

Converts a numeric type code back to its corresponding type enum.

Used for deserialization.

Parameters
codeThe numeric type code to convert (as returned by dcodeof())
Returns
Corresponding type enum value (none for invalid codes)
Note
This is the inverse operation of dcodeof(). The code values follow the same pattern.
See also
dcodeof() for the reverse conversion

◆ headerof()

Header tannic::headerof ( Tensor const &  tensor)
inline

◆ matmul()

template<Expression Multiplicand, Expression Multiplier>
constexpr auto tannic::matmul ( Multiplicand &&  multiplicand,
Multiplier &&  multiplier,
double  scale = 1.0 
)
constexpr

Matrix multiplication convenience function.

Template Parameters
MultiplicandLeft tensor expression type
MultiplierRight tensor expression type
Parameters
multiplicandLeft tensor operand
multiplierRight tensor operand
Returns
Transformation expression representing matrix multiplication

◆ metadataof()

Metadata< Tensor > tannic::metadataof ( Tensor const &  tensor)
inline

◆ nbytesof()

constexpr std::size_t tannic::nbytesof ( type  dtype,
std::size_t  nelements 
)
inlineconstexpr

Returns the total number of bytes required to store nelements elements of the given data type.

Parameters
typeThe data type.
nelementsNumber of elements.
Returns
Total size in bytes required.
Note
  • For boolean, storage is bit-packed. The result is (nelements + 7) / 8.
  • For all other types, result is dsizeof(type) * nelements.

Example:

nbytesof(float32, 10); // returns 40
nbytesof(complex64, 5); // returns 40
nbytesof(boolean, 100); // returns 13
constexpr std::size_t nbytesof(type dtype, std::size_t nelements)
Returns the total number of bytes required to store nelements elements of the given data type.
Definition: types.hpp:127

◆ operator<<() [1/5]

std::ostream & tannic::operator<< ( std::ostream &  os,
Shape const &  shape 
)
inline

◆ operator<<() [2/5]

std::ostream & tannic::operator<< ( std::ostream &  os,
Strides const &  strides 
)
inline

◆ operator<<() [3/5]

template<Expression Source>
std::ostream & tannic::operator<< ( std::ostream &  ostream,
Source  source 
)
inline

◆ operator<<() [4/5]

std::ostream & tannic::operator<< ( std::ostream &  ostream,
Tensor const &  tensor 
)

◆ operator<<() [5/5]

std::ostream & tannic::operator<< ( std::ostream &  ostream,
type  type 
)
inline

◆ operator==() [1/2]

constexpr bool tannic::operator== ( Shape const &  first,
Shape const &  second 
)
constexpr

Equality comparison operator for shapes.

Parameters
firstFirst shape.
secondSecond shape.
Returns
True if both shapes have the same rank and sizes, false otherwise.

◆ operator==() [2/2]

constexpr bool tannic::operator== ( Strides const &  first,
Strides const &  second 
)
constexpr

Equality comparison for strides.

Returns
True if all stride sizes are equal for each dimension.

Variable Documentation

◆ MAGIC

constexpr uint32_t tannic::MAGIC = 0x43495245
constexpr