| 
									
										
										
										
											2019-04-17 10:49:11 +08:00
										 |  |  | //
 | 
					
						
							|  |  |  | //  ShapeLSTM.cpp
 | 
					
						
							|  |  |  | //  MNN
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | //  Created by MNN on 2019/01/10.
 | 
					
						
							|  |  |  | //  Copyright © 2018, Alibaba Group Holding Limited
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-12-27 22:16:57 +08:00
										 |  |  | #include "core/Macro.h"
 | 
					
						
							|  |  |  | #include "core/SizeComputer.hpp"
 | 
					
						
							|  |  |  | #include "core/TensorUtils.hpp"
 | 
					
						
							| 
									
										
										
										
											2019-04-17 10:49:11 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | namespace MNN { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // Size Computer
 | 
					
						
							|  |  |  | class LSTMComputer : public SizeComputer { | 
					
						
							|  |  |  |     virtual bool onComputeSize(const MNN::Op *op, const std::vector<Tensor *> &inputs, | 
					
						
							|  |  |  |                                const std::vector<Tensor *> &outputs) const override { | 
					
						
							|  |  |  |         MNN_ASSERT(2 >= inputs.size()); | 
					
						
							|  |  |  |         MNN_ASSERT(1 == outputs.size()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         // copy dims
 | 
					
						
							|  |  |  |         auto &input  = inputs[0]->buffer(); | 
					
						
							|  |  |  |         auto &output = outputs[0]->buffer(); | 
					
						
							|  |  |  |         memcpy(output.dim, input.dim, sizeof(halide_dimension_t) * input.dimensions); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         auto LSTM            = op->main_as_LSTM(); | 
					
						
							| 
									
										
										
										
											2020-02-26 09:57:17 +08:00
										 |  |  |         output.dimensions = 4; | 
					
						
							| 
									
										
										
										
											2019-04-17 10:49:11 +08:00
										 |  |  |         output.dim[3].extent = LSTM->outputCount(); | 
					
						
							|  |  |  |         output.dim[2].extent = 1; | 
					
						
							| 
									
										
										
										
											2020-02-26 09:57:17 +08:00
										 |  |  |         output.type = halide_type_of<float>(); | 
					
						
							| 
									
										
										
										
											2019-08-22 20:13:46 +08:00
										 |  |  |         TensorUtils::getDescribe(outputs[0])->dimensionFormat = TensorUtils::getDescribe(inputs[0])->dimensionFormat; | 
					
						
							| 
									
										
										
										
											2019-04-17 10:49:11 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |         return true; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | REGISTER_SHAPE(LSTMComputer, OpType_LSTM); | 
					
						
							|  |  |  | } // namespace MNN
 |