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

[WIP] 【Complex op】No.38 add complex support for matrix_power #56549

Closed
Closed
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
4 changes: 3 additions & 1 deletion paddle/phi/kernels/cpu/matrix_power_grad_kernel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,6 @@ PD_REGISTER_KERNEL(matrix_power_grad,
ALL_LAYOUT,
phi::MatrixPowerGradKernel,
float,
double) {}
double,
phi::dtype::complex64,
phi::dtype::complex128) {}
10 changes: 8 additions & 2 deletions paddle/phi/kernels/cpu/matrix_power_kernel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,11 @@ limitations under the License. */
#include "paddle/phi/core/kernel_registry.h"
#include "paddle/phi/kernels/impl/matrix_power_kernel_impl.h"

PD_REGISTER_KERNEL(
matrix_power, CPU, ALL_LAYOUT, phi::MatrixPowerKernel, float, double) {}
PD_REGISTER_KERNEL(matrix_power,
CPU,
ALL_LAYOUT,
phi::MatrixPowerKernel,
float,
double,
phi::dtype::complex64,
phi::dtype::complex128) {}
4 changes: 3 additions & 1 deletion paddle/phi/kernels/gpu/matrix_power_grad_kernel.cu
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,6 @@ PD_REGISTER_KERNEL(matrix_power_grad,
ALL_LAYOUT,
phi::MatrixPowerGradKernel,
float,
double) {}
double,
phi::dtype::complex64,
phi::dtype::complex128) {}
10 changes: 8 additions & 2 deletions paddle/phi/kernels/gpu/matrix_power_kernel.cu
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,11 @@ limitations under the License. */
#include "paddle/phi/core/kernel_registry.h"
#include "paddle/phi/kernels/impl/matrix_power_kernel_impl.h"

PD_REGISTER_KERNEL(
matrix_power, GPU, ALL_LAYOUT, phi::MatrixPowerKernel, float, double) {}
PD_REGISTER_KERNEL(matrix_power,
GPU,
ALL_LAYOUT,
phi::MatrixPowerKernel,
float,
double,
phi::dtype::complex64,
phi::dtype::complex128) {}
76 changes: 76 additions & 0 deletions test/legacy_test/test_matrix_power_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,82 @@ def config(self):
self.n = -1


class TestMatrixPowerOpCP64(TestMatrixPowerOp):
def config(self):
self.matrix_shape = [10, 10]
self.dtype = "complex64"
self.n = 2

def test_grad(self):
self.check_grad(["X"], "Out", max_relative_error=1e-5)


class TestMatrixPowerOpBatchedCP64(TestMatrixPowerOpCP64):
def config(self):
self.matrix_shape = [2, 8, 4, 4]
self.dtype = "complex64"
self.n = 2


class TestMatrixPowerOpLarge1CP64(TestMatrixPowerOpCP64):
def config(self):
self.matrix_shape = [32, 32]
self.dtype = "complex64"
self.n = 2


class TestMatrixPowerOpLarge2CP64(TestMatrixPowerOpCP64):
def config(self):
self.matrix_shape = [10, 10]
self.dtype = "complex64"
self.n = 32


class TestMatrixPowerOpCP64Minus(TestMatrixPowerOpCP64):
def config(self):
self.matrix_shape = [10, 10]
self.dtype = "complex64"
self.n = -1


class TestMatrixPowerOpCP128(TestMatrixPowerOp):
def config(self):
self.matrix_shape = [10, 10]
self.dtype = "complex128"
self.n = 2

def test_grad(self):
self.check_grad(["X"], "Out", max_relative_error=1e-5)


class TestMatrixPowerOpBatchedCP128(TestMatrixPowerOpCP128):
def config(self):
self.matrix_shape = [2, 8, 4, 4]
self.dtype = "complex128"
self.n = 2


class TestMatrixPowerOpLarge1CP128(TestMatrixPowerOpCP128):
def config(self):
self.matrix_shape = [32, 32]
self.dtype = "complex128"
self.n = 2


class TestMatrixPowerOpLarge2CP128(TestMatrixPowerOpCP128):
def config(self):
self.matrix_shape = [10, 10]
self.dtype = "complex128"
self.n = 32


class TestMatrixPowerOpCP128Minus(TestMatrixPowerOpCP128):
def config(self):
self.matrix_shape = [10, 10]
self.dtype = "complex128"
self.n = -1


class TestMatrixPowerAPI(unittest.TestCase):
def setUp(self):
np.random.seed(123)
Expand Down