Assert tensor shapes and dimension size relationships between tensors.

This Op checks that a collection of tensors shape relationships satisfies given constraints.


n = 10
q = 3
d = 7
x = tf.zeros([n,q])
y = tf.ones([n,d])
param = tf.Variable([1.0, 2.0, 3.0])
scalar = 1.0
 (x, ('N', 'Q')),
 (y, ('N', 'D')),
 (param, ('Q',)),
 (scalar, ()),
  (x, ('N', 'D')),
  (y, ('N', 'D'))
Traceback (most recent call last):

ValueError: ...

If x, y, param or scalar does not have a shape that satisfies all specified constraints, message, as well as the first summarize entries of the first encountered violating tensor are printed, and InvalidArgumentError is raised.

Size entries in the specified shapes are checked against other entries by their hash, except:

  • a size entry is interpreted as an explicit size if it can be parsed as an integer primitive.
  • a size entry is interpreted as any size if it is None or '.'.

If the first entry of a shape is ... (type Ellipsis) or '*' that indicates a variable number of outer dimensions of unspecified size, i.e. the constraint applies to the inner-most dimensions only.

Scalar tensors and specified shapes of length zero (excluding the 'inner-most' prefix) are both treated as having a single dimension of size one.

shapes dictionary with (Tensor to shape) items, or a list of (Tensor, shape) tuples. A shape must be an iterable.