dmlc/mshadow

The CroppingExp for RValue

Closed this issue · 5 comments

Hi,
this issue is comming from:How to copy the data from the Tensor 'src' to the crop of Tensor 'dst'?. i'm not familiar with mshadow, it puzzled me here:

i found that the extensions which support RValue(like SliceExp, ConcatExp ) is inherited from TRValue, but the currently CroppingExp is inherited from MakeTensorExp, so should we change this?

would someone give some more advises for doing this?
i guess we should add REval in Plan structer, like slice and concat, are there any other place to pay attention to?
ths~

I think we can nolonger use MakeTensorExp, but need to do it similarly as slice

@tqchen , i tried it today, but faild, and i think if we change crop to support RValue, we also need to change uppooling,pack_col2patch, to support RValue, for the reasons:
one change in the code of the crop() should be:
change

template<typename SrcExp, typename Device, typename DType, int etype>
inline CroppingExp<SrcExp, Device, DType, ExpInfo<SrcExp>::kDim>
crop(const Exp<SrcExp, DType, etype> &src, Shape<2> oshape) {
  TypeCheckPass<ExpInfo<SrcExp>::kDim >= 2>
      ::Error_Expression_Does_Not_Meet_Dimension_Req();
  return CroppingExp<SrcExp, Device, DType, ExpInfo<SrcExp>::kDim>(src.self(), oshape);
}

to

template<typename SrcExp, typename Device, typename DType, int srcdim>
inline CroppingExp<SrcExp, Device, DType, ExpInfo<SrcExp>::kDim>
crop(const TRValue<SrcExp, Device, srcdim, DType> &src, Shape<2> oshape) {
  // TypeCheckPass<ExpInfo<SrcExp>::kDim >= 2>
  //     ::Error_Expression_Does_Not_Meet_Dimension_Req();
  return CroppingExp<SrcExp, Device, DType, ExpInfo<SrcExp>::kDim>(src.self(), oshape);
}

(the first param template of crop(), from Exp to TRValue.)

but when we using crop() in convolution-inl.h:217, pooling-inl.h:139,pooling-inl.h:127, deconvolution-inl.h:132, it passed the MakeTensorExp object:uppooling,pack_col2patch, so we'll not directly use these exps.
if analyse above is correct, then we should change more source file in mshadow, and this is risky, i think.

and any other temporary trick for apache/mxnet#686 ?
ths~

Oh, i see, you can try to use slice then, something like

slice<3>( slice<2>(X, xbegin, xend), ybegin, yend) = src

wow, i test it just now, and it works.
ths~