Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if count_ops(graph) > BACKEND_OPS_THRESHOLD:
backend = 'lambda'
else:
backend = 'llvm'
# TODO: did not replace zoo with oo
if include_obj:
func = lambdify(inp, [graph], backend=backend, cse=cse)
if include_grad or include_hess:
grad_graphs = list(graph.diff(w) for w in wrt)
grad_ops = sum(count_ops(x) for x in grad_graphs)
if grad_ops > BACKEND_OPS_THRESHOLD:
grad_backend = 'lambda'
else:
grad_backend = 'llvm'
if include_grad:
grad = lambdify(inp, grad_graphs, backend=grad_backend, cse=cse)
if include_hess:
hess_graphs = list(list(g.diff(w) for w in wrt) for g in grad_graphs)
# Hessians are hard-coded to always use the lambda backend, for performance
hess = lambdify(inp, hess_graphs, backend='lambda', cse=cse)
return BuildFunctionsResult(func=func, grad=grad, hess=hess)
if parameters is None:
parameters = []
else:
parameters = [wrap_symbol_symengine(p) for p in parameters]
variables = tuple(variables)
parameters = tuple(parameters)
func, grad, hess = None, None, None
inp = sympify(variables + parameters)
graph = sympify(sympy_graph)
if count_ops(graph) > BACKEND_OPS_THRESHOLD:
backend = 'lambda'
else:
backend = 'llvm'
# TODO: did not replace zoo with oo
if include_obj:
func = lambdify(inp, [graph], backend=backend, cse=cse)
if include_grad or include_hess:
grad_graphs = list(graph.diff(w) for w in wrt)
grad_ops = sum(count_ops(x) for x in grad_graphs)
if grad_ops > BACKEND_OPS_THRESHOLD:
grad_backend = 'lambda'
else:
grad_backend = 'llvm'
if include_grad:
grad = lambdify(inp, grad_graphs, backend=grad_backend, cse=cse)
if include_hess:
hess_graphs = list(list(g.diff(w) for w in wrt) for g in grad_graphs)
# Hessians are hard-coded to always use the lambda backend, for performance
hess = lambdify(inp, hess_graphs, backend='lambda', cse=cse)
return BuildFunctionsResult(func=func, grad=grad, hess=hess)
# TODO: did not replace zoo with oo
if include_obj:
func = lambdify(inp, [graph], backend=backend, cse=cse)
if include_grad or include_hess:
grad_graphs = list(graph.diff(w) for w in wrt)
grad_ops = sum(count_ops(x) for x in grad_graphs)
if grad_ops > BACKEND_OPS_THRESHOLD:
grad_backend = 'lambda'
else:
grad_backend = 'llvm'
if include_grad:
grad = lambdify(inp, grad_graphs, backend=grad_backend, cse=cse)
if include_hess:
hess_graphs = list(list(g.diff(w) for w in wrt) for g in grad_graphs)
# Hessians are hard-coded to always use the lambda backend, for performance
hess = lambdify(inp, hess_graphs, backend='lambda', cse=cse)
return BuildFunctionsResult(func=func, grad=grad, hess=hess)