Beispiel #1
0
    def test_has_ellipsis(self):
        msg = ""
        fail = False
        ds_pos = [
            dshape("... * float32"),
            dshape("A... * float32"),
            dshape("var * ... * float32"),
            dshape("(int32, M... * int16) -> var * int8"),
            dshape("(int32, var * int16) -> ... * int8"),
            dshape("10 * { f0: int32, f1: A... * float32 }"),
            dshape("{ f0 : { g0 : ... * int }, f1: int32 }"),
            (dshape("... * int32"),),
        ]
        ds_false_negatives = list(filter(lambda ds: not has_ellipsis(ds), ds_pos))
        if len(ds_false_negatives) != 0:
            fail = True
            msg += "The following dshapes should have an ellipsis\n  %s\n" % "\n  ".join(map(str, ds_false_negatives))
        ds_neg = [
            dshape("float32"),
            dshape("10 * var * float32"),
            dshape("M * float32"),
            dshape("(int32, M * int16) -> var * int8"),
            dshape("(int32, int16) -> var * int8"),
            dshape("10 * { f0: int32, f1: 10 * float32 }"),
            dshape("{ f0 : { g0 : 2 * int }, f1: int32 }"),
            (dshape("M * int32"),),
        ]
        ds_false_positives = list(filter(has_ellipsis, ds_neg))
        if len(ds_false_positives) != 0:
            fail = True
            msg += "The following dshapes should not have an ellipsis\n  %s \n" % "\n  ".join(
                map(str, ds_false_positives)
            )

        self.assertFalse(fail, msg)
Beispiel #2
0
def _add_elementwise_dims_to_sig(sig, typevarname):
    sig = _normalized_sig(sig)
    # Process the signature to add 'Dims... *' broadcasting
    if datashape.has_ellipsis(sig):
        raise TypeError(('Signature provided to ElementwiseBlazeFunc' +
                         'already includes ellipsis: %s') % sig)
    dims = coretypes.Ellipsis(coretypes.TypeVar(typevarname))
    params = [_prepend_to_ds(param, dims)
              for param in sig.parameters]
    return coretypes.Function(*params)
Beispiel #3
0
 def add_overload(self, sig, ck, associative, commutative, identity=None):
     sig = _normalized_sig(sig)
     if datashape.has_ellipsis(sig):
         raise TypeError(('Signature provided to ReductionBlazeFunc' +
                          'already includes ellipsis: %s') % sig)
     if len(sig.argtypes) != 1:
         raise TypeError(('Signature provided to ReductionBlazeFunc' +
                          'must have only one argument: %s') % sig)
     # Prepend 'DimsIn... *' to the args, and 'DimsOut... *' to
     # the return type
     sig = coretypes.Function(_prepend_to_ds(sig.argtypes[0],
                                             coretypes.Ellipsis(coretypes.TypeVar('DimsIn'))),
                              _prepend_to_ds(sig.restype,
                                             coretypes.Ellipsis(coretypes.TypeVar('DimsOut'))))
     # TODO: This probably should be an object instead of a dict
     info = {'tag': 'reduction',
             'ckernel': ck,
             'assoc': associative,
             'comm': commutative,
             'ident': identity}
     BlazeFunc.add_overload(self, sig, info)
Beispiel #4
0
    def test_has_ellipsis(self):
        msg = ""
        fail = False
        ds_pos = [
            dshape("... * float32"),
            dshape("A... * float32"),
            dshape("var * ... * float32"),
            dshape("(int32, M... * int16) -> var * int8"),
            dshape("(int32, var * int16) -> ... * int8"),
            dshape("10 * { f0: int32, f1: A... * float32 }"),
            dshape("{ f0 : { g0 : ... * int }, f1: int32 }"),
            (dshape("... * int32"), ),
        ]
        ds_false_negatives = list(
            filter(lambda ds: not has_ellipsis(ds), ds_pos))
        if len(ds_false_negatives) != 0:
            fail = True
            msg += "The following dshapes should have an ellipsis\n  %s\n" \
                   % "\n  ".join(map(str, ds_false_negatives))
        ds_neg = [
            dshape("float32"),
            dshape("10 * var * float32"),
            dshape("M * float32"),
            dshape("(int32, M * int16) -> var * int8"),
            dshape("(int32, int16) -> var * int8"),
            dshape("10 * { f0: int32, f1: 10 * float32 }"),
            dshape("{ f0 : { g0 : 2 * int }, f1: int32 }"),
            (dshape("M * int32"), ),
        ]
        ds_false_positives = list(filter(has_ellipsis, ds_neg))
        if len(ds_false_positives) != 0:
            fail = True
            msg += "The following dshapes should not have an ellipsis\n  %s \n" \
                   % "\n  ".join(map(str, ds_false_positives))

        self.assertFalse(fail, msg)
Beispiel #5
0
def test_not_has_ellipsis(ds):
    assert not has_ellipsis(ds)
Beispiel #6
0
def test_has_ellipsis(ds):
    assert has_ellipsis(ds)
Beispiel #7
0
def test_not_has_ellipsis(ds):
    assert not has_ellipsis(ds)
Beispiel #8
0
def test_has_ellipsis(ds):
    assert has_ellipsis(ds)