Skip to content

Commit 8c17abf

Browse files
committed
feat: add custom __reduce__ to kernels
1 parent 580ef67 commit 8c17abf

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

sumpy/kernel.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,10 @@ def __init__(self, dim: int):
466466
global_scaling_const=1,
467467
)
468468

469+
@override
470+
def __reduce__(self) -> tuple[object, ...]:
471+
return (self.__class__, (self.dim,))
472+
469473
@property
470474
@override
471475
def is_complex_valued(self) -> bool:
@@ -496,6 +500,10 @@ def __init__(self, dim: int) -> None:
496500

497501
super().__init__(dim, expression=expr, global_scaling_const=scaling)
498502

503+
@override
504+
def __reduce__(self) -> tuple[object, ...]:
505+
return (self.__class__, (self.dim,))
506+
499507
@property
500508
@override
501509
def is_complex_valued(self) -> bool:
@@ -545,6 +553,10 @@ def __init__(self, dim: int) -> None:
545553

546554
super().__init__(dim, expression=expr, global_scaling_const=scaling)
547555

556+
@override
557+
def __reduce__(self) -> tuple[object, ...]:
558+
return (self.__class__, (self.dim,))
559+
548560
@property
549561
@override
550562
def is_complex_valued(self) -> bool:
@@ -611,6 +623,13 @@ def __init__(self,
611623
object.__setattr__(self, "helmholtz_k_name", helmholtz_k_name)
612624
object.__setattr__(self, "allow_evanescent", allow_evanescent)
613625

626+
@override
627+
def __reduce__(self) -> tuple[object, ...]:
628+
return (
629+
self.__class__,
630+
(self.dim, self.helmholtz_k_name, self.allow_evanescent),
631+
)
632+
614633
@property
615634
@override
616635
def is_complex_valued(self) -> bool:
@@ -698,6 +717,10 @@ def __init__(self, dim: int, yukawa_lambda_name: str = "lam") -> None:
698717
super().__init__(dim, expression=expr, global_scaling_const=scaling)
699718
object.__setattr__(self, "yukawa_lambda_name", yukawa_lambda_name)
700719

720+
@override
721+
def __reduce__(self) -> tuple[object, ...]:
722+
return (self.__class__, (self.dim, self.yukawa_lambda_name))
723+
701724
@property
702725
@override
703726
def is_complex_valued(self) -> bool:
@@ -964,6 +987,13 @@ def __init__(self,
964987
object.__setattr__(self, "kcomp", kcomp)
965988
object.__setattr__(self, "viscosity_mu", mu)
966989

990+
@override
991+
def __reduce__(self) -> tuple[object, ...]:
992+
return (
993+
self.__class__,
994+
(self.dim, self.icomp, self.jcomp, self.kcomp, self.viscosity_mu),
995+
)
996+
967997
@property
968998
@override
969999
def is_complex_valued(self) -> bool:
@@ -1052,6 +1082,13 @@ def __init__(self,
10521082
object.__setattr__(self, "viscosity_mu", mu)
10531083
object.__setattr__(self, "poisson_ratio", nu)
10541084

1085+
@override
1086+
def __reduce__(self) -> tuple[object, ...]:
1087+
return (
1088+
self.__class__,
1089+
(self.dim, self.axis, self.viscosity_mu, self.poisson_ratio),
1090+
)
1091+
10551092
@property
10561093
@override
10571094
def is_complex_valued(self) -> bool:

0 commit comments

Comments
 (0)