Exemple #1
0
    def test_concatenate(self):
        n_dim = numpy.random.randint(2, 5)
        data_shape = numpy.random.randint(1, 10, (n_dim))
        n_bps = numpy.random.randint(2, 5)
        axis = numpy.random.randint(n_dim-1)

        bps = [BootPack.random(data_shape) for i in range(n_bps)]

        assert numpy.all(
            BootPack(
                numpy.concatenate(tuple(bp.true for bp in bps), axis=axis),
                numpy.concatenate(tuple(bp.boot for bp in bps), axis=axis)) ==
            BootPack.concatenate(bps, axis=axis))
Exemple #2
0
    def test_arithmetic(self):
        n_tests = 100
        max_dim = 5
        max_len = 10
        ops = [
            operator.abs,
            operator.neg,
            lambda x: x.real,
            lambda x: x.imag,
            ]
        binops = [
            operator.add,
            operator.sub,
            operator.mul,
            operator.div,
            operator.pow,
            ]
        rbinops = [
            operator.add,
            operator.sub,
            operator.mul,
            operator.div,
            ]

        for _ in range(n_tests):
            n_dim = numpy.random.randint(1, max_dim)
            data_shape = numpy.random.randint(1, max_len, (n_dim))

            a = BootPack.random(data_shape)
            b = BootPack.random(data_shape)

            c = numpy.random.random()

            for binop in binops:
                assert numpy.all(
                    BootPack(binop(a.true, b.true), binop(a.boot, b.boot))
                    == binop(a, b))
                assert numpy.all(
                    BootPack(binop(a.true, c), binop(a.boot, c))
                    == binop(a, c))

            for rbinop in rbinops:
                assert numpy.all(
                    BootPack(rbinop(b.true, a.true), rbinop(b.boot, a.boot))
                    == rbinop(b, a))
                assert numpy.all(
                    BootPack(rbinop(c, a.true), rbinop(c, a.boot))
                    == rbinop(c, a))

            for op in ops:
                assert numpy.all(BootPack(op(a.true), op(a.boot)) == op(a))