R/089_atoms_sum_smallest.R

Defines functions sum_smallest

Documented in sum_smallest

#####
## DO NOT EDIT THIS FILE!! EDIT THE SOURCE INSTEAD: rsrc_tree/atoms/sum_smallest.R
#####

## CVXPY SOURCE: atoms/sum_smallest.py
## At 1.9.0: sum_smallest threads axis/keepdims through to sum_largest (PR #3172).
## 2D axis slice fully ported; N/A for CVXR (2D-only): N-D tuple axis.
## SumSmallest -- sum of k smallest entries

#' Sum of k smallest entries
#'
#' @param x An Expression
#' @param k Number of smallest entries to sum
#' @param axis NULL (all entries), 1 (row-wise), or 2 (column-wise)
#' @param keepdims Logical; keep the reduced dimension as size 1
#' @returns An Expression equal to -SumLargest(-x, k)
#' @export
sum_smallest <- function(x, k, axis = NULL, keepdims = FALSE) {
  -SumLargest(-as_expr(x), k, axis = axis, keepdims = keepdims)
}

Try the CVXR package in your browser

Any scripts or data that you put into this service are public.

CVXR documentation built on Aug. 24, 2026, 9:10 a.m.