| 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/sparse/linalg/__pycache__/ |
Upload File : |
�
d�c\j � �* � d Z ddgZddlZddlmZmZ ddlmZ ddl m
Z
ddlmZ ddl
Zddl Zdd lmZ d
dlmZmZ dZd
� Zd� Zd� Zd#d�Z G d� de� � Z G d� de� � Z d$d�Z d$d�Z G d� d� � Zd� Zd� Z d%d�Z!d� Z"d � Z#d!� Z$d"� Z%dS )&z
Sparse matrix functions
�expm�inv� N)�solve�solve_triangular)�
isspmatrix)�spsolve)�is_pydata_spmatrix)�LinearOperator� )�_ident_like�
_exact_1_norm�upper_triangularc � � t j � | � � st | � � st d� � �t | � � }t
| |� � }|S )a�
Compute the inverse of a sparse matrix
Parameters
----------
A : (M, M) sparse matrix
square matrix to be inverted
Returns
-------
Ainv : (M, M) sparse matrix
inverse of `A`
Notes
-----
This computes the sparse inverse of `A`. If the inverse of `A` is expected
to be non-sparse, it will likely be faster to convert `A` to dense and use
`scipy.linalg.inv`.
Examples
--------
>>> from scipy.sparse import csc_matrix
>>> from scipy.sparse.linalg import inv
>>> A = csc_matrix([[1., 0.], [1., 2.]])
>>> Ainv = inv(A)
>>> Ainv
<2x2 sparse matrix of type '<class 'numpy.float64'>'
with 3 stored elements in Compressed Sparse Column format>
>>> A.dot(Ainv)
<2x2 sparse matrix of type '<class 'numpy.float64'>'
with 2 stored elements in Compressed Sparse Column format>
>>> A.dot(Ainv).toarray()
array([[ 1., 0.],
[ 0., 1.]])
.. versionadded:: 0.12.0
zInput must be a sparse matrix)�scipy�sparser r � TypeErrorr r )�A�I�Ainvs �?/usr/lib/python3/dist-packages/scipy/sparse/linalg/_matfuncs.pyr r s[ � �P
�L�#�#�A�&�&� 9�*<�Q�*?�*?� 9��7�8�8�8� �A���A��1�a�=�=�D��K� c �� � t |� � |k s|dk rt d� � �t |� � }t | j � � dk s| j d | j d k rt d� � �t j | j d dft �� � }| j }t |� � D ]}|� |� � }�t j
|� � S )a�
Compute the 1-norm of a non-negative integer power of a non-negative matrix.
Parameters
----------
A : a square ndarray or matrix or sparse matrix
Input matrix with non-negative entries.
p : non-negative integer
The power to which the matrix is to be raised.
Returns
-------
out : float
The 1-norm of the matrix power p of A.
r zexpected non-negative integer p� r �%expected A to be like a square matrix��dtype)�int�
ValueError�len�shape�np�ones�float�T�range�dot�max)r �p�v�M�is r �_onenorm_matrix_power_nnmr, O s� � �$ �1�v�v��{�{�a�!�e�e��:�;�;�;��A���A�
�1�7�|�|�q���A�G�A�J�!�'�!�*�4�4��@�A�A�A� ������Q��u�-�-�-�A� ��A�
�1�X�X� � ��
�E�E�!�H�H���
�6�!�9�9�r c �^ � t | � � rCt j � | d� � }|j dk p|� � � dk S t
| � � r%dd l}|� | d� � }|j dk S t j | d� � � � � S )N���r ) r r r �tril�nnz�
count_nonzeror r! �any)r �
lower_partr s r �_is_upper_triangularr4 p s� � ��!�}�}�
(��\�&�&�q�"�-�-�
� �~��"�E�j�&>�&>�&@�&@�A�&E�E� �A� � � (��
�
�
��[�[��B�'�'�
��~��"�"��7�1�b�>�>�%�%�'�'�'�'r c � � t | j � � dk rt d� � �t |j � � dk rt d� � �d}|t k r`t | � � sQt |� � sBt | � � s3t |� � s$t j � d| |f� � \ }|�|�d} ||| |� � }n0|�| � |� � }n|| � |� � z }|S )a�
A matrix product that knows about sparse and structured matrices.
Parameters
----------
A : 2d ndarray
First matrix.
B : 2d ndarray
Second matrix.
alpha : float
The matrix product will be scaled by this constant.
structure : str, optional
A string describing the structure of both matrices `A` and `B`.
Only `upper_triangular` is currently supported.
Returns
-------
M : 2d ndarray
Matrix product of A and B.
r z%expected A to be a rectangular matrixz%expected B to be a rectangular matrixN)�trmm� �?)
r r r �UPPER_TRIANGULARr r r �linalg�get_blas_funcsr&