MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / TensorShapeOld

Class TensorShapeOld

tensorflow/core/framework/tensor_shape_test.cc:216–322  ·  view source on GitHub ↗

Manages the dimensions of a Tensor and their sizes.

Source from the content-addressed store, hash-verified

214
215/// Manages the dimensions of a Tensor and their sizes.
216class TensorShapeOld {
217 public:
218 /// \brief Construct a `TensorShape` from the provided sizes.
219 /// REQUIRES: `dim_sizes[i] >= 0`
220 explicit TensorShapeOld(gtl::ArraySlice<int64> dim_sizes);
221 TensorShapeOld(std::initializer_list<int64> dim_sizes)
222 : TensorShapeOld(gtl::ArraySlice<int64>(dim_sizes)) {}
223
224 /// REQUIRES: `IsValid(proto)`
225 explicit TensorShapeOld(const TensorShapeProto& proto);
226
227 /// Create a tensor shape with no dimensions and one element, which you can
228 /// then call `AddDim()` on.
229 TensorShapeOld();
230
231 /// Returns `true` iff `proto` is a valid tensor shape.
232 static bool IsValid(const TensorShapeProto& proto);
233
234 /// Returns `OK` iff `proto` is a valid tensor shape, and a descriptive error
235 /// status otherwise.
236 static Status IsValidShape(const TensorShapeProto& proto);
237
238 /// Clear a tensor shape
239 void Clear();
240
241 /// \brief Add a dimension to the end ("inner-most").
242 /// REQUIRES: `size >= 0`
243 void AddDim(int64 size);
244
245 /// Appends all the dimensions from `shape`.
246 void AppendShape(const TensorShapeOld& shape);
247
248 /// \brief Insert a dimension somewhere in the `TensorShape`.
249 /// REQUIRES: `0 <= d <= dims()`
250 /// REQUIRES: `size >= 0`
251 void InsertDim(int d, int64 size);
252
253 /// \brief Modifies the size of the dimension `d` to be `size`
254 /// REQUIRES: `0 <= d < dims()`
255 /// REQUIRES: `size >= 0`
256 void set_dim(int d, int64 size);
257
258 /// \brief Removes dimension `d` from the `TensorShape`.
259 /// REQUIRES: `0 <= d < dims()`
260 void RemoveDim(int d);
261
262 /// Return the number of dimensions in the tensor.
263 int dims() const { return dim_sizes_.size(); }
264
265 /// \brief Returns the number of elements in dimension `d`.
266 /// REQUIRES: `0 <= d < dims()`
267 // TODO(touts): Rename to `dimension()` to match
268 // `Eigen::Tensor::dimension()`?
269 int64 dim_size(int d) const {
270 DCHECK_GE(d, 0);
271 DCHECK_LT(d, dims());
272 return dim_sizes_[d];
273 }

Callers 1

TESTFunction · 0.85

Calls

no outgoing calls

Tested by 1

TESTFunction · 0.68