| 102 | class BlstmComputerTestNormal : public MNNTestCase { |
| 103 | public: |
| 104 | virtual bool run(int precision) { |
| 105 | int timesteps = 2; |
| 106 | int batch = 2; |
| 107 | int inDim = 4; |
| 108 | int stateDim = 2; |
| 109 | int bidirectional = true; |
| 110 | |
| 111 | float input[] = {0.44579449, 0.27169554, 0.65260875, 0.31565022, 0.90375165, 0.06445987, |
| 112 | 0.5355081, 0.00180581, 0.14474092, 0.73850643, 0.33908029, 0.02118387, |
| 113 | 0.42463244, 0.91618846, 0.16352628, 0.16589524}; |
| 114 | |
| 115 | // weights + bias |
| 116 | // (inDim * stateDim + stateDim * stateDim + stateDim) * 4 * (bidirectional |
| 117 | // ? 2 : 1) |
| 118 | float weights[] = { |
| 119 | 0.2238575, 0.48818177, 0.68244838, 0.13634153, 0.66256713, 0.62072643, 0.77099263, 0.525549, 0.98192705, |
| 120 | 0.07248594, 0.86286398, 0.15345954, 0.06705897, 0.87608419, 0.75358085, 0.05641118, 0.95627635, 0.96339125, |
| 121 | 0.47342446, 0.92175236, 0.40918123, 0.43998353, 0.11528957, 0.58670112, 0.14460955, 0.10411315, 0.81912501, |
| 122 | 0.07275662, 0.55807365, 0.89699957, 0.51889823, 0.25331806, 0.66381276, 0.22328322, 0.6877316, 0.92511827, |
| 123 | 0.38725914, 0.04857563, 0.89930032, 0.11227703, 0.0540831, 0.56100574, 0.30010248, 0.94735647, 0.95685347, |
| 124 | 0.09243085, 0.20552173, 0.03578646, 0.76262415, 0.91767524, 0.97650681, 0.35745307, 0.02309165, 0.26921557, |
| 125 | 0.54497556, 0.67020231, 0.55593737, 0.80142984, 0.81460252, 0.31087914, 0.26101857, 0.79632238, 0.94220189, |
| 126 | 0.08358934, 0.1308584, 0.01036083, 0.36453937, 0.30837561, 0.57286502, 0.45081482, 0.21734892, 0.25597718, |
| 127 | 0.51861896, 0.74332179, 0.54929558, 0.17185688, 0.61304193, 0.78736534, 0.98097528, 0.12290096, 0.63355095, |
| 128 | 0.29947352, 0.98152295, 0.63781417, 0.90260405, 0.08585729, 0.21135987, 0.41743537, 0.20267783, 0.80777418, |
| 129 | 0.03285213, 0.9306145, 0.78912835, 0.77490629, 0.7590748, 0.78981628, 0.45081439, 0.95330662, 0.62282867, |
| 130 | 0.38536004, 0.88046332, 0.5811635, 0.84273814, 0.5468788, 0.15999526, 0.95592125, 0.02159869, 0.06027197, |
| 131 | 0.694669, 0.9606723, 0.07577876, 0.08770169}; |
| 132 | |
| 133 | // initH |
| 134 | float initH[] = {0.62370589, 0.41819492, 0.24196935, 0.2528544, 0.74764926, 0.28984179, 0.9113539, 0.06682115}; |
| 135 | |
| 136 | float *initC = nullptr; |
| 137 | |
| 138 | // lengths |
| 139 | vector<int> lengths = {1, 2}; |
| 140 | |
| 141 | // output |
| 142 | float expected[] = {0.63731168, 0.50447114, 0.54004276, 0.51610641, 0.0, 0.0, |
| 143 | 0.0, 0.0, 0.57669216, 0.3799657, 0.76510281, 0.70311715, |
| 144 | 0.81803278, 0.5823984, 0.55451016, 0.5276197}; |
| 145 | |
| 146 | auto output = BlstmComputerTest::createAndRun(timesteps, batch, inDim, stateDim, bidirectional, input, weights, |
| 147 | initH, initC, lengths); |
| 148 | |
| 149 | if (!checkVector<float>(output->host<float>(), expected, (bidirectional ? 2 : 1) * stateDim * batch, 0.00001)) { |
| 150 | MNN_ERROR("BlstmComputerTestNormal failed!\n"); |
| 151 | } |
| 152 | |
| 153 | return true; |
| 154 | } |
| 155 | }; |
| 156 | |
| 157 | class BlstmComputerTestUnidirection : public MNNTestCase { |
nothing calls this directly
no test coverage detected