Example #1
0
File: tensor.py Project: zwwlp/dgl
def argsort(input, dim, descending):
    idx = nd.argsort(input, dim, is_ascend=not descending)
    idx = nd.cast(idx, dtype='int64')
    return idx
Example #2
0
File: tensor.py Project: zwwlp/dgl
def sort_1d(input):
    # TODO: this isn't an ideal implementation.
    val = nd.sort(input, axis=None, is_ascend=True)
    idx = nd.argsort(input, is_ascend=True)
    idx = nd.cast(idx, dtype='int64')
    return val, idx
Example #3
0
def astype(input, ty):
    return nd.cast(input, ty)
Example #4
0
def merge(conv_w, gamma, beta, running_mean, running_var):
    gamma_over_var = gamma / nd.sqrt(running_var + 1e-5)
    gamma_over_var_expanded = nd.reshape(gamma_over_var, (gamma_over_var.shape[0], 1, 1, 1))
    new_w = gamma_over_var_expanded * nd.cast(conv_w, 'float32')
    new_b = beta - running_mean * gamma_over_var
    return new_w, new_b
Example #5
0
def acc(output, label):
    # output: (batch, num_output) float32 ndarray
    # label: (batch, ) int32 ndarray
    return (cast(output.argmax(axis=1),
                 dtype="int64") == label).mean().asscalar()
Example #6
0
def mxnet_cast(in1, in2):
    return [mxnd.cast(t, dtype='float32')
            for t in in1], [mxnd.cast(t, dtype='int64') for t in in2]
def __normalize_rgb_image(arr):
    return nd.cast(arr, "float32") / 255.0