Exemple #1
0
    bool Bgr48pToBgra32AutoTest(int width, int height, const Func & f1, const Func & f2)
    {
        bool result = true;

        TEST_LOG_SS(Info, "Test " << f1.description << " & " << f2.description << " for size [" << width << "," << height << "].");

        View blue(width, height, View::Int16, NULL, TEST_ALIGN(width));
        FillRandom(blue);
        View green(width, height, View::Int16, NULL, TEST_ALIGN(width));
        FillRandom(green);
        View red(width, height, View::Int16, NULL, TEST_ALIGN(width));
        FillRandom(red);

        uint8_t alpha = 0xFF;

        View bgra1(width, height, View::Bgra32, NULL, TEST_ALIGN(width));
        View bgra2(width, height, View::Bgra32, NULL, TEST_ALIGN(width));

        TEST_EXECUTE_AT_LEAST_MIN_TIME(f1.Call(blue, green, red, bgra1, alpha));

        TEST_EXECUTE_AT_LEAST_MIN_TIME(f2.Call(blue, green, red, bgra2, alpha));

        result = result && Compare(bgra1, bgra2, 0, true, 32);

        return result;
    }
Exemple #2
0
/*
 * Test the implementations of the Karatsuba alorithm. The result of the serial
 * implementation is compared to the results of the other three implementations.
 * If they all match, we assume that they're correct.
 */
static void TestKaratsuba()
{
    for (size_t trial=0; trial<4; ++trial)
    {
        for (size_t n=1; n<nMax; n*=3)
        {
            T x[nMax];
            T y[nMax];
            T z[2][2*nMax];

            FillRandom(x,n);
            FillRandom(y,n);

            // Start with the serial implementation
            karatsuba_serial(z[0],x,y,n);

            // Compare the serial implementation against the parallel, vectorized
            // implementation
//            karatsuba_parallel_vectorized(z[1],x,y,n);
//            for (size_t i=0; i<2*n-1; ++i)
//                assert(z[0][i]==z[1][i]);
//
//            // Compare the serial implementation against the vectorized implementation
//            karatsuba_vectorized(z[1],x,y,n);
//            for (size_t i=0; i<2*n-1; ++i)
//                assert(z[0][i]==z[1][i]);
//
//            // Compare the serial implementation against the parallel implementation
//            karatsuba_parallel(z[1],x,y,n);
//            for (size_t i=0; i<2*n-1; ++i)
//                assert(z[0][i]==z[1][i]);
          
        }
    }
}
Exemple #3
0
	bool DifferenceSumsMaskedAutoTest(int width, int height, const FuncM & f1, const FuncM & f2, int count)
	{
		bool result = true;

		std::cout << "Test " << f1.description << " & " << f2.description << " [" << width << ", " << height << "]." << std::endl;

		View a(width, height, View::Gray8, NULL, TEST_ALIGN(width));
		FillRandom(a);

		View b(width, height, View::Gray8, NULL, TEST_ALIGN(width));
		FillRandom(b);

		View m(width, height, View::Gray8, NULL, TEST_ALIGN(width));
		 uint8_t index = Random(256);
		FillRandomMask(m, index);

        Sums64 s1(count, 0), s2(count, 0);

        TEST_EXECUTE_AT_LEAST_MIN_TIME(f1.Call(a, b, m, index, s1.data()));

        TEST_EXECUTE_AT_LEAST_MIN_TIME(f2.Call(a, b, m, index, s2.data()));

        result = Compare(s1, s2, 0, true, count);

		return result;
	}
Exemple #4
0
	bool YuvToBgraAutoTest(int width, int height, const Func & f1, const Func & f2, int dx, int dy)
	{
		bool result = true;

		TEST_LOG_SS(Info, "Test " << f1.description << " & " << f2.description << " [" << width << ", " << height << "].");

		const int uvWidth = width/dx;
		const int uvHeight = height/dy;

		View y(width, height, View::Gray8, NULL, TEST_ALIGN(width));
		FillRandom(y);
		View u(uvWidth, uvHeight, View::Gray8, NULL, TEST_ALIGN(uvWidth));
		FillRandom(u);
		View v(uvWidth, uvHeight, View::Gray8, NULL, TEST_ALIGN(uvWidth));
		FillRandom(v);

		View bgra1(width, height, View::Bgra32, NULL, TEST_ALIGN(width));
		View bgra2(width, height, View::Bgra32, NULL, TEST_ALIGN(width));

		TEST_EXECUTE_AT_LEAST_MIN_TIME(f1.Call(y, u, v, bgra1));

		TEST_EXECUTE_AT_LEAST_MIN_TIME(f2.Call(y, u, v, bgra2));

		result = result && Compare(bgra1, bgra2, 0, true, 64);

		return result;
	}
	bool AddFeatureDifferenceAutoTest(int width, int height, uint16_t weight, const Func & f1, const Func & f2)
	{
		bool result = true;

		TEST_LOG_SS(Info, "Test " << f1.description << " & " << f2.description << " [" << width << ", " << height << "] (" << weight/256 << "*256).");

		View value(width, height, View::Gray8, NULL, TEST_ALIGN(width));
		FillRandom(value);
		View lo(width, height, View::Gray8, NULL, TEST_ALIGN(width));
		FillRandom(lo);
		View hi(width, height, View::Gray8, NULL, TEST_ALIGN(width));
		FillRandom(hi);
        View differenceSrc(width, height, View::Gray8, NULL, TEST_ALIGN(width));
        FillRandom(differenceSrc);

		View differenceDst1(width, height, View::Gray8, NULL, TEST_ALIGN(width));
		View differenceDst2(width, height, View::Gray8, NULL, TEST_ALIGN(width));

		TEST_EXECUTE_AT_LEAST_MIN_TIME(f1.Call(value, lo, hi, weight, differenceSrc, differenceDst1));

		TEST_EXECUTE_AT_LEAST_MIN_TIME(f2.Call(value, lo, hi, weight, differenceSrc, differenceDst2));

		result = result && Compare(differenceDst1, differenceDst2, 0, true, 32, 0);

		return result;
	}
	bool YuvToAnyAutoTest(int width, int height, bool is420, View::Format dstType, const Func & f1, const Func & f2)
	{
		bool result = true;

		std::cout << "Test " << f1.description << " & " << f2.description << " [" << width << ", " << height << "]." << std::endl;

		const int uvWidth = is420 ? width/2 : width;
		const int uvHeight = is420 ? height/2 : height;

		View y(width, height, View::Gray8, NULL, TEST_ALIGN(width));
		FillRandom(y);
		View u(uvWidth, uvHeight, View::Gray8, NULL, TEST_ALIGN(uvWidth));
		FillRandom(u);
		View v(uvWidth, uvHeight, View::Gray8, NULL, TEST_ALIGN(uvWidth));
		FillRandom(v);

		View dst1(width, height, dstType, NULL, TEST_ALIGN(width));
		View dst2(width, height, dstType, NULL, TEST_ALIGN(width));

		TEST_EXECUTE_AT_LEAST_MIN_TIME(f1.Call(y, u, v, dst1));

		TEST_EXECUTE_AT_LEAST_MIN_TIME(f2.Call(y, u, v, dst2));

		result = result && Compare(dst1, dst2, 0, true, 64);

		return result;
	}
Exemple #7
0
static void TimeRoutine2(Routine2 r, const char* what)
{
    // First call is used to choose how many iterations to time.
    static int TrialCount;
    bool firstCall = TrialCount==0;
    static double tBase;
    double t;

    T x[nMax];
    T y[nMax];
    T z[2*nMax];
    GLT_ult *ults;
    glt_args * args;
    FillRandom(x,nMax);
    FillRandom(y,nMax);

    if (firstCall)
        TrialCount=1;
    for(;;)
    {
         printf("En Starttime2 %d numero de counts %d\n", glt_get_thread_num(),TrialCount);

        unsigned long long t0 = cilk_getticks();
        ults = glt_ult_malloc(TrialCount);
        args = (glt_args *)malloc(sizeof(glt_args)*TrialCount);
        for (int i=0; i<TrialCount; ++i){
            
            //(*r)(z,x,y,nMax);
            args[i].z=z;
            args[i].x=x;
            args[i].y=y;
            args[i].nMax=nMax;
            glt_ult_creation_to(r,(void*)&args[i],&ults[i],0);
        }
        glt_yield();
        for (int i=0; i<TrialCount; ++i){
            glt_ult_join(&ults[i]);
        }
        unsigned long long t1 = cilk_getticks();
        free(ults);
        free (args);
        t = cilk_ticks_to_seconds(t1-t0);
        if (!firstCall || (t>=MinTime))
            break;
        // Double the number of iterations
        TrialCount*=2;
    }

    if (firstCall)
    {
        // Print table caption and heading
        printf("Timing %d multiplications of %lu-degree polynomials\n\n",TrialCount,(unsigned long)nMax);
        printf("%20s  %s  %s\n","Version","Time", "Speedup");
        tBase = t;
    }
    std::printf("%20s %6.3f %5.2f x\n",what,t,tBase/t);
}
    bool AddFeatureDifferenceDataTest(bool create, int width, int height, const Func & f)
    {
        bool result = true;

        Data data(f.description);

        TEST_LOG_SS(Info, (create ? "Create" : "Verify") << " test " << f.description << " [" << width << ", " << height << "].");

        View value(width, height, View::Gray8, NULL, TEST_ALIGN(width));
        View lo(width, height, View::Gray8, NULL, TEST_ALIGN(width));
        View hi(width, height, View::Gray8, NULL, TEST_ALIGN(width));
        View differenceSrc(width, height, View::Gray8, NULL, TEST_ALIGN(width));

        View differenceDst1(width, height, View::Gray8, NULL, TEST_ALIGN(width));
        View differenceDst2(width, height, View::Gray8, NULL, TEST_ALIGN(width));

        const uint16_t weight = 256*7;

        if(create)
        {
            FillRandom(value);
            FillRandom(lo);
            FillRandom(hi);
            FillRandom(differenceSrc);

            TEST_SAVE(value);
            TEST_SAVE(lo);
            TEST_SAVE(hi);
            TEST_SAVE(differenceSrc);

            f.Call(value, lo, hi, weight, differenceSrc, differenceDst1);

            TEST_SAVE(differenceDst1);
        }
        else
        {
            TEST_LOAD(value);
            TEST_LOAD(lo);
            TEST_LOAD(hi);

            TEST_LOAD(differenceSrc);
            TEST_LOAD(differenceDst1);

            f.Call(value, lo, hi, weight, differenceSrc, differenceDst2);

            TEST_SAVE(differenceDst2);

            result = result && Compare(differenceDst1, differenceDst2, 0, true, 32, 0);
        }

        return result;
    }
Exemple #9
0
    bool YuvToBgraDataTest(bool create, int width, int height, const Func & f, int dx, int dy)
    {
        bool result = true;

        Data data(f.description);

        TEST_LOG_SS(Info, (create ? "Create" : "Verify") << " test " << f.description << " [" << width << ", " << height << "].");

        const int uvWidth = width/dx;
        const int uvHeight = height/dy;

        View y(width, height, View::Gray8, NULL, TEST_ALIGN(width));
        View u(uvWidth, uvHeight, View::Gray8, NULL, TEST_ALIGN(uvWidth));
        View v(uvWidth, uvHeight, View::Gray8, NULL, TEST_ALIGN(uvWidth));

        View bgra1(width, height, View::Bgra32, NULL, TEST_ALIGN(width));
        View bgra2(width, height, View::Bgra32, NULL, TEST_ALIGN(width));

        if(create)
        {
            FillRandom(y);
            FillRandom(u);
            FillRandom(v);

            TEST_SAVE(y);
            TEST_SAVE(u);
            TEST_SAVE(v);

            f.Call(y, u, v, bgra1);

            TEST_SAVE(bgra1);
        }
        else
        {
            TEST_LOAD(y);
            TEST_LOAD(u);
            TEST_LOAD(v);

            TEST_LOAD(bgra1);

            f.Call(y, u, v, bgra2);

            TEST_SAVE(bgra2);

            result = result && Compare(bgra1, bgra2, 0, true, 64);
        }

        return result;
    }
    bool YuvToAnyDataTest(bool create, int width, int height, bool is420, View::Format dstType, const Func & f)
    {
        bool result = true;

        Data data(f.description);

        std::cout << (create ? "Create" : "Verify") << " test " << f.description << " [" << width << ", " << height << "]." << std::endl;

        const int uvWidth = is420 ? width/2 : width;
        const int uvHeight = is420 ? height/2 : height;

        View y(width, height, View::Gray8, NULL, TEST_ALIGN(width));
        View u(uvWidth, uvHeight, View::Gray8, NULL, TEST_ALIGN(uvWidth));
        View v(uvWidth, uvHeight, View::Gray8, NULL, TEST_ALIGN(uvWidth));

        View dst1(width, height, dstType, NULL, TEST_ALIGN(width));
        View dst2(width, height, dstType, NULL, TEST_ALIGN(width));

        if(create)
        {
            FillRandom(y);
            FillRandom(u);
            FillRandom(v);

            TEST_SAVE(y);
            TEST_SAVE(u);
            TEST_SAVE(v);

            f.Call(y, u, v, dst1);

            TEST_SAVE(dst1);
        }
        else
        {
            TEST_LOAD(y);
            TEST_LOAD(u);
            TEST_LOAD(v);

            TEST_LOAD(dst1);

            f.Call(y, u, v, dst2);

            TEST_SAVE(dst2);

            result = result && Compare(dst1, dst2, 0, true, 64);
        }

        return result;
    }
Exemple #11
0
    bool Bgr48pToBgra32DataTest(bool create, int width, int height, const Func & f)
    {
        bool result = true;

        Data data(f.description);

        TEST_LOG_SS(Info, (create ? "Create" : "Verify") << " test " << f.description << " [" << width << ", " << height << "].");

        View blue(width, height, View::Int16, NULL, TEST_ALIGN(width));
        View green(width, height, View::Int16, NULL, TEST_ALIGN(width));
        View red(width, height, View::Int16, NULL, TEST_ALIGN(width));

        uint8_t alpha = 0xFF;

        View bgra1(width, height, View::Bgra32, NULL, TEST_ALIGN(width));
        View bgra2(width, height, View::Bgra32, NULL, TEST_ALIGN(width));

        if(create)
        {
            FillRandom(blue);
            FillRandom(green);
            FillRandom(red);

            TEST_SAVE(blue);
            TEST_SAVE(green);
            TEST_SAVE(red);

            f.Call(blue, green, red, bgra1, alpha);

            TEST_SAVE(bgra1);
        }
        else
        {
            TEST_LOAD(blue);
            TEST_LOAD(green);
            TEST_LOAD(red);

            TEST_LOAD(bgra1);

            f.Call(blue, green, red, bgra2, alpha);

            TEST_SAVE(bgra2);

            result = result && Compare(bgra1, bgra2, 0, true, 32);
        }

        return result;
    }
Exemple #12
0
    bool SegmentationPropagate2x2DataTest(bool create, int width, int height, const FuncP & f)
    {
        bool result = true;

        Data data(f.description);

        TEST_LOG_SS(Info, (create ? "Create" : "Verify") << " test " << f.description << " [" << width << ", " << height << "].");

        const uint8_t currentIndex = 3, invalidIndex = 2, emptyIndex = 0, differenceThreshold = 128;
        View parent(width, height, View::Gray8, NULL, TEST_ALIGN(width));
        View childSrc(2*width, 2*height, View::Gray8, NULL, TEST_ALIGN(width));
        View difference(2*width, 2*height, View::Gray8, NULL, TEST_ALIGN(width));
        View childDst1(2*width, 2*height, View::Gray8, NULL, TEST_ALIGN(width));
        View childDst2(2*width, 2*height, View::Gray8, NULL, TEST_ALIGN(width));

        const uint8_t oldIndex = 3, newIndex = 2;

        if(create)
        {
            FillRandomMask(parent, currentIndex);
            FillRandom(childSrc, 0, currentIndex - 1);
            FillRandom(difference, 255);

            TEST_SAVE(parent);
            TEST_SAVE(childSrc);
            TEST_SAVE(difference);

            f.Call(parent, childSrc, childDst1, difference, currentIndex, invalidIndex, emptyIndex, differenceThreshold);

            TEST_SAVE(childDst1);
        }
        else
        {
            TEST_LOAD(parent);
            TEST_LOAD(childSrc);
            TEST_LOAD(difference);

            TEST_LOAD(childDst1);

            f.Call(parent, childSrc, childDst2, difference, currentIndex, invalidIndex, emptyIndex, differenceThreshold);

            TEST_SAVE(childDst2);

            result = result && Compare(childDst1, childDst2, 0, true, 64);
        }

        return result;
    }
Exemple #13
0
    bool CreateBackground(View & bkg, Rect & rect)
    {
        View obj;

        const uint8_t lo = 64, hi = 192;
        const size_t s = 256, co = s / 2;
        const size_t rl2 = Simd::Square(co * 2 / 7), rh2 = Simd::Square(co * 4 / 7);
        obj.Recreate(s, s, View::Gray8);
        for (size_t y = 0; y < s; ++y)
        {
            size_t dy2 = Simd::Square(co - y);
            for (size_t x = 0; x < s; ++x)
            {
                size_t dx2 = Simd::Square(co - x);
                size_t r2 = dy2 + dx2;
                obj.At<uint8_t>(x, y) = (r2 >= rl2 && r2 <= rh2 ? hi : lo);
          
            }
        }
        FillRandom(bkg, 0, lo * 2);
        Point c(bkg.width / 2, bkg.height / 2);

        std::vector<uint8_t> profile(s, 255);
        for (size_t i = 0, n = s / 4; i < n; ++i)
            profile[s - i - 1] = profile[i] = uint8_t(i * 255 / n);
        View alpha(s, s, View::Gray8);
        Simd::VectorProduct(profile.data(), profile.data(), alpha);

        size_t hs = s / 2;
        rect = Rect(c.x - hs, c.y - hs, c.x + hs, c.y + hs);
        Simd::AlphaBlending(obj, alpha, bkg.Region(rect).Ref());
        rect.AddBorder(-int(hs / 4));

        return true;
    }
Exemple #14
0
    bool IntegralAutoTest(int width, int height, bool sqsumEnable, bool tiltedEnable, View::Format sumFormat, View::Format sqsumFormat, const Func & f1, const Func & f2)
    {
        bool result = true;

        TEST_LOG_SS(Info, "Test " << f1.description << " & " << f2.description << " [" << width << ", " << height << "].");

        View src(width, height, View::Gray8, NULL, TEST_ALIGN(width));
        FillRandom(src);

        View sum1(width + 1, height + 1, sumFormat, NULL, TEST_ALIGN(width));
        View sum2(width + 1, height + 1, sumFormat, NULL, TEST_ALIGN(width));
        View sqsum1, sqsum2, tilted1, tilted2;
        if(sqsumEnable)
        {
            sqsum1.Recreate(width + 1, height + 1, sqsumFormat, NULL, TEST_ALIGN(width));
            sqsum2.Recreate(width + 1, height + 1, sqsumFormat, NULL, TEST_ALIGN(width));
        }
        if(tiltedEnable)
        {
            tilted1.Recreate(width + 1, height + 1, sumFormat, NULL, TEST_ALIGN(width));
            tilted2.Recreate(width + 1, height + 1, sumFormat, NULL, TEST_ALIGN(width));
        }

        TEST_EXECUTE_AT_LEAST_MIN_TIME(f1.Call(src, sum1, sqsum1, tilted1));

        TEST_EXECUTE_AT_LEAST_MIN_TIME(f2.Call(src, sum2, sqsum2, tilted2));

        result = result && Compare(sum1, sum2, 0, true, 32, 0, "sum");
        if(sqsumEnable)
            result = result && Compare(sqsum1, sqsum2, 0, true, 32, 0, "sqsum");
        if(tiltedEnable)
            result = result && Compare(tilted1, tilted2, 0, true, 32, 0, "tilted");

        return result;
    }
Exemple #15
0
    bool AveragingBinarizationAutoTest(int width, int height, SimdCompareType type, const Func2 & f1, const Func2 & f2)
    {
        bool result = true;

        TEST_LOG_SS(Info, "Test " << f1.description << " & " << f2.description << " [" << width << ", " << height << "].");

        View src(width, height, View::Gray8, NULL, TEST_ALIGN(width));
        FillRandom(src);

        uint8_t value = 127;
        size_t neighborhood = 17;
        uint8_t threshold = 128;
        uint8_t positive = 7;
        uint8_t negative = 3;

        View d1(width, height, View::Gray8, NULL, TEST_ALIGN(width));
        View d2(width, height, View::Gray8, NULL, TEST_ALIGN(width));

        TEST_EXECUTE_AT_LEAST_MIN_TIME(f1.Call(src, value, neighborhood, threshold, positive, negative, d1, type));

        TEST_EXECUTE_AT_LEAST_MIN_TIME(f2.Call(src, value, neighborhood, threshold, positive, negative, d2, type));

        result = result && Compare(d1, d2, 0, true, 64);

        return result;
    }
Exemple #16
0
    bool DifferenceSumsMaskedDataTest(bool create, int width, int height, const FuncM & f, int count)
    {
        bool result = true;

        Data data(f.description);

        std::cout << (create ? "Create" : "Verify") << " test " << f.description << " [" << width << ", " << height << "]." << std::endl;

        View a(width, height, View::Gray8, NULL, TEST_ALIGN(width));
        View b(width, height, View::Gray8, NULL, TEST_ALIGN(width));
        View m(width, height, View::Gray8, NULL, TEST_ALIGN(width));

        Sums64 s1(count, 0), s2(count, 0);

        uint8_t index = 17;

        if(create)
        {
            FillRandom(a);
            FillRandom(b);
            FillRandomMask(m, index);

            TEST_SAVE(a);
            TEST_SAVE(b);
            TEST_SAVE(m);

            f.Call(a, b, m, index, s1.data());

            TEST_SAVE(s1);
        }
        else
        {
            TEST_LOAD(a);
            TEST_LOAD(b);
            TEST_LOAD(m);

            TEST_LOAD(s1);

            f.Call(a, b, m, index, s2.data());

            TEST_SAVE(s2);

            result = result && Compare(s1, s2, 0, true, count);
        }

        return result;
    }
Exemple #17
0
    bool AlphaBlendingDataTest(bool create, View::Format format, int width, int height, const FuncAB & f)
    {
        bool result = true;

        Data data(f.description);

        TEST_LOG_SS(Info, (create ? "Create" : "Verify") << " test " << f.description << " [" << width << ", " << height << "].");

        View s(width, height, format, NULL, TEST_ALIGN(width));
        View a(width, height, View::Gray8, NULL, TEST_ALIGN(width));
        View b(width, height, format, NULL, TEST_ALIGN(width));

        View d1(width, height, format, NULL, TEST_ALIGN(width));
        View d2(width, height, format, NULL, TEST_ALIGN(width));

        if(create)
        {
            FillRandom(s);
            FillRandom(a);
            FillRandom(b);

            TEST_SAVE(s);
            TEST_SAVE(a);
            TEST_SAVE(b);

            f.Call(s, a, b, d1);

            TEST_SAVE(d1);
        }
        else
        {
            TEST_LOAD(s);
            TEST_LOAD(a);
            TEST_LOAD(b);

            TEST_LOAD(d1);

            f.Call(s, a, b, d2);

            TEST_SAVE(d2);

            result = result && Compare(d1, d2, 0, true, 64);
        }

        return result;
    }
Exemple #18
0
    bool TextureGetDifferenceSumDataTest(bool create, int width, int height, const Func3 & f)
    {
        bool result = true;

        Data data(f.description);

        TEST_LOG_SS(Info, (create ? "Create" : "Verify") << " test " << f.description << " [" << width << ", " << height << "].");

        View src(width, height, View::Gray8, NULL, TEST_ALIGN(width));
        View lo(width, height, View::Gray8, NULL, TEST_ALIGN(width));
        View hi(width, height, View::Gray8, NULL, TEST_ALIGN(width));

        int64_t s1, s2;

        if(create)
        {
            FillRandom(src);
            FillRandom(lo);
            FillRandom(hi);

            TEST_SAVE(src);
            TEST_SAVE(lo);
            TEST_SAVE(hi);

            f.Call(src, lo, hi, &s1);

            TEST_SAVE(s1);
        }
        else
        {
            TEST_LOAD(src);
            TEST_LOAD(lo);
            TEST_LOAD(hi);

            TEST_LOAD(s1);

            f.Call(src, lo, hi, &s2);

            TEST_SAVE(s2);

            TEST_CHECK_VALUE(s);
        }

        return result;
    }
Exemple #19
0
    bool ShiftBilinearDataTest(bool create, int width, int height, View::Format format, const Func & f)
    {
        bool result = true;

        Data data(f.description);

        std::cout << (create ? "Create" : "Verify") << " test " << f.description << " [" << width << ", " << height << "]." << std::endl;

        View s(width, height, format, NULL, TEST_ALIGN(width));
        View b(width, height, format, NULL, TEST_ALIGN(width));
        View d1(width, height, format, NULL, TEST_ALIGN(width));
        View d2(width, height, format, NULL, TEST_ALIGN(width));

        const double dx = -5.3, dy = 3.7;
        const int crop = 3;

        if(create)
        {
            FillRandom(s);
            FillRandom(b);
            TEST_SAVE(s);
            TEST_SAVE(b);

            f.Call(s, b, dx, dy, crop, crop, width - crop, height - crop, d1);

            TEST_SAVE(d1);
        }
        else
        {
            TEST_LOAD(s);
            TEST_LOAD(b);
            TEST_LOAD(d1);

            f.Call(s, b, dx, dy, crop, crop, width - crop, height - crop, d2);

            TEST_SAVE(d2);

            result = result && Compare(d1, d2, 0, true, 64);
        }

        return result;
    }
Exemple #20
0
    bool HistogramConditionalDataTest(bool create, int width, int height, SimdCompareType type, const FuncHC & f)
    {
        bool result = true;

        Data data(f.description);

        TEST_LOG_SS(Info, (create ? "Create" : "Verify") << " test " << f.description << " [" << width << ", " << height << "].");

        View src(width, height, View::Gray8, NULL, TEST_ALIGN(width));
        View mask(width, height, View::Gray8, NULL, TEST_ALIGN(width));

        const uint8_t value = 127;
        Histogram h1, h2;

        if (create)
        {
            FillRandom(src);
            FillRandom(mask);

            TEST_SAVE(src);
            TEST_SAVE(mask);

            f.Call(src, mask, value, type, h1);

            TEST_SAVE(h1);
        }
        else
        {
            TEST_LOAD(src);
            TEST_LOAD(mask);

            TEST_LOAD(h1);

            f.Call(src, mask, value, type, h2);

            TEST_SAVE(h2);

            result = result && Compare(h1, h2, 0, true, 32);
        }

        return result;
    }
Exemple #21
0
    bool ContourMetricsMaskedDataTest(bool create, int width, int height, const FuncM & f)
    {
        bool result = true;

        Data data(f.description);

        TEST_LOG_SS(Info, (create ? "Create" : "Verify") << " test " << f.description << " [" << width << ", " << height << "].");

        View src(width, height, View::Gray8, NULL, TEST_ALIGN(width));
        View mask(width, height, View::Gray8, NULL, TEST_ALIGN(width));

        View dst1(width, height, View::Int16, NULL, TEST_ALIGN(width));
        View dst2(width, height, View::Int16, NULL, TEST_ALIGN(width));

        if(create)
        {
            FillRandom(src);
            FillRandom(mask);

            TEST_SAVE(src);
            TEST_SAVE(mask);

            f.Call(src, mask, 128, dst1);

            TEST_SAVE(dst1);
        }
        else
        {
            TEST_LOAD(src);
            TEST_LOAD(mask);

            TEST_LOAD(dst1);

            f.Call(src, mask, 128, dst2);

            TEST_SAVE(dst2);

            result = result && Compare(dst1, dst2, 0, true, 32, 0);
        }

        return result;
    }
Exemple #22
0
    bool TexturePerformCompensationDataTest(bool create, int width, int height, const Func4 & f)
    {
        bool result = true;

        Data data(f.description);

        TEST_LOG_SS(Info, (create ? "Create" : "Verify") << " test " << f.description << " [" << width << ", " << height << "].");

        View src(width, height, View::Gray8, NULL, TEST_ALIGN(width));
        FillRandom(src);

        View dst1(width, height, View::Gray8, NULL, TEST_ALIGN(width));
        View dst2(width, height, View::Gray8, NULL, TEST_ALIGN(width));

        const int shift = -7;

        if(create)
        {
            FillRandom(src);

            TEST_SAVE(src);

            f.Call(src, shift, dst1);

            TEST_SAVE(dst1);
        }
        else
        {
            TEST_LOAD(src);

            TEST_LOAD(dst1);

            f.Call(src, shift, dst2);

            TEST_SAVE(dst2);

            result = result && Compare(dst1, dst2, 0, true, 32, 0);
        }

        return result;
    }
Exemple #23
0
    bool TextureGetDifferenceSumAutoTest(int width, int height, const Func3 & f1, const Func3 & f2)
    {
        bool result = true;

        TEST_LOG_SS(Info, "Test " << f1.description << " & " << f2.description << " [" << width << ", " << height << "].");

        View src(width, height, View::Gray8, NULL, TEST_ALIGN(width));
        FillRandom(src);
        View lo(width, height, View::Gray8, NULL, TEST_ALIGN(width));
        FillRandom(lo);
        View hi(width, height, View::Gray8, NULL, TEST_ALIGN(width));
        FillRandom(hi);

        int64_t s1, s2;

        TEST_EXECUTE_AT_LEAST_MIN_TIME(f1.Call(src, lo, hi, &s1));

        TEST_EXECUTE_AT_LEAST_MIN_TIME(f2.Call(src, lo, hi, &s2));

        TEST_CHECK_VALUE(s);

        return result;
    }
Exemple #24
0
	bool ShiftAutoTest(View::Format format, int width, int height, double dx, double dy, int crop, const Func & f1, const Func & f2)
	{
		bool result = true;

		TEST_LOG_SS(Info, std::setprecision(1) << std::fixed << "Test " << f1.description << " & " << f2.description 
            << " [" << width << ", " << height << "]," << " (" << dx << ", " << dy << ", " << crop << ").");

		View s(width, height, format, NULL, TEST_ALIGN(width));
		FillRandom(s);
		View b(width, height, format, NULL, TEST_ALIGN(width));
		FillRandom(b);

		View d1(width, height, format, NULL, TEST_ALIGN(width));
		View d2(width, height, format, NULL, TEST_ALIGN(width));

		TEST_EXECUTE_AT_LEAST_MIN_TIME(f1.Call(s, b, dx, dy, crop, crop, width - crop, height - crop, d1));

		TEST_EXECUTE_AT_LEAST_MIN_TIME(f2.Call(s, b, dx, dy, crop, crop, width - crop, height - crop, d2));

		result = result && Compare(d1, d2, 0, true, 32);

		return result;
	}
Exemple #25
0
    bool HistogramConditionalAutoTest(int width, int height, SimdCompareType type, const FuncHC & f1, const FuncHC & f2)
    {
        bool result = true;

        TEST_LOG_SS(Info, "Test " << f1.description << " & " << f2.description << " [" << width << ", " << height << "].");

        View s(int(width), int(height), View::Gray8, NULL, TEST_ALIGN(width));
        View m(int(width), int(height), View::Gray8, NULL, TEST_ALIGN(width));

        uint8_t value = 127;
        FillRandom(s);
        FillRandom(m);

        Histogram h1 = { 0 }, h2 = { 0 };

        TEST_EXECUTE_AT_LEAST_MIN_TIME(f1.Call(s, m, value, type, h1));

        TEST_EXECUTE_AT_LEAST_MIN_TIME(f2.Call(s, m, value, type, h2));

        result = result && Compare(h1, h2, 0, true, 32);

        return result;
    }
Exemple #26
0
    bool ContourMetricsMaskedAutoTest(int width, int height, const FuncM & f1, const FuncM & f2)
    {
        bool result = true;

        TEST_LOG_SS(Info, "Test " << f1.description << " & " << f2.description << " [" << width << ", " << height << "].");

        View s(width, height, View::Gray8, NULL, TEST_ALIGN(width));
        FillRandom(s);

        View m(width, height, View::Gray8, NULL, TEST_ALIGN(width));
        FillRandom(m);

        View d1(width, height, View::Int16, NULL, TEST_ALIGN(width));
        View d2(width, height, View::Int16, NULL, TEST_ALIGN(width));

        TEST_EXECUTE_AT_LEAST_MIN_TIME(f1.Call(s, m, 128, d1));

        TEST_EXECUTE_AT_LEAST_MIN_TIME(f2.Call(s, m, 128, d2));

        result = result && Compare(d1, d2, 0, true, 64);

        return result;
    }
void SimpleHistogram()
{
   // Create a histogram with 64 bins and an x axis ranging from 0 to 16
   auto h = new TH1F("myPyHisto", "Productivity;C++ Knowledge;Productivity", 64, 0, 16);

   // Fill it with random numbers distributed according to a linear function ("pol1")
   h->FillRandom("pol1");

   // Change its line width with a thicker one
   h->SetLineWidth(4);

   // Draw!
   h->Draw();
}
Exemple #28
0
    bool IntegralDataTest(bool create, int width, int height, const Func & f)
    {
        bool result = true;

        Data data(f.description);

        TEST_LOG_SS(Info, (create ? "Create" : "Verify") << " test " << f.description << " [" << width << ", " << height << "].");

        View src(width, height, View::Gray8, NULL, TEST_ALIGN(width));

        View sum1(width + 1, height + 1, View::Int32, NULL, TEST_ALIGN(width));
        View sum2(width + 1, height + 1, View::Int32, NULL, TEST_ALIGN(width));
        View sqsum1(width + 1, height + 1, View::Int32, NULL, TEST_ALIGN(width));
        View sqsum2(width + 1, height + 1, View::Int32, NULL, TEST_ALIGN(width));
        View tilted1(width + 1, height + 1, View::Int32, NULL, TEST_ALIGN(width));
        View tilted2(width + 1, height + 1, View::Int32, NULL, TEST_ALIGN(width));

        if(create)
        {
            FillRandom(src);

            TEST_SAVE(src);

            f.Call(src, sum1, sqsum1, tilted1);

            TEST_SAVE(sum1);
            TEST_SAVE(sqsum1);
            TEST_SAVE(tilted1);
        }
        else
        {
            TEST_LOAD(src);

            TEST_LOAD(sum1);
            TEST_LOAD(sqsum1);
            TEST_LOAD(tilted1);

            f.Call(src, sum2, sqsum2, tilted2);

            TEST_SAVE(sum2);
            TEST_SAVE(sqsum2);
            TEST_SAVE(tilted2);

            result = result && Compare(sum1, sum2, 0, true, 32, 0, "sum");
            result = result && Compare(sqsum1, sqsum2, 0, true, 32, 0, "sqsum");
            result = result && Compare(tilted1, tilted2, 0, true, 32, 0, "tilted");
        }

        return result;
    }
Exemple #29
0
void ratioplot2() {
   gStyle->SetOptStat(0);
   auto c1 = new TCanvas("c1", "fit residual simple");
   auto h1 = new TH1D("h1", "h1", 50, -5, 5);
   h1->FillRandom("gaus", 2000);
   h1->Fit("gaus");
   h1->GetXaxis()->SetTitle("x");
   c1->Clear(); // Fit does not draw into correct pad
   auto rp1 = new TRatioPlot(h1);
   rp1->Draw();
   rp1->GetLowerRefYaxis()->SetTitle("ratio");
   rp1->GetUpperRefYaxis()->SetTitle("entries");
   c1->Update();
}
Exemple #30
0
void fillrandom() {
   TCanvas *c1 = new TCanvas("c1","The FillRandom example",200,10,700,900);

   auto pad1 = new TPad("pad1","The pad with the function",0.05,0.50,0.95,0.95);
   auto pad2 = new TPad("pad2","The pad with the histogram",0.05,0.05,0.95,0.45);
   pad1->Draw();
   pad2->Draw();
   pad1->cd();

   gBenchmark->Start("fillrandom");
   //
   // A function (any dimension) or a formula may reference
   // an already defined formula
   //
   auto form1 = new TFormula("form1","abs(sin(x)/x)");
   auto sqroot = new TF1("sqroot","x*gaus(0) + [3]*form1",0,10);
   sqroot->SetParameters(10,4,1,20);
   pad1->SetGridx();
   pad1->SetGridy();
   pad1->GetFrame()->SetBorderMode(-1);
   pad1->GetFrame()->SetBorderSize(5);
   sqroot->SetLineColor(4);
   sqroot->SetLineWidth(6);
   sqroot->Draw();
   auto lfunction = new TPaveLabel(5,39,9.8,46,"The sqroot function");
   lfunction->Draw();
   c1->Update();

   //
   // Create a one dimensional histogram (one float per bin)
   // and fill it following the distribution in function sqroot.
   //
   pad2->cd();
   pad2->GetFrame()->SetBorderMode(-1);
   pad2->GetFrame()->SetBorderSize(5);
   auto h1f = new TH1F("h1f","Test random numbers",200,0,10);
   h1f->SetFillColor(45);
   h1f->FillRandom("sqroot",10000);
   h1f->Draw();
   c1->Update();
   //
   // Open a ROOT file and save the formula, function and histogram
   //
   TFile myfile("fillrandom.root","RECREATE");
   form1->Write();
   sqroot->Write();
   h1f->Write();
   gBenchmark->Show("fillrandom");
}