Skip to content

Commit e11e940

Browse files
committed
docs: improve kernel docs
1 parent 559b6d8 commit e11e940

2 files changed

Lines changed: 140 additions & 8 deletions

File tree

doc/conf.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
from urllib.request import urlopen
33

44

5-
_conf_url = \
6-
"https://raw.githubusercontent.com/inducer/sphinxconfig/main/sphinxconfig.py"
5+
_conf_url = "https://raw.githubusercontent.com/inducer/sphinxconfig/main/sphinxconfig.py"
76
with urlopen(_conf_url) as _inf:
87
exec(compile(_inf.read(), _conf_url, "exec"), globals())
98

@@ -30,9 +29,13 @@
3029
]
3130

3231
sphinxconfig_missing_reference_aliases = {
32+
# sympy
33+
"sp.Matrix": "class:sympy.matrices.dense.DenseMatrix",
3334
# pymbolic
34-
"Expression": "obj:pymbolic.typing.Expression",
3535
"ArithmeticExpression": "obj:pymbolic.ArithmeticExpression",
36+
"Expression": "obj:pymbolic.typing.Expression",
37+
# sumpy
38+
"ArithmeticExpr": "obj:sumpy.kernel.ArithmeticExpr",
3639
}
3740

3841

sumpy/kernel.py

Lines changed: 134 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,25 +69,46 @@
6969
Kernel interface
7070
----------------
7171
72-
.. autoclass:: Kernel
72+
.. autoclass:: ArithmeticExpr
73+
7374
.. autoclass:: KernelArgument
75+
.. autoclass:: Kernel
76+
:show-inheritance:
7477
7578
Symbolic kernels
7679
----------------
7780
7881
.. autoclass:: ExpressionKernel
82+
:show-inheritance:
83+
:members: mapper_method
7984
8085
PDE kernels
8186
-----------
8287
8388
.. autoclass:: LaplaceKernel
89+
:show-inheritance:
90+
:members: mapper_method
8491
.. autoclass:: BiharmonicKernel
92+
:show-inheritance:
93+
:members: mapper_method
8594
.. autoclass:: HelmholtzKernel
95+
:show-inheritance:
96+
:members: mapper_method
8697
.. autoclass:: YukawaKernel
98+
:show-inheritance:
99+
:members: mapper_method
87100
.. autoclass:: StokesletKernel
101+
:show-inheritance:
102+
:members: mapper_method
88103
.. autoclass:: StressletKernel
104+
:show-inheritance:
105+
:members: mapper_method
89106
.. autoclass:: ElasticityKernel
107+
:show-inheritance:
108+
:members: mapper_method
90109
.. autoclass:: LineOfCompressionKernel
110+
:show-inheritance:
111+
:members: mapper_method
91112
92113
Derivatives
93114
-----------
@@ -97,22 +118,50 @@
97118
98119
.. autoclass:: DerivativeBase
99120
.. autoclass:: AxisTargetDerivative
121+
:show-inheritance:
122+
:undoc-members:
123+
:members: mapper_method,target_array_name
100124
.. autoclass:: AxisSourceDerivative
125+
:show-inheritance:
126+
:members: mapper_method
127+
.. autoclass:: DirectionalDerivative
128+
:show-inheritance:
129+
:members: directional_kind
101130
.. autoclass:: DirectionalSourceDerivative
131+
:show-inheritance:
132+
:members: mapper_method,directional_kind
102133
.. autoclass:: DirectionalTargetDerivative
134+
:show-inheritance:
135+
:undoc-members:
136+
:members: mapper_method,directional_kind,target_array_name
103137
104138
Transforming kernels
105139
--------------------
106140
141+
.. autoclass:: TargetPointMultiplier
142+
:undoc-members:
143+
:members: mapper_method,target_array_name
144+
145+
.. autoclass:: ResultT
146+
107147
.. autoclass:: KernelMapper
148+
:show-inheritance:
108149
.. autoclass:: KernelCombineMapper
150+
:show-inheritance:
109151
.. autoclass:: KernelIdentityMapper
152+
:show-inheritance:
110153
.. autoclass:: AxisSourceDerivativeRemover
154+
:show-inheritance:
111155
.. autoclass:: AxisTargetDerivativeRemover
156+
:show-inheritance:
112157
.. autoclass:: SourceDerivativeRemover
158+
:show-inheritance:
113159
.. autoclass:: TargetDerivativeRemover
114-
.. autoclass:: TargetPointMultiplier
160+
:show-inheritance:
161+
.. autoclass:: TargetTransformationRemover
162+
:show-inheritance:
115163
.. autoclass:: DerivativeCounter
164+
:show-inheritance:
116165
"""
117166

118167
ArithmeticExpr: TypeAlias = int | float | complex | sym.Basic
@@ -145,7 +194,7 @@ class Kernel(ABC):
145194
.. autoattribute:: is_translation_invariant
146195
147196
.. autoattribute:: dim
148-
.. autoattribute:: is_complex_valued
197+
.. autoproperty:: is_complex_valued
149198
150199
.. automethod:: get_base_kernel
151200
.. automethod:: replace_base_kernel
@@ -516,6 +565,11 @@ def get_pde_as_diff_op(self) -> LinearPDESystemOperator:
516565

517566
@dataclass(frozen=True)
518567
class HelmholtzKernel(ExpressionKernel):
568+
"""
569+
.. autoattribute:: helmholtz_k_name
570+
.. autoattribute:: allow_evanescent
571+
"""
572+
519573
mapper_method: ClassVar[str] = "map_helmholtz_kernel"
520574

521575
helmholtz_k_name: str
@@ -592,6 +646,10 @@ def get_pde_as_diff_op(self) -> LinearPDESystemOperator:
592646

593647
@dataclass(frozen=True)
594648
class YukawaKernel(ExpressionKernel):
649+
"""
650+
.. autoattribute:: yukawa_lambda_name
651+
"""
652+
595653
mapper_method: ClassVar[str] = "map_yukawa_kernel"
596654

597655
yukawa_lambda_name: str
@@ -675,6 +733,12 @@ def get_pde_as_diff_op(self) -> LinearPDESystemOperator:
675733

676734
@dataclass(frozen=True)
677735
class ElasticityKernel(ExpressionKernel):
736+
"""
737+
.. autoattribute:: icomp
738+
.. autoattribute:: jcomp
739+
.. autoattribute:: viscosity_mu
740+
.. autoattribute:: poisson_ratio
741+
"""
678742
mapper_method: ClassVar[str] = "map_elasticity_kernel"
679743

680744
icomp: int
@@ -791,6 +855,12 @@ def get_pde_as_diff_op(self) -> LinearPDESystemOperator:
791855

792856

793857
class StokesletKernel(ElasticityKernel):
858+
"""
859+
.. autoattribute:: icomp
860+
.. autoattribute:: jcomp
861+
.. autoattribute:: viscosity_mu
862+
"""
863+
794864
def __new__(cls, dim, icomp, jcomp, viscosity_mu="mu", poisson_ratio=0.5):
795865
return object.__new__(cls)
796866

@@ -806,6 +876,12 @@ def __str__(self) -> str:
806876

807877
@dataclass(frozen=True)
808878
class StressletKernel(ExpressionKernel):
879+
"""
880+
.. autoattribute:: icomp
881+
.. autoattribute:: jcomp
882+
.. autoattribute:: kcomp
883+
.. autoattribute:: viscosity_mu
884+
"""
809885
mapper_method: ClassVar[str] = "map_stresslet_kernel"
810886

811887
icomp: int
@@ -893,6 +969,10 @@ class LineOfCompressionKernel(ExpressionKernel):
893969
*Force at a Point in the Interior of a Semi-Infinite Solid*.
894970
Physics. 7 (5): 195-202.
895971
`doi:10.1063/1.1745385 <https://doi.org/10.1063/1.1745385>`__.
972+
973+
.. autoattribute:: axis
974+
.. autoattribute:: viscosity_mu
975+
.. autoattribute:: poisson_ratio
896976
"""
897977

898978
mapper_method: ClassVar[str] = "map_line_of_compression_kernel"
@@ -976,6 +1056,7 @@ def get_pde_as_diff_op(self) -> LinearPDESystemOperator:
9761056
@dataclass(frozen=True)
9771057
class KernelWrapper(Kernel, ABC):
9781058
inner_kernel: Kernel
1059+
"""The kernel that is being wrapped (to take a derivative of, etc.)."""
9791060

9801061
def __init__(self, inner_kernel: Kernel) -> None:
9811062
Kernel.__init__(self, inner_kernel.dim)
@@ -1056,16 +1137,26 @@ def get_derivative_taker(
10561137
# {{{ derivatives
10571138

10581139
class DerivativeBase(KernelWrapper, ABC):
1140+
"""
1141+
.. autoattribute:: inner_kernel
1142+
"""
1143+
10591144
@override
10601145
def get_pde_as_diff_op(self) -> LinearPDESystemOperator:
10611146
return self.inner_kernel.get_pde_as_diff_op()
10621147

10631148

10641149
@dataclass(frozen=True)
10651150
class AxisSourceDerivative(DerivativeBase):
1151+
"""
1152+
.. autoattribute:: axis
1153+
.. automethod:: replace_inner_kernel
1154+
"""
1155+
10661156
mapper_method: ClassVar[str] = "map_axis_source_derivative"
10671157

10681158
axis: int
1159+
"""Direction axis for the source derivative."""
10691160

10701161
def __init__(self, axis: int, inner_kernel: Kernel) -> None:
10711162
super().__init__(inner_kernel)
@@ -1095,11 +1186,20 @@ def replace_base_kernel(self, new_base_kernel: Kernel) -> Kernel:
10951186
inner_kernel=self.inner_kernel.replace_base_kernel(new_base_kernel))
10961187

10971188
def replace_inner_kernel(self, new_inner_kernel: Kernel) -> Kernel:
1189+
"""Replace the inner kernel of this wrapper.
1190+
1191+
This is essentially the same as :meth:`Kernel.replace_base_kernel`, but it does
1192+
not recurse.
1193+
"""
10981194
return replace(self, inner_kernel=new_inner_kernel)
10991195

11001196

11011197
@dataclass(frozen=True)
11021198
class AxisTargetDerivative(DerivativeBase):
1199+
"""
1200+
.. autoattribute:: axis
1201+
"""
1202+
11031203
mapper_method: ClassVar[str] = "map_axis_target_derivative"
11041204
target_array_name: ClassVar[str] = "targets"
11051205

@@ -1178,8 +1278,14 @@ def map_common_subexpression_uncached(self,
11781278

11791279
@dataclass(frozen=True)
11801280
class DirectionalDerivative(DerivativeBase):
1281+
"""
1282+
.. autoattribute:: dir_vec_name
1283+
"""
11811284
directional_kind: ClassVar[Literal["src", "tgt"]]
1285+
"""The kind of this directional derivative (can only be a source or target)."""
1286+
11821287
dir_vec_name: str
1288+
"""Name of the vector used for the direction."""
11831289

11841290
def __init__(self, inner_kernel: Kernel, dir_vec_name: str | None = None) -> None:
11851291
if dir_vec_name is None:
@@ -1196,7 +1302,6 @@ def __str__(self) -> str:
11961302

11971303
class DirectionalTargetDerivative(DirectionalDerivative):
11981304
mapper_method: ClassVar[str] = "map_directional_target_derivative"
1199-
12001305
directional_kind: ClassVar[Literal["src", "tgt"]] = "tgt"
12011306
target_array_name: ClassVar[str] = "targets"
12021307

@@ -1328,14 +1433,19 @@ def prepare_loopy_kernel(self, loopy_knl: lp.TranslationUnit) -> lp.TranslationU
13281433

13291434

13301435
class TargetPointMultiplier(KernelWrapper):
1331-
"""Wraps a kernel :math:`G(x, y)` and outputs :math:`x_j G(x, y)`
1436+
"""Bases: :class:`Kernel`
1437+
1438+
Wraps a kernel :math:`G(x, y)` and outputs :math:`x_j G(x, y)`
13321439
where :math:`x, y` are targets and sources respectively.
1440+
1441+
.. autoattribute:: axis
13331442
"""
13341443

13351444
mapper_method: ClassVar[str] = "map_target_point_multiplier"
13361445
target_array_name: ClassVar[str] = "targets"
13371446

13381447
axis: int
1448+
"""Coordinate axis with which to multiply the kernel."""
13391449

13401450
def __init__(self, axis: int, inner_kernel: Kernel) -> None:
13411451
KernelWrapper.__init__(self, inner_kernel)
@@ -1402,6 +1512,9 @@ def get_pde_as_diff_op(self) -> LinearPDESystemOperator:
14021512

14031513

14041514
class KernelMapper(Generic[ResultT]):
1515+
"""
1516+
.. automethod:: __call__
1517+
"""
14051518
def rec(self, kernel: Kernel) -> ResultT:
14061519
try:
14071520
method = cast(
@@ -1417,6 +1530,10 @@ def __call__(self, kernel: Kernel) -> ResultT:
14171530

14181531

14191532
class KernelCombineMapper(KernelMapper[ResultT], ABC):
1533+
"""
1534+
.. automethod:: combine
1535+
"""
1536+
14201537
@abstractmethod
14211538
def combine(self, values: Iterable[ResultT]) -> ResultT:
14221539
raise NotImplementedError
@@ -1473,32 +1590,42 @@ def map_directional_source_derivative(
14731590

14741591

14751592
class AxisSourceDerivativeRemover(KernelIdentityMapper):
1593+
"""Removes all axis source derivatives from the kernel."""
1594+
14761595
@override
14771596
def map_axis_source_derivative(self, kernel: AxisSourceDerivative) -> Kernel:
14781597
return self.rec(kernel.inner_kernel)
14791598

14801599

14811600
class AxisTargetDerivativeRemover(KernelIdentityMapper):
1601+
"""Removes all axis target derivatives from the kernel."""
1602+
14821603
@override
14831604
def map_axis_target_derivative(self, kernel: AxisTargetDerivative) -> Kernel:
14841605
return self.rec(kernel.inner_kernel)
14851606

14861607

14871608
class TargetDerivativeRemover(AxisTargetDerivativeRemover):
1609+
"""Removes all target derivatives from the kernel."""
1610+
14881611
@override
14891612
def map_directional_target_derivative(
14901613
self, kernel: DirectionalTargetDerivative) -> Kernel:
14911614
return self.rec(kernel.inner_kernel)
14921615

14931616

14941617
class SourceDerivativeRemover(AxisSourceDerivativeRemover):
1618+
"""Removes all source derivatives from the kernel."""
1619+
14951620
@override
14961621
def map_directional_source_derivative(
14971622
self, kernel: DirectionalSourceDerivative) -> Kernel:
14981623
return self.rec(kernel.inner_kernel)
14991624

15001625

15011626
class TargetTransformationRemover(TargetDerivativeRemover):
1627+
"""Removes all target transformations from the kernel."""
1628+
15021629
@override
15031630
def map_target_point_multiplier(self, kernel: TargetPointMultiplier) -> Kernel:
15041631
return self.rec(kernel.inner_kernel)
@@ -1508,6 +1635,8 @@ def map_target_point_multiplier(self, kernel: TargetPointMultiplier) -> Kernel:
15081635

15091636

15101637
class DerivativeCounter(KernelCombineMapper[int]):
1638+
"""Counts the number of derivatives in the kernel."""
1639+
15111640
@override
15121641
def combine(self, values: Iterable[int]) -> int:
15131642
return sum(values)

0 commit comments

Comments
 (0)