void BufferedStreamingGrid::reset (bool read,int minWindowSize) { this->read=read; win=minWindowSize<rows() ? minWindowSize : rows(); FreePointer( data ); data = AllocPointer< byte >( rowSize() * win ); if( !data ) fprintf( stderr , "[ERROR] Failed to allocate memory for BufferedStreamingGrid\n" ) , exit( 0 ); sg->reset( read , 1 ); if( read ) { for(int w=0;w<win;w++) { Pointer( byte ) row = (*sg)[w]; memcpy( data+w*rowSize() , row , rowSize() ); sg->advance(); } } current=0; }
UpperMatrix<T>::UpperMatrix(const ParamMatrix<T>& matrix) { int index = 0; int rowNum = 0; m_rowSize = matrix.rowSize(); m_numRows = matrix.numRows(); m_dataPtr = new T[m_numRows*(m_numRows+1)/2]; for(int i = 0; i < theoSize(); i++) { if(i%rowSize() >= rowNum) { m_dataPtr[index] = matrix[i]; index++; } if(i%rowSize() == rowSize()-1) rowNum++; } }
void BufferedStreamingGrid::advance(void) { if(read) { current++; if(current+win-1<rows()) { sg->advance(); memcpy( data + ((current+win-1)%win)*rowSize() , (*sg)[current+win-1] , rowSize() ); } } else { if(current-win+1>=0) { memcpy( (*sg)[current-win+1] , data+((current-win+1)%win)*rowSize() , rowSize() ); sg->advance(); } current++; } }
Pointer( byte ) BufferedStreamingGrid::operator[] (int idx) { return data+(idx%win)*rowSize(); }