0

I need to use the eigen library in my project on Ubuntu (this project works fine on windows). However when I compile I receive the following error:

dv_qkd_ldpc_tx_error_correction_20200819.cpp:186:91:   required from here

Eigen/src/Core/util/XprHelper.h:835:96: error: static assertion failed: YOU_MIXED_DIFFERENT_NUMERIC_TYPES__YOU_NEED_TO_USE_THE_CAST_METHOD_OF_MATRIXBASE_TO_CAST_NUMERIC_TYPES_EXPLICITLY

Acording to terminal, this error is caused by one of my .cpp file at the line 186:

 *pt_calculatedSindrome = sparseParityCheckMatrix * (*pt_receivedData);

or

*pt_calculatedSindrome = (*pt_calculatedSindrome).unaryExpr([](const t_binary x) {return x % 2;}); //to compute mod(sindrome,2)

I understand that this error is asking to apply some casting on the matrixes. And according to this page, I applied the following which didn't work:

*pt_calculatedSindrome = (sparseParityCheckMatrix.cast<t_binary>()) * ((*pt_receivedData).cast<t_binary>());
    

*pt_calculatedSindrome = ((*pt_calculatedSindrome).cast<t_binary>()).unaryExpr([](const t_binary x) {return x % 2;}); //to compute mod(sindrome,2)

Edit: in which:

t_binary = uint8_t

Even when I comment these lines (or even when I remove the whole lines of the file), I still get the same error with the same error line!!! I checked my Makefile to make sure it builds all the .cpp files and it seems to be ok.

Here are the terminal errors:

    In file included from Eigen/Core:369,
                 from Eigen/SparseCore:11,
                 from Eigen/Sparse:26,
                 from netxpto_20200819.h:48,
                 from dv_qkd_ldpc_tx_error_correction_20200819.h:4,
                 from dv_qkd_ldpc_tx_error_correction_20200819.cpp:1:
Eigen/src/Core/AssignEvaluator.h: In instantiation of ‘void Eigen::internal::call_assignment_no_alias(Dst&, const Src&, const Func&) [with Dst = Eigen::Matrix<unsigned char, -1, 1, 0, -1, 1>; Src = Eigen::CwiseUnaryOp<DvQkdLdpcTxErrorCorrection::runBlock()::<lambda(t_binary)>, const Eigen::Matrix<unsigned char, -1, 1, 0, -1, 1> >; Func = Eigen::internal::assign_op<unsigned char, int>]’:
Eigen/src/Core/AssignEvaluator.h:804:27:   required from ‘void Eigen::internal::call_assignment(Dst&, const Src&, const Func&, typename Eigen::internal::enable_if<(! Eigen::internal::evaluator_assume_aliasing<Src>::value), void*>::type) [with Dst = Eigen::Matrix<unsigned char, -1, 1, 0, -1, 1>; Src = Eigen::CwiseUnaryOp<DvQkdLdpcTxErrorCorrection::runBlock()::<lambda(t_binary)>, const Eigen::Matrix<unsigned char, -1, 1, 0, -1, 1> >; Func = Eigen::internal::assign_op<unsigned char, int>; typename Eigen::internal::enable_if<(! Eigen::internal::evaluator_assume_aliasing<Src>::value), void*>::type = void*]’
Eigen/src/Core/AssignEvaluator.h:782:18:   required from ‘void Eigen::internal::call_assignment(Dst&, const Src&) [with Dst = Eigen::Matrix<unsigned char, -1, 1, 0, -1, 1>; Src = Eigen::CwiseUnaryOp<DvQkdLdpcTxErrorCorrection::runBlock()::<lambda(t_binary)>, const Eigen::Matrix<unsigned char, -1, 1, 0, -1, 1> >]’
Eigen/src/Core/PlainObjectBase.h:714:32:   required from ‘Derived& Eigen::PlainObjectBase<Derived>::_set(const Eigen::DenseBase<OtherDerived>&) [with OtherDerived = Eigen::CwiseUnaryOp<DvQkdLdpcTxErrorCorrection::runBlock()::<lambda(t_binary)>, const Eigen::Matrix<unsigned char, -1, 1, 0, -1, 1> >; Derived = Eigen::Matrix<unsigned char, -1, 1, 0, -1, 1>]’
Eigen/src/Core/Matrix.h:225:24:   required from ‘Eigen::Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols>& Eigen::Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols>::operator=(const Eigen::DenseBase<OtherDerived>&) [with OtherDerived = Eigen::CwiseUnaryOp<DvQkdLdpcTxErrorCorrection::runBlock()::<lambda(t_binary)>, const Eigen::Matrix<unsigned char, -1, 1, 0, -1, 1> >; _Scalar = unsigned char; int _Rows = -1; int _Cols = 1; int _Options = 0; int _MaxRows = -1; int _MaxCols = 1]’
dv_qkd_ldpc_tx_error_correction_20200819.cpp:186:89:   required from here
Eigen/src/Core/util/XprHelper.h:835:96: error: static assertion failed: YOU_MIXED_DIFFERENT_NUMERIC_TYPES__YOU_NEED_TO_USE_THE_CAST_METHOD_OF_MATRIXBASE_TO_CAST_NUMERIC_TYPES_EXPLICITLY
  835 | ernal::has_ReturnType<ScalarBinaryOpTraits<LHS, RHS,BINOP> >::value), \
      | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~

Eigen/src/Core/util/StaticAssert.h:33:54: note: in definition of macro ‘EIGEN_STATIC_ASSERT’
   33 |     #define EIGEN_STATIC_ASSERT(X,MSG) static_assert(X,#MSG);
      |                                                      ^
Eigen/src/Core/AssignEvaluator.h:834:3: note: in expansion of macro ‘EIGEN_CHECK_BINARY_COMPATIBILIY’
  834 |   EIGEN_CHECK_BINARY_COMPATIBILIY(Func,typename ActualDstTypeCleaned::Scalar,typename Src::Scalar);

Makefile:91: recipe for target 'dv_qkd_ldpc_tx_error_correction_20200819.o' failed

Terminal screenshot

Here is .cpp file causing error:

#include "cv_qokd_ldpc_tx_sindrome_reconciliation_20200819.h"

void CvQokdLdpcTxSindromeReconciliation::initialize(void)
{
    if (errorCorrectionMethod == CvQokdLdpcTxSindromeReconciliation::t_method::LDPC)
    {
        loadSparseParityCheckMatrix();

        sparseParityCheckMatrixTranspose = sparseParityCheckMatrix.transpose();

        calculatedSindromeSize_0 = codeLength - codeRank;
        calculatedSindrome_0.resize(calculatedSindromeSize_0, 1);
        calculatedSindrome_0_posIn = 0;
        calculatedSindrome_0_posOut = calculatedSindrome_0.size();
        calculatedSindrome_0_newData = false;

        calculatedSindromeSize_1 = codeLength - codeRank;
        calculatedSindrome_1.resize(calculatedSindromeSize_1, 1);
        calculatedSindrome_1_posIn = 0;
        calculatedSindrome_1_posOut = calculatedSindrome_1.size();
        calculatedSindrome_1_newData = false;

        receivedSindromeSize = 1; // codeLength - codeRank;
        receivedSindrome.resize(receivedSindromeSize, 1);
        receivedSindrome_posIn = 0;
        receivedSindrome_posOut = receivedSindrome.size();
        receivedSindrome_newData = false;

        receivedDataSize_0 = codeLength;
        receivedData_0.resize(receivedDataSize_0, 1);
        receivedData_0_posIn = 0;
        receivedData_0_posOut = receivedData_0.size();
        receivedData_0_newData = false;

        receivedDataSize_1 = codeLength;
        receivedData_1.resize(receivedDataSize_1, 1);
        receivedData_1_posIn = 0;
        receivedData_1_posOut = receivedData_1.size();
        receivedData_1_newData = false;

        DataIn.resize((size_t)4*inputSignals[0]->getBufferLength());
        DataOut.resize(DataIn.size());
        SindromeIn.resize((size_t)4*inputSignals[1]->getBufferLength());
        SindromeOut.resize(SindromeIn.size());

        prioriMessageProbabilities.resize(codeLength, 1);

        M.resize(codeLength - codeRank, codeLength);
        M.reserve(numberOfNonZerosValuesInSparseParityCheckMatrix);

        E.resize(codeLength - codeRank, codeLength);
        E.reserve(numberOfNonZerosValuesInSparseParityCheckMatrix);

        tripletList.reserve(getNumberOfNonZerosValuesInSparseParityCheckMatrix());

        bitFillingPeriod = numberOfDataBitsPerBitFillingPeriod + numberOfDummyBitsPerBitFillingPeriod;
    }
    else
    {
        std::cerr << "DVQkdErrorCorrectionLDPC::initialize() - wrong error correction method";
    }

    startSendingSindrome = (getErrorCorrectionRole() == t_role::Rx && getErrorCorrectionMode() == t_mode::InverseReconciliation) || (getErrorCorrectionRole() == t_role::Tx && getErrorCorrectionMode() == t_mode::DirectReconciliation);
}

bool CvQokdLdpcTxSindromeReconciliation::runBlock(void)
{
    if (bypassErrorCorrection)
    {
        auto ready = inputSignals[0]->ready();
        auto space = outputSignals[0]->space();
        auto process = std::min(ready, space);
        totalNumberOfInputBits += process;
        totalNumberOfOutputBits += process;

        for (; process--;)
        {
            t_binary dataIn{ 0 };
            inputSignals[0]->bufferGet(&dataIn);
            outputSignals[0]->bufferPut(dataIn);
        }

        for (auto k = 1; k < inputSignals.size(); k++)
        {
            ready = inputSignals[k]->ready();
            space = inputSignals[k]->space();
            process = std::min(ready, space);
            for (; process--;)
                inputSignals[k]->bufferGet();
        }
        return false;
    }

    bool alive{ false };

    Eigen::Index ready = DataOut.ready();
    Eigen::Index space = outputSignals[0]->space();
    Eigen::Index process = std::min(ready, space);
    alive = !alive ? process > 0: alive;
    totalNumberOfOutputBits += process;
    for (; process--;)
        outputSignals[0]->bufferPut(DataOut.bufferGet());
    
    ready = SindromeOut.ready();
    space = outputSignals[1]->space();
    process = std::min(ready, space);
    alive = !alive ? process > 0: alive;
    for (; process--;)
        outputSignals[1]->bufferPut(SindromeOut.bufferGet());

    ready = inputSignals[0]->ready();
    space = DataIn.space();
    process = std::min(ready, space);
    alive = !alive ? process > 0: alive;
    totalNumberOfInputBits += process;
    for (; process--;)
    {
        t_binary val{ 0 };
        inputSignals[0]->bufferGet(&val);
        DataIn.bufferPut(val);
    }

    ready = inputSignals[1]->ready();
    space = SindromeIn.space();
    process = std::min(ready, space);
    alive = !alive ? process > 0: alive;
    for (; process--;)
    {
        t_binary val{ 0 };
        inputSignals[1]->bufferGet(&val);
        SindromeIn.bufferPut(val);
    }

    ready = SindromeIn.ready();
    process = std::min(ready, receivedSindromeSize - receivedSindrome_posIn);
    alive = !alive ? process > 0: alive;
    for (auto k = receivedSindrome_posIn; k < receivedSindrome_posIn + process; k++)
        receivedSindrome(k, 0) = SindromeIn.bufferGet();

    receivedSindrome_posIn += process;
    if (process > 0 && receivedSindrome_posIn == receivedSindromeSize)
    {
        if (getVerboseMode())
        {
            std::ofstream file;
            file.open(getSignalsFolderName() + "/received_sindrome_tx.txt", std::ios_base::app);
            for (auto k = 0; k < receivedSindromeSize; k++)
            {
                if (k != 0) file << " ";
                file << std::to_string(receivedSindrome[k]);
            }
            file << std::endl;
            file.close();
        }
        receivedSindrome_newData = true;
    }

    ready = DataIn.ready();
    process = std::min( ready, *pt_receivedDataSize - *pt_receivedData_posIn);
    alive = !alive ? process > 0: alive;
    for (auto k = *pt_receivedData_posIn; k < *pt_receivedData_posIn + process; k++)
    {
        if (numberOfDummyBitsPerBitFillingPeriod)
        {
            if (*pt_inDataBitFillingCounter >= numberOfDataBitsPerBitFillingPeriod)
            {
                (*pt_receivedData)[k] = 0;
            }
            else
                (*pt_receivedData)[k] = DataIn.bufferGet();

            *pt_inDataBitFillingCounter = ++(*pt_inDataBitFillingCounter) % bitFillingPeriod;
        }
        else
            (*pt_receivedData)[k] = DataIn.bufferGet();
    }

    *pt_receivedData_posIn += process;
    if (process > 0 && *pt_receivedData_posIn == *pt_receivedDataSize)
        *pt_receivedData_newData = true;

    if (*pt_receivedData_newData && *pt_calculatedSindrome_posIn == 0 && *pt_calculatedSindrome_newData == false)
    {
        if (getVerboseMode())
        {
            std::ofstream file;
            file.open(getSignalsFolderName() + "/receivedData_tx.txt", std::ios_base::app);
            for (auto k = 0; k < *pt_receivedDataSize; k++)
            {
                if (k != 0 && k % 200 == 0) file << std::endl;
                file << std::to_string((*pt_receivedData)[k]);
            }
            file << std::endl;
            file.close();
        }

        *pt_calculatedSindrome = sparseParityCheckMatrix * *pt_receivedData;
        *pt_calculatedSindrome = (*pt_calculatedSindrome).unaryExpr([](const t_binary x) {return x % 2;}); //to compute mod(sindrome,2)

        numberOfCalculatedSindromes++;

        *pt_receivedData_posIn = *pt_receivedDataSize;
        *pt_receivedData_posOut = *pt_receivedDataSize;
        *pt_receivedData_newData = false;

        if (getVerboseMode())
        {
            std::ofstream file;
            file.open(getSignalsFolderName() + "/calculated_sindrome_tx.txt", std::ios_base::app);
            for (auto k = 0; k < *pt_calculatedSindromeSize; k++)
            {
                if (k != 0) file << " ";
                file << std::to_string((*pt_calculatedSindrome)[k]);
            }
            file << std::endl;
            file.close();
        }

        *pt_calculatedSindrome_posIn = *pt_calculatedSindromeSize;
        *pt_calculatedSindrome_newData = true;

        if (process_block == 1)
        {
            if (startSendingSindrome)
            {
                calculatedSindrome_1_posOut = 0;
                startedSendingSindrome_1 = true;
            }

            process_block = 0;

            pt_receivedDataSize = &receivedDataSize_0;
            pt_receivedData = &receivedData_0;
            pt_receivedData_posIn = &receivedData_0_posIn;
            pt_receivedData_posOut = &receivedData_0_posOut;
            pt_receivedData_newData = &receivedData_0_newData;

            pt_calculatedSindrome = &calculatedSindrome_0;
            pt_calculatedSindromeSize = &calculatedSindromeSize_0;
            pt_calculatedSindrome_posIn = &calculatedSindrome_0_posIn;
            pt_calculatedSindrome_posOut = &calculatedSindrome_0_posOut;
            pt_calculatedSindrome_newData = &calculatedSindrome_0_newData;

            pt_inDataBitFillingCounter = &inDataBitFillingCounter_0;
            pt_outDataBitFillingCounter = &outDataBitFillingCounter_0;
        }
        else
        {
            if (startSendingSindrome)
            {
                calculatedSindrome_0_posOut = 0;
                startedSendingSindrome_0 = true;
            }

            process_block = 1;

            pt_receivedDataSize = &receivedDataSize_1;
            pt_receivedData = &receivedData_1;
            pt_receivedData_posIn = &receivedData_1_posIn;
            pt_receivedData_posOut = &receivedData_1_posOut;
            pt_receivedData_newData = &receivedData_1_newData;

            pt_calculatedSindrome = &calculatedSindrome_1;
            pt_calculatedSindromeSize = &calculatedSindromeSize_1;
            pt_calculatedSindrome_posIn = &calculatedSindrome_1_posIn;
            pt_calculatedSindrome_posOut = &calculatedSindrome_1_posOut;
            pt_calculatedSindrome_newData = &calculatedSindrome_1_newData;

            pt_inDataBitFillingCounter = &inDataBitFillingCounter_1;
            pt_outDataBitFillingCounter = &outDataBitFillingCounter_1;
        }
    
    }

    ready = calculatedSindromeSize_0 - calculatedSindrome_0_posOut;
    space = SindromeOut.space();
    process = std::min(ready, space);
    if ( startedSendingSindrome_0 && (!startedSendingSindrome_1) && process)
    {
        for (auto k = calculatedSindrome_0_posOut; k < calculatedSindrome_0_posOut + process; k++)
            SindromeOut.bufferPut(calculatedSindrome_0[k]);

        calculatedSindrome_0_posOut = calculatedSindrome_0_posOut + process;
        if (calculatedSindrome_0_posIn == calculatedSindromeSize_0) calculatedSindrome_0_posIn = 0;

        if (calculatedSindrome_0_posOut == calculatedSindromeSize_0)
            startedSendingSindrome_0 = false;
    }

    ready = calculatedSindromeSize_1 - calculatedSindrome_1_posOut;
    space = SindromeOut.space();
    process = std::min(ready, space);
    if (startedSendingSindrome_1 && (!startedSendingSindrome_0) && process)
    {
        for (auto k = calculatedSindrome_1_posOut; k < calculatedSindrome_1_posOut + process; k++)
            SindromeOut.bufferPut(calculatedSindrome_1[k]);

        calculatedSindrome_1_posOut = calculatedSindrome_1_posOut + process;
        if (calculatedSindrome_1_posIn == calculatedSindromeSize_1) calculatedSindrome_1_posIn = 0;

        if (calculatedSindrome_1_posOut == calculatedSindromeSize_1)
            startedSendingSindrome_1 = false;
    }

    if (receivedSindrome_newData)
    {
        numberOfValidatedSindromes++;

        if (receivedSindrome[0]==0)
        {
            numberOfNoMatchedSindromes++;
            receivedData_0_posIn = 0;
            receivedData_1_posIn = 0;
        }
        else
        {
            receivedData_0_posOut = 0;
            receivedData_1_posOut = 0;
        }

        receivedSindrome_posIn = 0;
        receivedSindrome_newData = false;

        calculatedSindrome_0_newData = false;
        calculatedSindrome_1_newData = false;

        calculatedSindrome_0_posOut = 0;
        calculatedSindrome_1_posOut = 0;
    }
    
    ready = std::min(receivedDataSize_0 - receivedData_0_posOut, receivedDataSize_1 - receivedData_1_posOut);
    space = (Eigen::Index) (DataOut.space()/3);
    process = std::min(ready, space);
    if (process)
    {
        for (auto k = 0; k < process; k++)
        {
            if (numberOfDummyBitsPerBitFillingPeriod)
            {
                if (*pt_outDataBitFillingCounter < numberOfDataBitsPerBitFillingPeriod)
                {
                    DataOut.bufferPut(receivedData_0[receivedData_0_posOut + k]);
                    DataOut.bufferPut(receivedData_1[receivedData_1_posOut + k]);
                }
                *pt_outDataBitFillingCounter = ++(*pt_outDataBitFillingCounter) % bitFillingPeriod;
            }
            else
            {
                DataOut.bufferPut((t_binary) 0);
                DataOut.bufferPut(receivedData_0[receivedData_0_posOut + k]);
                DataOut.bufferPut(receivedData_1[receivedData_1_posOut + k]);
            }
        }


        receivedData_0_posOut = receivedData_0_posOut + process;
        receivedData_1_posOut = receivedData_1_posOut + process;
        if (receivedData_0_posIn == receivedDataSize_0) receivedData_0_posIn = 0;
        if (receivedData_1_posIn == receivedDataSize_1) receivedData_1_posIn = 0;

        if (sindromeMatch) sindromeMatch = false;
    }

    ready = DataOut.ready();
    space = outputSignals[0]->space();
    process = std::min(ready, space);
    alive = !alive ? process > 0: alive;
    totalNumberOfOutputBits += process;
    for (; process--;)
        outputSignals[0]->bufferPut(DataOut.bufferGet());
    
    ready = SindromeOut.ready();
    space = outputSignals[1]->space();
    process = std::min(ready, space);
    alive = !alive ? process > 0: alive;
    for (; process--;)
        outputSignals[1]->bufferPut(SindromeOut.bufferGet());

    ready = SindromeIn.ready();
    process = std::min(ready, receivedSindromeSize - receivedSindrome_posIn);
    alive = !alive ? process > 0: alive;
    for (auto k = receivedSindrome_posIn; k < receivedSindrome_posIn + process; k++)
        receivedSindrome(k, 0) = SindromeIn.bufferGet();

    receivedSindrome_posIn += process;
    if (process > 0 && receivedSindrome_posIn == receivedSindromeSize)
    {
        if (getVerboseMode())
        {
            std::ofstream file;
            file.open("/received_sindrome_tx.txt", std::ios_base::app);
            for (auto k = 0; k < receivedSindromeSize; k++)
                file << std::to_string(receivedSindrome[k]);
            file.close();
        }
        receivedSindrome_newData = true;
    }
    
    ready = DataIn.ready();
    process = std::min(ready, (*pt_receivedDataSize) - (*pt_receivedData_posIn));
    alive = !alive ? process > 0: alive;
    for (auto k = *pt_receivedData_posIn; k < *pt_receivedData_posIn + process; k++)
    {
        if (numberOfDummyBitsPerBitFillingPeriod)
        {
            if (*pt_inDataBitFillingCounter >= numberOfDataBitsPerBitFillingPeriod)
            {
                (*pt_receivedData)[k] = 0;
            }
            else
                (*pt_receivedData)[k] = DataIn.bufferGet();

            *pt_inDataBitFillingCounter = ++(*pt_inDataBitFillingCounter) % bitFillingPeriod;
        }
        else
            (*pt_receivedData)[k] = DataIn.bufferGet();
    }

    *pt_receivedData_posIn += process;
    if (process > 0 && *pt_receivedData_posIn == *pt_receivedDataSize)
        *pt_receivedData_newData = true;
    
    return alive;
}

t_bool CvQokdLdpcTxSindromeReconciliation::errorCorrectionLDPCAlgorithm(Eigen::Matrix<t_binary, Eigen::Dynamic, 1>* pt_calculatedSindrome, Eigen::Matrix<t_binary, Eigen::Dynamic, 1>* pt_receivedData)
{

    for (int k = 0; k < codeLength; ++k)
    {
        if ((*pt_receivedData)[k] == 0)
            prioriMessageProbabilities[k] = log((1 - p_f) / p_f);
        else
            prioriMessageProbabilities[k] = log(p_f / (1 - p_f));
    }

    for (int k = 0; k < sparseParityCheckMatrix.outerSize(); ++k)   // iterates over the columns
    {
        for (Eigen::SparseMatrix<t_binary>::InnerIterator h(sparseParityCheckMatrix, k); h; ++h)  //iterates over the non-zero elements of each column
        {
            tripletList.push_back(T((int)h.row(), k, prioriMessageProbabilities[k]));
        }
    }

    M.setFromTriplets(tripletList.begin(), tripletList.end());
    tripletList.resize(0);

    auto sindromeNoMatch{ 0 };
    for (auto m = 0; m < ldpcErrorCorrectionAlgorithMaxIterations; ++m) 
    {
        for (int k = 0; k < sparseParityCheckMatrixTranspose.outerSize(); ++k)   // iterates over the columns of H^T, i.e. the lines of H
        {
            for (Eigen::SparseMatrix<t_binary>::InnerIterator h(sparseParityCheckMatrixTranspose, k); h; ++h)  //iterates over the non-zero elements of each column of H^T, i.e. over the non-zero elements of each line of H
            {
                t_real prod{ 1 };
                for (Eigen::SparseMatrix<t_binary>::InnerIterator o(sparseParityCheckMatrixTranspose, k); o; ++o)  //iterates over the non-zero elements of each column of H^T, i.e. over the non-zero elements of each line of H
                {
                    if (o.row() != h.row())
                        prod = prod * tanh(M.coeff(k, (int)o.row()) / 2);
                }
                tripletList.push_back(T(k, (int)h.row(), log(1 + (1 - 2 * (t_real)receivedSindrome[k]) * prod) - log(1 - (1 - 2 * (t_real)receivedSindrome[k]) * prod)));
            }
        }

        E.setFromTriplets(tripletList.begin(), tripletList.end());
        tripletList.resize(0);

        for (int k = 0; k < codeLength; ++k)
        {
            t_real sum{ 0 };
            for (Eigen::SparseMatrix<t_binary>::InnerIterator h(sparseParityCheckMatrix, k); h; ++h)
            {
                sum = sum + E.coeff((int)h.row(), k);
            }
            auto L = sum + prioriMessageProbabilities[k];
            if (L <= 0.0)
                (*pt_receivedData)[k] = 1;
            else
                (*pt_receivedData)[k] = 0;
        }

        *pt_calculatedSindrome = sparseParityCheckMatrix * *pt_receivedData;
        *pt_calculatedSindrome = (*pt_calculatedSindrome).unaryExpr([](const t_binary x) {return x % 2;}); //to compute mod(sindrome,2)

        sindromeNoMatch = 0;
        for (auto k = 0; k < *pt_calculatedSindromeSize; k++)
            if ((*pt_calculatedSindrome)[k] != receivedSindrome[k])
                sindromeNoMatch++;

        if (sindromeNoMatch == 0)
        {
            if (getVerboseMode())
            {
                std::ofstream file;
                file.open( getSignalsFolderName() + "/new_sindrome_tx.txt", std::ios_base::app);
                if (file.is_open())
                {
                    for (auto k = 0; k < *pt_calculatedSindromeSize; k++)
                        file << std::to_string((*pt_calculatedSindrome)[k]);
                    file << std::endl;
                    file.close();
                }
                else
                    std::cerr << "DV_QKD_LDPC_TX_Error_Correction: Error opening file";
            }
            break;
        }

        for (int k = 0; k < sparseParityCheckMatrix.outerSize(); ++k)   // iterates over the columns of H
        {
            for (Eigen::SparseMatrix<t_binary>::InnerIterator h(sparseParityCheckMatrix, k); h; ++h)  //iterates over the non-zero elements of each column of H
            {
                t_real sum{ 0 };
                for (Eigen::SparseMatrix<t_binary>::InnerIterator o(sparseParityCheckMatrix, k); o; ++o)  //iterates over the non-zero elements of each column of H^T, i.e. over the non-zero elements of each line of H
                {
                    if (o.row() != h.row())
                        sum = sum + E.coeff((int)o.row(), k);
                }
                tripletList.push_back(T((int)h.row(), k, sum + prioriMessageProbabilities[k]));
            }
        }
        M.setFromTriplets(tripletList.begin(), tripletList.end());
        tripletList.resize(0);
    }

    if (sindromeNoMatch > 0)
        return false;
    else
        return true;
}

void CvQokdLdpcTxSindromeReconciliation::loadSparseParityCheckMatrix()
{
    auto pos_a = parityCheckMatrixFileName.find("_n");
    auto pos_b = parityCheckMatrixFileName.find("_k");
    codeLength = stoi(parityCheckMatrixFileName.substr(pos_a + 2, pos_b - pos_a - 2));

    pos_a = parityCheckMatrixFileName.find("_k");
    pos_b = parityCheckMatrixFileName.find("_nonZeros");
    codeRank = stoi(parityCheckMatrixFileName.substr(pos_a + 2, pos_b - pos_a - 2));

    pos_a = parityCheckMatrixFileName.find("_nonZeros");
    pos_b = parityCheckMatrixFileName.find(".dat");
    numberOfNonZerosValuesInSparseParityCheckMatrix = stoi(parityCheckMatrixFileName.substr(pos_a + 9, pos_b - pos_a - 9));

    sparseParityCheckMatrix.resize(codeLength - codeRank, codeLength);
    sparseParityCheckMatrix.reserve(numberOfNonZerosValuesInSparseParityCheckMatrix);

    if (parityCheckMatrixFileName.substr(parityCheckMatrixFileName.find_last_of(".") + 1) == "txt")
    {
        std::fstream fp;
        fp.open(parityCheckMatrixFolderName + "/" + parityCheckMatrixFileName, std::ios::in);
        if (!fp.is_open()) std::cerr << "Error in dv_qkd_ldpc_error_correction_.cpp: file sparseParityCheckMatrix.txt not found!!!!";
        double data;
        int row{ 0 }, column{ 0 };
        while (true)
        {
            fp >> data;
            if (data != 0)
                sparseParityCheckMatrix.insert(row, column) = (uint8_t)data;
            column++;
            if (column == codeLength)
            {
                column = 0;
                row++;
            }
            if (row == codeLength - codeRank)
                break;
        }
        fp.close();
    } 
    else if (parityCheckMatrixFileName.substr(parityCheckMatrixFileName.find_last_of(".") + 1) == "dat")
    {
        std::ifstream parityCheckMatrixFile(parityCheckMatrixFolderName + "/" + parityCheckMatrixFileName);
        if (!parityCheckMatrixFile.is_open()) std::cerr << "Error in dv_qkd_ldpc_error_correction_.cpp: file parityCheckMatrixFileName not found!!!!";;
        size_t bufferSize = (codeLength - codeRank) * codeLength;
        std::unique_ptr<char[]> buffer(new char[bufferSize]);
        parityCheckMatrixFile.read(buffer.get(), bufferSize);

        int row{ 0 }, column{ 0 };
        uint8_t data{ 0 };
        char* ptr{ &buffer[0] };
        for (auto k = 0; k < bufferSize; ++k)
        {
            data = *ptr - '0';
            if (data != 0)
                sparseParityCheckMatrix.insert(row, column) = (uint8_t)data;
            ptr++;
            column++;
            if (column == codeLength)
            {
                column = 0;
                row++;
            }
        }
    }
    else
    {
        std::cerr << "DVQkdRxErrorCorrectionLDPC::loadSparseParityCheckMatrix() - wrong file extension";
    }

    if (getVerboseMode())
    {
        std::ofstream file;
        file.open(getSignalsFolderName() + "/SparseParityCheckMatrix.txt", std::ios_base::out);
        if (file.is_open())
        {
            file << "Position of no-zero values (row, column)" << std::endl;
            for (int k = 0; k < sparseParityCheckMatrix.outerSize(); ++k)   // iterates over the columns of H
            {
                for (Eigen::SparseMatrix<t_binary>::InnerIterator it(sparseParityCheckMatrix, k); it; ++it)
                    file << "(" << it.row() << ", " << it.col() << ")" << std::endl;
            }
            file.close();
        }
        else
            std::cerr << "Error in dv_qkd_ldpc_rx_error_correction_.cpp: file not open!!!";
    }
    return;
}

Any help is appreciated.

Zeinab Rahmani
  • 77
  • 3
  • 10
  • 1
    Please [read this](https://meta.stackoverflow.com/a/285557/1387438) then copy paste content of your terminal. – Marek R Sep 16 '21 at 10:01
  • 1
    Also static assertion explains problem pretty clearly. – Marek R Sep 16 '21 at 10:03
  • Also, please reduce your problem to a [mre]. – chtz Sep 16 '21 at 12:29
  • @chtz I don't think so it is possible to reproduce it. The project consists of 30 .h and .cpp files that are entangled. – Zeinab Rahmani Sep 16 '21 at 13:53
  • well but `t_binary` is not `unsigned char`... what are actual types of the matrix variables involved? also some line numbers could help, line 186 is `std::ofstream file;` in the code you posted. – numzero Sep 16 '21 at 14:28
  • @numzero In fact, in my project "t_binary" is defined as "unsigned int". About the error line, that's strange, because both "text editor" and "vim" are referring to the lines that I posted! – Zeinab Rahmani Sep 16 '21 at 14:36
  • 2
    I see that it is `unsigned int`, you posted that. But the error message tells you use `Matrix – numzero Sep 16 '21 at 14:42

0 Answers0