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/version.py
.py
# Copyright (c) ONNX Project Contributors # # SPDX-License-Identifier: Apache-2.0 """Backward-compatibility shim for onnx.version. This module is deprecated. Use ``onnx.__version__`` instead. """ from __future__ import annotations import warnings from onnx import __version__ as version warnings.warn( "onnx.ve...
25
473
onnx
onnx/gen_proto.py
.py
#!/usr/bin/env python # Copyright (c) ONNX Project Contributors # # SPDX-License-Identifier: Apache-2.0 from __future__ import annotations import argparse import glob import os import re import subprocess from textwrap import dedent from typing import TYPE_CHECKING if TYPE_CHECKING: from collections.abc import I...
273
8,718
onnx
onnx/checker.py
.py
# Copyright (c) ONNX Project Contributors # # SPDX-License-Identifier: Apache-2.0 """Graph utilities for checking whether an ONNX proto message is legal.""" from __future__ import annotations __all__ = [ "check_attribute", "check_function", "check_graph", "check_model", "check_node", "check_sp...
172
5,554
onnx
onnx/helper.py
.py
# Copyright (c) ONNX Project Contributors # # SPDX-License-Identifier: Apache-2.0 from __future__ import annotations import collections.abc import functools import math import numbers import typing from typing import TYPE_CHECKING, Any, TypeVar import google.protobuf.message import numpy as np import typing_extension...
1,382
46,471
onnx
onnx/serialization.py
.py
# Copyright (c) ONNX Project Contributors # # SPDX-License-Identifier: Apache-2.0 from __future__ import annotations import warnings __all__ = [ "registry", ] import typing from typing import Any, Protocol, TypeVar import google.protobuf.json_format import google.protobuf.message import google.protobuf.text_fo...
213
7,910
onnx
onnx/bin/checker.py
.py
# Copyright (c) ONNX Project Contributors # # SPDX-License-Identifier: Apache-2.0 from __future__ import annotations import argparse from onnx import NodeProto, checker, load def check_model() -> None: parser = argparse.ArgumentParser("check-model") parser.add_argument("model_pb", type=argparse.FileType("rb...
28
693
onnx
onnx/reference/reference_evaluator.py
.py
# Copyright (c) ONNX Project Contributors # # SPDX-License-Identifier: Apache-2.0 from __future__ import annotations from io import BytesIO from typing import Any import numpy as np import onnx import onnx.model_container from onnx.onnx_pb import ( FunctionProto, GraphProto, ModelProto, NodeProto, ...
618
24,519
onnx
onnx/reference/op_run.py
.py
# SPDX-License-Identifier: Apache-2.0 from __future__ import annotations import abc from typing import TYPE_CHECKING, Any import numpy as np import onnx if TYPE_CHECKING: from collections.abc import Sequence class RuntimeTypeError(RuntimeError): """Raised when a type of a variable is unexpected.""" cl...
683
25,409
onnx
onnx/reference/ops_optimized/op_conv_optimized.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 _make_ind(dim, shape): m = np.empty(shape, dtype=np.int64) ind = [slice(0, shape[i]) for i in range(len(shape))] new_shape = ...
190
6,398
onnx
onnx/reference/ops/op_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 OpRunBinaryNumpy class Max(OpRunBinaryNumpy): def __init__(self, onnx_node, run_params): OpRunBinaryNumpy.__init__(self, np.maximum, o...
26
729
onnx
onnx/reference/ops/op_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 Or(OpRunBinary): def _run(self, x, y): return (np.logical_or(x, y),)
14
273
onnx
onnx/reference/ops/op_matmul_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 class MatMulInteger(OpRun): def _run(self, A, B, a_zero_point=None, b_zero_point=None): A32 = A.astype(np.int32) if a_zer...
20
503
onnx
onnx/reference/ops/op_optional_get_element.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 OptionalGetElement(OpRun): def _run(self, x): if x is None: raise ValueError("The requested optional input has no value.") ...
14
332
onnx
onnx/reference/ops/op_and.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 And(OpRunBinary): def _run(self, x, y): return (np.logical_and(x, y),)
14
275
onnx
onnx/reference/ops/op_expand.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 common_reference_implementation(data: np.ndarray, shape: np.ndarray) -> np.ndarray: ones = np.ones(shape, dtype=data.dtype) retur...
19
453
onnx
onnx/reference/ops/op_reduce_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 OpRunReduceNumpy class ReduceMin_1(OpRunReduceNumpy): def _run(self, data, axes=None, keepdims=None): axes = tuple(axes) if axes is no...
51
1,647
onnx
onnx/reference/ops/op_log.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 Log(OpRunUnaryNum): def _run(self, x): return (np.log(x).astype(x.dtype),)
14
281
onnx
onnx/reference/ops/op_affine_grid.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 construct_original_grid(data_size, align_corners): is_2d = len(data_size) == 2 size_zeros = np.zeros(data_size) original_grid...
91
3,490
onnx
onnx/reference/ops/op_sin.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 Sin(OpRunUnaryNum): def _run(self, x): return (np.sin(x),)
14
265
onnx
onnx/reference/ops/op_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.ops._op import OpRunBinaryNum def numpy_matmul(a, b): """Implements a matmul product. See :func:`np.matmul`. Handles sparse matrices. """ try: ...
26
644
onnx
onnx/reference/ops/op_negative_log_likelihood_loss.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 _compute_negative_log_likelihood_loss( x, target, weight=None, reduction="mean", ignore_index=None ): input_shape = x.shape i...
85
2,902
onnx
onnx/reference/ops/op_hardmax.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 Hardmax(OpRunUnaryNum): def _run(self, x, axis=None): axis = axis or self.axis if x.size == 0: ...
25
564
onnx
onnx/reference/ops/op_conv_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 from onnx.reference.ops.op_col2im import col2im_naive_implementation class ConvTranspose(OpRun): def _run( self, X, ...
140
5,166
onnx
onnx/reference/ops/op_sub.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 Sub(OpRunBinaryNumpy): def __init__(self, onnx_node, run_params): OpRunBinaryNumpy.__init__(self, np.subtract, ...
14
343
onnx
onnx/reference/ops/op_leaky_relu.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.ops._op import OpRunUnaryNum if TYPE_CHECKING: import numpy as np def _leaky_relu(x: np.ndarray, alpha: float) -> np.ndarray: sign = (x > ...
24
569
onnx
onnx/reference/ops/op_cosh.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 Cosh(OpRunUnaryNum): def _run(self, x): return (np.cosh(x),)
14
267
onnx
onnx/reference/ops/op_atanh.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 Atanh(OpRunUnaryNum): def _run(self, x): return (np.arctanh(x),)
14
271
onnx
onnx/reference/ops/op_tanh.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 Tanh(OpRunUnaryNum): def _run(self, x): return (np.tanh(x),)
14
267
onnx
onnx/reference/ops/op_sequence_erase.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 SequenceErase(OpRun): def _run(self, S, ind=None): if ind is None: ind = -1 else: ind = int(ind) S2 = S...
18
369
onnx
onnx/reference/ops/op_softsign.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 Softsign(OpRunUnaryNum): def _run(self, X): tmp = np.abs(X) tmp += 1 np.divide(X, tmp, out=tmp) ...
17
340
onnx
onnx/reference/ops/op_random_uniform_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 RandomUniformLike(_CommonRandom): def _run(self, x, dtype=None, high=None, low=...
20
630
onnx
onnx/reference/ops/op_rotary_embedding.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 rotary_embedding( input: np.ndarray, cos_cache: np.ndarray, sin_cache: np.ndarray, position_ids: np.ndarray | None = Non...
120
4,316
onnx
onnx/reference/ops/_quant_utils.py
.py
# Copyright (c) ONNX Project Contributors # SPDX-License-Identifier: Apache-2.0 from __future__ import annotations import numpy as np def reshape_input( value: np.ndarray, shape: tuple[int, ...], axis: int, block_size: int | None = None, ) -> np.ndarray: """Reshape/Replicate scale/zero-point to ...
57
1,907
onnx
onnx/reference/ops/op_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 Not(OpRunUnary): def _run(self, x): return (np.logical_not(x),)
14
267
onnx
onnx/reference/ops/op_softplus.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 Softplus(OpRunUnaryNum): def _run(self, X): tmp = np.asarray(np.exp(X), dtype=X.dtype) tmp += 1 np...
17
361
onnx
onnx/reference/ops/op_elu.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 Elu(OpRunUnaryNum): def _run(self, x, alpha=None): alpha = alpha or self.alpha return (np.where(x > 0, x, ...
15
363
onnx
onnx/reference/ops/op_round.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 Round(OpRunUnaryNum): def _run(self, x): return (np.round(x).astype(x.dtype),)
14
285
onnx
onnx/reference/ops/op_reshape.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 reshape_reference_implementation( data: np.ndarray, shape: np.ndarray, allowzero: int = 0 ) -> np.ndarray: # replace zeros with c...
39
1,118
onnx
onnx/reference/ops/op_swiglu.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 SwiGLU(OpRun): def _run(self, a, b, alpha=None): # SwiGLU requires identical shapes and dtypes for A and B: broadcasting is...
33
1,352
onnx
onnx/reference/ops/op_pool_common.py
.py
# Copyright (c) ONNX Project Contributors # # SPDX-License-Identifier: Apache-2.0 from __future__ import annotations import itertools import math from typing import TYPE_CHECKING import numpy as np from onnx.reference.op_run import OpRun if TYPE_CHECKING: from collections.abc import Sequence def get_pad_shape...
346
12,618
onnx
onnx/reference/ops/op_pad.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 _pad_impl(data, raw_pads, mode, constant_values=0.0, axes=None): input_rank = data.ndim if axes is None: axes = list(rang...
66
2,004
onnx
onnx/reference/ops/op_neg.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 Neg(OpRunUnaryNum): def _run(self, x): return (np.negative(x),)
14
270
onnx
onnx/reference/ops/op_ceil.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 Ceil(OpRunUnaryNum): def _run(self, x): return (np.ceil(x),)
14
267
onnx
onnx/reference/ops/op_hann_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 HannWindow(_CommonWindow): r"""Returns :math:`\\omega_n = \\sin^2\\left( \\frac{\\pi n}{N-1} \\right)` where...
21
670
onnx
onnx/reference/ops/op_tfidf_vectorizer.py
.py
# Copyright (c) ONNX Project Contributors # SPDX-License-Identifier: Apache-2.0 from __future__ import annotations import collections from enum import IntEnum import numpy as np from onnx.reference.op_run import OpRun class IntMap(collections.UserDict): def __init__(self): super().__init__() s...
381
12,527
onnx
onnx/reference/ops/op_global_max_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_max_pool(x: np.ndarray) -> np.ndarray: spatial_shape = np.ndim(x) - 2 y = x.max(axis=tuple(range(spatial_shape, spatial_s...
23
523
onnx
onnx/reference/ops/op_tensor_scatter.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 TensorScatter(OpRun): def _run(self, past_cache, update, write_indices=None, mode="linear", axis=-2): if mode not in {"line...
51
1,910
onnx
onnx/reference/ops/op_cast_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.op_run import OpRun from onnx.reference.ops.op_cast import cast_to def _cast_like(x, y, saturate: bool): return (cast_to(x, np_d...
28
679
onnx
onnx/reference/ops/op_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 import OpRunUnaryNum class Softmax(OpRunUnaryNum): def _run(self, X, axis=None): if X.size == 0: return (X,) axis = axis ...
20
482
onnx
onnx/reference/ops/op_celu.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 _vcelu1(x: np.ndarray, alpha: float = 1.0) -> np.ndarray: positive_input = np.maximum(0, x) negative_input = np.minimum(0, alpha ...
20
498
onnx
onnx/reference/ops/op_optional.py
.py
# Copyright (c) ONNX Project Contributors # SPDX-License-Identifier: Apache-2.0 from __future__ import annotations from onnx.helper import tensor_dtype_to_np_dtype from onnx.reference.op_run import OpRun class Optional(OpRun): def _run(self, x=None, type=None): # type: ignore[override] # noqa: A002 if...
19
601
onnx
onnx/reference/ops/op_isnan.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 IsNaN(OpRunUnary): def _run(self, data): return (np.isnan(data),)
14
269
onnx
onnx/reference/ops/op_unique.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 _specify_int64(indices, inverse_indices, counts): return ( np.array(indices, dtype=np.int64), np.array(inverse_indice...
52
1,773
onnx
onnx/reference/ops/op_bernoulli.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 Bernoulli(_CommonRandom): def _run(self, x, dtype=None, seed=None): if ...
18
576
onnx
onnx/reference/ops/op_dft.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 _fft(x: np.ndarray, fft_length: int, axis: int) -> np.ndarray: """Compute the FFT return the real representation of the complex resul...
147
4,821
onnx
onnx/reference/ops/op_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 Equal(OpRunBinaryComparison): def _run(self, a, b): return (np.equal(a, b),)
14
291
onnx
onnx/reference/ops/op_center_crop_pad.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 CenterCropPad(OpRun): def _run(self, input_data, shape, axes=None): axes = axes or self.axes input_rank = len(input...
51
1,626
onnx
onnx/reference/ops/op_sinh.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 Sinh(OpRunUnaryNum): def _run(self, x): return (np.sinh(x),)
14
267
onnx
onnx/reference/ops/op_asin.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 Asin(OpRunUnaryNum): def _run(self, x): return (np.arcsin(x),)
14
269
onnx
onnx/reference/ops/op_isinf.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 IsInf(OpRun): def _run(self, data, detect_negative=None, detect_positive=None): if detect_negative: if detect_p...
21
568
onnx
onnx/reference/ops/op_string_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 _acceptable_str_dtypes = ("U", "O") class StringConcat(OpRun): def _run(self, x, y): if ( x.dtype.kind not in _accep...
24
708
onnx
onnx/reference/ops/op_argmax.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 _argmax(data, axis=0, keepdims=True): result = np.argmax(data, axis=axis) if keepdims and len(result.shape) < len(data.shape): ...
43
1,182
onnx
onnx/reference/ops/op_non_max_suppression.py
.py
# Copyright (c) ONNX Project Contributors # SPDX-License-Identifier: Apache-2.0 from __future__ import annotations import dataclasses import numpy as np from onnx.reference.op_run import OpRun @dataclasses.dataclass class PrepareContext: boxes_data_: np.ndarray | None = None boxes_size_: int = 0 score...
272
9,282
onnx
onnx/reference/ops/op_thresholded_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 ThresholdedRelu(OpRunUnaryNum): def _run(self, x, alpha=None): alpha = alpha or self.alpha return (np.wher...
15
357
onnx
onnx/reference/ops/op_gather.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 Gather(OpRun): def _run(self, x, indices, axis=None): if not x.flags["C_CONTIGUOUS"]: x = np.ascontiguousarray(...
22
625
onnx
onnx/reference/ops/op_max_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_common_pool import CommonPool class MaxPool(CommonPool): def _run( self, x, auto_pad=None, ceil_mode=None, di...
414
14,553
onnx
onnx/reference/ops/op_reduce_l1.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 ReduceL1_1(OpRunReduceNumpy): def _run(self, data, axes=None, keepdims=None): axes = tuple(axes) if axes is not...
35
1,140
onnx
onnx/reference/ops/op_reduce_log_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 ReduceLogSum_1(OpRunReduceNumpy): def _run(self, data, axes=None, keepdims=True): tax = tuple(axes) if axes is ...
35
1,093
onnx
onnx/reference/ops/op_scatter_elements.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 scatter_elements(data, indices, updates, axis=0, reduction=None): """Scatter elements. :: for 3-dim and axis=0 ...
120
3,806
onnx
onnx/reference/ops/op_dropout.py
.py
# Copyright (c) ONNX Project Contributors # SPDX-License-Identifier: Apache-2.0 from __future__ import annotations import numpy as np from numpy.random import RandomState from onnx.reference.op_run import OpRun def _dropout( X: np.ndarray, drop_probability: float = 0.5, seed: int | None = None, tra...
67
1,779
onnx
onnx/reference/ops/op_size.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 Size(OpRun): def _run(self, data): return (np.array(data.size, dtype=np.int64),)
14
278
onnx
onnx/reference/ops/_op_common_indices.py
.py
# Copyright (c) ONNX Project Contributors # SPDX-License-Identifier: Apache-2.0 from __future__ import annotations import numpy as np def _get_indices(i, shape): res = np.empty((len(shape),), dtype=np.int64) k = len(shape) - 1 while k > 0: m = i % shape[k] res[k] = m i -= m ...
38
746
onnx
onnx/reference/ops/op_compress.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 Compress(OpRun): def _run(self, x, condition, axis=None): return (np.compress(condition, x, axis=axis),)
14
302
onnx
onnx/reference/ops/op_loop.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 Loop(OpRun): def __init__(self, onnx_node, run_params): OpRun.__init__(self, onnx_node, run_params) if "opsets" not...
87
3,454
onnx
onnx/reference/ops/op_reduce_prod.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 ReduceProd_1(OpRunReduceNumpy): def _run(self, data, axes=None, keepdims=None): axes = tuple(axes) if axes is n...
31
1,071
onnx
onnx/reference/ops/op_qlinear_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 from onnx.reference.ops.op_conv import _conv_implementation class QLinearConv(OpRun): def _run( self, x, x_scale,...
79
2,516
onnx
onnx/reference/ops/op_gather_elements.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_numpy_2(self: np.ndarray, index: np.ndarray) -> np.ndarray: res = [] for a, b in zip(self, index, strict=True): re...
48
1,598
onnx
onnx/reference/ops/op_bitwise_and.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 BitwiseAnd(OpRunBinary): def _run(self, x, y): return (np.bitwise_and(x, y),)
14
282
onnx
onnx/reference/ops/op_reduce_sum_square.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 ReduceSumSquare_1(OpRunReduceNumpy): def _run(self, data, axes=None, keepdims=None): axes = tuple(axes) if axes...
31
1,066
onnx
onnx/reference/ops/op_rnn.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 CommonRNN(OpRun): def __init__(self, onnx_node, run_params): OpRun.__init__(self, onnx_node, run_params) if self.d...
203
6,149
onnx
onnx/reference/ops/op_cum_prod.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 CumProd(OpRun): def _run(self, x, axis, exclusive=None, reverse=None): axis = np.asarray(axis) if axis.ndim != 0: ...
32
1,087
onnx
onnx/reference/ops/op_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 Shape_1(OpRun): def _run(self, data): return (np.array(data.shape, dtype=np.int64),) class Shape_15(Shape_1): @static...
36
1,023
onnx
onnx/reference/ops/op_hamming_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 HammingWindow(_CommonWindow): r"""Returns :math:`\\omega_n = \\alpha - \\beta \\cos \\left( \\frac{\\pi n}{N...
24
791
onnx
onnx/reference/ops/op_random_normal.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 RandomNormal(_CommonRandom): def _run(self, dtype=None, mean=None, scale=None, seed=None, shape=None): state = self._get...
17
512
onnx
onnx/reference/ops/op_where.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 Where(OpRun): def _run(self, condition, x, y): if ( x.dtype not in (y.dtype, object) and x.dtype.ty...
22
577
onnx
onnx/reference/ops/op_identity.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 Identity(OpRun): def _run(self, a): if a is None: return (None,) return (a.copy(),)
14
281
onnx
onnx/reference/ops/op_greater.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 Greater(OpRunBinaryComparison): def _run(self, a, b): return (np.greater(a, b),)
14
295
onnx
onnx/reference/ops/_op_list.py
.py
# Copyright (c) ONNX Project Contributors # SPDX-License-Identifier: Apache-2.0 """Every class imported in this module defines an implementation of an operator of the main domain. Any class name uses `_` to specify a version defined in a specific opset. The class name without `_` defines the current implementation. If...
630
21,806
onnx
onnx/reference/ops/op_unsqueeze.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 Unsqueeze_1(OpRun): def _run(self, data, axes=None): if isinstance(axes, np.ndarray): axes = tuple(axes) ...
53
1,592
onnx
onnx/reference/ops/op_instance_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 class InstanceNormalization(OpRun): def _run(self, x, s, bias, epsilon=None): dims_x = len(x.shape) axis = tuple(range(2,...
22
646
onnx
onnx/reference/ops/op_mul.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 Mul(OpRunBinaryNumpy): def __init__(self, onnx_node, run_params): OpRunBinaryNumpy.__init__(self, np.multiply, ...
14
343
onnx
onnx/reference/ops/op_erf.py
.py
# Copyright (c) ONNX Project Contributors # SPDX-License-Identifier: Apache-2.0 from __future__ import annotations from math import erf import numpy as np from onnx.reference.ops._op import OpRunUnaryNum class Erf(OpRunUnaryNum): def __init__(self, onnx_node, run_params): OpRunUnaryNum.__init__(self, ...
20
466
onnx
onnx/reference/ops/op_argmin.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 _argmin(data, axis=0, keepdims=True): result = np.argmin(data, axis=axis) if keepdims and len(result.shape) < len(data.shape): ...
43
1,182
onnx
onnx/reference/ops/op_sequence_empty.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 SequenceEmpty(OpRun): def _run(self, dtype=None): # type: ignore[override] # noqa: ARG002 return ([],)
12
282
onnx
onnx/reference/ops/op_string_split.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 _acceptable_str_dtypes = ("U", "O") def pad_empty_string( split_lists: list | np.ndarray, padding_requirement: list | int ) -> list: ...
47
1,695
onnx
onnx/reference/ops/op_softmax_cross_entropy_loss.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 softmaxcrossentropy( x, target, weight=None, reduction="mean", ignore_index=None, get_log_prob=None ): input_shape = x.shape ...
95
2,950
onnx
onnx/reference/ops/op_less.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 Less(OpRunBinaryComparison): def _run(self, a, b): return (np.less(a, b),)
14
289
onnx
onnx/reference/ops/op_scatternd.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 _scatter_nd_impl(data, indices, updates, reduction=None): output = np.copy(data) for i in np.ndindex(indices.shape[:-1]): ...
35
1,050
onnx
onnx/reference/ops/op_space_to_depth.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 SpaceToDepth(OpRun): def _run(self, data, blocksize=None): if len(data.shape) != 4: raise RuntimeError(f"Unexpe...
34
883
onnx
onnx/reference/ops/op_acos.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 Acos(OpRunUnaryNum): def _run(self, x): return (np.arccos(x),)
14
269