<commit_before>//
//  SymMatrix.h
//  Sparse_Matrix
//
//  Created by <NAME> on 6/24/13.
//  Copyright (c) 2013 <NAME>. All rights reserved.
//

#ifndef _SymMatrix_h
#define _SymMatrix_h


#include <cstdlib>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <fstream>
#include <sstream>
#include <iterator>
#include <iomanip>
#include <cstring>
#include <limits>
#include "Matrix.h"
#include "MatrixExceptions.h"

#ifdef USE_MPI
#include "mpi.h"
#endif

#ifdef __linux__
#include "dsmatrxa.h"
#include "ardsmat.h"
#include "ardssym.h"
#include "lsymsol.h"
#endif

template <typename DT>
class SymMatrix;

template <typename DT>
std::ostream& operator<< (std::ostream&, const SymMatrix<DT>&);

template <typename DT>
class SymMatrix
{
private:
    const static int _DEFAULT_MATRIX_SIZE = 1;
    size_t _getArrSize() const;
    void _initilalizeMatrix();
    void _copy(const SymMatrix<DT>&);
    
protected:
    int _size;
    DT* _edges;

public:
    
    /**************
     *Constructors*
     **************/
    SymMatrix();
    SymMatrix(int size);
    SymMatrix(const SymMatrix<DT>&);
    SymMatrix(const std::string&);

    #ifdef USE_MPI
    SymMatrix(int,MPI_Status&);
    SymMatrix(int,int,MPI_Status&);
    #endif
    


    /************
     *Destructor*
     ************/
    virtual ~SymMatrix();
    
    /***********
     *ACCESSORS*
     ***********/
    int getSize() const;
    int getSparseFormSize();
    std::vector<DT> getSumOfRows();
    std::vector<DT> getTopEigenVector();
    std::vector<int> getNeighbors(int vertex);
    Matrix<DT> getScatteredSelection(const std::vector<int>& vec_A, const std::vector<int> vec_B);
    
    /**********
     *MUTATORS*
     **********/
    
    /**********
     *OPERATORS*
     **********/
    DT& operator()(int,int) const;
    bool operator==(const SymMatrix<DT>&);
    SymMatrix<DT> kron(const SymMatrix<DT>&); /* WORKS SHOULD BE CHANGED */
    SymMatrix<DT>& operator= (const SymMatrix<DT>&);
    SymMatrix<DT> diagonalVectorTimesMatrix(const std::vector<DT>&);
    SymMatrix<DT> matrixTimesDiagonalVector(const std::vector<DT>&);
    friend std::ostream& operator<< <> (std::ostream& stream, const Matrix<DT>& matrix);
    
    /*************
    *MPI Send/REC*
    **************/
    #ifdef USE_MPI
    void MPI_Send_SymMatrix(int, int);
    void MPI_Bcast_Send_SymMatrix(int);
    #endif

    
    /* WILL IMPLEMENT IF I HAD TIME AND IF THE OPERATION MADE SENSE FOR SYMMATRIX
     SymMatrix<DT> operator* (const SymMatrix<DT>&);
     SymMatrix<DT> operator+ (const SymMatrix<DT>&);
     SymMatrix<DT> operator- (const SymMatrix<DT>&);
     SymMatrix<DT> operator* (DT);
     SymMatrix<DT> operator+ (DT);
     SymMatrix<DT> operator- (DT);
     void operator*= (const SymMatrix<DT>&);
     void operator+= (const SymMatrix<DT>&);
     void operator-= (const SymMatrix<DT>&);
     void operator*= (DT);
     void operator+= (DT);
     void operator-= (DT);
     */
};

//==========================================================CONSTRUCTORS============================================================

template <typename DT>
inline SymMatrix<DT>::SymMatrix()
{
    this->_size = _DEFAULT_MATRIX_SIZE;
    _initilalizeMatrix();
}

template<typename DT>
inline SymMatrix<DT>::SymMatrix(const std::string& file_path)
{
    int tmp_x;
    int tmp_y;
    std::ifstream file_reader;
    file_reader.open(file_path.c_str());
    
    if(file_reader.fail())
    {
        file_reader.close();
        throw FileDoesNotExistException(file_path.c_str());
    }
    
    file_reader >> this->_size;
    file_reader >> tmp_x;
    
    if (this->_size != tmp_x)
    {
        file_reader.close();
        throw NotASquareMatrixException();
    }
    
    _initilalizeMatrix();
    file_reader >> tmp_x;      //skip the line number
    
    while (!file_reader.eof())
    {
        file_reader >> tmp_x;
        file_reader >> tmp_y;
        (*this)(tmp_x - 1 ,tmp_y - 1) = 1;
    }
    
    file_reader.close();
}

template <typename DT>
inline SymMatrix<DT>::SymMatrix(int size)
{
    this->_size = size;
    _initilalizeMatrix();
}

#ifdef USE_MPI
template <typename DT><commit_msg>added MPI send/recv<commit_after>//
//  SymMatrix.h
//  Sparse_Matrix
//
//  Created by <NAME> on 6/24/13.
//  Copyright (c) 2013 <NAME>. All rights reserved.
//

#ifndef _SymMatrix_h
#define _SymMatrix_h


#include <cstdlib>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <fstream>
#include <sstream>
#include <iterator>
#include <iomanip>
#include <cstring>
#include <limits>
#include "Matrix.h"
#include "MatrixExceptions.h"

#ifdef USE_MPI
#include "mpi.h"
#endif

#ifdef __linux__
#include "dsmatrxa.h"
#include "ardsmat.h"
#include "ardssym.h"
#include "lsymsol.h"
#endif

template <typename DT>
class SymMatrix;

template <typename DT>
std::ostream& operator<< (std::ostream&, const SymMatrix<DT>&);

template <typename DT>
class SymMatrix
{
private:
    const static int _DEFAULT_MATRIX_SIZE = 1;
    size_t _getArrSize() const;
    void _initilalizeMatrix();
    void _copy(const SymMatrix<DT>&);
    
protected:
    int _size;
    DT* _edges;
  

public:
      
    /**************
     *Constructors*
     **************/
    SymMatrix();
    SymMatrix(int size);
    SymMatrix(const SymMatrix<DT>&);
    SymMatrix(const std::string&);

    #ifdef USE_MPI
    SymMatrix(int,MPI_Status&);
    SymMatrix(int,int,MPI_Status&);
    #endif
    


    /************
     *Destructor*
     ************/
    virtual ~SymMatrix();
    
    /***********
     *ACCESSORS*
     ***********/
    int getSize() const;
    int getSparseFormSize();
    std::vector<DT> getSumOfRows();
    std::vector<DT> getTopEigenVector();
    std::vector<int> getNeighbors(int vertex);
    Matrix<DT> getScatteredSelection(const std::vector<int>& vec_A, const std::vector<int> vec_B);
    
    /**********
     *MUTATORS*
     **********/
    
    /**********
     *OPERATORS*
     **********/
    DT& operator()(int,int) const;
    bool operator==(const SymMatrix<DT>&);
    SymMatrix<DT> kron(const SymMatrix<DT>&); /* WORKS SHOULD BE CHANGED */
    SymMatrix<DT>& operator= (const SymMatrix<DT>&);
    SymMatrix<DT> diagonalVectorTimesMatrix(const std::vector<DT>&);
    SymMatrix<DT> matrixTimesDiagonalVector(const std::vector<DT>&);
    friend std::ostream& operator<< <> (std::ostream& stream, const Matrix<DT>& matrix);
    
    /*************
    *MPI Send/REC*
    **************/
    #ifdef USE_MPI
    void MPI_Send_SymMatrix(int, int);
    void MPI_Bcast_Send_SymMatrix(int);
    #endif

    
    /* WILL IMPLEMENT IF I HAD TIME AND IF THE OPERATION MADE SENSE FOR SYMMATRIX
     SymMatrix<DT> operator* (const SymMatrix<DT>&);
     SymMatrix<DT> operator+ (const SymMatrix<DT>&);
     SymMatrix<DT> operator- (const SymMatrix<DT>&);
     SymMatrix<DT> operator* (DT);
     SymMatrix<DT> operator+ (DT);
     SymMatrix<DT> operator- (DT);
     void operator*= (const SymMatrix<DT>&);
     void operator+= (const SymMatrix<DT>&);
     void operator-= (const SymMatrix<DT>&);
     void operator*= (DT);
     void operator+= (DT);
     void operator-= (DT);
     */
};

//==========================================================CONSTRUCTORS============================================================

template <typename DT>
inline SymMatrix<DT>::SymMatrix()
{
    this->_size = _DEFAULT_MATRIX_SIZE;
    _initilalizeMatrix();
}

template<typename DT>
inline SymMatrix<DT>::SymMatrix(const std::string& file_path)
{
    int tmp_x;
    int tmp_y;
    std::ifstream file_reader;
    file_reader.open(file_path.c_str());
    
    if(file_reader.fail())
    {
        file_reader.close();
        throw FileDoesNotExistException(file_path.c_str());
    }
    
    file_reader >> this->_size;
    file_reader >> tmp_x;
    
    
    if (this->_size != tmp_x)
    {
        file_reader.close();
        throw NotASquareMatrixException();
    }
    
    _initilalizeMatrix();
    file_reader >> tmp_x;      //skip the line number
    
    while (!file_reader.eof())
    {
        file_reader >> tmp_x;
        file_reader >> tmp_y;
        (*this)(tmp_x - 1 ,tmp_y - 1) = 1;
    }
    
    file_reader.close();
}

template <typename DT>
inline SymMatrix<DT>::SymMatrix(int size)
{
    this->_size = size;
    _initilalizeMatrix();
}

#ifdef USE_MPI
template <typename DT>
{'fraction_non_alphanumeric': 0.19408129308295696, 'fraction_numerical': 0.0030900879486570002, 'mean_word_length': 3.447674418604651, 'pattern_counts': {'":': 0, '<': 123, '<?xml version=': 0, '>': 143, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7421404', 'n_tokens_mistral': 2869, 'n_tokens_neox': 2815, 'n_words': 611}