diff --git a/scijo/differentiate/deriv.mojo b/scijo/differentiate/deriv.mojo index ac55a01..1002677 100644 --- a/scijo/differentiate/deriv.mojo +++ b/scijo/differentiate/deriv.mojo @@ -32,21 +32,18 @@ from .utility import ( fn derivative[ - dtype: DType, - func: fn[dtype: DType]( - x: Scalar[dtype], args: Optional[List[Scalar[dtype]]] - ) -> Scalar[dtype], + func: fn(x: Scalar[f64], args: Optional[List[Scalar[f64]]]) -> Scalar[f64], *, step_direction: Int = 0, ]( - x0: Scalar[dtype], - args: Optional[List[Scalar[dtype]]] = None, - tolerances: Dict[String, Scalar[dtype]] = {"atol": 1e-6, "rtol": 1e-6}, + x0: Scalar[f64], + args: Optional[List[Scalar[f64]]] = None, + tolerances: Dict[String, Scalar[f64]] = {"atol": 1e-6, "rtol": 1e-6}, max_iter: Int = 10, order: Int = 8, - initial_step: Scalar[dtype] = 0.5, - step_factor: Scalar[dtype] = 2.0, -) raises -> DiffResult[dtype] where dtype.is_floating_point(): + initial_step: Scalar[f64] = 0.5, + step_factor: Scalar[f64] = 2.0, +) raises -> DiffResult[f64]: """Computes the first derivative of a scalar function using finite differences. Provides a unified interface for computing first-order derivatives using @@ -54,8 +51,7 @@ fn derivative[ size reduction for improved accuracy. Parameters: - dtype: The floating-point data type. - func: Function to differentiate with signature fn(x, args) -> Scalar[dtype]. + func: Function to differentiate with signature fn(x, args) -> Scalar[f64]. step_direction: Direction of finite difference (central=0, forward=1, backward=-1). Keyword-only. @@ -70,7 +66,7 @@ fn derivative[ step_factor: Factor by which to reduce step size in each iteration (must be > 1). Returns: - DiffResult[dtype] containing the derivative, convergence status, + DiffResult[f64] containing the derivative, convergence status, estimated error, iteration count, and function evaluation count. Raises: @@ -82,19 +78,17 @@ fn derivative[ from scijo.differentiate import derivative from scijo.prelude import * - fn f[dtype: DType](x: Scalar[dtype], args: Optional[List[Scalar[dtype]]]) -> Scalar[dtype]: + fn f(x: Scalar[f64], args: Optional[List[Scalar[f64]]]) -> Scalar[f64]: return x * x - var res = derivative[f64, f](1.0) + var res = derivative[f](1.0) ``` """ @parameter if step_direction == 0: - comptime first_order_coefficients = generate_central_finite_difference_table[ - dtype - ]() - return _derivative_central_difference[dtype, func]( + comptime first_order_coefficients = generate_central_finite_difference_table() + return _derivative_central_difference[func]( x0, args, tolerances=tolerances, @@ -104,10 +98,8 @@ fn derivative[ max_iter=max_iter, ) elif step_direction == 1: - comptime first_order_coefficients = generate_forward_finite_difference_table[ - dtype - ]() - return _derivative_forward_difference[dtype, func]( + comptime first_order_coefficients = generate_forward_finite_difference_table() + return _derivative_forward_difference[func]( x0, args, tolerances, @@ -117,10 +109,8 @@ fn derivative[ max_iter, ) elif step_direction == -1: - comptime first_order_coefficients = generate_backward_finite_difference_table[ - dtype - ]() - return _derivative_backward_difference[dtype, func]( + comptime first_order_coefficients = generate_backward_finite_difference_table() + return _derivative_backward_difference[func]( x0, args, tolerances, @@ -149,27 +139,23 @@ fn derivative[ fn _derivative_central_difference[ - dtype: DType, - func: fn[dtype: DType]( - x: Scalar[dtype], args: Optional[List[Scalar[dtype]]] - ) -> Scalar[dtype], + func: fn(x: Scalar[f64], args: Optional[List[Scalar[f64]]]) -> Scalar[f64], ]( - x0: Scalar[dtype], - args: Optional[List[Scalar[dtype]]], - tolerances: Dict[String, Scalar[dtype]] = {"atol": 1e-6, "rtol": 1e-6}, + x0: Scalar[f64], + args: Optional[List[Scalar[f64]]], + tolerances: Dict[String, Scalar[f64]] = {"atol": 1e-6, "rtol": 1e-6}, order: Int = 8, - initial_step: Scalar[dtype] = 0.5, - step_factor: Scalar[dtype] = 2.0, + initial_step: Scalar[f64] = 0.5, + step_factor: Scalar[f64] = 2.0, max_iter: Int = 10, -) raises -> DiffResult[dtype]: +) raises -> DiffResult[f64]: """Computes first derivative using central finite difference method. Uses symmetric stencils around the evaluation point with adaptive step size reduction until convergence within specified tolerances. Parameters: - dtype: The floating-point data type. - func: Function to differentiate with signature fn(x, args) -> Scalar[dtype]. + func: Function to differentiate with signature fn(x, args) -> Scalar[f64]. Args: x0: Point at which to evaluate the derivative. @@ -180,24 +166,24 @@ fn _derivative_central_difference[ step_factor: Factor by which to reduce step size in each iteration. max_iter: Maximum number of iterations. - Returns: - DiffResult[dtype] containing the derivative and convergence information. - Raises: Error: If the specified order is not in {2, 4, 6, 8}. Error: If tolerances, step size, step factor, or max_iter are invalid. + + Returns: + DiffResult[f64] containing the derivative and convergence information. """ comptime first_order_coefficients_compiletime: Dict[ - Int, List[Scalar[dtype]] - ] = generate_central_finite_difference_table[dtype]() + Int, List[Scalar[f64]] + ] = generate_central_finite_difference_table() var first_order_coefficients = materialize[ first_order_coefficients_compiletime ]() - var diff_estimate: Scalar[dtype] = 0.0 - var prev_diff: Scalar[dtype] = 0.0 - var atol: Scalar[dtype] = tolerances["atol"] - var rtol: Scalar[dtype] = tolerances["rtol"] + var diff_estimate: Scalar[f64] = 0.0 + var prev_diff: Scalar[f64] = 0.0 + var atol: Scalar[f64] = tolerances["atol"] + var rtol: Scalar[f64] = tolerances["rtol"] if atol < 0: raise Error( @@ -247,7 +233,7 @@ fn _derivative_central_difference[ " computation." ) - var coefficients: List[Scalar[dtype]] + var coefficients: List[Scalar[f64]] if order in (2, 4, 6, 8): coefficients = first_order_coefficients[order].copy() else: @@ -260,14 +246,14 @@ fn _derivative_central_difference[ " function evaluations.\n Available orders map to truncation" " errors: 2→O(h²), 4→O(h⁴), 6→O(h⁶), 8→O(h⁸)" ) - var step: Scalar[dtype] = initial_step + var step: Scalar[f64] = initial_step for i in range(max_iter): diff_estimate = 0.0 var j: Int = 0 for ref coeff in coefficients: diff_estimate += coeff * func( - x0 + step * Scalar[dtype](j - len(coefficients) // 2), args + x0 + step * Scalar[f64](j - len(coefficients) // 2), args ) j += 1 diff_estimate /= step @@ -275,7 +261,7 @@ fn _derivative_central_difference[ var diff_change = abs(diff_estimate - prev_diff) var tolerance_threshold = atol + rtol * abs(diff_estimate) if diff_change < tolerance_threshold: - return DiffResult[dtype]( + return DiffResult[f64]( success=True, df=diff_estimate, error=diff_change, @@ -287,7 +273,7 @@ fn _derivative_central_difference[ prev_diff = diff_estimate step /= step_factor - return DiffResult[dtype]( + return DiffResult[f64]( success=False, df=diff_estimate, error=0.0, @@ -298,19 +284,16 @@ fn _derivative_central_difference[ fn _derivative_forward_difference[ - dtype: DType, - func: fn[dtype: DType]( - x: Scalar[dtype], args: Optional[List[Scalar[dtype]]] - ) -> Scalar[dtype], + func: fn(x: Scalar[f64], args: Optional[List[Scalar[f64]]]) -> Scalar[f64], ]( - x0: Scalar[dtype], - args: Optional[List[Scalar[dtype]]], - tolerances: Dict[String, Scalar[dtype]] = {"atol": 1e-6, "rtol": 1e-6}, + x0: Scalar[f64], + args: Optional[List[Scalar[f64]]], + tolerances: Dict[String, Scalar[f64]] = {"atol": 1e-6, "rtol": 1e-6}, order: Int = 8, - initial_step: Scalar[dtype] = 0.5, - step_factor: Scalar[dtype] = 2.0, + initial_step: Scalar[f64] = 0.5, + step_factor: Scalar[f64] = 2.0, max_iter: Int = 10, -) raises -> DiffResult[dtype]: +) raises -> DiffResult[f64]: """Computes first derivative using forward finite difference method. Uses one-sided stencils in the forward direction with adaptive step size @@ -318,8 +301,7 @@ fn _derivative_forward_difference[ are not available. Parameters: - dtype: The floating-point data type. - func: Function to differentiate with signature fn(x, args) -> Scalar[dtype]. + func: Function to differentiate with signature fn(x, args) -> Scalar[f64]. Args: x0: Point at which to evaluate the derivative. @@ -331,23 +313,23 @@ fn _derivative_forward_difference[ max_iter: Maximum number of iterations. Returns: - DiffResult[dtype] containing the derivative and convergence information. + DiffResult[f64] containing the derivative and convergence information. Raises: Error: If the specified order is not in {1, 2, 3, 4, 5, 6}. Error: If tolerances, step size, step factor, or max_iter are invalid. """ comptime first_order_coefficients_compiletime: Dict[ - Int, List[Scalar[dtype]] - ] = generate_forward_finite_difference_table[dtype]() + Int, List[Scalar[f64]] + ] = generate_forward_finite_difference_table() var first_order_coefficients = materialize[ first_order_coefficients_compiletime ]() - var diff_estimate: Scalar[dtype] = 0.0 - var prev_diff: Scalar[dtype] = 0.0 - var atol: Scalar[dtype] = tolerances["atol"] - var rtol: Scalar[dtype] = tolerances["rtol"] + var diff_estimate: Scalar[f64] = 0.0 + var prev_diff: Scalar[f64] = 0.0 + var atol: Scalar[f64] = tolerances["atol"] + var rtol: Scalar[f64] = tolerances["rtol"] if atol < 0: raise Error( @@ -409,20 +391,20 @@ fn _derivative_forward_difference[ " numerical stability.\n Available orders map to truncation" " errors: 1→O(h), 2→O(h²), ..., 6→O(h⁶)" ) - var step: Scalar[dtype] = initial_step + var step: Scalar[f64] = initial_step for i in range(max_iter): diff_estimate = 0.0 var j: Int = 0 for ref coeff in coefficients: - diff_estimate += coeff * func(x0 + step * Scalar[dtype](j), args) + diff_estimate += coeff * func(x0 + step * Scalar[f64](j), args) j += 1 diff_estimate /= step if i > 0: var diff_change = abs(diff_estimate - prev_diff) var tolerance_threshold = atol + rtol * abs(diff_estimate) if diff_change < tolerance_threshold: - return DiffResult[dtype]( + return DiffResult[f64]( success=True, df=diff_estimate, error=diff_change, @@ -434,7 +416,7 @@ fn _derivative_forward_difference[ prev_diff = diff_estimate step /= step_factor - return DiffResult[dtype]( + return DiffResult[f64]( success=False, df=diff_estimate, error=0.0, @@ -445,19 +427,16 @@ fn _derivative_forward_difference[ fn _derivative_backward_difference[ - dtype: DType, - func: fn[dtype: DType]( - x: Scalar[dtype], args: Optional[List[Scalar[dtype]]] - ) -> Scalar[dtype], + func: fn(x: Scalar[f64], args: Optional[List[Scalar[f64]]]) -> Scalar[f64], ]( - x0: Scalar[dtype], - args: Optional[List[Scalar[dtype]]], - tolerances: Dict[String, Scalar[dtype]] = {"atol": 1e-6, "rtol": 1e-6}, + x0: Scalar[f64], + args: Optional[List[Scalar[f64]]], + tolerances: Dict[String, Scalar[f64]] = {"atol": 1e-6, "rtol": 1e-6}, order: Int = 8, - initial_step: Scalar[dtype] = 0.5, - step_factor: Scalar[dtype] = 2.0, + initial_step: Scalar[f64] = 0.5, + step_factor: Scalar[f64] = 2.0, max_iter: Int = 10, -) raises -> DiffResult[dtype]: +) raises -> DiffResult[f64]: """Computes first derivative using backward finite difference method. Uses one-sided stencils in the backward direction with adaptive step size @@ -465,8 +444,7 @@ fn _derivative_backward_difference[ are not available. Parameters: - dtype: The floating-point data type. - func: Function to differentiate with signature fn(x, args) -> Scalar[dtype]. + func: Function to differentiate with signature fn(x, args) -> Scalar[f64]. Args: x0: Point at which to evaluate the derivative. @@ -478,23 +456,23 @@ fn _derivative_backward_difference[ max_iter: Maximum number of iterations. Returns: - DiffResult[dtype] containing the derivative and convergence information. + DiffResult[f64] containing the derivative and convergence information. Raises: Error: If the specified order is not in {1, 2, 3, 4, 5, 6}. Error: If tolerances, step size, step factor, or max_iter are invalid. """ comptime first_order_coefficients_compiletime: Dict[ - Int, List[Scalar[dtype]] - ] = generate_backward_finite_difference_table[dtype]() + Int, List[Scalar[f64]] + ] = generate_backward_finite_difference_table() var first_order_coefficients = materialize[ first_order_coefficients_compiletime ]() - var diff_estimate: Scalar[dtype] = 0.0 - var prev_diff: Scalar[dtype] = 0.0 - var atol: Scalar[dtype] = tolerances["atol"] - var rtol: Scalar[dtype] = tolerances["rtol"] + var diff_estimate: Scalar[f64] = 0.0 + var prev_diff: Scalar[f64] = 0.0 + var atol: Scalar[f64] = tolerances["atol"] + var rtol: Scalar[f64] = tolerances["rtol"] if atol < 0: raise Error( @@ -556,11 +534,11 @@ fn _derivative_backward_difference[ " numerical stability.\n Available orders map to truncation" " errors: 1→O(h), 2→O(h²), ..., 6→O(h⁶)" ) - var step: Scalar[dtype] = initial_step + var step: Scalar[f64] = initial_step for i in range(max_iter): diff_estimate = 0.0 - var j: Scalar[dtype] = 0 + var j: Scalar[f64] = 0 for ref coeff in coefficients: diff_estimate += coeff * func(x0 + step * j, args) j += 1 @@ -569,7 +547,7 @@ fn _derivative_backward_difference[ var diff_change = abs(diff_estimate - prev_diff) var tolerance_threshold = atol + rtol * abs(diff_estimate) if diff_change < tolerance_threshold: - return DiffResult[dtype]( + return DiffResult[f64]( success=True, df=diff_estimate, error=diff_change, @@ -581,7 +559,7 @@ fn _derivative_backward_difference[ prev_diff = diff_estimate step /= step_factor - return DiffResult[dtype]( + return DiffResult[f64]( success=False, df=diff_estimate, error=0.0, diff --git a/scijo/differentiate/jacob.mojo b/scijo/differentiate/jacob.mojo index c080e99..7cdb81a 100644 --- a/scijo/differentiate/jacob.mojo +++ b/scijo/differentiate/jacob.mojo @@ -18,16 +18,15 @@ from algorithm.functional import parallelize fn jacobian[ - dtype: DType, - f: fn[dtype: DType]( - x: NDArray[dtype], args: Optional[List[Scalar[dtype]]] - ) raises -> NDArray[dtype], + f: fn(x: NDArray[f64], args: Optional[List[Scalar[f64]]]) raises -> NDArray[ + f64 + ], ]( - x: NDArray[dtype], - args: Optional[List[Scalar[dtype]]] = None, - tolerances: Dict[String, Scalar[dtype]] = {"abs": 1e-5, "rel": 1e-3}, + x: NDArray[f64], + args: Optional[List[Scalar[f64]]] = None, + tolerances: Dict[String, Scalar[f64]] = {"abs": 1e-5, "rel": 1e-3}, maxiter: Int = 10, -) raises -> NDArray[dtype]: +) raises -> NDArray[f64]: """Computes the Jacobian matrix of a vector-valued function using central finite differences. Evaluates J[i, j] = ∂f_i/∂x_j using the central difference formula @@ -35,8 +34,7 @@ fn jacobian[ Each column of the Jacobian is computed in parallel. Parameters: - dtype: The floating-point data type. - f: Vector-valued function with signature fn(x, args) -> NDArray[dtype]. + f: Vector-valued function with signature fn(x, args) -> NDArray[f64]. Args: x: Input vector of shape (n,) at which to evaluate the Jacobian. @@ -48,7 +46,7 @@ fn jacobian[ Error: If function evaluation fails for any perturbation. Returns: - NDArray[dtype] of shape (m, n) representing the Jacobian matrix, + NDArray[f64] of shape (m, n) representing the Jacobian matrix, where m is the output dimension and n is the input dimension. Examples: @@ -57,19 +55,19 @@ fn jacobian[ from scijo.differentiate import jacobian from scijo.prelude import * - fn f[dtype: DType](x: NDArray[dtype], args: Optional[List[Scalar[dtype]]]) raises -> NDArray[dtype]: + fn f(x: NDArray[f64], args: Optional[List[Scalar[f64]]]) raises -> NDArray[f64]: return x * x var x = nm.array[f64]([1.0, 2.0]) - var J = jacobian[f64, f](x) + var J = jacobian[f](x) ``` """ var n: Int = len(x) - var f0: NDArray[dtype] = f(x, args) + var f0: NDArray[f64] = f(x, args) var m: Int = len(f0) - var jacob: NDArray[dtype] = zeros[dtype](Shape(m, n)) - var step: NDArray[dtype] = full[dtype](Shape(n), fill_value=0.5) + var jacob: NDArray[f64] = zeros[f64](Shape(m, n)) + var step: NDArray[f64] = full[f64](Shape(n), fill_value=0.5) @parameter fn closure(j: Int): @@ -82,10 +80,10 @@ fn jacobian[ var f_plus = f(x_plus, args) var f_minus = f(x_minus, args) - var col: NDArray[dtype] = (f_plus - f_minus) / (2.0 * hj) + var col: NDArray[f64] = (f_plus - f_minus) / (2.0 * hj) for i in range(m): - var val: Scalar[dtype] = col.load(i) + var val: Scalar[f64] = col.load(i) var flat_idx: Int = i * n + j jacob.store(flat_idx, val=val) except: diff --git a/scijo/differentiate/utility.mojo b/scijo/differentiate/utility.mojo index 9c2d362..dc48956 100644 --- a/scijo/differentiate/utility.mojo +++ b/scijo/differentiate/utility.mojo @@ -23,7 +23,7 @@ References: # ===----------------------------------------------------------------------=== # -struct DiffResult[dtype: DType](ImplicitlyCopyable, Writable): +struct DiffResult[dtype: DType = DType.float64](ImplicitlyCopyable, Writable): """Result structure for numerical differentiation operations. Encapsulates the results of derivative computations, including the computed @@ -98,28 +98,23 @@ struct DiffResult[dtype: DType](ImplicitlyCopyable, Writable): @parameter -fn generate_central_finite_difference_table[ - dtype: DType -]() -> Dict[Int, List[Scalar[dtype]]]: +fn generate_central_finite_difference_table() -> Dict[Int, List[Scalar[f64]]]: """Generates central finite difference coefficients for first-order derivatives. Creates a lookup table of coefficients for central difference approximations using symmetric stencils: f'(x) ≈ Σ(c_i * f(x + i*h)) / h. - Parameters: - dtype: The floating-point data type for the coefficients. - Returns: Coefficient arrays indexed by accuracy order. Available orders: 2, 4, 6, 8 with truncation errors O(h²), O(h⁴), O(h⁶), O(h⁸). """ - var coefficients = Dict[Int, List[Scalar[dtype]]]() + var coefficients = Dict[Int, List[Scalar[f64]]]() # Order 2: points [-1, 0, 1] - coefficients[2]: List[Scalar[dtype]] = [-0.5, 0.0, 0.5] + coefficients[2]: List[Scalar[f64]] = [-0.5, 0.0, 0.5] # Order 4: points [-2, -1, 0, 1, 2] - coefficients[4]: List[Scalar[dtype]] = [ + coefficients[4]: List[Scalar[f64]] = [ 1.0 / 12.0, -2.0 / 3.0, 0.0, @@ -128,7 +123,7 @@ fn generate_central_finite_difference_table[ ] # Order 6: points [-3, -2, -1, 0, 1, 2, 3] - coefficients[6]: List[Scalar[dtype]] = [ + coefficients[6]: List[Scalar[f64]] = [ -1.0 / 60.0, 3.0 / 20.0, -3.0 / 4.0, @@ -139,7 +134,7 @@ fn generate_central_finite_difference_table[ ] # Order 8: points [-4, -3, -2, -1, 0, 1, 2, 3, 4] - coefficients[8]: List[Scalar[dtype]] = [ + coefficients[8]: List[Scalar[f64]] = [ 1.0 / 280.0, -4.0 / 105.0, 1.0 / 5.0, @@ -155,9 +150,7 @@ fn generate_central_finite_difference_table[ @parameter -fn generate_forward_finite_difference_table[ - dtype: DType -]() -> Dict[Int, List[Scalar[dtype]]]: +fn generate_forward_finite_difference_table() -> Dict[Int, List[Scalar[f64]]]: """Generates forward finite difference coefficients for first-order derivatives. Creates a lookup table of coefficients for forward difference approximations @@ -166,23 +159,20 @@ fn generate_forward_finite_difference_table[ Forward differences are necessary at left domain boundaries or when backward evaluations are not feasible. - Parameters: - dtype: The floating-point data type for the coefficients. - Returns: Coefficient arrays indexed by accuracy order. Available orders: 1, 2, 3, 4, 5, 6 with truncation errors O(h) through O(h⁶). """ - var coefficients = Dict[Int, List[Scalar[dtype]]]() + var coefficients = Dict[Int, List[Scalar[f64]]]() # Order 1: points [0, 1] - coefficients[1]: List[Scalar[dtype]] = [-1.0, 1.0] + coefficients[1]: List[Scalar[f64]] = [-1.0, 1.0] # Order 2: points [0, 1, 2] - coefficients[2]: List[Scalar[dtype]] = [-3.0 / 2.0, 2.0, -1.0 / 2.0] + coefficients[2]: List[Scalar[f64]] = [-3.0 / 2.0, 2.0, -1.0 / 2.0] # Order 3: points [0, 1, 2, 3] - coefficients[3]: List[Scalar[dtype]] = [ + coefficients[3]: List[Scalar[f64]] = [ -11.0 / 6.0, 3.0, -3.0 / 2.0, @@ -190,7 +180,7 @@ fn generate_forward_finite_difference_table[ ] # Order 4: points [0, 1, 2, 3, 4] - coefficients[4]: List[Scalar[dtype]] = [ + coefficients[4]: List[Scalar[f64]] = [ -25.0 / 12.0, 4.0, -3.0, @@ -199,7 +189,7 @@ fn generate_forward_finite_difference_table[ ] # Order 5: points [0, 1, 2, 3, 4, 5] - coefficients[5]: List[Scalar[dtype]] = [ + coefficients[5]: List[Scalar[f64]] = [ -137.0 / 60.0, 5.0, -5.0, @@ -209,7 +199,7 @@ fn generate_forward_finite_difference_table[ ] # Order 6: points [0, 1, 2, 3, 4, 5, 6] - coefficients[6]: List[Scalar[dtype]] = [ + coefficients[6]: List[Scalar[f64]] = [ -49.0 / 20.0, 6.0, -15.0 / 2.0, @@ -223,9 +213,7 @@ fn generate_forward_finite_difference_table[ @parameter -fn generate_backward_finite_difference_table[ - dtype: DType -]() -> Dict[Int, List[Scalar[dtype]]]: +fn generate_backward_finite_difference_table() -> Dict[Int, List[Scalar[f64]]]: """Generates backward finite difference coefficients for first-order derivatives. Creates a lookup table of coefficients for backward difference approximations @@ -235,23 +223,20 @@ fn generate_backward_finite_difference_table[ stencil and adjusting signs. They are necessary at right domain boundaries or when forward evaluations are not feasible. - Parameters: - dtype: The floating-point data type for the coefficients. - Returns: Coefficient arrays indexed by accuracy order. Available orders: 1, 2, 3, 4, 5, 6 with truncation errors O(h) through O(h⁶). """ - var coefficients = Dict[Int, List[Scalar[dtype]]]() + var coefficients = Dict[Int, List[Scalar[f64]]]() # Order 1: points [-1, 0] - coefficients[1]: List[Scalar[dtype]] = [-1.0, 1.0] + coefficients[1]: List[Scalar[f64]] = [-1.0, 1.0] # Order 2: points [-2, -1, 0] - coefficients[2]: List[Scalar[dtype]] = [1.0 / 2.0, -2.0, 3.0 / 2.0] + coefficients[2]: List[Scalar[f64]] = [1.0 / 2.0, -2.0, 3.0 / 2.0] # Order 3: points [-3, -2, -1, 0] - coefficients[3]: List[Scalar[dtype]] = [ + coefficients[3]: List[Scalar[f64]] = [ -1.0 / 3.0, 3.0 / 2.0, -3.0, @@ -259,7 +244,7 @@ fn generate_backward_finite_difference_table[ ] # Order 4: points [-4, -3, -2, -1, 0] - coefficients[4]: List[Scalar[dtype]] = [ + coefficients[4]: List[Scalar[f64]] = [ 1.0 / 4.0, -4.0 / 3.0, 3.0, @@ -268,7 +253,7 @@ fn generate_backward_finite_difference_table[ ] # Order 5: points [-5, -4, -3, -2, -1, 0] - coefficients[5]: List[Scalar[dtype]] = [ + coefficients[5]: List[Scalar[f64]] = [ -1.0 / 5.0, 5.0 / 4.0, -10.0 / 3.0, @@ -278,7 +263,7 @@ fn generate_backward_finite_difference_table[ ] # Order 6: points [-6, -5, -4, -3, -2, -1, 0] - coefficients[6]: List[Scalar[dtype]] = [ + coefficients[6]: List[Scalar[f64]] = [ 1.0 / 6.0, -6.0 / 5.0, 15.0 / 4.0,