text
stringlengths
1
2.05k
import make_test, to_fp, Tensor, Dtype, FixedImpl, Trait def gather_elements(data, indices, axis=0): data_swaped = np.swapaxes(data, 0, axis) index_swaped = np.swapaxes(indices, 0, axis) gathered = np.choose(index_swaped, data_swaped, mode="wrap") y = np.swapaxes(gathered, 0, axis) return y
class Gather_elements(RunAll): @staticmethod def gather_elements_fp16x16(): def default(): x1 = np.arange(0,27).reshape(3,3,3).astype(np.int64) x2 = np.random.randint(low = 0,high=2, size=(3,3,3)).astype(np.uint32) y = gather_elements(x1, x2, axis=0) x1 ...
_sig = "input_0.gather_elements(indices:input_1, axis:Option::Some(2))", name= name) def negative_indices(): x1 = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]], dtype=np.float32) x2 = np.array([[-1, -2, 0], [-2, 0, 0]], dtype=np.int32) y = gather_elemen...
import numpy as np from nodegen.node
import RunAll from ..helpers
import make_test, to_fp, Tensor, Dtype, FixedImpl def gather_nd_impl( data: np.ndarray, indices: np.ndarray, batch_dims: int ) -> np.ndarray: data_rank = len(data.shape) assert indices.shape[-1] <= data_rank batch_dims_shape = [] batch_dims_size = 1 for i in range(b...
class Gather_nd(RunAll): @staticmethod def gather_nd_fp16x16(): def gather_nd_3D(): def default(): x1 = np.arange(0,27).reshape(3,3,3).astype(np.int64) x2 = np.random.randint(low = 0,high=2, size=(3,3,3)).astype(np.uint32) y = gather_nd_impl(x...
y = Tensor(Dtype.FP16x16, y.shape, to_fp( y.flatten(), FixedImpl.FP16x16)) name = "gather_nd_fp16x16_3d_batch_dims2" make_test( inputs = [x1, x2], output = y, func_sig = "input_0.gather_nd(indices:input_1, batch_dims:Option::Some(2))", ...
f batch_dims2(): x1 = np.arange(0,54).reshape(3,3,3,2).astype(np.int64) x2 = np.random.randint(low = 0,high=2, size=(3,3,2)).astype(np.uint32) y = gather_nd_impl(x1, x2, batch_dims=2) x1 = Tensor(Dtype.FP8x23, x1.shape, to_fp(x1.flatten(), FixedImpl.FP8x2...
d_batch_dims1" make_test( inputs = [x1, x2], output = y, func_sig = "input_0.gather_nd(indices:input_1, batch_dims:Option::Some(1))", name= name) default() batch_dims1() gather_nd_3D() @staticmeth...
shape, x1.flatten()) x2 = Tensor(Dtype.U32, x2.shape, x2.flatten()) y = Tensor(Dtype.I32, y.shape, y.flatten()) name = "gather_nd_i32_3d_batch_dims2" make_test( inputs = [x1, x2], output = y, func_sig = "input_0.gather_nd(indices:in...
pe(np.int32) x2 = np.random.randint(low = 0,high=2, size=(3,3,2)).astype(np.uint32) y = gather_nd_impl(x1, x2, batch_dims=2) x1 = Tensor(Dtype.U32, x1.shape, x1.flatten()) x2 = Tensor(Dtype.U32, x2.shape, x2.flatten()) y = Tensor(Dtype....
from typing
import Optional
import numpy as np from nodegen.node
import RunAll from ..helpers
import make_test, to_fp, Tensor, Dtype, FixedImpl, Trait def gemm_reference_implementation( A: np.ndarray, B: np.ndarray, C: Optional[np.ndarray] = None, alpha: float = 1.0, beta: float = 1.0, transA: int = 0, transB: int = 0, ) -> np.ndarray: A = A if transA == 0 else A.T B = B if...
class Gemm(RunAll): @staticmethod def gemm_default_zero_bias(): a = np.random.ranf([3, 5]).astype(np.float32) b = np.random.ranf([5, 4]).astype(np.float32) c = np.zeros([1, 4]).astype(np.float32) y = gemm_reference_implementation(a, b, c) a = Tensor(Dtype.FP16x16, a.sha...
, to_fp( b.flatten(), FixedImpl.FP16x16)) c = Tensor(Dtype.FP16x16, c.shape, to_fp( c.flatten(), FixedImpl.FP16x16)) y = Tensor(Dtype.FP16x16, y.shape, to_fp( y.flatten(), FixedImpl.FP16x16)) name = "gemm_default_matrix_bias" make_test( [a...
np.random.ranf([5, 4]).astype(np.float32) c = np.zeros([1, 4]).astype(np.float32) y = gemm_reference_implementation(a, b, c, alpha=0.5) a = Tensor(Dtype.FP16x16, a.shape, to_fp( a.flatten(), FixedImpl.FP16x16)) b = Tensor(Dtype.FP16x16, b.shape, to_fp( b.flatten(...
c = Tensor(Dtype.FP16x16, c.shape, to_fp( c.flatten(), FixedImpl.FP16x16)) y = Tensor(Dtype.FP16x16, y.shape, to_fp( y.flatten(), FixedImpl.FP16x16)) name = "gemm_all_attributes" make_test( [a, b, c], y, "NNTrait::gemm(input_0, input_1, Option::Some(input_2),...
import numpy as np from nodegen.node
import RunAll from ..helpers
import make_test, to_fp, Tensor, Dtype, FixedImpl
class Greater(RunAll): @staticmethod def greater_u32(): def default(): x = np.random.randint(0, 6, (3, 3, 3)).astype(np.uint32) y = np.random.randint(0, 6, (3, 3, 3)).astype(np.uint32) z = np.greater(x, y) x = Tensor(Dtype.U32, x.shape, x.flatten()) ...
oadcast() @staticmethod def greater_i8(): def default(): x = np.random.randint(-3, 3, (3, 3, 3)).astype(np.int8) y = np.random.randint(-3, 3, (3, 3, 3)).astype(np.int8) z = np.greater(x, y) x = Tensor(Dtype.I8, x.shape, x.flatten()) y = Tenso...
type.U32, z.shape, z.flatten()) name = "greater_fp8x23_broadcast" make_test([x, y], z, "input_0.greater(@input_1)", name) default() broadcast() @staticmethod def greater_fp16x16(): def default(): x = np.random.randint(-3, 3, (3, 3, 3)).astype(np.flo...
import numpy as np from nodegen.node
import RunAll from ..helpers
import make_test, to_fp, Tensor, Dtype, FixedImpl
class Greater_equal(RunAll): @staticmethod def greater_equal_u32(): def default(): x = np.random.randint(0, 6, (3, 3, 3)).astype(np.uint32) y = np.random.randint(0, 6, (3, 3, 3)).astype(np.uint32) z = np.greater_equal(x, y) x = Tensor(Dtype.U32, x.shape, ...
make_test([x, y], z, "input_0.greater_equal(@input_1)", name) default() broadcast() @staticmethod def greater_equal_i8(): def default(): x = np.random.randint(-3, 3, (3, 3, 3)).astype(np.int8) y = np.random.randint(-3, 3, (3, 3, 3)).astype(np.int8) z...
ape, to_fp( x.flatten(), FixedImpl.FP8x23)) y = Tensor(Dtype.FP8x23, y.shape, to_fp( y.flatten(), FixedImpl.FP8x23)) z = Tensor(Dtype.U32, z.shape, z.flatten()) name = "greater_equal_fp8x23_broadcast" make_test([x, y], z, "input_0.greater...
import numpy as np from nodegen.node
import RunAll from ..helpers
import make_test, to_fp, Tensor, Dtype, FixedImpl, Trait from .resize
import _get_all_coords
import numbers from typing
import List
import numpy as np def grid_sample(X, grid, mode='linear', padding_mode='zeros', align_corners=0): x_dims = X.shape grid_dims = grid.shape N = x_dims[0] C = x_dims[1] y_dims = (N, C, *grid_dims[1:-1]) if np.prod(y_dims) == 0: return np.array([], dtype=X.dtype) Y = np.empty(y_dims,...
=border, padding_mode=padding_mode ) else: raise RuntimeError( "GridSample interpolation only supports nearest, linear, and cubic modes." ) return (Y.astype(X.dtype),) def _gs_denormalize(n, length: int, align_corn...
- x coeffs[1] = x def _gs_bicubic_interpolate(p, x, y): v = np.empty((4,), dtype=p.dtype) coeffs = np.empty((4,), dtype=p.dtype) _gs_get_cubic_coeffs(x, coeffs) for i in range(4): v[i] = coeffs @ p[i, :] _gs_get_cubic_coeffs(y, coeffs) return coeffs @ v def _gs_cubic_interpol...
padding_mode=padding_mode, ) res1d.append(r) res1d = np.array(res1d) return _gs_linear_interpolation_1d_with_x( data=res1d, x=x[0], border=[border[0], border[num_dims]], padding_mode=padding_mode, ) def _gs_cubic_interpolation_nd_with_x(data, x, border, p...
r[1 + num_dims : 2 * num_dims]), padding_mode=padding_mode, ) def _pixel_at_array(array, i: int, border, padding_mode): assert array.ndim == 1 d = array.shape[0] if padding_mode == "zeros": if i >= 0 and i < d: pixel = array[i] else: pixel = 0 elif p...
class Grid_sample(RunAll): @staticmethod def export_gridsample() -> None: x = np.array( [ [ [ [0.0, 1.0, 2.0, 3.0], [4.0, 5.0, 6.0, 7.0], [8.0, 9.0, 10.0, 11.0], ...
[ [-1.0000, 1.0000], [-0.6000, 1.0000], [-0.2000, 1.0000], [0.2000, 1.0000], [0.6000, 1.0000], [1.0000, 1.0000], ], ] ], ...
x16)) y = Tensor(Dtype.FP16x16, y.shape, to_fp(y.flatten(), FixedImpl.FP16x16)) name = "grid_sample_padding_zeros" func_sig = "NNTrait::grid_sample(" func_sig += "@input_0," func_sig += "@input_1," func_sig += "Option::None," func_sig += "Option::None," ...
0, 3.0], [4.0, 5.0]]]], dtype=np.float32, ) grid = np.array( [ [ [ [-10.0000, -10.0000], [-5.0000, -5.0000], [-0.2000, -0.2000], [10.0000, 10.0000],...
], ] ], dtype=np.float32, ) y = grid_sample(x, grid, mode ="linear", align_corners=1) y = np.array(y[0]) x = Tensor(Dtype.FP16x16, x.shape, to_fp(x.flatten(), FixedImpl.FP16x16)) grid = Tensor(Dtype.FP16x16, grid.shape, to_fp(gri...
t_1," func_sig += "Option::Some(0)," func_sig += "Option::Some(MODE::NEAREST)," func_sig += "Option::None)" make_test( [x, grid], y, func_sig, name, Trait.NN) @staticmethod def export_gridsample_nearest_align_corner() -> None: x = np.array( ...
[-0.2000, -0.2000], [0.0000, 0.0000], ], [ [0.0000, 0.0000], [-0.2000, -0.2000], [0.5000, 0.5000], [1.0000, 1.0000], ], ] ...
import numpy as np from nodegen.node
import RunAll from ..helpers
import make_test, to_fp, Tensor, Dtype, FixedImpl, Trait, get_data_statement def hamming_window(size, output_datatype=None, periodic=None) -> np.ndarray: if periodic == 1: N_1 = size else: N_1 = size - 1 ni = np.arange(size, dtype=output_datatype) alpha = 25.0 / 46.0 beta = 1 - al...
class Hamming_window(RunAll): @staticmethod def fp8x23(): args = [4] args_str = get_data_statement(to_fp(np.array(args).flatten(), FixedImpl.FP8x23), Dtype.FP8x23) y = hamming_window(*args, np.float64) y = Tensor(Dtype.FP8x23, y.shape, to_fp(...
import numpy as np from nodegen.node
import RunAll from ..helpers
import make_test, to_fp, Tensor, Dtype, FixedImpl, Trait, get_data_statement def hann_window(size, output_datatype=None, periodic=None) -> np.ndarray: if periodic == 1: N_1 = size else: N_1 = size - 1 ni = np.arange(size, dtype=output_datatype) res = np.sin((ni * np.float64(np.pi).ast...
class Hann_window(RunAll): @staticmethod def fp8x23(): print(get_data_statement(to_fp(np.array([np.pi]).flatten(), FixedImpl.FP8x23), Dtype.FP8x23)) args = [4] args_str = get_data_statement(to_fp(np.array(args).flatten(), FixedImpl.FP8x23), Dtype.FP8x23) y = h...
import numpy as np from nodegen.node import RunAll from ..helpers import make_test, to_fp, Tensor, Dtype, FixedImpl, Trait class Hard_sigmoid(RunAll): @staticmethod def fp8x23(): alpha = 0.2 beta = 0.5 x = np.random.uniform(-3, 3, (2, 2)).astype(np.float32) y = np.maximum(0, np...
import numpy as np from nodegen.node
import RunAll from ..helpers
import make_test, to_fp, Tensor, Dtype, FixedImpl
class Identity(RunAll): @staticmethod def identity_fP8x23(): def identity(): x = np.array([[1, 2], [3, 4]]) y = x x = Tensor(Dtype.FP8x23, x.shape, x.flatten()) y = Tensor(Dtype.FP8x23, y.shape, y.flatten()) name = "identity_fP8x2...
import numpy as np from nodegen.node
import RunAll from ..helpers
import make_test, to_fp, Tensor, Dtype, FixedImpl INF = 2**32 - 1
class Is_inf(RunAll): @staticmethod def is_inf_u32(): def default(): input_0 = np.array([1, 0, INF, 8, -INF, INF], dtype=np.uint32) output = np.array([False, False, True, False, True, True], dtype=bool) input_0 = Tensor(Dtype.U32, input_0.shape, input_0.flatten()) ...
e(0))", name) default() positive() negative() @staticmethod def is_inf_i8(): def default(): input_0 = np.array([-1, 0, INF, 8, -INF, INF], dtype=np.int8) output = np.array([False, False, True, False, True, True], dtype=bool) input_0 = Tensor...
en()) name = "is_inf_fp8x23" make_test([input_0], output, "TensorTrait::is_inf(@input_0, Option::None, Option::None)", name) def positive(): input_0 = np.array([-1.2, 0, INF, 2.8, -INF, INF], dtype=np.float64) output = np.array([False, False, True, F...
, input_0.shape, input_0.flatten()) output = Tensor(Dtype.BOOL, output.shape, output.flatten()) name = "is_pos_inf_fp16x16" make_test([input_0], output, "TensorTrait::is_inf(@input_0, Option::Some(0), Option::Some(1))", name) def negative(): input_0 ...
import numpy as np from nodegen.node import RunAll from ..helpers import make_test, to_fp, Tensor, Dtype, FixedImpl # NaN is represented with -0 NaN = -0 class Is_nan(RunAll): @staticmethod def is_nan_fp8x23(): def default(): input_0 = np.array([-1.2, 0, NaN, 2.8, NaN, NaN], dtype=np.flo...
import numpy as np from nodegen.node
import RunAll from ..helpers
import make_test, to_fp, Tensor, Dtype, FixedImpl, Trait def labelEncoder( x, default_float=None, default_int64=None, default_string=None, keys_floats=None, keys_int64s=None, keys_strings=None, values_floats=None, values_int64s=None, values_strings=None, ): keys = keys_...
class Label_encoder(RunAll): @staticmethod def label_encoder_fp16x16(): def labelencoder(): def default(): x = np.array([1, 2, 3, 4, 5, 6, 1, 2, 3]).astype(np.int64) keys = np.array([1, 2, 5, 6, ]).astype(np.int64) values = np.arr...
x = Tensor(Dtype.FP8x23, x.shape, to_fp(x.flatten(), FixedImpl.FP8x23)) default = Tensor(Dtype.FP8x23, default.shape, to_fp(default.flatten(), FixedImpl.FP8x23)) keys = Tensor(Dtype.FP8x23, keys.shape, to_fp(keys.flatten(), FixedImpl.FP8x23)) values = Tensor(Dtype.FP8x23,...
nsor: Option::Some(input_1), keys:Option::None, keys_tensor: Option::Some(input_2), values: Option::None, values_tensor: Option::Some(input_3))""", name= name) default() label_encoder_3D() @staticmethod ...
default = np.array(99).astype(np.uint32) y = labelEncoder(x=x, keys_int64s=keys, values_int64s=values, default_int64=default) x = Tensor(Dtype.U32, x.shape, x.flatten()) default = Tensor(Dtype.U32, default.shape, default.flatten()) keys = Tensor(Dtype...
import numpy as np from nodegen.node
import RunAll from ..helpers
import make_test, to_fp, Tensor, Dtype, FixedImpl, Trait
import numpy as np
import onnx from onnx.backend.test.case.base
import Base from onnx.backend.test.case.node
import expect def _layer_normalization(X, W, B, axis=-1, epsilon=1e-5): X_shape = X.shape X_rank = len(X_shape) if axis < 0: axis = axis + X_rank unsqueezed_rank = X_rank - axis reduction_shape = X_shape[0:axis] + (1,) * unsqueezed_rank row_number = 1 col_number = 1 for i in ...
class Layer_normalization(RunAll): @staticmethod def export4d() -> None: X = np.random.randn(2, 3, 4, 5).astype(np.float32) def case(axis: int) -> None: normalized_shape = calculate_normalized_shape(X.shape, axis) W = np.random.randn(*normalized_shape).astype(np.float32)...
ensor(Dtype.FP16x16, Y.shape, to_fp(Y.flatten(), FixedImpl.FP16x16)) name = "layer_normalization_default_axis" make_test([x,w,b], y, "input_0.layer_normalization(@input_1,Option::Some(@input_2),Option::None,Option::None,Option::None)", name) @staticmethod def export3d_epsilon() -> None...
2) B = np.random.randn(*normalized_shape).astype(np.float32) Y, mean, inv_std_dev = _layer_normalization(X, W, B, axis=axis) node = onnx.helper.make_node( "LayerNormalization", inputs=["X", "W", "B"], outputs=["Y", "Mean", "InvStdDev"]...
import numpy as np from nodegen.node import RunAll from ..helpers import make_test, to_fp, Tensor, Dtype, FixedImpl, Trait import tensorflow as tf class Leaky_relu(RunAll): @staticmethod def leaky_relu_fp8x23(): x = np.random.uniform(-5, 7, (2, 2)).astype(np.float64) layer = tf.keras.layers....
import numpy as np from nodegen.node
import RunAll from ..helpers
import make_test, to_fp, Tensor, Dtype, FixedImpl
class Less(RunAll): @staticmethod def less_u32(): def default(): x = np.random.randint(0, 6, (3, 3, 3)).astype(np.uint32) y = np.random.randint(0, 6, (3, 3, 3)).astype(np.uint32) z = np.less(x, y) x = Tensor(Dtype.U32, x.shape, x.flatten()) y ...
def less_i8(): def default(): x = np.random.randint(-3, 3, (3, 3, 3)).astype(np.int8) y = np.random.randint(-3, 3, (3, 3, 3)).astype(np.int8) z = np.less(x, y) x = Tensor(Dtype.I8, x.shape, x.flatten()) y = Tensor(Dtype.I8, y.shape, y.flatten()) ...
_fp8x23_broadcast" make_test([x, y], z, "input_0.less(@input_1)", name) default() broadcast() @staticmethod def less_fp16x16(): def default(): x = np.random.randint(-3, 3, (3, 3, 3)).astype(np.float64) y = np.random.randint(-3, 3, (3, 3, 3)).astype(n...
import numpy as np from nodegen.node
import RunAll from ..helpers
import make_test, to_fp, Tensor, Dtype, FixedImpl
class Less_equal(RunAll): @staticmethod def less_equal_u32(): def default(): x = np.random.randint(0, 6, (2, 2)).astype(np.uint32) y = np.random.randint(0, 6, (2, 2)).astype(np.uint32) z = np.less_equal(x, y) x = Tensor(Dtype.U32, x.shape, x.flatten()) ...