獲取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];
}