本文整理匯總了C++中E函數的典型用法代碼示例。如果您正苦於以下問題:C++ E函數的具體用法?C++ E怎麽用?C++ E使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了E函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C++代碼示例。
示例2: GeneratedKey
void GeneratedKey(char *p_fname, char *q_fname, char *e_fname, char *name)
{
BigInt P(p_fname, false), Q(q_fname, false), E(e_fname, false);
BigInt N = P * Q, Fi, FiEl("1"), D("1");
Fi = (P - BigInt("1")) * (Q - BigInt("1"));
int amount = 5761456;
/*std::ifstream num("simpleNum.txt");
amount = Space(num);
num.close();*/
std::ifstream ifst("simpleNum.txt");
if(!ifst)
{
GenetateSimpleList();
ifst.open("simpleNum.txt");
}
int **degree, i;
char *buf_ch = new char[10];
BigInt A = BigInt(&Fi), B, buf_bi;
degree = new int *[2];
for(i = 0; i < 2; i ++)
degree[i] = new int [amount];
memset(degree[0], 0, 4 * amount);
memset(degree[1], 0, 4 * amount);
i = 0;
bool end = true;
while(end)
{
buf_ch = getSimpleNum(ifst);
if((A % BigInt(buf_ch)) == BigInt("0"))
{
A /= BigInt(buf_ch);
degree[0][i] = charToInt(buf_ch);
degree[1][i]++;
i = 0;
ifst.seekg (0, ifst.beg);
}
else
i++;
if(A == BigInt("1"))
end = false;
}
ifst.close();
for(i = 0; i < amount; i++)
{
if(degree[0][i] != 0)
{
A = B = BigInt(intToChar(degree[0][i]));
A ^= BigInt(intToChar(degree[1][i]));
B ^= BigInt(intToChar(degree[1][i] - 1));
buf_bi = A - B;
FiEl *= buf_bi;
}
}
FiEl--;
BigInt DegreeNet[RNet];
DegreeNet[0] = D * E;
DegreeNet[0] %= Fi;
for(i = 1; i < RNet; i++)
{
DegreeNet[i] = DegreeNet[i-1] * DegreeNet[i-1];
DegreeNet[i] %= Fi;
}
BigInt degreeNum[RNet];
degreeNum[0] = BigInt("1");
for(int i = 1; i < RNet; i++)
degreeNum[i] = degreeNum[i-1] * BigInt("2");
BigInt I("0");
for(int j = RNet-1; j >= 0;)
{
if(FiEl >= I + degreeNum[j])
{
D *= DegreeNet[j];
D %= Fi;
I += degreeNum[j];
}
else
j--;
}
char fname[32];
strcpy(fname, name);
strcat(fname, "N.txt");
N.TextWrite(fname);
strcpy(fname, name);
strcat(fname, "D.txt");
D.TextWrite(fname);
};
示例3: E
IGL_INLINE void igl::simplify_polyhedron(
const Eigen::MatrixXd & OV,
const Eigen::MatrixXi & OF,
Eigen::MatrixXd & V,
Eigen::MatrixXi & F,
Eigen::VectorXi & J)
{
// TODO: to generalize to open meshes, 0-cost should keep all incident
// boundary edges on their original lines. (for non-manifold meshes,
// igl::decimate needs to be generalized)
Eigen::MatrixXd N;
// Function for computing cost of collapsing edge (0 if at least one
// direction doesn't change pointset, inf otherwise) and placement (in lowest
// cost direction).
const auto & perfect= [&N](
const int e,
const Eigen::MatrixXd & V,
const Eigen::MatrixXi & F,
const Eigen::MatrixXi & E,
const Eigen::VectorXi & EMAP,
const Eigen::MatrixXi & EF,
const Eigen::MatrixXi & EI,
double & cost,
Eigen::RowVectorXd & p)
{
// Function for ocmputing cost (0 or inf) of collapsing edge by placing
// vertex at `positive` end of edge.
const auto & perfect_directed = [&N](
const int e,
const bool positive,
const Eigen::MatrixXd & V,
const Eigen::MatrixXi & F,
const Eigen::MatrixXi & E,
const Eigen::VectorXi & EMAP,
const Eigen::MatrixXi & EF,
const Eigen::MatrixXi & EI,
double & cost,
Eigen::RowVectorXd & p)
{
const auto vi = E(e,positive);
const auto vj = E(e,!positive);
p = V.row(vj);
std::vector<int> faces = igl::circulation(e,positive,F,E,EMAP,EF,EI);
cost = 0;
for(auto f : faces)
{
// Skip the faces being collapsed
if(f == EF(e,0) || f == EF(e,1))
{
continue;
}
const Eigen::RowVectorXd nbefore = N.row(f);
// Face with vi replaced with vj
const Eigen::RowVector3i fafter(
F(f,0) == vi ? vj : F(f,0),
F(f,1) == vi ? vj : F(f,1),
F(f,2) == vi ? vj : F(f,2));
Eigen::RowVectorXd nafter;
igl::per_face_normals(V,fafter,nafter);
const double epsilon = 1e-10;
// if normal changed then not feasible, break
if((nbefore-nafter).norm() > epsilon)
{
cost = std::numeric_limits<double>::infinity();
break;
}
}
};
p.resize(3);
double cost0, cost1;
Eigen::RowVectorXd p0, p1;
perfect_directed(e,false,V,F,E,EMAP,EF,EI,cost0,p0);
perfect_directed(e,true,V,F,E,EMAP,EF,EI,cost1,p1);
if(cost0 < cost1)
{
cost = cost0;
p = p0;
}else
{
cost = cost1;
p = p1;
}
};
igl::per_face_normals(OV,OF,N);
Eigen::VectorXi I;
igl::decimate(
OV,OF,
perfect,
igl::infinite_cost_stopping_condition(perfect),
V,F,J,I);
}
示例4: main
int main(int argc,char * argv[])
{
int i = 0, j = 0, rc;
MDB_env *env;
MDB_dbi dbi;
MDB_val key, data;
MDB_txn *txn;
MDB_stat mst;
MDB_cursor *cursor;
int count;
int *values;
char sval[32];
char kval[sizeof(int)];
srandom(time(NULL));
memset(sval, 0, sizeof(sval));
count = (random()%384) + 64;
values = (int *)malloc(count*sizeof(int));
for(i = 0;i<count;i++) {
values[i] = random()%1024;
}
E(mdb_env_create(&env));
E(mdb_env_set_mapsize(env, 10485760));
E(mdb_env_set_maxdbs(env, 4));
E(mdb_env_open(env, "./testdb", MDB_FIXEDMAP|MDB_NOSYNC, 0664));
E(mdb_txn_begin(env, NULL, 0, &txn));
E(mdb_open(txn, "id2", MDB_CREATE|MDB_DUPSORT, &dbi));
key.mv_size = sizeof(int);
key.mv_data = kval;
data.mv_size = sizeof(sval);
data.mv_data = sval;
printf("Adding %d values\n", count);
for (i=0;i<count;i++) {
if (!(i & 0x0f))
sprintf(kval, "%03x", values[i]);
sprintf(sval, "%03x %d foo bar", values[i], values[i]);
if (RES(MDB_KEYEXIST, mdb_put(txn, dbi, &key, &data, MDB_NODUPDATA)))
j++;
}
if (j) printf("%d duplicates skipped\n", j);
E(mdb_txn_commit(txn));
E(mdb_env_stat(env, &mst));
E(mdb_txn_begin(env, NULL, 1, &txn));
E(mdb_cursor_open(txn, dbi, &cursor));
while ((rc = mdb_cursor_get(cursor, &key, &data, MDB_NEXT)) == 0) {
printf("key: %p %.*s, data: %p %.*s\n",
key.mv_data, (int) key.mv_size, (char *) key.mv_data,
data.mv_data, (int) data.mv_size, (char *) data.mv_data);
}
CHECK(rc == MDB_NOTFOUND, "mdb_cursor_get");
mdb_cursor_close(cursor);
mdb_txn_abort(txn);
j=0;
for (i= count - 1; i > -1; i-= (random()%5)) {
j++;
txn=NULL;
E(mdb_txn_begin(env, NULL, 0, &txn));
sprintf(kval, "%03x", values[i & ~0x0f]);
sprintf(sval, "%03x %d foo bar", values[i], values[i]);
key.mv_size = sizeof(int);
key.mv_data = kval;
data.mv_size = sizeof(sval);
data.mv_data = sval;
if (RES(MDB_NOTFOUND, mdb_del(txn, dbi, &key, &data))) {
j--;
mdb_txn_abort(txn);
} else {
E(mdb_txn_commit(txn));
}
}
free(values);
printf("Deleted %d values\n", j);
E(mdb_env_stat(env, &mst));
E(mdb_txn_begin(env, NULL, 1, &txn));
E(mdb_cursor_open(txn, dbi, &cursor));
printf("Cursor next\n");
while ((rc = mdb_cursor_get(cursor, &key, &data, MDB_NEXT)) == 0) {
printf("key: %.*s, data: %.*s\n",
(int) key.mv_size, (char *) key.mv_data,
(int) data.mv_size, (char *) data.mv_data);
}
CHECK(rc == MDB_NOTFOUND, "mdb_cursor_get");
printf("Cursor prev\n");
while ((rc = mdb_cursor_get(cursor, &key, &data, MDB_PREV)) == 0) {
printf("key: %.*s, data: %.*s\n",
(int) key.mv_size, (char *) key.mv_data,
(int) data.mv_size, (char *) data.mv_data);
}
CHECK(rc == MDB_NOTFOUND, "mdb_cursor_get");
mdb_cursor_close(cursor);
//.........這裏部分代碼省略.........
示例5: main
int main() {
union supp *p;
if(! HAS_KIND(p, SAFE_KIND)) E(1);
SUCCESS;
}
示例6: cs_routine
int cs_routine(int fd, sqlite3 *db)
{
sockfd_buf_t *rwbuf = sockfd_list[fd];
if (rwbuf == NULL)
return -1;
if (rwbuf->rbuf.data == NULL)
return -1;
if (rwbuf->wbuf.data == NULL)
return -1;
int n = read(fd, rwbuf->rbuf.data, rwbuf->rbuf.max);
if (n < 0) {
E("%s", strerror(errno));
return -1;
} else if (n == 0) {
sockfd_buf_free(rwbuf);
sockfd_list[fd] = NULL;
unregister_readfd(fd);
unregister_writefd(fd);
unregister_exceptfd(fd);
close(fd);
D(GREEN"close %d client success."NO, fd);
return 0;
}
D(GREEN"receive %s %d bytes from %d."NO,
rwbuf->rbuf.data, n, fd);
rwbuf->rbuf.len = n;
DDBUF(rwbuf->rbuf);
rwbuf->rbuf.len -= 4;
strncpy(rwbuf->rbuf.data, rwbuf->rbuf.data + 4, rwbuf->rbuf.len);
DDSTR(rwbuf->rbuf);
n = sql_routine(fd, db, rwbuf);
if (n == -1) {
E("sql_routine() failed.");
if (rwbuf->wbuf.len == 0) {
strncpy(rwbuf->wbuf.data, "err", 3);
rwbuf->wbuf.len = 3;
}
//return -1;
}
D(GREEN"send %s %d bytes to %d."NO,
rwbuf->wbuf.data, rwbuf->wbuf.len, fd);
//rwbuf->wbuf.data[0] = '\0';
//rwbuf->wbuf.data[1] = '\0';
//rwbuf->wbuf.data[2] = '\0';
//rwbuf->wbuf.data[3] = 8;
//DDBUF(rwbuf->wbuf);
n = write(fd, rwbuf->wbuf.data, rwbuf->wbuf.len);
if (n == -1) {
E("%s", strerror(errno));
return -1;
}
memset(rwbuf->wbuf.data, 0, rwbuf->wbuf.max);
rwbuf->wbuf.len = 0;
memset(rwbuf->rbuf.data, 0, rwbuf->rbuf.max);
rwbuf->rbuf.len = 0;
return 0;
}
示例7: register_stack_extend
static void
register_stack_extend(rb_context_t *cont, VALUE *curr_bsp)
{
if (rb_dummy_false) {
/* use registers as much as possible */
E(a) = E(b) = E(c) = E(d) = E(e) =
E(f) = E(g) = E(h) = E(i) = E(j) =
E(k) = E(l) = E(m) = E(n) = E(o) =
E(p) = E(q) = E(r) = E(s) = E(t) = 0;
E(a) = E(b) = E(c) = E(d) = E(e) =
E(f) = E(g) = E(h) = E(i) = E(j) =
E(k) = E(l) = E(m) = E(n) = E(o) =
E(p) = E(q) = E(r) = E(s) = E(t) = 0;
}
if (curr_bsp < cont->machine_register_stack_src+cont->machine_register_stack_size) {
register_stack_extend(cont, (VALUE*)rb_ia64_bsp());
}
cont_restore_1(cont);
}
示例8: Real
inline void ALM
( const AbstractDistMatrix<F>& MPre,
AbstractDistMatrix<F>& LPre, AbstractDistMatrix<F>& SPre,
const RPCACtrl<Base<F>>& ctrl )
{
auto MPtr = ReadProxy<F,MC,MR>( &MPre ); auto& M = *MPtr;
auto LPtr = WriteProxy<F,MC,MR>( &LPre ); auto& L = *LPtr;
auto SPtr = WriteProxy<F,MC,MR>( &SPre ); auto& S = *SPtr;
typedef Base<F> Real;
const Int m = M.Height();
const Int n = M.Width();
const Int commRank = mpi::Rank( M.Grid().Comm() );
// If tau is unspecified, set it to 1/sqrt(max(m,n))
const Base<F> tau =
( ctrl.tau <= Real(0) ? Real(1) / sqrt(Real(Max(m,n))) : ctrl.tau );
if( ctrl.tol <= Real(0) )
LogicError("tol cannot be non-positive");
const Base<F> tol = ctrl.tol;
const double startTime = mpi::Time();
DistMatrix<F> Y( M );
NormalizeEntries( Y );
const Real twoNorm = TwoNorm( Y );
const Real maxNorm = MaxNorm( Y );
const Real infNorm = maxNorm / tau;
const Real dualNorm = Max( twoNorm, infNorm );
Scale( F(1)/dualNorm, Y );
// If beta is unspecified, set it to 1 / 2 || sign(M) ||_2
Base<F> beta =
( ctrl.beta <= Real(0) ? Real(1) / (2*twoNorm) : ctrl.beta );
const Real frobM = FrobeniusNorm( M );
const Real maxM = MaxNorm( M );
if( ctrl.progress && commRank == 0 )
cout << "|| M ||_F = " << frobM << "\n"
<< "|| M ||_max = " << maxM << endl;
Zeros( L, m, n );
Zeros( S, m, n );
Int numIts=0, numPrimalIts=0;
DistMatrix<F> LLast( M.Grid() ), SLast( M.Grid() ), E( M.Grid() );
while( true )
{
++numIts;
Int rank, numNonzeros;
while( true )
{
++numPrimalIts;
LLast = L;
SLast = S;
// ST_{tau/beta}(M - L + Y/beta)
S = M;
Axpy( F(-1), L, S );
Axpy( F(1)/beta, Y, S );
SoftThreshold( S, tau/beta );
numNonzeros = ZeroNorm( S );
// SVT_{1/beta}(M - S + Y/beta)
L = M;
Axpy( F(-1), S, L );
Axpy( F(1)/beta, Y, L );
if( ctrl.usePivQR )
rank = SVT( L, Real(1)/beta, ctrl.numPivSteps );
else
rank = SVT( L, Real(1)/beta );
Axpy( F(-1), L, LLast );
Axpy( F(-1), S, SLast );
const Real frobLDiff = FrobeniusNorm( LLast );
const Real frobSDiff = FrobeniusNorm( SLast );
if( frobLDiff/frobM < tol && frobSDiff/frobM < tol )
{
if( ctrl.progress && commRank == 0 )
cout << "Primal loop converged: "
<< mpi::Time()-startTime << " total secs" << endl;
break;
}
else
{
if( ctrl.progress && commRank == 0 )
cout << " " << numPrimalIts
<< ": \n"
<< " || Delta L ||_F / || M ||_F = "
<< frobLDiff/frobM << "\n"
<< " || Delta S ||_F / || M ||_F = "
<< frobSDiff/frobM << "\n"
<< " rank=" << rank
<< ", numNonzeros=" << numNonzeros
<< ", " << mpi::Time()-startTime << " total secs"
<< endl;
}
//.........這裏部分代碼省略.........
示例9: main
int main()
{
int i ;
/* Flush Cache*/
A(0x90A4001C);
W(0x00000001);
/* Data memory addressing mode (0: not interleaved 1: interleaved) */
A(0x90A80008);
W(0x00000000);
/* Data memory access priority (0: Core>BIU>CFU 1: BIU>Core>CFU) */
A(0x90A8000C);
W(0x00000000);
/* Base Address */
A(0x90A80004);
W(0x90A00000);
/* DBGISR */
A(0x90A0001C);
W(0x10000000);
/* EXCISR */
A(0x90A00020);
W(0x10000000);
/* FIQISR */
A(0x90A00024);
W(0x10000000);
/* IRQISR */
A(0x90A00028);
W(0x10000000);
/* Start address to PSCU */
A(0x90A00000);
W(0x10000000);
/* Start Address to ICache */
A(0x90A40008);
W(0x10000000);
/* Initial program size to ICache */
A(0x90A4000C);
W(0x00000B6C); /* Size x 1024bits */
/* Miss program size to ICache */
A(0x90A40018);
W(0x00000003); /* Size x 1024bits */
/* Configure ICache size*/
A(0x90A40000);
W(0x00000000);
/* Configure ICache to cahce/scratch pad mode*/
A(0x90A40004);
W(0x00000000);
/* Start ICache initialization*/
A(0x90A40010);
W(0x00000000);
/* Start the program operation */
A(0x90A00004);
W(0x00000001);
/* Control vector (two address vector followed by one read/write vector) */
/* WAIT = {Bit[11]} */
/* HPROT = {Bit[10:9], Bit[6:5]} */
/* HLOCK = {Bit[4]} */
/* HsizeGen = {Bit[3:2]} */
A(0xC0000000);
for (i = 0; i <= 2000; i++)
R(0x00000000,All_Mask);
A(0x25000100); W(0x00000000);
A(0x25000104); W(0x00000000);
A(0x25000108); W(0x00000000);
A(0x2500010C); W(0x00000000);
/* Result check */
/* Store */
A(0x25000100); R(0x30201000,0xFFFFFFFF);
A(0x25000104); R(0x70605040,0xFFFFFFFF);
A(0x25000108); R(0xB0A09080,0xFFFFFFFF);
A(0x2500010C); R(0xF0E0D0C0,0xFFFFFFFF);
E();
return 0;
}
示例10: main
//.........這裏部分代碼省略.........
A(0x25000218); W(0x14141414);
A(0x2500021c); W(0x14141414);
A(0x25000220); W(0x00000014);
/* parameters setting */
A(0x25000228); W(0x00020300);
A(0x2500022c); W(0xffff0300);
A(0x25000230); W(0x02000210);
A(0x25000234); W(0x00000000);
/* =================== */
/* End of initial DATA */
/* compare result */
/* Keep reading CBUSY for delaying the result check */
int i;
A(0x24050008);
for (i = 0; i <= 300; i++)
R(0x00000000,All_Mask);
/* OutYReconstructed */
A(0x25000300); R(0x0f0f0f0f,NO_Mask);
A(0x25000304); R(0x0f0f0f0f,NO_Mask);
A(0x25000308); R(0x0f0f0f0f,NO_Mask);
A(0x2500030c); R(0x0f0f0f0f,NO_Mask);
A(0x25000310); R(0x0f0f0f0f,NO_Mask);
A(0x25000314); R(0x0f0f0f0f,NO_Mask);
A(0x25000318); R(0x0f0f0f0f,NO_Mask);
A(0x2500031c); R(0x0f0f0f0f,NO_Mask);
A(0x25000320); R(0x0f0f0f0f,NO_Mask);
A(0x25000324); R(0x0f0f0f0f,NO_Mask);
A(0x25000328); R(0x0f0f0f0f,NO_Mask);
A(0x2500032c); R(0x0f0f0f0f,NO_Mask);
A(0x25000330); R(0x0f0f0f0f,NO_Mask);
A(0x25000334); R(0x0f0f0f0f,NO_Mask);
A(0x25000338); R(0x0f0f0f0f,NO_Mask);
A(0x2500033c); R(0x0f0f0f0f,NO_Mask);
A(0x25000340); R(0x0f0f0f0f,NO_Mask);
A(0x25000344); R(0x0f0f0f0f,NO_Mask);
A(0x25000348); R(0x0f0f0f0f,NO_Mask);
A(0x2500034c); R(0x0f0f0f0f,NO_Mask);
A(0x25000350); R(0x0f0f0f0f,NO_Mask);
A(0x25000354); R(0x0f0f0f0f,NO_Mask);
A(0x25000358); R(0x0f0f0f0f,NO_Mask);
A(0x2500035c); R(0x0f0f0f0f,NO_Mask);
A(0x25000360); R(0x0f0f0f0f,NO_Mask);
A(0x25000364); R(0x0f0f0f0f,NO_Mask);
A(0x25000368); R(0x0f0f0f0f,NO_Mask);
A(0x2500036c); R(0x0f0f0f0f,NO_Mask);
A(0x25000370); R(0x0f0f0f0f,NO_Mask);
A(0x25000374); R(0x0f0f0f0f,NO_Mask);
A(0x25000378); R(0x0f0f0f0f,NO_Mask);
A(0x2500037c); R(0x0f0f0f0f,NO_Mask);
A(0x25000380); R(0x0f0f0f0f,NO_Mask);
A(0x25000384); R(0x0f0f0f0f,NO_Mask);
A(0x25000388); R(0x0f0f0f0f,NO_Mask);
A(0x2500038c); R(0x0f0f0f0f,NO_Mask);
A(0x25000390); R(0x0f0f0f0f,NO_Mask);
A(0x25000394); R(0x0f0f0f0f,NO_Mask);
A(0x25000398); R(0x0f0f0f0f,NO_Mask);
A(0x2500039c); R(0x0f0f0f0f,NO_Mask);
A(0x250003a0); R(0x0f0f0f0f,NO_Mask);
A(0x250003a4); R(0x0f0f0f0f,NO_Mask);
A(0x250003a8); R(0x0f0f0f0f,NO_Mask);
A(0x250003ac); R(0x0f0f0f0f,NO_Mask);
A(0x250003b0); R(0x0f0f0f0f,NO_Mask);
A(0x250003b4); R(0x0f0f0f0f,NO_Mask);
A(0x250003b8); R(0x0f0f0f0f,NO_Mask);
A(0x250003bc); R(0x0f0f0f0f,NO_Mask);
A(0x250003c0); R(0x0f0f0f0f,NO_Mask);
A(0x250003c4); R(0x0f0f0f0f,NO_Mask);
A(0x250003c8); R(0x0f0f0f0f,NO_Mask);
A(0x250003cc); R(0x0f0f0f0f,NO_Mask);
A(0x250003d0); R(0x0f0f0f0f,NO_Mask);
A(0x250003d4); R(0x0f0f0f0f,NO_Mask);
A(0x250003d8); R(0x0f0f0f0f,NO_Mask);
A(0x250003dc); R(0x0f0f0f0f,NO_Mask);
A(0x250003e0); R(0x0f0f0f0f,NO_Mask);
A(0x250003e4); R(0x0f0f0f0f,NO_Mask);
A(0x250003e8); R(0x0f0f0f0f,NO_Mask);
A(0x250003ec); R(0x0f0f0f0f,NO_Mask);
A(0x250003f0); R(0x0f0f0f0f,NO_Mask);
A(0x250003f4); R(0x0f0f0f0f,NO_Mask);
A(0x250003f8); R(0x0f0f0f0f,NO_Mask);
A(0x250003fc); R(0x0f0f0f0f,NO_Mask);
E();
return 0;
}
示例11: main
int main(int argc,char * argv[])
{
int i = 0, j = 0, rc;
MDB_env *env;
MDB_dbi dbi;
MDB_val key, data;
MDB_txn *txn;
MDB_stat mst;
MDB_cursor *cursor, *cur2;
MDB_cursor_op op;
int count;
int *values;
char sval[32] = "";
srand(time(NULL));
count = (rand()%384) + 64;
values = (int *)malloc(count*sizeof(int));
for(i = 0;i<count;i++) {
values[i] = rand()%1024;
}
E(mdb_env_create(&env));
E(mdb_env_set_maxreaders(env, 1));
E(mdb_env_set_mapsize(env, 10485760));
E(mdb_env_open(env, "./testdb", MDB_FIXEDMAP /*|MDB_NOSYNC*/, 0664));
E(mdb_txn_begin(env, NULL, 0, &txn));
E(mdb_dbi_open(txn, NULL, 0, &dbi));
key.mv_size = sizeof(int);
key.mv_data = sval;
printf("Adding %d values\n", count);
for (i=0;i<count;i++) {
sprintf(sval, "%03x %d foo bar", values[i], values[i]);
/* Set <data> in each iteration, since MDB_NOOVERWRITE may modify it */
data.mv_size = sizeof(sval);
data.mv_data = sval;
if (RES(MDB_KEYEXIST, mdb_put(txn, dbi, &key, &data, MDB_NOOVERWRITE))) {
j++;
data.mv_size = sizeof(sval);
data.mv_data = sval;
}
}
if (j) printf("%d duplicates skipped\n", j);
E(mdb_txn_commit(txn));
E(mdb_env_stat(env, &mst));
E(mdb_txn_begin(env, NULL, MDB_RDONLY, &txn));
E(mdb_cursor_open(txn, dbi, &cursor));
while ((rc = mdb_cursor_get(cursor, &key, &data, MDB_NEXT)) == 0) {
printf("key: %p %.*s, data: %p %.*s\n",
key.mv_data, (int) key.mv_size, (char *) key.mv_data,
data.mv_data, (int) data.mv_size, (char *) data.mv_data);
}
CHECK(rc == MDB_NOTFOUND, "mdb_cursor_get");
mdb_cursor_close(cursor);
mdb_txn_abort(txn);
j=0;
key.mv_data = sval;
for (i= count - 1; i > -1; i-= (rand()%5)) {
j++;
txn=NULL;
E(mdb_txn_begin(env, NULL, 0, &txn));
sprintf(sval, "%03x ", values[i]);
if (RES(MDB_NOTFOUND, mdb_del(txn, dbi, &key, NULL))) {
j--;
mdb_txn_abort(txn);
} else {
E(mdb_txn_commit(txn));
}
}
free(values);
printf("Deleted %d values\n", j);
E(mdb_env_stat(env, &mst));
E(mdb_txn_begin(env, NULL, MDB_RDONLY, &txn));
E(mdb_cursor_open(txn, dbi, &cursor));
printf("Cursor next\n");
while ((rc = mdb_cursor_get(cursor, &key, &data, MDB_NEXT)) == 0) {
printf("key: %.*s, data: %.*s\n",
(int) key.mv_size, (char *) key.mv_data,
(int) data.mv_size, (char *) data.mv_data);
}
CHECK(rc == MDB_NOTFOUND, "mdb_cursor_get");
printf("Cursor last\n");
E(mdb_cursor_get(cursor, &key, &data, MDB_LAST));
printf("key: %.*s, data: %.*s\n",
(int) key.mv_size, (char *) key.mv_data,
(int) data.mv_size, (char *) data.mv_data);
printf("Cursor prev\n");
while ((rc = mdb_cursor_get(cursor, &key, &data, MDB_PREV)) == 0) {
printf("key: %.*s, data: %.*s\n",
(int) key.mv_size, (char *) key.mv_data,
(int) data.mv_size, (char *) data.mv_data);
}
CHECK(rc == MDB_NOTFOUND, "mdb_cursor_get");
//.........這裏部分代碼省略.........
示例12: nmod_poly_mat_inv
int
nmod_poly_mat_inv(nmod_poly_mat_t Ainv, nmod_poly_t den,
const nmod_poly_mat_t A)
{
slong n = nmod_poly_mat_nrows(A);
if (n == 0)
{
nmod_poly_one(den);
return 1;
}
else if (n == 1)
{
nmod_poly_set(den, E(A, 0, 0));
nmod_poly_one(E(Ainv, 0, 0));
return !nmod_poly_is_zero(den);
}
else if (n == 2)
{
nmod_poly_mat_det(den, A);
if (nmod_poly_is_zero(den))
{
return 0;
}
else if (Ainv == A)
{
nmod_poly_swap(E(A, 0, 0), E(A, 1, 1));
nmod_poly_neg(E(A, 0, 1), E(A, 0, 1));
nmod_poly_neg(E(A, 1, 0), E(A, 1, 0));
return 1;
}
else
{
nmod_poly_set(E(Ainv, 0, 0), E(A, 1, 1));
nmod_poly_set(E(Ainv, 1, 1), E(A, 0, 0));
nmod_poly_neg(E(Ainv, 0, 1), E(A, 0, 1));
nmod_poly_neg(E(Ainv, 1, 0), E(A, 1, 0));
return 1;
}
}
else
{
nmod_poly_mat_t LU, I;
slong * perm;
int result;
perm = _perm_init(n);
nmod_poly_mat_init_set(LU, A);
result = (nmod_poly_mat_fflu(LU, den, perm, LU, 1) == n);
if (result)
{
nmod_poly_mat_init(I, n, n, nmod_poly_mat_modulus(A));
nmod_poly_mat_one(I);
nmod_poly_mat_solve_fflu_precomp(Ainv, perm, LU, I);
nmod_poly_mat_clear(I);
}
else
nmod_poly_zero(den);
if (_perm_parity(perm, n))
{
nmod_poly_mat_neg(Ainv, Ainv);
nmod_poly_neg(den, den);
}
_perm_clear(perm);
nmod_poly_mat_clear(LU);
return result;
}
}
示例13: TEST_F
/**
* dri2_query_renderer_integer will call queryInteger with the correct DRI2 enum
* for each GLX attribute value.
*
* \note
* This test does \b not perform any checking for invalid GLX attribte values.
* Other unit tests verify that invalid values are filtered before
* dri2_query_renderer_integer is called.
*/
TEST_F(dri2_query_renderer_integer_test, valid_attribute_mapping)
{
struct dri2_screen dsc;
struct attribute_test_vector valid_attributes[] = {
E(GLX_RENDERER_VENDOR_ID_MESA,
__DRI2_RENDERER_VENDOR_ID),
E(GLX_RENDERER_DEVICE_ID_MESA,
__DRI2_RENDERER_DEVICE_ID),
E(GLX_RENDERER_VERSION_MESA,
__DRI2_RENDERER_VERSION),
E(GLX_RENDERER_ACCELERATED_MESA,
__DRI2_RENDERER_ACCELERATED),
E(GLX_RENDERER_VIDEO_MEMORY_MESA,
__DRI2_RENDERER_VIDEO_MEMORY),
E(GLX_RENDERER_UNIFIED_MEMORY_ARCHITECTURE_MESA,
__DRI2_RENDERER_UNIFIED_MEMORY_ARCHITECTURE),
E(GLX_RENDERER_PREFERRED_PROFILE_MESA,
__DRI2_RENDERER_PREFERRED_PROFILE),
E(GLX_RENDERER_OPENGL_CORE_PROFILE_VERSION_MESA,
__DRI2_RENDERER_OPENGL_CORE_PROFILE_VERSION),
E(GLX_RENDERER_OPENGL_COMPATIBILITY_PROFILE_VERSION_MESA,
__DRI2_RENDERER_OPENGL_COMPATIBILITY_PROFILE_VERSION),
E(GLX_RENDERER_OPENGL_ES_PROFILE_VERSION_MESA,
__DRI2_RENDERER_OPENGL_ES_PROFILE_VERSION),
E(GLX_RENDERER_OPENGL_ES2_PROFILE_VERSION_MESA,
__DRI2_RENDERER_OPENGL_ES2_PROFILE_VERSION),
};
memset(&dsc, 0, sizeof(dsc));
dsc.rendererQuery = &rendererQueryExt;
if (setjmp(jmp) == 0) {
for (unsigned i = 0; i < ARRAY_SIZE(valid_attributes); i++) {
unsigned int value = 0xDEADBEEF;
const int success =
dri2_query_renderer_integer(&dsc.base,
valid_attributes[i].glx_attribute,
&value);
EXPECT_EQ(0, success);
EXPECT_EQ(valid_attributes[i].dri_attribute, queryInteger_attribute)
<< valid_attributes[i].glx_string;
EXPECT_EQ((unsigned int) ~valid_attributes[i].dri_attribute, value)
<< valid_attributes[i].glx_string;
}
} else {
EXPECT_FALSE(got_sigsegv);
}
}
示例14: Rosen34
Vector Rosen34(
Fun &F ,
size_t M ,
const Scalar &ti ,
const Scalar &tf ,
const Vector &xi ,
Vector &e )
{
// check numeric type specifications
CheckNumericType<Scalar>();
// check simple vector class specifications
CheckSimpleVector<Scalar, Vector>();
// Parameters for Shampine's Rosenbrock method
// are static to avoid recalculation on each call and
// do not use Vector to avoid possible memory leak
static Scalar a[3] = {
Scalar(0),
Scalar(1),
Scalar(3) / Scalar(5)
};
static Scalar b[2 * 2] = {
Scalar(1),
Scalar(0),
Scalar(24) / Scalar(25),
Scalar(3) / Scalar(25)
};
static Scalar ct[4] = {
Scalar(1) / Scalar(2),
- Scalar(3) / Scalar(2),
Scalar(121) / Scalar(50),
Scalar(29) / Scalar(250)
};
static Scalar cg[3 * 3] = {
- Scalar(4),
Scalar(0),
Scalar(0),
Scalar(186) / Scalar(25),
Scalar(6) / Scalar(5),
Scalar(0),
- Scalar(56) / Scalar(125),
- Scalar(27) / Scalar(125),
- Scalar(1) / Scalar(5)
};
static Scalar d3[3] = {
Scalar(97) / Scalar(108),
Scalar(11) / Scalar(72),
Scalar(25) / Scalar(216)
};
static Scalar d4[4] = {
Scalar(19) / Scalar(18),
Scalar(1) / Scalar(4),
Scalar(25) / Scalar(216),
Scalar(125) / Scalar(216)
};
CppADUsageError(
M >= 1,
"Error in Rosen34: the number of steps is less than one"
);
CppADUsageError(
e.size() == xi.size(),
"Error in Rosen34: size of e not equal to size of xi"
);
size_t i, j, k, l, m; // indices
size_t n = xi.size(); // number of components in X(t)
Scalar ns = Scalar(double(M)); // number of steps as Scalar object
Scalar h = (tf - ti) / ns; // step size
Scalar zero = Scalar(0); // some constants
Scalar one = Scalar(1);
Scalar two = Scalar(2);
// permutation vectors needed for LU factorization routine
CppAD::vector<size_t> ip(n), jp(n);
// initialize e = 0
for(i = 0; i < n; i++)
e[i] = zero;
// vectors used to store values returned by F
Vector E(n * n), Eg(n), f_t(n);
Vector g(n * 3), x3(n), x4(n), xf(n), ftmp(n), xtmp(n);
xf = xi; // initialize solution
for(m = 0; m < M; m++)
{ // time at beginning of this interval
Scalar t = ti * (Scalar(int(M - m)) / ns)
+ tf * (Scalar(int(m)) / ns);
// value of x at beginning of this interval
x3 = x4 = xf;
// evaluate partial derivatives at beginning of this interval
F.Ode_ind(t, xf, f_t);
F.Ode_dep(t, xf, E); // E = f_x
// E = I - f_x * h / 2
for(i = 0; i < n; i++)
{ for(j = 0; j < n; j++)
//.........這裏部分代碼省略.........
示例15: magma_dtile_bulge_applyQ
static void magma_dtile_bulge_applyQ(magma_int_t core_id, char side, magma_int_t n_loc, magma_int_t n, magma_int_t nb, magma_int_t Vblksiz,
double *E, magma_int_t lde, double *V, magma_int_t ldv,
double *TAU, double *T, magma_int_t ldt)//, magma_int_t* info)
{
//%===========================
//% local variables
//%===========================
magma_int_t firstcolj;
magma_int_t bg, rownbm;
magma_int_t st,ed,fst,vlen,vnb,colj;
magma_int_t vpos,tpos;
magma_int_t cur_blksiz,avai_blksiz, ncolinvolvd;
magma_int_t nbgr, colst, coled;
if(n<=0)
return ;
if(n_loc<=0)
return ;
//info = 0;
magma_int_t INFO=0;
magma_int_t nbGblk = magma_ceildiv(n-1, Vblksiz);
/*
* version v1: for each chunck it apply all the V's then move to
* the other chunck. the locality here inside each
* chunck meaning that thread t apply V_k then move
* to V_k+1 which overlap with V_k meaning that the
* E_k+1 overlap with E_k. so here is the
* locality however thread t had to read V_k+1 and
* T_k+1 at each apply. note that all thread if they
* run at same speed they might reading the same V_k
* and T_k at the same time.
* */
magma_int_t nb_loc = 128; //$$$$$$$$
magma_int_t lwork = 2*nb_loc*max(Vblksiz,64);
double *work, *work2;
magma_dmalloc_cpu(&work, lwork);
magma_dmalloc_cpu(&work2, lwork);
magma_int_t nbchunk = magma_ceildiv(n_loc, nb_loc);
/* SIDE LEFT meaning apply E = Q*E = (q_1*q_2*.....*q_n) * E ==> so traverse Vs in reverse order (forward) from q_n to q_1
* each q_i consist of applying V to a block of row E(row_i,:) and applies are overlapped meaning
* that q_i+1 overlap a portion of the E(row_i, :).
* IN parallel E is splitten in vertical block over the threads */
/* SIDE RIGHT meaning apply E = E*Q = E * (q_1*q_2*.....*q_n) ==> so tarverse Vs in normal order (forward) from q_1 to q_n
* each q_i consist of applying V to a block of col E(:, col_i,:) and the applies are overlapped meaning
* that q_i+1 overlap a portion of the E(:, col_i).
* IN parallel E is splitten in horizontal block over the threads */
#ifdef ENABLE_DEBUG
if((core_id==0)||(core_id==1))
printf(" APPLY Q2_cpu dbulge_back_m N %d N_loc %d nbchunk %d NB %d Vblksiz %d SIDE %c \n", n, n_loc, nbchunk, nb, Vblksiz, side);
#endif
for (magma_int_t i = 0; i<nbchunk; i++)
{
magma_int_t ib_loc = min(nb_loc, (n_loc - i*nb_loc));
if(side=='L'){
for (bg = nbGblk; bg>0; bg--)
{
firstcolj = (bg-1)*Vblksiz + 1;
rownbm = magma_ceildiv((n-(firstcolj+1)),nb);
if(bg==nbGblk) rownbm = magma_ceildiv((n-(firstcolj)),nb); // last blk has size=1 used for real to handle A(N,N-1)
for (magma_int_t j = rownbm; j>0; j--)
{
vlen = 0;
vnb = 0;
colj = (bg-1)*Vblksiz; // for k=0;I compute the fst and then can remove it from the loop
fst = (rownbm -j)*nb+colj +1;
for (magma_int_t k=0; k<Vblksiz; k++)
{
colj = (bg-1)*Vblksiz + k;
st = (rownbm -j)*nb+colj +1;
ed = min(st+nb-1,n-1);
if(st>ed)
break;
if((st==ed)&&(colj!=n-2))
break;
vlen=ed-fst+1;
vnb=k+1;
}
colst = (bg-1)*Vblksiz;
magma_bulge_findVTpos(n, nb, Vblksiz, colst, fst, ldv, ldt, &vpos, &tpos);
if((vlen>0)&&(vnb>0)){
lapackf77_dlarfb( "L", "N", "F", "C", &vlen, &ib_loc, &vnb, V(vpos), &ldv, T(tpos), &ldt, E(fst,i*nb_loc), &lde, work, &ib_loc);
}
if(INFO!=0)
printf("ERROR DORMQR INFO %d \n", (int) INFO);
}
}
}else if (side=='R'){
rownbm = magma_ceildiv((n-1),nb);
for (magma_int_t k = 1; k<=rownbm; k++)
//.........這裏部分代碼省略.........