pyyeti.ytools.mattype¶
- pyyeti.ytools.mattype(A, mtype=None, return_cholesky=False)[source]¶
Checks contents of square matrix A to see if it is symmetric, hermitian, positive-definite, diagonal, and identity.
- Parameters:
A (2d array_like or None) – If not square or if number of dimensions does not equal 2, the return type is 0. If None, just return the mattypes output (not a tuple).
mtype (string or None) – If string, it must be one of the mattypes listed below; in this case, True is returned if A is of the type specified or False otherwise. If None, Atype (if A is not None) and mattypes is returned. mtype is ignored if A is None.
return_cholesky (bool; optional) – If True, the output of
scipy.linalg.cholesky()is returned if computed. Output will be None if A is not positive-definite. See example usages below.
- Returns:
flag (bool) – True/False flag specifying whether or not A is of the type specified by mtype. Not returned if either A or mtype is None. If flag is returned, it is the only returned value.
Atype (integer) – Integer with bits set according to content. Not returned if A is None or if mtype is specified.
mattypes (dictionary) –
Provided for reference:
mattypes = {'symmetric': 1, 'hermitian': 2, 'posdef': 4, 'diagonal': 8, 'identity': 16}
Not returned if mtype is specified. This is the only return if A is None.
chol (2d ndarray or None) – See return_cholesky above. If returned, chol will be the output of
scipy.linalg.cholesky()(with default settings) or None, depending on whether matrix is positive-definite or not.
Notes
Here are some example usages:
Usage
Returns
mattype(A)
(Atype, mattypes)
mattype(A, return_cholesky=True)
(Atype, mattypes, chol)
mattype(A, ‘symmetric’)
True or False
mattype(A, ‘posdef’, return_cholesky=True)
(True or False, chol)
mattype(None)
mattypes
See also
Examples
>>> from pyyeti import ytools >>> import numpy as np >>> A = np.eye(5) >>> ytools.mattype(A, 'identity') True >>> Atype, mattypes = ytools.mattype(A) >>> >>> Atype == 1 | 4 | 8 | 16 True >>> if Atype & mattypes['identity']: ... print('A is identity') A is identity >>> for i in sorted(mattypes): ... print(f'{i:10s}: {mattypes[i]:2}') diagonal : 8 hermitian : 2 identity : 16 posdef : 4 symmetric : 1 >>> mattypes = ytools.mattype(None) >>> for i in sorted(mattypes): ... print(f'{i:10s}: {mattypes[i]:2}') diagonal : 8 hermitian : 2 identity : 16 posdef : 4 symmetric : 1