Beispiel #1
0
def template(x_shape=[2, 3, 4, 5],
             x_order=OrderNHWC,
             axis=Axis.C,
             keep_dims=False,
             description: str = ""):
    x = tf.placeholder(np.float32, x_shape)
    y = tf.reduce_sum(x, axis=x_order.axes_dict[axis], keep_dims=keep_dims)

    vx = np.random.rand(*x_shape).astype(np.float32)
    with tf.Session() as sess:
        vy, = sess.run([y], {x: vx})

        graph = TensorFlowConverter(sess, batch_size=2).convert([x], [y])

    assert list(vy.shape) == list(graph.outputs[0].shape)

    generate_kernel_test_case(
        description=f"[TensorFlow] Sum {description}",
        graph=graph,
        backend=["webgpu", "webassembly", "webgl"],
        inputs={graph.inputs[0]: vx},
        expected={graph.outputs[0]: vy},
    )
Beispiel #2
0
def test_explicit_ellipsis():
    x = tf.placeholder(np.float32, [2, 4, 6, 8])
    y = x[0:2, ..., 1:5]
    template(x, y, "ellipsis")
Beispiel #3
0
def test_large_stride():
    x = tf.placeholder(np.float32, [2, 4, 6, 8])
    y = x[0:1, ::2, ::2, 1::3]
    template(x, y, "shrink axis")
Beispiel #4
0
def test_shrink():
    x = tf.placeholder(np.float32, [2, 4, 6, 8])
    y = x[0:1, 2, 3:5, 4:7]
    template(x, y, "shrink axis")
Beispiel #5
0
def test_new_axis():
    x = tf.placeholder(np.float32, [2, 4, 6, 8])
    y = x[0:1, 2:3, None, 3:5, 4:7]
    template(x, y, "insert new axis")
Beispiel #6
0
def test_omit_both_reversed():
    x = tf.placeholder(np.float32, [2, 4, 6, 8])
    y = x[::-1, ::-1, ::-1, ::-1]
    template(x, y, "omit both")
Beispiel #7
0
def test_omit_both():
    x = tf.placeholder(np.float32, [2, 4, 6, 8])
    y = x[:, :, :, :]
    template(x, y, "omit both")
Beispiel #8
0
def test_omit_end_reversed():
    x = tf.placeholder(np.float32, [2, 4, 6, 8])
    y = x[1::-1, 2::-1, 3::-1, 4::-1]
    template(x, y, "omit end reversed")
Beispiel #9
0
def test_omit_end():
    x = tf.placeholder(np.float32, [2, 4, 6, 8])
    y = x[0:, 2:, 3:, 4:]
    template(x, y, "omit end")
Beispiel #10
0
def test_omit_start_reversed():
    x = tf.placeholder(np.float32, [2, 4, 6, 8])
    y = x[:0:-1, :3:-1, :5:-1, :7:-1]
    template(x, y, "omit start reversed")
Beispiel #11
0
def test_omit_start():
    x = tf.placeholder(np.float32, [2, 4, 6, 8])
    y = x[:1, :3, :5, :7]
    template(x, y, "omit start")
Beispiel #12
0
def test_reversed():
    x = tf.placeholder(np.float32, [2, 4, 6, 8])
    y = x[1:0:-1, 3:2:-1, 5:3:-1, 7:4:-1]
    template(x, y, "reversed")
Beispiel #13
0
def test_negative_index():
    x = tf.placeholder(np.float32, [2, 4, 6, 8])
    y = x[0:1, 2:3, 1:-1, 2:-2]
    template(x, y)
Beispiel #14
0
def test():
    x = tf.placeholder(np.float32, [2, 4, 6, 8])
    y = x[0:1, 2:3, 3:5, 4:7]
    template(x, y)