TensorSpecification

class samplomatic.tensor_interface.TensorSpecification(name: str, shape: tuple[int | str, ...], dtype: dtype, description: str = '', broadcastable: bool = False, optional: bool = False)[source]

Bases: Specification[ndarray]

A specification for tensor-valued interface values of a specific type and shape.

Parameters:
  • name – The name of the interface.

  • shape – The shape of the input array.

  • dtype – The data type of the array.

  • description – A description of what the interface represents.

  • broadcastable – Whether values in an interface that are constrained by this specification are allowed to be broadcastable with other broadcastable values in the same interface.

  • optional – Whether the specification is optional.

Attributes Summary

description

A description of this specification.

free_dimensions

Named dimensions whose sizes are free until an interface value binds their value.

name

The name of this specification.

ndim

The number of dimensions, i.e. the length of shape.

optional

Whether this is an optional specification.

Methods Summary

describe()

Return a human-readable description of this specification.

validate_and_coerce(value)

Coerce a value into a correct type if valid.

Attributes Documentation

description
free_dimensions
name
ndim

The number of dimensions, i.e. the length of shape.

optional

Methods Documentation

describe() str[source]

Return a human-readable description of this specification.

validate_and_coerce(value)[source]

Coerce a value into a correct type if valid.

Parameters:

value – A value to validate and coerce with respect to this specification.

Raises:

TypeError – If the value cannot be coerced into a valid type.

Returns:

The coerced value, and a dictionary mapping each member of free_dimensions to a size implied by the value.