MCPcopy Create free account
hub / github.com/davisking/dlib / test_dng_floats

Function test_dng_floats

dlib/test/image.cpp:1747–1812  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1745
1746 template <typename T>
1747 void test_dng_floats(double scale)
1748 {
1749 dlog << LINFO << "in test_dng_floats";
1750 print_spinner();
1751 array2d<T> img(100,101);
1752
1753 dlib::rand rnd;
1754 for (long r = 0; r < img.nr(); ++r)
1755 {
1756 for (long c = 0; c < img.nc(); ++c)
1757 {
1758 T val = rnd.get_random_double()*scale;
1759 img[r][c] = val;
1760
1761 // Lets the float_details object while we are here doing this stuff.
1762 float_details temp = val;
1763 T val2 = temp;
1764 // for the same type we should exactly reproduce the value (unless
1765 // it's long double and then maybe it's slightly different).
1766 if (is_same_type<T,long double>::value)
1767 {
1768 DLIB_TEST(std::abs(val2-val) < scale*std::numeric_limits<T>::epsilon());
1769 }
1770 else
1771 {
1772 DLIB_TEST(val2 == val);
1773 }
1774
1775 float valf = temp;
1776 double vald = temp;
1777 long double vall = temp;
1778
1779 DLIB_TEST(std::abs(valf-val) < scale*std::numeric_limits<float>::epsilon());
1780 DLIB_TEST(std::abs(vald-val) < scale*std::numeric_limits<double>::epsilon());
1781 DLIB_TEST(std::abs(vall-val) < scale*std::numeric_limits<long double>::epsilon());
1782 }
1783 }
1784
1785 ostringstream sout;
1786 save_dng(img, sout);
1787 istringstream sin;
1788
1789 array2d<float> img1;
1790 array2d<double> img2;
1791 array2d<long double> img3;
1792
1793 sin.clear(); sin.str(sout.str());
1794 load_dng(img1, sin);
1795
1796 sin.clear(); sin.str(sout.str());
1797 load_dng(img2, sin);
1798
1799 sin.clear(); sin.str(sout.str());
1800 load_dng(img3, sin);
1801
1802 DLIB_TEST(img.nr() == img1.nr());
1803 DLIB_TEST(img.nr() == img2.nr());
1804 DLIB_TEST(img.nr() == img3.nr());

Callers

nothing calls this directly

Calls 11

print_spinnerFunction · 0.85
absFunction · 0.85
save_dngFunction · 0.85
load_dngFunction · 0.85
get_random_doubleMethod · 0.80
maxFunction · 0.50
matFunction · 0.50
nrMethod · 0.45
ncMethod · 0.45
clearMethod · 0.45
strMethod · 0.45

Tested by

no test coverage detected