Esempio n. 1
0
def samples_to_broadcast(fixture_sizes, fixture_shapes):
    samples = [np.empty(s) for s in fixture_shapes]
    try:
        broadcast_shape = broadcast_dist_samples_shape(fixture_shapes,
                                                       size=fixture_sizes)
    except ValueError:
        broadcast_shape = None
    return fixture_sizes, samples, broadcast_shape
Esempio n. 2
0
def samples_to_broadcast_to(request, samples_to_broadcast):
    to_shape = request.param
    size, samples, broadcast_shape = samples_to_broadcast
    if broadcast_shape is not None:
        try:
            broadcast_shape = broadcast_dist_samples_shape(
                [broadcast_shape, to_tuple(to_shape)], size=size)
        except ValueError:
            broadcast_shape = None
    return to_shape, size, samples, broadcast_shape
Esempio n. 3
0
 def test_broadcast_dist_samples_shape(self, fixture_sizes, fixture_shapes):
     size = fixture_sizes
     shapes = fixture_shapes
     size_ = to_tuple(size)
     shapes_ = [
         s if s[:min([len(size_), len(s)])] != size_ else s[len(size_):]
         for s in shapes
     ]
     try:
         expected_out = np.broadcast(*(np.empty(s) for s in shapes_)).shape
     except ValueError:
         expected_out = None
     if expected_out is not None and any(
             s[:min([len(size_), len(s)])] == size_ for s in shapes):
         expected_out = size_ + expected_out
     if expected_out is None:
         with pytest.raises(ValueError):
             broadcast_dist_samples_shape(shapes, size=size)
     else:
         out = broadcast_dist_samples_shape(shapes, size=size)
         assert out == expected_out