/*
    Copyright (C) 2012 Bartosz Broda, Jacek Bochenek, Łukasz Biłeńkij, 
    Damian Jaworski, Wojciech Mazur, Dominik Piasecki, Maciej Piasecki, 
    Radosław Ramocki
    
    This program is free software; you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as published by the Free
Software Foundation; either version 3 of the License, or (at your option)
any later version.

    This program 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 LICENSE and COPYING files for more details.
*/

#include "../comparator_stdheaders.h"
#include "Transformation.h"
#include "../compare/CompareFunction.h"

namespace smartcomparator
{
	namespace transformations
	{
		class SVDTransformation : public Transformation
		{
		public:
			SVDTransformation(Matrices::SuperMatrixPtr matrix, int dimensions=0, bool testing_mode=false);

			virtual void TransformMatrix();

			/**
			  * Works only if testing_mode=true
			  */
			Matrices::CRSMatrixPtr getTestUCRS();
			Matrices::CRSMatrixPtr getTestSCRS();

		private:
			Matrices::SuperMatrixPtr m_pMatrix;
			Matrices::CCSMatrixPtr STFormat;
			Matrices::CRSMatrixPtr UxS;
			Matrices::CRSMatrixPtr test_UCRS;
			Matrices::CRSMatrixPtr test_SCRS;
			size_t m_dimensions;
			std::string open_temp(std::string path);
			bool m_testing;
			void SVDRun();
			void SVDCompute();
			void LoadAndMultiplyMatrices();
			void crs2sm();
			Matrices::CRSMatrixPtr multiplyMatrices(Matrices::CRSMatrixPtr matrix1, Matrices::CRSMatrixPtr matrix2);

			std::string workDir;
			std::string matrixPath;
        };
    }
}

