Elffuss BraidHub

kikocis/ncnn public

master · 4.1 KiBRawPermalink
1// Tencent is pleased to support the open source community by making ncnn available.
2//
3// Copyright (C) 2023 THL A29 Limited, a Tencent company. All rights reserved.
4//
5// Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
6// in compliance with the License. You may obtain a copy of the License at
7//
8// https://opensource.org/licenses/BSD-3-Clause
9//
10// Unless required by applicable law or agreed to in writing, software distributed
11// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
12// CONDITIONS OF ANY KIND, either express or implied. See the License for the
13// specific language governing permissions and limitations under the License.
14
15#include "pass_level2.h"
16
17namespace pnnx {
18
19class torch_stft : public GraphRewriterPass
20{
21public:
22 const char* match_pattern_graph() const
23 {
24 return R"PNNXIR(7767517
2510 9
26pnnx.Input input_0 0 1 input
27pnnx.Input input_1 0 1 n_fft
28pnnx.Input input_2 0 1 hop_length
29pnnx.Input input_3 0 1 win_length
30pnnx.Input input_4 0 1 window
31pnnx.Input input_5 0 1 normalized
32pnnx.Input input_6 0 1 onesided
33pnnx.Input input_7 0 1 return_complex
34aten::stft op_0 8 1 input n_fft hop_length win_length window normalized onesided return_complex out
35pnnx.Output output 1 0 out
36)PNNXIR";
37 }
38
39 const char* type_str() const
40 {
41 return "torch.stft";
42 }
43
44 void write(Operator* op, const std::map<std::string, Parameter>& /*captured_params*/) const
45 {
46 op->params["center"] = false;
47 }
48};
49
50REGISTER_GLOBAL_PNNX_GRAPH_REWRITER_PASS(torch_stft, 20)
51
52class torch_stft_1 : public GraphRewriterPass
53{
54public:
55 const char* match_pattern_graph() const
56 {
57 return R"PNNXIR(7767517
5837 36
59pnnx.Input input_0 0 1 input
60pnnx.Input input_1 0 1 n_fft
61pnnx.Input input_2 0 1 hop_length
62pnnx.Input input_3 0 1 win_length
63pnnx.Input input_4 0 1 window
64pnnx.Input input_5 0 1 normalized
65pnnx.Input input_6 0 1 onesided
66pnnx.Input input_7 0 1 return_complex
67prim::Constant op_0 0 1 4 value=0
68aten::size op_1 2 1 input 4 5
69prim::NumToTensor op_2 1 1 5 6
70aten::Int op_3 1 1 6 9
71prim::Constant op_4 0 1 11 value=1
72aten::size op_5 2 1 input 11 12
73prim::NumToTensor op_6 1 1 12 13
74aten::Int op_7 1 1 13 18
75prim::Constant op_8 0 1 62 value=1
76prim::ListConstruct op_9 3 1 62 9 18 19
77aten::view op_10 2 1 input 19 a
78prim::Constant op_11 0 1 21 value=%pad_left
79prim::Constant op_12 0 1 63 value=%pad_right
80prim::ListConstruct op_13 2 1 21 63 22
81prim::Constant op_14 0 1 23 value=%pad_mode
82prim::Constant op_15 0 1 24 value=None
83aten::pad op_16 4 1 a 22 23 24 b
84prim::Constant op_17 0 1 64 value=1
85aten::size op_18 2 1 b 64 27
86prim::NumToTensor op_19 1 1 27 28
87aten::Int op_20 1 1 28 31
88prim::Constant op_21 0 1 33 value=2
89aten::size op_22 2 1 b 33 34
90prim::NumToTensor op_23 1 1 34 35
91aten::Int op_24 1 1 35 40
92prim::ListConstruct op_25 2 1 31 40 41
93aten::view op_26 2 1 b 41 c
94aten::stft op_27 8 1 c n_fft hop_length win_length window normalized onesided return_complex out
95pnnx.Output output 1 0 out
96)PNNXIR";
97 }
98
99 const char* type_str() const
100 {
101 return "torch.stft";
102 }
103
104 void write(Operator* op, const std::map<std::string, Parameter>& captured_params) const
105 {
106 op->params["pad_mode"] = captured_params.at("pad_mode");
107 op->params["center"] = true;
108 }
109};
110
111REGISTER_GLOBAL_PNNX_GRAPH_REWRITER_PASS(torch_stft_1, 19)
112
113} // namespace pnnx