Given a matrix ${\bf A} \in {\Bbb R}^{n \times n}$, define the $n \times n$ binary matrix $\bf B$ as follows
$$ b_{ij} := \begin{cases}
1 & \text{if} & a_{ij} \neq 0 \\
0 & \text{if} & a_{ij} = 0 \end{cases} $$
The matrix $\bf B$ contains the sparsity pattern of the matrix $\bf A$. Hence, if $\operatorname{tr} ({\bf B}) = n$, or if there exists an $n \times n$ nontrivial permutation matrix ${\bf P} \neq {\bf I}_n$ that permutes the columns of $\bf B$ such that $\operatorname{tr} ({\bf B} {\bf P}) = n$, then the matrix $\bf A$ does have support.
Let ${\Bbb P}_n$ denote the set of $n \times n$ permutation matrices. Relaxing, the convex hull of ${\Bbb P}_n$ is the Birkhoff polytope ${\Bbb B}_n$ (the set of all $n \times n$ doubly stochastic matrices). Hence, a permutation matrix can be found via the following linear program (LP)
$$\begin{array}{ll} \underset{{\bf X} \in {\Bbb R}^{n \times n}}{\text{maximize}} & \operatorname{tr} ({\bf B} {\bf X}) \\ \text{subject to} & {\bf X} {\bf 1}_n = {\bf 1}_n \\ & {\bf 1}_n^\top {\bf X} = {\bf 1}_n^\top\\ & {\bf X} \geq {\bf O}_n\end{array}$$
Let $\bar{\bf X}$ denote the maximizer. If $\operatorname{tr} \left( {\bf B} \bar{\bf X} \right) = n$, then the matrix $\bf A$ does have support.
Numerical experiment
From the question,
$$ {\bf A} := \begin{pmatrix}
1 & 0 & 0 \\
0 & 2 & 3 \\
0 & 5 & 0 \end{pmatrix} $$
Using CVXPY to solve the LP,
from cvxpy import *
import numpy as np
determine whether square matrix A has support
def hasSupport(A):
# extract the number of rows (or columns)
n = A.shape[0]
# extract the sparsity pattern of matrix A
B = (A != 0).astype(int)
# create column vector of n ones
ones_n = np.ones((n,1))
# create matrix decision variable
X = Variable((n,n))
# create linear program (LP)
constraints = [ X @ ones_n == ones_n,
ones_n.T @ X == ones_n.T,
X >= 0 ]
LP = Problem(Maximize(trace(B @ X)), constraints)
LP.solve(verbose = False)
# check if the optimization problem was solved
if LP.status == "optimal":
# maximal trace attained (rounded to integer)
maxTrace = int(np.round(LP.value, 0))
# return has-support-ness, maximal trace and permutation matrix
return (maxTrace == n, maxTrace, np.round(X.value, 3))
else:
return "Error!"
def main():
A = np.array([[ 1, 0, 0],
[ 0, 2, 3],
[ 0, 5, 0]])
hasSupp, maxTrace, P = hasSupport(A)
print("Matrix A has support: ", hasSupp )
print("Permutation matrix: ", P )
print("Maximal trace: ", maxTrace)
print("A with permuted columns:", A @ P )
if name == "main":
main()
which outputs
Matrix A has support: True
Permutation matrix: [[ 1. 0. 0.]
[ 0. -0. 1.]
[ 0. 1. -0.]]
Maximal trace: 3
A with permuted columns: [[1. 0. 0.]
[0. 3. 2.]
[0. 0. 5.]]