Esempio n. 1
0
def test_check_broadcast():
    assert misc.check_broadcast((10, 1), (3,)) == (10, 3)
    assert misc.check_broadcast((10, 1), (3,), (4, 1, 1, 3)) == (4, 1, 10, 3)
    with pytest.raises(ValueError):
        misc.check_broadcast((10, 2), (3,))

    with pytest.raises(ValueError):
        misc.check_broadcast((10, 1), (3,), (4, 1, 2, 3))
Esempio n. 2
0
def test_check_broadcast():
    assert misc.check_broadcast((10, 1), (3,)) == (10, 3)
    assert misc.check_broadcast((10, 1), (3,), (4, 1, 1, 3)) == (4, 1, 10, 3)
    with pytest.raises(ValueError):
        misc.check_broadcast((10, 2), (3,))

    with pytest.raises(ValueError):
        misc.check_broadcast((10, 1), (3,), (4, 1, 2, 3))
Esempio n. 3
0
    def prepare_arrays(self):
        """Make sure input arrays are all C-contiguous and have same shape."""
        self.max_shape = None
        for arr in self.arrs:
            if self.max_shape is None:
                self.max_shape = arr.shape
            elif arr.shape > self.max_shape:
                self.max_shape = arr.shape

        orig_shapes = []
        arrs_1d = []
        for arr in self.arrs:
            orig_shapes.append(arr.shape)
            arr = np.broadcast_to(arr, self.max_shape).ravel()
            arrs_1d.append(np.ascontiguousarray(arr.astype(np.float64)))

        if not check_broadcast(orig_shapes):
            raise ValueError(
                "Shapes are not broadcastable: {0}".format(orig_shapes))

        return arrs_1d