# Path: sucemfem/Utilities/MatrixIO.py
# def load_scipy_matrix_from_mat ( path, name ):
#     """
#     Load a scipy sparse matrix from a .mat file.
#     
#     @param path: the folder in which the matrix is saved
#     @param name: the filename of the matrix
#     """
#     import scipy.io
#     import scipy.sparse
#     
#     filename =  os.path.join ( path, name)
#     
#     if not os.path.exists( filename + '.mat' ):
#         return None
#     
#     data = scipy.io.loadmat ( filename )[name]
#     
#     if type(data) is np.ndarray:
#         matrix = data
#     else:
#         matrix = data.tocsr ()
#          
#     return matrix
# 
# def save_scipy_matrix_as_mat ( path, name, matrix ):
#     """
#     Save a scipy sparse matrix as a .mat file.
#     
#     @param path: the folder in which the matrix is to be saved
#     @param name: the filename of the matrix
#     @param matrix: the scipy matrix to save
#     """
#     import scipy.io
#     if not check_path ( path ):
#         return False
#     
#     scipy.io.savemat ( os.path.join(path, name), {name: matrix }, oned_as='column' )
#     
#     return True


import numpy as np
import sys
import unittest
        import scipy.sparse
        import scipy.sparse
        import scipy.sparse
from sucemfem.Utilities.MatrixIO import (
                                           load_scipy_matrix_from_mat,
                                           save_scipy_matrix_as_mat,
                                           )
## SUCEM is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with SUCEM. If not, see <http://www.gnu.org/licenses/>. 
##
## Contact: cemagga@gmail.com 
# Authors:
# Neilen Marais <nmarais@gmail.com>
# Evan Lezar <mail@evanlezar.com>

"""this is a set of test cases for the testing of the matrix IO routines in FenicsCode/Utilities"""


sys.path.insert(0, '../')
del sys.path[0]

data_path = 'data/MatrixIO'


class TestMatrixIO ( unittest.TestCase ):
    def test_save_scipy_matrix ( self ):
        N = 1000;
        A = scipy.sparse.rand ( N, N, format='csr' )
        
        save_scipy_matrix_as_mat ( data_path, 'A', A )
    
    def __save_and_load_test (self, name, A ):

# Path: sucemfem/Utilities/MatrixIO.py
# def load_scipy_matrix_from_mat ( path, name ):
#     """
#     Load a scipy sparse matrix from a .mat file.
#     
#     @param path: the folder in which the matrix is saved
#     @param name: the filename of the matrix
#     """
#     import scipy.io
#     import scipy.sparse
#     
#     filename =  os.path.join ( path, name)
#     
#     if not os.path.exists( filename + '.mat' ):
#         return None
#     
#     data = scipy.io.loadmat ( filename )[name]
#     
#     if type(data) is np.ndarray:
#         matrix = data
#     else:
#         matrix = data.tocsr ()
#          
#     return matrix
# 
# def save_scipy_matrix_as_mat ( path, name, matrix ):
#     """
#     Save a scipy sparse matrix as a .mat file.
#     
#     @param path: the folder in which the matrix is to be saved
#     @param name: the filename of the matrix
#     @param matrix: the scipy matrix to save
#     """
#     import scipy.io
#     if not check_path ( path ):
#         return False
#     
#     scipy.io.savemat ( os.path.join(path, name), {name: matrix }, oned_as='column' )
#     
#     return True


# Path: sucemfem/Utilities/tests/test_MatrixIO.py
import numpy as np
import sys
import unittest
        import scipy.sparse
        import scipy.sparse
        import scipy.sparse
from sucemfem.Utilities.MatrixIO import (
                                           load_scipy_matrix_from_mat,
                                           save_scipy_matrix_as_mat,
                                           )

## SUCEM is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with SUCEM. If not, see <http://www.gnu.org/licenses/>. 
##
## Contact: cemagga@gmail.com 
# Authors:
# Neilen Marais <nmarais@gmail.com>
# Evan Lezar <mail@evanlezar.com>

"""this is a set of test cases for the testing of the matrix IO routines in FenicsCode/Utilities"""


sys.path.insert(0, '../')
del sys.path[0]

data_path = 'data/MatrixIO'


class TestMatrixIO ( unittest.TestCase ):
    def test_save_scipy_matrix ( self ):
        N = 1000;
        A = scipy.sparse.rand ( N, N, format='csr' )
        
        save_scipy_matrix_as_mat ( data_path, 'A', A )
    
    def __save_and_load_test (self, name, A ):

        save_scipy_matrix_as_mat ( data_path, name, A )