Files
pytorch/test/cpp/tensorexpr/padded_buffer.cpp
Will Constable 4f34cd6d1e Replace all CHECK_ and DCHECK_ with TORCH_* macros (#82032)
Avoid exposing defines that conflict with google logging, since this blocks external usage of libtorch in certain cases.

All the 'interesting' changes should be in these two files, and the rest should just be mechanical changes via sed.
c10/util/logging_is_not_google_glog.h
c10/util/logging_is_google_glog.h

Fixes https://github.com/pytorch/pytorch/issues/81415

cc @miladm @malfet
Pull Request resolved: https://github.com/pytorch/pytorch/pull/82032
Approved by: https://github.com/soumith, https://github.com/miladm
2022-07-26 01:20:44 +00:00

38 lines
947 B
C++

#include "test/cpp/tensorexpr/padded_buffer.h"
#include <c10/util/Logging.h>
#include <c10/util/irange.h>
#include <sstream>
namespace torch {
namespace jit {
namespace tensorexpr {
int PaddedBufferBase::Index(const std::vector<int>& indices) const {
TORCH_DCHECK_EQ(dims_.size(), indices.size());
int total_index = 0;
for (const auto i : c10::irange(dims_.size())) {
total_index += indices[i] * strides_[i];
}
return total_index;
}
PaddedBufferBase::PaddedBufferBase(
const std::vector<int>& dims,
// NOLINTNEXTLINE(modernize-pass-by-value)
const std::string& name)
: dims_(dims), name_(name), strides_(dims.size()) {
for (int i = (int)dims.size() - 1; i >= 0; --i) {
if (i == (int)dims.size() - 1) {
strides_[i] = 1;
} else {
strides_[i] = strides_[i + 1] * dims[i + 1];
}
}
total_size_ = strides_[0] * dims[0];
}
} // namespace tensorexpr
} // namespace jit
} // namespace torch