R/093_atoms_norm.R

Defines functions cvxr_norm

Documented in cvxr_norm

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

## CVXPY SOURCE: atoms/norm.py
## Norm factory function (matching old CVXR API)
## Dispatches to Norm1, NormInf, or Pnorm based on p

#' Compute a norm of an expression
#'
#' @param x An Expression
#' @param p Norm type: 1, 2, Inf, or "fro" (Frobenius)
#' @param axis NULL (all), 0 (columns), or 1 (rows)
#' @param keepdims Logical
#' @param max_denom Integer max denominator
#' @returns A norm atom
#' @export
cvxr_norm <- function(x, p = 2, axis = NULL, keepdims = FALSE, max_denom = 1024L) {
  if (identical(p, "fro") || identical(p, "F")) {
    ## Frobenius norm = p_norm(vec(x), 2)
    return(p_norm(x, 2, axis = NULL, keepdims = FALSE, max_denom = max_denom))
  }
  p <- as.numeric(p)
  if (p == 1) return(norm1(x, axis, keepdims))
  if (p == Inf) return(norm_inf(x, axis, keepdims))
  p_norm(x, p, axis, keepdims, max_denom)
}

Try the CVXR package in your browser

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

CVXR documentation built on March 6, 2026, 9:10 a.m.