@@ -590,7 +590,7 @@ def parse_unary_docstring(docstring: str) -> List[UnaryCase]:
590
590
Parses a Sphinx-formatted docstring of a unary function to return a list of
591
591
codified unary cases, e.g.
592
592
593
- >>> def sqrt(x: array, /) -> array :
593
+ >>> def sqrt(x) :
594
594
... '''
595
595
... Calculates the square root
596
596
...
@@ -607,14 +607,14 @@ def parse_unary_docstring(docstring: str) -> List[UnaryCase]:
607
607
... Parameters
608
608
... ----------
609
609
... x: array
610
- ... input array. Should have a floating-point data type
610
+ ... input array
611
611
...
612
612
... Returns
613
613
... -------
614
614
... out: array
615
615
... an array containing the square root of each element in ``x``
616
616
... '''
617
- ... ...
617
+ ...
618
618
>>> unary_cases = parse_unary_docstring(sqrt.__doc__)
619
619
>>> for case in unary_cases:
620
620
... print(repr(case))
@@ -1014,6 +1014,46 @@ def cond(i1: float, i2: float) -> bool:
1014
1014
1015
1015
1016
1016
def parse_binary_docstring (docstring : str ) -> List [BinaryCase ]:
1017
+ """
1018
+ Parses a Sphinx-formatted docstring of a binary function to return a list of
1019
+ codified binary cases, e.g.
1020
+
1021
+ >>> def logaddexp(x1, x2):
1022
+ ... '''
1023
+ ... Calculates the logarithm of the sum of exponentiations
1024
+ ...
1025
+ ... **Special Cases**
1026
+ ...
1027
+ ... For floating-point operands,
1028
+ ...
1029
+ ... - If either ``x1_i`` or ``x2_i`` is ``NaN``, the result is ``NaN``.
1030
+ ... - If ``x1_i`` is ``+infinity`` and ``x2_i`` is not ``NaN``, the
1031
+ ... result is ``+infinity``.
1032
+ ... - If ``x1_i`` is not ``NaN`` and ``x2_i`` is ``+infinity``, the
1033
+ ... result is ``+infinity``.
1034
+ ...
1035
+ ... Parameters
1036
+ ... ----------
1037
+ ... x1: array
1038
+ ... first input array
1039
+ ... x2: array
1040
+ ... second input array
1041
+ ...
1042
+ ... Returns
1043
+ ... -------
1044
+ ... out: array
1045
+ ... an array containing the results
1046
+ ... '''
1047
+ ...
1048
+ >>> binary_cases = parse_binary_docstring(logaddexp.__doc__)
1049
+ >>> for case in binary_cases:
1050
+ ... print(repr(case))
1051
+ BinaryCase(x1_i == NaN or x2_i == NaN -> NaN)
1052
+ BinaryCase(x1_i == +infinity and not x2_i == NaN -> +infinity)
1053
+ BinaryCase(not x1_i == NaN and x2_i == +infinity -> +infinity)
1054
+
1055
+ """
1056
+
1017
1057
match = r_special_cases .search (docstring )
1018
1058
if match is None :
1019
1059
return []
0 commit comments