text
stringlengths
1
2.05k
import RunAll from ..helpers
import make_test, Tensor, Dtype, FixedImpl, to_fp
class Reduce_log_sum_exp(RunAll): @staticmethod def reduce_log_sum_exp_fp32x32(): def reduce_log_sum_exp_export_do_not_keepdims(): shape = [3, 2, 2] axes = np.array([2], dtype=np.int64) keepdims = False x = np.reshape(np.arange(1, np.prod(shape) + 1), shap...
egative_axes_keepdims" make_test( [x], y, "input_0.reduce_log_sum_exp(0, true)", name) reduce_log_sum_exp_export_do_not_keepdims() reduce_log_sum_exp_export_keepdims() reduce_log_sum_exp_axis_0()
import numpy as np from nodegen.node
import RunAll from ..helpers
import make_test, to_fp, Tensor, Dtype, FixedImpl
class Reduce_mean(RunAll): @staticmethod def reduce_mean_u32(): def reduce_mean_1D(): x = np.array([0, 1, 2,]).astype(np.uint32) y = np.mean(x, keepdims=True).astype(np.uint32) x = Tensor(Dtype.U32, x.shape, x.flatten()) y = Tensor(Dtype.U32, y.shape, y.f...
axis_1() reduce_mean_1D() reduce_mean_2D() @staticmethod def reduce_mean_i32(): def reduce_mean_1D(): x = np.array([0, 1, 2,]).astype(np.int32) y = np.mean(x, keepdims=True).astype(np.int32) x = Tensor(Dtype.I32, x.shape, x.flatten()) y =...
) keepdims() axis_1() reduce_mean_1D() reduce_mean_2D() @staticmethod def reduce_mean_i8(): def reduce_mean_1D(): x = np.array([0, 1, 2,]).astype(np.int8) y = np.mean(x, keepdims=True).astype(np.int8) x = Tensor(Dtype.FP8x23, ...
n::None(()))", name) default() keepdims() axis_1() reduce_mean_1D() reduce_mean_2D() @staticmethod def reduce_mean_fp8x23(): def reduce_mean_1D(): x = np.array([0, 1, 2,]).astype(np.int64) y = np.mean(x, keepdims=True) ...
.shape, to_fp( x.flatten(), FixedImpl.FP8x23)) y = Tensor(Dtype.FP8x23, y.shape, to_fp( y.flatten(), FixedImpl.FP8x23)) name = "reduce_mean_fp8x23_2D_axis_1" make_test( [x], y, "input_0.reduce_mean(Option::Some(...
name = "reduce_mean_fp16x16_2D_keepdims" make_test( [x], y, "input_0.reduce_mean(Option::None(()), Option::Some(false), Option::None(()))", name) def axis_1(): x = np.array([0, 1, 2, 3]).astype(np.int64).reshape(2, 2) y = np.mean(x, axis=(...
import numpy as np from nodegen.node
import RunAll from ..helpers
import make_test, to_fp, Tensor, Dtype, FixedImpl
class Reduce_min(RunAll): @staticmethod def reduce_min_u32(): def reduce_min_1D(): x = np.array([0, 1, 2,]).astype(np.uint32) y = np.minimum.reduce(x, axis=None, keepdims=True).astype(np.uint32) x = Tensor(Dtype.U32, x.shape, x.flatten()) y = Tensor(Dtype...
", name) default() keepdims() axis_1() reduce_min_1D() reduce_min_2D() @staticmethod def reduce_min_i32(): def reduce_min_1D(): x = np.array([0, 1, 2,]).astype(np.int32) y = np.minimum.reduce(x, axis=None, keepdims=True).astyp...
y, "input_0.reduce_min(Option::Some(array![1].span()), Option::None(()), Option::None(()))", name) default() keepdims() axis_1() reduce_min_1D() reduce_min_2D() @staticmethod def reduce_min_i8(): def reduce_min_1D(): x = np.array([0, 1, 2...
name = "reduce_min_i8_2D_axis_1" make_test( [x], y, "input_0.reduce_min(Option::Some(array![1].span()), Option::None(()), Option::None(()))", name) default() keepdims() axis_1() reduce_min_1D() reduce_min_2D() @staticmethod ...
alse), Option::None(()))", name) def axis_1(): x = np.array([0, 1, 2, 3]).astype(np.int64).reshape(2, 2) y = np.minimum.reduce(x, axis=(1), keepdims=True) x = Tensor(Dtype.FP8x23, x.shape, to_fp( x.flatten(), FixedImpl.FP8x23)) ...
y = np.minimum.reduce(x, axis=None, keepdims=False) x = Tensor(Dtype.FP16x16, x.shape, to_fp( x.flatten(), FixedImpl.FP16x16)) y = Tensor(Dtype.FP16x16, y.shape, to_fp( y.flatten(), FixedImpl.FP16x16)) name = "reduce_min_fp16x16_2...
import numpy as np from nodegen.node
import RunAll from ..helpers
import make_test, to_fp, Tensor, Dtype, FixedImpl
class Reduce_sum(RunAll): @staticmethod def reduce_sum_no_keep_dims(): axes = np.array([1], dtype=np.uint32) keepdims = 0 x = np.array([[[1, 2], [3, 4]], [[5, 6], [7, 8]], [ [9, 10], [11, 12]]]).astype(np.uint32) y = np.sum(x, axis=tuple(axes.tolist()), kee...
ims=keepdims == 1) x = Tensor(Dtype.U32, x.shape, x.flatten()) y = Tensor(Dtype.U32, y.shape, y.flatten()) name = "reduce_sum_negative_axes_keepdims" make_test( [x], y, "input_0.reduce_sum(Option::Some(array![-2].span()), Option::Some(true), Option::None)", name) @stat...
import numpy as np from nodegen.node
import RunAll from ..helpers
import make_test, to_fp, Tensor, Dtype, FixedImpl
import numpy as np
class Reduce_sum_square(RunAll): @staticmethod def reduce_sum_square_fp8x23(): def reduce_sum_square_export_do_not_keepdims(): shape = [3, 2, 2] axes = np.array([2], dtype=np.int64) keepdims = False x = np.reshape(np.arange(1, np.prod(shape) + 1, dtype=np....
reduce_sum_square_export_do_not_keepdims() reduce_sum_square_export_keepdims() reduce_sum_square_axis_0() @staticmethod def reduce_sum_square_fp16x16(): def reduce_sum_square_export_do_not_keepdims(): shape = [3, 2, 2] axes = np.array([2], dtype=np.int64) ...
make_test( [x], y, "input_0.reduce_sum_square(0, true)", name) reduce_sum_square_export_do_not_keepdims() reduce_sum_square_export_keepdims() reduce_sum_square_axis_0() @staticmethod def reduce_sum_square_i8(): def reduce_sum_square_export_do_not_keepdi...
quare_i8_export_negative_axes_keepdims" make_test( [x], y, "input_0.reduce_sum_square(0, true)", name) reduce_sum_square_export_do_not_keepdims() reduce_sum_square_export_keepdims() reduce_sum_square_axis_0() @staticmethod def reduce_su...
Dtype.I32, y.shape, y.flatten()) name = "reduce_sum_square_i32_export_negative_axes_keepdims" make_test( [x], y, "input_0.reduce_sum_square(0, true)", name) reduce_sum_square_export_do_not_keepdims() reduce_sum_square_export_keepdims() ...
x = Tensor(Dtype.U32, x.shape, x.flatten()) y = Tensor(Dtype.U32, y.shape, y.flatten()) name = "reduce_sum_square_u32_export_negative_axes_keepdims" make_test( [x], y, "input_0.reduce_sum_square(0, true)", name) reduce_sum_square_export...
import numpy as np from nodegen.node import RunAll from ..helpers import make_test, to_fp, Tensor, Dtype, Trait, FixedImpl import tensorflow as tf class Relu(RunAll): @staticmethod def relu_i32(): x = np.random.randint(-5, 9, (2, 2)).astype(np.int32) layer = tf.keras.layers.ReLU() y =...
import numpy as np from nodegen.node
import RunAll from ..helpers
import make_test, Tensor, Dtype original_shape = [2, 3, 4] data = np.random.random_sample(original_shape).astype(np.int32) def reshape_reference_implementation( data: np.ndarray, shape: np.ndarray, allowzero: int = 0 ) -> np.ndarray: new_shape = np.copy(shape) if allowzero == 0: zeros_i...
class Reshape(RunAll): @staticmethod def reshape_reordered_all_dims(): y = reshape_reference_implementation( data, np.array([4, 2, 3], dtype=np.int64)) x = Tensor(Dtype.I32, data.shape, data.flatten()) y = Tensor(Dtype.I32, y.shape, y.flatten()) name = "reshape_reor...
data, np.array([2, -1, 2], dtype=np.int64)) x = Tensor(Dtype.I32, data.shape, data.flatten()) y = Tensor(Dtype.I32, y.shape, y.flatten()) name = "reshape_negative_dim" make_test([x], y, "input_0.reshape(array![2, -1, 2].span(), false)", name) @staticmethod def reshape_negative...
import numpy as np from typing
import Any, Callable from nodegen.node
import RunAll from ..helpers
import make_test, to_fp, Tensor, Dtype, FixedImpl def _cartesian(arrays: list[np.ndarray], out: np.ndarray | None = None) -> np.ndarray: arrays = [np.asarray(x) for x in arrays] dtype = arrays[0].dtype n = np.prod([x.size for x in arrays]) if out is None: out = np.zeros([n, len(arrays)],...
i_start, i_end)] coeffs = [compute_coeff(x) for x in args] return np.array(coeffs) / sum(coeffs) def nearest_coeffs( ratio: float | int | np.ndarray, mode: str = "round_prefer_floor" ) -> np.ndarray: if isinstance(ratio, int) or ratio.is_integer(): return np.array([0, 1]) if mode == "round_...
de == "half_pixel": x_ori = (x + 0.5) / scale_factor - 0.5 elif coordinate_transformation_mode == "half_pixel_symmetric": adjustment = output_width_int / output_width center = input_width / 2 offset = center * (1 - adjustment) x_ori = offset + (x + 0.5) / scale_factor - 0.5 ...
get_coeffs, roi=None if roi is None else [roi[0], roi[n]], exclude_outside=exclude_outside, **kwargs, ) def _get_all_coords(data: np.ndarray) -> np.ndarray: return _cartesian( [list(range(data.shape[i])) for i in range(len(data.shape))] ) def interpolate_nd( data: ...
lueError( f"Invalid keep_aspect_ratio_policy={keep_aspect_ratio_policy!r}" ) scale_factors = [scale if i in axes else 1.0 for i in range(r)] def round_half_up(x: float) -> int: return int(x + 0.5) output_size = [ ...
class Resize(RunAll): @staticmethod def resize_upsample_scales_nearest() -> None: data = np.array( [ [ [ [1, 2], [3, 4], ] ] ], dtype=np.float32, ...
ype.FP16x16, x[i].shape, to_fp(x[i].flatten(), FixedImpl.FP16x16)) y = Tensor(Dtype.FP16x16, y.shape, to_fp(y.flatten(), FixedImpl.FP16x16)) name = "resize_downsample_scales_nearest" func_sig = "data.resize(" func_sig += "Option::None," func_sig += "scales," fu...
ption::None,)" make_test([x[0], x[1]], y, func_sig, name) @staticmethod def resize_downsample_sizes_nearest() -> None: data = np.array( [ [ [ [1, 2, 3, 4], [5, 6, 7, 8], ] ...
x[i] = Tensor(Dtype.FP16x16, x[i].shape, to_fp(x[i].flatten(), FixedImpl.FP16x16)) y = Tensor(Dtype.FP16x16, y.shape, to_fp(y.flatten(), FixedImpl.FP16x16)) name = "resize_upsample_scales_linear" func_sig = "data.resize(" func_sig += "Option::None," func_sig += "scales...
::None," func_sig += "Option::None," func_sig += "Option::None," func_sig += "Option::Some(MODE::LINEAR)," func_sig += "Option::None,)" make_test([x[0], x[1]], y, func_sig, name) @staticmethod def resize_downsample_scales_linear() -> None: data = np.array( ...
lambda x, _: linear_coeffs(x, None), scale_factors=scales, coordinate_transformation_mode="align_corners", ).astype(np.float32) x = [data, scales] y = output for i in range(len(x)): x[i] = Tensor(Dtype.FP16x16, x[i].shape, to_fp(x[i].flatten(), Fixed...
tion::None," func_sig += "scales," func_sig += "Option::None," func_sig += "Option::None," func_sig += "Option::None," func_sig += "Option::None," func_sig += "Option::None," func_sig += "Option::None," func_sig += "Option::None," func_sig += "Op...
sig, name) @staticmethod def resize_downsample_scales_cubic() -> None: data = np.array( [ [ [ [1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 16], ...
e_factors=scales, coordinate_transformation_mode="align_corners", ).astype(np.float32) x = [data, scales] y = output for i in range(len(x)): x[i] = Tensor(Dtype.FP16x16, x[i].shape, to_fp(x[i].flatten(), FixedImpl.FP16x16)) y = Tensor(Dtype.FP1...
c_sig += "sizes," func_sig += "Option::None," func_sig += "Option::None," func_sig += "Option::None," func_sig += "Option::None," func_sig += "Option::None," func_sig += "Option::None," func_sig += "Option::None," func_sig += "Option::Some(MODE::CUBIC),"...
[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 16], ] ] ], dtype=np.float32, ) scales = np.array([1.0, 1.0, 2.0, 2.0], dtype=np.float32) output = interp...
les, exclude_outside=True, ).astype(np.float32) x = [data, scales] y = output for i in range(len(x)): x[i] = Tensor(Dtype.FP16x16, x[i].shape, to_fp(x[i].flatten(), FixedImpl.FP16x16)) y = Tensor(Dtype.FP16x16, y.shape, to_fp(y.flatten(), Fixed...
func_sig += "Option::None," func_sig += "scales," func_sig += "Option::None," func_sig += "Option::None," func_sig += "Option::None," func_sig += "Option::Some(TRANSFORMATION_MODE::ASYMMETRIC)," func_sig += "Option::None," func_sig += "Option::None," f...
c_sig += "Option::None," func_sig += "Option::None," func_sig += "Option::None," func_sig += "Option::Some(MODE::LINEAR)," func_sig += "Option::None,)" make_test([x[0], x[1], x[2]], y, func_sig, name) @staticmethod def resize_tf_crop_and_resize_extrapolation_value() -> N...
func_sig += "Option::None,)" make_test([x[0], x[1], x[2]], y, func_sig, name) @staticmethod def resize_downsample_sizes_linear_pytorch_half_pixel() -> None: data = np.array( [ [ [ [1, 2, 3, 4], [5, 6...
] ] ], dtype=np.float32, ) sizes = np.array([1, 1, 8, 8], dtype=np.int64) output = interpolate_nd( data, lambda x, _: nearest_coeffs(x, mode="floor"), output_size=sizes, coordinate_transformation_mode="align...
x = [data, sizes] y = output x[0] = Tensor(Dtype.FP16x16, x[0].shape, to_fp(x[0].flatten(), FixedImpl.FP16x16)) x[1] = Tensor(Dtype.U32, x[1].shape, x[1].flatten()) y = Tensor(Dtype.FP16x16, y.shape, to_fp(y.flatten(), FixedImpl.FP16x16)) name = "resize_upsample_sizes...
c_sig += "sizes," func_sig += "Option::None," func_sig += "Option::None," func_sig += "Option::Some(TRANSFORMATION_MODE::HALF_PIXEL)," func_sig += "Option::None," func_sig += "Option::None," func_sig += "Option::None," func_sig += "Option::None," func_si...
[ [ [1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 16], ] ] ], dtype=np.float32, ) sizes = np.array([1, 1, 3, 3], dt...
x[i] = Tensor(Dtype.FP16x16, x[i].shape, to_fp(x[i].flatten(), FixedImpl.FP16x16)) y = Tensor(Dtype.FP16x16, y.shape, to_fp(y.flatten(), FixedImpl.FP16x16)) name = "resize_downsample_scales_cubic_antialias" func_sig = "data.resize(" func_sig += "Option::None," func_sig...
ig += "Option::None," func_sig += "Option::None," func_sig += "Option::Some(MODE::CUBIC)," func_sig += "Option::None,)" make_test([x[0], x[1]], y, func_sig, name) @staticmethod def resize_upsample_scales_nearest_axes_2_3() -> None: axes = np.array([2, 3], dtype=np.int64)...
_: nearest_coeffs(x), scale_factors=scales, axes=axes ).astype(np.float32) x = [data, scales, axes] y = output x[0] = Tensor(Dtype.FP16x16, x[0].shape, to_fp(x[0].flatten(), FixedImpl.FP16x16)) x[1] = Tensor(Dtype.FP16x16, x[1].shape, to_fp(x[1].flatten(), FixedImpl.FP16x16)) ...
" func_sig += "Option::None," func_sig += "Option::None," func_sig += "sizes," func_sig += "Option::None," func_sig += "axes," func_sig += "Option::None," func_sig += "Option::None," func_sig += "Option::None," func_sig += "Option::None," ...
xes_2_3() -> None: axes = np.array([2, 3], dtype=np.int64) data = np.array( [ [ [ [1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 16], ...
[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 16], ] ] ], dtype=np.float32, ) roi = np.array([0.6, 0.4, 0.8, 0.6], dtype=np.float32) sizes = np.array([...
] ], dtype=np.float32, ) sizes = np.array([7, 8], dtype=np.int64) output = interpolate_nd( data, lambda x, _: nearest_coeffs(x), output_size=sizes, axes=axes, keep_aspect_ratio_policy=keep_aspect_ratio_policy, ...
= [data, sizes, axes] y = output x[0] = Tensor(Dtype.FP16x16, x[0].shape, to_fp(x[0].flatten(), FixedImpl.FP16x16)) x[1] = Tensor(Dtype.U32, x[1].shape, x[1].flatten()) x[2] = Tensor(Dtype.U32, x[2].shape, x[2].flatten()) y = Tensor(Dtype.FP16x16, y.shape, to_fp(y.flatten()...
name = "resize_downsample_sizes_nearest_not_larger" func_sig = "data.resize(" func_sig += "Option::None," func_sig += "Option::None," func_sig += "sizes," func_sig += "Option::None," func_sig += "axes," func_sig += "Option::None," func_sig += "Option::No...
func_sig += "Option::None," func_sig += "Option::None," func_sig += "Option::Some(KEEP_ASPECT_RATIO_POLICY::NOT_SMALLER)," func_sig += "Option::Some(MODE::NEAREST)," func_sig += "Option::None,)" make_test([x[0], x[1], x[2]], y, func_sig, name) @staticmethod def resize...
ymmetric", ).astype(np.float32) x = [data, scales] y = output for i in range(len(x)): x[i] = Tensor(Dtype.FP16x16, x[i].shape, to_fp(x[i].flatten(), FixedImpl.FP16x16)) y = Tensor(Dtype.FP16x16, y.shape, to_fp(y.flatten(), FixedImpl.FP16x16)) name ...
import numpy as np from nodegen.node
import RunAll from ..helpers
import make_test, to_fp, Tensor, Dtype, FixedImpl
class Reverse_sequence(RunAll): @staticmethod def Reverse_sequence_u32(): def reverse_sequence_u32_4x4_batch(): x = np.array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15], dtype=np.uint32).reshape((4, 4)) y = np.array([0, 1, 2, 3, 5, 4, 6, 7, 10, 9, 8, 11, 15, 14, 13, 12...
name ) def reverse_sequence_u32_3x3_time(): x = np.array([0,1,2,3,4,5,6,7,8], dtype=np.uint32).reshape(3,3) y = np.array([0,7,8,3,4,5,6,1,2], dtype=np.uint32).reshape(3,3) _x = Tensor(Dtype.U32, x.shape, x.flatten()) _y = Tensor(Dtype.U32, y.shape,...
( [_x], _y, "input_0.reverse_sequence(TensorTrait::<usize>::new(array![4].span(), array![4,3,2,1].span()), Option::Some(1), Option::Some(0))", name ) reverse_sequence_i32_batch() reverse_sequence_i32_time() ...
np.array([0, 1, 2, 3, 5, 4, 6, 7, 10, 9, 8, 11, 15, 14, 13, 12], dtype=np.int64).reshape(4, 4), FixedImpl.FP16x16) _x = Tensor(Dtype.FP16x16, x.shape, x.flatten()) _y = Tensor(Dtype.FP16x16, y.shape, y.flatten()) name = "reverse_sequence_fp16x16_batch_equal_parts" make_te...
me(1))", name ) def reverse_sequence_different_dimensions_2_4(): x = np.array([1,2,3,4,5,6,7,8], dtype=np.uint32).reshape(2,4) y = np.array([5,6,7,8,1,2,3,4], dtype=np.uint32).reshape(2,4) _x = Tensor(Dtype.U32, x.shape, x.flatten()) ...
name ) def reverse_sequence_different_dimensions_3x9_time(): x = np.array([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26], dtype=np.uint32).reshape(3,9) y = np.array([18,10,20,12,22,14,24,16,8,9,1,11,3,13,5,15,7,17,0,19,2,21,4,23,6,25,26], dtype=n...
import numpy as np from nodegen.node import RunAll from ..helpers import make_test, to_fp, Tensor, Dtype, FixedImpl class Round(RunAll): @staticmethod def round_fp8x23(): x = np.array([0.1, 0.5, 0.9, 1.2, 1.5, 1.8, 2.3, 2.5, 2.7, -1.1, -1.5, -1.9, -2.2, -2.5, -2.8]).astype(np.float64) y = n...
import os import glob # Directory path where Python files/modules are located directory_path = 'nodegen/node/' # Get all files in the directory all_files = os.listdir(directory_path) # Filter Python files using glob and '*.py' pattern python_files = [file[:-3] for file in all_files if file.endswith('.py')] fixed =...
import numpy as np from nodegen.node
import RunAll from ..helpers
import make_test, to_fp, Tensor, Dtype, FixedImpl, Trait def scatter_elements(data, indices, updates, axis=0, reduction="none"): if axis < 0: axis = data.ndim + axis idx_xsection_shape = indices.shape[:axis] + indices.shape[axis + 1 :] def make_slice(arr, axis, i): slc = [slice(None)...
tes[updates_idx[iter]] ) return scattered
class Scatter(RunAll): @staticmethod def scatter_fp16x16(): def scatter(): def default(): x1 = np.zeros((3, 3)).astype(np.int64) x2 = np.arange(1, 10).reshape((3, 3)).astype(np.int64) x3 = np.array( [[0,1,2...
ices:input_2, axis:Option::Some(1), reduction:Option::Some('none'))", name= name) def axis_1_add(): x1 = np.zeros((3, 3)).astype(np.int64) x2 = np.arange(1, 10).reshape((3, 3)).astype(np.int64) x3 = np.array( ...
ame = "scatter_fp8x23_default" make_test( inputs = [x1, x2, x3], output = y, func_sig = "input_0.scatter(updates:input_1, indices:input_2, axis:Option::Some(0), reduction:Option::Some('none'))", name= name) def axis1(): ...
make_test( inputs = [x1, x2, x3], output = y, func_sig = "input_0.scatter(updates:input_1, indices:input_2, axis:Option::Some(0), reduction:Option::Some('mul'))", name= name) default() axis1() axis1_mul() scatter() ...