Nothing
#####
## DO NOT EDIT THIS FILE!! EDIT THE SOURCE INSTEAD: rsrc_tree/atoms/norm1.R
#####
## CVXPY SOURCE: atoms/norm1.py
## Norm1 -- L1 norm (sum of absolute values), axis-aware
Norm1 <- new_class("Norm1", parent = AxisAtom, package = "CVXR",
constructor = function(x, axis = NULL, keepdims = FALSE, id = NULL) {
if (is.null(id)) id <- next_expr_id()
x <- as_expr(x)
if (!is.null(axis)) .validate_axis(axis, length(x@shape))
shape <- .axis_shape(x@shape, axis, keepdims)
obj <- new_object(S7_object(),
id = as.integer(id),
.cache = new.env(parent = emptyenv()),
args = list(x),
shape = shape,
axis = axis,
keepdims = keepdims
)
obj
}
)
# -- sign: always nonneg ------------------------------------------
method(sign_from_args, Norm1) <- function(x) {
list(is_nonneg = TRUE, is_nonpos = FALSE)
}
# -- curvature: convex --------------------------------------------
method(is_atom_convex, Norm1) <- function(x) TRUE
method(is_atom_concave, Norm1) <- function(x) FALSE
# -- monotonicity -------------------------------------------------
method(is_incr, Norm1) <- function(x, idx, ...) is_nonneg(x@args[[1L]])
method(is_decr, Norm1) <- function(x, idx, ...) is_nonpos(x@args[[1L]])
# -- PWL ----------------------------------------------------------
method(is_pwl, Norm1) <- function(x) {
is_pwl(x@args[[1L]]) && is_real(x@args[[1L]])
}
# -- numeric ------------------------------------------------------
method(numeric_value, Norm1) <- function(x, values, ...) {
v <- values[[1L]]
if (is.null(x@axis)) {
matrix(sum(abs(v)), 1L, 1L)
} else if (x@axis == 2L) {
res <- colSums(abs(v))
if (x@keepdims) matrix(res, nrow = 1L) else matrix(res, nrow = 1L)
} else {
res <- rowSums(abs(v))
if (x@keepdims) matrix(res, ncol = 1L) else matrix(res, ncol = 1L)
}
}
# -- graph_implementation: stub -----------------------------------
method(graph_implementation, Norm1) <- function(x, arg_objs, shape, data = NULL, ...) {
cli_abort("graph_implementation for {.cls Norm1} not yet implemented.")
}
#' L1 norm of an expression
#'
#' @param x An Expression
#' @param axis NULL (all), 1 (row-wise), or 2 (column-wise)
#' @param keepdims Logical: keep reduced dimensions?
#' @returns A Norm1 atom
#' @export
norm1 <- function(x, axis = NULL, keepdims = FALSE) {
Norm1(x, axis, keepdims)
}
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.