Example #1
0
def test_broadcast_to(test_case):
    src_shape, dst_shape = test_case

    # numpy results
    x_np = np.array(np.random.rand(*src_shape))
    f_np = x_np + np.zeros(dst_shape)

    # ngraph results
    x_ng = ng.constant(x_np, axes=make_pos_axes(x_np.shape))
    f_ng = broadcast_to(x_ng, dst_shape)

    with ExecutorFactory() as ex:
        f_ng_comp = ex.transformer.computation(f_ng)
        f_ng_val = f_ng_comp()
        np.testing.assert_allclose(f_ng_val, f_np)
Example #2
0
def _element_wise_binary(x, y, ng_op, name=None):
    out_shape = broadcasted_shape(x.axes.lengths, y.axes.lengths)
    x = broadcast_to(x, out_shape)
    y = broadcast_to(y, out_shape)
    return ng_op(x, y).named(name)