获取Op的输入和输出 const auto& X = Input(0):获取第一个输入,注意输入一般为常量类型,因为我们一般只读不更改数据。 auto* Y = Output(0): 指向第一个输出,不能为常量类型。 X是一个Tensor对象,可以按照操作一个Tensor的方式去操作X,在tensor.h中可以找到具体的方法。
获得输入的维度信息 vector dims_
/**
* Returns the i-th dimension of the tensor in int.
* 返回第i维的值,是一个int型
* This function returns an int value instead of TIndex, which depending on
* the typedef could be int64. If you want int64 dim values, make sure you
* call dim() instead.
*/
inline int dim32(const int i) const {
#ifndef NDEBUG
CAFFE_ENFORCE_LT_WITH_CALLER(i, dims_.size(), "Exceeding ndim limit");
CAFFE_ENFORCE_GE_WITH_CALLER(i, 0, "Cannot have negative dimension index");
#endif
CAFFE_ENFORCE_LT_WITH_CALLER(dims_[i], std::numeric_limits<int>::max());
return static_cast<int>(dims_[i]);
}
/**
* Returns the i-th dimension of the tensor. Note that the passed in index
* must be between 0 (inclusive) and the number of dimensions, otherwise
* this function will produce a fatal message.
*/
inline TIndex dim(const int i) const {
#ifndef NDEBUG
CAFFE_ENFORCE_LT_WITH_CALLER(i, dims_.size(), "Exceeding ndim limit");
CAFFE_ENFORCE_GE_WITH_CALLER(i, 0, "Cannot have negative dimension index");
#endif
return dims_[i];
}