Skip to content

Commit

Permalink
Replace if-else chain with switch statement.
Browse files Browse the repository at this point in the history
  • Loading branch information
TFiFiE committed Jul 21, 2018
1 parent 5596041 commit 06b1ace
Showing 1 changed file with 21 additions and 30 deletions.
51 changes: 21 additions & 30 deletions src/Network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,36 +233,27 @@ std::pair<int, int> Network::load_v1_network(std::istream& wtfile) {
process_bn_var(weights);
batchnorm_stddivs.emplace_back(weights);
}
} else if (linecount == plain_conv_wts) {
conv_pol_w = std::move(weights);
} else if (linecount == plain_conv_wts + 1) {
conv_pol_b = std::move(weights);
} else if (linecount == plain_conv_wts + 2) {
std::copy(cbegin(weights), cend(weights), begin(bn_pol_w1));
} else if (linecount == plain_conv_wts + 3) {
process_bn_var(weights);
std::copy(cbegin(weights), cend(weights), begin(bn_pol_w2));
} else if (linecount == plain_conv_wts + 4) {
std::copy(cbegin(weights), cend(weights), begin(ip_pol_w));
} else if (linecount == plain_conv_wts + 5) {
std::copy(cbegin(weights), cend(weights), begin(ip_pol_b));
} else if (linecount == plain_conv_wts + 6) {
conv_val_w = std::move(weights);
} else if (linecount == plain_conv_wts + 7) {
conv_val_b = std::move(weights);
} else if (linecount == plain_conv_wts + 8) {
std::copy(cbegin(weights), cend(weights), begin(bn_val_w1));
} else if (linecount == plain_conv_wts + 9) {
process_bn_var(weights);
std::copy(cbegin(weights), cend(weights), begin(bn_val_w2));
} else if (linecount == plain_conv_wts + 10) {
std::copy(cbegin(weights), cend(weights), begin(ip1_val_w));
} else if (linecount == plain_conv_wts + 11) {
std::copy(cbegin(weights), cend(weights), begin(ip1_val_b));
} else if (linecount == plain_conv_wts + 12) {
std::copy(cbegin(weights), cend(weights), begin(ip2_val_w));
} else if (linecount == plain_conv_wts + 13) {
std::copy(cbegin(weights), cend(weights), begin(ip2_val_b));
} else {
const auto offset = linecount - plain_conv_wts;
if (offset == 3 || offset == 9) {
process_bn_var(weights);
}
switch (offset) {
case 0: conv_pol_w = std::move(weights); break;
case 1: conv_pol_b = std::move(weights); break;
case 2: std::copy(cbegin(weights), cend(weights), begin(bn_pol_w1)); break;
case 3: std::copy(cbegin(weights), cend(weights), begin(bn_pol_w2)); break;
case 4: std::copy(cbegin(weights), cend(weights), begin(ip_pol_w)); break;
case 5: std::copy(cbegin(weights), cend(weights), begin(ip_pol_b)); break;
case 6: conv_val_w = std::move(weights); break;
case 7: conv_val_b = std::move(weights); break;
case 8: std::copy(cbegin(weights), cend(weights), begin(bn_val_w1)); break;
case 9: std::copy(cbegin(weights), cend(weights), begin(bn_val_w2)); break;
case 10: std::copy(cbegin(weights), cend(weights), begin(ip1_val_w)); break;
case 11: std::copy(cbegin(weights), cend(weights), begin(ip1_val_b)); break;
case 12: std::copy(cbegin(weights), cend(weights), begin(ip2_val_w)); break;
case 13: std::copy(cbegin(weights), cend(weights), begin(ip2_val_b)); break;
}
}
linecount++;
}
Expand Down

0 comments on commit 06b1ace

Please sign in to comment.