@Override
    public boolean equals(Object o)
    {
        if (!(o instanceof Matrix)) {
            return false;
        }
        @SuppressWarnings("unchecked")
        Matrix<T> other = (Matrix<T>)o;
        if (mat.length != other.mat.length) {
            return false;
        }
        for (int ii = 0; ii < mat.length; ii++) {
            if (mat[ii].length != other.mat[ii].length) {
                return false;
            }
            for (int jj = 0; jj < mat[ii].length; jj++) {
                if (!mat[ii][jj].equals(other.mat[ii][jj])) {
                    return false;
                }
            }
        }
        return true;
    }