i have two GMatrix, like matrixA, matixB, and want to combine these into one
GMatrix. after the operation, the resulting matrix has the relation name of
matrixA, all the attr and data of both matrixA and matrixB. the function
mergeHoriz(...) doesn`t meet the demand.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
it is very easy to cast GArffRelation into GRelation, it is not clearly but by
type() function to do inversely. i add some code in function mergHoriz() to do
what i want above.
GMatrix*GMatrix::mergeHoriz(GMatrix*pSetA,GMatrix*pSetB){if(pSetA->rows()!=pSetB->rows())ThrowError("Expected same number of rows");GArffRelation*pRel=newGArffRelation();sp_relationspRel;spRel=pRel;GRelation*pRelA=pSetA->relation().get();GRelation*pRelB=pSetB->relation().get();size_tnSetADims=pRelA->size();size_tnSetBDims=pRelB->size();pRel->addAttrs(pRelA);pRel->addAttrs(pRelB);if(pSetA->relation()->type()==GRelation::ARFF){GArffRelation*p=(GArffRelation*)pSetA->relation().get();pRel->setName(p->name());}GMatrix*pNewSet=newGMatrix(spRel);Holder<GMatrix>hNewSet(pNewSet);pNewSet->reserve(pSetA->rows());double*pNewRow;for(size_ti=0;i<pSetA->rows();i++){pNewRow=pNewSet->newRow();GVec::copy(pNewRow,pSetA->row(i),nSetADims);GVec::copy(&pNewRow[nSetADims],pSetB->row(i),nSetBDims);}returnhNewSet.release();}
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
i have two GMatrix, like matrixA, matixB, and want to combine these into one
GMatrix. after the operation, the resulting matrix has the relation name of
matrixA, all the attr and data of both matrixA and matrixB. the function
mergeHoriz(...) doesn`t meet the demand.
matrixA, matixB have the same number of rows
Would this do what you want?
1- use mergeHoriz
2- copy the relation name
Step 2 could be implemented like this:
if(matrixA.relation()->type() == GRelation::ARFF)
{
GArffRelation pRelA = (GArffRelation)matrixA.relation().get();
GArffRelation pRelMerged = (GArffRelation)pMatrixMerged->relation().get();
pRelMerged->setName(pRelA->name());
}
else
ThrowError("the relation of matrixA does not have a name");
(I did not try to compile this, so it may contain bugs.)
thanks for you r help!! it is solved!
it is very easy to cast GArffRelation into GRelation, it is not clearly but by
type() function to do inversely. i add some code in function mergHoriz() to do
what i want above.