| 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 | |
| 17 | namespace pnnx { |
| 18 | |
| 19 | class torch_stft : public GraphRewriterPass |
| 20 | { |
| 21 | public: |
| 22 | const char* match_pattern_graph() const |
| 23 | { |
| 24 | return R"PNNXIR(7767517 |
| 25 | 10 9 |
| 26 | pnnx.Input input_0 0 1 input |
| 27 | pnnx.Input input_1 0 1 n_fft |
| 28 | pnnx.Input input_2 0 1 hop_length |
| 29 | pnnx.Input input_3 0 1 win_length |
| 30 | pnnx.Input input_4 0 1 window |
| 31 | pnnx.Input input_5 0 1 normalized |
| 32 | pnnx.Input input_6 0 1 onesided |
| 33 | pnnx.Input input_7 0 1 return_complex |
| 34 | aten::stft op_0 8 1 input n_fft hop_length win_length window normalized onesided return_complex out |
| 35 | pnnx.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 | |
| 50 | REGISTER_GLOBAL_PNNX_GRAPH_REWRITER_PASS(torch_stft, 20) |
| 51 | |
| 52 | class torch_stft_1 : public GraphRewriterPass |
| 53 | { |
| 54 | public: |
| 55 | const char* match_pattern_graph() const |
| 56 | { |
| 57 | return R"PNNXIR(7767517 |
| 58 | 37 36 |
| 59 | pnnx.Input input_0 0 1 input |
| 60 | pnnx.Input input_1 0 1 n_fft |
| 61 | pnnx.Input input_2 0 1 hop_length |
| 62 | pnnx.Input input_3 0 1 win_length |
| 63 | pnnx.Input input_4 0 1 window |
| 64 | pnnx.Input input_5 0 1 normalized |
| 65 | pnnx.Input input_6 0 1 onesided |
| 66 | pnnx.Input input_7 0 1 return_complex |
| 67 | prim::Constant op_0 0 1 4 value=0 |
| 68 | aten::size op_1 2 1 input 4 5 |
| 69 | prim::NumToTensor op_2 1 1 5 6 |
| 70 | aten::Int op_3 1 1 6 9 |
| 71 | prim::Constant op_4 0 1 11 value=1 |
| 72 | aten::size op_5 2 1 input 11 12 |
| 73 | prim::NumToTensor op_6 1 1 12 13 |
| 74 | aten::Int op_7 1 1 13 18 |
| 75 | prim::Constant op_8 0 1 62 value=1 |
| 76 | prim::ListConstruct op_9 3 1 62 9 18 19 |
| 77 | aten::view op_10 2 1 input 19 a |
| 78 | prim::Constant op_11 0 1 21 value=%pad_left |
| 79 | prim::Constant op_12 0 1 63 value=%pad_right |
| 80 | prim::ListConstruct op_13 2 1 21 63 22 |
| 81 | prim::Constant op_14 0 1 23 value=%pad_mode |
| 82 | prim::Constant op_15 0 1 24 value=None |
| 83 | aten::pad op_16 4 1 a 22 23 24 b |
| 84 | prim::Constant op_17 0 1 64 value=1 |
| 85 | aten::size op_18 2 1 b 64 27 |
| 86 | prim::NumToTensor op_19 1 1 27 28 |
| 87 | aten::Int op_20 1 1 28 31 |
| 88 | prim::Constant op_21 0 1 33 value=2 |
| 89 | aten::size op_22 2 1 b 33 34 |
| 90 | prim::NumToTensor op_23 1 1 34 35 |
| 91 | aten::Int op_24 1 1 35 40 |
| 92 | prim::ListConstruct op_25 2 1 31 40 41 |
| 93 | aten::view op_26 2 1 b 41 c |
| 94 | aten::stft op_27 8 1 c n_fft hop_length win_length window normalized onesided return_complex out |
| 95 | pnnx.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 | |
| 111 | REGISTER_GLOBAL_PNNX_GRAPH_REWRITER_PASS(torch_stft_1, 19) |
| 112 | |
| 113 | } // namespace pnnx |