Ejemplo n.º 1
0
void
PreviewThread::quitThread()
{
    if (!isRunning()) {
        return;
    }
    QMutexLocker k(&_imp->mustQuitMutex);
    assert(!_imp->mustQuit);
    _imp->mustQuit = true;
    
    {
        QMutexLocker k2(&_imp->previewQueueMutex);
        ComputePreviewRequest r;
        r.node = NodeGuiPtr();
        r.time = 0;
        _imp->previewQueue.push_back(r);
        _imp->previewQueueNotEmptyCond.wakeOne();
    }
    while (_imp->mustQuit) {
        _imp->mustQuitCond.wait(&_imp->mustQuitMutex);
    }
    
    {
        QMutexLocker k2(&_imp->previewQueueMutex);
        _imp->previewQueue.clear();
    }
}
Ejemplo n.º 2
0
//-----------------------------------------------------------------------------
// github issue #388
BOOST_AUTO_TEST_CASE_TEMPLATE(
    waitForEventThatAlreadyFinishedShouldBeSkipped,
    TDevStream,
    TestStreams)
{
    using Fixture = alpaka::test::stream::StreamTestFixture<TDevStream>;
    using Stream = typename Fixture::Stream;
    using Dev = typename Fixture::Dev;

    if(!alpaka::test::stream::IsSyncStream<Stream>::value)
    {
        Fixture f1;
        Fixture f2;
        auto s1 = f1.m_stream;
        auto s2 = f2.m_stream;
        alpaka::test::event::EventHostManualTrigger<Dev> k1(f1.m_dev);
        alpaka::test::event::EventHostManualTrigger<Dev> k2(f2.m_dev);
        alpaka::event::Event<Stream> e1(f1.m_dev);

        // 1. kernel k1 is enqueued into stream s1
        // s1 = [k1]
        alpaka::stream::enqueue(s1, k1);
        // 2. kernel k2 is enqueued into stream s2
        // s2 = [k2]
        alpaka::stream::enqueue(s2, k2);

        // 3. event e1 is enqueued into stream s1
        // s1 = [k1, e1]
        alpaka::stream::enqueue(s1, e1);

        // 4. s2 waits for e1
        // s2 = [k2, ->e1]
        alpaka::wait::wait(s2, e1);

        // 5. kernel k1 finishes
        // s1 = [e1]
        k1.trigger();

        // 6. e1 is finished
        // s1 = []
        alpaka::wait::wait(e1);
        BOOST_REQUIRE_EQUAL(true, alpaka::event::test(e1));

        // 7. e1 is re-enqueued again but this time into s2
        // s2 = [k2, ->e1, e1]
        alpaka::stream::enqueue(s2, e1);

        // 8. kernel k2 finishes
        // s2 = [->e1, e1]
        k2.trigger();

        // 9. e1 had already been signaled so there should not be waited even though the event is now reused within s2 and its current state is 'unfinished' again.
        // s2 = [e1]

        // Both streams should successfully finish
        alpaka::wait::wait(s1);
        // s2 = []
        alpaka::wait::wait(s2);
    }
}
Ejemplo n.º 3
0
void RK4_step(                          // replaces x(t) by x(t + dt)
    Matrix<double,1>& x,                // solution vector
    double dt,                          // fixed time step
    Matrix<double,1> flow(Matrix<double,1>&))   // derivative vector
{
    int n = x.size();
    Matrix<double,1> f(n), k1(n), k2(n), k3(n), k4(n), x_temp(n);
    f = flow(x);
    for (int i = 0; i < n; i++) {
        k1[i] = dt * f[i];
        x_temp[i] = x[i] + k1[i] / 2;
    }
    f = flow(x_temp);
    for (int i = 0; i < n; i++) {
        k2[i] = dt * f[i];
        x_temp[i] = x[i] + k2[i] / 2;
    }
    f = flow(x_temp);
    for (int i = 0; i < n; i++) {
        k3[i] = dt * f[i];
        x_temp[i] = x[i] + k3[i];
    }
    f = flow(x_temp);
    for (int i = 0; i < n; i++)
        k4[i] = dt * f[i];
    for (int i = 0; i < n; i++)
        x[i] += (k1[i] + 2 * k2[i] + 2 * k3[i] + k4[i]) / 6;
}
Ejemplo n.º 4
0
 TEST(KeyBtreeTest, put_overwrite)
 {
   KeyBtree<KeyInfo, int> btr(sizeof(KeyInfo));
   KeyInfo k1(10, 1);
   KeyInfo k2(10, 2);
   KeyInfo key(1, 1);
   int value, old_value;
   EXPECT_EQ(btr.put(k1, 100), ERROR_CODE_OK);
   EXPECT_EQ(btr.put(k2, 101, true), ERROR_CODE_OK);
   {
     BtreeReadHandle handle;
     btr.get_read_handle(handle);
     btr.set_key_range(handle, btr.get_min_key(), 0, btr.get_max_key(), 0);
     EXPECT_EQ(btr.get_next(handle, key, value), ERROR_CODE_OK);
     EXPECT_EQ(value, 101);
     EXPECT_EQ(key.b_, 1);
   }
   // overwrite key
   EXPECT_EQ(btr.put(k2, 102, old_value, true, true), ERROR_CODE_OK);
   {
     BtreeReadHandle handle;
     btr.get_read_handle(handle);
     btr.set_key_range(handle, btr.get_min_key(), 0, btr.get_max_key(), 0);
     EXPECT_EQ(btr.get_next(handle, key, value), ERROR_CODE_OK);
     EXPECT_EQ(old_value, 101);
     EXPECT_EQ(value, 102);
     EXPECT_EQ(key.b_, 2);
   }
 }
Ejemplo n.º 5
0
bool
GenericSchedulerThread::startTask(const ThreadStartArgsPtr& inArgs)
{
    {
        QMutexLocker quitLocker(&_imp->mustQuitMutex);
        if (!_imp->startingThreadAllowed || _imp->mustQuit) {
            return false;
        }
    }

    {
        QMutexLocker k1(&_imp->enqueuedTasksMutex);
        QMutexLocker k2(&_imp->abortRequestedMutex);
#ifdef TRACE_GENERIC_SCHEDULER_THREAD
        qDebug() << QThread::currentThread() << ": Requesting task on" <<  getThreadName().c_str() << ", is thread aborted?" << (bool)(_imp->abortRequested > 0);
#endif
        if (_imp->abortRequested > 0) {
            _imp->queuedTaskWhileProcessingAbort.push_back(inArgs);
        } else {
            _imp->enqueuedTasks.push_back(inArgs);
        }
    }

    if ( !isRunning() ) {
        start();
    } else {
        ///Wake up the thread with a start request
        QMutexLocker locker(&_imp->startRequestsMutex);
        ++_imp->startRequests;

        _imp->startRequestsCond.wakeOne();
    }

    return true;
}
Ejemplo n.º 6
0
TPZCompMesh * ComputationalMesh(TPZGeoMesh * gmesh, int p)
{
    int matid = 1;
    int dim = 2;
    REAL wavespeed = 1.0;

    ///Computational Mesh
    TPZCompEl::SetgOrder(p);
    TPZCompMesh * cmesh = new TPZCompMesh(gmesh);
    cmesh->SetDimModel(dim);    
    cmesh->SetAllCreateFunctionsContinuous();
    
    TPZMaterial * Air = new TPZLinearWave(matid,dim);
    cmesh->InsertMaterialObject(Air);
    
    {
        //Boundary Conditions
        TPZFMatrix<STATE> k1(dim,dim,0.), k2(dim,dim,0.);
        TPZMaterial * BCD = Air->CreateBC(Air, 2, 0, k1, k2);
        cmesh->InsertMaterialObject(BCD);
        
        TPZMaterial * BCN = Air->CreateBC(Air, 3, 1, k1, k2);
        cmesh->InsertMaterialObject(BCN);
    }   
        
    cmesh->AutoBuild();
    cmesh->AdjustBoundaryElements();
    cmesh->CleanUpUnconnectedNodes();    
    
    return cmesh;
}
Ejemplo n.º 7
0
/**
 * returns the modified spherical Bessel function of the second kind needed
 * for bound states.
 \param l = order of the function (orbital angular momentum)
 \param rho = independent variable (rho = k * r)
 */
double sphericalB::k(int l, double rho)
{
  switch (l)
    {
    case 0:
      return k0(rho);
    case 1:
      return k1(rho);
    case 2: 
      return k2(rho);
    case 3: 
      return k3(rho);
    case 4:
      return k4(rho);
    case 5:
      return k5(rho);
    case 6:
      return k6(rho);
    case 7:
      return k7(rho);
    default:
      cout << "no l>6 programed in sphericalB" << endl;
      return 0.;
    }
}
Ejemplo n.º 8
0
static bool ocl_integral( InputArray _src, OutputArray _sum, int sdepth )
{
    if ( _src.type() != CV_8UC1 || _src.step() % vlen != 0 || _src.offset() % vlen != 0  ||
         !(sdepth == CV_32S || sdepth == CV_32F) )
        return false;

    ocl::Kernel k1("integral_sum_cols", ocl::imgproc::integral_sum_oclsrc,
                   format("-D sdepth=%d", sdepth));
    if (k1.empty())
        return false;

    Size size = _src.size(), t_size = Size(((size.height + vlen - 1) / vlen) * vlen, size.width),
            ssize(size.width + 1, size.height + 1);
    _sum.create(ssize, sdepth);
    UMat src = _src.getUMat(), t_sum(t_size, sdepth), sum = _sum.getUMat();
    t_sum = t_sum(Range::all(), Range(0, size.height));

    int offset = (int)src.offset / vlen, pre_invalid = (int)src.offset % vlen;
    int vcols = (pre_invalid + src.cols + vlen - 1) / vlen;
    int sum_offset = (int)sum.offset / vlen;

    k1.args(ocl::KernelArg::PtrReadOnly(src), ocl::KernelArg::PtrWriteOnly(t_sum),
            offset, pre_invalid, src.rows, src.cols, (int)src.step, (int)t_sum.step);
    size_t gt = ((vcols + 1) / 2) * 256, lt = 256;
    if (!k1.run(1, &gt, &lt, false))
        return false;

    ocl::Kernel k2("integral_sum_rows", ocl::imgproc::integral_sum_oclsrc,
                   format("-D sdepth=%d", sdepth));
    k2.args(ocl::KernelArg::PtrReadWrite(t_sum), ocl::KernelArg::PtrWriteOnly(sum),
            t_sum.rows, t_sum.cols, (int)t_sum.step, (int)sum.step, sum_offset);

    size_t gt2 = t_sum.cols  * 32, lt2 = 256;
    return k2.run(1, &gt2, &lt2, false);
}
Ejemplo n.º 9
0
void build_kernel(Binary<expr::op::Sub, L, R> e, Kernel<T>& k)
{
  Kernel_builder<L, T>::apply(e.arg1(), k);
  Kernel<T> k2(k);
  Kernel_builder<R, T>::apply(e.arg2(), k2);
  k -= k2;
}
Ejemplo n.º 10
0
	void simpleMatrixTest::testConstructor()
	{
		matrix<int> a = matrix<int>(4, 3);
		Assert(a.nrows == 4 && a.ncols == 3, "Constructor 1 failed");
		matrix<int> b;
		b = matrix<int>(5, 6);
		Assert(b.nrows == 5 && b.ncols == 6, "Constructor 2 failed");
		matrix<int> c = matrix<int>();
		Assert(c.nrows == 0 && c.ncols == 0, "Constructor 3 failed");
		matrix<int> d = c;
		Assert(d.nrows == 0 && d.ncols == 0, "Constructor 4 failed");

		matrix<int> a2 = matrix<int>(4, 3, true);
		Assert(a2.nrows == 4 && a2.ncols == 3, "Constructor 1 failed");
		matrix<int> b2;
		b2 = matrix<int>(5, 6, true);
		Assert(b2.nrows == 5 && b2.ncols == 6, "Constructor 2 failed");

		double* e = new double[8];
		for (int i = 0; i < 8; i++)
			e[i] = static_cast<double>(i*2);
		double f[6] = {1.0, 2.0, 3.0, 4.0, 5.0, 6.0};

		matrix<double> g = matrix<double>(4, 2, e);
		matrix<double> g2 = matrix<double>(4, 2, e, true);
		for (int i = 0; i < 4; i++)
		{
			for (int j = 0; j < 2; j++)
			{
				Assert(g(i, j) == e[j*4+i], "Constructor 5 failed");
				Assert(g2(i, j) == e[i*2 + j], "Constructor 5 failed");
			}
		}

		matrix<double> h = matrix<double>(3, 2, f);
		matrix<double> h2 = matrix<double>(3, 2, f, true);
		for (int i = 0; i < 3; i++)
		{
			for (int j = 0; j < 2; j++)
			{
				Assert(h(i, j) == f[j*3 + i], "Constructor 6 failed");
				Assert(h2(i, j) == f[i*2 + j], "Constructor 6 failed");
			}
		}

		matrix<double> k = h;
		matrix<double> k2 = h2;
		for (int i = 0; i < 3; i++)
		{
			for (int j = 0; j < 2; j++)
			{
				Assert(k(i, j) == f[j*3+i], "Constructor 7 failed");
				Assert(k2(i, j) == f[i*2+j], "Constructor 7 failed");
			}
		}

		matrix<unsigned int> * m = new matrix<unsigned int>(1, 10);
		Assert(m->nrows == 1 && m->ncols == 10, "Constructor 8 failed");
	}
Ejemplo n.º 11
0
TextStream& SVGFEComposite::externalRepresentation(TextStream& ts) const
{
    ts << "[type=COMPOSITE] ";
    SVGFilterEffect::externalRepresentation(ts);
    if (!in2().isEmpty())
        ts << " [in2=\"" << in2() << "\"]";
    ts << " [k1=" << k1() << " k2=" << k2() << " k3=" << k3() << " k4=" << k4() << "]";
    return ts;
}
Ejemplo n.º 12
0
FloatRect FEComposite::determineAbsolutePaintRect(const FloatRect& originalRequestedRect)
{
    FloatRect requestedRect = originalRequestedRect;
    if (clipsToBounds())
        requestedRect.intersect(maxEffectRect());

    // We may be called multiple times if result is used more than once. Return
    // quickly if nothing new is required.
    if (absolutePaintRect().contains(enclosingIntRect(requestedRect)))
        return requestedRect;

    // No mapPaintRect required for FEComposite.
    FloatRect input1Rect = inputEffect(1)->determineAbsolutePaintRect(requestedRect);
    FloatRect affectedRect;
    switch (m_type) {
    case FECOMPOSITE_OPERATOR_IN:
        // 'in' has output only in the intersection of both inputs.
        affectedRect = intersection(input1Rect, inputEffect(0)->determineAbsolutePaintRect(input1Rect));
        break;
    case FECOMPOSITE_OPERATOR_ATOP:
        // 'atop' has output only in the extents of the second input.
        // Make sure first input knows where it needs to produce output.
        inputEffect(0)->determineAbsolutePaintRect(input1Rect);
        affectedRect = input1Rect;
        break;
    case FECOMPOSITE_OPERATOR_ARITHMETIC:
        if (k4() > 0) {
            // Make sure first input knows where it needs to produce output.
            inputEffect(0)->determineAbsolutePaintRect(requestedRect);
            // Arithmetic with non-zero k4 may influnce the complete filter primitive
            // region. So we can't optimize the paint region here.
            affectedRect = requestedRect;
            break;
        }
        if (k2() <= 0) {
            // Input 0 does not appear where input 1 is not present.
            FloatRect input0Rect = inputEffect(0)->determineAbsolutePaintRect(input1Rect);
            if (k3() > 0) {
                affectedRect = input1Rect;
            } else {
                // Just k1 is positive. Use intersection.
                affectedRect = intersection(input1Rect, input0Rect);
            }
            break;
        }
        // else fall through to use union
    default:
        // Take the union of both input effects.
        affectedRect = unionRect(input1Rect, inputEffect(0)->determineAbsolutePaintRect(requestedRect));
        break;
    }

    affectedRect.intersect(requestedRect);
    addAbsolutePaintRect(affectedRect);
    return affectedRect;
}
Ejemplo n.º 13
0
static bool ocl_integral( InputArray _src, OutputArray _sum, OutputArray _sqsum, int sdepth, int sqdepth )
{
    bool doubleSupport = ocl::Device::getDefault().doubleFPConfig() > 0;

    if ( _src.type() != CV_8UC1 || _src.step() % vlen != 0 || _src.offset() % vlen != 0 ||
         (!doubleSupport && (sdepth == CV_64F || sqdepth == CV_64F)) )
        return false;

    char cvt[40];
    String opts = format("-D sdepth=%d -D sqdepth=%d -D TYPE=%s -D TYPE4=%s4 -D convert_TYPE4=%s%s",
                         sdepth, sqdepth, ocl::typeToStr(sqdepth), ocl::typeToStr(sqdepth),
                         ocl::convertTypeStr(sdepth, sqdepth, 4, cvt),
                         doubleSupport ? " -D DOUBLE_SUPPORT" : "");

    ocl::Kernel k1("integral_cols", ocl::imgproc::integral_sqrsum_oclsrc, opts);
    if (k1.empty())
        return false;

    Size size = _src.size(), dsize = Size(size.width + 1, size.height + 1),
            t_size = Size(((size.height + vlen - 1) / vlen) * vlen, size.width);
    UMat src = _src.getUMat(), t_sum(t_size, sdepth), t_sqsum(t_size, sqdepth);
    t_sum = t_sum(Range::all(), Range(0, size.height));
    t_sqsum = t_sqsum(Range::all(), Range(0, size.height));

    _sum.create(dsize, sdepth);
    _sqsum.create(dsize, sqdepth);
    UMat sum = _sum.getUMat(), sqsum = _sqsum.getUMat();

    int offset = src.offset / vlen;
    int pre_invalid = src.offset % vlen;
    int vcols = (pre_invalid + src.cols + vlen - 1) / vlen;
    int sum_offset = sum.offset / sum.elemSize();
    int sqsum_offset = sqsum.offset / sqsum.elemSize();
    CV_Assert(sqsum.offset % sqsum.elemSize() == 0);

    k1.args(ocl::KernelArg::PtrReadOnly(src), ocl::KernelArg::PtrWriteOnly(t_sum),
            ocl::KernelArg::PtrWriteOnly(t_sqsum), offset, pre_invalid, src.rows,
            src.cols, (int)src.step, (int)t_sum.step, (int)t_sqsum.step);

    size_t gt = ((vcols + 1) / 2) * 256, lt = 256;
    if (!k1.run(1, &gt, &lt, false))
        return false;

    ocl::Kernel k2("integral_rows", ocl::imgproc::integral_sqrsum_oclsrc, opts);
    if (k2.empty())
        return false;

    k2.args(ocl::KernelArg::PtrReadOnly(t_sum), ocl::KernelArg::PtrReadOnly(t_sqsum),
            ocl::KernelArg::PtrWriteOnly(sum), ocl::KernelArg::PtrWriteOnly(sqsum),
            t_sum.rows, t_sum.cols, (int)t_sum.step, (int)t_sqsum.step,
            (int)sum.step, (int)sqsum.step, sum_offset, sqsum_offset);

    size_t gt2 = t_sum.cols  * 32, lt2 = 256;
    return k2.run(1, &gt2, &lt2, false);
}
Ejemplo n.º 14
0
        void uniqueIndexCompatibleTest() {
            ShardKeyPattern k1( BSON( "a" << 1 ) );
            verify( k1.isUniqueIndexCompatible( BSON( "_id" << 1 ) ) );
            verify( k1.isUniqueIndexCompatible( BSON( "a" << 1 << "b" << 1 ) ) );
            verify( k1.isUniqueIndexCompatible( BSON( "a" << -1 ) ) );
            verify( ! k1.isUniqueIndexCompatible( BSON( "b" << 1 ) ) );

            ShardKeyPattern k2( BSON( "a" <<  "hashed") );
            verify( k2.isUniqueIndexCompatible( BSON( "a" << 1 ) ) );
            verify( ! k2.isUniqueIndexCompatible( BSON( "b" << 1 ) ) );
        }
Ejemplo n.º 15
0
PassRefPtr<FilterEffect> SVGFECompositeElement::build(SVGFilterBuilder* filterBuilder)
{
    FilterEffect* input1 = filterBuilder->getEffectById(in1());
    FilterEffect* input2 = filterBuilder->getEffectById(in2());
    
    if (!input1 || !input2)
        return 0;
    
    return FEComposite::create(input1, input2, static_cast<CompositeOperationType>(_operator()),
                                        k1(), k2(), k3(), k4());
}
Ejemplo n.º 16
0
//-----------------------------------------------------------------------------
BOOST_AUTO_TEST_CASE_TEMPLATE(
    eventReEnqueueShouldBePossibleIfNobodyWaitsFor,
    TDevStream,
    TestStreams)
{
    using Fixture = alpaka::test::stream::StreamTestFixture<TDevStream>;
    using Stream = typename Fixture::Stream;
    using Dev = typename Fixture::Dev;

    if(!alpaka::test::stream::IsSyncStream<Stream>::value)
    {
        Fixture f1;
        auto s1 = f1.m_stream;
        alpaka::event::Event<Stream> e1(f1.m_dev);
        alpaka::test::event::EventHostManualTrigger<Dev> k1(f1.m_dev);
        alpaka::test::event::EventHostManualTrigger<Dev> k2(f1.m_dev);

        // s1 = [k1]
        alpaka::stream::enqueue(s1, k1);
        BOOST_REQUIRE_EQUAL(false, alpaka::event::test(k1));

        // s1 = [k1, e1]
        alpaka::stream::enqueue(s1, e1);
        BOOST_REQUIRE_EQUAL(false, alpaka::event::test(k1));
        BOOST_REQUIRE_EQUAL(false, alpaka::event::test(e1));

        // s1 = [k1, e1, k2]
        alpaka::stream::enqueue(s1, k2);
        BOOST_REQUIRE_EQUAL(false, alpaka::event::test(k1));
        BOOST_REQUIRE_EQUAL(false, alpaka::event::test(e1));
        BOOST_REQUIRE_EQUAL(false, alpaka::event::test(k2));

        // re-enqueue should be possible
        // s1 = [k1, k2, e1]
        alpaka::stream::enqueue(s1, e1);
        BOOST_REQUIRE_EQUAL(false, alpaka::event::test(k1));
        BOOST_REQUIRE_EQUAL(false, alpaka::event::test(k2));
        BOOST_REQUIRE_EQUAL(false, alpaka::event::test(e1));

        // s1 = [k2, e1]
        k1.trigger();
        BOOST_REQUIRE_EQUAL(true, alpaka::event::test(k1));
        BOOST_REQUIRE_EQUAL(false, alpaka::event::test(k2));
        BOOST_REQUIRE_EQUAL(false, alpaka::event::test(e1));

        // s1 = [e1]
        k2.trigger();
        BOOST_REQUIRE_EQUAL(true, alpaka::event::test(k2));
        alpaka::wait::wait(e1);
        BOOST_REQUIRE_EQUAL(true, alpaka::event::test(e1));
    }
}
Ejemplo n.º 17
0
int main()
{
  try
    {
      symbol k("k"),q("q"),p("p"),p1("p1"),p2("p2"),p3("p3"),ms("ms"),l("l"),s("s"),m1s("m1s"),m2s("m2s"),m3s("m3s");
      symbol l1("l1"),l2("l2"),l3("l3"),l4("l4"),t("t"),p4("p4"),p5("p5"),p6("p6"),tp("tp"),v1("v1"),v2("v2"),l5("l5");
      symbol k1("k1"),k2("k2"),k3("k3"),k4("k4"),k5("k5"),ms1("ms1"),ms2("ms2"),ms3("ms3"),ms4("ms4");
      symbol s12("s12"),s23("s23"),s34("s34"),s45("s45"),s51("s51"),s13("s13"),s15("s15"),s56("s56"),s16("s16"),s123("s123"),s234("s234"),s345("s345");
      lst inv_l;
      inv_l.append(p1*p1 == 0);
      inv_l.append( p2*p2 == 0);inv_l.append( p3*p3  ==  0);inv_l.append( p4*p4  ==  0);inv_l.append( p5*p5  ==  0);inv_l.append( p6*p6  ==  0);
      inv_l.append(p1* p2  ==  s12/2);inv_l.append( p2* p3  ==  s23/2);inv_l.append( p3* p4  ==  s34/2);inv_l.append( p4* p5  ==  s45/2);
      inv_l.append(p5* p6  ==  s56/2);inv_l.append( p1* p6  ==  s16/2);inv_l.append( p1* p3  ==  (-s12 + s123 - s23)/2);
      inv_l.append(p2* p4  ==  (-s23 + s234 - s34)/2);
      inv_l.append( p3* p5  ==  (-s34 + s345 - s45)/2);
      inv_l.append(p1* p4  ==  (-s123 + s23 - s234 + s56)/2);
      inv_l.append(p1* p5  ==  (-s16 + s234 - s56)/2);
      inv_l.append( p2* p5  ==  (s16 - s234 + s34 - s345)/2);
      inv_l.append( p2* p6  ==  (-s12 - s16 + s345)/2);
      inv_l.append( p3* p6  ==  (s12 - s123 - s345 + s45)/2);
      inv_l.append( p4* p6  ==  (s123 - s45 - s56)/2);
      
      
      RoMB_loop_by_loop hexag(lst(k1),
                              lst(-pow(p1 + k1,2),-pow(p1 + p2 + k1,2),
                                  -pow(p1 + p2 + p3 + k1,2),
                                  -pow(p1 + p2 + p3 + p4 + k1,2),
                                  -pow(p1+p2+p3+p4+p5+k1,2),-pow(k1,2)),
                              inv_l,
                              lst(1,1,1,1,1,1),true);
      hexag.integrate_map(lst(s12 == -1, s23 == -2, s34 == -3, s45 == -4, s56 == -5, s16 == -6, s123 == -7, s234 == -8, s345 == -9));
/*

 FRESULT for parameters: {s12==-1,s23==-2,s34==-3,s45==-4,s56==-5,s16==-6,s123==-7,s234==-8,s345==-9}
 
  FRESULT anl :           = -0.1955084880526298663-1/240*log(8)*log(6)+947/60480*log(2)^2-1/480*log(6)*log(4)+1/1080*log(3)*log(7)+131/7560*log(9)*log(2)+19/1260*log(9)^2-1/560*log(8)*log(4)+523/60480*log(3)^2-1/1080*log(7)*log(5)+41/4320*log(3)*log(5)-1/48*log(8)*log(5)-1/1080*log(7)*log(4)+22/945*log(6)*log(7)+19/3780*log(3)*log(4)+493/30240*Pi^2+43/1008*eps^(-2)+49/8640*log(5)^2-641/30240*log(2)*log(6)+1/1080*log(9)*log(5)-22/945*log(2)*log(7)+271/60480*log(4)^2-3/112*log(8)*log(3)-19/3780*log(9)*log(4)+1/1080*log(4)*log(5)-61/2520*log(9)*log(7)+61/5040*log(7)^2+1/168*log(3)*log(2)+1/168*log(8)*log(9)+13/3360*log(2)*log(4)-1/30240*(-1132.7960047725738361+576*log(8)-163*log(3)+264*log(9)+533*log(2)-479*log(6)-444*log(7)+271*log(4)-287*log(5))*eps^(-1)+47/1680*log(8)^2-17/1680*log(8)*log(2)+767/60480*log(6)^2-22/945*log(9)*log(6)-13/1890*log(3)*log(9)
   FRESULT num:           = 1.9907333428263254975E-4+(0.032177795803854872908)*eps^(-1)+(0.04265873015873015873)*eps^(-2)
    eps^-2 term: 43/1008 +/- 0
     eps^-1 term: 0.03746018534300839405-2/105*log(8)+163/30240*log(3)-11/1260*log(9)-533/30240*log(2)+479/30240*log(6)+37/2520*log(7)-271/30240*log(4)+41/4320*log(5) +/- 9.022403780167233619E-6
      eps^0 term: -0.1955084880526298663-1/240*log(8)*log(6)+947/60480*log(2)^2-1/480*log(6)*log(4)+1/1080*log(3)*log(7)+131/7560*log(9)*log(2)+19/1260*log(9)^2-1/560*log(8)*log(4)+523/60480*log(3)^2-1/1080*log(7)*log(5)+41/4320*log(3)*log(5)-1/48*log(8)*log(5)-1/1080*log(7)*log(4)+22/945*log(6)*log(7)+19/3780*log(3)*log(4)+493/30240*Pi^2+49/8640*log(5)^2-641/30240*log(2)*log(6)+1/1080*log(9)*log(5)-22/945*log(2)*log(7)+271/60480*log(4)^2-3/112*log(8)*log(3)-19/3780*log(9)*log(4)+1/1080*log(4)*log(5)-61/2520*log(9)*log(7)+61/5040*log(7)^2+1/168*log(3)*log(2)+1/168*log(8)*log(9)+13/3360*log(2)*log(4)+47/1680*log(8)^2-17/1680*log(8)*log(2)+767/60480*log(6)^2-22/945*log(9)*log(6)-13/1890*log(3)*log(9) +/- 1.04620404922048185285E-4
      */

    }
  catch(std::exception &p)
    {
      std::cerr<<"******************************************************************"<<endl;
      std::cerr<<"   >>>ERROR:  "<<p.what()<<endl;
      std::cerr<<"******************************************************************"<<endl;
      return 1;
    }
  return 0;
}
Ejemplo n.º 18
0
inline OutputIterator copy_if_impl(InputIterator first,
                                   InputIterator last,
                                   OutputIterator result,
                                   Predicate predicate,
                                   bool copyIndex,
                                   command_queue &queue)
{
    typedef typename std::iterator_traits<OutputIterator>::difference_type difference_type;

    size_t count = detail::iterator_range_size(first, last);
    if(count == 0){
        return result;
    }

    const context &context = queue.get_context();

    // storage for destination indices
    ::boost::compute::vector<cl_uint> indices(count, context);

    // write counts
    ::boost::compute::detail::meta_kernel k1("copy_if_write_counts");
    k1 << indices.begin()[k1.get_global_id(0)] << " = "
           << predicate(first[k1.get_global_id(0)]) << " ? 1 : 0;\n";
    k1.exec_1d(queue, 0, count);

    // count number of elements to be copied
    size_t copied_element_count =
        ::boost::compute::count(indices.begin(), indices.end(), 1, queue);

    // scan indices
    ::boost::compute::exclusive_scan(indices.begin(),
                                     indices.end(),
                                     indices.begin(),
                                     queue);

    // copy values
    ::boost::compute::detail::meta_kernel k2("copy_if_do_copy");
    k2 << "if(" << predicate(first[k2.get_global_id(0)]) << ")" <<
          "    " << result[indices.begin()[k2.get_global_id(0)]] << "=";

    if(copyIndex){
        k2 << k2.get_global_id(0) << ";\n";
    }
    else {
        k2 << first[k2.get_global_id(0)] << ";\n";
    }

    k2.exec_1d(queue, 0, count);

    return result + static_cast<difference_type>(copied_element_count);
}
Ejemplo n.º 19
0
	void simpleMatrixTest::testUnsafeConstructor()
	{
		matrix_unsafe<int> c = matrix_unsafe<int>();
		Assert(c.nrows == 0 && c.ncols == 0, "Unsafe Constructor 3 failed");
		matrix_unsafe<int> d = c;
		Assert(d.nrows == 0 && d.ncols == 0, "Unsafe Constructor 4 failed");

		double* e = new double[8];
		for (int i = 0; i < 8; i++)
			e[i] = static_cast<double>(i*2);
		double f[6] = {1.0, 2.0, 3.0, 4.0, 5.0, 6.0};

		matrix_unsafe<double> g = matrix_unsafe<double>(4, 2, e);
		matrix_unsafe<double> g2 = matrix_unsafe<double>(4, 2, e, true);
		for (int i = 0; i < 4; i++)
		{
			for (int j = 0; j < 2; j++)
			{
				Assert(g(i, j) == e[j*4+i], "Unsafe Constructor 5 failed");
				Assert(g2(i, j) == e[i*2+j], "Unsafe Constructor 5 failed");
			}
		}

		matrix_unsafe<double> h = matrix_unsafe<double>(3, 2, f);
		matrix_unsafe<double> h2 = matrix_unsafe<double>(3, 2, f, true);
		for (int i = 0; i < 3; i++)
		{
			for (int j = 0; j < 2; j++)
			{
				Assert(h(i, j) == f[j*3+i], "Unsafe Constructor 6 failed");
				Assert(h2(i, j) == f[i*2+j], "Unsafe Constructor 6 failed");
			}
		}

		matrix_unsafe<double> k = h;
		matrix_unsafe<double> k2 = h2;
		for (int i = 0; i < 3; i++)
		{
			for (int j = 0; j < 2; j++)
			{
				Assert(k(i, j) == f[j*3+i], "Unsafe Constructor 7 failed");
				Assert(k2(i, j) == f[i*2+j], "Unsafe Constructor 7 failed");
			}
		}
		
		int w[3] = {1,2,3};
		matrix_unsafe<int> z = matrix_unsafe<int>(1,3,w);
		Assert(z(0,0) == w[0], "Unsafe Constructor 8 failed");
		Assert(z(0,1) == w[1], "Unsafe Constructor 8 failed");
		Assert(z(0,2) == w[2], "Unsafe Constructor 8 failed");
	}
Ejemplo n.º 20
0
bool SVGFECompositeElement::build(SVGResourceFilter* filterResource)
{
    FilterEffect* input1 = filterResource->builder()->getEffectById(in1());
    FilterEffect* input2 = filterResource->builder()->getEffectById(in2());
    
    if(!input1 || !input2)
        return false;
    
    RefPtr<FilterEffect> effect = FEComposite::create(input1, input2, static_cast<CompositeOperationType>(_operator()),
                                        k1(), k2(), k3(), k4());
    filterResource->addFilterEffect(this, effect.release());

    return true;
}
Ejemplo n.º 21
0
bool SVGFECompositeElement::build(FilterBuilder* builder)
{
    FilterEffect* input1 = builder->getEffectById(in1());
    FilterEffect* input2 = builder->getEffectById(in2());
    
    if(!input1 || !input2)
        return false;
    
    RefPtr<FilterEffect> addedEffect = FEComposite::create(input1, input2, static_cast<CompositeOperationType> (_operator()),
                                        k1(), k2(), k3(), k4());
    builder->add(result(), addedEffect.release());

    return true;
}
Ejemplo n.º 22
0
void RK4::integrate(std::valarray<double> &X, std::valarray<double> &V, double dt, SolarSystem mysystem, double G, double eps)
{
    std::valarray<double> k1(1,6*mysystem.numberOfBodies());
    std::valarray<double> k2(1,6*mysystem.numberOfBodies());
    std::valarray<double> k3(1,6*mysystem.numberOfBodies());
    std::valarray<double> k4(1,6*mysystem.numberOfBodies());

    // RK4 integration using vector X from solarysystem class.
    k1 = mysystem.calculateRK4(X, V, G, eps) * dt;
    k2 = mysystem.calculateRK4(X + 0.5 * k1, V, G, eps) * dt;
    k3 = mysystem.calculateRK4(X + 0.5 * k2, V, G, eps) * dt;
    k4 = mysystem.calculateRK4(X + k3, V, G, eps) * dt;
    X += (1.0/6) * (k1 + 2 * (k2 + k3) + k4);

}
Ejemplo n.º 23
0
void lengthcalc(Mat_DP origins, Segment *segchain[]) {

	Vec_DP k0(3), k1(3), k2(3), k3(3);

	for (int i=0; i<3; i++) {
		k0[i]=origins[0][i];
		k1[i]=origins[1][i];
		k2[i]=origins[2][i];
		k3[i]=origins[3][i];
	}

	segchain[0]->length=KINEMATICS::distpnts(k0,k1);
	segchain[1]->length=KINEMATICS::distpnts(k1,k2);
	segchain[2]->length=KINEMATICS::distpnts(k2,k3);

	return;
}
Ejemplo n.º 24
0
void DynamicalSystem::integrateStepRungeKutta(double dt, const Ref<const VectorXd> x, Ref<VectorXd> x_updated, Ref<VectorXd> xd_updated) const
{
  // 4th order Runge-Kutta for a 1st order system
  // http://en.wikipedia.org/wiki/Runge-Kutta_method#The_Runge.E2.80.93Kutta_method

  int l = x.size();
  VectorXd k1(l), k2(l), k3(l), k4(l);
  differentialEquation(x,k1);
  VectorXd input_k2 = x + dt*0.5*k1;
  differentialEquation(input_k2,k2);
  VectorXd input_k3 = x + dt*0.5*k2;
  differentialEquation(input_k3,k3);
  VectorXd input_k4 = x + dt*k3;
  differentialEquation(input_k4,k4);

  x_updated = x + dt*(k1 + 2.0*(k2+k3) + k4)/6.0;
  differentialEquation(x_updated,xd_updated);
}
Ejemplo n.º 25
0
int main(){
   Btree<Key,Value> index;
   index.recover("test.index");
   Key k1("12134");
   Key k2("11111");
   Value v1(1,1);
   Value v2(3,2);
   Value v3(4,5);
   index.insert_kv(k1,v1);
   index.insert_kv(k1,v2);
   index.insert_kv(k2,v3);
   list<Value> vs;
   list<Value>::iterator it;
   index.find_values(k1,vs);
   for(it=vs.begin();it!=vs.end();it++){
       cout<<(*it).s_id<<" "<<(*it).d_id<<endl;
   }
     
}
Ejemplo n.º 26
0
void ctBdG::RK_Propagator(int i, int eta){
	VectorXcd wvVec(4), k1(4), k2(4), k3(4), k4(4);
	double normwv;
	wvVec(0) = _bdg_u(i,eta);
	wvVec(1) = _bdg_a(i,eta);
	wvVec(2) = _bdg_b(i,eta);
	wvVec(3) = _bdg_v(i,eta);
	k1 = -myI * (_bdg *  wvVec);
	k2 = -myI * (_bdg * (wvVec+_dt*k1*0.5));
	k3 = -myI * (_bdg * (wvVec+_dt*k2*0.5));
	k4 = -myI * (_bdg * (wvVec+_dt*k3));
	wvVec += _dt*(k1+2.0*k2+2.0*k3+k4)/6.0;
	normwv = wvVec.norm();
	wvVec /= normwv;
	//		cout << normwv << endl;
	_bdg_u(i,eta) = wvVec(0);
	_bdg_a(i,eta) = wvVec(1);
	_bdg_b(i,eta) = wvVec(2);
	_bdg_v(i,eta) = wvVec(3);
}
Ejemplo n.º 27
0
void PlaneMetricRep::drawRectangleForPlane(Vector3D p0_r, Vector3D n_r, double size)
{
	if (!mRect)
		return;
	// draw a rectangle showing the plane:
	Vector3D e_z = n_r;
	Vector3D k1(1,0,0);
	Vector3D k2(0,1,0);
	Vector3D e_x;
	if (cross(k2,e_z).length() > cross(k1,e_z).length())
		e_x = cross(k2,e_z)/cross(k2,e_z).length();
	else
		e_x = cross(k1,e_z)/cross(k1,e_z).length();

	Vector3D e_y = cross(e_z,e_x);
	Transform3D rMb = createTransformIJC(e_x, e_y, p0_r);
	double bb_size = 0.10/size;
	DoubleBoundingBox3D bb(-bb_size,bb_size,-bb_size,bb_size,0,0);

	mRect->updatePosition(bb, rMb);
}
Ejemplo n.º 28
0
aes_factory::aes_factory(std::string const &algo,crypto::key const &k) :
	cbc_(algo),
	hmac_("sha1")
{
	std::auto_ptr<crypto::message_digest> md_ptr(crypto::message_digest::create_by_name(hmac_));
	std::auto_ptr<crypto::cbc> cbc_ptr(crypto::cbc::create(algo));
	if(!cbc_ptr.get()) {
		throw booster::invalid_argument("cppcms::sessions::aes_factory: the algorithm " + algo + " is not supported,"
						" or the cppcms library was compiled without OpenSSL/GNU-TLS support");
	}
	size_t digest_size = md_ptr->digest_size();
	size_t cbc_key_size = cbc_ptr->key_size();
	size_t expected_size = digest_size + cbc_key_size;

	if(k.size() == cbc_key_size + digest_size) {
		cbc_key_.set(k.data(),cbc_key_size);
		hmac_key_.set(k.data() + cbc_key_size,digest_size);
	}
	else if(k.size() >= cbc_key_size && cbc_key_size * 8 < 512) {
		std::string name = k.size() * 8 <= 256 ? "sha256" : "sha512";
		crypto::hmac mac(name,k);
		std::vector<char> k1(mac.digest_size(),0);		
		std::vector<char> k2(mac.digest_size(),0);
		mac.append("0",1);
		mac.readout(&k1[0]);
		mac.append("\1",1);
		mac.readout(&k2[0]);
		cbc_key_.set(&k1[0],cbc_key_size);
		hmac_key_.set(&k2[0],digest_size);
		memset(&k1[0],0,k1.size());
		memset(&k2[0],0,k2.size());
	}
	else {
		std::ostringstream ss;
		ss	<<"cppcms::sessions::aes_factory: invalid key length: " << k.size() << " bytes; " 
			<<"expected " << expected_size << " or at least: " << cbc_key_size << " bytes";
		throw booster::invalid_argument(ss.str());
	}
}
Ejemplo n.º 29
0
int main(int argc, char** argv){

	tf::Transform t1;
	Eigen::Displacementd k1(1., 2., 3., 1., 0., 0., 0.);

	tf::LgsmDisplacementToTransformTF(k1, t1);
	std::cout << "Displacement:\n" << k1 << std::endl;
	std::cout << "Conversion to TF:\n" ;
	printTransform(t1);
	std::cout << std::endl;

	tf::Transform t2;
	Eigen::Displacementd k2(1., 2., 3., 1., 0., 0., 0.);
    t2.setOrigin( tf::Vector3( 3., 4., 5. ) );
	t2.setRotation(tf::Quaternion( 0., 0.707, 0., 0.707 ) );

	tf::TransformTFToLgsmDisplacement(t2, k2);
	std::cout << "Transform:\n";
	printTransform(t2);
	std::cout << "Conversion to Displacement:\n" << k2 << std::endl;

	return 1;
}
Ejemplo n.º 30
0
int main()
{	float x[N]={0},y[N]={0},all=0;
	double z[N]={0};
	int type,i;
	char cont;
	for(i=0;i<10;i++)
	{	printf("type: ");
		scanf("%d",&type);
		printf("x1,x2: ");
		scanf("%f,%f",&x[i],&y[i]);
		getchar();
		if(type==1) z[i]=k1(x[i],y[i]);
		else z[i]=k2(x[i],y[i]);
		printf("%lf\n",z[i]);
		printf("if continue?y/n");
		cont=getchar();
		if(cont=='n'||cont=='N') break;
	}
	for(i=0;i<10;i++)
		all+=z[i];
	printf("%.0f\n",all);
	return 0;
}