
sparsediff: R interface to the SparseDiffEngine differentiation backend
Source:R/sparsediff-package.R
sparsediff-package.RdR bindings to the 'SparseDiffEngine' C library — the sparse Jacobian and Hessian differentiation backend used by 'CVXPY' for its Disciplined Nonlinear Programming (DNLP) extension. This package is the R analog of the 'sparsediffpy' Python package and wraps the same C library (pinned at the upstream v0.10.0 release, with its sparse linear-algebra library 'sparsediff_linalg' v0.7.0).
Correspondence with 'sparsediffpy'
Every low-level 'sparsediffpy' 0.10.0 function (the ones 'CVXPY' calls) has
an sd_* counterpart that
calls the same engine routine with the same arguments in the same order.
Names map make_<atom> to sd_<atom> and problem_<step>
to sd_<step> (for example make_exp to sd_exp,
problem_init_jacobian to sd_init_jacobian), with these
exceptions:
make_multiply:sd_elementwise_mult;make_param_scalar_mult/make_param_vector_mult:sd_scalar_mult/sd_vector_mult.make_left_matmul,make_right_matmulandmake_quad_form, which take a format string, are split by format:"sparse"issd_left_matmul,sd_right_matmul,sd_quad_form;"dense"issd_left_matmul_dense,sd_right_matmul_dense,sd_quad_form_dense.make_rel_entr:sd_rel_entr, which dispatches on operand size the same way; the two scalar cases are also available directly assd_rel_entr_first_scalarandsd_rel_entr_second_scalar.get_jacobian_sparsity_coo,problem_eval_jacobian_vals:sd_jacobian_sparsity,sd_jacobian_values;problem_init_hessian_coo_lower_triangular,get_problem_hessian_sparsity_coo,problem_eval_hessian_vals_coo:sd_init_hessian_coo,sd_hessian_sparsity,sd_hessian_values;get_jacobian,get_hessian,get_expr_dimensions,get_expr_size:sd_get_jacobian,sd_get_hessian,sd_get_expr_dimensions,sd_get_expr_size.Arguments that are optional in 'sparsediffpy' are required here (R stubs have no defaults):
verboseofsd_problem,valuesofsd_parameter(the engine requires it anyway), andn_varsofsd_hstack/sd_vstack, which 'sparsediffpy' takes from the first argument.The parameter argument of the sparse matrix products is not exposed: the engine aborts on it.
problem_jacobian_csrandproblem_hessian_csr(sd_jacobian_csr,sd_hessian_csr) return views of the engine's storage in 'sparsediffpy'; here they return copies. Read again aftersd_jacobian_evalorsd_hessian_eval.
Indices are 0-based as in 'sparsediffpy'. CSR results are a list with
data, indices, indptr and shape, the pieces of
its (data, indices, indptr, (m, n)) tuple. The modeling layer that
'sparsediffpy' adds on top of these functions (its Variable,
Expression, compile and Problem, new in 0.9) is not
provided yet.
Author
Maintainer: Balasubramanian Narasimhan naras@stanford.edu
Authors:
Balasubramanian Narasimhan naras@stanford.edu
Daniel Cederberg (Author of the bundled SparseDiffEngine C library) [copyright holder]
William Zijie Zhang (Author of the bundled SparseDiffEngine C library) [copyright holder]