Example #1
0
def test_reshape():

    fname = os.path.join(this_file_dir,
                         'runtime_analysis/{}/general/reshape.txt'.format(DIM))
    if os.path.exists(fname):
        os.remove(fname)
    for lib, call in [
        (l, c) for l, c in helpers.calls
            if c not in [helpers.tf_graph_call, helpers.mx_graph_call]
    ]:

        time_lib = LIB_DICT[lib]

        append_to_file(fname, '{}'.format(lib))

        x0 = ivy_gen.array([random.uniform(0, 1) for _ in range(DIM)], f=lib)

        ivy_gen.reshape(x0, [1, DIM], f=lib)
        ivy_gen_w_time.reshape(x0, [1, DIM], f=time_lib)
        TIMES_DICT.clear()

        for _ in range(100):

            log_time(fname, 'tb0')
            ivy_gen_w_time.reshape(x0, [1, DIM], f=time_lib)
            log_time(fname, 'tb4', time_at_start=True)

            log_time(fname, 'tt0')
            ivy_gen.reshape(x0, [1, DIM], f=lib)
            log_time(fname, 'tt1', time_at_start=True)

        write_times()

    append_to_file(fname, 'end of analysis')
Example #2
0
    def concat(containers, dim, f=None):
        """
        Concatenate containers together along the specified dimension.

        :param containers: containers to _concatenate
        :type containers: sequence of Container objects
        :param dim: dimension along which to _concatenate
        :type dim: int
        :param f: Machine learning framework. Inferred from inputs if None.
        :type f: ml_framework, optional
        :return: Concatenated containers
        """

        container0 = containers[0]

        if isinstance(container0, dict):
            return_dict = dict()
            for key in container0.keys():
                return_dict[key] = Container.concat([container[key] for container in containers], dim)
            return Container(return_dict)
        else:
            f = _get_framework(container0, f=f)
            # noinspection PyBroadException
            try:
                if len(containers[0].shape) == 0:
                    return _ivy_gen.concatenate([_ivy_gen.reshape(item, [1]*(dim+1)) for item in containers], dim, f=f)
                else:
                    return _ivy_gen.concatenate(containers, dim, f=f)
            except Exception as e:
                raise Exception(str(e) + '\nContainer concat operation only valid for containers of arrays')
Example #3
0
def test_conv3d_transpose():

    fname = os.path.join(this_file_dir, 'runtime_analysis/{}/layers/conv3d_transpose.txt'.format(DIM))
    if os.path.exists(fname):
        os.remove(fname)
    for lib, call in [(l, c) for l, c in helpers.calls if c not in [helpers.tf_graph_call, helpers.mx_graph_call]]:

        time_lib = LIB_DICT[lib]

        if call in [helpers.np_call, helpers.jnp_call, helpers.mx_call, helpers.mx_graph_call]:
            # numpy and jax do not yet support 3d convolutions, and mxnet only supports with CUDNN
            continue

        x0 = ivy_gen.array([[[[[random.uniform(0, 1)], [random.uniform(0, 1)]],
                              [[random.uniform(0, 1)], [random.uniform(0, 1)]]],
                             [[[random.uniform(0, 1)], [random.uniform(0, 1)]],
                              [[random.uniform(0, 1)], [random.uniform(0, 1)]]]] for _ in range(DIM)], f=lib)
        if call in [helpers.tf_call, helpers.tf_graph_call]:
            data_format = "NDHWC"
        else:
            x0 = ivy_gen.reshape(x0, (DIM, 1, 2, 2, 2))
            data_format = "NCDHW"

        append_to_file(fname, '{}'.format(lib))

        filters = ivy_gen.array([[[[[0.]], [[0.]]], [[[1.]], [[1.]]]],
                                 [[[[1.]], [[1.]]], [[[0.]], [[0.]]]]], f=lib)
        ivy_layers.conv3d_transpose(x0, filters, 1, "SAME", (DIM, 2, 2, 2, 1), data_format, filter_shape=[2, 2, 2],
                                    num_filters=1, f=lib)
        ivy_layers_w_time.conv3d_transpose(x0, filters, 1, "SAME", (DIM, 2, 2, 2, 1), data_format,
                                           filter_shape=[2, 2, 2], num_filters=1, f=time_lib)
        TIMES_DICT.clear()

        for _ in range(100):

            log_time(fname, 'tb0')
            ivy_layers_w_time.conv3d_transpose(x0, filters, 1, "SAME", (DIM, 2, 2, 2, 1), data_format,
                                               filter_shape=[2, 2, 2], num_filters=1, f=time_lib)
            log_time(fname, 'tb4', time_at_start=True)

            log_time(fname, 'tt0')
            ivy_layers.conv3d_transpose(x0, filters, 1, "SAME", (DIM, 2, 2, 2, 1), data_format, filter_shape=[2, 2, 2],
                                        num_filters=1, f=lib)
            log_time(fname, 'tt1', time_at_start=True)

        write_times()

    append_to_file(fname, 'end of analysis')