#include "daal.h"
#include "service.h"
using namespace std;
using namespace daal;
using namespace daal::algorithms;
const string datasetFileName = "../data/online/svd.csv";
const size_t nRowsInBlock      = 4000;
int main(int argc, char *argv[])
{
    checkArguments(argc, argv, 1, &datasetFileName);
    
    FileDataSource<CSVFeatureManager> dataSource(datasetFileName, DataSource::doAllocateNumericTable,
                                                 DataSource::doDictionaryFromContext);
    
    svd::Online<> algorithm;
    while(dataSource.loadDataBlock(nRowsInBlock) == nRowsInBlock)
    {
        algorithm.input.set( svd::data, dataSource.getNumericTable() );
        
        algorithm.compute();
    }
    
    algorithm.finalizeCompute();
    services::SharedPtr<svd::Result> res = algorithm.getResult();
    
    printNumericTable(res->get(svd::singularValues),      "Singular values:");
    printNumericTable(res->get(svd::rightSingularMatrix), "Right orthogonal matrix V:");
    printNumericTable(res->get(svd::leftSingularMatrix),  "Left orthogonal matrix U:", 10);
    return 0;
}