R/041_atoms_affine_transpose.R

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

## CVXPY SOURCE: atoms/affine/transpose.py
## Transpose -- transpose an expression


# -- Transpose class --------------------------------------------------
## CVXPY SOURCE: atoms/affine/transpose.py lines 26-111

Transpose <- new_class("Transpose", parent = AffAtom, package = "CVXR",
  constructor = function(expr) {
    expr <- as_expr(expr)
    shape <- rev(expr@shape)

    new_object(S7_object(),
      id    = next_expr_id(),
      .cache = new.env(parent = emptyenv()),
      args  = list(expr),
      shape = as.integer(shape)
    )
  }
)

# -- shape_from_args --------------------------------------------------
## CVXPY SOURCE: transpose.py lines 81-85

method(shape_from_args, Transpose) <- function(x) {
  rev(x@args[[1L]]@shape)
}

# -- sign_from_args ---------------------------------------------------
## Inherits from AffAtom: sum_signs(args)

# -- log-log curvature: affine (CVXPY transpose.py lines 56-60) ------
method(is_atom_log_log_convex, Transpose) <- function(x) TRUE
method(is_atom_log_log_concave, Transpose) <- function(x) TRUE

# -- numeric_value ----------------------------------------------------
## CVXPY SOURCE: transpose.py lines 52-54

method(numeric_value, Transpose) <- function(x, values, ...) {
  val <- values[[1L]]
  if (is.matrix(val) || inherits(val, "Matrix")) {
    t(val)
  } else {
    ## Scalar: transpose is identity
    val
  }
}

# -- is_symmetric -----------------------------------------------------
## CVXPY SOURCE: transpose.py lines 66-69

method(is_symmetric, Transpose) <- function(x) {
  x@args[[1L]]@shape[1L] == x@args[[1L]]@shape[2L] &&
    is_symmetric(x@args[[1L]])
}

# -- is_hermitian -----------------------------------------------------
## CVXPY SOURCE: transpose.py lines 76-79

method(is_hermitian, Transpose) <- function(x) {
  x@args[[1L]]@shape[1L] == x@args[[1L]]@shape[2L] &&
    is_hermitian(x@args[[1L]])
}

# -- graph_implementation ---------------------------------------------
## CVXPY SOURCE: transpose.py lines 92-111

method(graph_implementation, Transpose) <- function(x, arg_objs, shape, data = NULL, ...) {
  list(transpose_linop(arg_objs[[1L]]), list())
}

# -- expr_name --------------------------------------------------------
## CVXPY SOURCE: transpose.py lines 37-41

method(expr_name, Transpose) <- function(x) {
  sprintf("t(%s)", expr_name(x@args[[1L]]))
}

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.