Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

【complex op No.50】tan_coo/tan_csr(sparse) #67885

Merged
merged 4 commits into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion paddle/phi/kernels/sparse/cpu/unary_grad_kernel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@
kernel->InputAt(0).SetDataLayout(phi::DataLayout::SPARSE_CSR); \
}

PD_REGISTER_SPARSE_UNARY_CPU_GRAD_KERNEL(tan, Tan)
PD_REGISTER_SPARSE_UNARY_CPU_GRAD_KERNEL(asin, Asin)
PD_REGISTER_SPARSE_UNARY_CPU_GRAD_KERNEL(atan, Atan)
PD_REGISTER_SPARSE_UNARY_CPU_GRAD_KERNEL(sinh, Sinh)
Expand All @@ -76,6 +75,7 @@ PD_REGISTER_SPARSE_UNARY_CPU_GRAD_KERNEL(expm1, Expm1)
PD_REGISTER_SPARSE_UNARY_CPU_GRAD_KERNEL(relu6, Relu6)
PD_REGISTER_SPARSE_UNARY_CPU_GRAD_KERNEL(leaky_relu, LeakyRelu)

PD_REGISTER_SPARSE_UNARY_CPU_GRAD_KERNEL_WITH_COMPLEX(tan, Tan)
PD_REGISTER_SPARSE_UNARY_CPU_GRAD_KERNEL_WITH_COMPLEX(sin, Sin)
PD_REGISTER_SPARSE_UNARY_CPU_GRAD_KERNEL_WITH_COMPLEX(abs, Abs)

Expand Down
2 changes: 1 addition & 1 deletion paddle/phi/kernels/sparse/cpu/unary_kernel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ void DivScalarCsrKernel(const Context& dev_ctx,
kernel->InputAt(0).SetDataLayout(phi::DataLayout::SPARSE_CSR); \
}

PD_REGISTER_SPARSE_UNARY_CPU_KERNEL(tan, Tan)
PD_REGISTER_SPARSE_UNARY_CPU_KERNEL(asin, Asin)
PD_REGISTER_SPARSE_UNARY_CPU_KERNEL(atan, Atan)
PD_REGISTER_SPARSE_UNARY_CPU_KERNEL(sinh, Sinh)
Expand All @@ -118,6 +117,7 @@ PD_REGISTER_SPARSE_UNARY_CPU_KERNEL(expm1, Expm1)
PD_REGISTER_SPARSE_UNARY_CPU_KERNEL(relu6, Relu6)
PD_REGISTER_SPARSE_UNARY_CPU_KERNEL(leaky_relu, LeakyRelu)

PD_REGISTER_SPARSE_UNARY_CPU_KERNEL_WITH_COMPLEX(tan, Tan)
PD_REGISTER_SPARSE_UNARY_CPU_KERNEL_WITH_COMPLEX(sin, Sin)
PD_REGISTER_SPARSE_UNARY_CPU_KERNEL_WITH_COMPLEX(abs, Abs)

Expand Down
2 changes: 1 addition & 1 deletion paddle/phi/kernels/sparse/gpu/unary_grad_kernel.cu
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@
kernel->InputAt(0).SetDataLayout(phi::DataLayout::SPARSE_CSR); \
}

PD_REGISTER_SPARSE_UNARY_GPU_GRAD_KERNEL(tan, Tan)
PD_REGISTER_SPARSE_UNARY_GPU_GRAD_KERNEL(asin, Asin)
PD_REGISTER_SPARSE_UNARY_GPU_GRAD_KERNEL(atan, Atan)
PD_REGISTER_SPARSE_UNARY_GPU_GRAD_KERNEL(sinh, Sinh)
Expand All @@ -82,6 +81,7 @@ PD_REGISTER_SPARSE_UNARY_GPU_GRAD_KERNEL(leaky_relu, LeakyRelu)

PD_REGISTER_SPARSE_UNARY_GPU_GRAD_KERNEL_WITH_COMPLEX(sin, Sin)
PD_REGISTER_SPARSE_UNARY_GPU_GRAD_KERNEL_WITH_COMPLEX(abs, Abs)
PD_REGISTER_SPARSE_UNARY_GPU_GRAD_KERNEL_WITH_COMPLEX(tan, Tan)

PD_REGISTER_KERNEL(cast_coo_grad,
GPU,
Expand Down
2 changes: 1 addition & 1 deletion paddle/phi/kernels/sparse/gpu/unary_kernel.cu
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ void DivScalarCsrKernel(const Context& dev_ctx,
kernel->InputAt(0).SetDataLayout(phi::DataLayout::SPARSE_CSR); \
}

PD_REGISTER_SPARSE_UNARY_GPU_KERNEL(tan, Tan)
PD_REGISTER_SPARSE_UNARY_GPU_KERNEL(asin, Asin)
PD_REGISTER_SPARSE_UNARY_GPU_KERNEL(atan, Atan)
PD_REGISTER_SPARSE_UNARY_GPU_KERNEL(sinh, Sinh)
Expand All @@ -111,6 +110,7 @@ PD_REGISTER_SPARSE_UNARY_GPU_KERNEL(expm1, Expm1)
PD_REGISTER_SPARSE_UNARY_GPU_KERNEL(relu6, Relu6)
PD_REGISTER_SPARSE_UNARY_GPU_KERNEL(leaky_relu, LeakyRelu)

PD_REGISTER_SPARSE_UNARY_GPU_KERNEL_WITH_COMPLEX(tan, Tan)
PD_REGISTER_SPARSE_UNARY_GPU_KERNEL_WITH_COMPLEX(sin, Sin)
PD_REGISTER_SPARSE_UNARY_GPU_KERNEL_WITH_COMPLEX(abs, Abs)

Expand Down
2 changes: 1 addition & 1 deletion paddle/phi/kernels/sparse/impl/unary_kernel_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ namespace sparse {
dev_ctx, x.non_zero_elements(), out->mutable_non_zero_elements()); \
}

DEFINE_SPARSE_UNARY_KERNEL(Tan)
DEFINE_SPARSE_UNARY_KERNEL(Asin)
DEFINE_SPARSE_UNARY_KERNEL(Atan)
DEFINE_SPARSE_UNARY_KERNEL(Sinh)
Expand All @@ -120,6 +119,7 @@ DEFINE_SPARSE_UNARY_KERNEL_WITH_ONE_ATTR(Pow, factor)
DEFINE_SPARSE_UNARY_KERNEL_WITH_ONE_ATTR(LeakyRelu, alpha)
DEFINE_SPARSE_UNARY_KERNEL_WITH_COMPLEX(Abs)
DEFINE_SPARSE_UNARY_KERNEL_WITH_COMPLEX(Sin)
DEFINE_SPARSE_UNARY_KERNEL_WITH_COMPLEX(Tan)

template <typename T, typename Context>
void ScaleCooKernel(const Context& dev_ctx,
Expand Down
2 changes: 1 addition & 1 deletion python/paddle/sparse/unary.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def tan(x: Tensor, name: str | None = None) -> Tensor:
out = tan(x)

Parameters:
x (Tensor): The input Sparse Tensor with data type float32, float64.
x (Tensor): The input Sparse Tensor with data type float32, float64, complex64, complex128.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

请对应更新下 docs repo的中文文档。

name (str|None, optional): Name for the operation (optional, default is None).
For more information, please refer to :ref:`api_guide_Name`.

Expand Down
12 changes: 10 additions & 2 deletions test/legacy_test/test_sparse_unary_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,11 @@ def test_sparse_sin(self):
self.compare_with_dense(paddle.sin, paddle.sparse.sin, 'complex128')

def test_sparse_tan(self):
self.compare_with_dense(paddle.tan, paddle.sparse.tan)
self.compare_with_dense(paddle.tan, paddle.sparse.tan, 'float16')
self.compare_with_dense(paddle.tan, paddle.sparse.tan, 'float32')
self.compare_with_dense(paddle.tan, paddle.sparse.tan, 'float64')
self.compare_with_dense(paddle.tan, paddle.sparse.tan, 'complex64')
self.compare_with_dense(paddle.tan, paddle.sparse.tan, 'complex128')

def test_sparse_asin(self):
self.compare_with_dense(paddle.asin, paddle.sparse.asin)
Expand Down Expand Up @@ -400,7 +404,11 @@ def test_sparse_sin(self):
self.compare_with_dense(paddle.sin, paddle.sparse.sin, 'complex128')

def test_sparse_tan(self):
self.compare_with_dense(paddle.tan, paddle.sparse.tan)
self.compare_with_dense(paddle.tan, paddle.sparse.tan, 'float16')
self.compare_with_dense(paddle.tan, paddle.sparse.tan, 'float32')
self.compare_with_dense(paddle.tan, paddle.sparse.tan, 'float64')
self.compare_with_dense(paddle.tan, paddle.sparse.tan, 'complex64')
self.compare_with_dense(paddle.tan, paddle.sparse.tan, 'complex128')

def test_sparse_asin(self):
self.compare_with_dense(paddle.asin, paddle.sparse.asin)
Expand Down