void TestResizeAndCopy() { typedef tbb::concurrent_vector<Foo> vector_t; for( int old_size=0; old_size<=128; NextSize( old_size ) ) { for( int new_size=old_size; new_size<=128; NextSize( new_size ) ) { long count = FooCount; vector_t v; ASSERT( count==FooCount, NULL ); v.grow_by(old_size); ASSERT( count+old_size==FooCount, NULL ); for( int j=0; j<old_size; ++j ) v[j].bar() = j*j; v.grow_to_at_least(new_size); ASSERT( count+new_size==FooCount, NULL ); for( int j=0; j<new_size; ++j ) { int expected = j<old_size ? j*j : Foo::initial_value_of_bar; if( v[j].bar()!=expected ) std::printf("ERROR on line %d for old_size=%ld new_size=%ld v[%ld].bar()=%d != %d\n",__LINE__,long(old_size),long(new_size),long(j),v[j].bar(), expected); } ASSERT( v.size()==size_t(new_size), NULL ); for( int j=0; j<new_size; ++j ) { v[j].bar() = ~j; } const vector_t& cv = v; // Try copy constructor vector_t copy_of_v(cv); CheckVector(cv,new_size,old_size); v.clear(); ASSERT( v.empty(), NULL ); CheckVector(copy_of_v,new_size,old_size); } } }
static int Player_Teleport( lua_State *L ) { luaPlayer_t *player = CheckPlayer( L, 1 ); gentity_t *ent = &g_entities[player->clientNum]; vector3 *pos = CheckVector( L, 2 ); vector3 *angles = CheckVector( L, 3 ); TeleportPlayer( ent, pos, angles ); return 0; }
/*--------------------------------------------------------------------------*/ int sci_xfarcs(char *fname, unsigned long fname_len) { int m1 = 0, n1 = 0, l1 = 0; int m2 = 0, n2 = 0, l2 = 0; long hdl = 0; int i = 0; double angle1 = 0.0; double angle2 = 0.0; CheckRhs(1, 2); GetRhsVar(1, MATRIX_OF_DOUBLE_DATATYPE, &m1, &n1, &l1); if (m1 != 6) { Scierror(999, _("%s: Wrong size for input argument #%d: %s expected.\n"), fname, 1, "(6,n)"); return 0; } if (Rhs == 2) { GetRhsVar(2, MATRIX_OF_INTEGER_DATATYPE, &m2, &n2, &l2); CheckVector(2, m2, n2); if (n1 != m2 * n2) { Scierror(999, _("%s: Wrong size for input arguments #%d and #%d.\n"), fname, 1, 2); return 0; } } else { m2 = 1; n2 = n1; CreateVar(2, MATRIX_OF_INTEGER_DATATYPE, &m2, &n2, &l2); for (i = 0; i < n2; ++i) { *istk(l2 + i) = i + 1; } } getOrCreateDefaultSubwin(); for (i = 0; i < n1; ++i) { angle1 = DEG2RAD(*stk(l1 + (6 * i) + 4) / 64.0); angle2 = DEG2RAD(*stk(l1 + (6 * i) + 5) / 64.0); Objarc(&angle1, &angle2, stk(l1 + (6 * i)), stk(l1 + (6 * i) + 1), stk(l1 + (6 * i) + 2), stk(l1 + (6 * i) + 3), istk(l2 + i), istk(l2 + i), TRUE, FALSE, &hdl); } /** Construct Compound and make it current object **/ setCurrentObject(ConstructCompoundSeq(n1)); LhsVar(1) = 0; PutLhsVar(); return 0; }
static INT CheckVectors (GRID *theGrid) { INT nerr = 0; VECTOR *theVector; for (theVector=PFIRSTVECTOR(theGrid); theVector!=NULL; theVector=SUCCVC(theVector)) { nerr += CheckVector(theGrid,theVector); } return(nerr); }
//! Test of assign, grow, copying with various sizes void TestResizeAndCopy() { typedef static_counting_allocator<debug_allocator<Foo,std::allocator>, std::size_t> allocator_t; typedef tbb::concurrent_vector<Foo, allocator_t> vector_t; allocator_t::init_counters(); for( int old_size=0; old_size<=128; NextSize( old_size ) ) { for( int new_size=0; new_size<=1280; NextSize( new_size ) ) { long count = FooCount; vector_t v; ASSERT( count==FooCount, NULL ); v.assign(old_size/2, Foo() ); ASSERT( count+old_size/2==FooCount, NULL ); for( int j=0; j<old_size/2; ++j ) ASSERT( v[j].state == Foo::CopyInitialized, NULL); v.assign(FooIterator(0), FooIterator(old_size)); v.resize(new_size, Foo(33) ); ASSERT( count+new_size==FooCount, NULL ); for( int j=0; j<new_size; ++j ) { int expected = j<old_size ? j : 33; if( v[j].bar()!=expected ) REPORT("ERROR on line %d for old_size=%ld new_size=%ld v[%ld].bar()=%d != %d\n",__LINE__,long(old_size),long(new_size),long(j),v[j].bar(), expected); } ASSERT( v.size()==size_t(new_size), NULL ); for( int j=0; j<new_size; ++j ) { v[j].bar() = ~j; } const vector_t& cv = v; // Try copy constructor vector_t copy_of_v(cv); CheckVector(cv,new_size,old_size); ASSERT( !(v != copy_of_v), NULL ); v.clear(); ASSERT( v.empty(), NULL ); swap(v, copy_of_v); ASSERT( copy_of_v.empty(), NULL ); CheckVector(v,new_size,old_size); } } ASSERT( allocator_t::items_allocated == allocator_t::items_freed, NULL); ASSERT( allocator_t::allocations == allocator_t::frees, NULL); }
//! Test reserve, compact, capacity void TestCapacity() { typedef static_counting_allocator<debug_allocator<Foo,tbb::cache_aligned_allocator>, std::size_t> allocator_t; typedef tbb::concurrent_vector<Foo, allocator_t> vector_t; allocator_t::init_counters(); for( size_t old_size=0; old_size<=11000; old_size=(old_size<5 ? old_size+1 : 3*old_size) ) { for( size_t new_size=0; new_size<=11000; new_size=(new_size<5 ? new_size+1 : 3*new_size) ) { long count = FooCount; { vector_t v; v.reserve(old_size); ASSERT( v.capacity()>=old_size, NULL ); v.reserve( new_size ); ASSERT( v.capacity()>=old_size, NULL ); ASSERT( v.capacity()>=new_size, NULL ); ASSERT( v.empty(), NULL ); size_t fill_size = 2*new_size; for( size_t i=0; i<fill_size; ++i ) { ASSERT( size_t(FooCount)==count+i, NULL ); #if TBB_DEPRECATED size_t j = v.grow_by(1); #else size_t j = v.grow_by(1) - v.begin(); #endif ASSERT( j==i, NULL ); v[j].bar() = int(~j); } vector_t copy_of_v(v); // should allocate first segment with same size as for shrink_to_fit() if(__TBB_Log2(/*reserved size*/old_size|1) > __TBB_Log2(fill_size|1) ) ASSERT( v.capacity() != copy_of_v.capacity(), NULL ); v.shrink_to_fit(); ASSERT( v.capacity() == copy_of_v.capacity(), NULL ); CheckVector(v, new_size*2, old_size); // check vector correctness ASSERT( v==copy_of_v, NULL ); // TODO: check also segments layout equality } ASSERT( FooCount==count, NULL ); } } ASSERT( allocator_t::items_allocated == allocator_t::items_freed, NULL); ASSERT( allocator_t::allocations == allocator_t::frees, NULL); }
//! Test the assignment operator and swap void TestAssign() { typedef tbb::concurrent_vector<FooWithAssign, local_counting_allocator<std::allocator<FooWithAssign>, size_t > > vector_t; local_counting_allocator<std::allocator<FooWithAssign>, size_t > init_alloc; init_alloc.allocations = 100; for( int dst_size=1; dst_size<=128; NextSize( dst_size ) ) { for( int src_size=2; src_size<=128; NextSize( src_size ) ) { vector_t u(FooIterator(0), FooIterator(src_size), init_alloc); for( int i=0; i<src_size; ++i ) ASSERT( u[i].bar()==i, NULL ); vector_t v(dst_size, FooWithAssign(), init_alloc); for( int i=0; i<dst_size; ++i ) { ASSERT( v[i].state==Foo::CopyInitialized, NULL ); v[i].bar() = ~i; } ASSERT( v != u, NULL); v.swap(u); CheckVector(u, dst_size, src_size); u.swap(v); // using assignment v = u; ASSERT( v == u, NULL); u.clear(); ASSERT( u.size()==0, NULL ); ASSERT( v.size()==size_t(src_size), NULL ); for( int i=0; i<src_size; ++i ) ASSERT( v[i].bar()==i, NULL ); ASSERT( 0 == u.get_allocator().frees, NULL); u.shrink_to_fit(); // deallocate unused memory size_t items_allocated = u.get_allocator().items_allocated, items_freed = u.get_allocator().items_freed; size_t allocations = u.get_allocator().allocations, frees = u.get_allocator().frees + 100; ASSERT( items_allocated == items_freed, NULL); ASSERT( allocations == frees, NULL); } } }
static void Player_SetVelocity( lua_State *L, jpluaEntity_t *ent ) { VectorCopy(CheckVector(L, 3), &ent->client->ps.velocity); }
static void Player_SetPosition( lua_State *L, jpluaEntity_t *ent ) { vector3 *origin = CheckVector(L, 3); VectorCopy(origin, &ent->client->ps.origin); }
static void Player_SetAngles( lua_State *L, jpluaEntity_t *ent ) { const vector3 *vec = CheckVector( L, 3 ); VectorCopy( vec, &ent->client->ps.viewangles ); }
/*--------------------------------------------------------------------------*/ int intsplin3d(char * fname,unsigned long fname_len) { /* * [tlist] = splin3d(x, y, z, v [,orderxyz]) */ static char *Str[] = {"tensbs3d", "tx", "ty", "tz", "order", "bcoef", "xyzminmax"}; int minrhs = 4, maxrhs = 5, minlhs = 1, maxlhs = 1; int mx = 0, nx = 0, lx = 0, my = 0, ny = 0, ly = 0, mz = 0, nz = 0, lz = 0, mo = 0; int no = 0, lo = 0, kx = 0, ky = 0, kz = 0; int ntx = 0, nty = 0, ntz = 0, ltx = 0, lty = 0, ltz = 0, lbcoef = 0, lxyzminmax = 0; int mwk = 0, mwkx = 0, mwky = 0, mwkz = 0; int flag = 0, one = 1, three = 3, six = 6, seven = 7, ltlist = 0, nxyz = 0, lwork = 0; int lar = 0, lorder = 0, *order = NULL; double *x = NULL, *y = NULL, *z = NULL, *xyzminmax = NULL; int i = 0; RealHyperMat V; CheckRhs(minrhs, maxrhs); CheckLhs(minlhs, maxlhs); GetRhsVar(1, MATRIX_OF_DOUBLE_DATATYPE, &mx, &nx, &lx); CheckVector(1, mx, nx); x = stk(lx); GetRhsVar(2,MATRIX_OF_DOUBLE_DATATYPE, &my, &ny, &ly); CheckVector(2, my, ny); y = stk(ly); GetRhsVar(3,MATRIX_OF_DOUBLE_DATATYPE, &mz, &nz, &lz); CheckVector(2, mz, nz); z = stk(lz); for (i = 1; i <= minrhs - 1; i++) { SciErr sciErr; int *piAddressVar = NULL; sciErr = getVarAddressFromPosition(pvApiCtx, i, &piAddressVar); if(sciErr.iErr) { printError(&sciErr, 0); Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, i); return 0; } if (isVarComplex(pvApiCtx, piAddressVar)) { Scierror(202, _("%s: Wrong type for argument #%d: Real matrix expected.\n"), fname, i); return 0; } } nx = mx * nx; ny = my * ny; nz = mz * nz; if (nx < 3 || ny < 3 || nz < 3) { Scierror(999,_("%s: Wrong size for input arguments: x, y and z grids must have at least %d points.\n"), fname, 3); return 0; } GetRhsRealHMat(4, &V); if ( V.dimsize != 3 ) { Scierror(999,_("%s: Wrong size for input argument #%d: A real 3-dimension hypermatrix expected.\n"),fname,4); return 0; } if ( V.dims[0] != nx || V.dims[1] != ny || V.dims[2] != nz ) { Scierror(999,"%s: Wrong value for input argument: Size incompatibility between grid points and grid values.\n", fname); return 0; } if ( Rhs == 5 ) { GetRhsVar(5,MATRIX_OF_DOUBLE_DATATYPE, &mo, &no, &lo); if ( (mo != 1 && no != 1) || mo*no != 3 ) { Scierror(999,_("%s: Wrong value for input argument #%d: Vector with %d components expected.\n"),fname,4,3); return 0; } kx = (int)*stk(lo); ky = (int)*stk(lo+1); kz = (int)*stk(lo+2); if ( kx < 2 || kx >= nx || ky < 2 || ky >= ny || kz < 2 || kz >= nz ) { Scierror(999,_("%s: Wrong values for input argument #%d.\n"), fname, 5); return 0; } } else { kx = 4; ky = 4; kz = 4; } ntx = nx + kx; nty = ny + ky; ntz = nz + kz; mwkx = kx*(nx+1); mwky = ky*(ny+1); mwkz = kz*(nz+1); mwkx = Max(mwkx, mwky); mwk = nx*ny*nz + 2*(Max(mwkx, mwkz)); nxyz = nx*ny*nz; CreateVar(Rhs+1,TYPED_LIST_DATATYPE, &seven, &one, <list); CreateListVarFromPtr(Rhs+1, 1,MATRIX_OF_STRING_DATATYPE, &one, &seven, Str); lar = -1; CreateListVarFrom(Rhs+1, 2,MATRIX_OF_DOUBLE_DATATYPE, &ntx, &one, <x, &lar); lar = -1; CreateListVarFrom(Rhs+1, 3,MATRIX_OF_DOUBLE_DATATYPE, &nty, &one, <y, &lar); lar = -1; CreateListVarFrom(Rhs+1, 4,MATRIX_OF_DOUBLE_DATATYPE, &ntz, &one, <z, &lar); lorder = 4; lar = -1; CreateListVarFrom(Rhs+1, 5,MATRIX_OF_VARIABLE_SIZE_INTEGER_DATATYPE, &three, &one, &lorder, &lar); order = istk(lorder); order[0] = kx; order[1] = ky; order[2] = kz; lar = -1; CreateListVarFrom(Rhs+1, 6,MATRIX_OF_DOUBLE_DATATYPE, &nxyz, &one, &lbcoef, &lar); lar = -1; CreateListVarFrom(Rhs+1, 7,MATRIX_OF_DOUBLE_DATATYPE, &six, &one, &lxyzminmax, &lar); xyzminmax = stk(lxyzminmax); xyzminmax[0] = x[0]; xyzminmax[1] = x[nx - 1]; xyzminmax[2] = y[0]; xyzminmax[3] = y[ny - 1]; xyzminmax[4] = z[0]; xyzminmax[5] = z[nz - 1]; CreateVar(Rhs + 2, MATRIX_OF_DOUBLE_DATATYPE, &mwk, &one, &lwork); flag = 0; C2F(db3ink) ( stk(lx), &nx, stk(ly), &ny, stk(lz), &nz, V.R, &nx, &ny, &kx, &ky, &kz, stk(ltx), stk(lty), stk(ltz), stk(lbcoef), stk(lwork), &flag); if ( flag != 1 ) { Scierror(999, _("%s: Problem with 'flag' = %d\n"), fname, flag); return 0; } /* Return only the tlist */ LhsVar(1) = Rhs+1; PutLhsVar(); return 0; }