| 181 | |
| 182 | template <typename Dtype> |
| 183 | void RecurrentLayer<Dtype>::Reshape(const vector<Blob<Dtype>*>& bottom, |
| 184 | const vector<Blob<Dtype>*>& top) { |
| 185 | CHECK_GE(bottom[0]->num_axes(), 2) |
| 186 | << "bottom[0] must have at least 2 axes -- (#timesteps, #streams, ...)"; |
| 187 | CHECK_EQ(T_, bottom[0]->shape(0)) << "input number of timesteps changed"; |
| 188 | N_ = bottom[0]->shape(1); |
| 189 | CHECK_EQ(bottom[1]->num_axes(), 2) |
| 190 | << "bottom[1] must have exactly 2 axes -- (#timesteps, #streams)"; |
| 191 | CHECK_EQ(T_, bottom[1]->shape(0)); |
| 192 | CHECK_EQ(N_, bottom[1]->shape(1)); |
| 193 | x_input_blob_->ReshapeLike(*bottom[0]); |
| 194 | vector<int> cont_shape = bottom[1]->shape(); |
| 195 | cont_input_blob_->Reshape(cont_shape); |
| 196 | if (static_input_) { |
| 197 | x_static_input_blob_->ReshapeLike(*bottom[2]); |
| 198 | } |
| 199 | vector<BlobShape> recur_input_shapes; |
| 200 | RecurrentInputShapes(&recur_input_shapes); |
| 201 | CHECK_EQ(recur_input_shapes.size(), recur_input_blobs_.size()); |
| 202 | for (int i = 0; i < recur_input_shapes.size(); ++i) { |
| 203 | recur_input_blobs_[i]->Reshape(recur_input_shapes[i]); |
| 204 | } |
| 205 | unrolled_net_->Reshape(); |
| 206 | x_input_blob_->ShareData(*bottom[0]); |
| 207 | x_input_blob_->ShareDiff(*bottom[0]); |
| 208 | cont_input_blob_->ShareData(*bottom[1]); |
| 209 | if (static_input_) { |
| 210 | x_static_input_blob_->ShareData(*bottom[2]); |
| 211 | x_static_input_blob_->ShareDiff(*bottom[2]); |
| 212 | } |
| 213 | if (expose_hidden_) { |
| 214 | const int bottom_offset = 2 + static_input_; |
| 215 | for (int i = bottom_offset, j = 0; i < bottom.size(); ++i, ++j) { |
| 216 | CHECK(recur_input_blobs_[j]->shape() == bottom[i]->shape()) |
| 217 | << "bottom[" << i << "] shape must match hidden state input shape: " |
| 218 | << recur_input_blobs_[j]->shape_string(); |
| 219 | recur_input_blobs_[j]->ShareData(*bottom[i]); |
| 220 | } |
| 221 | } |
| 222 | for (int i = 0; i < output_blobs_.size(); ++i) { |
| 223 | top[i]->ReshapeLike(*output_blobs_[i]); |
| 224 | top[i]->ShareData(*output_blobs_[i]); |
| 225 | top[i]->ShareDiff(*output_blobs_[i]); |
| 226 | } |
| 227 | if (expose_hidden_) { |
| 228 | const int top_offset = output_blobs_.size(); |
| 229 | for (int i = top_offset, j = 0; i < top.size(); ++i, ++j) { |
| 230 | top[i]->ReshapeLike(*recur_output_blobs_[j]); |
| 231 | } |
| 232 | } |
| 233 | } |
| 234 | |
| 235 | template <typename Dtype> |
| 236 | void RecurrentLayer<Dtype>::Reset() { |
nothing calls this directly
no test coverage detected