| Server IP : 217.160.0.135 / Your IP : 216.73.217.85 Web Server : Apache System : Linux www 6.18.52-i1-ampere #1203 SMP Mon Sep 14 18:29:59 CEST 2026 aarch64 User : sws1074145052 ( 1074145052) PHP Version : 8.3.32 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /lib/python3/dist-packages/scipy/linalg/__pycache__/ |
Upload File : |
�
d�c�0 � � � d dl mZ d dlZd dlmZmZmZmZmZm Z m
Z
mZmZm
Z
mZ ddlmZ ddlmZmZ dgZdd
�Zdd�Zdd�Zdd
�ZdS )� )�warnN)�
atleast_2d�ComplexWarning�arange�
zeros_like�imag�diag�iscomplexobj�tril�triu�argsort�
empty_like� )�_asarray_validated)�get_lapack_funcs�_compute_lwork�ldlTFc � � t t | |�� � � � }|j d |j d k rt d� � �|j dk r8t |� � t |� � t
j g t �� � fS |j d }t |� � rt nt }|t u rM|rKd\ }} t
j t t |� � � � � � rt dt d� � � nd
\ }} t# || f|f� � \ }
}t% |||�� � } |
||||�� � \ }
}}|dk r6t d
� |� � � | � � � � �t+ ||�� � \ }}t- |
|||�� � \ }}t/ ||||�� � \ }}|||fS )aG Computes the LDLt or Bunch-Kaufman factorization of a symmetric/
hermitian matrix.
This function returns a block diagonal matrix D consisting blocks of size
at most 2x2 and also a possibly permuted unit lower triangular matrix
``L`` such that the factorization ``A = L D L^H`` or ``A = L D L^T``
holds. If `lower` is False then (again possibly permuted) upper
triangular matrices are returned as outer factors.
The permutation array can be used to triangularize the outer factors
simply by a row shuffle, i.e., ``lu[perm, :]`` is an upper/lower
triangular matrix. This is also equivalent to multiplication with a
permutation matrix ``P.dot(lu)``, where ``P`` is a column-permuted
identity matrix ``I[:, perm]``.
Depending on the value of the boolean `lower`, only upper or lower
triangular part of the input array is referenced. Hence, a triangular
matrix on entry would give the same result as if the full matrix is
supplied.
Parameters
----------
A : array_like
Square input array
lower : bool, optional
This switches between the lower and upper triangular outer factors of
the factorization. Lower triangular (``lower=True``) is the default.
hermitian : bool, optional
For complex-valued arrays, this defines whether ``A = A.conj().T`` or
``A = A.T`` is assumed. For real-valued arrays, this switch has no
effect.
overwrite_a : bool, optional
Allow overwriting data in `A` (may enhance performance). The default
is False.
check_finite : bool, optional
Whether to check that the input matrices contain only finite numbers.
Disabling may give a performance gain, but may result in problems
(crashes, non-termination) if the inputs do contain infinities or NaNs.
Returns
-------
lu : ndarray
The (possibly) permuted upper/lower triangular outer factor of the
factorization.
d : ndarray
The block diagonal multiplier of the factorization.
perm : ndarray
The row-permutation index array that brings lu into triangular form.
Raises
------
ValueError
If input array is not square.
ComplexWarning
If a complex-valued array with nonzero imaginary parts on the
diagonal is given and hermitian is set to True.
See Also
--------
cholesky, lu
Notes
-----
This function uses ``?SYTRF`` routines for symmetric matrices and
``?HETRF`` routines for Hermitian matrices from LAPACK. See [1]_ for
the algorithm details.
Depending on the `lower` keyword value, only lower or upper triangular
part of the input array is referenced. Moreover, this keyword also defines
the structure of the outer factors of the factorization.
.. versionadded:: 1.1.0
References
----------
.. [1] J.R. Bunch, L. Kaufman, Some stable methods for calculating
inertia and solving symmetric linear systems, Math. Comput. Vol.31,
1977. :doi:`10.2307/2005787`
Examples
--------
Given an upper triangular array ``a`` that represents the full symmetric
array with its entries, obtain ``l``, 'd' and the permutation vector `perm`:
>>> import numpy as np
>>> from scipy.linalg import ldl
>>> a = np.array([[2, -1, 3], [0, 2, 0], [0, 0, 1]])
>>> lu, d, perm = ldl(a, lower=0) # Use the upper part
>>> lu
array([[ 0. , 0. , 1. ],
[ 0. , 1. , -0.5],
[ 1. , 1. , 1.5]])
>>> d
array([[-5. , 0. , 0. ],
[ 0. , 1.5, 0. ],
[ 0. , 0. , 2. ]])
>>> perm
array([2, 1, 0])
>>> lu[perm, :]
array([[ 1. , 1. , 1.5],
[ 0. , 1. , -0.5],
[ 0. , 0. , 1. ]])
>>> lu.dot(d).dot(lu.T)
array([[ 2., -1., 3.],
[-1., 2., 0.],
[ 3., 0., 1.]])
)�check_finiter r z%The input array "a" should be square.��dtype)�hetrf�hetrf_lworkz�scipy.linalg.ldl():
The imaginary parts of the diagonalare ignored. Use "hermitian=False" for factorization ofcomplex symmetric arrays.� )�
stacklevel)�sytrf�sytrf_lwork)�lower)�lworkr �overwrite_azv{} exited with the internal error "illegal value in argument number {}". See LAPACK documentation for the error codes.)r � hermitian)r r �shape�
ValueError�sizer �np�array�intr
�complex�float�anyr r r r r r �format�upper�_ldl_sanitize_ipiv�_ldl_get_d_and_l�_ldl_construct_tri_factor)�Ar r! r r �a�n�r_or_c�s�sl�solver�solver_lworkr �ldu�piv�info�swap_arr� pivot_arr�d�lu�perms �:/usr/lib/python3/dist-packages/scipy/linalg/_decomp_ldl.pyr r s� � �Z �%�a�l�C�C�C�D�D�A��w�q�z�Q�W�Q�Z����@�A�A�A��v��{�{��!�}�}�j��m�m�R�X�b��-D�-D�-D�D�D� ���
�A�$�Q���
2�W�W�U�F� ����Y��&���2�
�6�$�t�A�w�w�-�-� � � L�� -�.<��
L�
L�
L�
L�� '���2�+�Q��G�a�T�:�:��F�L��<��%�8�8�8�E��V�A�U�%�(3�5� 5� 5�N�C��d��a�x�x�� 0�06��q�w�w�y�y�4�%�0H�0H�J� J� J� -�S��>�>�>��H�i��S�)�5�I�N�N�N�E�A�r�(��X�y��N�N�N�H�B��
�q�$�;�� c � � | j }t |� � }t |t �� � }d}|rddd|dfn dd|dz
ddf\ }}}} }
t || |
� � D ]|}|rd}�| | }|dk r||dz k r||dz
||<