//' rcpp_neutral_hotspots //' //' Implements neutral model in two dimensions //' //' @param nbs An \code{spdep} \code{nb} object listing all neighbours of each //' point. //' @param wts Weighting factors for each neighbour; must have same length as //' nbs. //' @param nbsi List of matrices as returned from \code{get_nbsi}. each element //' of which contains the i-th nearest neighbour to each point. //' @param alpha Strength of spatial autocorrelation //' @param sd0 Standard deviation of truncated normal distribution used to model //' environmental variation (with mean of 1) //' @param log_scale If TRUE, raw hotspot values are log-transformed //' @param niters Number of iterations of spatial autocorrelation //' @param ac_type Character string specifying type of aucorrelation //' (\code{moran}, \code{geary}, or code{getis-ord}). //' //' @return A vector of simulated values of same size as \code{nbs}. //' // [[Rcpp::export]] Rcpp::NumericMatrix rcpp_neutral_hotspots (Rcpp::List nbs, Rcpp::List wts, Rcpp::List nbsi, double alpha, double sd0, bool log_scale, int niters, std::string ac_type) { const int size = nbs.size (); int indx; double wtsum, tempd; Rcpp::NumericMatrix tempmat; Rcpp::NumericVector z1 = rcpp_trunc_ndist (size, sd0); Rcpp::NumericVector z2 (size), nbs_to, nbs_from, nbs_n, ac; // Spatial autocorrelation for (int i=0; i<niters; i++) { std::fill (z2.begin (), z2.end (), 0.0); for (int j=0; j<nbsi.size (); j++) { tempmat = Rcpp::as <Rcpp::NumericMatrix> (nbsi (j)); nbs_to = tempmat (Rcpp::_, 0); nbs_from = tempmat (Rcpp::_, 1); nbs_n = tempmat (Rcpp::_, 2); // Note that nbs are 1-indexed for (int k=0; k<nbs_to.size (); k++) { z2 (nbs_to (k) - 1) += ((1.0 - alpha) * z1 (nbs_to (k) - 1) + alpha * z1 (nbs_from (k) - 1)) / (double) nbs_n (k); } } // end for j over nbsi std::copy (z2.begin (), z2.end (), z1.begin ()); } // end for i over niters if (log_scale) { // negative values sometimes arise for alpha < 0, but scale is // arbitrary, so re-scaled here to ensure all values are > 0 z1 = 1.0 + z1 - (double) Rcpp::min (z1); z1 = log10 (z1); } ac = rcpp_ac_stats (z1, nbs, wts, ac_type); std::sort (z1.begin (), z1.end (), std::greater<double> ()); z1 = (z1 - (double) Rcpp::min (z1)) / ((double) Rcpp::max (z1) - (double) Rcpp::min (z1)); Rcpp::NumericMatrix result (size, 2); result (Rcpp::_, 0) = z1; result (Rcpp::_, 1) = ac; Rcpp::colnames (result) = Rcpp::CharacterVector::create ("y", "ac"); return result; }
int main() { Complex z1(4,3); z1.Show(); std::cout << "z1="<< z1 <<std::endl; Complex z2(4,-3); z2.Show(); std::cout << "z2="<< z2 <<std::endl; Complex z3(0,3); z3.Show(); std::cout << "z3="<< z3 <<std::endl; Complex z4(1,0); z4.Show(); std::cout << "z4="<< z4 <<std::endl; Complex z5(0,5); z5.Show(); std::cout << "z5="<< z5 <<std::endl; Complex z6(0,0); z6.Show(); std::cout << "z6="<< z6 <<std::endl; (z1 + z2).Show(); (z1 - z2).Show(); (z1 * z1).Show(); (z1 * z2).Show(); std::cout << "|z1| = " << z1.GetLenth() << std::endl; z1.Conjugate().Show(); z2.Conjugate().Show(); return 0; }
void mu3(int x,int y,char po[24],int f) { int m,n; static int i=0; for(m=0;m<2;m++) { for(n=0;n<3;n++) { blackground z1(x,y,m,n,BACKGROUND_BLUE|BACKGROUND_INTENSITY|FOREGROUND_INTENSITY); z1.display1(); if(f&&i<24) { po[i++]=x+m; // x po[i++]=y+n; // y po[i++]=2; // 颜色 } } } for(n=0,m=0;m<2;m++) { blackground z10(x+2,y+1,m,n,BACKGROUND_BLUE|BACKGROUND_INTENSITY|FOREGROUND_INTENSITY); z10.display1(); if(f&&i<24) { po[i++]=x+m+2; // x po[i++]=y+n+1; // y po[i++]=2; // 颜色 } } }
int main(int argc, char** argv) { mapnik::parameters params; benchmark::handle_args(argc,argv,params); mapnik::datasource_cache::instance().register_datasources("./plugins/input/"); mapnik::box2d<double> z1(-20037508.3428,-8317435.0606,20037508.3428,18399242.7298); // bbox for 16/10491/22911.png mapnik::box2d<double> z16(-13622912.929097254,6026906.8062295765,-13621689.93664469,6028129.79868214); { test test_runner(params, "benchmark/data/polygon_rendering_clip.xml", z1); run(test_runner,"polygon clip render z1"); } { test test_runner(params, "benchmark/data/polygon_rendering_no_clip.xml", z1); run(test_runner,"polygon noclip render z1"); } { test test_runner(params, "benchmark/data/polygon_rendering_clip.xml", z16); run(test_runner,"polygon clip render z16"); } { test test_runner(params, "benchmark/data/polygon_rendering_no_clip.xml", z16); run(test_runner,"polygon noclip render z16"); } return 0; }
/// \brief Update Kalman filter void UnscentedKalmanFilter::updateUKF(vnl_vector<double> u, vnl_vector<double> z) { // create Sigma points X for the current estimate distribution vnl_matrix<double> X(N,2*N+1); sigmas(x_hat, P_hat+Q, sqrt(C), X); vnl_matrix<double> Dbg; qDebug() << "X: "; for( int i = 0; i<6; i++) { qDebug() << X(i,0) << " " << X(i,1) << " " << X(i,2) << " " << X(i,3) << " " << X(i,4) << " " << X(i,5) << " " << X(i,6) << " " << X(i,7) << " " << X(i,8) << " " << X(i,9) << " " << X(i,10) << " " << X(i,11) << " " << X(i,12); } // apply unscented transformation for process model vnl_vector<double> x1(6); vnl_matrix<double> X1(N,2*N+1), P1(N,N), X2(N,2*N+1); utf(X, u, x1, X1, P1, X2); // apply unscented transformation for observation model vnl_vector<double> z1(M); vnl_matrix<double> Z1(M,2*M+1), P2(M,M), Z2(M,2*M+1); utg(X1, z1, Z1, P2, Z2); // define transformated cross-covariance vnl_matrix<double> WC(2*N+1,2*N+1,0.0); WC.set_diagonal(Wc.get_row(0)); vnl_matrix<double> P12 = X2*WC*Z2.transpose(); // perform state update K = P12*vnl_matrix_inverse<double>(P2); x_hat = x1 + K*(z-z1); // perform covariance update P_hat = P1 - K*P12.transpose(); }
void HashImpl<HASH, DRBGINFO>::HashGenerate(byte* hash, size_t hsize) { ASSERT(SeedLength == m_v.size()); ASSERT(SeedLength == m_c.size()); ASSERT(hash && hsize); ASSERT(m_rctr <= MaxReseed); ASSERT(hsize <= MaxRequest); try { ///////////////////////////////////////////////////////// // Preprocess V, Step1 ///////////////////////////////////////////////////////// byte w[HASH::DIGESTSIZE]; ByteArrayZeroizer z1(w, sizeof(w)); static const int two = 0x02; m_hash.Update((const byte*)&two, sizeof(two)); m_hash.Update(m_v.data(), m_v.size()); m_hash.TruncatedFinal(w, sizeof(w)); ///////////////////////////////////////////////////////// // Preprocess V, Step 2 ///////////////////////////////////////////////////////// CascadingAddModPower2(m_v.data(), m_v.size(), w, sizeof(w)); ///////////////////////////////////////////////////////// // Hashgen, Step 3 ///////////////////////////////////////////////////////// HashGenerateHelper(hash, hsize); ///////////////////////////////////////////////////////// // Postprocess V, Steps 4, 5, and 6 ///////////////////////////////////////////////////////// static const byte three = 0x03; byte h[HASH::DIGESTSIZE]; ByteArrayZeroizer z2(h, sizeof(h)); m_hash.Update(&three, sizeof(three)); m_hash.Update(m_v.data(), m_v.size()); m_hash.TruncatedFinal(h, sizeof(h)); CascadingAddModPower2(m_v.data(), m_v.size(), h, sizeof(h)); CascadingAddModPower2(m_v.data(), m_v.size(), m_c.data(), m_c.size()); CascadingAddModPower2(m_v.data(), m_v.size(), (const byte*)&m_rctr, sizeof(m_rctr)); ///////////////////////////////////////////////////////// // Copy out the generated data to the hash ///////////////////////////////////////////////////////// m_rctr++; } catch(CryptoPP::Exception& ex) { m_catastrophic = true; throw EncryptionException(NarrowString("Internal error: ") + ex.what()); } }
void HashImpl<HASH, DRBGINFO>::HashInstantiate(const byte* seed, size_t ssize) { ASSERT(SeedLength == m_v.size()); ASSERT(SeedLength == m_c.size()); ASSERT(seed && ssize); if(!seed || !ssize) throw IllegalArgumentException("Unable to instatiate hash drbg. The seed buffer or size is not valid"); try { HashDerivationFunction(seed, ssize, m_v.data(), m_v.size()); byte c[SeedLength+1]; ByteArrayZeroizer z1 (c, sizeof(c)); HashInitBufferWithData(0x00, m_v.data(), m_v.size(), c, sizeof(c)); HashDerivationFunction(c, sizeof(c), m_c.data(), m_c.size()); } catch(CryptoPP::Exception& ex) { m_catastrophic = true; throw EncryptionException(NarrowString("Internal error: ") + ex.what()); } }
//' rcpp_neutral_hotspots_ntests //' //' Performs repeated neutral tests to yield average distributions of both //' hotspot values and spatial autocorrelation statistics. //' //' @param nbs An \code{spdep} \code{nb} object listing all neighbours of each //' point. //' @param wts Weighting factors for each neighbour; must have same length as //' nbs. //' @param nbsi List of matrices as returned from \code{get_nbsi}. each element //' of which contains the i-th nearest neighbour to each point. //' @param alpha Strength of spatial autocorrelation //' @param sd0 Standard deviation of truncated normal distribution used to model //' environmental variation (with mean of 1) //' @param nt Number of successive layers of temporal and spatial autocorrelation //' used to generate final modelled values //' @param ntests Number of tests used to obtain average values //' @param ac_type Character string specifying type of aucorrelation //' (\code{moran}, \code{geary}, or code{getis-ord}). //' //' @return A matrix of dimension (size, 2), with first column containing //' sorted and re-scaled hotspot values, and second column containing sorted and //' re-scaled spatial autocorrelation statistics. //' // [[Rcpp::export]] Rcpp::NumericMatrix rcpp_neutral_hotspots_ntests (Rcpp::List nbs, Rcpp::List wts, Rcpp::List nbsi, double alpha, double sd0, int niters, std::string ac_type, bool log_scale, int ntests) { const int size = nbs.size (); Rcpp::NumericMatrix hs1; Rcpp::NumericVector z (size), z1 (size), ac (size), ac1 (size); std::fill (ac.begin (), ac.end (), 0.0); std::fill (z.begin (), z.end (), 0.0); for (int n=0; n<ntests; n++) { hs1 = rcpp_neutral_hotspots (nbs, wts, nbsi, alpha, sd0, log_scale, niters, ac_type); z += hs1 (Rcpp::_, 0); ac += hs1 (Rcpp::_, 1); } Rcpp::NumericMatrix result (size, 2); result (Rcpp::_, 0) = z / (double) ntests; result (Rcpp::_, 1) = ac / (double) ntests; Rcpp::colnames (result) = Rcpp::CharacterVector::create ("z", "ac"); return result; }
void CParametricSurface::Vertex(Vec2 domain) { Vec3 p0, p1, p2, p3; Vec3 normal; float u = domain.x; float v = domain.y; Eval(domain, p0); Vec2 z1(u + du/2, v); Eval(z1, p1); Vec2 z2(u + du/2 + du, v); Eval(z2, p3); if (flipped) { Vec2 z3(u + du/2, v - dv); Eval(z3, p2); } else { Vec2 z4(u + du/2, v + dv); Eval(z4, p2); } const float epsilon = 0.00001f; Vec3 tangent = p3 - p1; Vec3 binormal = p2 - p1; MatrixVec3CrossProduct(normal, tangent, binormal); if (normal.length() < epsilon) normal = p0; normal.normalize(); if (tangent.length() < epsilon) MatrixVec3CrossProduct(tangent, binormal, normal); tangent.normalize(); binormal.normalize(); binormal = binormal * -1.0f; /* if (CustomAttributeLocation() != -1) glVertexAttrib1f(CustomAttributeLocation(), CustomAttributeValue(domain)); */ //glNormal(normal); //glTexCoord(domain); //glVertex(p0); int vertexIndex = totalVertex * 14; vertexBuffer[vertexIndex++] = p0.x; vertexBuffer[vertexIndex++] = p0.y; vertexBuffer[vertexIndex++] = p0.z; vertexBuffer[vertexIndex++] = domain.x; vertexBuffer[vertexIndex++] = domain.y; vertexBuffer[vertexIndex++] = normal.x; vertexBuffer[vertexIndex++] = normal.y; vertexBuffer[vertexIndex++] = normal.z; vertexBuffer[vertexIndex++] = tangent.x; vertexBuffer[vertexIndex++] = tangent.y; vertexBuffer[vertexIndex++] = tangent.z; vertexBuffer[vertexIndex++] = binormal.x; vertexBuffer[vertexIndex++] = binormal.y; vertexBuffer[vertexIndex++] = binormal.z; }
int main() { foo(); bar(); z1(); z2(); return 0; }
TEST(FractionTest, Different_Numbers_Not_Equal) { // Arrange Fraction z1(2, 14); Fraction z2(1, 8); // Act & Assert EXPECT_NE(z1, z2); }
TEST(FractionTest, Equal_Numbers_Are_Equal) { // Arrange Fraction z1(2, 14); Fraction z2(1, 7); // Act & Assert EXPECT_EQ(z1, z2); }
void ComposeFrobeniusMap(GF2EX& y, const GF2EXModulus& F) { long d = GF2E::degree(); long n = deg(F); long i; i = 1; while (i <= d) i = i << 1; i = i >> 1; GF2EX z(INIT_SIZE, n), z1(INIT_SIZE, n); i = i >> 1; long m = 1; if (n == 2) { SetX(z); SqrMod(z, z, F); } else { while (i) { long m1 = 2*m; if (i & d) m1++; if (m1 >= NTL_BITS_PER_LONG-1 || (1L << m1) >= n) break; m = m1; i = i >> 1; } clear(z); SetCoeff(z, 1L << m); } while (i) { z1 = z; long j, k, dz; dz = deg(z); for (j = 0; j <= dz; j++) for (k = 0; k < m; k++) sqr(z1.rep[j], z1.rep[j]); CompMod(z, z1, z, F); m = 2*m; if (d & i) { SqrMod(z, z, F); m++; } i = i >> 1; } y = z; }
float f2(float y) { float qgaus(float (*func)(float), float a, float b); float f3(float z); float z1(float,float),z2(float,float); ysav=y; return qgaus(f3,z1(xsav,y),z2(xsav,y)); }
bool evclm(XLong& e,XLong& N, XLong& result) { XLong m(N); XLong n(e); XLong p(0,e.GetBitLength()); XLong q(0,e.GetBitLength()); XLong r(0,e.GetBitLength()); XLong s(0,e.GetBitLength()); XLong z1(0,e.GetBitLength()); p=1; q=0; r=0; s=1; //!2OPTIMIZE: replace % and / by div one time while (!((m==0)||(n==0))) { if (m >= n) { z1 = m/n; m = m % n; p -= r*z1; q -= s*z1; } else { z1 = n/m; n = n % m; r -= p*z1; s -= q*z1; } } if (m==0) { result = e*s; if (n != 1) { result = 0; return false; } return true; } else { // CRASH("evclm:right exc"); p += r; q += s; result = e*q; if (m != 1) { result = 0; return false; } return true; } }
int main() { Complex z1(3,4); Complex z2(1,-2); std::cout << z1+z2 << std::endl; std::cout << z1-z2 << std::endl; std::cout << z1*z2 << std::endl; std::cout << z1/z2 << std::endl; std::cout << z1*z2 << std::endl; }
/** Scalar product operator (vector) */ complex vector<complex>::operator*(const vector<complex>& v) const { complex z1(0., 0., false); vector<complex> v1(_vector); if (gsl_blas_zdotu(v1.as_gsl_type_ptr(), v.as_gsl_type_ptr(), z1.as_gsl_type_ptr())) { std::cout << "\n Error in vector<complex> *" << std::endl; exit(EXIT_FAILURE); } return z1; }
void ComplexTestSuite::ElementaryFunctions() { real rTolerance = 1e-14; real a = 1; real b = 2; gsl::complex z1(a,b); // Power functions real r = std::sqrt( a*a + b*b ); real q = std::atan( b / a ); CPPUNIT_ASSERT_DOUBLES_EQUAL( std::sqrt(r), gsl::sqrt(z1).abs(), rTolerance ); CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.5*q, gsl::sqrt(z1).arg(), rTolerance ); real c = -4; CPPUNIT_ASSERT_DOUBLES_EQUAL( std::sqrt( fabs(c) ), gsl::sqrt( c ).y(), rTolerance ); CPPUNIT_ASSERT_DOUBLES_EQUAL( 0, gsl::sqrt( c ).x(), rTolerance ); gsl::complex z2(b,a); gsl::complex z3 = gsl::pow( z1, z2 ); real r3 = std::exp( z2.x()*std::log( z1.abs() ) - z1.arg()*z2.y() ); real q3 = z1.arg()*z2.x() + z2.y()*std::log( z1.abs() ); CPPUNIT_ASSERT_DOUBLES_EQUAL( r3, z3.abs(), rTolerance ); CPPUNIT_ASSERT_DOUBLES_EQUAL( q3, z3.arg(), rTolerance ); gsl::complex z4 = gsl::pow( z3, c ); real q4 = z3.arg()*c; // unwind the argument, so that it's -pi < x <= pi const real pi = 3.14159265358979323846; q4 = q4 - pi * static_cast< int >( q4 / (pi) ) + pi; CPPUNIT_ASSERT_DOUBLES_EQUAL( std::pow( z3.abs(), c), z4.abs(), rTolerance ); CPPUNIT_ASSERT_DOUBLES_EQUAL( q4, z4.arg(), rTolerance ); // Exponentials gsl::complex z5 = gsl::exp( z4 ); CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.12334173203738, z5.x(), rTolerance ); CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0710310274678569, z5.y(), rTolerance ); gsl::complex z6 = gsl::log( z1 ); CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.80471895621705, z6.x(), rTolerance ); CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.10714871779409, z6.y(), rTolerance ); CPPUNIT_ASSERT( z6 == gsl::ln( z1 ) ); gsl::complex z7 = gsl::log10( z2 ); CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.349485002168009, z7.x(), rTolerance ); CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.201359598136687, z7.y(), rTolerance ); gsl::complex z8 = gsl::log_b( z4, z5 ); CPPUNIT_ASSERT_DOUBLES_EQUAL( -11.4955609428967, z8.x(), 100*rTolerance ); CPPUNIT_ASSERT_DOUBLES_EQUAL( 10.2805834567583, z8.y(), rTolerance ); }
void mukuai() { int m,n; for(n=0;n<3;n++) { for(m=0;m<15;m++) { blackground z0(86,8,m,n,BACKGROUND_GREEN|FOREGROUND_INTENSITY); z0.display1(); } } SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|BACKGROUND_GREEN|BACKGROUND_INTENSITY); COORD pos1; pos1.X=88; pos1.Y=9; SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),pos1); printf("play again!"); for(n=0;n<3;n++) { for(m=0;m<8;m++) { blackground z1(74,25,m,n,BACKGROUND_GREEN|FOREGROUND_INTENSITY); z1.display1(); } } SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|BACKGROUND_GREEN|BACKGROUND_INTENSITY); COORD pos2; pos2.X=76; pos2.Y=26; SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),pos2); printf("save"); for(n=0;n<3;n++) { for(m=0;m<8;m++) { blackground z2(84,25,m,n,BACKGROUND_GREEN|FOREGROUND_INTENSITY); z2.display1(); } } SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|BACKGROUND_GREEN|BACKGROUND_INTENSITY); COORD pos3; pos3.X=86; pos3.Y=26; SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),pos3); printf("open"); for(n=0;n<3;n++) { for(m=0;m<8;m++) { blackground z2(94,25,m,n,BACKGROUND_GREEN|FOREGROUND_INTENSITY); z2.display1(); } } SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|BACKGROUND_GREEN|BACKGROUND_INTENSITY); COORD pos4; pos4.X=96 ; pos4.Y=26; SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),pos4); printf("over"); }
TEST(FractionTest, Can_Division_Fraction) { // Arrange Fraction z1(5, 2); Fraction z2(7, 3); // Act Fraction z = z2 / z1; // Assert Fraction expected_z(14, 15); EXPECT_EQ(expected_z, z); }
TEST(FractionTest, Can_Multiplication_Fraction) { // Arrange Fraction z1(5, 3); Fraction z2(4, 6); // Act Fraction z = z1 * z2; // Assert Fraction expected_z(20, 18); EXPECT_EQ(expected_z, z); }
TEST(FractionTest, Can_Add_Negative_Fractions) { // Arrange Fraction z1(-3, 5); Fraction z2(-1, 3); // Arrange Fraction z = z1 + z2; // Assert Fraction expected_z(-14, 15); EXPECT_EQ(expected_z, z); }
TEST(FractionTest, Can_Add_Fraction) { // Arrange Fraction z1(0, 14); Fraction z2(1, 7); // Arrange Fraction z = z1 + z2; // Assert Fraction expected_z(1, 7); EXPECT_EQ(expected_z, z); }
TEST(FractionTest, Can_Difference_Fraction) { // Arrange Fraction z1(3, 14); Fraction z2(1, 7); Fraction z; // Act z = z1 - z2; // Assert Fraction expected_z(1, 14); EXPECT_EQ(expected_z, z); }
void MainWindow::slot1() { qreal *b = a->getParams(ui->comboBox->currentText()); QVariant z1(b[0]); ui->lineEdit_2->setText(z1.toString()); QVariant z2(b[1]); ui->lineEdit_3->setText(z2.toString()); QVariant z3(b[2]); ui->lineEdit_4->setText(z3.toString()); QVariant z4(b[3]); ui->lineEdit_5->setText(z4.toString()); }
// Send out a normal, texture coordinate, vertex coordinate, and an optional custom attribute. void TParametricSurface::Vertex(vec2 domain) { vec3 p0, p1, p2, p3; vec3 normal; float u = domain.u; float v = domain.v; Eval(domain, p0); vec2 z1(u + du/2, v); Eval(z1, p1); vec2 z2(u + du/2 + du, v); Eval(z2, p3); if (flipped) { vec2 z3(u + du/2, v - dv); Eval(z3, p2); } else { vec2 z4(u + du/2, v + dv); Eval(z4, p2); } const float epsilon = 0.00001f; vec3 tangent = p3 - p1; vec3 binormal = p2 - p1; normal = cross(tangent, binormal); if (normal.magnitude() < epsilon) normal = p0; normal.unitize(); if (tangentLoc != -1) { if (tangent.magnitude() < epsilon) tangent = cross(binormal, normal); tangent.unitize(); glVertexAttrib(tangentLoc, tangent); } if (binormalLoc != -1) { binormal.unitize(); glVertexAttrib(binormalLoc, -binormal); } if (CustomAttributeLocation() != -1) glVertexAttrib1f(CustomAttributeLocation(), CustomAttributeValue(domain)); glNormal(normal); glTexCoord(domain); glVertex(p0); }
TEST(Voevodin_Andrew_ComplexNumberTest, Sum_Complex_Conjugate_Is_Real) { // Arrange ComplexNumber z1(6.0, 5.12); ComplexNumber z2(6.0, -5.12); ComplexNumber Model_Mult; double Square; // Act Model_Mult = z1+z2; Square = 2.0*z1.getRe(); // Assert EXPECT_DOUBLE_EQ(Model_Mult.getIm(), 0.0); EXPECT_DOUBLE_EQ(Model_Mult.getRe(), Square); }
TEST(Voevodin_Andrew_ComplexNumberTest, Module_Of_Sum_less_Sum_Module) { // Arrange ComplexNumber z1(5.0, 5.0); ComplexNumber z2(5.0, 5.0); double Model_Sum, Sum_Model; // Act Model_Sum = pow(pow((z1+z2).getRe(), 2) + pow((z1+z2).getIm(), 2), 0.5); Sum_Model = pow(pow(z1.getRe(), 2) + pow(z1.getIm(), 2), 0.5) + pow(pow(z2.getRe(), 2) + pow(z2.getIm(), 2), 0.5); // Assert EXPECT_TRUE(Model_Sum <= Sum_Model); }
// ---------------------------------------------------------------- fpnpoly_t fpnpoly_from_qpoly(qpoly_t q, fppoly_t im) { int d = q.find_degree(); int p = im.get_char(); intmod_t z0(0, p); fppoly_t z1(z0); fppolymod_t z2(z0, im); fpnpoly_t rv(z2); for (int i = d; i >= 0; i--) { intmod_t m = intmod_from_rat(q.get_coeff(i), p); fppolymod_t c = fppolymod_t::prime_sfld_elt(m.get_residue(), im); rv.set_coeff(i, c); } return rv; }
int main() { Complex z1(1.0, 1.0); Complex z2(2.0, 3.0); Complex z3 = z1 * z2; // Complex z4 = 2.0 * z4; ?? compiles Complex z4 = 2.0 * z3; Complex z5 = - z3; // Create a dynamic list of Complex numbers int Size = 5; Complex* cpArray = new Complex[Size]; cpArray[0] = z1; cpArray[1] = z2; cpArray[2] = z3; cpArray[3] = z4; cpArray[4] = z5; // Now define an array on the stack Complex fixedArray[5]; // The constant '5' is mandatory for (int i = 0; i < Size; i++) { fixedArray[i] = Complex ((double) i, 0.0); } // Call function and print values for each z for (int j = 0; j < Size; j++) { cout << myFunc(cpArray[j]) << ", "; } // Now work with functions of several complex variables Complex product = ComplexProduct(fixedArray, Size); cout << "Product: " << product << endl; Complex sum = ComplexSum(fixedArray, Size); cout << "Sum: " << sum << endl; delete [] cpArray; return 0; }