jaxdf.conv
The conv module contains some functions behind the numerical implementation of Finite Differences operators and related functionality.
bubble_sort_abs_value(points_list)
Sorts a sequence of grid points by their absolute value.
Sorting is done in place. This function is written with numpy, so it can't be transformed by JAX.
Example
lst = [-3, -2, -1, 0, 1, 2, 3]
sorted_lst = bubble_sort_abs_value(lst)
print(sorted_lst)
# [0, 1, -1, 2, -2, 3, -3]
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
points_list
|
List[Union[float, int]]
|
The grid points to sort. |
required |
Returns:
| Type | Description |
|---|---|
List[Union[float, int]]
|
The sorted grid points. |
fd_coefficients_fornberg(order, grid_points, x0)
Generate finite difference stencils for a given order and grid points, using the Fornberg algorithm described in [Fornberg, 2018].
The grid points can be placed in any order, can be at arbitrary locations (for example, to implemente staggered
stencils) and don't need to be equidistant.
The stencil is evaluated for a point in x0. Note that setting order=0 will generate interpolation coefficients
for the point x0.
Example
grid_points = [0, 1, 2, -1, -2]
x0 = 0.0
order = 2
stencil, nodes = fd_coefficients_fornberg(order, grid_points, x0)
print(f"Stencil: {stencil}, Nodes: {nodes}")
# Stencil: [-0.08333333 1.33333333 -2.5 1.33333333 -0.08333333], Nodes: [-2 -1 0 1 2]
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
order
|
int
|
The order of the stencil. |
required |
grid_points
|
List[Union[float, int]]
|
The grid points to use. |
required |
x0
|
Union[float, int]
|
The point at which to evaluate the stencil. |
required |
Returns:
| Type | Description |
|---|---|
Tuple[List[None], List[Union[float, int]]]
|
The stencil and the grid points where the stencil is evaluated. |
reflection_conv(kernel, array, reverse=True)
Convolves an array with a kernel, using reflection padding. The kernel is supposed to have the same number of dimensions as the array.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
kernel
|
ndarray
|
The kernel to convolve with. |
required |
array
|
ndarray
|
The array to convolve. |
required |
reverse
|
bool
|
Whether to reverse the kernel before convolving. Defaults to True. |
True
|
Returns:
| Type | Description |
|---|---|
ndarray
|
The convolved array. |