Beginner here at Python, using it for Economic Research. I'm currently having a problem relating to finding the roots of a function using a python function from this package (https://quanteconpy.readthedocs.io/en/latest/optimize/root_finding.html). I've posted an earlier query about it (Python TypeError for Root-Finding Code(QuantEcon Package)), but I still can't seem to resolve this issue.
My code is attached below:
from numba import jit
import timeit
####################QuantEcon Methods#######################
from quantecon.optimize.root_finding import newton, newton_halley, newton_secant
, bisect, brentq
##Coded Up Functions (Jitted)##
@jit
def ces(x,y,rho):
U = (x**rho + y**rho)**(1/rho)
return U # original CES Function
@jit
def ces_d(x,y,rho):
U_x = (x**(rho-1))* ((x**rho + y**rho)**((1-rho)/rho))
return U_x # CES Derivative
@jit
def ces_dd(x,y,rho,ud):
U_obj = ces_d(x,y,rho) - ud
return U_obj # New Objective Function = CES Derivative - ud
@jit
def ces_d2(x,y,rho):
U_xx = (rho-1) * (x**(rho-2)) *(y**rho) * ((x**rho + y**rho)**(1/rho-2))
return U_xx #The derivative of the new objective function (ud drops out)
##Default Newton-Raphson##
@jit
def ces_inv(y,rho,ud):
args = (y,rho,ud) #order must be preserved
x_bar = newton(ces_dd, 0 ,ces_d2, args)
return x_bar
print(ces_inv(2,0.5,1)) #TypingError Occurs Here
And the relevant stacktrace is here:
TypingError: Internal error at <numba.core.typeinfer.CallConstraint object at 0x000002619E33BB20>.
too many positional arguments
During: resolving callee type: type(CPUDispatcher(<function ces_d2 at 0x000002619E1B15E0>))
During: typing of call at C:UsersOrphanidesanaconda3libsite-packagesquanteconoptimize
oot_finding.py (89)
Enable logging at debug level for details.
Entire StackTrace History:
<ipython-input-1-1251fd61b2b2>:32: NumbaWarning:
Compilation is falling back to object mode WITH looplifting enabled because Function "ces_inv" failed type inference due to: Failed in nopython mode pipeline (step: nopython frontend)
Internal error at <numba.core.typeinfer.CallConstraint object at 0x000002619E2727F0>.
too many positional arguments
During: resolving callee type: type(CPUDispatcher(<function ces_d2 at 0x000002619E1B15E0>))
During: typing of call at C:UsersOrphanidesanaconda3libsite-packagesquanteconoptimize
oot_finding.py (89)
Enable logging at debug level for details.
File "............anaconda3libsite-packagesquanteconoptimize
oot_finding.py", line 89:
def newton(func, x0, fprime, args=(), tol=1.48e-8, maxiter=50,
<source elided>
break
fder = fprime(p0, *args)
^
During: resolving callee type: type(CPUDispatcher(<function newton at 0x000002619E15C5E0>))
During: typing of call at <ipython-input-1-1251fd61b2b2> (35)
During: resolving callee type: type(CPUDispatcher(<function newton at 0x000002619E15C5E0>))
During: typing of call at <ipython-input-1-1251fd61b2b2> (35)
File "<ipython-input-1-1251fd61b2b2>", line 35:
def ces_inv(y,rho,ud):
<source elided>
args = (y,rho,ud) #order must be preserved
x_bar = newton(ces_dd, 0 ,ces_d2, args)
^
@jit
C:UsersOrphanidesanaconda3libsite-packages
umbacoreobject_mode_passes.py:177: NumbaWarning: Function "ces_inv" was compiled in object mode without forceobj=True.
File "<ipython-input-1-1251fd61b2b2>", line 33:
@jit
def ces_inv(y,rho,ud):
^
warnings.warn(errors.NumbaWarning(warn_msg,
C:UsersOrphanidesanaconda3libsite-packages
umbacoreobject_mode_passes.py:187: NumbaDeprecationWarning:
Fall-back from the nopython compilation path to the object mode compilation path has been detected, this is deprecated behaviour.
For more information visit https://numba.pydata.org/numba-doc/latest/reference/deprecation.html#deprecation-of-object-mode-fall-back-behaviour-when-using-jit
File "<ipython-input-1-1251fd61b2b2>", line 33:
@jit
def ces_inv(y,rho,ud):
^
warnings.warn(errors.NumbaDeprecationWarning(msg,
Traceback (most recent call last):
File "<ipython-input-1-1251fd61b2b2>", line 38, in <module>
print(ces_inv(2,0.5,1)) #TypingError Occurs Here
File "C:UsersOrphanidesanaconda3libsite-packages
umbacoredispatcher.py", line 415, in _compile_for_args
error_rewrite(e, 'typing')
File "C:UsersOrphanidesanaconda3libsite-packages
umbacoredispatcher.py", line 358, in error_rewrite
reraise(type(e), e, None)
File "C:UsersOrphanidesanaconda3libsite-packages
umbacoreutils.py", line 80, in reraise
raise value.with_traceback(tb)
TypingError: Internal error at <numba.core.typeinfer.CallConstraint object at 0x000002619E33BB20>.
too many positional arguments
During: resolving callee type: type(CPUDispatcher(<function ces_d2 at 0x000002619E1B15E0>))
During: typing of call at C:UsersOrphanidesanaconda3libsite-packagesquanteconoptimize
oot_finding.py (89)
Enable logging at debug level for details.
Any help would be much appreciated, thank you!