PyFinitDiff 2.0.3.post0__py3-none-any.whl → 2.1.2.post0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
PyFinitDiff/_version.py CHANGED
@@ -12,5 +12,5 @@ __version__: str
12
12
  __version_tuple__: VERSION_TUPLE
13
13
  version_tuple: VERSION_TUPLE
14
14
 
15
- __version__ = version = '2.0.3.post0'
16
- __version_tuple__ = version_tuple = (2, 0, 3)
15
+ __version__ = version = '2.1.2.post0'
16
+ __version_tuple__ = version_tuple = (2, 1, 2)
@@ -15,15 +15,19 @@ config_dict = ConfigDict(
15
15
  frozen=False
16
16
  )
17
17
 
18
-
19
18
  @dataclass(config=config_dict)
20
19
  class Boundary:
21
- """Class representing a boundary with a specific name, value, and mesh information.
22
-
23
- Attributes:
24
- name (str): The name of the boundary.
25
- value (Optional[str]): The value associated with the boundary.
26
- mesh_info (object): The mesh information object.
20
+ """
21
+ Class representing a boundary with a specific name, value, and mesh information.
22
+
23
+ Parameters
24
+ ----------
25
+ name : str
26
+ The name of the boundary.
27
+ value : Optional[str]
28
+ The value associated with the boundary, such as 'symmetric', 'anti-symmetric', 'zero', or 'none'.
29
+ mesh_info : object
30
+ The mesh information object containing information about the mesh size and structure.
27
31
  """
28
32
 
29
33
  name: str
@@ -31,13 +35,18 @@ class Boundary:
31
35
  mesh_info: object
32
36
 
33
37
  def get_factor(self) -> float:
34
- """Gets the factor associated with the boundary value.
38
+ """
39
+ Get the factor associated with the boundary value.
35
40
 
36
- Returns:
37
- float: The factor corresponding to the boundary value.
41
+ Returns
42
+ -------
43
+ float
44
+ The factor corresponding to the boundary value.
38
45
 
39
- Raises:
40
- ValueError: If the boundary value is unexpected.
46
+ Raises
47
+ ------
48
+ ValueError
49
+ If the boundary value is unexpected.
41
50
  """
42
51
  match self.value:
43
52
  case 'symmetric':
@@ -52,16 +61,23 @@ class Boundary:
52
61
  raise ValueError(f"Unexpected boundary value: {self.value}")
53
62
 
54
63
  def get_shift_vector(self, offset: int) -> Optional[numpy.ndarray]:
55
- """Calculates the shift vector based on the boundary name and offset.
56
-
57
- Args:
58
- offset (int): The offset value to be used in the shift vector calculation.
59
-
60
- Returns:
61
- Optional[numpy.ndarray]: The shift vector as a numpy array, or None if the boundary name is 'center'.
62
-
63
- Raises:
64
- ValueError: If the boundary name is unexpected.
64
+ """
65
+ Calculate the shift vector based on the boundary name and offset.
66
+
67
+ Parameters
68
+ ----------
69
+ offset : int
70
+ The offset value to be used in the shift vector calculation.
71
+
72
+ Returns
73
+ -------
74
+ Optional[numpy.ndarray]
75
+ The shift vector as a numpy array, or None if the boundary name is 'center'.
76
+
77
+ Raises
78
+ ------
79
+ ValueError
80
+ If the boundary name is unexpected.
65
81
  """
66
82
  offset = abs(offset)
67
83
 
@@ -79,16 +95,21 @@ class Boundary:
79
95
  case _:
80
96
  raise ValueError(f"Unexpected boundary name: {self.name}")
81
97
 
82
-
83
98
  @dataclass(config=config_dict)
84
99
  class Boundaries:
85
- """Class representing the boundaries with left and right values.
86
-
87
- Attributes:
88
- left (Optional[str]): Value of the left boundary. Defaults to 'zero' must be either ['zero', 'symmetric', 'anti-symmetric'].
89
- right (Optional[str]): Value of the right boundary. Defaults to 'zero' either ['zero', 'symmetric', 'anti-symmetric'].
90
- acceptable_boundary (List[str]): List of acceptable boundary values.
91
- all_boundaries (List[str]): List of all boundary names.
100
+ """
101
+ Class representing the boundaries with left and right values.
102
+
103
+ Parameters
104
+ ----------
105
+ left : Optional[str]
106
+ Value of the left boundary. Defaults to 'zero'. Must be either 'zero', 'symmetric', or 'anti-symmetric'.
107
+ right : Optional[str]
108
+ Value of the right boundary. Defaults to 'zero'. Must be either 'zero', 'symmetric', or 'anti-symmetric'.
109
+ acceptable_boundary : List[str]
110
+ List of acceptable boundary values.
111
+ all_boundaries : List[str]
112
+ List of all boundary names.
92
113
  """
93
114
  left: Optional[str] = 'zero'
94
115
  right: Optional[str] = 'zero'
@@ -97,31 +118,44 @@ class Boundaries:
97
118
  all_boundaries = ['left', 'right']
98
119
 
99
120
  def __post_init__(self) -> None:
100
- """Post-initialization method to assert acceptable boundary values."""
121
+ """
122
+ Post-initialization method to assert acceptable boundary values.
123
+ """
101
124
  for boundary in self.all_boundaries:
102
125
  self.assert_boundary_acceptable(boundary_string=boundary)
103
126
 
104
127
  def assert_both_boundaries_not_same(self, boundary_0: str, boundary_1: str) -> None:
105
- """Asserts that both boundaries are not the same axis symmetries if they are not 'zero'.
106
-
107
- Args:
108
- boundary_0 (str): The first boundary value.
109
- boundary_1 (str): The second boundary value.
110
-
111
- Raises:
112
- ValueError: If both boundaries are set to the same axis symmetries.
128
+ """
129
+ Assert that both boundaries are not the same axis symmetries if they are not 'zero'.
130
+
131
+ Parameters
132
+ ----------
133
+ boundary_0 : str
134
+ The first boundary value.
135
+ boundary_1 : str
136
+ The second boundary value.
137
+
138
+ Raises
139
+ ------
140
+ ValueError
141
+ If both boundaries are set to the same axis symmetries.
113
142
  """
114
143
  if boundary_0 != 'zero' and boundary_1 != 'zero':
115
144
  raise ValueError("Same-axis symmetries shouldn't be set on both ends")
116
145
 
117
146
  def assert_boundary_acceptable(self, boundary_string: str) -> None:
118
- """Asserts that a given boundary value is acceptable.
147
+ """
148
+ Assert that a given boundary value is acceptable.
119
149
 
120
- Args:
121
- boundary_string (str): The name of the boundary to check.
150
+ Parameters
151
+ ----------
152
+ boundary_string : str
153
+ The name of the boundary to check.
122
154
 
123
- Raises:
124
- AssertionError: If the boundary value is not acceptable.
155
+ Raises
156
+ ------
157
+ AssertionError
158
+ If the boundary value is not acceptable.
125
159
  """
126
160
  boundary_value = getattr(self, boundary_string)
127
161
  assert boundary_value in self.acceptable_boundary, (
@@ -130,24 +164,34 @@ class Boundaries:
130
164
  )
131
165
 
132
166
  def get_boundary_pairs(self) -> List[Tuple[str, str]]:
133
- """Gets the pairs of boundaries.
167
+ """
168
+ Get the pairs of boundaries.
134
169
 
135
- Returns:
136
- List[Tuple[str, str]]: A list of tuples containing boundary pairs.
170
+ Returns
171
+ -------
172
+ List[Tuple[str, str]]
173
+ A list of tuples containing boundary pairs.
137
174
  """
138
175
  return [(self.left, self.right)]
139
176
 
140
177
  def get_boundary(self, name: str) -> Boundary:
141
- """Returns a specific instance of the boundary.
142
-
143
- Args:
144
- name (str): The name of the boundary.
145
-
146
- Returns:
147
- Boundary: The boundary instance.
148
-
149
- Raises:
150
- AttributeError: If the boundary name is not an attribute of the instance.
178
+ """
179
+ Return a specific instance of the boundary.
180
+
181
+ Parameters
182
+ ----------
183
+ name : str
184
+ The name of the boundary.
185
+
186
+ Returns
187
+ -------
188
+ Boundary
189
+ The boundary instance.
190
+
191
+ Raises
192
+ ------
193
+ AttributeError
194
+ If the boundary name is not an attribute of the instance.
151
195
  """
152
196
  if not hasattr(self, name):
153
197
  value = None
@@ -163,16 +207,23 @@ class Boundaries:
163
207
  return boundary
164
208
 
165
209
  def offset_to_boundary(self, offset: int) -> str:
166
- """Determines the boundary based on the offset.
167
-
168
- Args:
169
- offset (int): The offset value.
170
-
171
- Returns:
172
- str: The name of the boundary corresponding to the offset.
173
-
174
- Raises:
175
- ValueError: If the offset does not correspond to a valid boundary.
210
+ """
211
+ Determine the boundary based on the offset.
212
+
213
+ Parameters
214
+ ----------
215
+ offset : int
216
+ The offset value.
217
+
218
+ Returns
219
+ -------
220
+ str
221
+ The name of the boundary corresponding to the offset.
222
+
223
+ Raises
224
+ ------
225
+ ValueError
226
+ If the offset does not correspond to a valid boundary.
176
227
  """
177
228
  if offset == 0:
178
229
  return self.get_boundary('center')
@@ -186,5 +237,3 @@ class Boundaries:
186
237
  return self.get_boundary('left')
187
238
 
188
239
  raise ValueError("Offset does not correspond to a valid boundary.")
189
-
190
- # -
@@ -3,7 +3,6 @@
3
3
 
4
4
  from PyFinitDiff.coefficients import FiniteCoefficients
5
5
 
6
-
7
6
  def get_function_derivative(
8
7
  function: callable,
9
8
  x_eval: float,
@@ -13,19 +12,36 @@ def get_function_derivative(
13
12
  accuracy: int = 4,
14
13
  coefficient_type: str = 'central') -> float:
15
14
  """
16
- Computes the derivative of a given function at a specified point using finite differences.
17
-
18
- Args:
19
- function (callable): The function to differentiate.
20
- x_eval (float): The point at which to evaluate the derivative.
21
- derivative (int): The order of the derivative.
22
- delta (float): The distance between points.
23
- function_kwargs (dict): Additional keyword arguments to pass to the function.
24
- accuracy (int, optional): The accuracy of the finite difference approximation. Defaults to 4.
25
- coefficient_type (str, optional): The type of finite difference coefficients ('central', 'forward', 'backward'). Defaults to 'central'.
26
-
27
- Returns:
28
- float: The value of the derivative at the specified point.
15
+ Compute the derivative of a given function at a specified point using finite differences.
16
+
17
+ Parameters
18
+ ----------
19
+ function : callable
20
+ The function to differentiate.
21
+ x_eval : float
22
+ The point at which to evaluate the derivative.
23
+ derivative : int
24
+ The order of the derivative.
25
+ delta : float
26
+ The distance between points used in the finite difference.
27
+ function_kwargs : dict
28
+ Additional keyword arguments to pass to the function.
29
+ accuracy : int, optional
30
+ The accuracy of the finite difference approximation (default is 4).
31
+ coefficient_type : str, optional
32
+ The type of finite difference coefficients to use ('central', 'forward', 'backward'). Defaults to 'central'.
33
+
34
+ Returns
35
+ -------
36
+ float
37
+ The value of the derivative at the specified point.
38
+
39
+ Examples
40
+ --------
41
+ >>> def func(x):
42
+ >>> return x**2
43
+ >>> get_function_derivative(func, 1.0, 1, 0.01, {})
44
+ 2.0
29
45
  """
30
46
  coefficients = FiniteCoefficients(
31
47
  derivative=derivative,
@@ -40,5 +56,3 @@ def get_function_derivative(
40
56
  summation += value * y
41
57
 
42
58
  return summation / delta ** derivative
43
-
44
- # -