Tags: SparseDifferentiation/SparseDiffEngine
Tags
Add native kron (Kronecker product) affine atom (#101) * Add native kron (Kronecker product) affine atom cvxpy's kron(A, B) always has one variable-free operand, so every output entry depends on a single child entry: Z[OUT] = coeff[OUT] * child[child_row[OUT]]. The output Jacobian is therefore the child Jacobian's rows gathered (with repetition) and scaled by the variable-free operand -- no coefficient matrix, no matmul, no CSC conversion; O(nnz(result)). child_row[] and coeff_idx[] depend only on the operand shapes and are precomputed once in new_kron. Handles kron(param/const, var) and kron(var, param/const), parametric or constant, with column-major (Fortran) flattening, and re-evaluates the variable-free operand each solve. forward, Jacobian and the affine Hessian backprop are all scaled gathers. Adds forward/Jacobian/wsum_hess unit tests (both forms, scalar operand, and numerical Jacobian/Hessian checks on a composite arg); all_tests now 405. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * Format kron atom and mirror left_matmul structure Apply clang-format and tidy the native kron atom: factor parameter refresh into a helper, null freed pointers, and trim doc duplicated by the kron_expr definition in subexpr.h. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * Rework kron into sparse-only left/right constructors with active blocks new_kron materialized every output row, including the structurally-zero blocks of a sparse constant operand — kron(I_p, X) built p^2 blocks of Jacobian rows with p(p-1) of them zero. Replace it with new_left_kron / new_right_kron taking the constant operand's active (nonzero) block indices, column-major; inactive output rows keep child_row == -1 and contribute a zero value and an empty Jacobian row. cvxpy passes the constant's nonzeros (all blocks for an updatable parameter, whose zeros are not permanent). Constructors assert active block indices are in range. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * Run clang-format over the kron changes Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * Condense kron comments and remove unused struct fields Drop the never-read p/q/r/s fields from kron_expr, tighten the header and inline comment blocks, brace single-statement bodies to match the surrounding atoms, and remove unused includes. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * Use memcpy to gather child row indices in kron jacobian_init Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> --------- Co-authored-by: Transurgeon <peter.zijie@gmail.com> Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Add stacked permuted dense logic * stacked_pd struct, constructor, and BA_spd_csc * first draft of coalesce * first draft of transpose * DA_spd_fill_values * chain rule infrastructure * BA_pd_spd * BA_spd_spd * polymorphism * index, broadcast, diag_vec etc. * BA_spd_pd * continguous memory between blocks so we can just x field in matrix * bug wrong ordering of rows * small bug fixes * before refactor * split up stacked pd into two files * accumulate in ATDA_spd_fill_values * move coalesce to stacked_pd + general clean up * split up permuted dense into permuted_dense_linalg.h * split up permuted dense into permuted_dense_linalg.h * unify code in stacked_pd * clean up BA_pd_spd * wire vtable refactor * remove unnecessary polymorphishm * clean up and coalesce in new file * happy with stacked_pd.c * clean up coalesce * update some comments * remove A_spd from left_matmul by implementing kron wrappers * the actual kron wrappers * clean up left matmul * get rid of to_csr in sum.c by computing a different idx map * small kron debug * remove to-csr in multiply by building correct idx map for stacked pd * remove to-csr in matmul by building correct idx map for stacked pd * simplify idx map * run formatter * remove to_csr in problem.c by updating idx map for stacked_Pdd * general clean up * kernel work * BTA_pd_spd * BTDA_spd_pd_fill_values * unify BTA_pd_spd like kernels * BTA_spd_spd * BTA_spd_matrix dispatcher * add BTA_pd_matrices * BTA_csc_spd * BTA sparse matrix dispatcher * wire in new dispatchers * clarify contract for kron * improve matmul dispatchers interface * unify kron functions * fix comments * update version to 0.4.0
[WIP] New matrix abstraction (#87) * start with permuted dense struct, without integration * better polymorphism * make hessian matrix * dispatch for elementwise chainr rule hessian * better polymorphism for copying sparsity pattern * remove many to_csr * remove memcpy in to_csr * add profile for trimmed log reg * infrastructure for matrix multiplication when one matrix is permuted_dense * ran formatter * better BTDA for permuted dense x permuted_dense * more cache friendly BA_pd_csc_fill_values * edits * better permuted dense times CSC function * better infrastructure permuted dense * get rid of unnecessary allocation * change name of some functions * run formatter * permutation dense preserving transpose implementation via index polymorhpim * clean up multiply * clean up matrix.h * lazy allocation of dwork in permuted_dense * Implement block_left_mult on permuted_dense * swap dense matrix for permuted dense and delete dense_matrix * more infrastructure * better BA_pd_pd_fill_values * add permuted dense polymorphism to left matmul * minor * add test * clean up left_matmul and enable parameter * fix filename
new convolve atom (#85) * initial iteration for convolve atom * apply formatter * adds test for row convolve in case it is 1d in python * improve convention of data pointer when we have parameters for left and right matmul * get rid of sparse matrix abstraction and just do CSR instead * get rid of block abstraction and use non-block logic instead * happy with convolve.c --------- Co-authored-by: dance858 <danielcederberg1@gmail.com>
PreviousNext