template <typename DstType, typename SrcType>
bool CastOp<CPUContext>::DoRunWithType() {
auto& input = Input(0);
- auto* output = Output(0);
- output->ResizeLike(input);
+
+ auto* output = Output(0, input.sizes(), at::dtype<DstType>());
const auto* data = input.template data<SrcType>();
auto* out = output->template mutable_data<DstType>();
auto N = input.numel();
bool RunOnDevice() override {
auto& X = Input(0);
- auto* Y = Output(0);
- Y->ResizeLike(X);
+
+ auto* Y = Output(0, X.sizes(), at::dtype<float>());
const float* Xdata = X.template data<float>();
float* Ydata = Y->template mutable_data<float>();
template <>
bool ChannelShuffleOp<float, CPUContext>::RunOnDeviceWithOrderNCHW() {
const auto& X = Input(0);
- auto* Y = Output(0);
- Y->ResizeLike(X);
+
+ auto* Y = Output(0, X.sizes(), at::dtype<float>());
const int N = X.dim32(0);
const int C = X.dim32(1);
const int G = group_;
template <>
bool ChannelShuffleOp<float, CPUContext>::RunOnDeviceWithOrderNHWC() {
const auto& X = Input(0);
- auto* Y = Output(0);
- Y->ResizeLike(X);
+
+ auto* Y = Output(0, X.sizes(), at::dtype<float>());
const int ndim = X.dim();
const int N = X.dim32(0);
const int C = X.dim32(ndim - 1);
template <>
bool ChannelShuffleGradientOp<float, CPUContext>::RunOnDeviceWithOrderNCHW() {
const auto& dY = Input(0);
- auto* dX = Output(0);
- dX->ResizeLike(dY);
+
+ auto* dX = Output(0, dY.sizes(), at::dtype<float>());
const int N = dY.dim32(0);
const int C = dY.dim32(1);
const int G = group_;
template <>
bool ChannelShuffleGradientOp<float, CPUContext>::RunOnDeviceWithOrderNHWC() {
const auto& dY = Input(0);
- auto* dX = Output(0);
- dX->ResizeLike(dY);
+
+ auto* dX = Output(0, dY.sizes(), at::dtype<float>());
const int ndim = dY.dim();
const int N = dY.dim32(0);
const int C = dY.dim32(ndim - 1);
template <>
bool ClipOp<float, CPUContext>::RunOnDevice() {
auto& X = Input(0);
- auto* Y = Output(0);
- Y->ResizeLike(X);
+
+ auto* Y = Output(0, X.sizes(), at::dtype<float>());
EigenVectorMap<float>(Y->template mutable_data<float>(), Y->numel()) =
ConstEigenVectorMap<float>(X.data<float>(), X.numel())
.cwiseMax(min_)
bool ClipGradientOp<float, CPUContext>::RunOnDevice() {
auto& Y = Input(0);
auto& dY = Input(1);
- auto* dX = Output(0);
+
CAFFE_ENFORCE_GE(Y.numel(), 0);
CAFFE_ENFORCE_EQ(dY.numel(), Y.numel());
- dX->ResizeLike(Y);
+ auto* dX = Output(0, Y.sizes(), at::dtype<float>());
const float* Ydata = Y.data<float>();
const float* dYdata = dY.data<float>();
float* dXdata = dX->template mutable_data<float>();
auto& X = Input(INPUT);
auto& filter = Input(FILTER);
auto& dY = Input(OUTPUT_GRAD);
- auto* dfilter = Output(FILTER_GRAD);
CAFFE_ENFORCE(X.dim() >= 3 && X.dim() <= 5);
CAFFE_ENFORCE(filter.dim() >= 3 && filter.dim() <= 5);
} else {
CAFFE_THROW("Unsupported kernel size:", kernel_.size());
}
- dfilter->ResizeLike(filter);
+ auto* dfilter = Output(FILTER_GRAD, filter.sizes(), at::dtype<T_DW>());
// Set up the cudnn algorithms & workspace if necessary
bool input_changed = (X.sizes() != cudnn_input_dims_);
data_perf_stat;
cudnn_wrapper_.with_cudnn_state(
cudnn_state_, [&](CuDNNState* state) {
- auto* dX =
- Output(no_bias_ ? BIAS_OR_INPUT_GRAD : INPUT_GRAD);
- dX->ResizeLike(X);
+ auto* dX = Output(
+ no_bias_ ? BIAS_OR_INPUT_GRAD : INPUT_GRAD,
+ X.sizes(),
+ at::dtype<T_DX>());
const T_W* filter_data = filter.template data<T_W>();
const T_DY* dYdata = dY.template data<T_DY>();
T_DX* dXdata = dX->template mutable_data<T_DX>();
dfilter->template mutable_data<T_DW>()));
if (OutputSize() == 3 || (no_bias_ && (OutputSize() == 2))) {
// Compute the gradient w.r.t. the input.
- auto* dX = Output(no_bias_ ? BIAS_OR_INPUT_GRAD : INPUT_GRAD);
- dX->ResizeLike(X);
+
+ auto* dX = Output(
+ no_bias_ ? BIAS_OR_INPUT_GRAD : INPUT_GRAD,
+ X.sizes(),
+ at::dtype<T_DX>());
CUDNN_ENFORCE(cudnnConvolutionBackwardData(
state->cudnn_handle(),
cudnnTypeWrapper<T_W>::kOne(),
auto& X = Input(INPUT);
auto& filter = Input(FILTER);
auto& dY = Input(OUTPUT_GRAD);
- auto* dfilter = Output(FILTER_GRAD);
+
const int N = X.dim32(0), C = X.dim32(1);
const vector<int> input_dims = this->GetDims(X);
}
CAFFE_ENFORCE_EQ(M % group_, 0);
- dfilter->ResizeLike(filter);
+ auto* dfilter = Output(FILTER_GRAD, filter.sizes(), at::dtype<T>());
// The dimension of each kernel
const int kernel_dim = C / group_ * kernel_dims_size;
// The offset corresponding to a single input image, and a single output
}
if (OutputSize() == 3 || (no_bias_ && (OutputSize() == 2))) {
// Compute the gradient w.r.t. the input.
- auto* dX = Output(no_bias_ ? BIAS_OR_INPUT_GRAD : INPUT_GRAD);
- dX->ResizeLike(X);
+
+ auto* dX = Output(
+ no_bias_ ? BIAS_OR_INPUT_GRAD : INPUT_GRAD, X.sizes(), at::dtype<T>());
T* dXdata = dX->template mutable_data<T>();
dYdata = dY.template data<T>();
for (int image_id = 0; image_id < N; ++image_id) {
auto& X = Input(INPUT);
auto& filter = Input(FILTER);
auto& dY = Input(OUTPUT_GRAD);
- auto* dfilter = Output(FILTER_GRAD);
+
const int N = X.dim32(0), C = X.dim32(X.dim() - 1);
const vector<int> input_dims = this->GetDims(X);
}
CAFFE_ENFORCE_EQ(M % group_, 0);
- dfilter->ResizeLike(filter);
+ auto* dfilter = Output(FILTER_GRAD, filter.sizes(), at::dtype<T>());
// The dimension of each kernel
const int kernel_dim = C / group_ * kernel_dims_size;
// The offset corresponding to a single input image, and a single output
if (OutputSize() == 3 || (no_bias_ && (OutputSize() == 2))) {
// Compute the gradient w.r.t. the input.
- auto* dX = Output(no_bias_ ? BIAS_OR_INPUT_GRAD : INPUT_GRAD);
- dX->ResizeLike(X);
+
+ auto* dX = Output(
+ no_bias_ ? BIAS_OR_INPUT_GRAD : INPUT_GRAD, X.sizes(), at::dtype<T>());
T* dXdata = dX->template mutable_data<T>();
for (int image_id = 0; image_id < N; ++image_id) {
// Compute gradient into col_buffer.
auto& X = Input(INPUT);
auto& filter = Input(FILTER);
auto& dY = Input(OUTPUT_GRAD);
- auto* dfilter = Output(FILTER_GRAD);
+
CAFFE_ENFORCE_EQ(X.dim(), 4);
CAFFE_ENFORCE_EQ(filter.dim(), 4);
int C = 0;
}
// Since we only handle LegacyPadding::NOTSET, we don't need to
// compute padding.
- dfilter->ResizeLike(filter);
+ auto* dfilter = Output(FILTER_GRAD, filter.sizes(), at::dtype<T>());
// Set up the cudnn algorithms & workspace if necessary
bool input_changed = (X.sizes() != cudnn_input_dims_);
if (OutputSize() == 3 || (no_bias_ && (OutputSize() == 2))) {
// Compute the gradient w.r.t. the input.
- auto* dX = Output(no_bias_ ? BIAS_OR_INPUT_GRAD : INPUT_GRAD);
- dX->ResizeLike(X);
+
+ auto* dX = Output(
+ no_bias_ ? BIAS_OR_INPUT_GRAD : INPUT_GRAD,
+ X.sizes(),
+ at::dtype<T>());
CUDNN_ENFORCE(cudnnConvolutionForward(
state->cudnn_handle(),
cudnnTypeWrapper<T>::kOne(),
auto& X = Input(INPUT);
auto& filter = Input(FILTER);
auto& dY = Input(OUTPUT_GRAD);
- auto* dfilter = Output(FILTER_GRAD);
+
const int N = X.dim32(0), M = X.dim32(1), H = X.dim32(2), W = X.dim32(3);
// We only handle LegacyPadding::NOTSET case and ignore cases of
// LegacyPadding::VALID and LegacyPadding::SAME
CAFFE_ENFORCE(
filter.dim32(3) == this->kernel_w(),
"filter width must be equal to kernel width");
- dfilter->ResizeLike(filter);
+ auto* dfilter = Output(FILTER_GRAD, filter.sizes(), at::dtype<T>());
const int kernel_dim = C * this->kernel_h() * this->kernel_w();
const int output_image_size = dY.dim32(2) * dY.dim32(3);
// Compute gradients w.r.t. the input
// Since we have changed dYdata in the above loop, we will need to reset.
dYdata = dY.template data<T>();
- auto* dX = Output(no_bias_ ? BIAS_OR_INPUT_GRAD : INPUT_GRAD);
- dX->ResizeLike(X);
+
+ auto* dX = Output(
+ no_bias_ ? BIAS_OR_INPUT_GRAD : INPUT_GRAD, X.sizes(), at::dtype<T>());
T* dXdata = dX->template mutable_data<T>();
for (auto image_id = 0; image_id < N; ++image_id) {
// Im2Col.
auto& X = Input(INPUT);
auto& filter = Input(FILTER);
auto& dY = Input(OUTPUT_GRAD);
- auto* dfilter = Output(FILTER_GRAD);
+
const int N = X.dim32(0), H = X.dim32(1), W = X.dim32(2), M = X.dim32(3);
// We only handle LegacyPadding::NOTSET case and ignore cases of
// LegacyPadding::VALID and LegacyPadding::SAME
filter.dim32(2) == this->kernel_w(),
"filter width must be equal to kernel width");
const int C = filter.dim32(3);
- dfilter->ResizeLike(filter);
+ auto* dfilter = Output(FILTER_GRAD, filter.sizes(), at::dtype<T>());
const int kernel_dim = C * this->kernel_h() * this->kernel_w();
const int output_image_size = dY.dim32(1) * dY.dim32(2);
// Compute gradients w.r.t. the input
// Since we have changed dYdata in the above loop, we will need to reset.
dYdata = dY.template data<T>();
- auto* dX = Output(no_bias_ ? BIAS_OR_INPUT_GRAD : INPUT_GRAD);
- dX->ResizeLike(X);
+
+ auto* dX = Output(
+ no_bias_ ? BIAS_OR_INPUT_GRAD : INPUT_GRAD, X.sizes(), at::dtype<T>());
T* dXdata = dX->template mutable_data<T>();
for (auto image_id = 0; image_id < N; ++image_id) {
// Im2Col.
bool CosineEmbeddingCriterionOp<CPUContext>::RunOnDevice() {
auto& S = Input(0);
auto& Y = Input(1);
- auto* output = Output(0);
+
CAFFE_ENFORCE(
S.numel() == Y.numel(),
"The embedding and label should have the same size.");
- output->ResizeLike(S);
+ auto* output = Output(0, S.sizes(), at::dtype<float>());
const float* Sdata = S.data<float>();
const int* Ydata = Y.data<int>();
auto& S = Input(0);
auto& Y = Input(1);
auto& dOutput = Input(2);
- auto* dS = Output(0);
- dS->ResizeLike(S);
+ auto* dS = Output(0, S.sizes(), at::dtype<float>());
const float* Sdata = S.data<float>();
const int* Ydata = Y.data<int>();
bool RunOnDevice() override {
auto& data = Input(0);
auto& newBestIdicies = Input(1);
- auto* updatedData = Output(0);
CAFFE_ENFORCE(
data.dim() == 2 && newBestIdicies.dim() == 1,
data.size(0) == newBestIdicies.size(0),
"predictions and bestPath dimensions not matching");
- updatedData->ResizeLike(data);
+ auto* updatedData = Output(0, data.sizes(), at::dtype<float>());
float* outData = updatedData->template mutable_data<float>();
context_.CopyItemsSameDevice(
data.dtype(), data.numel(), data.template data<float>(), outData);
const auto outer_size = logits.numel() / inner_size;
CAFFE_ENFORCE(g.numel() == outer_size);
- auto* out = Output(0);
- out->ResizeLike(logits);
+ auto* out = Output(0, logits.sizes(), at::dtype<float>());
auto* out_ptr = out->template mutable_data<float>();
auto* logits_ptr = logits.data<float>();
const auto outer_size = logits.numel() / inner_size;
CAFFE_ENFORCE(g.numel() == outer_size);
- auto* out = Output(0);
- out->ResizeLike(logits);
+ auto* out = Output(0, logits.sizes(), at::dtype<float>());
auto* out_ptr = out->template mutable_data<float>();
auto* logits_ptr = logits.data<float>();
auto& X = Input(0);
auto& label = Input(1);
auto& dY = Input(2);
- auto* dX = Output(0);
+
int N, D;
if (X.dim() > 1) {
N = X.dim32(0);
CAFFE_ENFORCE_EQ(label.dim32(0), N);
CAFFE_ENFORCE_EQ(dY.dim(), 1);
CAFFE_ENFORCE_EQ(dY.dim32(0), N);
- dX->ResizeLike(X);
+ auto* dX = Output(0, X.sizes(), at::dtype<float>());
math::Set<float, CPUContext>(
dX->numel(), 0.f, dX->template mutable_data<float>(), &context_);
const float* Xdata = X.data<float>();
auto& X = Input(0);
auto& label = Input(1);
auto& dY = Input(2);
- auto* dX = Output(0);
+
int N, D;
if (X.dim() > 1) {
N = X.dim32(0);
CAFFE_ENFORCE_EQ(label.dim32(0), N);
CAFFE_ENFORCE_EQ(dY.dim(), 1);
CAFFE_ENFORCE_EQ(dY.dim32(0), N);
- dX->ResizeLike(X);
+ auto* dX = Output(0, X.sizes(), at::dtype<float>());
math::Set<float, CPUContext>(
dX->numel(), 0.f, dX->template mutable_data<float>(), &context_);
const float* Xdata = X.data<float>();
auto& X = Input(0);
auto& Y = Input(1);
auto& dDistance = Input(2);
- auto* dX = Output(0);
- auto* dY = Output(1);
+
CAFFE_ENFORCE_EQ(X.dim(), Y.dim());
for (int i = 0; i < X.dim(); ++i) {
CAFFE_ENFORCE_EQ(X.dim32(i), Y.dim32(i));
}
CAFFE_ENFORCE(dDistance.dim() == 1);
CAFFE_ENFORCE(dDistance.dim32(0) == N);
- dX->ResizeLike(X);
- dY->ResizeLike(Y);
+ auto* dX = Output(0, X.sizes(), at::dtype<float>());
+ auto* dY = Output(1, Y.sizes(), at::dtype<float>());
for (int i = 0; i < N; ++i) {
auto offset = i * D;
auto& X = Input(X_IN);
auto& Y = Input(Y_IN);
auto& dCos = Input(DER_COS_IN);
- auto* dX = Output(DER_X_OUT);
- auto* dY = Output(DER_Y_OUT);
+
const int N = X.dim() > 0 ? X.dim32(0) : 1;
const int D = X.size_from_dim(1);
CAFFE_ENFORCE(X.dim() == Y.dim());
}
CAFFE_ENFORCE(dCos.dim() == 1);
CAFFE_ENFORCE(dCos.dim32(0) == N);
- dX->ResizeLike(X);
- dY->ResizeLike(Y);
+ auto* dX = Output(DER_X_OUT, X.sizes(), at::dtype<float>());
+ auto* dY = Output(DER_Y_OUT, Y.sizes(), at::dtype<float>());
const auto* X_data = X.template data<float>();
const auto* Y_data = Y.template data<float>();
auto& X = Input(X_IN);
auto& Y = Input(Y_IN);
auto& dDot = Input(DER_DOT_IN);
- auto* dX = Output(DER_X_OUT);
- auto* dY = Output(DER_Y_OUT);
+
int N, D;
if (X.numel() > 0) {
N = X.dim() > 0 ? X.dim32(0) : 1;
}
CAFFE_ENFORCE(dDot.dim() == 1);
CAFFE_ENFORCE(dDot.dim32(0) == N);
- dX->ResizeLike(X);
- dY->ResizeLike(Y);
+ auto* dX = Output(DER_X_OUT, X.sizes(), at::dtype<float>());
+ auto* dY = Output(DER_Y_OUT, Y.sizes(), at::dtype<float>());
const auto* X_data = X.template data<float>();
const auto* Y_data = Y.template data<float>();
auto& X = Input(0);
auto& Y = Input(1);
auto& dDistance = Input(2);
- auto* dX = Output(0);
- auto* dY = Output(1);
+
int N = X.dim() > 0 ? X.dim32(0) : 1;
int D = N > 0 ? X.numel() / N : 0;
CAFFE_ENFORCE(X.dim() == Y.dim());
}
CAFFE_ENFORCE(dDistance.dim() == 1);
CAFFE_ENFORCE(dDistance.dim32(0) == N);
- dX->ResizeLike(X);
- dY->ResizeLike(Y);
+ auto* dX = Output(0, X.sizes(), at::dtype<T>());
+ auto* dY = Output(1, Y.sizes(), at::dtype<T>());
math::Sub<T, Context>(
X.numel(),
X.template data<T>(),
auto& X = Input(X_IN);
auto& Y = Input(Y_IN);
auto& dDot = Input(DER_DOT_IN);
- auto* dX = Output(DER_X_OUT);
- auto* dY = Output(DER_Y_OUT);
+
int N, D, DX, DY, restD;
if (X.numel() > 0) {
N = X.dim() > 0 ? X.dim32(0) : 1;
CAFFE_ENFORCE_EQ(X.dim32(0), Y.dim32(0));
CAFFE_ENFORCE_EQ(dDot.dim(), 1);
CAFFE_ENFORCE_EQ(dDot.dim32(0), N);
- dX->ResizeLike(X);
- dY->ResizeLike(Y);
+ auto* dX = Output(DER_X_OUT, X.sizes(), at::dtype<T>());
+ auto* dY = Output(DER_Y_OUT, Y.sizes(), at::dtype<T>());
const auto* X_data = X.template data<T>();
const auto* Y_data = Y.template data<T>();
template <typename T>
bool DoRunWithType() {
- auto* dA = Output(0);
- auto* dB = Output(1);
const T* dC_data = nullptr;
const T* A_data = nullptr;
const T* B_data = nullptr;
const T* C_data = nullptr;
std::vector<int> A_dims;
std::vector<int> B_dims;
+ at::IntList dA_sizes;
+ at::IntList dB_sizes;
if (InputSize() == 3) {
const auto& B = Input(0);
const auto& C = Input(1);
B_data = B.template data<T>();
C_data = C.template data<T>();
dC_data = dC.template data<T>();
- dA->ResizeLike(C);
- dB->ResizeLike(B);
+ dA_sizes = C.sizes();
+ dB_sizes = B.sizes();
} else {
const auto& dC = Input(0);
const auto& A = Input(1);
A_data = A.template data<T>();
B_data = B.template data<T>();
C_data = C.template data<T>();
- dA->ResizeLike(A);
- dB->ResizeLike(B);
+ dA_sizes = A.sizes();
+ dB_sizes = B.sizes();
}
+ auto* dA = Output(0, dA_sizes, at::dtype<T>());
+ auto* dB = Output(1, dB_sizes, at::dtype<T>());
auto* dA_data = dA->template mutable_data<T>();
auto* dB_data = dB->template mutable_data<T>();
return functor_.Backward(
const auto& X = Input(0);
const auto& a = Input(1);
const auto& b = Input(2);
- auto* Y = Output(0);
const auto canonical_axis = X.canonical_axis_index(axis_);
const int N = X.size_to_dim(canonical_axis);
CAFFE_ENFORCE_EQ(b.dim(), 1, b.dim());
CAFFE_ENFORCE_EQ(b.size(0), D, b.dim());
- Y->ResizeLike(X);
+ auto* Y = Output(0, X.sizes(), at::dtype<float>());
const float* X_data = X.data<float>();
const float* a_data = a.data<float>();
CAFFE_ENFORCE_EQ(a.dim(), 1, a.dim());
CAFFE_ENFORCE_EQ(a.size(0), D, a.dim());
- auto* g_X = Output(0);
- auto *g_a = Output(1);
- auto *g_b = Output(2);
- g_X->ResizeLike(X);
- g_a->ResizeLike(a);
- g_b->ResizeLike(a);
+ auto* g_X = Output(0, X.sizes(), at::dtype<float>());
+ auto* g_a = Output(1, a.sizes(), at::dtype<float>());
+ auto* g_b = Output(2, a.sizes(), at::dtype<float>());
const float* g_o_data = g_o.data<float>();
const float* X_data = X.data<float>();
auto& select = Input(0);
auto& left = Input(1);
auto& right = Input(2);
- auto* output = Output(0);
+
if (enable_broadcast_) {
CAFFE_ENFORCE_EQ(select.dim(), 1);
CAFFE_ENFORCE_EQ(select.size(0), right.size(0));
CAFFE_ENFORCE_EQ(select.sizes(), left.sizes());
CAFFE_ENFORCE_EQ(select.sizes(), right.sizes());
}
- output->ResizeLike(left);
+ auto* output = Output(0, left.sizes(), at::dtype<T>());
const bool* select_data = select.template data<bool>();
const T* left_data = left.template data<T>();
template <typename T>
bool DoRunWithType() {
auto& input = Input(0);
- auto* output = Output(0);
- output->ResizeLike(input);
+
+ auto* output = Output(0, input.sizes(), at::dtype<bool>());
if (!values_.has_values()) {
values_.set(this->template GetRepeatedArgument<T>(VALUE_TAG));
bool SumReduceLikeOp<CPUContext>::DoRunWithType() {
const auto& A = Input(0);
const auto& B = Input(1);
- auto* C = Output(0);
- CAFFE_ENFORCE(&B != C, "In-place is not allowed.");
- C->ResizeLike(B);
+
+ CAFFE_ENFORCE(!IsInputOutputAlias(1, 0), "In-place is not allowed.");
+ auto* C = Output(0, B.sizes(), at::dtype<T>());
const T* Adata = A.template data<T>();
auto* Cdata = C->template mutable_data<T>();
if (B.numel() == 1) {
template <typename T>
bool DoRunWithType() {
const auto& X = Input(0);
- auto* Y = Output(0);
- Y->ResizeLike(X);
+
+ auto* Y = Output(
+ 0, X.sizes(), at::dtype<typename OutputTypeMap::template type<T>>());
return functor_(
X.numel(),
X.template data<T>(),
const auto& dC = Input(0);
const auto& A = Input(1);
const auto& B = Input(2);
- auto* dA = Output(0);
- auto* dB = Output(1);
+
vector<int> A_dims;
vector<int> B_dims;
if (legacy_broadcast_) {
dC.template data<typename GradientTypeMap::template type<T>>();
const T* A_data = A.template data<T>();
const T* B_data = B.template data<T>();
- dA->ResizeLike(A);
- dB->ResizeLike(B);
+ auto* dA = Output(
+ 0, A.sizes(), at::dtype<typename GradientTypeMap::template type<T>>());
+ auto* dB = Output(
+ 1, B.sizes(), at::dtype<typename GradientTypeMap::template type<T>>());
auto* dA_data =
dA->template mutable_data<typename GradientTypeMap::template type<T>>();
auto* dB_data =
template <typename T>
bool DoRunWithType() {
const auto& X = Input(0);
- auto* Y = Output(0);
- Y->ResizeLike(X);
+
+ auto* Y = Output(0, X.sizes(), at::dtype<T>());
if (X.numel() == 0) {
Y->template mutable_data<T>();
return true;
bool DoRunWithType() {
const auto& Y = Input(0);
const auto& dY = Input(1);
- auto* dX = Output(0);
- dX->ResizeLike(Y);
+
+ auto* dX = Output(0, Y.sizes(), at::dtype<T>());
if (Y.numel() == 0) {
dX->template mutable_data<T>();
return true;
this, Input(INDICES));
} else {
auto& X = Input(PARAM);
- auto* Y = Output(OUTPUT_PARAM);
- Y->ResizeLike(X);
+
+ auto* Y = Output(OUTPUT_PARAM, X.sizes(), at::dtype<float>());
EigenVectorMap<float>(Y->template mutable_data<float>(), Y->numel()) =
ConstEigenVectorMap<float>(X.template data<float>(), X.numel())
.cwiseMax(min_)
bool DoRunWithType() {
const auto& dY = Input(0);
const auto& X = Input(1);
- auto* dX = Output(0);
+
const int ndim = dY.dim();
const std::vector<int> dX_dims(X.sizes().cbegin(), X.sizes().cend());
const std::vector<int> dY_dims(dY.sizes().cbegin(), dY.sizes().cend());
- dX->ResizeLike(X);
+ auto* dX = Output(0, X.sizes(), at::dtype<T>());
std::vector<int> axes;
const int offset = ndim - X.dim();
for (int i = 0; i < ndim; i++) {
bool DoRunWithType() {
auto& idx = Input(0);
auto& needles = Input(1);
- auto* res_indices = Output(0);
- res_indices->ResizeLike(needles);
+
+ auto* res_indices = Output(0, needles.sizes(), at::dtype<T>());
const T* idx_data = idx.template data<T>();
const T* needles_data = needles.template data<T>();
bool RunOnDevice() override {
auto& X = Input(0);
- auto* Y = Output(0);
- Y->ResizeLike(X);
+
+ auto* Y = Output(0, X.sizes(), at::dtype<float>());
const float* Xdata = X.template data<float>();
float* Ydata = Y->template mutable_data<float>();
CAFFE_ENFORCE(M * K == X.numel(), dimErrorString());
CAFFE_ENFORCE(K * N == W.numel(), dimErrorString());
- auto* dW = Output(0);
-
- dW->ResizeLike(W);
+ auto* dW = Output(0, W.sizes(), at::dtype<T_DW>());
auto* db = Output(1, {N}, at::dtype<T_DB>());
if (X.numel() == 0) {
&context_);
if (OutputSize() == 3) {
- auto* dX = Output(2);
- dX->ResizeLike(X);
- dX->template mutable_data<T_DX>();
+ Output(2, X.sizes(), at::dtype<T_DX>());
}
return true;
// Compute dX
if (OutputSize() == 3) {
- auto* dX = Output(2);
- dX->ResizeLike(X);
+ auto* dX = Output(2, X.sizes(), at::dtype<T_DX>());
math::Gemm<T_DX, Context, Engine>(
CblasNoTrans,
TransposeWeight ? CblasNoTrans : CblasTrans,
CAFFE_ENFORCE_EQ(beta.numel(), C);
const int G = group_;
const int D = C / G;
- auto* Y = Output(OUTPUT);
- Y->ResizeLike(X);
+
+ auto* Y = Output(OUTPUT, X.sizes(), at::dtype<T>());
T* mu_data = nullptr;
T* rsig_data = nullptr;
if (OutputSize() == 3) {
CAFFE_ENFORCE_EQ(beta.numel(), C);
const int G = group_;
const int D = C / G;
- auto* dX = Output(INPUT_GRAD);
- auto* dgamma = Output(GAMMA_GRAD);
- auto* dbeta = Output(BETA_GRAD);
- dX->ResizeLike(X);
- dgamma->ResizeLike(gamma);
- dbeta->ResizeLike(beta);
+
+ auto* dX = Output(INPUT_GRAD, X.sizes(), at::dtype<T>());
+ auto* dgamma = Output(GAMMA_GRAD, gamma.sizes(), at::dtype<T>());
+ auto* dbeta = Output(BETA_GRAD, beta.sizes(), at::dtype<T>());
return RunOnDeviceImpl(
N,
G,