Exemple #1
0
// This function if to delete the feature with index in indexList.
void deleteFeature(Mat &dataSet, Row &featureName, vector<int> &indexList) {
    if (dataSet.size() == 0)
        return;
    
    Mat matTemp = dataSet;
    Row featureNameTemp = featureName;
    
    dataSet.clear();
    featureName.clear();
    
    int dataRowSize = (int)matTemp[0].size();
    vector<int> indexIsDelete(dataRowSize);
    
    for (int i = 0; i != dataRowSize; ++i)
        indexIsDelete[i] = 0;
    
    for (auto item : indexList)
        indexIsDelete[item] = 1;
    
    for (auto row : matTemp) {
        Row rowTemp;
        for (int i = 0; i < dataRowSize; ++i) {
            if(indexIsDelete[i] == 0) {
                rowTemp.push_back(row[i]);
            }
        }
        dataSet.push_back(rowTemp);
    }
    
    for (int i = 0; i < featureNameTemp.size(); ++i) {
        if (indexIsDelete[i] == 0)
            featureName.push_back(featureNameTemp[i]);
    }
}
Exemple #2
0
inline void copyDenseArrayToSparseRow(const Ring& R, uint64* arr1, uint64* arr2, const uint32 line_size, Row& v, bool reduce)
{

	//Row tmp;

	v.clear ();
	if(v.size() != 0)
		cout << "EROOOOR\n";
	//if(v.capacity () < 128)
		//v.reserve (128);

	//register uint16 l;
	register typename Ring::Element e1, e2;

	if(reduce)
		for(uint32 j=0; j<DEFAULT_BLOC_WIDTH; ++j)
		{
			//ModularTraits<typename Ring::Element>::reduce (e, arr[j], R._modulus);
			//l = arr[j] >> 16;
			//l = R._modulus - l;

			ModularTraits<typename Ring::Element>::reduce (e1, arr1[j], R._modulus);
			ModularTraits<typename Ring::Element>::reduce (e2, arr2[j], R._modulus);

			if ((!R.isZero(e1)) || (!R.isZero(e2)))
			{
				v.IndexData.push_back (j); // (typename SparseBloc<typename Ring::Element>::Row::value_type (j, e));
				v.ValuesData.push_back (e1);
				v.ValuesData.push_back (e2);
			}
		}
	else
		for(uint32 j=0; j<DEFAULT_BLOC_WIDTH; ++j)
		{
			if (arr1[j] != 0 || arr2[j] != 0)
			{
				v.IndexData.push_back (j); // (typename SparseBloc<typename Ring::Element>::Row::value_type (j, e));
				v.ValuesData.push_back (arr1[j]);
				v.ValuesData.push_back (arr2[j]);
			}
		}

	//v.swap(tmp);
}
Exemple #3
0
void OsiIF::_row(int i, Row &r) const
{
	const CoinPackedMatrix* coinMatrix;
	CoinPackedVector coinVector;
	int coinNumEl;
	const int* coinIndices;
	const double* coinElements;

	coinMatrix = osiLP_->getMatrixByRow();
	coinVector = coinMatrix->getVector(i);
	coinNumEl = coinVector.getNumElements();
	coinIndices = coinVector.getIndices();
	coinElements = coinVector.getElements();

	r.clear();

	for (int j = 0; j < coinNumEl; j++)
		r.insert(coinIndices[j], coinElements[j]);
	r.sense(osi2csense(rowsense_[i]));
	r.rhs(_rhs(i));
}
Exemple #4
0
FileCSV::ReadResult FileCSV::readRow(Row &row)
{
    row.clear();
    if (!isOpen() || m_file.eof())
        return rrEmpty;

    ReadResult rr;
    while (true)
    {
        GVariant value;
        rr = readValue(value);
        if (rr == rrEmpty)
            break;
        row.push_back(value);
        if (rr == rrEOL)
            break;
    }

    if (rr != rrEmpty && m_lineNo++ > 0 && row.size() != m_header.size())
        return rrInvalidSize;
    return rr == rrEmpty ? rrEmpty : rrOK;
}
Exemple #5
0
SparseMatrix& SparseMatrix::transposition() {
    Table& t = *(new Table(size));
    Row r;
    bool null;
    size_t first_num;
    real crnt;

    for (size_t i = 0; i < size; ++i) {
        first_num = 0;
        null = true;
        for (size_t j = i; j < size; ++j) {
            crnt = (*this)(i,j);
            if (!null)
                r.push_back(crnt);
            else {
                if (crnt == 0)
                    ++first_num;
                else {
                    null = false;
                    if (first_num == 1) {
                        r.push_back(0);
                        first_num = 0;
                    }
                    else
                        if (first_num == 2) {
                            r.push_back(0);
                            r.push_back(0);
                            first_num = 0;
                        }
                    r.push_back(crnt);
                }
            }
        }
        SparseArray* t_i = new SparseArray(r, first_num);
        t[i] = t_i;
        r.clear();
    }
    return *(new SparseMatrix(t));
}