|
|
|
@ -59,7 +59,12 @@ void ColwiseSum<DeviceContext, T>::operator()(const DeviceContext& context,
|
|
|
|
|
framework::Tensor* out) {
|
|
|
|
|
auto in_dims = input.dims();
|
|
|
|
|
auto size = input.numel() / in_dims[0];
|
|
|
|
|
PADDLE_ENFORCE_EQ(out->numel(), size);
|
|
|
|
|
PADDLE_ENFORCE_EQ(out->numel(), size,
|
|
|
|
|
platform::errors::InvalidArgument(
|
|
|
|
|
"The size of output tensor "
|
|
|
|
|
"should be equal to the size of input tensor column"
|
|
|
|
|
" dimension. Expected output size=%d, but received %d",
|
|
|
|
|
size, out->numel()));
|
|
|
|
|
|
|
|
|
|
auto in = framework::EigenMatrix<T>::From(input);
|
|
|
|
|
auto vec = framework::EigenVector<T>::Flatten(*out);
|
|
|
|
@ -78,7 +83,13 @@ class ColwiseSum<platform::CPUDeviceContext, T> {
|
|
|
|
|
auto& in_dims = input.dims();
|
|
|
|
|
auto height = in_dims[0];
|
|
|
|
|
auto size = in_dims[1];
|
|
|
|
|
PADDLE_ENFORCE_EQ(out->numel(), size);
|
|
|
|
|
PADDLE_ENFORCE_EQ(
|
|
|
|
|
out->numel(), size,
|
|
|
|
|
platform::errors::InvalidArgument(
|
|
|
|
|
"The size of output tensor "
|
|
|
|
|
"should be equal to the size of input tensor column"
|
|
|
|
|
" dimension. Expected output size=%d, but received %d",
|
|
|
|
|
size, out->numel()));
|
|
|
|
|
|
|
|
|
|
T* out_buf = out->mutable_data<T>(out->place());
|
|
|
|
|
const T* in_buf = input.data<T>();
|
|
|
|
@ -100,8 +111,16 @@ void RowwiseMean<DeviceContext, T>::operator()(const DeviceContext& context,
|
|
|
|
|
const framework::Tensor& input,
|
|
|
|
|
framework::Tensor* out) {
|
|
|
|
|
auto in_dims = input.dims();
|
|
|
|
|
PADDLE_ENFORCE_EQ(in_dims.size(), 2U);
|
|
|
|
|
PADDLE_ENFORCE_EQ(out->numel(), in_dims[0]);
|
|
|
|
|
PADDLE_ENFORCE_EQ(in_dims.size(), 2U, platform::errors::InvalidArgument(
|
|
|
|
|
"The rank of input tensor "
|
|
|
|
|
"should be 2, but received %d",
|
|
|
|
|
in_dims.size()));
|
|
|
|
|
PADDLE_ENFORCE_EQ(out->numel(), in_dims[0],
|
|
|
|
|
platform::errors::InvalidArgument(
|
|
|
|
|
"The size of output tensor "
|
|
|
|
|
"should be equal to the size of input tensor row"
|
|
|
|
|
" dimension. Expected output size=%d, but received %d",
|
|
|
|
|
in_dims[0], out->numel()));
|
|
|
|
|
|
|
|
|
|
auto in = framework::EigenMatrix<T>::From(input);
|
|
|
|
|
auto vec = framework::EigenVector<T>::Flatten(*out);
|
|
|
|
@ -118,10 +137,19 @@ class RowwiseMean<platform::CPUDeviceContext, T> {
|
|
|
|
|
void operator()(const platform::CPUDeviceContext& context,
|
|
|
|
|
const framework::Tensor& input, framework::Tensor* out) {
|
|
|
|
|
auto& in_dims = input.dims();
|
|
|
|
|
PADDLE_ENFORCE_EQ(in_dims.size(), 2U);
|
|
|
|
|
PADDLE_ENFORCE_EQ(in_dims.size(), 2U, platform::errors::InvalidArgument(
|
|
|
|
|
"The rank of input tensor "
|
|
|
|
|
"should be 2, but received %d",
|
|
|
|
|
in_dims.size()));
|
|
|
|
|
auto height = in_dims[0];
|
|
|
|
|
auto size = in_dims[1];
|
|
|
|
|
PADDLE_ENFORCE_EQ(out->numel(), height);
|
|
|
|
|
PADDLE_ENFORCE_EQ(
|
|
|
|
|
out->numel(), height,
|
|
|
|
|
platform::errors::InvalidArgument(
|
|
|
|
|
"The size of output tensor "
|
|
|
|
|
"should be equal to the size of input tensor row"
|
|
|
|
|
" dimension. Expected output size=%d, but received %d",
|
|
|
|
|
height, out->numel()));
|
|
|
|
|
auto inv_size = 1.0 / size;
|
|
|
|
|
T* out_buf = out->mutable_data<T>(out->place());
|
|
|
|
|
const T* in_buf = input.data<T>();
|
|
|
|
@ -141,8 +169,16 @@ void RowwiseSum<DeviceContext, T>::operator()(const DeviceContext& context,
|
|
|
|
|
const framework::Tensor& input,
|
|
|
|
|
framework::Tensor* out) {
|
|
|
|
|
auto in_dims = input.dims();
|
|
|
|
|
PADDLE_ENFORCE_EQ(in_dims.size(), 2U);
|
|
|
|
|
PADDLE_ENFORCE_EQ(out->numel(), in_dims[0]);
|
|
|
|
|
PADDLE_ENFORCE_EQ(in_dims.size(), 2U, platform::errors::InvalidArgument(
|
|
|
|
|
"The rank of input tensor "
|
|
|
|
|
"should be 2, but received %d",
|
|
|
|
|
in_dims.size()));
|
|
|
|
|
PADDLE_ENFORCE_EQ(out->numel(), in_dims[0],
|
|
|
|
|
platform::errors::InvalidArgument(
|
|
|
|
|
"The size of output tensor "
|
|
|
|
|
"should be equal to the size of input tensor row"
|
|
|
|
|
" dimension. Expected output size=%d, but received %d",
|
|
|
|
|
in_dims[0], out->numel()));
|
|
|
|
|
|
|
|
|
|
auto in = framework::EigenMatrix<T>::From(input);
|
|
|
|
|
auto vec = framework::EigenVector<T>::Flatten(*out);
|
|
|
|
@ -159,10 +195,19 @@ class RowwiseSum<platform::CPUDeviceContext, T> {
|
|
|
|
|
void operator()(const platform::CPUDeviceContext& context,
|
|
|
|
|
const framework::Tensor& input, framework::Tensor* out) {
|
|
|
|
|
auto& in_dims = input.dims();
|
|
|
|
|
PADDLE_ENFORCE_EQ(in_dims.size(), 2U);
|
|
|
|
|
PADDLE_ENFORCE_EQ(in_dims.size(), 2U, platform::errors::InvalidArgument(
|
|
|
|
|
"The rank of input tensor "
|
|
|
|
|
"should be 2, but received %d",
|
|
|
|
|
in_dims.size()));
|
|
|
|
|
auto height = in_dims[0];
|
|
|
|
|
auto size = in_dims[1];
|
|
|
|
|
PADDLE_ENFORCE_EQ(out->numel(), height);
|
|
|
|
|
PADDLE_ENFORCE_EQ(
|
|
|
|
|
out->numel(), height,
|
|
|
|
|
platform::errors::InvalidArgument(
|
|
|
|
|
"The size of output tensor "
|
|
|
|
|
"should be equal to the size of input tensor row"
|
|
|
|
|
" dimension. Expected output size=%d, but received %d",
|
|
|
|
|
height, out->numel()));
|
|
|
|
|
|
|
|
|
|
T* out_buf = out->mutable_data<T>(out->place());
|
|
|
|
|
const T* in_buf = input.data<T>();
|
|
|
|
|