AndreaCensi / contracts

PyContracts is a Python package that allows to declare constraints on function parameters and return values. Contracts can be specified using Python3 annotations, or inside a docstring. PyContracts supports a basic type system, variables binding, arithmetic constraints, and has several specialized contracts and an extension API.
http://andreacensi.github.io/contracts/
Other
398 stars 62 forks source link

Front ... for dimensionality #76

Open srush opened 5 years ago

srush commented 5 years ago

It is often convention to have the fixed dimensions in a numpy array be leading dimensions. However it seems like this syntax is not supported. Would it be possible to do this?

@contract
def batch_matrix_multiply(a,  b):
    ''' Multiplies two batches fo matrices together.

        :param a: The first tensor, must end in MxN.
         :type a: array[...xMxN],M>0,N>0

        :param b: The second tensor, must end in NxP
         :type b: array[...xNxP],P>0

          :rtype: array[...xMxP]
    '''