code: def test_pinv_rank_deficient():
      # Test the four properties of the pseudoinverse for various matrices.
      As = [
          Matrix([[1, 1, 1], [2, 2, 2]]),
          Matrix([[1, 0], [0, 0]]),
          Matrix([[1, 2], [2, 4], [3, 6]]),
      ]
  
      for A in As:
          A_pinv = A.pinv(method="RD")
          AAp = A * A_pinv
          ApA = A_pinv * A
          assert simplify(AAp * A) == A
          assert simplify(ApA * A_pinv) == A_pinv
          assert AAp.H == AAp
          assert ApA.H == ApA
  
      for A in As:
          A_pinv = A.pinv(method="ED")
          AAp = A * A_pinv
          ApA = A_pinv * A
          assert simplify(AAp * A) == A
          assert simplify(ApA * A_pinv) == A_pinv
          assert AAp.H == AAp
          assert ApA.H == ApA
  
      # Test solving with rank-deficient matrices.
      A = Matrix([[1, 0], [0, 0]])
      # Exact, non-unique solution.
      B = Matrix([3, 0])
      solution = A.pinv_solve(B)
      w1 = solution.atoms(Symbol).pop()
      assert w1.name == "w1_0"
      assert solution == Matrix([3, w1])
      assert A * A.pinv() * B == B
      # Least squares, non-unique solution.
      B = Matrix([3, 1])
      solution = A.pinv_solve(B)
      w1 = solution.atoms(Symbol).pop()
      assert w1.name == "w1_0"
      assert solution == Matrix([3, w1])
      assert A * A.pinv() * B != B
  
imports: import pytest
  from sympy.core.function import expand_mul
  from sympy.core.numbers import I, Rational
  from sympy.core.singleton import S
  from sympy.core.symbol import Symbol, symbols
  from sympy.core.sympify import sympify
  from sympy.simplify.simplify import simplify
  from sympy.matrices.exceptions import ShapeError, NonSquareMatrixError
  from sympy.matrices import ImmutableMatrix, Matrix, eye, ones, ImmutableDenseMatrix, dotprodsimp
  from sympy.matrices.determinant import _det_laplace
  from sympy.testing.pytest import raises
  from sympy.matrices.exceptions import NonInvertibleMatrixError
  from sympy.polys.matrices.exceptions import DMShapeError
  from sympy.solvers.solveset import linsolve
  from sympy.abc import x, y
label_desc: Use image node_id 14 for calling a global function with example usage: test_pinv_rank_deficient() without return types