69#include "absl/strings/str_cat.h"
70#include "absl/strings/str_join.h"
87template <
typename Dtype>
91 explicit Blob(
bool use_cuda_host_malloc)
99 const bool use_cuda_host_malloc =
false);
100 explicit Blob(
const std::vector<int>&
shape,
101 const bool use_cuda_host_malloc =
false);
127 ? absl::StrCat(
"(",
count_,
")")
128 : absl::StrCat(absl::StrJoin(
shape_,
" "),
" (",
count_,
")");
153 inline int count(
int start_axis,
int end_axis)
const {
154 CHECK_LE(start_axis, end_axis);
155 CHECK_GE(start_axis, 0);
156 CHECK_GE(end_axis, 0);
160 for (
int i = start_axis; i < end_axis; ++i) {
171 inline int count(
int start_axis)
const {
198 <<
"axis " << axis_index <<
" out of range for " <<
num_axes()
201 <<
"axis " << axis_index <<
" out of range for " <<
num_axes()
203 if (axis_index < 0) {
219 <<
"Cannot use legacy accessors on Blobs with > 4 axes.";
231 inline int offset(
const int n,
const int c = 0,
const int h = 0,
232 const int w = 0)
const {
239 CHECK_GE(
width(), 0);
240 CHECK_LE(w,
width());
244 inline int offset(
const std::vector<int>& indices)
const {
245 CHECK_LE(indices.size(),
static_cast<size_t>(
num_axes()));
247 for (
int i = 0; i <
num_axes(); ++i) {
249 if (
static_cast<int>(indices.size()) > i) {
250 CHECK_GE(indices[i], 0);
251 CHECK_LT(indices[i],
shape(i));
267 inline Dtype
data_at(
const int n,
const int c,
const int h,
272 inline Dtype
data_at(
const std::vector<int>& index)
const {
276 inline const std::shared_ptr<SyncedMemory>&
data()
const {
304 std::shared_ptr<SyncedMemory>
data_;
312template <
typename Dtype>
314template <
typename Dtype>
A wrapper around SyncedMemory holders serving as the basic computational unit for images,...
int CanonicalAxisIndex(int axis_index) const
create RoI Blob.
const Dtype * gpu_data() const
const Dtype * cpu_data() const
Dtype * mutable_cpu_data()
std::shared_ptr< SyncedMemory > data_
std::shared_ptr< SyncedMemory > shape_data_
const std::vector< int > & shape() const
Dtype * mutable_gpu_data()
void ReshapeLike(const Blob &other)
void operator=(const Blob &)=delete
Dtype data_at(const int n, const int c, const int h, const int w) const
void CopyFrom(const Blob< Dtype > &source, bool reshape=false)
Copy from a source Blob.
int shape(int index) const
Returns the dimension of the index-th axis (or the negative index-th axis from the end,...
int offset(const int n, const int c=0, const int h=0, const int w=0) const
int count(int start_axis, int end_axis) const
Compute the volume of a slice; i.e., the product of dimensions among a range of axes.
int count(int start_axis) const
Compute the volume of a slice spanning from a particular first axis to the final axis.
std::string shape_string() const
int LegacyShape(int index) const
const int * gpu_shape() const
void set_cpu_data(Dtype *data)
Blob(const Blob &)=delete
void Reshape(const int num, const int channels, const int height, const int width)
Deprecated; use Reshape(const std::vector<int>& shape).
std::vector< int > shape_
int offset(const std::vector< int > &indices) const
bool use_cuda_host_malloc_
Blob(bool use_cuda_host_malloc)
void ShareData(const Blob &other)
Set the data_ std::shared_ptr to point to the SyncedMemory holding the data_ of Blob other – useful i...
int height() const
Deprecated legacy shape accessor height: use shape(2) instead.
SyncedMemory::SyncedHead head() const
int channels() const
Deprecated legacy shape accessor channels: use shape(1) instead.
int num() const
Deprecated legacy shape accessor num: use shape(0) instead.
Dtype data_at(const std::vector< int > &index) const
void set_gpu_data(Dtype *data)
const std::shared_ptr< SyncedMemory > & data() const
int width() const
Deprecated legacy shape accessor width: use shape(3) instead.
std::shared_ptr< const Blob< Dtype > > BlobConstPtr
constexpr size_t kMaxBlobAxes
std::shared_ptr< Blob< Dtype > > BlobPtr