Commit 3a91295e authored by Joachim's avatar Joachim
Browse files

Merge branch 'master' of https://github.com/davisking/dlib

parents 22164e5d 75f66582
......@@ -57,7 +57,7 @@ namespace dlib
{}
sockstreambuf_unbuffered (
const scoped_ptr<connection>& con_
const std::unique_ptr<connection>& con_
) :
con(*con_),
peek(EOF),
......
......@@ -6,12 +6,14 @@
#include "sqlite_abstract.h"
#include <iostream>
#include <limits>
#include <memory>
#include <vector>
#include "../algs.h"
#include <sqlite3.h>
#include "../smart_pointers.h"
#include "../serialize.h"
#include <limits>
// --------------------------------------------------------------------------------------------
......@@ -105,7 +107,7 @@ namespace dlib
friend class statement;
std::string filename;
shared_ptr<sqlite3> db;
std::shared_ptr<sqlite3> db;
};
// --------------------------------------------------------------------------------------------
......@@ -593,7 +595,7 @@ namespace dlib
int step_status;
bool at_first_step;
shared_ptr<sqlite3> db;
std::shared_ptr<sqlite3> db;
sqlite3_stmt* stmt;
std::string sql_string;
};
......
......@@ -4,6 +4,8 @@
#define DLIB_KKMEANs_
#include <cmath>
#include <vector>
#include "../matrix/matrix_abstract.h"
#include "../algs.h"
#include "../serialize.h"
......@@ -12,8 +14,6 @@
#include "kcentroid.h"
#include "kkmeans_abstract.h"
#include "../noncopyable.h"
#include "../smart_pointers.h"
#include <vector>
namespace dlib
{
......@@ -176,7 +176,7 @@ namespace dlib
item.centers.resize(num);
for (unsigned long i = 0; i < item.centers.size(); ++i)
{
scoped_ptr<kcentroid<kernel_type> > temp(new kcentroid<kernel_type>(kernel_type()));
std::unique_ptr<kcentroid<kernel_type> > temp(new kcentroid<kernel_type>(kernel_type()));
deserialize(*temp, in);
item.centers[i].swap(temp);
}
......@@ -270,7 +270,7 @@ namespace dlib
}
array<scoped_ptr<kcentroid<kernel_type> > > centers;
array<std::unique_ptr<kcentroid<kernel_type> > > centers;
kcentroid<kernel_type> kc;
scalar_type min_change;
......
......@@ -10,7 +10,7 @@
#include "kernel.h"
#include "kcentroid.h"
#include <iostream>
#include "../smart_pointers.h"
#include <memory>
namespace dlib
{
......@@ -460,7 +460,7 @@ namespace dlib
const sample_vector_type* samples;
shared_ptr<cache_type> cache;
std::shared_ptr<cache_type> cache;
mutable unsigned long counter;
unsigned long counter_threshold;
long cache_size;
......
......@@ -3,20 +3,19 @@
#ifndef DLIB_STRUCTURAL_SVM_DISTRIBUTeD_Hh_
#define DLIB_STRUCTURAL_SVM_DISTRIBUTeD_Hh_
#include <memory>
#include <iostream>
#include <vector>
#include "structural_svm_distributed_abstract.h"
#include "structural_svm_problem.h"
#include "../bridge.h"
#include "../smart_pointers.h"
#include "../misc_api.h"
#include "../statistics.h"
#include "../threads.h"
#include "../pipe.h"
#include "../type_safe_union.h"
#include <iostream>
#include <vector>
namespace dlib
{
......@@ -333,7 +332,7 @@ namespace dlib
};
scoped_ptr<base> the_problem;
std::unique_ptr<base> the_problem;
};
// ----------------------------------------------------------------------------------------
......@@ -678,9 +677,9 @@ namespace dlib
typedef type_safe_union<impl::oracle_request<matrix_type> > tsu_out;
typedef type_safe_union<impl::oracle_response<matrix_type>, long> tsu_in;
std::vector<shared_ptr<pipe<tsu_out> > > out_pipes;
std::vector<std::shared_ptr<pipe<tsu_out> > > out_pipes;
mutable pipe<tsu_in> in;
std::vector<shared_ptr<bridge> > bridges;
std::vector<std::shared_ptr<bridge> > bridges;
long num_dims;
};
......
......@@ -3,21 +3,21 @@
#ifndef DLIB_SVm_THREADED_
#define DLIB_SVm_THREADED_
#include "svm_threaded_abstract.h"
#include "svm.h"
#include <cmath>
#include <iostream>
#include <limits>
#include <sstream>
#include <vector>
#include "svm_threaded_abstract.h"
#include "svm.h"
#include "../matrix.h"
#include "../algs.h"
#include "../serialize.h"
#include "function.h"
#include "kernel.h"
#include "../threads.h"
#include <vector>
#include "../smart_pointers.h"
#include "../pipe.h"
#include <iostream>
namespace dlib
{
......
......@@ -125,7 +125,6 @@ set (tests
set.cpp
sldf.cpp
sliding_buffer.cpp
smart_pointers.cpp
sockets2.cpp
sockets.cpp
sockstreambuf.cpp
......
......@@ -692,6 +692,36 @@ namespace
cpu::add(2, AA, 3, BB);
DLIB_TEST_MSG(max(abs(mat(A)-mat(AA) )) < 1e-6, max(abs(mat(A)-mat(AA) )));
}
{
print_spinner();
resizable_tensor dest1(123,456), dest2(123,456);
resizable_tensor src1(123,456), src2(123,456);
tt::tensor_rand rnd;
rnd.fill_uniform(src1); tt::affine_transform(src1, src1, 1, 2); src2 = src1; // random in range [2, 3]
dest1 = exp(mat(src1));
tt::exp(dest2, src2);
tt::exp(src2, src2); // should work in place
DLIB_TEST_MSG(max(abs(mat(dest1)-mat(dest2))) < 1e-5, max(abs(mat(dest1)-mat(dest2))));
DLIB_TEST(max(abs(mat(dest1)-mat(src2))) < 1e-5);
rnd.fill_uniform(src1); tt::affine_transform(src1, src1, 1, 2); src2 = src1; // random in range [2, 3]
dest1 = log(mat(src1));
tt::log(dest2, src2);
tt::log(src2, src2); // should work in place
DLIB_TEST(max(abs(mat(dest1)-mat(dest2))) < 1e-5);
DLIB_TEST(max(abs(mat(dest1)-mat(src2))) < 1e-5);
rnd.fill_uniform(src1); tt::affine_transform(src1, src1, 1, 2); src2 = src1; // random in range [2, 3]
dest1 = log10(mat(src1));
tt::log10(dest2, src2);
tt::log10(src2, src2); // should work in place
DLIB_TEST(max(abs(mat(dest1)-mat(dest2))) < 1e-5);
DLIB_TEST(max(abs(mat(dest1)-mat(src2))) < 1e-5);
}
}
// ----------------------------------------------------------------------------------------
......
......@@ -109,7 +109,7 @@ namespace
results = basic_elastic_net(X, Y, ridge_lambda, lasso_budget*s, eps);
results2 = solver(ridge_lambda, lasso_budget*s);
dlog << LINFO << "error: "<< max(abs(results - results2));
DLIB_TEST(max(abs(results - results2) < 1e-3));
DLIB_TEST(max(abs(results - results2)) < 1e-3);
}
}
} a;
......
#include <fstream>
#include <iostream>
#include <memory>
#include <sstream>
#include <string>
#include "dlib/image_io.h"
#include "dlib/array2d.h"
#include "dlib/gui_core.h"
#include "dlib/assert.h"
#include "dlib/misc_api.h"
#include <string>
#include "dlib/image_transforms.h"
#include "dlib/timer.h"
#include "dlib/gui_widgets.h"
#include "dlib/queue.h"
#include <sstream>
#include <iostream>
#include <fstream>
using namespace dlib;
using namespace std;
......@@ -444,7 +447,7 @@ public:
{
bool use_bdf_fonts = false;
shared_ptr_thread_safe<bdf_font> f(new bdf_font);
std::shared_ptr<bdf_font> f(new bdf_font);
if (use_bdf_fonts)
{
......
......@@ -131,7 +131,6 @@ SRC += serialize.cpp
SRC += set.cpp
SRC += sldf.cpp
SRC += sliding_buffer.cpp
SRC += smart_pointers.cpp
SRC += sockets2.cpp
SRC += sockets.cpp
SRC += sockstreambuf.cpp
......
......@@ -287,13 +287,16 @@ namespace
const double C = 2;
matrix<double,0,1> alpha(3), d(3), lambda;
d = 0;
alpha = C/2, C/2, 0;
solve_qp4_using_smo(A, tmp(trans(A)*A), b, d, alpha, lambda, 1e-9, 3000);
unsigned long iters = solve_qp4_using_smo(A, tmp(trans(A)*A), b, d, alpha, lambda, 1e-9, 3000);
matrix<double,0,1> w = lowerbound(-A*alpha, 0);
dlog << LINFO << "*******************************************************";
dlog << LINFO << "alpha: " << trans(alpha);
dlog << LINFO << "lambda: " << trans(lambda);
dlog << LINFO << "w: " << trans(w);
......@@ -303,7 +306,12 @@ namespace
dlog << LINFO << "computed obj: "<< computed_obj;
dlog << LINFO << "with true w obj: "<< true_obj;
DLIB_TEST_MSG(abs(computed_obj - true_obj) < 1e-8, abs(computed_obj - true_obj));
DLIB_TEST_MSG(abs(computed_obj - true_obj) < 1e-8,
"computed_obj: "<< computed_obj << " true_obj: " << true_obj << " delta: "<< abs(computed_obj - true_obj)
<< " iters: " << iters
<< "\n alpha: " << trans(alpha)
<< " lambda: " << trans(lambda)
);
}
void test_qp4_test7()
......
......@@ -378,7 +378,7 @@ namespace dlib
h(0,3) = h(0,3) + 8.0E+00 * f1 * f2 * df1dx1 * df2dx4;
h(1,0) = h(1,0) + 12.0E+00 * pow(f1,2) * df1dx2 * df1dx1 + 4.0E+00 * pow(f2,2) * df1dx2 * df1dx1;
h(1,1) = h(1,1) + 12.0E+00 * pow(f1,2) * df1dx2 * df1dx2 + 4.0E+00 * pow(f2,2) * df1dx2 * df1dx1;
h(1,1) = h(1,1) + 12.0E+00 * pow(f1,2) * df1dx2 * df1dx2 + 4.0E+00 * pow(f2,2) * df1dx2 * df1dx2;
h(1,2) = h(1,2) + 8.0E+00 * f1 * f2 * df1dx2 * df2dx3;
h(1,3) = h(1,3) + 8.0E+00 * f1 * f2 * df1dx2 * df2dx4;
......
// Copyright (C) 2007 Davis E. King (davis@dlib.net)
// License: Boost Software License See LICENSE.txt for the full license.
// This is a legacy test for old dlib smart pointers which is excluded
// from CMakeLists.txt. Including this test will pull legacy smart_pointers.h
// code which is uncompilable on C++17 compilers
#include <dlib/smart_pointers.h>
#include <sstream>
......
......@@ -2,10 +2,12 @@
// License: Boost Software License See LICENSE.txt for the full license.
#include <sstream>
#include <string>
#include <cstdlib>
#include <ctime>
#include <memory>
#include <sstream>
#include <string>
#include <dlib/sockets.h>
#include <dlib/server.h>
#include <dlib/misc_api.h>
......@@ -118,7 +120,7 @@ namespace {
}
int status;
scoped_ptr<connection> con;
std::unique_ptr<connection> con;
string hostname;
string ip;
status = get_local_hostname(hostname);
......
// Copyright (C) 2008 Davis E. King (davis@dlib.net)
// License: Boost Software License See LICENSE.txt for the full license.
#include <algorithm>
#include <memory>
#include "tester.h"
#include <dlib/sockets.h>
#include <dlib/threads.h>
#include <dlib/array.h>
#include <algorithm>
// This is called an unnamed-namespace and it has the effect of making everything
// inside this file "private" so that everything you declare will have static linkage.
......@@ -39,7 +41,7 @@ namespace
{
try
{
scoped_ptr<connection> con(connect("127.0.0.1", port_num));
std::unique_ptr<connection> con(connect("127.0.0.1", port_num));
// Send a copy of the data down the connection so we can test our the read() function
// that uses timeouts in the main thread.
......@@ -63,7 +65,7 @@ namespace
{
try
{
scoped_ptr<connection> con(connect("127.0.0.1", port_num));
std::unique_ptr<connection> con(connect("127.0.0.1", port_num));
// just do nothing until the connection closes
char ch;
......@@ -120,17 +122,17 @@ namespace
dlog << LINFO << "data block size: " << data_to_send.size();
scoped_ptr<listener> list;
std::unique_ptr<listener> list;
DLIB_TEST(create_listener(list, port_num, "127.0.0.1") == 0);
DLIB_TEST(list);
DLIB_TEST(bool(list));
// kick off the sending threads
start();
dlib::array<scoped_ptr<connection> > cons;
dlib::array<std::unique_ptr<connection> > cons;
std::vector<long> bytes_received(6,0);
scoped_ptr<connection> con_temp;
std::unique_ptr<connection> con_temp;
// accept the 6 connections we should get
for (int i = 0; i < 6; ++i)
......
......@@ -2,15 +2,15 @@
// License: Boost Software License See LICENSE.txt for the full license.
#include <cstdlib>
#include <sstream>
#include <string>
#include <cstdlib>
#include <vector>
#include <ctime>
#include <dlib/sockets.h>
#include <dlib/misc_api.h>
#include <dlib/sockstreambuf.h>
#include <vector>
#include <dlib/smart_pointers.h>
#include "tester.h"
......@@ -143,7 +143,7 @@ namespace
}
// make sure con gets deleted
scoped_ptr<connection> del_con(con);
std::unique_ptr<connection> del_con(con);
ssb buf(con);
istream in(&buf);
......
......@@ -17,7 +17,7 @@
#endif
#define DLIB_TEST(_exp) check_test(_exp, __LINE__, __FILE__, #_exp)
#define DLIB_TEST(_exp) check_test(bool(_exp), __LINE__, __FILE__, #_exp)
#define DLIB_TEST_MSG(_exp,_message) \
do{increment_test_count(); if ( !(_exp) ) \
......
......@@ -18,7 +18,7 @@ namespace
logger dlog("test.tuple");
struct nil
struct s_nil
{
template <typename T>
void operator() (
......@@ -122,10 +122,10 @@ namespace
b = a;
inc i;
nil n;
s_nil n;
a.for_each(inc());
a.for_each(i);
const_cast<const T&>(a).for_each(nil());
const_cast<const T&>(a).for_each(s_nil());
const_cast<const T&>(a).for_each(n);
DLIB_TEST(a.get<0>() == b.get<0>()+2);
......@@ -145,7 +145,7 @@ namespace
a.for_index(i,0);
a.for_index(inc(),1);
const_cast<const T&>(a).for_index(n,2);
const_cast<const T&>(a).for_index(nil(),0);
const_cast<const T&>(a).for_index(s_nil(),0);
DLIB_TEST(a.get<0>() == b.get<0>()+1);
DLIB_TEST(a.get<1>() == b.get<1>()+1);
......
// Copyright (C) 2007 Davis E. King (davis@dlib.net)
// License: Boost Software License See LICENSE.txt for the full license.
#ifndef DLIB_THREAD_FUNCTIOn_
#define DLIB_THREAD_FUNCTIOn_
#define DLIB_THREAD_FUNCTIOn_
#include <memory>
#include "thread_function_extension_abstract.h"
#include "threads_kernel.h"
#include "auto_mutex_extension.h"
#include "threaded_object_extension.h"
#include "../smart_pointers.h"
namespace dlib
{
......@@ -197,7 +198,7 @@ namespace dlib
f->go();
}
scoped_ptr<base_funct> f;
std::unique_ptr<base_funct> f;
// restricted functions
thread_function(thread_function&); // copy constructor
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment