MathPHP\LinearAlgebra\MatrixFactory::determineMatrixType PHP Method

determineMatrixType() private static method

Determine what type of matrix to create
private static determineMatrixType ( array $A, $vandermonde_n ) : string
$A array 1- or 2-dimensional array of Matrix data 1-dimensional array for Diagonal and Vandermonde matrices 2-dimensional array for Square, Function, and regular Matrices
return string indicating what matrix type to create
    private static function determineMatrixType(array $A, $vandermonde_n) : string
    {
        $m = count($A);
        // 1-dimensional array is how we create diagonal and vandermonde matrices
        $one_dimensional = count(array_filter($A, 'is_array')) === 0;
        if ($one_dimensional) {
            if (is_null($vandermonde_n)) {
                return 'diagonal';
            }
            if ($m === $vandermonde_n) {
                return 'vandermonde_square';
            }
            return 'vandermonde';
        }
        // Square Matrices have the same number of rows (m) and columns (n)
        $n = count($A[0]);
        if ($m === $n) {
            if (is_callable($A[0][0])) {
                return 'function_square';
            }
            return 'square';
        }
        // Non square Matrices
        // First check to make sure it isn't something strange
        if (is_array($A[0][0])) {
            return 'unknown';
        }
        // Then check remaining matrix types
        if (is_callable($A[0][0])) {
            return 'function';
        }
        return 'matrix';
    }