📄 vlastreams.cc
字号:
verify_ap_stream(LAStrideStreamIn(str,range,LAS::beg), incr*stride+pattern,2*incr*stride+pattern,incr*stride); assert( str.bof() ); verify_ap_stream(LAStrideStreamIn(str,range,LAS::end), (nsteps-1)*incr*stride+pattern, nsteps*incr*stride+pattern,incr*stride); str.ignore(1); if( !str.eof() ) verify_ap_stream(LAStrideStreamIn(str,range,LAS::cur), pattern+2*incr*stride,3*incr*stride+pattern,incr*stride); } { LAStrideStreamIn str(v,stride); IRange range(-2,-2); cout << "\tchecking subranging of an LAStrideStreamIn by " << range << endl; assert( range.q_proper() ); assert( !range.q_empty() ); str.ignore(3); if( !str.eof() ) verify_ap_stream(LAStrideStreamIn(str,range,LAS::cur), pattern+incr*stride,2*incr*stride+pattern,incr*stride); } { LAStrideStreamIn str(v,stride); IRange range(1,0); cout << "\tchecking subranging of an LAStrideStreamIn by " << range << endl; assert( !range.q_proper() ); assert( range.q_empty() ); if( nsteps > 1 ) verify_ap_stream(LAStrideStreamIn(str,range,LAS::beg), pattern,pattern,incr*stride); assert( str.bof() ); verify_ap_stream(LAStrideStreamIn(str,range,LAS::end), (nsteps-1)*incr*stride+pattern, nsteps*incr*stride+pattern,incr*stride); if( nsteps > 2 ) str.ignore(nsteps-2), verify_ap_stream(LAStrideStreamIn(str,range,LAS::cur), pattern,pattern,incr*stride); } if( nsteps > 2 ) { Vector v1 = v; assert( v1 == v ); IRange range(1,2); cout << "\tchecking modifying via a subranged LAStrideStreamOut by " << range << endl; assert( range.q_proper() ); assert( !range.q_empty() ); LAStrideStreamOut str1(v1,stride); LAStrideStreamOut str2(str1,range,LAS::beg); str2.get() += 1; str2.get() += 1; assert( str2.eof() ); verify_ap_stream(LAStrideStreamIn(str1,range), pattern+incr*stride+1,3*incr*stride+1+pattern,incr*stride); v1(v1.q_lwb()+stride) -= 1; v1(v1.q_lwb()+2*stride) -= 1; assert( v1 == v ); verify_ap_stream(str1, pattern,nsteps*incr*stride+pattern,incr*stride); } cout << "\nDone\n";} // Make sure the stream represents a _2D_ Arithmetic Progression // seed + i*incr_small + j*incr_big, // i=0..(nrows-1), j=0..(ncols-1)static void verify_ap_stream(AREALBlockStreamIn& stream, const DimSpec dims, const double seed, const double incr_small, const double incr_big){ double col_val = seed; for(register int j=0; j<dims.q_ncols(); j++, col_val += incr_big) { double row_val = col_val; for(register int i=0; i<dims.q_nrows(); i++, row_val += incr_small) { if( stream.eof() ) _error("Unexpected stream EOF at (%d,%d)\n",i,j); const REAL stream_val = stream.get(); if( abs(stream_val - row_val) >= FLT_EPSILON ) _error("verify_ap_stream: a value taken from the stream %g is different " "from the expected %g, at (%d,%d)\n", stream_val,row_val,i,j); } } if( !stream.eof() ) _error("The stream was supposed to end after (%d,%d)", dims.q_nrows(),dims.q_ncols());}static void test_LABlockStreams(const int nrows, const int ncols){ const double pattern = 4.25; const double incr = 0.5; Matrix m(2,nrows+1,0,ncols-1); cout << "\n---> Test LABlockStreams for " << static_cast<DimSpec&>(m) << endl; { cout << "\tFilling out the matrix in the natural order..." << endl; LAStreamOut str(m); for( double val = pattern; !str.eof(); val += incr ) str.get() = val; } { cout << "\tchecking accessing of the whole matrix as a block stream..." << endl; LABlockStreamIn str(m,IRange::from(-IRange::INF), IRange::from(-IRange::INF)); //str.dump(cerr); assert( str.peek() == pattern ); verify_ap_stream(str,m,pattern,incr,incr*nrows); assert( str.eof() ); str.rewind(); assert( str.bof() && !str.eof() ); verify_ap_stream(str,m,pattern,incr,incr*nrows); str.seek(0,LAS::beg); for(register int i=0; i<m.q_nrows(); i++) str.get(); AREALMark mark = str.tell(); verify_ap_stream(str,DimSpec(m.q_nrows(),m.q_ncols()-1), pattern+incr*nrows,incr,incr*nrows); str.seek(mark); verify_ap_stream(str,DimSpec(m.q_nrows(),m.q_ncols()-1), pattern+incr*nrows,incr,incr*nrows); str.seek(m.q_nrows(),LAS::beg); AREALMark mark1 = str.tell_prev(); str.get(); str.seek(m.q_nrows()-1); verify_ap_stream(str,DimSpec(m.q_nrows(),m.q_ncols()-2), pattern+2*incr*nrows,incr,incr*nrows); str.seek(mark1); str.get(); verify_ap_stream(str,DimSpec(m.q_nrows(),m.q_ncols()-1), pattern+incr*nrows,incr,incr*nrows); str.seek(m.q_nrows() * (m.q_ncols() - 3),LAS::end); verify_ap_stream(str,DimSpec(m.q_nrows(),m.q_ncols()-3), pattern+3*incr*nrows,incr,incr*nrows); } { cout << "\tchecking modifying the whole matrix as a block stream..." << endl; Matrix m1 = m; LABlockStreamOut str(m1,IRange::from(-IRange::INF), IRange::from(-IRange::INF)); //str.dump(cerr); assert( str.get() == pattern ); AREALMark bos = str.tell_prev(); str.seek(nrows*ncols); assert( str.eof() ); str.seek(nrows*ncols-1,LAS::beg); assert( abs(str.get() - (pattern + incr*(nrows*ncols-1))) <= FLT_EPSILON ); assert( str.eof() ); str.seek(bos); assert( str.bof() ); verify_ap_stream(str,m,pattern,incr,incr*nrows); str.rewind(); while( !str.eof() ) str.get() -= 1; str.rewind(); verify_ap_stream(str,m,pattern-1,incr,incr*nrows); str.rewind(); while( !str.eof() ) str.peek() -= 1, str.ignore(1); str.rewind(); verify_ap_stream(str,m,pattern-2,incr,incr*nrows); to_every(m1) += 2; verify_matrix_identity(m,m1); } { // The first column of m IRange row_range = IRange::through(IRange::INF); IRange col_range = IRange::through(m.q_col_lwb()); cout << "\tchecking LABlockStreams clipped as " << row_range << " x " << col_range << endl; LABlockStreamIn str(m,row_range,col_range); verify_ap_stream(str,DimSpec(nrows,1),pattern,incr,incr*nrows); } { // The second column of m IRange row_range = IRange::from(m.q_row_lwb()); IRange col_range(m.q_col_lwb()+1,m.q_col_lwb()+1); cout << "\tchecking LABlockStreams clipped as " << row_range << " x " << col_range << endl; LABlockStreamIn str(m,row_range,col_range); verify_ap_stream(str,DimSpec(nrows,1),pattern+incr*nrows,incr,incr*nrows); } { // A part of the last column of m IRange row_range(m.q_row_lwb()+1,m.q_row_upb()); IRange col_range = IRange::from(m.q_col_upb()); cout << "\tchecking LABlockStreams clipped as " << row_range << " x " << col_range << endl; LABlockStreamIn str(m,row_range,col_range); verify_ap_stream(str,DimSpec(nrows-1,1), pattern+incr*nrows*(ncols-1)+incr,incr,incr*nrows); } { // The first row of m IRange row_range = IRange::through(m.q_row_lwb()); IRange col_range = IRange::from(m.q_col_lwb()); cout << "\tchecking LABlockStreams clipped as " << row_range << " x " << col_range << endl; LABlockStreamIn str(m,row_range,col_range); verify_ap_stream(str,DimSpec(1,ncols),pattern,incr,incr*nrows); } { // The second row of m IRange row_range(m.q_row_lwb()+1,m.q_row_lwb()+1); IRange col_range = IRange::through(m.q_col_upb()); cout << "\tchecking LABlockStreams clipped as " << row_range << " x " << col_range << endl; LABlockStreamIn str(m,row_range,col_range); verify_ap_stream(str,DimSpec(1,ncols),pattern+incr,incr,incr*nrows); } { // A part of the last row of m IRange row_range = IRange::from(m.q_row_upb()); IRange col_range = IRange::through(m.q_col_upb()-1); cout << "\tchecking LABlockStreams clipped as " << row_range << " x " << col_range << endl; LABlockStreamIn str(m,row_range,col_range); verify_ap_stream(str,DimSpec(1,ncols-1), pattern+(nrows-1)*incr,incr,incr*nrows); } { // The first matrix element IRange row_range(m.q_row_lwb(),m.q_row_lwb()); IRange col_range(m.q_col_lwb(),m.q_col_lwb()); cout << "\tchecking LABlockStreams clipped as " << row_range << " x " << col_range << endl; LABlockStreamIn str(m,row_range,col_range); verify_ap_stream(str,DimSpec(1,1),pattern,incr,incr*nrows); } { // The last matrix element IRange row_range = IRange::from(m.q_row_upb()); IRange col_range = IRange::from(m.q_col_upb()); cout << "\tchecking LABlockStreams clipped as " << row_range << " x " << col_range << endl; LABlockStreamIn str(m,row_range,col_range); verify_ap_stream(str,DimSpec(1,1), pattern+(nrows*ncols-1)*incr,incr,incr*nrows); } { // A 2x3 block at the upper-right corner IRange row_range(m.q_row_lwb()+1,m.q_row_lwb()+2); IRange col_range = IRange::from(m.q_col_upb()-2); cout << "\tchecking LABlockStreams clipped as " << row_range << " x " << col_range << endl; LABlockStreamIn str(m,row_range,col_range); verify_ap_stream(str,DimSpec(2,3), pattern+(ncols-3)*nrows*incr+incr,incr,incr*nrows); } { // A 3x2 block at the lower-left corner IRange row_range(m.q_row_upb()-3,m.q_row_upb()-1); IRange col_range(m.q_col_lwb()+2,m.q_col_lwb()+3); cout << "\tchecking LABlockStreams clipped as " << row_range << " x " << col_range << endl; LABlockStreamIn str(m,row_range,col_range); verify_ap_stream(str,DimSpec(3,2), pattern+2*nrows*incr+(nrows-4)*incr,incr,incr*nrows); } { // Modifying the [2,3] matrix element IRange row_range(m.q_row_lwb()+2,m.q_row_lwb()+2); IRange col_range(m.q_col_lwb()+3,m.q_col_lwb()+3); cout << "\tchecking modifying LABlockStreams clipped as " << row_range << " x " << col_range << endl; Matrix m1 = m; LABlockStreamOut str(m1,row_range,col_range); str.get() += 1; assert( str.eof() ); assert( !( m1 == m ) ); (MatrixColumn(m1,col_range.lwb))(row_range.upb) -= 1; verify_matrix_identity(m,m1); } cout << "\nDone\n";}/* *------------------------------------------------------------------------ * Root module */main(){ cout << "\n\n" << _Minuses << "\n\t\tVerify streams over matrices and vectors\n"; test_LAStreams(11,21); test_LAStrideStreams(10,20,1); test_LAStrideStreams(20,10,2); test_LAStrideStreams(20,11,3); test_LAStrideStreams(20,11,11); test_LAStrideStreams(20,11,20*11); test_subranging(10); test_LAStride_subranging(10,1); test_LAStride_subranging(10,2); test_LAStride_subranging(10,3); test_LAStride_subranging(10,11); test_LABlockStreams(11,21); cout << "\n\nAll test passed" << endl;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -