Skip to content

Commit

Permalink
lint fix (apache#178)
Browse files Browse the repository at this point in the history
  • Loading branch information
piiswrong authored Nov 20, 2016
1 parent bb0f8c7 commit c8643fa
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 12 deletions.
4 changes: 4 additions & 0 deletions mshadow/base.h
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ extern "C" {
}

#if !(MSHADOW_USE_CUDA && MSHADOW_USE_CUDNN == 1 && CUDNN_MAJOR >= 5)
/*! \brief dummy definition when not using cudnn */
typedef int cudnnTensorFormat_t;
#endif

Expand Down Expand Up @@ -303,6 +304,7 @@ struct DataType<int32_t> {
/*! \brief type enum value for default real type */
const int default_type_flag = DataType<default_real_t>::kFlag;

/*! layout flag */
enum LayoutFlag {
kNCHW = 0,
kNHWC,
Expand Down Expand Up @@ -336,6 +338,7 @@ struct LayoutType<kNHWC> {
#endif
};

/*! \brief default layout for 4d tensor */
const int default_layout = kNCHW;

template<>
Expand All @@ -358,6 +361,7 @@ struct LayoutType<kNDHWC> {
#endif
};

/*! \brief default layout for 5d tensor */
const int default_layout_5d = kNCDHW;

/*! \brief namespace for operators */
Expand Down
38 changes: 26 additions & 12 deletions mshadow/tensor.h
Original file line number Diff line number Diff line change
Expand Up @@ -241,65 +241,79 @@ MSHADOW_XINLINE Shape<5> Shape5(index_t s0, index_t s1, index_t s2,
return s;
}

/*!
* \brief Convert shape in src_layout to shape in dst_layout
* \param src original shape
* \param src_layout layout of original shape
* \param dst_layout target layout
* \return shape in target layout
*/
inline Shape<4> ConvertLayout(const Shape<4>& src, int src_layout, int dst_layout) {
Shape<4> dst;
switch (src_layout) {
case kNCHW:
case kNCHW:
dst = src;
break;
case kNHWC:
case kNHWC:
dst[0] = src[0];
dst[2] = src[1];
dst[3] = src[2];
dst[1] = src[3];
break;
default:
default:
LOG(FATAL) << "Invalid layout for 4d shape " << src_layout;
}
Shape<4> dst2;
switch (dst_layout) {
case kNCHW:
case kNCHW:
return dst;
case kNHWC:
case kNHWC:
dst2[0] = dst[0];
dst2[1] = dst[2];
dst2[2] = dst[3];
dst2[3] = dst[1];
break;
default:
default:
LOG(FATAL) << "Invalid layout for 4d shape " << src_layout;
}
return dst2;
}

/*!
* \brief Convert shape in src_layout to shape in dst_layout
* \param src original shape
* \param src_layout layout of original shape
* \param dst_layout target layout
* \return shape in target layout
*/
inline Shape<5> ConvertLayout(const Shape<5>& src, int src_layout, int dst_layout) {
Shape<5> dst;
switch (src_layout) {
case kNCDHW:
case kNCDHW:
dst = src;
break;
case kNDHWC:
case kNDHWC:
dst[0] = src[0];
dst[2] = src[1];
dst[3] = src[2];
dst[4] = src[3];
dst[1] = src[4];
break;
default:
default:
LOG(FATAL) << "Invalid layout for 5d shape " << src_layout;
}
Shape<5> dst2;
switch (dst_layout) {
case kNCDHW:
case kNCDHW:
return dst;
case kNDHWC:
case kNDHWC:
dst2[0] = dst[0];
dst2[1] = dst[2];
dst2[2] = dst[3];
dst2[3] = dst[4];
dst2[4] = dst[1];
break;
default:
default:
LOG(FATAL) << "Invalid layout for 5d shape " << src_layout;
}
return dst2;
Expand Down

0 comments on commit c8643fa

Please sign in to comment.