@@ -28,9 +28,10 @@ class UserData:
28
28
disturbing foreign runtime.
29
29
"""
30
30
31
- def __init__ (self , fcn ):
31
+ def __init__ (self , fcn , ** kwargs ):
32
32
self .fcn = fcn
33
33
self .exception = None
34
+ self .kwargs = kwargs
34
35
35
36
36
37
@ffi .def_extern ()
@@ -46,6 +47,7 @@ def func(n, x, fvec, iflag, data) -> None:
46
47
handle .fcn (
47
48
np .frombuffer (ffi .buffer (x , n * real .itemsize ), dtype = real ),
48
49
np .frombuffer (ffi .buffer (fvec , n * real .itemsize ), dtype = real ),
50
+ ** handle .kwargs ,
49
51
)
50
52
except BaseException as e :
51
53
iflag [0 ] = - 1
@@ -68,6 +70,7 @@ def fcn_hybrj(n, x, fvec, fjac, ldfjac, iflag, data) -> None:
68
70
np .frombuffer (ffi .buffer (fvec , n * real .itemsize ), dtype = real ),
69
71
np .reshape (fjac , (n , ldfjac )),
70
72
iflag [0 ] == 2 ,
73
+ ** handle .kwargs ,
71
74
)
72
75
except BaseException as e :
73
76
iflag [0 ] = - 1
@@ -90,6 +93,7 @@ def fcn_lmder(m, n, x, fvec, fjac, ldfjac, iflag, data) -> None:
90
93
np .frombuffer (ffi .buffer (fvec , m * real .itemsize ), dtype = real ),
91
94
np .reshape (fjac , (n , ldfjac )),
92
95
iflag [0 ] == 2 ,
96
+ ** handle .kwargs ,
93
97
)
94
98
except BaseException as e :
95
99
iflag [0 ] = - 1
@@ -109,6 +113,7 @@ def func2(m, n, x, fvec, iflag, data) -> None:
109
113
handle .fcn (
110
114
np .frombuffer (ffi .buffer (x , n * real .itemsize ), dtype = real ),
111
115
np .frombuffer (ffi .buffer (fvec , m * real .itemsize ), dtype = real ),
116
+ ** handle .kwargs ,
112
117
)
113
118
except BaseException as e :
114
119
iflag [0 ] = - 1
@@ -130,6 +135,7 @@ def fcn_lmstr(m, n, x, fvec, fjrow, iflag, data) -> None:
130
135
np .frombuffer (ffi .buffer (fvec , m * real .itemsize ), dtype = real ),
131
136
np .frombuffer (ffi .buffer (fjrow , n * real .itemsize ), dtype = real ),
132
137
iflag [0 ] - 2 if iflag [0 ] > 1 else None ,
138
+ ** handle .kwargs ,
133
139
)
134
140
except BaseException as e :
135
141
iflag [0 ] = - 1
@@ -162,8 +168,8 @@ def cffi_callback(func, callback):
162
168
"""
163
169
164
170
@functools .wraps (func )
165
- def entry_point (fcn , * args ):
166
- data = UserData (fcn )
171
+ def entry_point (fcn , * args , ** kwargs ):
172
+ data = UserData (fcn , ** kwargs )
167
173
handle = ffi .new_handle (data )
168
174
func (callback , * args , handle )
169
175
if data .exception is not None :
@@ -191,6 +197,7 @@ def hybrd1(
191
197
x : np .ndarray ,
192
198
fvec : np .ndarray ,
193
199
tol : float = math .sqrt (np .finfo (real ).eps ),
200
+ ** kwargs ,
194
201
) -> int :
195
202
"""
196
203
Find a zero of a system of n nonlinear functions in n variables
@@ -262,6 +269,7 @@ def hybrd1(
262
269
info ,
263
270
ffi .cast ("double*" , wa .ctypes .data ),
264
271
lwa ,
272
+ ** kwargs ,
265
273
)
266
274
ex = info_hy (info [0 ])
267
275
if ex is not None :
@@ -286,6 +294,7 @@ def hybrd(
286
294
fjac : Optional [np .ndarray ] = None ,
287
295
r : Optional [np .ndarray ] = None ,
288
296
qtf : Optional [np .ndarray ] = None ,
297
+ ** kwargs ,
289
298
) -> int :
290
299
"""
291
300
Find a zero of a system of n nonlinear functions in n variables
@@ -353,6 +362,7 @@ def hybrd(
353
362
ffi .cast ("double*" , wa2 .ctypes .data ),
354
363
ffi .cast ("double*" , wa3 .ctypes .data ),
355
364
ffi .cast ("double*" , wa4 .ctypes .data ),
365
+ ** kwargs ,
356
366
)
357
367
ex = info_hy (info [0 ])
358
368
if ex is not None :
@@ -366,6 +376,7 @@ def hybrj1(
366
376
fvec : np .ndarray ,
367
377
fjac : np .ndarray ,
368
378
tol : float = math .sqrt (np .finfo (real ).eps ),
379
+ ** kwargs ,
369
380
) -> int :
370
381
"""
371
382
Find a zero of a system of n nonlinear functions in n variables
@@ -403,6 +414,7 @@ def hybrj1(
403
414
info ,
404
415
ffi .cast ("double*" , wa .ctypes .data ),
405
416
lwa ,
417
+ ** kwargs ,
406
418
)
407
419
ex = info_hy (info [0 ])
408
420
if ex is not None :
@@ -424,6 +436,7 @@ def hybrj(
424
436
nprint : int = 0 ,
425
437
r : Optional [np .ndarray ] = None ,
426
438
qtf : Optional [np .ndarray ] = None ,
439
+ ** kwargs ,
427
440
) -> int :
428
441
"""
429
442
Find a zero of a system of n nonlinear functions in n variables
@@ -486,6 +499,7 @@ def hybrj(
486
499
ffi .cast ("double*" , wa2 .ctypes .data ),
487
500
ffi .cast ("double*" , wa3 .ctypes .data ),
488
501
ffi .cast ("double*" , wa4 .ctypes .data ),
502
+ ** kwargs ,
489
503
)
490
504
ex = info_hy (info [0 ])
491
505
if ex is not None :
@@ -499,6 +513,7 @@ def lmder1(
499
513
fvec : np .ndarray ,
500
514
fjac : np .ndarray ,
501
515
tol : float = math .sqrt (np .finfo (real ).eps ),
516
+ ** kwargs ,
502
517
) -> int :
503
518
"""
504
519
Minimize the sum of the squares of m nonlinear functions in n variables
@@ -539,6 +554,7 @@ def lmder1(
539
554
ffi .cast ("int*" , ipvt .ctypes .data ),
540
555
ffi .cast ("double*" , wa .ctypes .data ),
541
556
lwa ,
557
+ ** kwargs ,
542
558
)
543
559
ex = info_lm (info [0 ])
544
560
if ex is not None :
@@ -562,6 +578,7 @@ def lmder(
562
578
nprint = 0 ,
563
579
ipvt : Optional [np .ndarray ] = None ,
564
580
qtf : Optional [np .ndarray ] = None ,
581
+ ** kwargs ,
565
582
) -> int :
566
583
"""
567
584
Minimize the sum of the squares of m nonlinear functions in n variables
@@ -624,6 +641,7 @@ def lmder(
624
641
ffi .cast ("double*" , wa2 .ctypes .data ),
625
642
ffi .cast ("double*" , wa3 .ctypes .data ),
626
643
ffi .cast ("double*" , wa4 .ctypes .data ),
644
+ ** kwargs ,
627
645
)
628
646
ex = info_lm (info [0 ])
629
647
if ex is not None :
@@ -636,6 +654,7 @@ def lmdif1(
636
654
x : np .ndarray ,
637
655
fvec : np .ndarray ,
638
656
tol : float = math .sqrt (np .finfo (real ).eps ),
657
+ ** kwargs ,
639
658
) -> int :
640
659
"""
641
660
Minimize the sum of the squares of m nonlinear functions in n variables
@@ -709,6 +728,7 @@ def lmdif1(
709
728
ffi .cast ("int*" , ipvt .ctypes .data ),
710
729
ffi .cast ("double*" , wa .ctypes .data ),
711
730
lwa ,
731
+ ** kwargs ,
712
732
)
713
733
ex = info_lm (info [0 ])
714
734
if ex is not None :
@@ -733,6 +753,7 @@ def lmdif(
733
753
fjac : Optional [np .ndarray ] = None ,
734
754
ipvt : Optional [np .ndarray ] = None ,
735
755
qtf : Optional [np .ndarray ] = None ,
756
+ ** kwargs ,
736
757
) -> int :
737
758
"""
738
759
Minimize the sum of the squares of m nonlinear functions in n variables
@@ -797,6 +818,7 @@ def lmdif(
797
818
ffi .cast ("double*" , wa2 .ctypes .data ),
798
819
ffi .cast ("double*" , wa3 .ctypes .data ),
799
820
ffi .cast ("double*" , wa4 .ctypes .data ),
821
+ ** kwargs ,
800
822
)
801
823
ex = info_lm (info [0 ])
802
824
if ex is not None :
@@ -810,6 +832,7 @@ def lmstr1(
810
832
fvec : np .ndarray ,
811
833
fjac : np .ndarray ,
812
834
tol : float = math .sqrt (np .finfo (real ).eps ),
835
+ ** kwargs ,
813
836
) -> int :
814
837
"""
815
838
Minimize the sum of the squares of m nonlinear functions in n variables by
@@ -851,6 +874,7 @@ def lmstr1(
851
874
ffi .cast ("int*" , ipvt .ctypes .data ),
852
875
ffi .cast ("double*" , wa .ctypes .data ),
853
876
lwa ,
877
+ ** kwargs ,
854
878
)
855
879
ex = info_lm (info [0 ])
856
880
if ex is not None :
@@ -874,6 +898,7 @@ def lmstr(
874
898
nprint = 0 ,
875
899
ipvt : Optional [np .ndarray ] = None ,
876
900
qtf : Optional [np .ndarray ] = None ,
901
+ ** kwargs ,
877
902
) -> int :
878
903
"""
879
904
Minimize the sum of the squares of m nonlinear functions in n variables by
@@ -937,6 +962,7 @@ def lmstr(
937
962
ffi .cast ("double*" , wa2 .ctypes .data ),
938
963
ffi .cast ("double*" , wa3 .ctypes .data ),
939
964
ffi .cast ("double*" , wa4 .ctypes .data ),
965
+ ** kwargs ,
940
966
)
941
967
ex = info_lm (info [0 ])
942
968
if ex is not None :
0 commit comments