示例#1
0
void splineInter2D(double *Tc, double *dT, const double *T,
        const double *omega, const double *m, int N, const double *X,
        double *h, bool doDerivative, bool boundary) {
    // Increments in X and Y direction
    int xf, yf, i, j, k, m0 = m[0], m1 = m[1];
    double x, y, p;
    
    //for each value X compute the value in  the spline
    #pragma omp parallel for default(shared) private(x, y, xf, yf, p, i, j, k)
    for (i=0;i<N;i++) {
        Tc[i]   = 0;
        
        x = (X[i]   - omega[0]) / h[0] + .5 - 1;
        y = (X[i+N] - omega[2]) / h[1] + .5 - 1;

        //check if it is a valid x
        if (!boundary && (x<=-2 || y<=-2 || x>=m0+1 || y>=m1+1))
            continue;
        
        xf = floor(x);
        yf = floor(y);
        x  = x - xf;
        y  = y - yf;
        
        if (doDerivative) {
            dT[i]   = 0;
            dT[i+N] = 0;
        }

        for (j=-1;j<3;j++) {
            for (k=-1;k<3;k++) {
                if (boundary) {
                    p = T[min(m0-1,max(0,xf+j))+m0*(min(m1-1,max(0,yf+k)))];
                } else {
                    p = (xf+j<0 || xf+j>m0-1 ||
                         yf+k<0 || yf+k>m1-1)? 0: T[xf+j+m0*(yf+k)];
                }
                Tc[i] += p*b0(3-j,x-j)*b0(3-k,y-k);
                if (doDerivative) {
                    dT[i]   += p*db0(3-j,x-j)* b0(3-k,y-k);
                    dT[i+N] += p* b0(3-j,x-j)*db0(3-k,y-k);
                }
            }
        }
        
        if (mxIsNaN(Tc[i]))
            mexPrintf("Is NAN. ");
        
        if (doDerivative) {
            dT[i]   = dT[i]/h[0];
            dT[i+N] = dT[i+N]/h[1];
        }
    }    
}
示例#2
0
文件: 2fish.c 项目: pktmonky/SLAE
/* given the Sbox keys, create the fully keyed QF */
void fullKey(u32 L[4], int k, u32 QF[4][256])
{
    BYTE y0, y1, y2, y3;

    int i;
    
    /* for all input values to the Q permutations */
    for (i=0; i<256; i++)
    {
	/* run the Q permutations */
	y0 = i; y1=i; y2=i; y3=i;
	switch(k)
    	{
    	    case 4:
    		y0 = Q1[y0] ^ b0(L[3]);
    		y1 = Q0[y1] ^ b1(L[3]);
    		y2 = Q0[y2] ^ b2(L[3]);
    		y3 = Q1[y3] ^ b3(L[3]);
    	    case 3:
    		y0 = Q1[y0] ^ b0(L[2]);
    		y1 = Q1[y1] ^ b1(L[2]);
    		y2 = Q0[y2] ^ b2(L[2]);
    		y3 = Q0[y3] ^ b3(L[2]);
    	    case 2:
    		y0 = Q1[  Q0 [ Q0[y0] ^ b0(L[1]) ] ^ b0(L[0]) ];
    		y1 = Q0[  Q0 [ Q1[y1] ^ b1(L[1]) ] ^ b1(L[0]) ];
    		y2 = Q1[  Q1 [ Q0[y2] ^ b2(L[1]) ] ^ b2(L[0]) ];
    		y3 = Q0[  Q1 [ Q1[y3] ^ b3(L[1]) ] ^ b3(L[0]) ];
    	}
	
	/* now do the partial MDS matrix multiplies */
	QF[0][i] = ((multEF[y0] << 24) 
		    | (multEF[y0] << 16) 
		    | (mult5B[y0] << 8)
		    | y0);
	QF[1][i] = ((y1 << 24) 
		    | (mult5B[y1] << 16) 
		    | (multEF[y1] << 8)
		    | multEF[y1]);
	QF[2][i] = ((multEF[y2] << 24) 
		    | (y2 << 16) 
		    | (multEF[y2] << 8)
		    | mult5B[y2]);
	QF[3][i] = ((mult5B[y3] << 24) 
		    | (multEF[y3] << 16)
		    | (y3 << 8) 
		    | mult5B[y3]);
    }
}
示例#3
0
//		Least mean square method
//		args:
//		A:			the input matrix
//		b:			the right hand vector
//		mu:			the scaling factor
//		return value: the obtained coefficient
static PyObject* pyLeastMeanSquare(PyObject *self,PyObject *args)
{

    PyObject *A,*b;
    float mu;
	if (!PyArg_ParseTuple(args,"OOf",&A,&b,&mu))
	 	return NULL;
	int m = PyObject_Size(A);
	int n = PyObject_Size(PyList_GetItem(A,0));
	Matrix A0(m,n);
	for(int i = 0;i < m;i++)
		for(int j = 0;j < n;j++)
			A0(i,j) = PyFloat_AsDouble(PyList_GetItem(PyList_GetItem(A,i),j));
	Vector b0(m);
	for(int i = 0;i < m;i++)
		b0[i] = PyFloat_AsDouble(PyList_GetItem(b,i));
	Vector x(n);
	COPT::LeastMeanSquareMethod(A0,b0,mu,x);

	PyObject *list;
	list = PyList_New(n);
	for(int j = 0;j < n;j++)
		PyList_SetItem(list,j,Py_BuildValue("f",x[j]));
	return Py_BuildValue("O",list);
}
示例#4
0
void giperbolic(double *x, double ts, double te){
     /* процедура для параболического уравнения*/
      for ( int i = 0; i < n; i++ ) {
          x[i]=1.0/n * i ; // количество шагов на оси x
      }
      double xi=1.0/n;
     double tau=xi*sqrt(r); // шаг по времени (из условия Куранта)
     double t=ts; // t-текущее время, ts -- время начала эксперимента
     
     /*пересчёт значений в середине по разносной схеме*/
     while(t < te){ //te -- время конца эксперимента
     for ( int i = 1; i < n-1; i++ ) {
     w[i] = 2 * (1 - r) * v[i] +
            r * (v[i-1] + v[i+1]) -
            u[i] + tau * tau * source(i * xi, t);
         }

     /* пересчёт значений на краях*/


      v[0] = (c0(t) - v[1] * a0(t) / xi) / (b0(t) - a0(t) / xi);
      v[n-1] = (c1(t) + v[n-2] * a1(t) / xi) / (b1(t) + a1(t) / xi);

    for ( int i = 0; i < n; i++ ) {
        q[i]=u[i]; 
        u[i]=v[i];
        v[i]=w[i];
        w[i]=q[i];
    }
        t += tau; //обновление времени
    for ( int i = 0; i < n; i++ ) {
       double   d = (v[i] - u[i]) / tau; //список производных по времени
      }
}
}
示例#5
0
void ChunkManager::initTree(ChunkTree&  pChild)
{
    boost::shared_ptr<Chunk>& pChunk = pChild.getValue();
    

    AABB bounds = pChild.getParent()->getValue()->m_bounds;
    vec center = bounds.CenterPoint();
    vec c0 = bounds.CornerPoint(pChild.getCorner().index());

    AABB b0(vec(min(c0.x, center.x),
                min(c0.y, center.y),
                min(c0.z, center.z)), 
            vec(max(c0.x, center.x),
                max(c0.y, center.y),
                max(c0.z, center.z)));

    pChunk = boost::make_shared<Chunk>(b0, 1.0f/pChild.getLevel(), this);

    pChunk->m_pTree = &pChild;

    *pChunk->m_workInProgress = true;

    m_chunkGeneratorQueue.push(pChild.getValueCopy());

}
示例#6
0
int test_if_assign() {
    int x = f0();
    if (b0(0)) x = f1();
    int y = f2();
    if (b1(1)) y = f2();
    return x + y;
}
示例#7
0
void testBufferConvertComplexComponents(const size_t inVlen, const size_t outVlen)
{
    const size_t numElems = 100 + (std::rand() % 100);
    Pothos::BufferChunk b0(Pothos::DType(typeid(InType), inVlen), numElems);
    const auto primElems = b0.length/b0.dtype.elemSize();

    //random fill primitive elements
    for (size_t i = 0; i < primElems; i++) randType(b0.as<InType *>()[i]);

    //convert
    const auto b1 = b0.convertComplex(Pothos::DType(typeid(OutType), outVlen), numElems);

    //check
    std::cout << "testBufferConvertComplexComponents: " << b0.dtype.toString() << " to " << b1.first.dtype.toString() << "...\t" << std::flush;
    for (size_t i = 0; i < primElems; i++)
    {
        const auto in = b0.as<const InType *>()[i];
        const auto outRe = b1.first.as<const OutType *>()[i];
        const auto outIm = b1.second.as<const OutType *>()[i];
        if (not checkEqual(in.real(), outRe) or not checkEqual(in.imag(), outIm))
        {
            std::cerr << "elem " << i << ": " << in << " != " << outRe << ", " << outIm << std::endl;
            POTHOS_TEST_TRUE(checkEqual(in.real(), outRe) and checkEqual(in.imag(), outIm));
        }
    }
    std::cout << "OK" << std::endl;
}
示例#8
0
void test_strategy()
{
    // Test by explicitly specifying a strategy
    typedef bg::model::d2::point_xy<double> point_type;
    typedef bg::model::box<point_type> box_type;
    point_type p(3, 3);
    box_type b(point_type(0, 0), point_type(5, 5));
    box_type b0(point_type(0, 0), point_type(5, 0));

    bool r = bg::within(p, b,
        bg::strategy::within::point_in_box<point_type, box_type>());
    BOOST_CHECK_EQUAL(r, true);

    r = bg::within(b, b,
        bg::strategy::within::box_in_box<box_type, box_type>());
    BOOST_CHECK_EQUAL(r, true);

    r = bg::within(b0, b0,
        bg::strategy::within::box_in_box<box_type, box_type>());
    BOOST_CHECK_EQUAL(r, false);

    r = bg::within(p, b,
        bg::strategy::within::point_in_box_by_side<point_type, box_type>());
    BOOST_CHECK_EQUAL(r, true);
}
示例#9
0
文件: math.cpp 项目: DavidPH/DH-dlc
real_t pi_make()
{
	// Gauss-Legrende algorithm

	real_t a0(1);
	real_t b0(real_t(1) / sqrt(real_t(2)));
	real_t t0(0.25);
	real_t p0(1);

	real_t a1, b1, t1, p1;

	// index is halved each time because the precision doubles per iteration.
	for (int index = option_precision + 2; index > 0; index /= 2)
	{
		a1 = (a0 + b0) / real_t(2);
		b1 = sqrt(real_t(a0 * b0));
		t1 = t0 - (p0 * (a0-a1) * (a0-a1));
		p1 = p0 * real_t(2);

		a0 = a1;
		b0 = b1;
		t0 = t1;
		p0 = p1;
	}

	return ((a0 + b0) * (a0 + b0)) / (t0 * real_t(4));
}
示例#10
0
static PyObject* geRLS(PyObject *self,PyObject *args)
{

    PyObject *A,*b;
    float lam,delta;
	if (!PyArg_ParseTuple(args,"OOff",&A,&b,&lam,&delta))
	 	return NULL;
	//std::cout<<PyObject_Size(A)<<std::endl;
    //std::cout<<PyObject_Size(PyList_GetItem(A,1))<<std::endl;
	int m = PyObject_Size(A);
	int n = PyObject_Size(PyList_GetItem(A,0));
    //std::cout<<PyFloat_AsDouble(PyList_GetItem(PyList_GetItem(A,1),1))<<std::endl;
	Matrix A0(m,n);
	for(int i = 0;i < m;i++)
		for(int j = 0;j < n;j++)
			A0(i,j) = PyFloat_AsDouble(PyList_GetItem(PyList_GetItem(A,i),j));
	//std::cout<<A0<<std::endl;
	Vector b0(m);
	for(int i = 0;i < m;i++)
		b0[i] = PyFloat_AsDouble(PyList_GetItem(b,i));
	Vector x(n);
	COPT::RLS_Method(A0,b0,x,lam,delta);
	//std::cout<<x<<std::endl;

	PyObject *list;
	list = PyList_New(n);
	for(int j = 0;j < n;j++)
		PyList_SetItem(list,j,Py_BuildValue("f",x[j]));
	//std::cout<<list<<std::endl;
	return Py_BuildValue("O",list);
	//return Py_BuildValue("s","successful extension!");
}
示例#11
0
std::string get_concatenated_path(std::string part0, std::string part1) {
  boost::filesystem::path b0(part0), b1(part1);
#if BOOST_FILESYSTEM_VERSION == 3
  return (b0 / b1).string();
#else
  return (b0 / b1).native_file_string();
#endif
}
示例#12
0
    /**
     * The resolution process
     * @param maxiters the upper bound for iterations on entry, on exit real number of performed iters
     * @param bncs the state of computations 
     * @param recupd true if record was updated
     */
    void solve(long long int& maxiters, BNCState<FT> & bnc, bool& recupd) {
        long long int I = 0;
        BNCSubPrinter<double> subprinter;
        for (; I < maxiters; I++) {
#if 0            
            std::cout << "step " << I << " ^^^^^^^^^^^^^^^^^^\n";
            std::cout << "Record = " << bnc.mRecord->getValue() << "\n";
#endif
#if 0 
            BNBTreeUtils::printTree(*bnc.mTree, subprinter);
            std::cout << "step " << I << " vvvvvvvvvvvvvvvvvv\n";
#endif            


            BNBNode* node = bnc.mTreeManager->get();
            if (node == NULL)
                break;
            BNCSub<FT>* sub = (BNCSub<FT>*) node->mData;


            mCutFactory->getCuts(sub->mBox, sub->mCuts);


            std::vector< Box<FT> > bv;
            std::vector< Cut<FT> > cuts;
            BNBNode* np = node;
            int cutd = 0;
            int n = sub->mBox.mDim;
            bv.push_back(sub->mBox);

            while (np && (cutd++ < mCutLookupDepth)) {
#if 0
                std::cout << "Cuts at node " << cutd << ":\n";
#endif                
                BNCSub<FT>* subp = (BNCSub<FT>*) np->mData;
                applyCuts(subp->mCuts, bv);
                if (bv.empty())
                    break;
                np = np->mParent;
            }
            if (bv.empty()) {
                deleteNode(node);
                continue;
            } else if (bv.size() == 1) {
                Box<FT> b0(n), b1(n), b2(n);
                b0 = bv.at(0);
                bv.pop_back();
                /*
                BoxUtils::divideByLongestEdge(b0, b1, b2);
                bv.push_back(b1);
                bv.push_back(b2);
                 */
                mBoxSplitter->split(b0, bv);
            }
            pushNewSubs(*bnc.mTreeManager, bv, node);
        }
        maxiters = I;
    }
/* Public functions */
void VGCRectangleTest::run(){
	VGCRectangle r0;
	VGCAssert(VGCVector(0, 0) == r0.getPosition());
	VGCAssert(0 == r0.getWidth());
	VGCAssert(0 == r0.getHeight());

	r0.setPosition(VGCVector(1, 2));
	VGCAssert(VGCVector(1, 2) == r0.getPosition());
	r0.setWidth(1);
	VGCAssert(1 == r0.getWidth());
	r0.setHeight(2);
	VGCAssert(2 == r0.getHeight());

	VGCRectangle r1(VGCVector(1, 2), 1, 2);
	VGCAssert(VGCVector(1, 2) == r1.getPosition());
	VGCAssert(1 == r1.getWidth());
	VGCAssert(2 == r1.getHeight());

	VGCRectangle r2(r1);
	VGCAssert(VGCVector(1, 2) == r2.getPosition());
	VGCAssert(1 == r2.getWidth());
	VGCAssert(2 == r2.getHeight());

	VGCRectangle r3;
	r3 = r2;
	VGCAssert(VGCVector(1, 2) == r3.getPosition());
	VGCAssert(1 == r3.getWidth());
	VGCAssert(2 == r3.getHeight());

	VGCRectangle r4(VGCVector(1, 2), 2, 3);
	VGCAssert(r4.isInside(VGCVector(1, 2)));
	VGCAssert(r4.isInside(VGCVector(2, 2)));
	VGCAssert(r4.isInside(VGCVector(1, 3)));
	VGCAssert(r4.isInside(VGCVector(2, 3)));
	VGCAssert(r4.isInside(VGCVector(1, 4)));
	VGCAssert(r4.isInside(VGCVector(2, 4)));
	VGCAssert(!r4.isInside(VGCVector(0, 3)));
	VGCAssert(!r4.isInside(VGCVector(2, 5)));


	VGCRectangle a0(VGCVector(0, 0), 0, 0);
	VGCRectangle a1(VGCVector(0, 0), 0, 1);
	VGCRectangle a2(VGCVector(0, 0), 1, 0);
	VGCRectangle a3(VGCVector(0, 1), 0, 0);
	VGCRectangle b0(VGCVector(0, 0), 0, 0);
	VGCRectangle b1(VGCVector(0, 0), 0, 1);
	VGCRectangle b2(VGCVector(0, 0), 1, 0);
	VGCRectangle b3(VGCVector(0, 1), 0, 0);
	VGCAssert(a0 == b0);
	VGCAssert(a1 == b1);
	VGCAssert(a2 == b2);
	VGCAssert(a3 == b3);
	VGCAssert(a0 != a1);
	VGCAssert(a0 != a2);
	VGCAssert(a0 != a3);
}
void dtkMatrixTestCase::testSubAssign(void)
{
    dtkUnderscore _;
    dtkDenseMatrix<double> a0(4,4),b0(4,4);

    a0.fill(82);
    b0.fill(40);

    a0-=b0;

    for(qlonglong j=1; j<5; j++)
    {
        for(qlonglong i=1; i<5; i++)
        {
            QVERIFY(a0(i,j)==42);
            QVERIFY(b0(i,j)==40);
        }
    }
}
示例#15
0
void return_inside_while() {
    int x = 0;
    while (b0(x)) {
        f0();
        if (b1(x)) return;
        f1();
        ++x;
    }
    f2();
}
示例#16
0
void branch_test(int c) {
    if (b0(c)) {
        f0();
    } else if (b1(c)) {
        f1();
    } else if (b2(c)) {
        f2();
    } else {
        f3();
    }
}
void dtkMatrixTestCase::testMultAssign(void)
{
    dtkUnderscore _;
    dtkDenseMatrix<double> a0(4,4),b0(4,4),c0(4,4);

    a0.fill(3);
    b0.fill(2);
    c0=a0*b0;

    a0*=5;

    for(qlonglong j=1; j<5; j++)
    {
        for(qlonglong i=1; i<5; i++)
        {
            QVERIFY(a0(i,j)==15);
            QVERIFY(b0(i,j)==2);
            QVERIFY(c0(i,j)==24);
        }
    }
}
示例#18
0
文件: Hillier.cpp 项目: corburn/ISIS
    /**
     * @brief Return parameters used for all bands
     *
     * Method creates keyword vectors of band specific parameters
     * used in the photometric correction.
     *
     * @author Kris Becker - 2/22/2010
     *
     * @param pvl Output PVL container write keywords
     */
    void Hillier::Report ( PvlContainer &pvl ) {
        pvl.addComment("I/F = mu0/(mu0+mu) * F(phase)");
                pvl.addComment(" where:");
                pvl.addComment("  mu0 = cos(incidence)");
                pvl.addComment("  mu = cos(incidence)");
                pvl.addComment("  F(phase) = B0*exp(-B1*phase) + A0 + A1*phase + A2*phase^2 + A3*phase^3 + A4*phase^4");

                pvl += PvlKeyword("Algorithm", "Hillier");
                pvl += PvlKeyword("IncRef", toString(_iRef), "degrees");
                pvl += PvlKeyword("EmaRef", toString(_eRef), "degrees");
                pvl += PvlKeyword("PhaRef", toString(_gRef), "degrees");
                PvlKeyword units("HillierUnits");
                PvlKeyword phostd("PhotometricStandard");
                PvlKeyword bbc("BandBinCenter");
                PvlKeyword bbct("BandBinCenterTolerance");
                PvlKeyword bbn("BandNumber");
                PvlKeyword b0("B0");
                PvlKeyword b1("B1");
                PvlKeyword a0("A0");
                PvlKeyword a1("A1");
                PvlKeyword a2("A2");
                PvlKeyword a3("A3");
                PvlKeyword a4("A4");
                for (unsigned int i = 0; i < _bandpho.size(); i++) {
                    Parameters &p = _bandpho[i];
                    units.addValue(p.units);
                    phostd.addValue(toString(p.phoStd));
                    bbc.addValue(toString(p.wavelength));
                    bbct.addValue(toString(p.tolerance));
                    bbn.addValue(toString(p.band));
                    b0.addValue(toString(p.b0));
                    b1.addValue(toString(p.b1));
                    a0.addValue(toString(p.a0));
                    a1.addValue(toString(p.a1));
                    a2.addValue(toString(p.a2));
                    a3.addValue(toString(p.a3));
                    a4.addValue(toString(p.a4));
                }
                pvl += units;
                pvl += phostd;
                pvl += bbc;
                pvl += bbct;
                pvl += bbn;
                pvl += b0;
                pvl += b1;
                pvl += a0;
                pvl += a1;
                pvl += a2;
                pvl += a3;
                pvl += a4;
                return;
            }
示例#19
0
void level_three()
{
	vector<DPipe> DirectPipes(13);
		vector<DoublePipe> DoublePipes(13);
		vector<CrossPipe> CrossPipes(2);
				DPipe a0(50,SCREEN_HEIGHT-50,100,40);
				DoublePipe b0(150,SCREEN_HEIGHT-50,70,40);
				DPipe a1(150,SCREEN_HEIGHT-150,100,40);
				DoublePipe b1(150,SCREEN_HEIGHT-250,70,40);
				DPipe a2(250,SCREEN_HEIGHT-350,100,40);
				DoublePipe b2(350,SCREEN_HEIGHT-250,70,40);
				DPipe a3(350,SCREEN_HEIGHT-350,100,40);
				DPipe a4(350,SCREEN_HEIGHT-150,100,40);
				DoublePipe b3(250,SCREEN_HEIGHT-450,70,40);
				DoublePipe b4(350,SCREEN_HEIGHT-450,70,40);
				CrossPipe c0(250,SCREEN_HEIGHT-250,100,40);
				DPipe a5(550,SCREEN_HEIGHT-50,100,40);
				DoublePipe b5(250,SCREEN_HEIGHT-150,70,40);
				DoublePipe b6(450,SCREEN_HEIGHT-50,70,40);
				DoublePipe b7(650,SCREEN_HEIGHT-150,70,40);
				DPipe a6(550,SCREEN_HEIGHT-50,100,40);
				DPipe a7(550,SCREEN_HEIGHT-150,100,40);
				DoublePipe b8(750,SCREEN_HEIGHT-50,70,40);
				DPipe a8(550,SCREEN_HEIGHT-250,100,40);
				DoublePipe b9(750,SCREEN_HEIGHT-350,70,40);
				CrossPipe c1(450,SCREEN_HEIGHT-150,100,40);
				DoublePipe b10(350,SCREEN_HEIGHT-450,70,40);
				DPipe a9(750,SCREEN_HEIGHT-150,100,40);
				DPipe a10(750,SCREEN_HEIGHT-250,100,40);
				DoublePipe b11(450,SCREEN_HEIGHT-250,70,40);
				DoublePipe b12(650,SCREEN_HEIGHT-250,70,40);
				DPipe a11(650,SCREEN_HEIGHT-50,100,40);
				DPipe a12(850,SCREEN_HEIGHT-350,100,40);

				DirectPipes[0] = a0; DoublePipes[0] = b0;
				DirectPipes[1] = a1; DoublePipes[1] = b1;
				DirectPipes[2] = a2; DoublePipes[2] = b2;
				DirectPipes[3] = a3; DoublePipes[3] = b3;
				DirectPipes[4] = a4; DoublePipes[4] = b4;
				DirectPipes[5] = a5; DoublePipes[5] = b5;
				DirectPipes[6] = a6; DoublePipes[6] = b6;
				DirectPipes[7] = a7; DoublePipes[7] = b7;
				DirectPipes[8] = a8; DoublePipes[8] = b8;
				DirectPipes[9] = a9; DoublePipes[9] = b9;
				DirectPipes[10] = a10; DoublePipes[10] = b10;
				DirectPipes[11] = a11; DoublePipes[11] = b11;
				DirectPipes[12] = a12; DoublePipes[12] = b12;
				CrossPipes[0] = c0; CrossPipes[1] = c1;
				Water a(20,SCREEN_HEIGHT-50,40,40);
}
示例#20
0
文件: 2fish.c 项目: pktmonky/SLAE
/* the Zero-keyed h function (used by the key setup routine) */
u32 h(u32 X, u32 L[4], int k)
{
    BYTE y0, y1, y2, y3;
    BYTE z0, z1, z2, z3;
    y0 = b0(X);
    y1 = b1(X);
    y2 = b2(X);
    y3 = b3(X);

    switch(k)
    {
	case 4:
	    y0 = Q1[y0] ^ b0(L[3]);
	    y1 = Q0[y1] ^ b1(L[3]);
	    y2 = Q0[y2] ^ b2(L[3]);
	    y3 = Q1[y3] ^ b3(L[3]);
	case 3:
	    y0 = Q1[y0] ^ b0(L[2]);
	    y1 = Q1[y1] ^ b1(L[2]);
	    y2 = Q0[y2] ^ b2(L[2]);
	    y3 = Q0[y3] ^ b3(L[2]);
	case 2:
	    y0 = Q1[  Q0 [ Q0[y0] ^ b0(L[1]) ] ^ b0(L[0]) ];
	    y1 = Q0[  Q0 [ Q1[y1] ^ b1(L[1]) ] ^ b1(L[0]) ];
	    y2 = Q1[  Q1 [ Q0[y2] ^ b2(L[1]) ] ^ b2(L[0]) ];
	    y3 = Q0[  Q1 [ Q1[y3] ^ b3(L[1]) ] ^ b3(L[0]) ];
    }

    /* inline the MDS matrix multiply */
    z0 = multEF[y0] ^ y1 ^         multEF[y2] ^ mult5B[y3]; 
    z1 = multEF[y0] ^ mult5B[y1] ^ y2 ^         multEF[y3]; 
    z2 = mult5B[y0] ^ multEF[y1] ^ multEF[y2] ^ y3; 
    z3 = y0 ^         multEF[y1] ^ mult5B[y2] ^ mult5B[y3]; 

    return BYTES_TO_U32(z0, z1, z2, z3);
}
示例#21
0
int main( void )
{
    BASE b0( 1, 1 );        // change to no arg.s later
    BASE b1( 3, 4 );

    b0.check( 1, 1, "BASE() failed" );
    b1.check( 3, 4, "BASE( 3, 4 ) failed" );
    b0 = b1;
    b0.check( 3, 4, "b0 = b1 failed" );

    DERIVED d0( 1, 1 );     // change to no arg.s later
    DERIVED d1( 5, 6 );

    d0.check( 1, 1, "DERIVED() failed" );
    d1.check( 5, 6, "DERIVED( 3, 4 ) failed" );
    d0 = d1;
    d0.check( 5, 6, "d0 = d1 failed" );

    {   DTOR dummy;
        dtor_called = FALSE;
        dummy = dummy;
    }
    if( ! dtor_called ) {
        printf( "DTOR not dtor'd properly\n" );
        ++ error_count;
    }

    {   class DTOR_DERIVED : public DTOR
        {
          public:
            int x;
        };
        DTOR_DERIVED dummy;
        dtor_called = FALSE;
        dummy.x = 18;
    }
    if( ! dtor_called ) {
        printf( "DTOR not dtor'd properly\n" );
        ++ error_count;
    }

    if( error_count == 0 ) {
        printf( "CHKCL -- passed all tests\n\n" );
    } else {
        printf( "CHKCL -- %d errors noted\n\n", error_count );
    }
    return( error_count != 0 );
}
int main()
{
	Big b0("b0");

	Big b1(b0);
	b1.setName("b1");
	std::cout << std::endl << "现在b1:" << std::endl;
	print(b1);

	Big b2(std::move(makeBig(1, 2, "临时b2") + 4));
	b2.setName("b2");
	std::cout << std::endl << "现在b2:" << std::endl;
	print(b2);

	Big b3("b3");
	b3 = b0;
	b3.setName("变量b3=b0");
	std::cout << std::endl << "现在b3:" << std::endl;
	print(b3);

	Big b4("b4");
	b4 = b0 + 8;
	b4.setName("变量b4=b0+8");
	std::cout << std::endl << "现在b4:" << std::endl;
	print(b4);

	std::cout << "-----------------------" << std::endl;

	std::vector<Big> *v = new std::vector<Big>;
	v->push_back(b0 + 16);
	std::cout << "1st push_back" << std::endl;

	v->push_back(makeBig(32, 64, "临时b5"));
	std::cout << "2nd push_back" << std::endl;

	v->push_back(makeBig(128, 256, "临时b6") + 512);
	std::cout << "3rd push_back" << std::endl;

	std::cout << std::endl << "释放vector<Big>内所有的资源:" << std::endl;
	delete v;

	std::cout << "-----------------------" << std::endl;
	
	std::cout << "程序到达终点,操作系统释放剩余的资源!" << std::endl;
	return 0;
}//main
示例#23
0
double MATHEMATICS::math_det3(Mat_DP m) {
	
	int x=m.nrows(), y=m.ncols();
	double a=0;
	Mat_DP b0(2,2), b1(2,2), b2(2,2);

	if (x!=3||y!=3) {
		cout << "Input matrix is not 3x3";
	}
	else {
		b0[0][0]=m[1][1], b0[0][1]=m[1][2], b0[1][0]=m[2][1], b0[1][1]=m[2][2];
		b1[0][0]=m[1][0], b1[0][1]=m[1][2], b1[1][0]=m[2][0], b1[1][1]=m[2][2];
		b2[0][0]=m[1][0], b2[0][1]=m[1][1], b2[1][0]=m[2][0], b2[1][1]=m[2][1];
		a=m[0][0]*MATHEMATICS::math_det2(b0)-m[0][1]*MATHEMATICS::math_det2(b1)+m[0][2]*MATHEMATICS::math_det2(b2);
	}

	return a;
}
示例#24
0
文件: b_0_49.cpp 项目: jakexie/micmac
template <class Type> void bench_pack_im(Type *,INT vmax,bool quick)
{

	for (INT x=10; x< (quick ? 300 : 1200); x+= 220)
	{
cout << x << "\n";
		Bench_PackB_IM<Type>  b1(Pt2di(x,x),0);
		Bench_PackB_IM<Type>  b0(Pt2di(x,x),FX%vmax);
		Bench_PackB_IM<Type>  b2(Pt2di(x,x),(FX>FY)*vmax);
		Bench_PackB_IM<Type>  b3(Pt2di(x,x),frandr()<0.1);
		Bench_PackB_IM<Type>  b4(Pt2di(x,x),frandr()<(1/128.0));

                b0.DoNothing();
                b1.DoNothing();
                b2.DoNothing();
                b3.DoNothing();
                b4.DoNothing();
	}
}
示例#25
0
void splineInter1D(double *Tc, double *dT, const double *T,
        const double *omega, const double *m, int N, const double *X,
        double *h, bool doDerivative, bool boundary) {
    int xf, i, j, m0 = m[0];
    double x, p;
    
    #pragma omp parallel for default(shared) private(x, xf, p, i, j)
    for (i=0;i<N;i++) {
        Tc[i] = 0;
        
        x = (X[i] - omega[0]) / h[0] + .5 - 1; //subtract 1 for indexing purposes in C
        
        //check if it is a valid x
        if (!boundary && (x<=-2 || x>=m0+1))
            continue;
        
        xf = floor(x);
        x  = x - xf;
        
        if (doDerivative) {
            dT[i] = 0;
        }
        
        for (j=-1;j<3;j++) {
            if (boundary) {
                p = T[min(m0-1,max(0,xf+j))];
            } else {
                p = (xf+j<0 || xf+j>m0-1)? 0: T[xf+j];
            }
            Tc[i] += p*b0(3-j,x-j);
            if (doDerivative) {
                dT[i] += p*db0(3-j,x-j);
            }
        }
        
        if (mxIsNaN(Tc[i]))
            mexPrintf("Is NAN. ");
        
        if (doDerivative) {
            dT[i] = dT[i]/h[0];
        }
    }
}
示例#26
0
Options Colorization::getDefaultOptions()
{
    Options options;

    Option x("x_dim", std::string("X"), "Dimension name to use for 'X' data");
    Option y("y_dim", std::string("Y"), "Dimension name to use for 'Y' data");

    pdal::Option red("dimension", "Red", "");
    pdal::Option b0("band",1, "");
    pdal::Option s0("scale", 1.0f, "scale factor for this dimension");
    pdal::Options redO;
    redO.add(b0);
    redO.add(s0);
    red.setOptions(redO);

    pdal::Option green("dimension", "Green", "");
    pdal::Option b1("band",2, "");
    pdal::Option s1("scale", 1.0f, "scale factor for this dimension");
    pdal::Options greenO;
    greenO.add(b1);
    greenO.add(s1);
    green.setOptions(greenO);

    pdal::Option blue("dimension", "Blue", "");
    pdal::Option b2("band",3, "");
    pdal::Option s2("scale", 1.0f, "scale factor for this dimension");
    pdal::Options blueO;
    blueO.add(b2);
    blueO.add(s2);
    blue.setOptions(blueO);

    pdal::Option reproject("reproject", false, "Reproject the input data into the same coordinate system as the raster?");

    options.add(x);
    options.add(y);
    options.add(red);
    options.add(green);
    options.add(blue);
    options.add(reproject);


    return options;
}
示例#27
0
文件: f.c 项目: PlanetAPL/a-plus
Z H2(xpn){
  A z;
  ND2 I1;
  {I ar=a->r,an=a->n;XW;
   I bn=b0(a->p,an),wl=wr?*wd:1;
   aw=0;
   Q(bn<0,9)
   Q(ar>1,7)
   if(!wr) wl=wr=1;
   if(wn==1) aw=2;
   else Q(wl!=bn,8)
   if(wr==1&&wt!=Et){
     W(gv(wt,an))
     C2((I(*)())(!wt?(I(*)())x0:wt==Ft?(I(*)())x1:(I(*)())x2))
   }
   v=tr(wr-1,wd+1);
   u=wn;
   W(ga(t=wt,wr,an*v,wd))*z->d=an;
   C2(x3)
}}
示例#28
0
Options AttributeFilter::getDefaultOptions()
{
    Options options;

    pdal::Option red("dimension", "Classification", "");
    pdal::Option b0("value","0", "");
    pdal::Option geometry("geometry","POLYGON ((30 10, 40 40, 20 40, 10 20, 30 10))", "");
    pdal::Option query("query","", "");
    pdal::Option layer("layer","", "");
    pdal::Option datasource("datasource","", "");
    pdal::Options redO;
    redO.add(b0);
    redO.add(geometry);
    redO.add(query);
    redO.add(layer);
    redO.add(datasource);
    red.setOptions(redO);

    options.add(red);

    return options;
}
示例#29
0
osgToy::PenroseTriangle::PenroseTriangle()
{
    setOverallColor( osg::Vec4(1,0,0,1) );

    osg::Vec3 a0(  0.1,  0.2,  1.2 );
    osg::Vec3 a1(  0.1,  0.2,  0.8 );
    osg::Vec3 a2( -0.1, -0.2,  0.8 );
    osg::Vec3 a3( -0.1, -0.2,  1.2 );

    osg::Vec3 b0(  0.9892,  0.2, -0.6866 );     // rotate 120 degrees
    osg::Vec3 b1(  0.6428,  0.2, -0.4866 );
    osg::Vec3 b2(  0.7428, -0.2, -0.3134 );
    osg::Vec3 b3(  1.0892, -0.2, -0.5134 );

    osg::Vec3 c0( -1.0892,  0.2, -0.5134 );     // rotate 240 degrees
    osg::Vec3 c1( -0.7428,  0.2, -0.3134 );
    osg::Vec3 c2( -0.6428, -0.2, -0.4866 );
    osg::Vec3 c3( -0.9892, -0.2, -0.6866 );

    const unsigned int NUM_QUADS = 16;

    addTristrip( a1, a0, b0, b3, NUM_QUADS );
    addTristrip( b1, b0, c0, c3, NUM_QUADS );
    addTristrip( c1, c0, a0, a3, NUM_QUADS );

    addTristrip( a2, a1, b1, b0, NUM_QUADS );
    addTristrip( b2, b1, c1, c0, NUM_QUADS );
    addTristrip( c2, c1, a1, a0, NUM_QUADS );

    addTristrip( a0, a3, b3, b2, NUM_QUADS );
    addTristrip( b0, b3, c3, c2, NUM_QUADS );
    addTristrip( c0, c3, a3, a2, NUM_QUADS );

    addTristrip( a3, a2, b2, b1, NUM_QUADS );
    addTristrip( b3, b2, c2, c1, NUM_QUADS );
    addTristrip( c3, c2, a2, a1, NUM_QUADS );

    osgToy::FacetingVisitor::facet( *this );
}
示例#30
0
int main()
{
    GeneralInteger a1(3);
    GeneralInteger a0(2);
    GeneralInteger b1(1);
    GeneralInteger b0(1);
    GeneralInteger a(0), b(0);
    for(unsigned int i = 3; i <= 100; ++i){
         int mult = 1;
         if(i%3 == 0) 
             mult = 2*(i/3);
         a = a1.multiply(mult) + a0;
         b = b1.multiply(mult) + b0;
         a0 = a1; 
         b0 = b1;
         a1 = a;
         b1 = b;
    }
    vector<int>& vn = a1.getNumber();
    int sum = accumulate(vn.begin(), vn.end(), 0);
    printf("%d\n", sum);
}