Skip to content

Commit a3e8cf0

Browse files
Merge pull request #31 from ringabout/master
add patches for stricteffects
2 parents 278353f + 8076350 commit a3e8cf0

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/numericalnim/optimize.nim

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ import std/[strformat, sequtils, math, deques]
22
import arraymancer
33
import ./differentiate
44

5+
when not defined(nimHasEffectsOf):
6+
{.pragma: effectsOf.}
7+
58
proc steepest_descent*(deriv: proc(x: float64): float64, start: float64, gamma: float64 = 0.01, precision: float64 = 1e-5, max_iters: Natural = 1000):float64 {.inline.} =
69
## Gradient descent optimization algorithm for finding local minimums of a function with derivative 'deriv'
710
##
@@ -75,7 +78,11 @@ proc conjugate_gradient*[T](A, b, x_0: Tensor[T], tolerance: float64): Tensor[T]
7578
rsold = rsnew
7679

7780

78-
proc newtons*(f: proc(x: float64): float64, deriv: proc(x: float64): float64, start: float64, precision: float64 = 1e-5, max_iters: Natural = 1000): float64 {.raises: [ArithmeticError].} =
81+
proc newtons*(f: proc(x: float64): float64,
82+
deriv: proc(x: float64): float64,
83+
start: float64, precision: float64 = 1e-5,
84+
max_iters: Natural = 1000
85+
): float64{.raises: [ArithmeticError], effectsOf: [f, deriv].} =
7986
## Newton-Raphson implementation for 1-dimensional functions
8087

8188
## Given a single variable function f and it's derivative, calcuate an approximation to f(x) = 0

0 commit comments

Comments
 (0)