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

Abstraction of dimensionality? #75

Closed srush closed 5 years ago

srush commented 5 years ago

I was curious for the numpy part of the library if you had considered anything like abstracting over lists of dimensions?

Would love to be able to write something like 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]
    '''
srush commented 5 years ago

Oops, I found it.