Skip to content

Commit

Permalink
change var name
Browse files Browse the repository at this point in the history
  • Loading branch information
Rayman96 committed Aug 24, 2022
1 parent 5b4af77 commit d1d8454
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 35 deletions.
6 changes: 3 additions & 3 deletions paddle/fluid/operators/triu_indices_op.cc
Expand Up @@ -37,12 +37,12 @@ class TriuIndicesOpMaker : public framework::OpProtoAndCheckerMaker {
void Make() override {
AddOutput("out",
"Tensor, the output tensor, with the shape (2,x), x bounded by "
"[0,rows*cols])");
AddAttr<int>("rows",
"[0,row*col])");
AddAttr<int>("row",
"int number, the input of triu_indices op"
"which describes the number of row of the matrix")
.SetDefault(0);
AddAttr<int>("cols",
AddAttr<int>("col",
"int number, the input of triu_indices op"
"which describes the number of col of the matrix")
.SetDefault(0);
Expand Down
6 changes: 3 additions & 3 deletions paddle/phi/api/yaml/legacy_api.yaml
Expand Up @@ -2748,14 +2748,14 @@
backward : trilinear_interp_grad

- api : triu_indices
args : (int rows, int cols, int offset, DataType dtype, Place place={})
args : (int row, int col, int offset, DataType dtype, Place place={})
output : Tensor(out)
infer_meta :
func : TriuIndicesInferMeta
param : [rows, cols, offset, dtype]
param : [row, col, offset, dtype]
kernel :
func : triu_indices
param : [rows, cols, offset, dtype]
param : [row, col, offset, dtype]
data_type : dtype
backend : place

Expand Down
12 changes: 6 additions & 6 deletions paddle/phi/infermeta/nullary.cc
Expand Up @@ -154,7 +154,7 @@ void TrilIndicesInferMeta(
}

void TriuIndicesInferMeta(
int rows, int cols, int offset, DataType dtype, MetaTensor* out) {
int row, int col, int offset, DataType dtype, MetaTensor* out) {
// number of elements in the first row of the tril,bounded by [0, cols]
// use total item number minus bottom rectangle item number to get
// the above rectangle item number
Expand All @@ -163,21 +163,21 @@ void TriuIndicesInferMeta(
// the item on the diagonal line
offset = offset - 1;
auto n_first_row =
offset > 0 ? std::min<int64_t>(cols, 1 + offset) : rows + offset > 0;
offset > 0 ? std::min<int64_t>(col, 1 + offset) : row + offset > 0;
// number of elements in the last row of the tril, bounded by [0, cols]
auto n_last_row =
std::max<int64_t>(0, std::min<int64_t>(cols, rows + offset));
std::max<int64_t>(0, std::min<int64_t>(col, row + offset));
// number of rows, bounded by [0, rows]
auto n_row_all = std::max<int64_t>(0, std::min<int64_t>(rows, rows + offset));
auto n_row_all = std::max<int64_t>(0, std::min<int64_t>(row, row + offset));
auto n_row_trapezoid = (n_last_row - n_first_row + 1);
// calculate # of elements in the top trapezoid
auto tril_size = (n_first_row + n_last_row) * n_row_trapezoid >> 1;
// calculate # of elements in the bottom rectangle if there is any
auto diff_row = n_row_all - n_row_trapezoid;
if (diff_row > 0) {
tril_size += diff_row * cols;
tril_size += diff_row * col;
}
std::vector<int64_t> tmp = {2, rows * cols - tril_size};
std::vector<int64_t> tmp = {2, row * col - tril_size};
auto out_dims = phi::make_ddim(tmp);
out->set_dims(out_dims);
out->set_dtype(dtype);
Expand Down
2 changes: 1 addition & 1 deletion paddle/phi/infermeta/nullary.h
Expand Up @@ -76,5 +76,5 @@ void TrilIndicesInferMeta(
int rows, int cols, int offset, DataType dtype, MetaTensor* out);

void TriuIndicesInferMeta(
int rows, int cols, int offset, DataType dtype, MetaTensor* out);
int row, int col, int offset, DataType dtype, MetaTensor* out);
} // namespace phi
6 changes: 3 additions & 3 deletions paddle/phi/kernels/cpu/triu_indices_kernel.cc
Expand Up @@ -20,8 +20,8 @@
namespace phi {
template <typename T, typename Context>
void TriuIndicesKernel(const Context& dev_ctx,
int rows,
int cols,
int row,
int col,
int offset,
DataType dtype,
DenseTensor* out) {
Expand All @@ -36,7 +36,7 @@ void TriuIndicesKernel(const Context& dev_ctx,

// move to the next column and check if (r, c) is still in bound
c += 1;
if (c >= cols) {
if (c >= col) {
r += 1;
// not typing std::max with scalar_t as it could be an unsigned type
// NOTE: not necessary to check if c is less than col or overflows here,
Expand Down
14 changes: 7 additions & 7 deletions paddle/phi/kernels/gpu/triu_indices_kernel.cu
Expand Up @@ -25,7 +25,7 @@ namespace phi {

template <typename T>
__device__ inline int resolve_root_int(int b, int cX4, int x, int32_t sign) {
int bXb_cX4 = b * b - cX4;
int64_t bXb_cX4 = b * b - cX4;
double sr = ::sqrt(static_cast<double>(bXb_cX4));
T res = ::__double2ll_rd((-b + sign * sr) / 2);
if (bXb_cX4 != static_cast<int>(sr * sr)) {
Expand Down Expand Up @@ -90,8 +90,8 @@ __global__ void triu_indices_kernel(T* out_data,

template <typename T, typename Context>
void TriuIndicesKernel(const Context& dev_ctx,
int rows,
int cols,
int row,
int col,
int offset,
DataType dtype,
DenseTensor* out) {
Expand All @@ -103,14 +103,14 @@ void TriuIndicesKernel(const Context& dev_ctx,

if (triu_size > 0) {
// # of triu elements in the first row
auto m_first_row = offset > 0 ? std::max<int>(cols - offset, 0)
auto m_first_row = offset > 0 ? std::max<int>(col - offset, 0)
: // upper bounded by col
cols;
col;

// size of the top rectangle
int rectangle_size = 0;
if (offset < 0) {
rectangle_size = std::min<int>(rows, -offset) * cols;
rectangle_size = std::min<int>(row, -offset) * col;
}

// using gpu_launch_config to get grid_size and block_size
Expand All @@ -122,7 +122,7 @@ void TriuIndicesKernel(const Context& dev_ctx,
dev_ctx.stream()>>>(out_data,
std::max<int>(0, offset),
m_first_row,
cols,
col,
rectangle_size,
triu_size);
}
Expand Down
4 changes: 2 additions & 2 deletions paddle/phi/kernels/triu_indices_kernel.h
Expand Up @@ -20,8 +20,8 @@ namespace phi {

template <typename T, typename Context>
void TriuIndicesKernel(const Context& dev_ctx,
int rows,
int cols,
int row,
int col,
int offset,
DataType dtype,
DenseTensor* out);
Expand Down
14 changes: 7 additions & 7 deletions python/paddle/fluid/tests/unittests/test_triu_indices_op.py
Expand Up @@ -36,26 +36,26 @@ def test_check_output(self):
self.check_output()

def init_config(self):
self.attrs = {'rows': 4, 'cols': 4, 'offset': -1}
self.target = np.triu_indices(self.attrs['rows'], self.attrs['offset'],
self.attrs['cols'])
self.attrs = {'row': 4, 'col': 4, 'offset': -1}
self.target = np.triu_indices(self.attrs['row'], self.attrs['offset'],
self.attrs['col'])
self.target = np.array(self.target)


class TestTriuIndicesOpCase1(TestTriuIndicesOp):

def init_config(self):
self.attrs = {'rows': 0, 'cols': 0, 'offset': 0}
self.attrs = {'row': 0, 'col': 0, 'offset': 0}
self.target = np.triu_indices(0, 0, 0)
self.target = np.array(self.target)


class TestTriuIndicesOpCase2(TestTriuIndicesOp):

def init_config(self):
self.attrs = {'rows': 4, 'cols': 4, 'offset': 2}
self.target = np.triu_indices(self.attrs['rows'], self.attrs['offset'],
self.attrs['cols'])
self.attrs = {'row': 4, 'col': 4, 'offset': 2}
self.target = np.triu_indices(self.attrs['row'], self.attrs['offset'],
self.attrs['col'])
self.target = np.array(self.target)


Expand Down
6 changes: 3 additions & 3 deletions python/paddle/tensor/creation.py
Expand Up @@ -1989,7 +1989,7 @@ def triu_indices(row, col=None, offset=0, dtype='int64'):
return out

if _in_legacy_dygraph():
out = _C_ops.triu_indices('rows', row, 'cols', col, 'offset', offset,
out = _C_ops.triu_indices('row', row, 'col', col, 'offset', offset,
"dtype", dtype)
return out

Expand All @@ -2002,8 +2002,8 @@ def triu_indices(row, col=None, offset=0, dtype='int64'):
inputs={},
outputs={'out': [out]},
attrs={
'rows': row,
'cols': col,
'row': row,
'col': col,
'offset': offset,
'dtype': dtype
})
Expand Down

0 comments on commit d1d8454

Please sign in to comment.