-
Notifications
You must be signed in to change notification settings - Fork 15
/
Not.py
46 lines (37 loc) · 1.48 KB
/
Not.py
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#
# SPDX-FileCopyrightText: Copyright (c) 2022-2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: MIT
#
# NVIDIA CORPORATION, its affiliates and licensors retain all intellectual
# property and proprietary rights in and to this material, related
# documentation and any modifications thereto. Any use, reproduction,
# disclosure or distribution of this material and related documentation
# without an express license agreement from NVIDIA CORPORATION or
# its affiliates is strictly prohibited.
#
"""Reconstruction of a Not op."""
from logging import info
import numpy as np
import onnx_graphsurgeon as gs
from common.BinaryOperator import BinaryOperator
class Not(BinaryOperator):
@classmethod
def reconstruct(cls, node, graph):
if cls.qualifies_for_reconstruction(node):
info(f'Reconstructing {node.op} node "{node.name}"...')
node.op = 'Sub'
for tensor in node.inputs + node.outputs:
tensor.dtype = np.float32
not_var = node.inputs[0]
not_constant = gs.Constant(name=f'{node.name}_tmp0',
values=np.ones(not_var.shape, dtype=not_var.dtype))
node.inputs = [not_constant, not_var]
def test(self):
input_shape = (1, 2, 1, 1)
input_data = np.array([True, False]).reshape(input_shape)
return super().test(input_data=input_data)
def main():
op = Not()
op.test()
if __name__ == '__main__':
main()