repo
stringclasses
454 values
file_path
stringlengths
5
201
extension
stringclasses
1 value
content
stringlengths
8
509k
num_lines
int64
3
16.9k
size_bytes
int64
8
511k
onnx
onnx/reference/ops/op_optional_has_element.py
.py
# Copyright (c) ONNX Project Contributors # SPDX-License-Identifier: Apache-2.0 from __future__ import annotations import numpy as np from onnx.reference.op_run import OpRun class OptionalHasElement(OpRun): def _run(self, x=None): return (np.array(x is not None),)
14
282
onnx
onnx/reference/ops/op_exp.py
.py
# Copyright (c) ONNX Project Contributors # SPDX-License-Identifier: Apache-2.0 from __future__ import annotations import numpy as np from onnx.reference.ops._op import OpRunUnaryNum class Exp(OpRunUnaryNum): def _run(self, x): return (np.exp(x).astype(x.dtype),)
14
281
onnx
onnx/reference/ops/op_gru.py
.py
# Copyright (c) ONNX Project Contributors # SPDX-License-Identifier: Apache-2.0 from __future__ import annotations import numpy as np from onnx.reference.op_run import OpRun class CommonGRU(OpRun): def __init__(self, onnx_node, run_params): OpRun.__init__(self, onnx_node, run_params) self.n_out...
188
5,444
onnx
onnx/reference/ops/op_cos.py
.py
# Copyright (c) ONNX Project Contributors # SPDX-License-Identifier: Apache-2.0 from __future__ import annotations import numpy as np from onnx.reference.ops._op import OpRunUnaryNum class Cos(OpRunUnaryNum): def _run(self, x): return (np.cos(x),)
14
265
onnx
onnx/reference/ops/op_lrn.py
.py
# Copyright (c) ONNX Project Contributors # SPDX-License-Identifier: Apache-2.0 from __future__ import annotations import math import numpy as np from onnx.reference.op_run import OpRun class LRN(OpRun): def _run(self, x, alpha=None, beta=None, bias=None, size=None): if len(x.shape) != 4: ...
29
880
onnx
onnx/reference/ops/op_qlinear_matmul.py
.py
# Copyright (c) ONNX Project Contributors # SPDX-License-Identifier: Apache-2.0 from __future__ import annotations import numpy as np from onnx.reference.op_run import OpRun class QLinearMatMul(OpRun): def _run( self, a, a_scale, a_zero_point, b, b_scale, b_zero_point, y_scale, y_zero_point ): ...
30
894
onnx
onnx/reference/ops/op_cum_sum.py
.py
# Copyright (c) ONNX Project Contributors # SPDX-License-Identifier: Apache-2.0 from __future__ import annotations import numpy as np from onnx.reference.op_run import OpRun class CumSum(OpRun): def _run(self, x, axis, exclusive=None, reverse=None): axis = np.asarray(axis) if axis.ndim != 0: ...
32
1,085
onnx
onnx/reference/ops/op_atan.py
.py
# Copyright (c) ONNX Project Contributors # SPDX-License-Identifier: Apache-2.0 from __future__ import annotations import numpy as np from onnx.reference.ops._op import OpRunUnaryNum class Atan(OpRunUnaryNum): def _run(self, x): return (np.arctan(x),)
14
269
onnx
onnx/reference/ops/_op_common_window.py
.py
# Copyright (c) ONNX Project Contributors # SPDX-License-Identifier: Apache-2.0 from __future__ import annotations import numpy as np from onnx.helper import tensor_dtype_to_np_dtype from onnx.reference.op_run import OpRun class _CommonWindow(OpRun): @staticmethod def _begin(size, periodic, output_datatype...
27
750
onnx
onnx/reference/ops/op_lp_pool.py
.py
# Copyright (c) ONNX Project Contributors # SPDX-License-Identifier: Apache-2.0 from __future__ import annotations import numpy as np from onnx.reference.ops.op_pool_common import CommonPool class LpPool(CommonPool): def _run( self, x, auto_pad=None, ceil_mode=None, dila...
44
1,252
onnx
onnx/reference/ops/op_topk.py
.py
# Copyright (c) ONNX Project Contributors # SPDX-License-Identifier: Apache-2.0 from __future__ import annotations import numpy as np from onnx.reference.op_run import OpRun def topk_sorted_implementation(X, k, axis, largest): """See function `_kneighbors_reduce_func <https://github.com/scikit-learn/scikit...
111
4,040
onnx
onnx/reference/ops/op_attribute_has_value.py
.py
# Copyright (c) ONNX Project Contributors # SPDX-License-Identifier: Apache-2.0 from __future__ import annotations import numpy as np from onnx.reference.op_run import OpRun class AttributeHasValue(OpRun): def _run( self, value_float=None, # noqa: ARG002 value_floats=None, # noqa: ARG...
34
1,084
onnx
onnx/reference/ops/op_tile.py
.py
# Copyright (c) ONNX Project Contributors # SPDX-License-Identifier: Apache-2.0 from __future__ import annotations import numpy as np from onnx.reference.op_run import OpRun class Tile(OpRun): def _run(self, x, repeats): return (np.tile(x, repeats),)
14
268
onnx
onnx/reference/ops/op_concat.py
.py
# Copyright (c) ONNX Project Contributors # SPDX-License-Identifier: Apache-2.0 from __future__ import annotations import numpy as np from onnx.reference.op_run import OpRun class Concat(OpRun): def _preprocess(self, a: np.ndarray, axis: int) -> np.ndarray: if len(a.shape) == 0: raise Runti...
23
682
onnx
onnx/reference/ops/op_eyelike.py
.py
# Copyright (c) ONNX Project Contributors # SPDX-License-Identifier: Apache-2.0 from __future__ import annotations import numpy as np from onnx.helper import tensor_dtype_to_np_dtype from onnx.onnx_pb import TensorProto from onnx.reference.op_run import OpRun class EyeLike(OpRun): def _run(self, data, *args, d...
32
991
onnx
onnx/reference/ops/op_min.py
.py
# Copyright (c) ONNX Project Contributors # SPDX-License-Identifier: Apache-2.0 from __future__ import annotations import numpy as np from onnx.reference.ops._op import OpRunBinaryNumpy class Min(OpRunBinaryNumpy): def __init__(self, onnx_node, run_params): OpRunBinaryNumpy.__init__(self, np.minimum, o...
26
729
onnx
onnx/reference/ops/op_mean.py
.py
# Copyright (c) ONNX Project Contributors # SPDX-License-Identifier: Apache-2.0 from __future__ import annotations from onnx.reference.op_run import OpRun class Mean(OpRun): def _run(self, *args): res = args[0].copy() for m in args[1:]: res += m return ((res / len(args)).asty...
15
340
onnx
onnx/reference/ops/op_average_pool.py
.py
# Copyright (c) ONNX Project Contributors # SPDX-License-Identifier: Apache-2.0 from __future__ import annotations from onnx.reference.ops.op_pool_common import CommonPool class AveragePool_1(CommonPool): def _run( self, x, auto_pad=None, ceil_mode=None, kernel_shape=None...
108
2,349
onnx
onnx/reference/ops/op_gathernd.py
.py
# Copyright (c) ONNX Project Contributors # SPDX-License-Identifier: Apache-2.0 from __future__ import annotations import numpy as np from onnx.reference.op_run import OpRun def _gather_nd_impl( data: np.ndarray, indices: np.ndarray, batch_dims: int ) -> tuple[np.ndarray]: # Note the data rank - will be re...
59
1,992
onnx
onnx/reference/ops/op_causal_conv_with_state.py
.py
# Copyright (c) ONNX Project Contributors # SPDX-License-Identifier: Apache-2.0 from __future__ import annotations import numpy as np from onnx.reference.op_run import OpRun from onnx.reference.ops.op_conv import _conv_implementation class CausalConvWithState(OpRun): def _run( self, input, ...
72
2,163
onnx
onnx/reference/ops/op_linear_attention.py
.py
# Copyright (c) ONNX Project Contributors # SPDX-License-Identifier: Apache-2.0 from __future__ import annotations import numpy as np from onnx.reference.op_run import OpRun def _unpack_3d_to_4d(x: np.ndarray, num_heads: int) -> np.ndarray: """Reshape (B, T, H*D) -> (B, H, T, D).""" b, t, hd = x.shape ...
182
7,881
onnx
onnx/reference/ops/op_concat_from_sequence.py
.py
# Copyright (c) ONNX Project Contributors # SPDX-License-Identifier: Apache-2.0 from __future__ import annotations from typing import Any import numpy as np from onnx.reference.op_run import OpRun def _concat_from_sequence(seq: list[Any], axis: int, new_axis: int = 0) -> np.ndarray: if new_axis == 1: ...
32
887
onnx
onnx/reference/ops/op_lstm.py
.py
# Copyright (c) ONNX Project Contributors # SPDX-License-Identifier: Apache-2.0 from __future__ import annotations import numpy as np from onnx.reference.op_run import OpRun class CommonLSTM(OpRun): def __init__(self, onnx_node, run_params): OpRun.__init__(self, onnx_node, run_params) self.n_ou...
213
6,254
onnx
onnx/reference/ops/op_bitwise_or.py
.py
# Copyright (c) ONNX Project Contributors # SPDX-License-Identifier: Apache-2.0 from __future__ import annotations import numpy as np from onnx.reference.ops._op import OpRunBinary class BitwiseOr(OpRunBinary): def _run(self, x, y): return (np.bitwise_or(x, y),)
14
280
onnx
onnx/reference/ops/op_less_or_equal.py
.py
# Copyright (c) ONNX Project Contributors # SPDX-License-Identifier: Apache-2.0 from __future__ import annotations import numpy as np from onnx.reference.ops._op import OpRunBinaryComparison class LessOrEqual(OpRunBinaryComparison): def _run(self, a, b): return (np.less_equal(a, b),)
14
302
onnx
onnx/reference/ops/op_random_uniform.py
.py
# Copyright (c) ONNX Project Contributors # SPDX-License-Identifier: Apache-2.0 from __future__ import annotations from onnx.reference.ops._op_common_random import _CommonRandom class RandomUniform(_CommonRandom): def _run(self, dtype=None, high=None, low=None, seed=None, shape=None): dtype = self._dtyp...
17
501
onnx
onnx/reference/ops/op_hard_sigmoid.py
.py
# Copyright (c) ONNX Project Contributors # SPDX-License-Identifier: Apache-2.0 from __future__ import annotations import numpy as np from onnx.reference.ops._op import OpRunUnaryNum class HardSigmoid(OpRunUnaryNum): def _run(self, x, alpha=None, beta=None): alpha = alpha or self.alpha beta = b...
17
432
onnx
onnx/reference/ops/_helpers.py
.py
# Copyright (c) ONNX Project Contributors # # SPDX-License-Identifier: Apache-2.0 from __future__ import annotations from typing import Any from onnx.reference.op_run import OpRun def _split_class_name(name): if "_" in name: prefix, vers = name.rsplit("_", maxsplit=1) try: v = int(ve...
68
2,139
onnx
onnx/reference/ops/op_reduce_sum.py
.py
# Copyright (c) ONNX Project Contributors # SPDX-License-Identifier: Apache-2.0 from __future__ import annotations import numpy as np from onnx.reference.ops._op import OpRunReduceNumpy class ReduceSum_1(OpRunReduceNumpy): def _run(self, x, axes=None, keepdims=None): axes = tuple(axes) if axes is not N...
36
1,249
onnx
onnx/reference/ops/op_einsum.py
.py
# Copyright (c) ONNX Project Contributors # SPDX-License-Identifier: Apache-2.0 from __future__ import annotations import numpy as np from onnx.reference.op_run import OpRun class Einsum(OpRun): def _run(self, *args, equation=None): if not isinstance(equation, str): raise TypeError(f"equati...
22
630
onnx
onnx/reference/ops/op_one_hot.py
.py
# Copyright (c) ONNX Project Contributors # SPDX-License-Identifier: Apache-2.0 from __future__ import annotations import numpy as np from onnx.reference.op_run import OpRun def _one_hot(indices, depth, axis=-1, dtype=np.float32): values = np.asarray(indices) rank = len(values.shape) depth_range = np.a...
33
1,057
onnx
onnx/reference/ops/_op_common_pool.py
.py
# Copyright (c) ONNX Project Contributors # SPDX-License-Identifier: Apache-2.0 from __future__ import annotations import itertools import numpy as np from onnx.reference.op_run import OpRun from onnx.reference.ops._op_common_indices import _get_index, _get_indices def _get_pad_shape( auto_pad: str, input...
302
10,283
onnx
onnx/reference/ops/op_tan.py
.py
# Copyright (c) ONNX Project Contributors # SPDX-License-Identifier: Apache-2.0 from __future__ import annotations import numpy as np from onnx.reference.ops._op import OpRunUnaryNum class Tan(OpRunUnaryNum): def _run(self, x): return (np.tan(x),)
14
265
onnx
onnx/reference/ops/op_reduce_max.py
.py
# Copyright (c) ONNX Project Contributors # SPDX-License-Identifier: Apache-2.0 from __future__ import annotations import numpy as np from onnx.reference.ops._op import OpRunReduceNumpy class ReduceMax_1(OpRunReduceNumpy): def _run(self, data, axes=None, keepdims=None): axes = tuple(axes) if axes is no...
47
1,605
onnx
onnx/reference/ops/op_gemm.py
.py
# Copyright (c) ONNX Project Contributors # SPDX-License-Identifier: Apache-2.0 from __future__ import annotations import numpy as np from onnx.reference.op_run import OpRun def _gemm00(a, b, c, alpha, beta): o = np.dot(a, b) * alpha if c is not None and beta != 0: o += c * beta return o def ...
78
1,945
onnx
onnx/reference/ops/op_string_normalizer.py
.py
# Copyright (c) ONNX Project Contributors # SPDX-License-Identifier: Apache-2.0 from __future__ import annotations import locale as pylocale import unicodedata import warnings import numpy as np from onnx.reference.op_run import OpRun, RuntimeTypeError class StringNormalizer(OpRun): """The operator is not rea...
150
4,941
onnx
onnx/reference/ops/op_pow.py
.py
# Copyright (c) ONNX Project Contributors # SPDX-License-Identifier: Apache-2.0 from __future__ import annotations from warnings import catch_warnings, simplefilter import numpy as np from onnx.reference.op_run import OpRun class Pow(OpRun): def _run(self, a, b): with catch_warnings(): sim...
18
393
onnx
onnx/reference/ops/op_flatten.py
.py
# Copyright (c) ONNX Project Contributors # SPDX-License-Identifier: Apache-2.0 from __future__ import annotations import numpy as np from onnx.reference.ops._op import OpRunUnary class Flatten(OpRunUnary): def _run(self, x, axis=None): i = axis or self.axis shape = x.shape new_shape = ...
17
419
onnx
onnx/reference/ops/op_lp_normalization.py
.py
# Copyright (c) ONNX Project Contributors # SPDX-License-Identifier: Apache-2.0 from __future__ import annotations import numpy as np from onnx.reference.ops._op import OpRunUnaryNum class LpNormalization(OpRunUnaryNum): def _run(self, x, axis=None, p=None): axis = axis or self.axis p = p or se...
20
582
onnx
onnx/reference/ops/op_bitwise_xor.py
.py
# Copyright (c) ONNX Project Contributors # SPDX-License-Identifier: Apache-2.0 from __future__ import annotations import numpy as np from onnx.reference.ops._op import OpRunBinary class BitwiseXor(OpRunBinary): def _run(self, x, y): return (np.bitwise_xor(x, y),)
14
282
onnx
onnx/reference/ops/op_greater_or_equal.py
.py
# Copyright (c) ONNX Project Contributors # SPDX-License-Identifier: Apache-2.0 from __future__ import annotations import numpy as np from onnx.reference.ops._op import OpRunBinaryComparison class GreaterOrEqual(OpRunBinaryComparison): def _run(self, a, b): return (np.greater_equal(a, b),)
14
308
onnx
onnx/reference/ops/op_swish.py
.py
# Copyright (c) ONNX Project Contributors # SPDX-License-Identifier: Apache-2.0 from __future__ import annotations import numpy as np from onnx.reference.ops._op import OpRunUnaryNum class Swish(OpRunUnaryNum): def _run(self, x, alpha=None): alpha = self.alpha if alpha is None else alpha return...
15
375
onnx
onnx/reference/ops/op_split_to_sequence.py
.py
# Copyright (c) ONNX Project Contributors # SPDX-License-Identifier: Apache-2.0 from __future__ import annotations from typing import TYPE_CHECKING from onnx.reference.op_run import OpRun if TYPE_CHECKING: import numpy as np class SplitToSequence(OpRun): def common_run( self, mat: np.ndarray, spli...
55
1,528
onnx
onnx/reference/ops/op_relu.py
.py
# Copyright (c) ONNX Project Contributors # SPDX-License-Identifier: Apache-2.0 from __future__ import annotations import numpy as np from onnx.reference.ops._op import OpRunUnaryNum class Relu(OpRunUnaryNum): def _run(self, x): return (np.maximum(x, 0).astype(x.dtype),)
14
289
onnx
onnx/reference/ops/op_split.py
.py
# Copyright (c) ONNX Project Contributors # SPDX-License-Identifier: Apache-2.0 from __future__ import annotations from onnx.reference.op_run import OpRun class CommonSplit(OpRun): def __init__(self, onnx_node, run_params): OpRun.__init__(self, onnx_node, run_params) self.n_outputs = len(onnx_no...
52
1,535
onnx
onnx/reference/ops/op_reduce_l2.py
.py
# Copyright (c) ONNX Project Contributors # SPDX-License-Identifier: Apache-2.0 from __future__ import annotations import numpy as np from onnx.reference.ops._op import OpRunReduceNumpy class ReduceL2_1(OpRunReduceNumpy): def _run(self, data, axes=None, keepdims=None): axes = tuple(axes) if axes is not...
35
1,164
onnx
onnx/reference/ops/op_layer_normalization.py
.py
# Copyright (c) ONNX Project Contributors # SPDX-License-Identifier: Apache-2.0 from __future__ import annotations import numpy as np from onnx.reference.op_run import OpRun def _layer_normalization( X: np.ndarray, W: np.ndarray, B: np.ndarray, axis: int = -1, epsilon: float = 1e-5, ) -> tuple[...
74
2,595
onnx
onnx/reference/ops/op_log_softmax.py
.py
# Copyright (c) ONNX Project Contributors # SPDX-License-Identifier: Apache-2.0 from __future__ import annotations import numpy as np from onnx.reference.ops.op_softmax import Softmax class LogSoftmax(Softmax): def _run(self, X): Y = Softmax._run(self, X)[0] np.log(Y, out=Y) return (Y,)...
16
321
onnx
onnx/reference/ops/op_sequence_construct.py
.py
# Copyright (c) ONNX Project Contributors # SPDX-License-Identifier: Apache-2.0 from __future__ import annotations from onnx.reference.op_run import OpRun class SequenceConstruct(OpRun): def _run(self, *data): return (list(data),)
12
247
onnx
onnx/reference/ops/op_attention.py
.py
# Copyright (c) ONNX Project Contributors # SPDX-License-Identifier: Apache-2.0 from __future__ import annotations import numpy as np import onnx from onnx.reference.op_run import OpRun def _softmax(x: np.ndarray, axis: int = -1) -> np.ndarray: x_max = np.max(x, axis=axis, keepdims=True) # A fully-masked r...
337
14,743
onnx
onnx/reference/ops/op_sum.py
.py
# Copyright (c) ONNX Project Contributors # SPDX-License-Identifier: Apache-2.0 from __future__ import annotations from onnx.reference.op_run import OpRun class Sum(OpRun): def _run(self, *args): return (sum(args).astype(args[0].dtype),)
12
254
onnx
onnx/reference/ops/op_add.py
.py
# Copyright (c) ONNX Project Contributors # SPDX-License-Identifier: Apache-2.0 from __future__ import annotations import numpy as np from onnx.reference.ops._op import OpRunBinaryNumpy class Add(OpRunBinaryNumpy): def __init__(self, onnx_node, run_params): OpRunBinaryNumpy.__init__(self, np.add, onnx_...
14
338
onnx
onnx/reference/ops/op_roi_align.py
.py
# Copyright (c) ONNX Project Contributors # SPDX-License-Identifier: Apache-2.0 from __future__ import annotations import numpy as np from onnx.reference.op_run import OpRun class PreCalc: def __init__(self, pos1=0, pos2=0, pos3=0, pos4=0, w1=0, w2=0, w3=0, w4=0): self.pos1 = pos1 self.pos2 = p...
297
10,843
onnx
onnx/reference/ops/op_dequantize_linear.py
.py
# Copyright (c) ONNX Project Contributors # SPDX-License-Identifier: Apache-2.0 from __future__ import annotations import numpy as np from onnx import TensorProto from onnx.helper import np_dtype_to_tensor_dtype, tensor_dtype_to_np_dtype from onnx.reference.op_run import OpRun from onnx.reference.ops._quant_utils im...
92
3,182
onnx
onnx/reference/ops/op_floor.py
.py
# Copyright (c) ONNX Project Contributors # SPDX-License-Identifier: Apache-2.0 from __future__ import annotations import numpy as np from onnx.reference.ops._op import OpRunUnaryNum class Floor(OpRunUnaryNum): def _run(self, x): return (np.floor(x),)
14
269
onnx
onnx/reference/ops/op_bitwise_not.py
.py
# Copyright (c) ONNX Project Contributors # SPDX-License-Identifier: Apache-2.0 from __future__ import annotations import numpy as np from onnx.reference.ops._op import OpRunUnary class BitwiseNot(OpRunUnary): def _run(self, X): return (np.bitwise_not(X),)
14
274
onnx
onnx/reference/ops/op_sequence_length.py
.py
# Copyright (c) ONNX Project Contributors # SPDX-License-Identifier: Apache-2.0 from __future__ import annotations import numpy as np from onnx.reference.op_run import OpRun class SequenceLength(OpRun): def _run(self, input_sequence): if not isinstance(input_sequence, list): raise TypeError...
18
477
onnx
onnx/reference/ops/op_sign.py
.py
# Copyright (c) ONNX Project Contributors # SPDX-License-Identifier: Apache-2.0 from __future__ import annotations import numpy as np from onnx.reference.ops._op import OpRunUnaryNum class Sign(OpRunUnaryNum): def _run(self, x): return (np.sign(x),)
14
267
onnx
onnx/reference/ops/op_transpose.py
.py
# Copyright (c) ONNX Project Contributors # SPDX-License-Identifier: Apache-2.0 from __future__ import annotations import numpy as np from onnx.reference.op_run import OpRun class Transpose(OpRun): def _run(self, data, perm=None): perm_ = None if (perm is None or len(perm) == 0) else perm if pe...
21
592
onnx
onnx/reference/ops/op_col2im.py
.py
# Copyright (c) ONNX Project Contributors # SPDX-License-Identifier: Apache-2.0 from __future__ import annotations import numpy as np from onnx.reference.op_run import OpRun from onnx.reference.ops._op_common_indices import _get_indices, _is_out def _col2im_shape_check_2d(X, output_shape, kernel_shape, dilations, ...
214
7,976
onnx
onnx/reference/ops/op_xor.py
.py
# Copyright (c) ONNX Project Contributors # SPDX-License-Identifier: Apache-2.0 from __future__ import annotations import numpy as np from onnx.reference.ops._op import OpRunBinary class Xor(OpRunBinary): def _run(self, x, y): return (np.logical_xor(x, y),)
14
275
onnx
onnx/reference/ops/op_asinh.py
.py
# Copyright (c) ONNX Project Contributors # SPDX-License-Identifier: Apache-2.0 from __future__ import annotations import numpy as np from onnx.reference.ops._op import OpRunUnaryNum class Asinh(OpRunUnaryNum): def _run(self, x): return (np.arcsinh(x),)
14
271
onnx
onnx/reference/ops/op_reverse_sequence.py
.py
# Copyright (c) ONNX Project Contributors # SPDX-License-Identifier: Apache-2.0 from __future__ import annotations from onnx.reference.op_run import OpRun class ReverseSequence(OpRun): def _run(self, data, sequence_lens, batch_axis=None, time_axis=None): index = [slice(0, s) for s in data.shape] ...
21
705
onnx
onnx/reference/ops/op_acosh.py
.py
# Copyright (c) ONNX Project Contributors # SPDX-License-Identifier: Apache-2.0 from __future__ import annotations import numpy as np from onnx.reference.ops._op import OpRunUnaryNum class Acosh(OpRunUnaryNum): def _run(self, x): return (np.arccosh(x),)
14
271
onnx
onnx/reference/ops/op_max_unpool.py
.py
# Copyright (c) ONNX Project Contributors # SPDX-License-Identifier: Apache-2.0 from __future__ import annotations import numpy as np from onnx.reference.op_run import OpRun class MaxUnpool(OpRun): def _run( self, X, indices, output_shape=None, kernel_shape=None, pads=None, strides=None ): ...
59
1,794
onnx
onnx/reference/ops/op_quantize_linear.py
.py
# Copyright (c) ONNX Project Contributors # SPDX-License-Identifier: Apache-2.0 from __future__ import annotations import numpy as np import onnx from onnx import TensorProto from onnx.helper import ( np_dtype_to_tensor_dtype, tensor_dtype_to_np_dtype, ) from onnx.reference.op_run import OpRun from onnx.re...
191
5,708
onnx
onnx/reference/ops/op_scan.py
.py
# Copyright (c) ONNX Project Contributors # SPDX-License-Identifier: Apache-2.0 from __future__ import annotations import numpy as np from onnx.reference.op_run import OpRun class Scan(OpRun): def __init__(self, onnx_node, run_params): OpRun.__init__(self, onnx_node, run_params) if not hasattr(...
182
6,573
onnx
onnx/reference/ops/_op_common_random.py
.py
# Copyright (c) ONNX Project Contributors # SPDX-License-Identifier: Apache-2.0 from __future__ import annotations import numpy as np from onnx.helper import tensor_dtype_to_np_dtype from onnx.reference.op_run import OpRun class _CommonRandom(OpRun): def __init__(self, onnx_node, run_params): OpRun.__i...
56
1,771
onnx
onnx/reference/ops/op_prelu.py
.py
# Copyright (c) ONNX Project Contributors # SPDX-License-Identifier: Apache-2.0 from __future__ import annotations import numpy as np from onnx.reference.op_run import OpRun class PRelu(OpRun): def _run(self, x, slope): try: return (np.where(x > 0, x, x * slope).astype(x.dtype),) ex...
35
1,170
onnx
onnx/reference/ops/op_conv_integer.py
.py
# Copyright (c) ONNX Project Contributors # SPDX-License-Identifier: Apache-2.0 from __future__ import annotations import numpy as np from onnx.reference.op_run import OpRun from onnx.reference.ops.op_conv import _conv_implementation class ConvInteger(OpRun): def _run( self, X, W, ...
53
1,436
onnx
onnx/reference/ops/op_grid_sample.py
.py
# Copyright (c) ONNX Project Contributors # SPDX-License-Identifier: Apache-2.0 from __future__ import annotations import numbers import numpy as np from onnx.reference.op_run import OpRun from onnx.reference.ops.op_resize import _get_all_coords class GridSample(OpRun): # https://github.com/pytorch/pytorch/bl...
366
13,169
onnx
onnx/reference/ops/op_sqrt.py
.py
# Copyright (c) ONNX Project Contributors # SPDX-License-Identifier: Apache-2.0 from __future__ import annotations from warnings import catch_warnings, simplefilter import numpy as np from onnx.reference.ops._op import OpRunUnaryNum class Sqrt(OpRunUnaryNum): def _run(self, x): with catch_warnings(): ...
18
404
onnx
onnx/reference/ops/op_selu.py
.py
# Copyright (c) ONNX Project Contributors # SPDX-License-Identifier: Apache-2.0 from __future__ import annotations import numpy as np from onnx.reference.op_run import OpRun class Selu(OpRun): def _run(self, x, alpha=None, gamma=None): return ( (np.where(x > 0, x, np.exp(x) * alpha - alpha)...
16
357
onnx
onnx/reference/ops/op_upsample.py
.py
# Copyright (c) ONNX Project Contributors # SPDX-License-Identifier: Apache-2.0 from __future__ import annotations import numpy as np from onnx.reference.op_run import OpRun class Upsample(OpRun): def _run(self, x, scale, mode=None): if mode == "nearest" and scale.astype(np.int64).tolist() == scale.tol...
21
608
onnx
onnx/reference/ops/op_sequence_insert.py
.py
# Copyright (c) ONNX Project Contributors # SPDX-License-Identifier: Apache-2.0 from __future__ import annotations from typing import Any import numpy as np from onnx.reference.op_run import OpRun def sequence_insert_reference_implementation( sequence: list[Any] | np.ndarray, tensor: np.ndarray, posit...
53
1,796
onnx
onnx/reference/ops/op_constant.py
.py
# Copyright (c) ONNX Project Contributors # SPDX-License-Identifier: Apache-2.0 from __future__ import annotations import numpy as np from onnx.reference.op_run import OpRun, RefAttrName def _check_dtype(val): dtype = val.dtype if not isinstance(dtype, np.dtype): raise TypeError( f"Type...
120
4,332
onnx
onnx/reference/ops/op_mel_weight_matrix.py
.py
# Copyright (c) ONNX Project Contributors # SPDX-License-Identifier: Apache-2.0 from __future__ import annotations import numpy as np from onnx.helper import tensor_dtype_to_np_dtype from onnx.reference.op_run import OpRun class MelWeightMatrix(OpRun): def _run( self, num_mel_bins, dft_...
62
2,353
onnx
onnx/reference/ops/op_cast.py
.py
# Copyright (c) ONNX Project Contributors # SPDX-License-Identifier: Apache-2.0 from __future__ import annotations import numpy as np import onnx from onnx.reference.op_run import OpRun def cast_to( x: np.ndarray, to: onnx.TensorProto.DataType, saturate: bool, round_mode: str = "up" ): if to == onnx.Tensor...
55
1,417
onnx
onnx/reference/ops/op_image_decoder.py
.py
# Copyright (c) ONNX Project Contributors # SPDX-License-Identifier: Apache-2.0 from __future__ import annotations import io import numpy as np from onnx.reference.op_run import OpRun class ImageDecoder(OpRun): def _run(self, encoded: np.ndarray, pixel_format="RGB") -> tuple[np.ndarray]: try: ...
34
1,077
onnx
onnx/reference/ops/op_if.py
.py
# Copyright (c) ONNX Project Contributors # SPDX-License-Identifier: Apache-2.0 from __future__ import annotations from typing import TYPE_CHECKING from onnx.reference.op_run import OpRun if TYPE_CHECKING: import numpy as np class If(OpRun): def __init__(self, onnx_node, run_params): OpRun.__init...
73
2,578
onnx
onnx/reference/ops/op_reduce_mean.py
.py
# Copyright (c) ONNX Project Contributors # SPDX-License-Identifier: Apache-2.0 from __future__ import annotations import numpy as np from onnx.reference.ops._op import OpRunReduceNumpy class ReduceMean_1(OpRunReduceNumpy): def _run(self, data, axes=None, keepdims=None): axes = tuple(axes) if axes is n...
36
1,283
onnx
onnx/reference/ops/op_blackman_window.py
.py
# Copyright (c) ONNX Project Contributors # SPDX-License-Identifier: Apache-2.0 from __future__ import annotations import numpy as np from onnx.reference.ops._op_common_window import _CommonWindow class BlackmanWindow(_CommonWindow): r"""Blankman windowing function. Returns :math:`\\omega_n = 0.42 - 0.5 \...
31
945
onnx
onnx/reference/ops/op_div.py
.py
# Copyright (c) ONNX Project Contributors # SPDX-License-Identifier: Apache-2.0 from __future__ import annotations import numpy as np from onnx.reference.ops._op import OpRunBinaryNumpy class Div(OpRunBinaryNumpy): def __init__(self, onnx_node, run_params): def func(x, y): if issubclass(x.d...
31
1,034
onnx
onnx/reference/ops/op_trilu.py
.py
# Copyright (c) ONNX Project Contributors # SPDX-License-Identifier: Apache-2.0 from __future__ import annotations import numpy as np from onnx.reference.op_run import OpRun class Trilu(OpRun): def _run(self, x, k=None, upper=None): k = 0 if k is None else k.item() if upper: return ...
17
385
onnx
onnx/reference/ops/op_bitshift.py
.py
# Copyright (c) ONNX Project Contributors # SPDX-License-Identifier: Apache-2.0 from __future__ import annotations import numpy as np from onnx.reference.ops._op import OpRunBinaryNumpy class BitShift(OpRunBinaryNumpy): def __init__(self, onnx_node, run_params): OpRunBinaryNumpy.__init__(self, np.right...
18
569
onnx
onnx/reference/ops/op_depth_to_space.py
.py
# Copyright (c) ONNX Project Contributors # SPDX-License-Identifier: Apache-2.0 from __future__ import annotations import numpy as np from onnx.reference.op_run import OpRun class DepthToSpace(OpRun): def _run(self, data, blocksize=None, mode=None): if len(data.shape) != 4: raise RuntimeErr...
47
1,298
onnx
onnx/reference/ops/op_shrink.py
.py
# Copyright (c) ONNX Project Contributors # SPDX-License-Identifier: Apache-2.0 from __future__ import annotations import numpy as np from onnx.reference.op_run import OpRun class Shrink(OpRun): def _run(self, x, bias=None, lambd=None): return ( np.where( x < -lambd, ...
20
430
onnx
onnx/reference/ops/op_sigmoid.py
.py
# Copyright (c) ONNX Project Contributors # SPDX-License-Identifier: Apache-2.0 from __future__ import annotations import numpy as np from onnx.reference.ops._op import OpRunUnaryNum def sigmoid(x: np.ndarray) -> np.ndarray: """Numerically stable sigmoid implementation that supports scalars and nd-arrays.""" ...
28
680
onnx
onnx/reference/ops/op_constant_of_shape.py
.py
# Copyright (c) ONNX Project Contributors # SPDX-License-Identifier: Apache-2.0 from __future__ import annotations import numpy as np from onnx.reference.op_run import OpRun class ConstantOfShape(OpRun): def _run(self, data, value: np.array | None = None): if self.value is None: value = np....
30
951
onnx
onnx/reference/ops/op_reciprocal.py
.py
# Copyright (c) ONNX Project Contributors # SPDX-License-Identifier: Apache-2.0 from __future__ import annotations import numpy as np from onnx.reference.ops._op import OpRunUnaryNum class Reciprocal(OpRunUnaryNum): def _run(self, x): with np.errstate(divide="ignore"): return (np.reciprocal...
15
342
onnx
onnx/reference/ops/op_mod.py
.py
# Copyright (c) ONNX Project Contributors # SPDX-License-Identifier: Apache-2.0 from __future__ import annotations import numpy as np from onnx.reference.op_run import OpRun class Mod(OpRun): def _run(self, a, b, fmod=None): fmod = fmod or self.fmod if fmod == 1: return (np.fmod(a, ...
19
482
onnx
onnx/reference/ops/op_det.py
.py
# Copyright (c) ONNX Project Contributors # SPDX-License-Identifier: Apache-2.0 from __future__ import annotations import numpy as np from onnx.reference.op_run import OpRun class Det(OpRun): def _run(self, x): return (np.array(np.linalg.det(x)),)
14
265
onnx
onnx/reference/ops/op_random_normal_like.py
.py
# Copyright (c) ONNX Project Contributors # SPDX-License-Identifier: Apache-2.0 from __future__ import annotations from onnx.helper import np_dtype_to_tensor_dtype from onnx.reference.ops._op_common_random import _CommonRandom class RandomNormalLike(_CommonRandom): def _run(self, x, dtype=None, mean=None, scale...
20
628
onnx
onnx/reference/ops/_op.py
.py
# Copyright (c) ONNX Project Contributors # SPDX-License-Identifier: Apache-2.0 from __future__ import annotations from typing import TYPE_CHECKING, Any import numpy as np from onnx.reference.op_run import OpRun, RuntimeTypeError if TYPE_CHECKING: from onnx.onnx_pb import NodeProto class OpRunUnary(OpRun): ...
183
6,219
onnx
onnx/reference/ops/op_squeeze.py
.py
# Copyright (c) ONNX Project Contributors # SPDX-License-Identifier: Apache-2.0 from __future__ import annotations import numpy as np from onnx.reference.op_run import OpRun class Squeeze_1(OpRun): def _run(self, data, axes=None): if isinstance(axes, np.ndarray): axes = tuple(axes) ...
46
1,154
onnx
onnx/reference/ops/op_conv.py
.py
# Copyright (c) ONNX Project Contributors # SPDX-License-Identifier: Apache-2.0 from __future__ import annotations import numpy as np from onnx.reference.op_run import OpRun def _conv_implementation( X, W, B, auto_pad, dilations, group, kernel_shape, pads, strides ): if dilations is None: dilations...
317
13,111
onnx
onnx/reference/ops/op_batch_normalization.py
.py
# Copyright (c) ONNX Project Contributors # SPDX-License-Identifier: Apache-2.0 from __future__ import annotations import numpy as np from onnx.reference.op_run import OpRun def _batchnorm_test_mode( x: np.ndarray, s: np.ndarray, bias: np.ndarray, mean: np.ndarray, var: np.ndarray, epsilon:...
102
3,018
onnx
onnx/reference/ops/op_global_average_pool.py
.py
# Copyright (c) ONNX Project Contributors # SPDX-License-Identifier: Apache-2.0 from __future__ import annotations import numpy as np from onnx.reference.op_run import OpRun def _global_average_pool(x: np.ndarray) -> np.ndarray: axis = tuple(range(2, np.ndim(x))) y = np.average(x, axis=axis) for _ in a...
22
487
onnx
onnx/reference/ops/op_sequence_map.py
.py
# Copyright (c) ONNX Project Contributors # SPDX-License-Identifier: Apache-2.0 from __future__ import annotations from onnx.reference.op_run import OpRun class SequenceMap(OpRun): def _run(self, input_sequence, *additional_inputs, body=None, attributes=None): if len(additional_inputs) == 1 and isinstan...
34
1,245
onnx
onnx/reference/ops/op_stft.py
.py
# Copyright (c) ONNX Project Contributors # SPDX-License-Identifier: Apache-2.0 from __future__ import annotations import numpy as np from onnx.reference.op_run import OpRun from onnx.reference.ops.op_concat_from_sequence import _concat_from_sequence from onnx.reference.ops.op_dft import _cfft as _dft from onnx.refe...
168
5,349