Source code for cvxpy.atoms.affine.transpose

"""

you may not use this file except in compliance with the License.
You may obtain a copy of the License at

Unless required by applicable law or agreed to in writing, software
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
"""

from cvxpy.atoms.affine.affine_atom import AffAtom
import cvxpy.lin_ops.lin_utils as lu
import numpy as np

[docs]class transpose(AffAtom):
"""Transpose an expression.
"""

def __init__(self, expr, axes=None):
self.axes = axes
super(AffAtom, self).__init__(expr)

# The string representation of the atom.
def name(self):
return "%s.T" % self.args

# Returns the transpose of the given value.
@AffAtom.numpy_numeric
def numeric(self, values):
return np.transpose(values, axes=self.axes)

def is_atom_log_log_convex(self):
"""Is the atom log-log convex?
"""
return True

def is_atom_log_log_concave(self):
"""Is the atom log-log concave?
"""
return True

def is_symmetric(self):
"""Is the expression symmetric?
"""
return self.args.is_symmetric()

def is_hermitian(self):
"""Is the expression Hermitian?
"""
return self.args.is_hermitian()

def shape_from_args(self):
"""Returns the shape of the transpose expression.
"""
return self.args.shape[::-1]

def get_data(self):
""" Returns the axes for transposition.
"""
return [self.axes]

@staticmethod
def graph_implementation(arg_objs, shape, data=None):
"""Create a new variable equal to the argument transposed.

Parameters
----------
arg_objs : list
LinExpr for each argument.
shape : tuple
The shape of the resulting expression.
data :
Additional data required by the atom.

Returns
-------
tuple
(LinOp for objective, list of constraints)
"""
# TODO(akshakya): This will need to be updated when we add support
# for >2D ararys.
return (lu.transpose(arg_objs), [])
{"ft_lang_label":"__label__en","ft_lang_prob":0.5195251,"math_prob":0.7315321,"size":2121,"snap":"2019-26-2019-30","text_gpt3_token_len":515,"char_repetition_ratio":0.1440718,"word_repetition_ratio":0.0,"special_character_ratio":0.261669,"punctuation_ratio":0.19689119,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9665953,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2019-06-19T06:56:26Z\",\"WARC-Record-ID\":\"<urn:uuid:ffb84e4c-26b7-4467-b4da-7117b94b4569>\",\"Content-Length\":\"14426\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:91bbec1b-3f06-4ef5-a940-76320f434c64>\",\"WARC-Concurrent-To\":\"<urn:uuid:08a84851-ae9e-4265-93bd-620620aa28d3>\",\"WARC-IP-Address\":\"185.199.111.153\",\"WARC-Target-URI\":\"https://www.cvxpy.org/_modules/cvxpy/atoms/affine/transpose.html\",\"WARC-Payload-Digest\":\"sha1:PSIPGRHOLVUUG6EJJBBXFYA3UDPIUVBY\",\"WARC-Block-Digest\":\"sha1:TAUBYPE6DOZDKTE4CTC2KO6GYE6GVNKG\",\"WARC-Identified-Payload-Type\":\"application/xhtml+xml\",\"warc_filename\":\"/cc_download/warc_2019/CC-MAIN-2019-26/CC-MAIN-2019-26_segments_1560627998923.96_warc_CC-MAIN-20190619063711-20190619085711-00141.warc.gz\"}"}