Skip to content

Commit

Permalink
use std size()
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-haibin-lin committed Jul 31, 2017
1 parent c23dc1a commit 1e821e1
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions src/common/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ inline bool GetDefaultBlobs(const std::vector<NDArray>& src,
std::vector<NDArray> *temp_src,
std::vector<NDArray> *temp_dst) {
bool require_cast = false;
size_t size = src.size();
for (size_t i = 0; i < size; i++) {
for (size_t i = 0; i < src.size(); i++) {
auto& nd = src[i];
if (nd.storage_type() != kDefaultStorage) {
NDArray temp(nd.shape(), nd.ctx(), false);
Expand All @@ -68,8 +67,7 @@ inline void CastNonDefaultStorage(const std::vector<NDArray>& src,
const OpContext& ctx,
bool storage_fallback = false) {
CHECK_GE(dst.size(), src.size());
size_t size = src.size();
if (size == 0) return;
if (src.size() == 0) return;
if (storage_fallback == false) {
storage_fallback = dmlc::GetEnv("MXNET_EXEC_STORAGE_FALLBACK", true);
}
Expand All @@ -78,21 +76,21 @@ inline void CastNonDefaultStorage(const std::vector<NDArray>& src,
<< "You are probably executing an operator which "
<< "doesn't support NDArray inputs with non-default storage.";
}
for (size_t i = 0; i < size; i++) {
for (size_t i = 0; i < src.size(); i++) {
CastStorageDispatch<xpu>(ctx, src[i], dst[i]);
}
}

// Check if any storage type is not default storage
inline bool ContainsNonDefaultStorage(const StorageTypeVector& vstorage) {
for (auto& i : vstorage) {
for (const auto& i : vstorage) {
if (i != kUndefinedStorage && i != kDefaultStorage) return true;
}
return false;
}

inline bool ContainsDefaultStorage(const std::vector<NDArray>& ndarrays) {
for (auto &nd : ndarrays) {
for (const auto &nd : ndarrays) {
if (nd.storage_type() == kDefaultStorage) {
return true;
}
Expand Down

0 comments on commit 1e821e1

Please sign in to comment.