Commit 37c815f6 authored by Davis King's avatar Davis King

All I did in this change was rename calls to array_to_matrix(),

vector_to_matrix(), pointer_to_column_vector(), and pointer_to_matrix() to
mat() (in addition to adding a few more mat() overloads for certain things).
parent 0d970e47
...@@ -367,7 +367,7 @@ namespace dlib ...@@ -367,7 +367,7 @@ namespace dlib
- #num_labels == the number of distinct values in labels. - #num_labels == the number of distinct values in labels.
- returns a vector V such that: - returns a vector V such that:
- V.size() == labels.size() - V.size() == labels.size()
- max(vector_to_matrix(V))+1 == num_labels. - max(mat(V))+1 == num_labels.
- for all valid i,j: - for all valid i,j:
- if (labels[i] == labels[j]) then - if (labels[i] == labels[j]) then
- V[i] == V[j] - V[i] == V[j]
......
...@@ -92,7 +92,7 @@ namespace dlib ...@@ -92,7 +92,7 @@ namespace dlib
// predict next state // predict next state
for (long i = 0; i < next.size(); ++i) for (long i = 0; i < next.size(); ++i)
next(i) = filter(vector_to_matrix(data[i])); next(i) = filter(mat(data[i]));
} }
template <typename EXP> template <typename EXP>
...@@ -127,7 +127,7 @@ namespace dlib ...@@ -127,7 +127,7 @@ namespace dlib
// showing it to the rls filter so it can do its thing. // showing it to the rls filter so it can do its thing.
if (count >= 2) if (count >= 2)
{ {
filter.train(vector_to_matrix(data[i]), z(i)); filter.train(mat(data[i]), z(i));
} }
// keep track of the measurements in our circular buffer // keep track of the measurements in our circular buffer
...@@ -139,7 +139,7 @@ namespace dlib ...@@ -139,7 +139,7 @@ namespace dlib
{ {
// predict next state // predict next state
for (long i = 0; i < z.size(); ++i) for (long i = 0; i < z.size(); ++i)
next(i) = filter(vector_to_matrix(data[i])); next(i) = filter(mat(data[i]));
} }
else else
{ {
......
...@@ -2375,7 +2375,7 @@ namespace dlib ...@@ -2375,7 +2375,7 @@ namespace dlib
/*! /*!
requires requires
- image_type == an implementation of array2d/array2d_kernel_abstract.h or - image_type == an implementation of array2d/array2d_kernel_abstract.h or
a dlib::matrix or something convertible to a matrix via array_to_matrix() a dlib::matrix or something convertible to a matrix via mat()
- pixel_traits<typename image_type::type> must be defined - pixel_traits<typename image_type::type> must be defined
ensures ensures
- #*this widget is now displaying the given image new_img. - #*this widget is now displaying the given image new_img.
...@@ -2790,7 +2790,7 @@ namespace dlib ...@@ -2790,7 +2790,7 @@ namespace dlib
/*! /*!
requires requires
- image_type == an implementation of array2d/array2d_kernel_abstract.h or - image_type == an implementation of array2d/array2d_kernel_abstract.h or
a dlib::matrix or something convertible to a matrix via array_to_matrix() a dlib::matrix or something convertible to a matrix via mat()
- pixel_traits<typename image_type::type> must be defined - pixel_traits<typename image_type::type> must be defined
ensures ensures
- this object is properly initialized - this object is properly initialized
......
...@@ -67,7 +67,7 @@ namespace dlib ...@@ -67,7 +67,7 @@ namespace dlib
) )
{ {
COMPILE_TIME_ASSERT( pixel_traits<typename image_type::type>::has_alpha == false ); COMPILE_TIME_ASSERT( pixel_traits<typename image_type::type>::has_alpha == false );
load_impl(array_to_matrix(img)); load_impl(mat(img));
} }
inline void unload( inline void unload(
......
...@@ -102,7 +102,7 @@ namespace dlib ...@@ -102,7 +102,7 @@ namespace dlib
/*! /*!
requires requires
- image_type is a dlib::matrix or something convertible to a matrix - image_type is a dlib::matrix or something convertible to a matrix
via array_to_matrix() via mat()
- pixel_traits<typename image_type::type>::has_alpha == false - pixel_traits<typename image_type::type>::has_alpha == false
ensures ensures
- if (img.nr() < min_size || img.nc() < min_size) then - if (img.nr() < min_size || img.nc() < min_size) then
......
...@@ -83,7 +83,7 @@ namespace dlib ...@@ -83,7 +83,7 @@ namespace dlib
) )
{ {
COMPILE_TIME_ASSERT( pixel_traits<typename image_type::type>::has_alpha == false ); COMPILE_TIME_ASSERT( pixel_traits<typename image_type::type>::has_alpha == false );
load_impl(array_to_matrix(img)); load_impl(mat(img));
} }
inline void unload( inline void unload(
......
...@@ -158,7 +158,7 @@ namespace dlib ...@@ -158,7 +158,7 @@ namespace dlib
/*! /*!
requires requires
- image_type is a dlib::matrix or something convertible to a matrix - image_type is a dlib::matrix or something convertible to a matrix
via array_to_matrix() via mat()
- pixel_traits<typename image_type::type>::has_alpha == false - pixel_traits<typename image_type::type>::has_alpha == false
ensures ensures
- if (img.nr() < min_size || img.nc() < min_size) then - if (img.nr() < min_size || img.nc() < min_size) then
......
...@@ -102,7 +102,7 @@ namespace dlib ...@@ -102,7 +102,7 @@ namespace dlib
{ {
const typename image_array_type::type& img = images[rects[i].first]; const typename image_array_type::type& img = images[rects[i].first];
const rectangle rect = get_rect(img).intersect(translate_rect(rects[i].second,position)); const rectangle rect = get_rect(img).intersect(translate_rect(rects[i].second,position));
temp += sum(matrix_cast<ptype>(subm(array_to_matrix(img), rect))); temp += sum(matrix_cast<ptype>(subm(mat(img), rect)));
} }
return static_cast<double>(temp); return static_cast<double>(temp);
...@@ -161,7 +161,7 @@ namespace dlib ...@@ -161,7 +161,7 @@ namespace dlib
{ {
const typename image_array_type::type& img = images[fixed_rects[i].first]; const typename image_array_type::type& img = images[fixed_rects[i].first];
const rectangle rect = get_rect(img).intersect(translate_rect(fixed_rects[i].second,position)); const rectangle rect = get_rect(img).intersect(translate_rect(fixed_rects[i].second,position));
temp += sum(matrix_cast<ptype>(subm(array_to_matrix(img), rect))); temp += sum(matrix_cast<ptype>(subm(mat(img), rect)));
} }
if (images.size() > 0) if (images.size() > 0)
...@@ -176,7 +176,7 @@ namespace dlib ...@@ -176,7 +176,7 @@ namespace dlib
const rectangle rect = get_rect(tempimg).intersect(translate_rect(window,position)); const rectangle rect = get_rect(tempimg).intersect(translate_rect(window,position));
if (rect.is_empty() == false) if (rect.is_empty() == false)
temp += std::max(0,max(matrix_cast<ptype>(subm(array_to_matrix(tempimg), rect)))); temp += std::max(0,max(matrix_cast<ptype>(subm(mat(tempimg), rect))));
} }
} }
......
...@@ -75,7 +75,7 @@ namespace dlib ...@@ -75,7 +75,7 @@ namespace dlib
if (is_same_object(dest,src)) if (is_same_object(dest,src))
return; return;
impl_assign_image(dest, array_to_matrix(src)); impl_assign_image(dest, mat(src));
} }
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
...@@ -175,7 +175,7 @@ namespace dlib ...@@ -175,7 +175,7 @@ namespace dlib
if (is_same_object(dest,src)) if (is_same_object(dest,src))
return; return;
impl_assign_image_scaled(dest, array_to_matrix(src),thresh); impl_assign_image_scaled(dest, mat(src),thresh);
} }
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
......
...@@ -21,7 +21,7 @@ namespace dlib ...@@ -21,7 +21,7 @@ namespace dlib
/*! /*!
requires requires
- src_image_type == is an implementation of array2d/array2d_kernel_abstract.h or - src_image_type == is an implementation of array2d/array2d_kernel_abstract.h or
a dlib::matrix or something convertible to a matrix via array_to_matrix() a dlib::matrix or something convertible to a matrix via mat()
- dest_image_type == is an implementation of array2d/array2d_kernel_abstract.h or - dest_image_type == is an implementation of array2d/array2d_kernel_abstract.h or
is a dlib::matrix. is a dlib::matrix.
- pixel_traits<typename src_image_type::type> is defined - pixel_traits<typename src_image_type::type> is defined
...@@ -48,7 +48,7 @@ namespace dlib ...@@ -48,7 +48,7 @@ namespace dlib
/*! /*!
requires requires
- src_image_type == is an implementation of array2d/array2d_kernel_abstract.h or - src_image_type == is an implementation of array2d/array2d_kernel_abstract.h or
a dlib::matrix or something convertible to a matrix via array_to_matrix() a dlib::matrix or something convertible to a matrix via mat()
- dest_image_type == is an implementation of array2d/array2d_kernel_abstract.h or - dest_image_type == is an implementation of array2d/array2d_kernel_abstract.h or
is a dlib::matrix. is a dlib::matrix.
- pixel_traits<typename src_image_type::type> is defined - pixel_traits<typename src_image_type::type> is defined
...@@ -75,8 +75,8 @@ namespace dlib ...@@ -75,8 +75,8 @@ namespace dlib
deviation of src_img. Call the mean M and the standard deviation deviation of src_img. Call the mean M and the standard deviation
D. Then the scaling from src_img to dest_img is performed using D. Then the scaling from src_img to dest_img is performed using
the following mapping: the following mapping:
let SRC_UPPER = min(M + thresh*D, max(array_to_matrix(src_img))) let SRC_UPPER = min(M + thresh*D, max(mat(src_img)))
let SRC_LOWER = max(M - thresh*D, min(array_to_matrix(src_img))) let SRC_LOWER = max(M - thresh*D, min(mat(src_img)))
let DEST_UPPER = pixel_traits<dest_image_type::type>::max() let DEST_UPPER = pixel_traits<dest_image_type::type>::max()
let DEST_LOWER = pixel_traits<dest_image_type::type>::min() let DEST_LOWER = pixel_traits<dest_image_type::type>::min()
......
...@@ -78,7 +78,7 @@ namespace dlib ...@@ -78,7 +78,7 @@ namespace dlib
(i.e. rect must not be outside the integral image) (i.e. rect must not be outside the integral image)
ensures ensures
- Let O denote the image this integral image was generated from. - Let O denote the image this integral image was generated from.
Then this function returns sum(subm(array_to_matrix(O),rect)). Then this function returns sum(subm(mat(O),rect)).
That is, this function returns the sum of the pixels in O that That is, this function returns the sum of the pixels in O that
are contained within the given rectangle. are contained within the given rectangle.
!*/ !*/
......
...@@ -554,7 +554,7 @@ namespace dlib ...@@ -554,7 +554,7 @@ namespace dlib
<< "\n\t is_same_object(in_img, out_img): " << is_same_object(in_img, out_img) << "\n\t is_same_object(in_img, out_img): " << is_same_object(in_img, out_img)
); );
assign_image(out_img, fliplr(array_to_matrix(in_img))); assign_image(out_img, fliplr(mat(in_img)));
} }
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
...@@ -575,7 +575,7 @@ namespace dlib ...@@ -575,7 +575,7 @@ namespace dlib
<< "\n\t is_same_object(in_img, out_img): " << is_same_object(in_img, out_img) << "\n\t is_same_object(in_img, out_img): " << is_same_object(in_img, out_img)
); );
assign_image(out_img, flipud(array_to_matrix(in_img))); assign_image(out_img, flipud(mat(in_img)));
} }
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
......
...@@ -177,7 +177,7 @@ namespace dlib ...@@ -177,7 +177,7 @@ namespace dlib
- else - else
- #label_img[r][c] != 0 - #label_img[r][c] != 0
- if (img.size() != 0) then - if (img.size() != 0) then
- returns max(array_to_matrix(#label_img))+1 - returns max(mat(#label_img))+1
(i.e. returns a number one greater than the maximum blob id number, (i.e. returns a number one greater than the maximum blob id number,
this is the number of blobs found.) this is the number of blobs found.)
- else - else
......
...@@ -663,7 +663,7 @@ namespace dlib ...@@ -663,7 +663,7 @@ namespace dlib
strip = strip.intersect(get_rect(img)); strip = strip.intersect(get_rect(img));
if (!strip.is_empty()) if (!strip.is_empty())
{ {
column_sum[j] = sum(matrix_cast<ptype>(subm(array_to_matrix(img),strip))); column_sum[j] = sum(matrix_cast<ptype>(subm(mat(img),strip)));
} }
++left; ++left;
...@@ -679,7 +679,7 @@ namespace dlib ...@@ -679,7 +679,7 @@ namespace dlib
// Now do the bulk of the filtering work. // Now do the bulk of the filtering work.
for (long r = 0; r < img.nr(); ++r) for (long r = 0; r < img.nr(); ++r)
{ {
// set to sum at point(-1,r). i.e. should be equal to sum(array_to_matrix(img), translate_rect(rect, point(-1,r))) // set to sum at point(-1,r). i.e. should be equal to sum(mat(img), translate_rect(rect, point(-1,r)))
// We compute it's value in the next loop. // We compute it's value in the next loop.
ptype cur_sum = 0; ptype cur_sum = 0;
......
...@@ -87,7 +87,7 @@ namespace dlib ...@@ -87,7 +87,7 @@ namespace dlib
counts[h[i]] += 1; counts[h[i]] += 1;
} }
const unsigned long max_h = index_of_max(vector_to_matrix(counts)); const unsigned long max_h = index_of_max(mat(counts));
temp.clear(); temp.clear();
for (unsigned long i = 0; i < v.size(); ++i) for (unsigned long i = 0; i < v.size(); ++i)
......
...@@ -301,7 +301,7 @@ namespace dlib ...@@ -301,7 +301,7 @@ namespace dlib
} }
} }
map_assignment[id_i] = index_of_max(vector_to_matrix(b)); map_assignment[id_i] = index_of_max(mat(b));
} }
} }
......
...@@ -28,12 +28,12 @@ namespace dlib ...@@ -28,12 +28,12 @@ namespace dlib
// can't call max on an empty vector. So put an if here to guard against it. // can't call max on an empty vector. So put an if here to guard against it.
if (assignment.size() > 0) if (assignment.size() > 0)
{ {
DLIB_ASSERT(0 <= min(vector_to_matrix(assignment)) && max(vector_to_matrix(assignment)) < cost.nr(), DLIB_ASSERT(0 <= min(mat(assignment)) && max(mat(assignment)) < cost.nr(),
"\t type assignment_cost(cost,assignment)" "\t type assignment_cost(cost,assignment)"
<< "\n\t cost.nr(): " << cost.nr() << "\n\t cost.nr(): " << cost.nr()
<< "\n\t cost.nc(): " << cost.nc() << "\n\t cost.nc(): " << cost.nc()
<< "\n\t min(assignment): " << min(vector_to_matrix(assignment)) << "\n\t min(assignment): " << min(mat(assignment))
<< "\n\t max(assignment): " << max(vector_to_matrix(assignment)) << "\n\t max(assignment): " << max(mat(assignment))
); );
} }
#endif #endif
......
...@@ -193,7 +193,7 @@ namespace dlib ...@@ -193,7 +193,7 @@ namespace dlib
universe_set.top_min = 0; universe_set.top_min = 0;
universe_set.bottom_max = mat.nr()-1; universe_set.bottom_max = mat.nr()-1;
universe_set.top_max = mat.nr()-1; universe_set.top_max = mat.nr()-1;
universe_set.weight = sum(rowm(array_to_matrix(sum_pos),mat.nr())); universe_set.weight = sum(rowm(dlib::mat(sum_pos),mat.nr()));
q.push(universe_set); q.push(universe_set);
...@@ -247,7 +247,7 @@ namespace dlib ...@@ -247,7 +247,7 @@ namespace dlib
} }
universe_set.weight = sum(rowm(array_to_matrix(sum_pos),mat.nr())); universe_set.weight = sum(rowm(dlib::mat(sum_pos),mat.nr()));
if (universe_set.weight <= thresh) if (universe_set.weight <= thresh)
break; break;
......
...@@ -874,7 +874,7 @@ L360: ...@@ -874,7 +874,7 @@ L360:
//goto L720; //goto L720;
} }
++nf; ++nf;
f = calfun(pointer_to_column_vector(&x[1], n)); f = calfun(mat(&x[1], n));
if (ntrits == -1) { if (ntrits == -1) {
fsave = f; fsave = f;
goto L720; goto L720;
...@@ -1946,7 +1946,7 @@ L50: ...@@ -1946,7 +1946,7 @@ L50:
} }
/* L60: */ /* L60: */
} }
f = calfun(pointer_to_column_vector(&x[1],n)); f = calfun(mat(&x[1],n));
fval[nf] = f; fval[nf] = f;
if (nf == 1) { if (nf == 1) {
fbeg = f; fbeg = f;
...@@ -2572,7 +2572,7 @@ L260: ...@@ -2572,7 +2572,7 @@ L260:
/* L290: */ /* L290: */
} }
++(nf); ++(nf);
f = calfun(pointer_to_column_vector(&w[1],n)); f = calfun(mat(&w[1],n));
fval[kpt] = f; fval[kpt] = f;
if (f < fval[kopt]) { if (f < fval[kopt]) {
kopt = kpt; kopt = kpt;
......
...@@ -191,18 +191,18 @@ namespace dlib ...@@ -191,18 +191,18 @@ namespace dlib
) )
{ {
// make sure requires clause is not broken // make sure requires clause is not broken
DLIB_ASSERT(is_vector(vector_to_matrix(list)) && list.size() > 0 && DLIB_ASSERT(is_vector(mat(list)) && list.size() > 0 &&
is_col_vector(x) && radius > 0, is_col_vector(x) && radius > 0,
"\t double solve_least_squares()" "\t double solve_least_squares()"
<< "\n\t invalid arguments were given to this function" << "\n\t invalid arguments were given to this function"
<< "\n\t is_vector(list): " << is_vector(vector_to_matrix(list)) << "\n\t is_vector(list): " << is_vector(mat(list))
<< "\n\t list.size(): " << list.size() << "\n\t list.size(): " << list.size()
<< "\n\t is_col_vector(x): " << is_col_vector(x) << "\n\t is_col_vector(x): " << is_col_vector(x)
<< "\n\t radius: " << radius << "\n\t radius: " << radius
); );
return find_min_trust_region(stop_strategy, return find_min_trust_region(stop_strategy,
least_squares_model<T>(f, der, vector_to_matrix(list)), least_squares_model<T>(f, der, mat(list)),
x, x,
radius); radius);
} }
...@@ -314,18 +314,18 @@ namespace dlib ...@@ -314,18 +314,18 @@ namespace dlib
) )
{ {
// make sure requires clause is not broken // make sure requires clause is not broken
DLIB_ASSERT(is_vector(vector_to_matrix(list)) && list.size() > 0 && DLIB_ASSERT(is_vector(mat(list)) && list.size() > 0 &&
is_col_vector(x) && radius > 0, is_col_vector(x) && radius > 0,
"\t double solve_least_squares_lm()" "\t double solve_least_squares_lm()"
<< "\n\t invalid arguments were given to this function" << "\n\t invalid arguments were given to this function"
<< "\n\t is_vector(list): " << is_vector(vector_to_matrix(list)) << "\n\t is_vector(list): " << is_vector(mat(list))
<< "\n\t list.size(): " << list.size() << "\n\t list.size(): " << list.size()
<< "\n\t is_col_vector(x): " << is_col_vector(x) << "\n\t is_col_vector(x): " << is_col_vector(x)
<< "\n\t radius: " << radius << "\n\t radius: " << radius
); );
return find_min_trust_region(stop_strategy, return find_min_trust_region(stop_strategy,
least_squares_lm_model<T>(f, der, vector_to_matrix(list)), least_squares_lm_model<T>(f, der, mat(list)),
x, x,
radius); radius);
} }
......
...@@ -30,7 +30,7 @@ namespace dlib ...@@ -30,7 +30,7 @@ namespace dlib
requires requires
- stop_strategy == an object that defines a stop strategy such as one of - stop_strategy == an object that defines a stop strategy such as one of
the objects from dlib/optimization/optimization_stop_strategies_abstract.h the objects from dlib/optimization/optimization_stop_strategies_abstract.h
- list == a matrix or something convertible to a matrix via vector_to_matrix() - list == a matrix or something convertible to a matrix via mat()
such as a std::vector. such as a std::vector.
- is_vector(list) == true - is_vector(list) == true
- list.size() > 0 - list.size() > 0
...@@ -78,7 +78,7 @@ namespace dlib ...@@ -78,7 +78,7 @@ namespace dlib
requires requires
- stop_strategy == an object that defines a stop strategy such as one of - stop_strategy == an object that defines a stop strategy such as one of
the objects from dlib/optimization/optimization_stop_strategies_abstract.h the objects from dlib/optimization/optimization_stop_strategies_abstract.h
- list == a matrix or something convertible to a matrix via vector_to_matrix() - list == a matrix or something convertible to a matrix via mat()
such as a std::vector. such as a std::vector.
- is_vector(list) == true - is_vector(list) == true
- list.size() > 0 - list.size() > 0
......
...@@ -225,9 +225,9 @@ namespace dlib ...@@ -225,9 +225,9 @@ namespace dlib
// Note that we warm start this optimization by using the alpha from the last // Note that we warm start this optimization by using the alpha from the last
// iteration as the starting point. // iteration as the starting point.
if (num_nonnegative != 0) if (num_nonnegative != 0)
solve_qp4_using_smo(rowm(planes,range(0,num_nonnegative-1)), K, vector_to_matrix(bs), alpha, eps, sub_max_iter); solve_qp4_using_smo(rowm(planes,range(0,num_nonnegative-1)), K, mat(bs), alpha, eps, sub_max_iter);
else else
solve_qp_using_smo(K, vector_to_matrix(bs), alpha, eps, sub_max_iter); solve_qp_using_smo(K, mat(bs), alpha, eps, sub_max_iter);
// construct the w that minimized the subproblem. // construct the w that minimized the subproblem.
w = -(planes*alpha); w = -(planes*alpha);
...@@ -245,14 +245,14 @@ namespace dlib ...@@ -245,14 +245,14 @@ namespace dlib
// Compute the lower bound on the true objective given to us by the cutting // Compute the lower bound on the true objective given to us by the cutting
// plane subproblem. // plane subproblem.
cp_obj = -0.5*trans(w)*w + trans(alpha)*vector_to_matrix(bs); cp_obj = -0.5*trans(w)*w + trans(alpha)*mat(bs);
// If it has been a while since a cutting plane was an active constraint then // If it has been a while since a cutting plane was an active constraint then
// we should throw it away. // we should throw it away.
while (max(vector_to_matrix(miss_count)) >= inactive_thresh) while (max(mat(miss_count)) >= inactive_thresh)
{ {
const long idx = index_of_max(vector_to_matrix(miss_count)); const long idx = index_of_max(mat(miss_count));
bs.erase(bs.begin()+idx); bs.erase(bs.begin()+idx);
miss_count.erase(miss_count.begin()+idx); miss_count.erase(miss_count.begin()+idx);
K = removerc(K, idx, idx); K = removerc(K, idx, idx);
......
...@@ -74,7 +74,7 @@ namespace dlib ...@@ -74,7 +74,7 @@ namespace dlib
const T& y const T& y
) )
{ {
return maximum_nu_impl(vector_to_matrix(y)); return maximum_nu_impl(mat(y));
} }
template < template <
...@@ -84,7 +84,7 @@ namespace dlib ...@@ -84,7 +84,7 @@ namespace dlib
const T& y const T& y
) )
{ {
return maximum_nu_impl(vector_to_matrix(y)); return maximum_nu_impl(mat(y));
} }
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
......
...@@ -37,7 +37,7 @@ namespace dlib ...@@ -37,7 +37,7 @@ namespace dlib
); );
/*! /*!
requires requires
- T == a matrix object or an object convertible to a matrix via vector_to_matrix() - T == a matrix object or an object convertible to a matrix via mat()
- is_col_vector(y) == true - is_col_vector(y) == true
- y.size() > 1 - y.size() > 1
- sum((y == +1) + (y == -1)) == y.size() - sum((y == +1) + (y == -1)) == y.size()
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include <vector> #include <vector>
#include "../algs.h" #include "../algs.h"
#include "../serialize.h" #include "../serialize.h"
#include "../matrix/matrix_mat.h"
namespace dlib namespace dlib
{ {
...@@ -209,6 +210,19 @@ namespace dlib ...@@ -209,6 +210,19 @@ namespace dlib
} }
} }
// ----------------------------------------------------------------------------------------
template <
typename T
>
const matrix_op<op_array_to_mat<circular_buffer<T> > > mat (
const circular_buffer<T>& m
)
{
typedef op_array_to_mat<circular_buffer<T> > op;
return matrix_op<op>(op(m));
}
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
} }
......
...@@ -222,6 +222,23 @@ namespace dlib ...@@ -222,6 +222,23 @@ namespace dlib
provides deserialization support provides deserialization support
!*/ !*/
// ----------------------------------------------------------------------------------------
template <
typename T
>
const matrix_exp mat (
const circular_buffer<T>& m
);
/*!
ensures
- returns a matrix R such that:
- is_col_vector(R) == true
- R.size() == m.size()
- for all valid r:
R(r) == m[r]
!*/
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
} }
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include "../algs.h" #include "../algs.h"
#include "../string.h" #include "../string.h"
#include "../serialize.h" #include "../serialize.h"
#include "../matrix/matrix_mat.h"
#include <iostream> #include <iostream>
namespace dlib namespace dlib
...@@ -346,6 +347,19 @@ namespace dlib ...@@ -346,6 +347,19 @@ namespace dlib
return subset; return subset;
} }
// ----------------------------------------------------------------------------------------
template <
typename T
>
const matrix_op<op_array_to_mat<random_subset_selector<T> > > mat (
const random_subset_selector<T>& m
)
{
typedef op_array_to_mat<random_subset_selector<T> > op;
return matrix_op<op>(op(m));
}
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
} }
......
...@@ -351,6 +351,23 @@ namespace dlib ...@@ -351,6 +351,23 @@ namespace dlib
generator used by this function. generator used by this function.
!*/ !*/
// ----------------------------------------------------------------------------------------
template <
typename T
>
const matrix_exp mat (
const random_subset_selector<T>& m
);
/*!
ensures
- returns a matrix R such that:
- is_col_vector(R) == true
- R.size() == m.size()
- for all valid r:
R(r) == m[r]
!*/
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
} }
......
...@@ -549,7 +549,7 @@ namespace dlib ...@@ -549,7 +549,7 @@ namespace dlib
<< "\n\t b.size(): " << b.size() << "\n\t b.size(): " << b.size()
); );
return mean(squared(matrix_cast<double>(vector_to_matrix(a))-matrix_cast<double>(vector_to_matrix(b)))); return mean(squared(matrix_cast<double>(mat(a))-matrix_cast<double>(mat(b))));
} }
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
...@@ -737,8 +737,8 @@ namespace dlib ...@@ -737,8 +737,8 @@ namespace dlib
<< "\n\tthis: " << this << "\n\tthis: " << this
); );
m = mean(vector_to_matrix(samples)); m = mean(mat(samples));
sd = reciprocal(sqrt(variance(vector_to_matrix(samples)))); sd = reciprocal(sqrt(variance(mat(samples))));
} }
long in_vector_size ( long in_vector_size (
...@@ -900,7 +900,7 @@ namespace dlib ...@@ -900,7 +900,7 @@ namespace dlib
<< "\n\tyou have to give a nonempty set of samples to this function" << "\n\tyou have to give a nonempty set of samples to this function"
<< "\n\tthis: " << this << "\n\tthis: " << this
); );
train_pca_impl(vector_to_matrix(samples),eps); train_pca_impl(mat(samples),eps);
} }
long in_vector_size ( long in_vector_size (
......
...@@ -101,7 +101,7 @@ namespace dlib ...@@ -101,7 +101,7 @@ namespace dlib
- a.size() == b.size() - a.size() == b.size()
ensures ensures
- returns the mean squared error between all the elements of a and b. - returns the mean squared error between all the elements of a and b.
(i.e. mean(squared(vector_to_matrix(a)-vector_to_matrix(b)))) (i.e. mean(squared(mat(a)-mat(b))))
!*/ !*/
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
...@@ -584,7 +584,7 @@ namespace dlib ...@@ -584,7 +584,7 @@ namespace dlib
requires requires
- samples.size() > 0 - samples.size() > 0
- samples == a column matrix or something convertible to a column - samples == a column matrix or something convertible to a column
matrix via vector_to_matrix(). Also, x should contain matrix via mat(). Also, x should contain
matrix_type objects that represent nonempty column vectors. matrix_type objects that represent nonempty column vectors.
ensures ensures
- #in_vector_size() == samples(0).nr() - #in_vector_size() == samples(0).nr()
...@@ -742,7 +742,7 @@ namespace dlib ...@@ -742,7 +742,7 @@ namespace dlib
- 0 < eps <= 1 - 0 < eps <= 1
- samples.size() > 0 - samples.size() > 0
- samples == a column matrix or something convertible to a column - samples == a column matrix or something convertible to a column
matrix via vector_to_matrix(). Also, x should contain matrix via mat(). Also, x should contain
matrix_type objects that represent nonempty column vectors. matrix_type objects that represent nonempty column vectors.
ensures ensures
- This object has learned how to normalize vectors that look like - This object has learned how to normalize vectors that look like
......
...@@ -177,6 +177,18 @@ namespace dlib ...@@ -177,6 +177,18 @@ namespace dlib
const array_type& array; const array_type& array;
const std::vector<unsigned long>& idx_set; const std::vector<unsigned long>& idx_set;
}; };
template <
typename T
>
const matrix_op<op_array_to_mat<array_subset_helper<T> > > mat (
const array_subset_helper<T>& m
)
{
typedef op_array_to_mat<array_subset_helper<T> > op;
return matrix_op<op>(op(m));
}
} }
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
......
...@@ -69,7 +69,7 @@ namespace dlib ...@@ -69,7 +69,7 @@ namespace dlib
const T& basis_samples const T& basis_samples
) )
{ {
load_impl(kernel_, vector_to_matrix(basis_samples)); load_impl(kernel_, mat(basis_samples));
} }
void load( void load(
...@@ -150,7 +150,7 @@ namespace dlib ...@@ -150,7 +150,7 @@ namespace dlib
<< "\n\t this: " << this << "\n\t this: " << this
); );
return decision_function<kernel_type>(trans(weights)*vect, 0, kernel, vector_to_matrix(basis)); return decision_function<kernel_type>(trans(weights)*vect, 0, kernel, mat(basis));
} }
template <typename EXP> template <typename EXP>
...@@ -168,7 +168,7 @@ namespace dlib ...@@ -168,7 +168,7 @@ namespace dlib
<< "\n\t this: " << this << "\n\t this: " << this
); );
return distance_function<kernel_type>(trans(weights)*vect, dot(vect,vect), kernel, vector_to_matrix(basis)); return distance_function<kernel_type>(trans(weights)*vect, dot(vect,vect), kernel, mat(basis));
} }
const projection_function<kernel_type> get_projection_function ( const projection_function<kernel_type> get_projection_function (
...@@ -181,7 +181,7 @@ namespace dlib ...@@ -181,7 +181,7 @@ namespace dlib
<< "\n\t this: " << this << "\n\t this: " << this
); );
return projection_function<kernel_type>(weights, kernel, vector_to_matrix(basis)); return projection_function<kernel_type>(weights, kernel, mat(basis));
} }
const matrix<scalar_type,0,0,mem_manager_type> get_transformation_to ( const matrix<scalar_type,0,0,mem_manager_type> get_transformation_to (
...@@ -242,7 +242,7 @@ namespace dlib ...@@ -242,7 +242,7 @@ namespace dlib
tmat = colm(target.weights, range(0,num1-1))*kernel_matrix(kernel, basis)*trans(weights); tmat = colm(target.weights, range(0,num1-1))*kernel_matrix(kernel, basis)*trans(weights);
empirical_kernel_map temp_ekm; empirical_kernel_map temp_ekm;
temp_ekm.load(kernel, rowm(vector_to_matrix(target.basis), range(num1,num2-1))); temp_ekm.load(kernel, rowm(mat(target.basis), range(num1,num2-1)));
partial_projection = temp_ekm.get_projection_function(); partial_projection = temp_ekm.get_projection_function();
......
...@@ -124,7 +124,7 @@ namespace dlib ...@@ -124,7 +124,7 @@ namespace dlib
); );
/*! /*!
requires requires
- T must be a dlib::matrix type or something convertible to a matrix via vector_to_matrix() - T must be a dlib::matrix type or something convertible to a matrix via mat()
(e.g. a std::vector) (e.g. a std::vector)
- is_vector(basis_samples) == true - is_vector(basis_samples) == true
- basis_samples.size() > 0 - basis_samples.size() > 0
......
...@@ -150,7 +150,7 @@ namespace dlib ...@@ -150,7 +150,7 @@ namespace dlib
const label_matrix_type& labels const label_matrix_type& labels
) )
{ {
return rank_features_impl(kc, vector_to_matrix(samples), vector_to_matrix(labels)); return rank_features_impl(kc, mat(samples), mat(labels));
} }
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
...@@ -266,14 +266,14 @@ namespace dlib ...@@ -266,14 +266,14 @@ namespace dlib
const long num_features const long num_features
) )
{ {
if (vector_to_matrix(samples).nr() > 0 && num_features == vector_to_matrix(samples)(0).nr()) if (mat(samples).nr() > 0 && num_features == mat(samples)(0).nr())
{ {
// if we are going to rank them all then might as well do the recursive feature elimination version // if we are going to rank them all then might as well do the recursive feature elimination version
return rank_features_impl(kc, vector_to_matrix(samples), vector_to_matrix(labels)); return rank_features_impl(kc, mat(samples), mat(labels));
} }
else else
{ {
return rank_features_impl(kc, vector_to_matrix(samples), vector_to_matrix(labels), num_features); return rank_features_impl(kc, mat(samples), mat(labels), num_features);
} }
} }
...@@ -416,8 +416,8 @@ namespace dlib ...@@ -416,8 +416,8 @@ namespace dlib
<< "\n\t is_binary_classification_problem(): " << is_binary_classification_problem(samples, labels) << "\n\t is_binary_classification_problem(): " << is_binary_classification_problem(samples, labels)
); );
return rank_features_helpers::find_gamma_with_big_centroid_gap_impl(vector_to_matrix(samples), return rank_features_helpers::find_gamma_with_big_centroid_gap_impl(mat(samples),
vector_to_matrix(labels), mat(labels),
initial_gamma, initial_gamma,
num_sv, num_sv,
false); false);
...@@ -443,8 +443,8 @@ namespace dlib ...@@ -443,8 +443,8 @@ namespace dlib
<< "\n\t is_binary_classification_problem(): " << is_binary_classification_problem(samples, labels) << "\n\t is_binary_classification_problem(): " << is_binary_classification_problem(samples, labels)
); );
return rank_features_helpers::find_gamma_with_big_centroid_gap_impl(vector_to_matrix(samples), return rank_features_helpers::find_gamma_with_big_centroid_gap_impl(mat(samples),
vector_to_matrix(labels), mat(labels),
initial_gamma, initial_gamma,
num_sv, num_sv,
true); true);
......
...@@ -28,8 +28,8 @@ namespace dlib ...@@ -28,8 +28,8 @@ namespace dlib
); );
/*! /*!
requires requires
- sample_matrix_type == a matrix or something convertible to a matrix via vector_to_matrix() - sample_matrix_type == a matrix or something convertible to a matrix via mat()
- label_matrix_type == a matrix or something convertible to a matrix via vector_to_matrix() - label_matrix_type == a matrix or something convertible to a matrix via mat()
- is_binary_classification_problem(samples, labels) == true - is_binary_classification_problem(samples, labels) == true
- kc.train(samples(0)) must be a valid expression. This means that - kc.train(samples(0)) must be a valid expression. This means that
kc must use a kernel type that is capable of operating on the kc must use a kernel type that is capable of operating on the
......
...@@ -337,10 +337,10 @@ namespace dlib ...@@ -337,10 +337,10 @@ namespace dlib
) const ) const
{ {
refresh_bias(); refresh_bias();
return distance_function<kernel_type>(vector_to_matrix(alpha), return distance_function<kernel_type>(mat(alpha),
bias, bias,
kernel, kernel,
vector_to_matrix(dictionary)); mat(dictionary));
} }
private: private:
...@@ -352,7 +352,7 @@ namespace dlib ...@@ -352,7 +352,7 @@ namespace dlib
{ {
bias_is_stale = false; bias_is_stale = false;
// recompute the bias term // recompute the bias term
bias = sum(pointwise_multiply(K, vector_to_matrix(alpha)*trans(vector_to_matrix(alpha)))); bias = sum(pointwise_multiply(K, mat(alpha)*trans(mat(alpha))));
} }
} }
...@@ -396,7 +396,7 @@ namespace dlib ...@@ -396,7 +396,7 @@ namespace dlib
if (do_test) if (do_test)
{ {
refresh_bias(); refresh_bias();
test_result = std::sqrt(kx + bias - 2*trans(vector_to_matrix(alpha))*k); test_result = std::sqrt(kx + bias - 2*trans(mat(alpha))*k);
} }
// compute the error we would have if we approximated the new x sample // compute the error we would have if we approximated the new x sample
...@@ -525,7 +525,7 @@ namespace dlib ...@@ -525,7 +525,7 @@ namespace dlib
// now compute the updated alpha values to take account that we just removed one of // now compute the updated alpha values to take account that we just removed one of
// our dictionary vectors // our dictionary vectors
a = (K_inv*remove_row(K,i)*vector_to_matrix(alpha)); a = (K_inv*remove_row(K,i)*mat(alpha));
// now copy over the new alpha values // now copy over the new alpha values
alpha.resize(alpha.size()-1); alpha.resize(alpha.size()-1);
......
...@@ -104,7 +104,7 @@ namespace dlib ...@@ -104,7 +104,7 @@ namespace dlib
long max_iter = 1000 long max_iter = 1000
) )
{ {
do_train(vector_to_matrix(samples),vector_to_matrix(initial_centers),max_iter); do_train(mat(samples),mat(initial_centers),max_iter);
} }
unsigned long operator() ( unsigned long operator() (
......
...@@ -112,7 +112,7 @@ namespace dlib ...@@ -112,7 +112,7 @@ namespace dlib
/*! /*!
requires requires
- matrix_type and matrix_type2 must either be dlib::matrix objects or convertible to dlib::matrix - matrix_type and matrix_type2 must either be dlib::matrix objects or convertible to dlib::matrix
via vector_to_matrix() via mat()
- matrix_type::type == sample_type (i.e. matrix_type should contain sample_type objects) - matrix_type::type == sample_type (i.e. matrix_type should contain sample_type objects)
- matrix_type2::type == sample_type (i.e. matrix_type2 should contain sample_type objects) - matrix_type2::type == sample_type (i.e. matrix_type2 should contain sample_type objects)
- initial_centers.nc() == 1 (i.e. must be a column vector) - initial_centers.nc() == 1 (i.e. must be a column vector)
......
...@@ -182,7 +182,7 @@ namespace dlib ...@@ -182,7 +182,7 @@ namespace dlib
temp.swap(P); temp.swap(P);
// now update the alpha vector (equation 3.16) // now update the alpha vector (equation 3.16)
const scalar_type k_a = (y-trans(k)*vector_to_matrix(alpha))/delta; const scalar_type k_a = (y-trans(k)*mat(alpha))/delta;
for (unsigned long i = 0; i < alpha.size(); ++i) for (unsigned long i = 0; i < alpha.size(); ++i)
{ {
alpha[i] -= a(i)*k_a; alpha[i] -= a(i)*k_a;
...@@ -198,7 +198,7 @@ namespace dlib ...@@ -198,7 +198,7 @@ namespace dlib
P -= q*temp_matrix; P -= q*temp_matrix;
// update the alpha vector (equation 3.13) // update the alpha vector (equation 3.13)
const scalar_type k_a = y-trans(k)*vector_to_matrix(alpha); const scalar_type k_a = y-trans(k)*mat(alpha);
for (unsigned long i = 0; i < alpha.size(); ++i) for (unsigned long i = 0; i < alpha.size(); ++i)
{ {
alpha[i] += (K_inv*q*k_a)(i); alpha[i] += (K_inv*q*k_a)(i);
...@@ -232,10 +232,10 @@ namespace dlib ...@@ -232,10 +232,10 @@ namespace dlib
) const ) const
{ {
return decision_function<kernel_type>( return decision_function<kernel_type>(
vector_to_matrix(alpha), mat(alpha),
-sum(vector_to_matrix(alpha))*tau, -sum(mat(alpha))*tau,
kernel, kernel,
vector_to_matrix(dictionary) mat(dictionary)
); );
} }
...@@ -295,7 +295,7 @@ namespace dlib ...@@ -295,7 +295,7 @@ namespace dlib
// now compute the updated alpha values to take account that we just removed one of // now compute the updated alpha values to take account that we just removed one of
// our dictionary vectors // our dictionary vectors
a = (K_inv*remove_row(K,i)*vector_to_matrix(alpha)); a = (K_inv*remove_row(K,i)*mat(alpha));
// now copy over the new alpha values // now copy over the new alpha values
alpha.resize(alpha.size()-1); alpha.resize(alpha.size()-1);
......
...@@ -88,15 +88,15 @@ namespace dlib ...@@ -88,15 +88,15 @@ namespace dlib
) )
{ {
// make sure requires clause is not broken // make sure requires clause is not broken
DLIB_ASSERT(basis_samples.size() > 0 && is_vector(vector_to_matrix(basis_samples)), DLIB_ASSERT(basis_samples.size() > 0 && is_vector(mat(basis_samples)),
"\tvoid krr_trainer::set_basis(basis_samples)" "\tvoid krr_trainer::set_basis(basis_samples)"
<< "\n\t You have to give a non-empty set of basis_samples and it must be a vector" << "\n\t You have to give a non-empty set of basis_samples and it must be a vector"
<< "\n\t basis_samples.size(): " << basis_samples.size() << "\n\t basis_samples.size(): " << basis_samples.size()
<< "\n\t is_vector(vector_to_matrix(basis_samples)): " << is_vector(vector_to_matrix(basis_samples)) << "\n\t is_vector(mat(basis_samples)): " << is_vector(mat(basis_samples))
<< "\n\t this: " << this << "\n\t this: " << this
); );
basis = vector_to_matrix(basis_samples); basis = mat(basis_samples);
ekm_stale = true; ekm_stale = true;
} }
...@@ -191,7 +191,7 @@ namespace dlib ...@@ -191,7 +191,7 @@ namespace dlib
{ {
std::vector<scalar_type> temp; std::vector<scalar_type> temp;
scalar_type temp2; scalar_type temp2;
return do_train(vector_to_matrix(x), vector_to_matrix(y), false, temp, temp2); return do_train(mat(x), mat(y), false, temp, temp2);
} }
template < template <
...@@ -205,7 +205,7 @@ namespace dlib ...@@ -205,7 +205,7 @@ namespace dlib
) const ) const
{ {
scalar_type temp; scalar_type temp;
return do_train(vector_to_matrix(x), vector_to_matrix(y), true, loo_values, temp); return do_train(mat(x), mat(y), true, loo_values, temp);
} }
template < template <
...@@ -219,7 +219,7 @@ namespace dlib ...@@ -219,7 +219,7 @@ namespace dlib
scalar_type& lambda_used scalar_type& lambda_used
) const ) const
{ {
return do_train(vector_to_matrix(x), vector_to_matrix(y), true, loo_values, lambda_used); return do_train(mat(x), mat(y), true, loo_values, lambda_used);
} }
......
...@@ -102,7 +102,7 @@ namespace dlib ...@@ -102,7 +102,7 @@ namespace dlib
); );
/*! /*!
requires requires
- T must be a dlib::matrix type or something convertible to a matrix via vector_to_matrix() - T must be a dlib::matrix type or something convertible to a matrix via mat()
(e.g. a std::vector) (e.g. a std::vector)
- is_vector(basis_samples) == true - is_vector(basis_samples) == true
- basis_samples.size() > 0 - basis_samples.size() > 0
...@@ -229,9 +229,9 @@ namespace dlib ...@@ -229,9 +229,9 @@ namespace dlib
) const; ) const;
/*! /*!
requires requires
- x == a matrix or something convertible to a matrix via vector_to_matrix(). - x == a matrix or something convertible to a matrix via mat().
Also, x should contain sample_type objects. Also, x should contain sample_type objects.
- y == a matrix or something convertible to a matrix via vector_to_matrix(). - y == a matrix or something convertible to a matrix via mat().
Also, y should contain scalar_type objects. Also, y should contain scalar_type objects.
- is_learning_problem(x,y) == true - is_learning_problem(x,y) == true
- if (get_lambda() == 0 && will_use_regression_loss_for_loo_cv() == false) then - if (get_lambda() == 0 && will_use_regression_loss_for_loo_cv() == false) then
......
...@@ -36,7 +36,7 @@ namespace dlib ...@@ -36,7 +36,7 @@ namespace dlib
- get_kernel() == kernel - get_kernel() == kernel
- minimum_tolerance() == min_tolerance - minimum_tolerance() == min_tolerance
- size() == dictionary.size() - size() == dictionary.size()
- get_dictionary() == vector_to_matrix(dictionary) - get_dictionary() == mat(dictionary)
- K.nr() == dictionary.size() - K.nr() == dictionary.size()
- K.nc() == dictionary.size() - K.nc() == dictionary.size()
- for all valid r,c: - for all valid r,c:
...@@ -302,7 +302,7 @@ namespace dlib ...@@ -302,7 +302,7 @@ namespace dlib
const matrix<sample_type,0,1,mem_manager_type> get_dictionary ( const matrix<sample_type,0,1,mem_manager_type> get_dictionary (
) const ) const
{ {
return vector_to_matrix(dictionary); return mat(dictionary);
} }
friend void serialize(const linearly_independent_subset_finder& item, std::ostream& out) friend void serialize(const linearly_independent_subset_finder& item, std::ostream& out)
...@@ -410,6 +410,18 @@ namespace dlib ...@@ -410,6 +410,18 @@ namespace dlib
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
template <
typename T
>
const matrix_op<op_array_to_mat<linearly_independent_subset_finder<T> > > mat (
const linearly_independent_subset_finder<T>& m
)
{
typedef op_array_to_mat<linearly_independent_subset_finder<T> > op;
return matrix_op<op>(op(m));
}
// ----------------------------------------------------------------------------------------
namespace impl namespace impl
{ {
template < template <
...@@ -485,7 +497,7 @@ namespace dlib ...@@ -485,7 +497,7 @@ namespace dlib
) )
{ {
dlib::rand rnd; dlib::rand rnd;
impl::fill_lisf(lisf, vector_to_matrix(samples),rnd, 2000); impl::fill_lisf(lisf, mat(samples),rnd, 2000);
} }
template < template <
...@@ -500,7 +512,7 @@ namespace dlib ...@@ -500,7 +512,7 @@ namespace dlib
const int sampling_size = 2000 const int sampling_size = 2000
) )
{ {
impl::fill_lisf(lisf, vector_to_matrix(samples),rnd, sampling_size); impl::fill_lisf(lisf, mat(samples),rnd, sampling_size);
} }
template < template <
...@@ -517,7 +529,7 @@ namespace dlib ...@@ -517,7 +529,7 @@ namespace dlib
{ {
dlib::rand rnd; dlib::rand rnd;
rnd.set_seed(cast_to_string(random_seed)); rnd.set_seed(cast_to_string(random_seed));
impl::fill_lisf(lisf, vector_to_matrix(samples), rnd, sampling_size); impl::fill_lisf(lisf, mat(samples), rnd, sampling_size);
} }
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
......
...@@ -255,6 +255,22 @@ namespace dlib ...@@ -255,6 +255,22 @@ namespace dlib
provides serialization support for linearly_independent_subset_finder objects provides serialization support for linearly_independent_subset_finder objects
!*/ !*/
template <
typename T
>
const matrix_exp mat (
const linearly_independent_subset_finder<T>& m
);
/*!
ensures
- converts m into a matrix
- returns a matrix R such that:
- is_col_vector(R) == true
- R.size() == m.size()
- for all valid r:
R(r) == m[r]
!*/
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
template < template <
...@@ -271,8 +287,8 @@ namespace dlib ...@@ -271,8 +287,8 @@ namespace dlib
/*! /*!
requires requires
- vector_type == a dlib::matrix or something convertible to one via - vector_type == a dlib::matrix or something convertible to one via
vector_to_matrix() mat()
- is_vector(vector_to_matrix(samples)) == true - is_vector(mat(samples)) == true
- rand_type == an implementation of rand/rand_kernel_abstract.h or a type - rand_type == an implementation of rand/rand_kernel_abstract.h or a type
convertible to a string via cast_to_string() convertible to a string via cast_to_string()
- sampling_size > 0 - sampling_size > 0
...@@ -297,8 +313,8 @@ namespace dlib ...@@ -297,8 +313,8 @@ namespace dlib
/*! /*!
requires requires
- vector_type == a dlib::matrix or something convertible to one via - vector_type == a dlib::matrix or something convertible to one via
vector_to_matrix() mat()
- is_vector(vector_to_matrix(samples)) == true - is_vector(mat(samples)) == true
ensures ensures
- performs fill_lisf(lisf, samples, default_rand_generator, 2000) - performs fill_lisf(lisf, samples, default_rand_generator, 2000)
!*/ !*/
......
...@@ -525,9 +525,9 @@ namespace dlib ...@@ -525,9 +525,9 @@ namespace dlib
) const ) const
{ {
if (use_cache) if (use_cache)
return do_train_cached(vector_to_matrix(x), vector_to_matrix(y)); return do_train_cached(mat(x), mat(y));
else else
return do_train(vector_to_matrix(x), vector_to_matrix(y)); return do_train(mat(x), mat(y));
} }
private: private:
......
...@@ -257,7 +257,7 @@ namespace dlib ...@@ -257,7 +257,7 @@ namespace dlib
// Note that we don't need to look at nonrel_counts since it is redundant with // Note that we don't need to look at nonrel_counts since it is redundant with
// the information in rel_counts in this case. // the information in rel_counts in this case.
total_wrong += sum(vector_to_matrix(rel_counts)); total_wrong += sum(mat(rel_counts));
} }
return static_cast<double>(total_pairs - total_wrong) / total_pairs; return static_cast<double>(total_pairs - total_wrong) / total_pairs;
...@@ -359,7 +359,7 @@ namespace dlib ...@@ -359,7 +359,7 @@ namespace dlib
// Note that we don't need to look at nonrel_counts since it is redundant with // Note that we don't need to look at nonrel_counts since it is redundant with
// the information in rel_counts in this case. // the information in rel_counts in this case.
total_wrong += sum(vector_to_matrix(rel_counts)); total_wrong += sum(mat(rel_counts));
} }
} // for (long i = 0; i < folds; ++i) } // for (long i = 0; i < folds; ++i)
......
...@@ -75,7 +75,7 @@ namespace dlib ...@@ -75,7 +75,7 @@ namespace dlib
const in_scalar_vector_type& y const in_scalar_vector_type& y
) const ) const
{ {
return do_train(vector_to_matrix(x), vector_to_matrix(y)); return do_train(mat(x), mat(y));
} }
void swap ( void swap (
......
...@@ -89,9 +89,9 @@ namespace dlib ...@@ -89,9 +89,9 @@ namespace dlib
) const ) const
/*! /*!
requires requires
- x == a matrix or something convertible to a matrix via vector_to_matrix(). - x == a matrix or something convertible to a matrix via mat().
Also, x should contain sample_type objects. Also, x should contain sample_type objects.
- y == a matrix or something convertible to a matrix via vector_to_matrix(). - y == a matrix or something convertible to a matrix via mat().
Also, y should contain scalar_type objects. Also, y should contain scalar_type objects.
- is_learning_problem(x,y) == true - is_learning_problem(x,y) == true
ensures ensures
......
...@@ -63,7 +63,7 @@ namespace dlib ...@@ -63,7 +63,7 @@ namespace dlib
"\t reduced_decision_function_trainer::train(x,y)" "\t reduced_decision_function_trainer::train(x,y)"
<< "\n\t You have tried to use an uninitialized version of this object" << "\n\t You have tried to use an uninitialized version of this object"
<< "\n\t num_bv: " << num_bv ); << "\n\t num_bv: " << num_bv );
return do_train(vector_to_matrix(x), vector_to_matrix(y)); return do_train(mat(x), mat(y));
} }
private: private:
...@@ -438,7 +438,7 @@ namespace dlib ...@@ -438,7 +438,7 @@ namespace dlib
// Now we compute the fist approximate distance function. // Now we compute the fist approximate distance function.
beta = pinv(kernel_matrix(kern,starting_basis)) * beta = pinv(kernel_matrix(kern,starting_basis)) *
(kernel_matrix(kern,starting_basis,target.get_basis_vectors())*target.get_alpha()); (kernel_matrix(kern,starting_basis,target.get_basis_vectors())*target.get_alpha());
matrix<sample_type,0,1,mem_manager_type> out_vectors(vector_to_matrix(starting_basis)); matrix<sample_type,0,1,mem_manager_type> out_vectors(mat(starting_basis));
// Now setup to do a global optimization of all the parameters in the approximate // Now setup to do a global optimization of all the parameters in the approximate
...@@ -529,7 +529,7 @@ namespace dlib ...@@ -529,7 +529,7 @@ namespace dlib
"\t reduced_decision_function_trainer2::train(x,y)" "\t reduced_decision_function_trainer2::train(x,y)"
<< "\n\t You have tried to use an uninitialized version of this object" << "\n\t You have tried to use an uninitialized version of this object"
<< "\n\t num_bv: " << num_bv ); << "\n\t num_bv: " << num_bv );
return do_train(vector_to_matrix(x), vector_to_matrix(y)); return do_train(mat(x), mat(y));
} }
private: private:
......
...@@ -123,7 +123,7 @@ namespace dlib ...@@ -123,7 +123,7 @@ namespace dlib
- stop_strategy == an object that defines a stop strategy such as one of - stop_strategy == an object that defines a stop strategy such as one of
the objects from dlib/optimization/optimization_stop_strategies_abstract.h the objects from dlib/optimization/optimization_stop_strategies_abstract.h
- requirements on starting_basis - requirements on starting_basis
- T must be a dlib::matrix type or something convertible to a matrix via vector_to_matrix() - T must be a dlib::matrix type or something convertible to a matrix via mat()
(e.g. a std::vector). Additionally, starting_basis must contain K::sample_type (e.g. a std::vector). Additionally, starting_basis must contain K::sample_type
objects which can be supplied to the kernel function used by target. objects which can be supplied to the kernel function used by target.
- is_vector(starting_basis) == true - is_vector(starting_basis) == true
......
...@@ -63,7 +63,7 @@ namespace dlib ...@@ -63,7 +63,7 @@ namespace dlib
); );
return do_train(vector_to_matrix(samples), vector_to_matrix(labels)); return do_train(mat(samples), mat(labels));
} }
private: private:
......
...@@ -73,9 +73,9 @@ namespace dlib ...@@ -73,9 +73,9 @@ namespace dlib
/*! /*!
requires requires
- is_binary_classification_problem(samples, labels) == true - is_binary_classification_problem(samples, labels) == true
- x == a matrix or something convertible to a matrix via vector_to_matrix(). - x == a matrix or something convertible to a matrix via mat().
Also, x should contain sample_type objects. Also, x should contain sample_type objects.
- y == a matrix or something convertible to a matrix via vector_to_matrix(). - y == a matrix or something convertible to a matrix via mat().
Also, y should contain scalar_type objects. Also, y should contain scalar_type objects.
ensures ensures
- performs training using the trainer object given to this object's - performs training using the trainer object given to this object's
......
...@@ -135,7 +135,7 @@ namespace dlib ...@@ -135,7 +135,7 @@ namespace dlib
{ {
std::vector<scalar_type> temp; std::vector<scalar_type> temp;
scalar_type temp2; scalar_type temp2;
return do_train(vector_to_matrix(x), vector_to_matrix(y), false, temp, temp2); return do_train(mat(x), mat(y), false, temp, temp2);
} }
template < template <
...@@ -149,7 +149,7 @@ namespace dlib ...@@ -149,7 +149,7 @@ namespace dlib
) const ) const
{ {
scalar_type temp; scalar_type temp;
return do_train(vector_to_matrix(x), vector_to_matrix(y), true, loo_values, temp); return do_train(mat(x), mat(y), true, loo_values, temp);
} }
template < template <
...@@ -163,7 +163,7 @@ namespace dlib ...@@ -163,7 +163,7 @@ namespace dlib
scalar_type& lambda_used scalar_type& lambda_used
) const ) const
{ {
return do_train(vector_to_matrix(x), vector_to_matrix(y), true, loo_values, lambda_used); return do_train(mat(x), mat(y), true, loo_values, lambda_used);
} }
......
...@@ -165,9 +165,9 @@ namespace dlib ...@@ -165,9 +165,9 @@ namespace dlib
) const; ) const;
/*! /*!
requires requires
- x == a matrix or something convertible to a matrix via vector_to_matrix(). - x == a matrix or something convertible to a matrix via mat().
Also, x should contain sample_type objects. Also, x should contain sample_type objects.
- y == a matrix or something convertible to a matrix via vector_to_matrix(). - y == a matrix or something convertible to a matrix via mat().
Also, y should contain scalar_type objects. Also, y should contain scalar_type objects.
- is_learning_problem(x,y) == true - is_learning_problem(x,y) == true
- if (get_lambda() == 0 && will_use_regression_loss_for_loo_cv() == false) then - if (get_lambda() == 0 && will_use_regression_loss_for_loo_cv() == false) then
......
...@@ -192,7 +192,7 @@ namespace dlib ...@@ -192,7 +192,7 @@ namespace dlib
const in_scalar_vector_type& y const in_scalar_vector_type& y
) const ) const
{ {
return do_train(vector_to_matrix(x), vector_to_matrix(y)); return do_train(mat(x), mat(y));
} }
void swap ( void swap (
...@@ -502,10 +502,10 @@ namespace dlib ...@@ -502,10 +502,10 @@ namespace dlib
} }
} }
return decision_function<kernel_type> ( vector_to_matrix(final_weights), return decision_function<kernel_type> ( mat(final_weights),
-sum(vector_to_matrix(final_weights))*tau, -sum(mat(final_weights))*tau,
kernel, kernel,
vector_to_matrix(dictionary)); mat(dictionary));
} }
...@@ -664,7 +664,7 @@ namespace dlib ...@@ -664,7 +664,7 @@ namespace dlib
const in_scalar_vector_type& t const in_scalar_vector_type& t
) const ) const
{ {
return do_train(vector_to_matrix(x), vector_to_matrix(t)); return do_train(mat(x), mat(t));
} }
void swap ( void swap (
...@@ -906,10 +906,10 @@ namespace dlib ...@@ -906,10 +906,10 @@ namespace dlib
} }
} }
return decision_function<kernel_type> ( vector_to_matrix(final_weights), return decision_function<kernel_type> ( mat(final_weights),
-sum(vector_to_matrix(final_weights))*tau, -sum(mat(final_weights))*tau,
kernel, kernel,
vector_to_matrix(dictionary)); mat(dictionary));
} }
......
...@@ -97,9 +97,9 @@ namespace dlib ...@@ -97,9 +97,9 @@ namespace dlib
/*! /*!
requires requires
- is_binary_classification_problem(x,y) == true - is_binary_classification_problem(x,y) == true
- x == a matrix or something convertible to a matrix via vector_to_matrix(). - x == a matrix or something convertible to a matrix via mat().
Also, x should contain sample_type objects. Also, x should contain sample_type objects.
- y == a matrix or something convertible to a matrix via vector_to_matrix(). - y == a matrix or something convertible to a matrix via mat().
Also, y should contain scalar_type objects. Also, y should contain scalar_type objects.
ensures ensures
- trains a relevance vector classifier given the training samples in x and - trains a relevance vector classifier given the training samples in x and
...@@ -219,9 +219,9 @@ namespace dlib ...@@ -219,9 +219,9 @@ namespace dlib
) const; ) const;
/*! /*!
requires requires
- x == a matrix or something convertible to a matrix via vector_to_matrix(). - x == a matrix or something convertible to a matrix via mat().
Also, x should contain sample_type objects. Also, x should contain sample_type objects.
- y == a matrix or something convertible to a matrix via vector_to_matrix(). - y == a matrix or something convertible to a matrix via mat().
Also, y should contain scalar_type objects. Also, y should contain scalar_type objects.
- is_learning_problem(x,y) == true - is_learning_problem(x,y) == true
- x.size() > 0 - x.size() > 0
......
...@@ -211,9 +211,9 @@ namespace dlib ...@@ -211,9 +211,9 @@ namespace dlib
) )
{ {
return bs_impl::sort_basis_vectors_impl(kern, return bs_impl::sort_basis_vectors_impl(kern,
vector_to_matrix(samples), mat(samples),
vector_to_matrix(labels), mat(labels),
vector_to_matrix(basis), mat(basis),
eps); eps);
} }
......
...@@ -33,9 +33,9 @@ namespace dlib ...@@ -33,9 +33,9 @@ namespace dlib
- basis.size() > 0 - basis.size() > 0
- kernel_type is a kernel function object as defined in dlib/svm/kernel_abstract.h - kernel_type is a kernel function object as defined in dlib/svm/kernel_abstract.h
It must be capable of operating on the elements of samples and basis. It must be capable of operating on the elements of samples and basis.
- vect1_type == a matrix or something convertible to a matrix via vector_to_matrix() - vect1_type == a matrix or something convertible to a matrix via mat()
- vect2_type == a matrix or something convertible to a matrix via vector_to_matrix() - vect2_type == a matrix or something convertible to a matrix via mat()
- vect3_type == a matrix or something convertible to a matrix via vector_to_matrix() - vect3_type == a matrix or something convertible to a matrix via mat()
ensures ensures
- A kernel based learning method ultimately needs to select a set of basis functions - A kernel based learning method ultimately needs to select a set of basis functions
represented by a particular choice of kernel and a set of basis vectors. represented by a particular choice of kernel and a set of basis vectors.
......
...@@ -550,7 +550,7 @@ namespace dlib ...@@ -550,7 +550,7 @@ namespace dlib
const T& samples const T& samples
) )
{ {
return impl::max_index_plus_one(vector_to_matrix(samples)); return impl::max_index_plus_one(mat(samples));
} }
// ------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------
......
...@@ -314,7 +314,7 @@ namespace dlib ...@@ -314,7 +314,7 @@ namespace dlib
requires requires
- samples == a single vector (either sparse or dense), or a container - samples == a single vector (either sparse or dense), or a container
of vectors which is either a dlib::matrix of vectors or something of vectors which is either a dlib::matrix of vectors or something
convertible to a dlib::matrix via vector_to_matrix() (e.g. a std::vector) convertible to a dlib::matrix via mat() (e.g. a std::vector)
Valid types of samples include (but are not limited to): Valid types of samples include (but are not limited to):
- dlib::matrix<double,0,1> // A single dense vector - dlib::matrix<double,0,1> // A single dense vector
- std::map<unsigned int, double> // A single sparse vector - std::map<unsigned int, double> // A single sparse vector
......
...@@ -110,13 +110,13 @@ namespace dlib ...@@ -110,13 +110,13 @@ namespace dlib
if (loss.size() >= prob->get_max_cache_size()) if (loss.size() >= prob->get_max_cache_size())
{ {
// find least recently used cache entry for idx-th sample // find least recently used cache entry for idx-th sample
const long i = index_of_min(vector_to_matrix(lru_count)); const long i = index_of_min(mat(lru_count));
// save our new data in the cache // save our new data in the cache
loss[i] = out_loss; loss[i] = out_loss;
psi[i] = out_psi; psi[i] = out_psi;
const long max_use = max(vector_to_matrix(lru_count)); const long max_use = max(mat(lru_count));
// Make sure this new cache entry has the best lru count since we have used // Make sure this new cache entry has the best lru count since we have used
// it most recently. // it most recently.
lru_count[i] = max_use + 1; lru_count[i] = max_use + 1;
...@@ -127,7 +127,7 @@ namespace dlib ...@@ -127,7 +127,7 @@ namespace dlib
psi.push_back(out_psi); psi.push_back(out_psi);
long max_use = 1; long max_use = 1;
if (lru_count.size() != 0) if (lru_count.size() != 0)
max_use = max(vector_to_matrix(lru_count)) + 1; max_use = max(mat(lru_count)) + 1;
lru_count.push_back(max_use); lru_count.push_back(max_use);
} }
} }
......
...@@ -181,7 +181,7 @@ namespace dlib ...@@ -181,7 +181,7 @@ namespace dlib
matrix<unsigned long,0,1> candidate_labeling; matrix<unsigned long,0,1> candidate_labeling;
for (unsigned long i = 0; i < sample.size(); ++i) for (unsigned long i = 0; i < sample.size(); ++i)
{ {
candidate_labeling = rowm(vector_to_matrix(label), range(i, std::max((int)i-order,0))); candidate_labeling = rowm(mat(label), range(i, std::max((int)i-order,0)));
fe_helpers::get_feature_vector(psi,fe,sample,candidate_labeling, i); fe_helpers::get_feature_vector(psi,fe,sample,candidate_labeling, i);
} }
......
...@@ -48,7 +48,7 @@ namespace dlib ...@@ -48,7 +48,7 @@ namespace dlib
const U& x_labels const U& x_labels
) )
{ {
return is_learning_problem_impl(vector_to_matrix(x), vector_to_matrix(x_labels)); return is_learning_problem_impl(mat(x), mat(x_labels));
} }
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
...@@ -93,7 +93,7 @@ namespace dlib ...@@ -93,7 +93,7 @@ namespace dlib
const U& x_labels const U& x_labels
) )
{ {
return is_binary_classification_problem_impl(vector_to_matrix(x), vector_to_matrix(x_labels)); return is_binary_classification_problem_impl(mat(x), mat(x_labels));
} }
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
...@@ -171,8 +171,8 @@ namespace dlib ...@@ -171,8 +171,8 @@ namespace dlib
) )
{ {
return test_binary_decision_function_impl(dec_funct, return test_binary_decision_function_impl(dec_funct,
vector_to_matrix(x_test), mat(x_test),
vector_to_matrix(y_test)); mat(y_test));
} }
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
...@@ -256,7 +256,7 @@ namespace dlib ...@@ -256,7 +256,7 @@ namespace dlib
{ {
for (unsigned long i = 0; i < samples.size(); ++i) for (unsigned long i = 0; i < samples.size(); ++i)
{ {
const unsigned long N = sum(vector_to_matrix(labels[i]) != -1); const unsigned long N = sum(mat(labels[i]) != -1);
if (std::min(samples[i].first.size(), samples[i].second.size()) != N) if (std::min(samples[i].first.size(), samples[i].second.size()) != N)
return false; return false;
} }
...@@ -418,8 +418,8 @@ namespace dlib ...@@ -418,8 +418,8 @@ namespace dlib
) )
{ {
return cross_validate_trainer_impl(trainer, return cross_validate_trainer_impl(trainer,
vector_to_matrix(x), mat(x),
vector_to_matrix(y), mat(y),
folds); folds);
} }
...@@ -600,8 +600,8 @@ namespace dlib ...@@ -600,8 +600,8 @@ namespace dlib
); );
// count the number of positive and negative examples // count the number of positive and negative examples
const long num_pos = (long)sum(vector_to_matrix(y) > 0); const long num_pos = (long)sum(mat(y) > 0);
const long num_neg = (long)sum(vector_to_matrix(y) < 0); const long num_neg = (long)sum(mat(y) < 0);
// figure out how many positive and negative examples we will have in each fold // figure out how many positive and negative examples we will have in each fold
const long num_pos_test_samples = num_pos/folds; const long num_pos_test_samples = num_pos/folds;
......
...@@ -30,8 +30,8 @@ namespace dlib ...@@ -30,8 +30,8 @@ namespace dlib
); );
/*! /*!
requires requires
- T == a matrix or something convertible to a matrix via vector_to_matrix() - T == a matrix or something convertible to a matrix via mat()
- U == a matrix or something convertible to a matrix via vector_to_matrix() - U == a matrix or something convertible to a matrix via mat()
ensures ensures
- returns true if all of the following are true and false otherwise: - returns true if all of the following are true and false otherwise:
- is_col_vector(x) == true - is_col_vector(x) == true
...@@ -50,8 +50,8 @@ namespace dlib ...@@ -50,8 +50,8 @@ namespace dlib
); );
/*! /*!
requires requires
- T == a matrix or something convertible to a matrix via vector_to_matrix() - T == a matrix or something convertible to a matrix via mat()
- U == a matrix or something convertible to a matrix via vector_to_matrix() - U == a matrix or something convertible to a matrix via mat()
ensures ensures
- returns true if all of the following are true and false otherwise: - returns true if all of the following are true and false otherwise:
- is_learning_problem(x, x_labels) == true - is_learning_problem(x, x_labels) == true
......
...@@ -149,15 +149,15 @@ namespace dlib ...@@ -149,15 +149,15 @@ namespace dlib
) )
{ {
// make sure requires clause is not broken // make sure requires clause is not broken
DLIB_ASSERT(basis_samples.size() > 0 && is_vector(vector_to_matrix(basis_samples)), DLIB_ASSERT(basis_samples.size() > 0 && is_vector(mat(basis_samples)),
"\tvoid svm_c_ekm_trainer::set_basis(basis_samples)" "\tvoid svm_c_ekm_trainer::set_basis(basis_samples)"
<< "\n\t You have to give a non-empty set of basis_samples and it must be a vector" << "\n\t You have to give a non-empty set of basis_samples and it must be a vector"
<< "\n\t basis_samples.size(): " << basis_samples.size() << "\n\t basis_samples.size(): " << basis_samples.size()
<< "\n\t is_vector(vector_to_matrix(basis_samples)): " << is_vector(vector_to_matrix(basis_samples)) << "\n\t is_vector(mat(basis_samples)): " << is_vector(mat(basis_samples))
<< "\n\t this: " << this << "\n\t this: " << this
); );
basis = vector_to_matrix(basis_samples); basis = mat(basis_samples);
ekm_stale = true; ekm_stale = true;
} }
...@@ -311,9 +311,9 @@ namespace dlib ...@@ -311,9 +311,9 @@ namespace dlib
{ {
scalar_type obj; scalar_type obj;
if (basis_loaded()) if (basis_loaded())
return do_train_user_basis(vector_to_matrix(x),vector_to_matrix(y),obj); return do_train_user_basis(mat(x),mat(y),obj);
else else
return do_train_auto_basis(vector_to_matrix(x),vector_to_matrix(y),obj); return do_train_auto_basis(mat(x),mat(y),obj);
} }
template < template <
...@@ -327,9 +327,9 @@ namespace dlib ...@@ -327,9 +327,9 @@ namespace dlib
) const ) const
{ {
if (basis_loaded()) if (basis_loaded())
return do_train_user_basis(vector_to_matrix(x),vector_to_matrix(y),svm_objective); return do_train_user_basis(mat(x),mat(y),svm_objective);
else else
return do_train_auto_basis(vector_to_matrix(x),vector_to_matrix(y),svm_objective); return do_train_auto_basis(mat(x),mat(y),svm_objective);
} }
......
...@@ -169,7 +169,7 @@ namespace dlib ...@@ -169,7 +169,7 @@ namespace dlib
); );
/*! /*!
requires requires
- T must be a dlib::matrix type or something convertible to a matrix via vector_to_matrix() - T must be a dlib::matrix type or something convertible to a matrix via mat()
(e.g. a std::vector) (e.g. a std::vector)
- is_vector(basis_samples) == true - is_vector(basis_samples) == true
- basis_samples.size() > 0 - basis_samples.size() > 0
...@@ -324,9 +324,9 @@ namespace dlib ...@@ -324,9 +324,9 @@ namespace dlib
/*! /*!
requires requires
- is_binary_classification_problem(x,y) == true - is_binary_classification_problem(x,y) == true
- x == a matrix or something convertible to a matrix via vector_to_matrix(). - x == a matrix or something convertible to a matrix via mat().
Also, x should contain sample_type objects. Also, x should contain sample_type objects.
- y == a matrix or something convertible to a matrix via vector_to_matrix(). - y == a matrix or something convertible to a matrix via mat().
Also, y should contain scalar_type objects. Also, y should contain scalar_type objects.
ensures ensures
- trains a C support vector classifier given the training samples in x and - trains a C support vector classifier given the training samples in x and
...@@ -355,9 +355,9 @@ namespace dlib ...@@ -355,9 +355,9 @@ namespace dlib
/*! /*!
requires requires
- is_binary_classification_problem(x,y) == true - is_binary_classification_problem(x,y) == true
- x == a matrix or something convertible to a matrix via vector_to_matrix(). - x == a matrix or something convertible to a matrix via mat().
Also, x should contain sample_type objects. Also, x should contain sample_type objects.
- y == a matrix or something convertible to a matrix via vector_to_matrix(). - y == a matrix or something convertible to a matrix via mat().
Also, y should contain scalar_type objects. Also, y should contain scalar_type objects.
ensures ensures
- trains a C support vector classifier given the training samples in x and - trains a C support vector classifier given the training samples in x and
......
...@@ -441,7 +441,7 @@ namespace dlib ...@@ -441,7 +441,7 @@ namespace dlib
) const ) const
{ {
optimizer_state state; optimizer_state state;
return do_train(vector_to_matrix(x), vector_to_matrix(y), state); return do_train(mat(x), mat(y), state);
} }
template < template <
...@@ -454,7 +454,7 @@ namespace dlib ...@@ -454,7 +454,7 @@ namespace dlib
optimizer_state& state optimizer_state& state
) const ) const
{ {
return do_train(vector_to_matrix(x), vector_to_matrix(y), state); return do_train(mat(x), mat(y), state);
} }
private: private:
......
...@@ -264,9 +264,9 @@ namespace dlib ...@@ -264,9 +264,9 @@ namespace dlib
- is_learning_problem(x,y) == true - is_learning_problem(x,y) == true
(Note that it is ok for x.size() == 1) (Note that it is ok for x.size() == 1)
- All elements of y must be equal to +1 or -1 - All elements of y must be equal to +1 or -1
- x == a matrix or something convertible to a matrix via vector_to_matrix(). - x == a matrix or something convertible to a matrix via mat().
Also, x should contain sample_type objects. Also, x should contain sample_type objects.
- y == a matrix or something convertible to a matrix via vector_to_matrix(). - y == a matrix or something convertible to a matrix via mat().
Also, y should contain scalar_type objects. Also, y should contain scalar_type objects.
ensures ensures
- Trains a C support vector classifier given the training samples in x and - Trains a C support vector classifier given the training samples in x and
...@@ -319,9 +319,9 @@ namespace dlib ...@@ -319,9 +319,9 @@ namespace dlib
- max_index_plus_one(x) == max_index_plus_one(X) - max_index_plus_one(x) == max_index_plus_one(X)
- else - else
- max_index_plus_one(x) >= max_index_plus_one(X) - max_index_plus_one(x) >= max_index_plus_one(X)
- x == a matrix or something convertible to a matrix via vector_to_matrix(). - x == a matrix or something convertible to a matrix via mat().
Also, x should contain sample_type objects. Also, x should contain sample_type objects.
- y == a matrix or something convertible to a matrix via vector_to_matrix(). - y == a matrix or something convertible to a matrix via mat().
Also, y should contain scalar_type objects. Also, y should contain scalar_type objects.
ensures ensures
- Trains a C support vector classifier given the training samples in x and - Trains a C support vector classifier given the training samples in x and
......
...@@ -511,7 +511,7 @@ namespace dlib ...@@ -511,7 +511,7 @@ namespace dlib
) const ) const
{ {
scalar_type obj; scalar_type obj;
return do_train(vector_to_matrix(x),vector_to_matrix(y),obj); return do_train(mat(x),mat(y),obj);
} }
...@@ -525,7 +525,7 @@ namespace dlib ...@@ -525,7 +525,7 @@ namespace dlib
scalar_type& svm_objective scalar_type& svm_objective
) const ) const
{ {
return do_train(vector_to_matrix(x),vector_to_matrix(y),svm_objective); return do_train(mat(x),mat(y),svm_objective);
} }
private: private:
......
...@@ -236,9 +236,9 @@ namespace dlib ...@@ -236,9 +236,9 @@ namespace dlib
/*! /*!
requires requires
- is_binary_classification_problem(x,y) == true - is_binary_classification_problem(x,y) == true
- x == a matrix or something convertible to a matrix via vector_to_matrix(). - x == a matrix or something convertible to a matrix via mat().
Also, x should contain sample_type objects. Also, x should contain sample_type objects.
- y == a matrix or something convertible to a matrix via vector_to_matrix(). - y == a matrix or something convertible to a matrix via mat().
Also, y should contain scalar_type objects. Also, y should contain scalar_type objects.
ensures ensures
- trains a C support vector classifier given the training samples in x and - trains a C support vector classifier given the training samples in x and
...@@ -265,9 +265,9 @@ namespace dlib ...@@ -265,9 +265,9 @@ namespace dlib
/*! /*!
requires requires
- is_binary_classification_problem(x,y) == true - is_binary_classification_problem(x,y) == true
- x == a matrix or something convertible to a matrix via vector_to_matrix(). - x == a matrix or something convertible to a matrix via mat().
Also, x should contain sample_type objects. Also, x should contain sample_type objects.
- y == a matrix or something convertible to a matrix via vector_to_matrix(). - y == a matrix or something convertible to a matrix via mat().
Also, y should contain scalar_type objects. Also, y should contain scalar_type objects.
ensures ensures
- trains a C support vector classifier given the training samples in x and - trains a C support vector classifier given the training samples in x and
......
...@@ -178,7 +178,7 @@ namespace dlib ...@@ -178,7 +178,7 @@ namespace dlib
const in_scalar_vector_type& y const in_scalar_vector_type& y
) const ) const
{ {
return do_train(vector_to_matrix(x), vector_to_matrix(y)); return do_train(mat(x), mat(y));
} }
void swap ( void swap (
......
...@@ -195,9 +195,9 @@ namespace dlib ...@@ -195,9 +195,9 @@ namespace dlib
/*! /*!
requires requires
- is_binary_classification_problem(x,y) == true - is_binary_classification_problem(x,y) == true
- x == a matrix or something convertible to a matrix via vector_to_matrix(). - x == a matrix or something convertible to a matrix via mat().
Also, x should contain sample_type objects. Also, x should contain sample_type objects.
- y == a matrix or something convertible to a matrix via vector_to_matrix(). - y == a matrix or something convertible to a matrix via mat().
Also, y should contain scalar_type objects. Also, y should contain scalar_type objects.
ensures ensures
- trains a C support vector classifier given the training samples in x and - trains a C support vector classifier given the training samples in x and
......
...@@ -75,7 +75,7 @@ namespace dlib ...@@ -75,7 +75,7 @@ namespace dlib
psi.push_back(std::make_pair(dims-1,static_cast<scalar_type>(-1))); psi.push_back(std::make_pair(dims-1,static_cast<scalar_type>(-1)));
// Find which distinct label goes with this psi. // Find which distinct label goes with this psi.
const long label_idx = index_of_max(vector_to_matrix(distinct_labels) == labels[idx]); const long label_idx = index_of_max(mat(distinct_labels) == labels[idx]);
offset_feature_vector(psi, dims*label_idx); offset_feature_vector(psi, dims*label_idx);
} }
...@@ -96,7 +96,7 @@ namespace dlib ...@@ -96,7 +96,7 @@ namespace dlib
{ {
// Compute the F(x,y) part: // Compute the F(x,y) part:
// perform: temp == dot(relevant part of current solution, samples[idx]) - current_bias // perform: temp == dot(relevant part of current solution, samples[idx]) - current_bias
scalar_type temp = dot(pointer_to_column_vector(&current_solution(i*dims),dims-1), samples[idx]) - current_solution((i+1)*dims-1); scalar_type temp = dot(mat(&current_solution(i*dims),dims-1), samples[idx]) - current_solution((i+1)*dims-1);
// Add the LOSS(idx,y) part: // Add the LOSS(idx,y) part:
if (labels[idx] != distinct_labels[i]) if (labels[idx] != distinct_labels[i])
......
...@@ -138,7 +138,7 @@ namespace dlib ...@@ -138,7 +138,7 @@ namespace dlib
const in_scalar_vector_type& y const in_scalar_vector_type& y
) const ) const
{ {
return do_train(vector_to_matrix(x), vector_to_matrix(y)); return do_train(mat(x), mat(y));
} }
void swap ( void swap (
......
...@@ -164,9 +164,9 @@ namespace dlib ...@@ -164,9 +164,9 @@ namespace dlib
/*! /*!
requires requires
- is_binary_classification_problem(x,y) == true - is_binary_classification_problem(x,y) == true
- x == a matrix or something convertible to a matrix via vector_to_matrix(). - x == a matrix or something convertible to a matrix via mat().
Also, x should contain sample_type objects. Also, x should contain sample_type objects.
- y == a matrix or something convertible to a matrix via vector_to_matrix(). - y == a matrix or something convertible to a matrix via mat().
Also, y should contain scalar_type objects. Also, y should contain scalar_type objects.
ensures ensures
- trains a nu support vector classifier given the training samples in x and - trains a nu support vector classifier given the training samples in x and
......
...@@ -133,7 +133,7 @@ namespace dlib ...@@ -133,7 +133,7 @@ namespace dlib
const in_sample_vector_type& x const in_sample_vector_type& x
) const ) const
{ {
return do_train(vector_to_matrix(x)); return do_train(mat(x));
} }
void swap ( void swap (
......
...@@ -160,7 +160,7 @@ namespace dlib ...@@ -160,7 +160,7 @@ namespace dlib
requires requires
- x.size() > 0 - x.size() > 0
- is_col_vector(x) == true - is_col_vector(x) == true
- x == a matrix or something convertible to a matrix via vector_to_matrix(). - x == a matrix or something convertible to a matrix via mat().
Also, x should contain sample_type objects. Also, x should contain sample_type objects.
ensures ensures
- trains a one-class support vector classifier given the training samples in x. - trains a one-class support vector classifier given the training samples in x.
......
...@@ -237,8 +237,8 @@ namespace dlib ...@@ -237,8 +237,8 @@ namespace dlib
) )
{ {
return cross_validate_trainer_threaded_impl(trainer, return cross_validate_trainer_threaded_impl(trainer,
vector_to_matrix(x), mat(x),
vector_to_matrix(y), mat(y),
folds, folds,
num_threads); num_threads);
} }
......
...@@ -140,7 +140,7 @@ namespace dlib ...@@ -140,7 +140,7 @@ namespace dlib
const in_scalar_vector_type& y const in_scalar_vector_type& y
) const ) const
{ {
return do_train(vector_to_matrix(x), vector_to_matrix(y)); return do_train(mat(x), mat(y));
} }
void swap ( void swap (
......
...@@ -170,9 +170,9 @@ namespace dlib ...@@ -170,9 +170,9 @@ namespace dlib
/*! /*!
requires requires
- is_learning_problem(x,y) == true - is_learning_problem(x,y) == true
- x == a matrix or something convertible to a matrix via vector_to_matrix(). - x == a matrix or something convertible to a matrix via mat().
Also, x should contain sample_type objects. Also, x should contain sample_type objects.
- y == a matrix or something convertible to a matrix via vector_to_matrix(). - y == a matrix or something convertible to a matrix via mat().
Also, y should contain scalar_type objects. Also, y should contain scalar_type objects.
ensures ensures
- performs support vector regression given the training samples in x and - performs support vector regression given the training samples in x and
......
...@@ -315,9 +315,9 @@ namespace ...@@ -315,9 +315,9 @@ namespace
for (unsigned long i = 0; i < samples.size(); ++i) for (unsigned long i = 0; i < samples.size(); ++i)
{ {
std::vector<long> out = ass(samples[i]); std::vector<long> out = ass(samples[i]);
dlog << LINFO << "true labels: " << trans(vector_to_matrix(labels[i])); dlog << LINFO << "true labels: " << trans(mat(labels[i]));
dlog << LINFO << "pred labels: " << trans(vector_to_matrix(out)); dlog << LINFO << "pred labels: " << trans(mat(out));
DLIB_TEST(trans(vector_to_matrix(labels[i])) == trans(vector_to_matrix(out))); DLIB_TEST(trans(mat(labels[i])) == trans(mat(out)));
} }
double accuracy; double accuracy;
...@@ -343,9 +343,9 @@ namespace ...@@ -343,9 +343,9 @@ namespace
for (unsigned long i = 0; i < samples.size(); ++i) for (unsigned long i = 0; i < samples.size(); ++i)
{ {
std::vector<long> out = ass2(samples[i]); std::vector<long> out = ass2(samples[i]);
dlog << LINFO << "true labels: " << trans(vector_to_matrix(labels[i])); dlog << LINFO << "true labels: " << trans(mat(labels[i]));
dlog << LINFO << "pred labels: " << trans(vector_to_matrix(out)); dlog << LINFO << "pred labels: " << trans(mat(out));
DLIB_TEST(trans(vector_to_matrix(labels[i])) == trans(vector_to_matrix(out))); DLIB_TEST(trans(mat(labels[i])) == trans(mat(out)));
} }
} }
......
...@@ -541,7 +541,7 @@ namespace ...@@ -541,7 +541,7 @@ namespace
dlog << LINFO << "score MAP: " << score2; dlog << LINFO << "score MAP: " << score2;
DLIB_TEST(std::abs(score1 - score2) < 1e-10); DLIB_TEST(std::abs(score1 - score2) < 1e-10);
DLIB_TEST(vector_to_matrix(map_assignment1) == vector_to_matrix(map_assignment2)); DLIB_TEST(mat(map_assignment1) == mat(map_assignment2));
} }
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
...@@ -568,10 +568,10 @@ namespace ...@@ -568,10 +568,10 @@ namespace
dlog << LINFO << "score NMPLP: " << score1; dlog << LINFO << "score NMPLP: " << score1;
dlog << LINFO << "score MAP: " << score2; dlog << LINFO << "score MAP: " << score2;
dlog << LINFO << "MAP assignment: "<< trans(vector_to_matrix(map_assignment1)); dlog << LINFO << "MAP assignment: "<< trans(mat(map_assignment1));
DLIB_TEST(std::abs(score1 - score2) < 1e-10); DLIB_TEST(std::abs(score1 - score2) < 1e-10);
DLIB_TEST(vector_to_matrix(map_assignment1) == vector_to_matrix(map_assignment2)); DLIB_TEST(mat(map_assignment1) == mat(map_assignment2));
} }
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
......
...@@ -131,9 +131,9 @@ namespace ...@@ -131,9 +131,9 @@ namespace
brute_force_find_max_factor_graph_viterbi(prob, assign); brute_force_find_max_factor_graph_viterbi(prob, assign);
find_max_factor_graph_viterbi(prob, assign2); find_max_factor_graph_viterbi(prob, assign2);
DLIB_TEST_MSG(vector_to_matrix(assign) == vector_to_matrix(assign2), DLIB_TEST_MSG(mat(assign) == mat(assign2),
trans(vector_to_matrix(assign)) trans(mat(assign))
<< trans(vector_to_matrix(assign2)) << trans(mat(assign2))
); );
} }
} }
......
...@@ -344,7 +344,7 @@ namespace ...@@ -344,7 +344,7 @@ namespace
// This test is just to make sure the covariance function can compile when used // This test is just to make sure the covariance function can compile when used
// on a dlib::vector. The actual test doesn't matter. // on a dlib::vector. The actual test doesn't matter.
DLIB_TEST(sum(covariance(vector_to_matrix(a))) < 10); DLIB_TEST(sum(covariance(mat(a))) < 10);
} }
...@@ -446,7 +446,7 @@ namespace ...@@ -446,7 +446,7 @@ namespace
DLIB_TEST(be.current_element_valid() == false); DLIB_TEST(be.current_element_valid() == false);
DLIB_TEST(be.at_start() == false); DLIB_TEST(be.at_start() == false);
DLIB_TEST(array_to_matrix(img) == array_to_matrix(img2)); DLIB_TEST(mat(img) == mat(img2));
} }
} }
...@@ -485,7 +485,7 @@ namespace ...@@ -485,7 +485,7 @@ namespace
DLIB_TEST(be.current_element_valid() == false); DLIB_TEST(be.current_element_valid() == false);
DLIB_TEST(be.at_start() == false); DLIB_TEST(be.at_start() == false);
DLIB_TEST(array_to_matrix(img) == array_to_matrix(img2)); DLIB_TEST(mat(img) == mat(img2));
} }
} }
...@@ -521,7 +521,7 @@ namespace ...@@ -521,7 +521,7 @@ namespace
DLIB_TEST(be.move_next() == false); DLIB_TEST(be.move_next() == false);
DLIB_TEST(be.current_element_valid() == false); DLIB_TEST(be.current_element_valid() == false);
DLIB_TEST(array_to_matrix(img) == array_to_matrix(img2)); DLIB_TEST(mat(img) == mat(img2));
} }
} }
......
...@@ -57,7 +57,7 @@ namespace ...@@ -57,7 +57,7 @@ namespace
DLIB_TEST(img2.size() == 0); DLIB_TEST(img2.size() == 0);
DLIB_TEST(img2.nr() == 0); DLIB_TEST(img2.nr() == 0);
DLIB_TEST(img2.nc() == 0); DLIB_TEST(img2.nc() == 0);
assign_image(img2, array_to_matrix(img1)); assign_image(img2, mat(img1));
DLIB_TEST_MSG(img1.nr() == 100 && img1.nc() == 100 && DLIB_TEST_MSG(img1.nr() == 100 && img1.nc() == 100 &&
img2.nr() == 100 && img2.nc() == 100,""); img2.nr() == 100 && img2.nc() == 100,"");
...@@ -669,22 +669,22 @@ namespace ...@@ -669,22 +669,22 @@ namespace
assign_border_pixels(img, 2,2, 4); assign_border_pixels(img, 2,2, 4);
DLIB_TEST(zeros_matrix<unsigned char>(6,6) == subm(array_to_matrix(img), rectangle(2,2,7,7))); DLIB_TEST(zeros_matrix<unsigned char>(6,6) == subm(mat(img), rectangle(2,2,7,7)));
DLIB_TEST(uniform_matrix<unsigned char>(1,10, 4) == rowm(array_to_matrix(img), 0)); DLIB_TEST(uniform_matrix<unsigned char>(1,10, 4) == rowm(mat(img), 0));
DLIB_TEST(uniform_matrix<unsigned char>(1,10, 4) == rowm(array_to_matrix(img), 1)); DLIB_TEST(uniform_matrix<unsigned char>(1,10, 4) == rowm(mat(img), 1));
DLIB_TEST(uniform_matrix<unsigned char>(1,10, 4) == rowm(array_to_matrix(img), 8)); DLIB_TEST(uniform_matrix<unsigned char>(1,10, 4) == rowm(mat(img), 8));
DLIB_TEST(uniform_matrix<unsigned char>(1,10, 4) == rowm(array_to_matrix(img), 9)); DLIB_TEST(uniform_matrix<unsigned char>(1,10, 4) == rowm(mat(img), 9));
DLIB_TEST(uniform_matrix<unsigned char>(10,1, 4) == colm(array_to_matrix(img), 0)); DLIB_TEST(uniform_matrix<unsigned char>(10,1, 4) == colm(mat(img), 0));
DLIB_TEST(uniform_matrix<unsigned char>(10,1, 4) == colm(array_to_matrix(img), 1)); DLIB_TEST(uniform_matrix<unsigned char>(10,1, 4) == colm(mat(img), 1));
DLIB_TEST(uniform_matrix<unsigned char>(10,1, 4) == colm(array_to_matrix(img), 8)); DLIB_TEST(uniform_matrix<unsigned char>(10,1, 4) == colm(mat(img), 8));
DLIB_TEST(uniform_matrix<unsigned char>(10,1, 4) == colm(array_to_matrix(img), 9)); DLIB_TEST(uniform_matrix<unsigned char>(10,1, 4) == colm(mat(img), 9));
assign_border_pixels(img, 7, 7, 5); assign_border_pixels(img, 7, 7, 5);
DLIB_TEST(uniform_matrix<unsigned char>(10,10, 5) == array_to_matrix(img)); DLIB_TEST(uniform_matrix<unsigned char>(10,10, 5) == mat(img));
assign_border_pixels(img, 37, 47, 5); assign_border_pixels(img, 37, 47, 5);
DLIB_TEST(uniform_matrix<unsigned char>(10,10, 5) == array_to_matrix(img)); DLIB_TEST(uniform_matrix<unsigned char>(10,10, 5) == mat(img));
} }
{ {
...@@ -694,21 +694,21 @@ namespace ...@@ -694,21 +694,21 @@ namespace
assign_border_pixels(img, 2,2, 4); assign_border_pixels(img, 2,2, 4);
DLIB_TEST(zeros_matrix<unsigned char>(7,7) == subm(array_to_matrix(img), rectangle(2,2,8,8))); DLIB_TEST(zeros_matrix<unsigned char>(7,7) == subm(mat(img), rectangle(2,2,8,8)));
DLIB_TEST(uniform_matrix<unsigned char>(1,11, 4) == rowm(array_to_matrix(img), 0)); DLIB_TEST(uniform_matrix<unsigned char>(1,11, 4) == rowm(mat(img), 0));
DLIB_TEST(uniform_matrix<unsigned char>(1,11, 4) == rowm(array_to_matrix(img), 1)); DLIB_TEST(uniform_matrix<unsigned char>(1,11, 4) == rowm(mat(img), 1));
DLIB_TEST(uniform_matrix<unsigned char>(1,11, 4) == rowm(array_to_matrix(img), 9)); DLIB_TEST(uniform_matrix<unsigned char>(1,11, 4) == rowm(mat(img), 9));
DLIB_TEST(uniform_matrix<unsigned char>(1,11, 4) == rowm(array_to_matrix(img), 10)); DLIB_TEST(uniform_matrix<unsigned char>(1,11, 4) == rowm(mat(img), 10));
DLIB_TEST(uniform_matrix<unsigned char>(11,1, 4) == colm(array_to_matrix(img), 0)); DLIB_TEST(uniform_matrix<unsigned char>(11,1, 4) == colm(mat(img), 0));
DLIB_TEST(uniform_matrix<unsigned char>(11,1, 4) == colm(array_to_matrix(img), 1)); DLIB_TEST(uniform_matrix<unsigned char>(11,1, 4) == colm(mat(img), 1));
DLIB_TEST(uniform_matrix<unsigned char>(11,1, 4) == colm(array_to_matrix(img), 9)); DLIB_TEST(uniform_matrix<unsigned char>(11,1, 4) == colm(mat(img), 9));
DLIB_TEST(uniform_matrix<unsigned char>(11,1, 4) == colm(array_to_matrix(img), 10)); DLIB_TEST(uniform_matrix<unsigned char>(11,1, 4) == colm(mat(img), 10));
assign_border_pixels(img, 7, 7, 5); assign_border_pixels(img, 7, 7, 5);
DLIB_TEST(uniform_matrix<unsigned char>(11,11, 5) == array_to_matrix(img)); DLIB_TEST(uniform_matrix<unsigned char>(11,11, 5) == mat(img));
assign_border_pixels(img, 70, 57, 5); assign_border_pixels(img, 70, 57, 5);
DLIB_TEST(uniform_matrix<unsigned char>(11,11, 5) == array_to_matrix(img)); DLIB_TEST(uniform_matrix<unsigned char>(11,11, 5) == mat(img));
} }
...@@ -752,9 +752,9 @@ namespace ...@@ -752,9 +752,9 @@ namespace
point p1(rnd.get_random_32bit_number()%img.nc(), rnd.get_random_32bit_number()%img.nr()); point p1(rnd.get_random_32bit_number()%img.nc(), rnd.get_random_32bit_number()%img.nr());
point p2(rnd.get_random_32bit_number()%img.nc(), rnd.get_random_32bit_number()%img.nr()); point p2(rnd.get_random_32bit_number()%img.nc(), rnd.get_random_32bit_number()%img.nr());
rectangle rect(p1,p2); rectangle rect(p1,p2);
DLIB_TEST(int_img.get_sum_of_area(rect) == sum(subm(matrix_cast<T>(array_to_matrix(img)), rect))); DLIB_TEST(int_img.get_sum_of_area(rect) == sum(subm(matrix_cast<T>(mat(img)), rect)));
rect = rectangle(p1,p1); rect = rectangle(p1,p1);
DLIB_TEST(int_img.get_sum_of_area(rect) == sum(subm(matrix_cast<T>(array_to_matrix(img)), rect))); DLIB_TEST(int_img.get_sum_of_area(rect) == sum(subm(matrix_cast<T>(mat(img)), rect)));
} }
} }
...@@ -812,7 +812,7 @@ namespace ...@@ -812,7 +812,7 @@ namespace
spatially_filter_image_separable(img, img3, row_filter, col_filter); spatially_filter_image_separable(img, img3, row_filter, col_filter);
DLIB_TEST(array_to_matrix(img2) == array_to_matrix(img3)); DLIB_TEST(mat(img2) == mat(img3));
dlib::rand rnd; dlib::rand rnd;
...@@ -844,7 +844,7 @@ namespace ...@@ -844,7 +844,7 @@ namespace
rectangle brect1, brect2; rectangle brect1, brect2;
brect1 = spatially_filter_image(img, img2, filter, scale, use_abs); brect1 = spatially_filter_image(img, img2, filter, scale, use_abs);
brect2 = spatially_filter_image_separable(img, img3, row_filter, col_filter, scale, use_abs); brect2 = spatially_filter_image_separable(img, img3, row_filter, col_filter, scale, use_abs);
DLIB_TEST(array_to_matrix(img2) == array_to_matrix(img3)); DLIB_TEST(mat(img2) == mat(img3));
DLIB_TEST(brect1 == shrink_rect(get_rect(img), filter.nc()/2, filter.nr()/2)); DLIB_TEST(brect1 == shrink_rect(get_rect(img), filter.nc()/2, filter.nr()/2));
DLIB_TEST(brect1 == brect2); DLIB_TEST(brect1 == brect2);
...@@ -1256,13 +1256,13 @@ namespace ...@@ -1256,13 +1256,13 @@ namespace
spatially_filter_image_separable_down(downsample, img, out2, row_filter, col_filter); spatially_filter_image_separable_down(downsample, img, out2, row_filter, col_filter);
DLIB_TEST(get_rect(out1) == get_rect(out2)); DLIB_TEST(get_rect(out1) == get_rect(out2));
DLIB_TEST(array_to_matrix(out1) == array_to_matrix(out2)); DLIB_TEST(mat(out1) == mat(out2));
test_spatially_filter_image_separable_down_simple(downsample, img, out1, row_filter, col_filter,3, true, true ); test_spatially_filter_image_separable_down_simple(downsample, img, out1, row_filter, col_filter,3, true, true );
spatially_filter_image_separable_down(downsample, img, out2, row_filter, col_filter, 3, true, true); spatially_filter_image_separable_down(downsample, img, out2, row_filter, col_filter, 3, true, true);
DLIB_TEST(get_rect(out1) == get_rect(out2)); DLIB_TEST(get_rect(out1) == get_rect(out2));
DLIB_TEST(array_to_matrix(out1) == array_to_matrix(out2)); DLIB_TEST(mat(out1) == mat(out2));
} }
} }
......
...@@ -70,7 +70,7 @@ namespace ...@@ -70,7 +70,7 @@ namespace
} }
} }
DLIB_TEST(equal(K, kernel_matrix(kern, vect1, vect2))); DLIB_TEST(equal(K, kernel_matrix(kern, vect1, vect2)));
DLIB_TEST(equal(K, kernel_matrix(kern, vector_to_matrix(vect1), vector_to_matrix(vect2)))); DLIB_TEST(equal(K, kernel_matrix(kern, mat(vect1), mat(vect2))));
K.set_size(vect2.size(), vect1.size()); K.set_size(vect2.size(), vect1.size());
...@@ -83,7 +83,7 @@ namespace ...@@ -83,7 +83,7 @@ namespace
} }
DLIB_TEST(equal(K, kernel_matrix(kern, vect2, vect1))); DLIB_TEST(equal(K, kernel_matrix(kern, vect2, vect1)));
DLIB_TEST(equal(K, tmp(kernel_matrix(kern, vect2, vect1)))); DLIB_TEST(equal(K, tmp(kernel_matrix(kern, vect2, vect1))));
DLIB_TEST(equal(K, kernel_matrix(kern, vector_to_matrix(vect2), vector_to_matrix(vect1)))); DLIB_TEST(equal(K, kernel_matrix(kern, mat(vect2), mat(vect1))));
K.set_size(vect1.size(), vect1.size()); K.set_size(vect1.size(), vect1.size());
...@@ -98,10 +98,10 @@ namespace ...@@ -98,10 +98,10 @@ namespace
DLIB_TEST(equal(K, tmp(kernel_matrix(kern, vect1, vect1)))); DLIB_TEST(equal(K, tmp(kernel_matrix(kern, vect1, vect1))));
DLIB_TEST(equal(K, kernel_matrix(kern, vect1))); DLIB_TEST(equal(K, kernel_matrix(kern, vect1)));
DLIB_TEST(equal(K, tmp(kernel_matrix(kern, vect1)))); DLIB_TEST(equal(K, tmp(kernel_matrix(kern, vect1))));
DLIB_TEST(equal(K, kernel_matrix(kern, vector_to_matrix(vect1), vector_to_matrix(vect1)))); DLIB_TEST(equal(K, kernel_matrix(kern, mat(vect1), mat(vect1))));
DLIB_TEST(equal(K, tmp(kernel_matrix(kern, vector_to_matrix(vect1), vector_to_matrix(vect1))))); DLIB_TEST(equal(K, tmp(kernel_matrix(kern, mat(vect1), mat(vect1)))));
DLIB_TEST(equal(K, kernel_matrix(kern, vector_to_matrix(vect1)))); DLIB_TEST(equal(K, kernel_matrix(kern, mat(vect1))));
DLIB_TEST(equal(K, tmp(kernel_matrix(kern, vector_to_matrix(vect1))))); DLIB_TEST(equal(K, tmp(kernel_matrix(kern, mat(vect1)))));
K.set_size(vect1.size(),1); K.set_size(vect1.size(),1);
...@@ -113,7 +113,7 @@ namespace ...@@ -113,7 +113,7 @@ namespace
} }
} }
DLIB_TEST(equal(K, kernel_matrix(kern, vect1, samp))); DLIB_TEST(equal(K, kernel_matrix(kern, vect1, samp)));
DLIB_TEST(equal(K, kernel_matrix(kern, vector_to_matrix(vect1), samp))); DLIB_TEST(equal(K, kernel_matrix(kern, mat(vect1), samp)));
K.set_size(1, vect1.size()); K.set_size(1, vect1.size());
...@@ -125,9 +125,9 @@ namespace ...@@ -125,9 +125,9 @@ namespace
} }
} }
DLIB_TEST(equal(K, kernel_matrix(kern, samp, vect1))); DLIB_TEST(equal(K, kernel_matrix(kern, samp, vect1)));
DLIB_TEST(equal(K, kernel_matrix(kern, samp, vector_to_matrix(vect1)))); DLIB_TEST(equal(K, kernel_matrix(kern, samp, mat(vect1))));
DLIB_TEST(equal(K, tmp(kernel_matrix(kern, samp, vect1)))); DLIB_TEST(equal(K, tmp(kernel_matrix(kern, samp, vect1))));
DLIB_TEST(equal(K, tmp(kernel_matrix(kern, samp, vector_to_matrix(vect1))))); DLIB_TEST(equal(K, tmp(kernel_matrix(kern, samp, mat(vect1)))));
......
...@@ -422,26 +422,26 @@ namespace ...@@ -422,26 +422,26 @@ namespace
DLIB_TEST(rowm(array_to_matrix(a),1).nr() == 1); DLIB_TEST(rowm(mat(a),1).nr() == 1);
DLIB_TEST(rowm(array_to_matrix(a),1).nc() == a.nc()); DLIB_TEST(rowm(mat(a),1).nc() == a.nc());
DLIB_TEST(colm(array_to_matrix(a),1).nr() == a.nr()); DLIB_TEST(colm(mat(a),1).nr() == a.nr());
DLIB_TEST(colm(array_to_matrix(a),1).nc() == 1); DLIB_TEST(colm(mat(a),1).nc() == 1);
for (long c = 0; c < a.nc(); ++c) for (long c = 0; c < a.nc(); ++c)
{ {
DLIB_TEST( rowm(array_to_matrix(a),1)(c) == 1*a.nc() + c); DLIB_TEST( rowm(mat(a),1)(c) == 1*a.nc() + c);
} }
for (long r = 0; r < a.nr(); ++r) for (long r = 0; r < a.nr(); ++r)
{ {
DLIB_TEST( colm(array_to_matrix(a),1)(r) == r*a.nc() + 1); DLIB_TEST( colm(mat(a),1)(r) == r*a.nc() + 1);
} }
for (long r = 0; r < 2; ++r) for (long r = 0; r < 2; ++r)
{ {
for (long c = 0; c < 3; ++c) for (long c = 0; c < 3; ++c)
{ {
DLIB_TEST(subm(array_to_matrix(a),1,2,2,3)(r,c) == (r+1)*a.nc() + c+2); DLIB_TEST(subm(mat(a),1,2,2,3)(r,c) == (r+1)*a.nc() + c+2);
} }
} }
...@@ -461,11 +461,11 @@ namespace ...@@ -461,11 +461,11 @@ namespace
} }
matrix<double> mi = pinv(cos(exp(array_to_matrix(m))) ); matrix<double> mi = pinv(cos(exp(mat(m))) );
DLIB_TEST(mi.nr() == m.nc()); DLIB_TEST(mi.nr() == m.nc());
DLIB_TEST(mi.nc() == m.nr()); DLIB_TEST(mi.nc() == m.nr());
DLIB_TEST((equal(round_zeros(mi*cos(exp(array_to_matrix(m))),0.000001) , identity_matrix<double,5>()))); DLIB_TEST((equal(round_zeros(mi*cos(exp(mat(m))),0.000001) , identity_matrix<double,5>())));
DLIB_TEST((equal(round_zeros(cos(exp(array_to_matrix(m)))*mi,0.000001) , identity_matrix<double,5>()))); DLIB_TEST((equal(round_zeros(cos(exp(mat(m)))*mi,0.000001) , identity_matrix<double,5>())));
} }
{ {
......
...@@ -171,33 +171,33 @@ namespace ...@@ -171,33 +171,33 @@ namespace
for (long i = 0; i < 4; ++i) for (long i = 0; i < 4; ++i)
stdv[i] = stdv_c[i] = arr[i] = i+1; stdv[i] = stdv_c[i] = arr[i] = i+1;
DLIB_TEST(vector_to_matrix(stdv)(0) == 1); DLIB_TEST(mat(stdv)(0) == 1);
DLIB_TEST(vector_to_matrix(stdv)(1) == 2); DLIB_TEST(mat(stdv)(1) == 2);
DLIB_TEST(vector_to_matrix(stdv)(2) == 3); DLIB_TEST(mat(stdv)(2) == 3);
DLIB_TEST(vector_to_matrix(stdv)(3) == 4); DLIB_TEST(mat(stdv)(3) == 4);
DLIB_TEST(vector_to_matrix(stdv).nr() == 4); DLIB_TEST(mat(stdv).nr() == 4);
DLIB_TEST(vector_to_matrix(stdv).nc() == 1); DLIB_TEST(mat(stdv).nc() == 1);
DLIB_TEST(vector_to_matrix(stdv).size() == 4); DLIB_TEST(mat(stdv).size() == 4);
DLIB_TEST(equal(trans(vector_to_matrix(stdv))*vector_to_matrix(stdv), trans(v)*v)); DLIB_TEST(equal(trans(mat(stdv))*mat(stdv), trans(v)*v));
DLIB_TEST(equal(trans(vector_to_matrix(stdv))*vector_to_matrix(stdv), tmp(trans(v)*v))); DLIB_TEST(equal(trans(mat(stdv))*mat(stdv), tmp(trans(v)*v)));
DLIB_TEST(vector_to_matrix(stdv_c)(0) == 1); DLIB_TEST(mat(stdv_c)(0) == 1);
DLIB_TEST(vector_to_matrix(stdv_c)(1) == 2); DLIB_TEST(mat(stdv_c)(1) == 2);
DLIB_TEST(vector_to_matrix(stdv_c)(2) == 3); DLIB_TEST(mat(stdv_c)(2) == 3);
DLIB_TEST(vector_to_matrix(stdv_c)(3) == 4); DLIB_TEST(mat(stdv_c)(3) == 4);
DLIB_TEST(vector_to_matrix(stdv_c).nr() == 4); DLIB_TEST(mat(stdv_c).nr() == 4);
DLIB_TEST(vector_to_matrix(stdv_c).nc() == 1); DLIB_TEST(mat(stdv_c).nc() == 1);
DLIB_TEST(vector_to_matrix(stdv_c).size() == 4); DLIB_TEST(mat(stdv_c).size() == 4);
DLIB_TEST(equal(trans(vector_to_matrix(stdv_c))*vector_to_matrix(stdv_c), trans(v)*v)); DLIB_TEST(equal(trans(mat(stdv_c))*mat(stdv_c), trans(v)*v));
DLIB_TEST(vector_to_matrix(arr)(0) == 1); DLIB_TEST(mat(arr)(0) == 1);
DLIB_TEST(vector_to_matrix(arr)(1) == 2); DLIB_TEST(mat(arr)(1) == 2);
DLIB_TEST(vector_to_matrix(arr)(2) == 3); DLIB_TEST(mat(arr)(2) == 3);
DLIB_TEST(vector_to_matrix(arr)(3) == 4); DLIB_TEST(mat(arr)(3) == 4);
DLIB_TEST(vector_to_matrix(arr).nr() == 4); DLIB_TEST(mat(arr).nr() == 4);
DLIB_TEST(vector_to_matrix(arr).nc() == 1); DLIB_TEST(mat(arr).nc() == 1);
DLIB_TEST(vector_to_matrix(arr).size() == 4); DLIB_TEST(mat(arr).size() == 4);
DLIB_TEST(equal(trans(vector_to_matrix(arr))*vector_to_matrix(arr), trans(v)*v)); DLIB_TEST(equal(trans(mat(arr))*mat(arr), trans(v)*v));
DLIB_TEST(v(0) == 1); DLIB_TEST(v(0) == 1);
DLIB_TEST(v(1) == 2); DLIB_TEST(v(1) == 2);
......
...@@ -723,16 +723,16 @@ namespace ...@@ -723,16 +723,16 @@ namespace
std::vector<double> v(34, 8); std::vector<double> v(34, 8);
std::vector<double> v2(34, 9); std::vector<double> v2(34, 9);
DLIB_TEST(pointer_to_column_vector(&v[0], v.size()) == vector_to_matrix(v)); DLIB_TEST(mat(&v[0], v.size()) == mat(v));
DLIB_TEST(pointer_to_column_vector(&v2[0], v.size()) != vector_to_matrix(v)); DLIB_TEST(mat(&v2[0], v.size()) != mat(v));
} }
{ {
std::vector<long> v(1, 3); std::vector<long> v(1, 3);
std::vector<long> v2(1, 2); std::vector<long> v2(1, 2);
DLIB_TEST(pointer_to_column_vector(&v[0], v.size()) == vector_to_matrix(v)); DLIB_TEST(mat(&v[0], v.size()) == mat(v));
DLIB_TEST(pointer_to_column_vector(&v2[0], v.size()) != vector_to_matrix(v)); DLIB_TEST(mat(&v2[0], v.size()) != mat(v));
} }
{ {
...@@ -940,7 +940,7 @@ namespace ...@@ -940,7 +940,7 @@ namespace
a = 0, 1, 2, a = 0, 1, 2,
3, 4, 5; 3, 4, 5;
DLIB_TEST(pointer_to_matrix(&v[0], 2, 3) == a); DLIB_TEST(mat(&v[0], 2, 3) == a);
} }
{ {
......
...@@ -66,7 +66,7 @@ namespace ...@@ -66,7 +66,7 @@ namespace
oca solver; oca solver;
// test the version without a non-negativity constraint on w. // test the version without a non-negativity constraint on w.
solver(make_oca_problem_c_svm<w_type>(2.0, 3.0, vector_to_matrix(x), vector_to_matrix(y), false, 1e-12, 40), w, 0); solver(make_oca_problem_c_svm<w_type>(2.0, 3.0, mat(x), mat(y), false, 1e-12, 40), w, 0);
dlog << LINFO << trans(w); dlog << LINFO << trans(w);
true_w = -0.5, 0.5, 0; true_w = -0.5, 0.5, 0;
dlog << LINFO << "error: "<< max(abs(w-true_w)); dlog << LINFO << "error: "<< max(abs(w-true_w));
...@@ -75,7 +75,7 @@ namespace ...@@ -75,7 +75,7 @@ namespace
print_spinner(); print_spinner();
// test the version with a non-negativity constraint on w. // test the version with a non-negativity constraint on w.
solver(make_oca_problem_c_svm<w_type>(2.0, 3.0, vector_to_matrix(x), vector_to_matrix(y), false, 1e-12, 40), w, 9999); solver(make_oca_problem_c_svm<w_type>(2.0, 3.0, mat(x), mat(y), false, 1e-12, 40), w, 9999);
dlog << LINFO << trans(w); dlog << LINFO << trans(w);
true_w = 0, 1, 0; true_w = 0, 1, 0;
dlog << LINFO << "error: "<< max(abs(w-true_w)); dlog << LINFO << "error: "<< max(abs(w-true_w));
...@@ -91,7 +91,7 @@ namespace ...@@ -91,7 +91,7 @@ namespace
print_spinner(); print_spinner();
// test the version with a non-negativity constraint on w. // test the version with a non-negativity constraint on w.
solver(make_oca_problem_c_svm<w_type>(2.0, 3.0, vector_to_matrix(x), vector_to_matrix(y), false, 1e-12, 40), w, 2); solver(make_oca_problem_c_svm<w_type>(2.0, 3.0, mat(x), mat(y), false, 1e-12, 40), w, 2);
dlog << LINFO << trans(w); dlog << LINFO << trans(w);
true_w = 0, 1, 0; true_w = 0, 1, 0;
dlog << LINFO << "error: "<< max(abs(w-true_w)); dlog << LINFO << "error: "<< max(abs(w-true_w));
...@@ -101,7 +101,7 @@ namespace ...@@ -101,7 +101,7 @@ namespace
// test the version with a non-negativity constraint on w. // test the version with a non-negativity constraint on w.
solver(make_oca_problem_c_svm<w_type>(2.0, 3.0, vector_to_matrix(x), vector_to_matrix(y), false, 1e-12, 40), w, 1); solver(make_oca_problem_c_svm<w_type>(2.0, 3.0, mat(x), mat(y), false, 1e-12, 40), w, 1);
dlog << LINFO << trans(w); dlog << LINFO << trans(w);
true_w = 0, 1, 0; true_w = 0, 1, 0;
dlog << LINFO << "error: "<< max(abs(w-true_w)); dlog << LINFO << "error: "<< max(abs(w-true_w));
...@@ -116,7 +116,7 @@ namespace ...@@ -116,7 +116,7 @@ namespace
y.push_back(+1); y.push_back(+1);
solver(make_oca_problem_c_svm<w_type>(2.0, 3.0, vector_to_matrix(x), vector_to_matrix(y), false, 1e-12, 40), w, 0); solver(make_oca_problem_c_svm<w_type>(2.0, 3.0, mat(x), mat(y), false, 1e-12, 40), w, 0);
dlog << LINFO << trans(w); dlog << LINFO << trans(w);
true_w = 0.5, -0.5, 0; true_w = 0.5, -0.5, 0;
dlog << LINFO << "error: "<< max(abs(w-true_w)); dlog << LINFO << "error: "<< max(abs(w-true_w));
...@@ -124,7 +124,7 @@ namespace ...@@ -124,7 +124,7 @@ namespace
print_spinner(); print_spinner();
solver(make_oca_problem_c_svm<w_type>(2.0, 3.0, vector_to_matrix(x), vector_to_matrix(y), false, 1e-12, 40), w, 1); solver(make_oca_problem_c_svm<w_type>(2.0, 3.0, mat(x), mat(y), false, 1e-12, 40), w, 1);
dlog << LINFO << trans(w); dlog << LINFO << trans(w);
true_w = 0.5, -0.5, 0; true_w = 0.5, -0.5, 0;
dlog << LINFO << "error: "<< max(abs(w-true_w)); dlog << LINFO << "error: "<< max(abs(w-true_w));
...@@ -132,7 +132,7 @@ namespace ...@@ -132,7 +132,7 @@ namespace
print_spinner(); print_spinner();
solver(make_oca_problem_c_svm<w_type>(2.0, 3.0, vector_to_matrix(x), vector_to_matrix(y), false, 1e-12, 40), w, 2); solver(make_oca_problem_c_svm<w_type>(2.0, 3.0, mat(x), mat(y), false, 1e-12, 40), w, 2);
dlog << LINFO << trans(w); dlog << LINFO << trans(w);
true_w = 1, 0, 0; true_w = 1, 0, 0;
dlog << LINFO << "error: "<< max(abs(w-true_w)); dlog << LINFO << "error: "<< max(abs(w-true_w));
...@@ -140,7 +140,7 @@ namespace ...@@ -140,7 +140,7 @@ namespace
print_spinner(); print_spinner();
solver(make_oca_problem_c_svm<w_type>(2.0, 3.0, vector_to_matrix(x), vector_to_matrix(y), false, 1e-12, 40), w, 5); solver(make_oca_problem_c_svm<w_type>(2.0, 3.0, mat(x), mat(y), false, 1e-12, 40), w, 5);
dlog << LINFO << trans(w); dlog << LINFO << trans(w);
true_w = 1, 0, 0; true_w = 1, 0, 0;
dlog << LINFO << "error: "<< max(abs(w-true_w)); dlog << LINFO << "error: "<< max(abs(w-true_w));
......
...@@ -58,8 +58,8 @@ namespace ...@@ -58,8 +58,8 @@ namespace
rx.set_max_size(x.size()); rx.set_max_size(x.size());
ry.set_max_size(x.size()); ry.set_max_size(x.size());
dlog << LINFO << "pos labels: "<< sum(vector_to_matrix(y) == +1); dlog << LINFO << "pos labels: "<< sum(mat(y) == +1);
dlog << LINFO << "neg labels: "<< sum(vector_to_matrix(y) == -1); dlog << LINFO << "neg labels: "<< sum(mat(y) == -1);
for (unsigned long i = 0; i < x.size(); ++i) for (unsigned long i = 0; i < x.size(); ++i)
{ {
......
...@@ -44,8 +44,8 @@ void test_pyramid_down_grayscale() ...@@ -44,8 +44,8 @@ void test_pyramid_down_grayscale()
overlap = rect1.intersect(rect2).area() / (double)(rect1 + rect2).area(); overlap = rect1.intersect(rect2).area() / (double)(rect1 + rect2).area();
DLIB_TEST(overlap > 0.95); DLIB_TEST(overlap > 0.95);
DLIB_TEST(min(array_to_matrix(down)) == 10); DLIB_TEST(min(mat(down)) == 10);
DLIB_TEST(max(array_to_matrix(down)) == 10); DLIB_TEST(max(mat(down)) == 10);
} }
void test_pyramid_down_rgb() void test_pyramid_down_rgb()
...@@ -169,11 +169,11 @@ void test_pyramid_down_rgb2() ...@@ -169,11 +169,11 @@ void test_pyramid_down_rgb2()
*/ */
DLIB_TEST(std::abs((int)mean(subm(matrix_cast<long>(array_to_matrix(img2)),rect1)) - 255/3) < 3); DLIB_TEST(std::abs((int)mean(subm(matrix_cast<long>(mat(img2)),rect1)) - 255/3) < 3);
DLIB_TEST(std::abs((int)mean(subm(matrix_cast<long>(array_to_matrix(img2)),rect2)) - 255/3) < 3); DLIB_TEST(std::abs((int)mean(subm(matrix_cast<long>(mat(img2)),rect2)) - 255/3) < 3);
DLIB_TEST(std::abs((int)mean(subm(matrix_cast<long>(array_to_matrix(img2)),rect3)) - 255/3) < 3); DLIB_TEST(std::abs((int)mean(subm(matrix_cast<long>(mat(img2)),rect3)) - 255/3) < 3);
assign_image(img4, img); assign_image(img4, img);
DLIB_TEST(std::abs((int)mean(array_to_matrix(img4)) - mean(array_to_matrix(img2))) < 2); DLIB_TEST(std::abs((int)mean(mat(img4)) - mean(mat(img2))) < 2);
rgb_pixel mean1 = mean_pixel(img3, rect1); rgb_pixel mean1 = mean_pixel(img3, rect1);
...@@ -256,11 +256,11 @@ void test_pyramid_down_grayscale2() ...@@ -256,11 +256,11 @@ void test_pyramid_down_grayscale2()
*/ */
DLIB_TEST(std::abs((int)mean(subm(matrix_cast<long>(array_to_matrix(img2)),rect1)) - 255) < 3); DLIB_TEST(std::abs((int)mean(subm(matrix_cast<long>(mat(img2)),rect1)) - 255) < 3);
DLIB_TEST(std::abs((int)mean(subm(matrix_cast<long>(array_to_matrix(img2)),rect2)) - 170) < 3); DLIB_TEST(std::abs((int)mean(subm(matrix_cast<long>(mat(img2)),rect2)) - 170) < 3);
DLIB_TEST(std::abs((int)mean(subm(matrix_cast<long>(array_to_matrix(img2)),rect3)) - 100) < 3); DLIB_TEST(std::abs((int)mean(subm(matrix_cast<long>(mat(img2)),rect3)) - 100) < 3);
assign_image(img4, img); assign_image(img4, img);
DLIB_TEST(std::abs((int)mean(array_to_matrix(img4)) - mean(array_to_matrix(img2))) < 2); DLIB_TEST(std::abs((int)mean(mat(img4)) - mean(mat(img2))) < 2);
//my_window.wait_until_closed(); //my_window.wait_until_closed();
......
...@@ -68,8 +68,8 @@ namespace ...@@ -68,8 +68,8 @@ namespace
count_ranking_inversions(x, y, x_count, y_count); count_ranking_inversions(x, y, x_count, y_count);
brute_force_count_ranking_inversions(x, y, x_count2, y_count2); brute_force_count_ranking_inversions(x, y, x_count2, y_count2);
DLIB_TEST(vector_to_matrix(x_count) == vector_to_matrix(x_count2)); DLIB_TEST(mat(x_count) == mat(x_count2));
DLIB_TEST(vector_to_matrix(y_count) == vector_to_matrix(y_count2)); DLIB_TEST(mat(y_count) == mat(y_count2));
} }
} }
......
...@@ -139,7 +139,7 @@ namespace ...@@ -139,7 +139,7 @@ namespace
strip = strip.intersect(get_rect(img)); strip = strip.intersect(get_rect(img));
if (!strip.is_empty()) if (!strip.is_empty())
{ {
column_sums[i][j] = sum(matrix_cast<ptype>(subm(array_to_matrix(img),strip))); column_sums[i][j] = sum(matrix_cast<ptype>(subm(mat(img),strip)));
} }
++left; ++left;
...@@ -434,8 +434,8 @@ namespace ...@@ -434,8 +434,8 @@ namespace
sum_filter(img, test1_i, rect); sum_filter(img, test1_i, rect);
sum_filter(img, test2_i, rect); sum_filter(img, test2_i, rect);
DLIB_TEST(array_to_matrix(test1) == array_to_matrix(test1_i)); DLIB_TEST(mat(test1) == mat(test1_i));
DLIB_TEST(array_to_matrix(test2) == array_to_matrix(test2_i)); DLIB_TEST(mat(test2) == mat(test2_i));
} }
} }
} }
...@@ -462,7 +462,7 @@ namespace ...@@ -462,7 +462,7 @@ namespace
for (long c = 0; c < img.nc(); ++c) for (long c = 0; c < img.nc(); ++c)
{ {
const rectangle win = centered_rect(point(c,r),width,height).intersect(area); const rectangle win = centered_rect(point(c,r),width,height).intersect(area);
out[r][c] += std::max(dlib::max(subm(array_to_matrix(img),win)), thresh); out[r][c] += std::max(dlib::max(subm(mat(img),win)), thresh);
} }
} }
} }
...@@ -492,7 +492,7 @@ namespace ...@@ -492,7 +492,7 @@ namespace
naive_max_filter(img, out2, rect.width(), rect.height(), thresh); naive_max_filter(img, out2, rect.width(), rect.height(), thresh);
max_filter(img, out, rect.width(), rect.height(), thresh); max_filter(img, out, rect.width(), rect.height(), thresh);
DLIB_TEST_MSG(array_to_matrix(out) == array_to_matrix(out2), DLIB_TEST_MSG(mat(out) == mat(out2),
"rows: "<< rows "rows: "<< rows
<< "\ncols: "<< rows << "\ncols: "<< rows
<< "\nwidth: "<< width << "\nwidth: "<< width
......
...@@ -307,8 +307,8 @@ namespace ...@@ -307,8 +307,8 @@ namespace
// print out some of the randomly sampled sequences // print out some of the randomly sampled sequences
for (int i = 0; i < 10; ++i) for (int i = 0; i < 10; ++i)
{ {
dlog << LINFO << "hidden states: " << trans(vector_to_matrix(labels[i])); dlog << LINFO << "hidden states: " << trans(mat(labels[i]));
dlog << LINFO << "observed states: " << trans(vector_to_matrix(samples[i].item)); dlog << LINFO << "observed states: " << trans(mat(samples[i].item));
dlog << LINFO << "******************************"; dlog << LINFO << "******************************";
} }
...@@ -325,10 +325,10 @@ namespace ...@@ -325,10 +325,10 @@ namespace
sequence_labeler<fe_type> labeler = trainer.train(samples, labels); sequence_labeler<fe_type> labeler = trainer.train(samples, labels);
std::vector<unsigned long> predicted_labels = labeler(samples[0]); std::vector<unsigned long> predicted_labels = labeler(samples[0]);
dlog << LINFO << "true hidden states: "<< trans(vector_to_matrix(labels[0])); dlog << LINFO << "true hidden states: "<< trans(mat(labels[0]));
dlog << LINFO << "predicted hidden states: "<< trans(vector_to_matrix(predicted_labels)); dlog << LINFO << "predicted hidden states: "<< trans(mat(predicted_labels));
DLIB_TEST(vector_to_matrix(labels[0]) == vector_to_matrix(predicted_labels)); DLIB_TEST(mat(labels[0]) == mat(predicted_labels));
print_spinner(); print_spinner();
......
...@@ -114,7 +114,7 @@ namespace ...@@ -114,7 +114,7 @@ namespace
for (unsigned long i = 0; i < samples.size(); ++i) for (unsigned long i = 0; i < samples.size(); ++i)
cur_vals.push_back(df(samples[i])); cur_vals.push_back(df(samples[i]));
const double err = max(abs(vector_to_matrix(cur_vals) - vector_to_matrix(prev_vals))); const double err = max(abs(mat(cur_vals) - mat(prev_vals)));
dlog << LINFO << "simplify error: "<< err; dlog << LINFO << "simplify error: "<< err;
DLIB_TEST(err < 1e-13); DLIB_TEST(err < 1e-13);
...@@ -150,7 +150,7 @@ namespace ...@@ -150,7 +150,7 @@ namespace
for (unsigned long i = 0; i < samples.size(); ++i) for (unsigned long i = 0; i < samples.size(); ++i)
cur_vals.push_back(df(samples[i])); cur_vals.push_back(df(samples[i]));
const double err = max(abs(vector_to_matrix(cur_vals) - vector_to_matrix(prev_vals))); const double err = max(abs(mat(cur_vals) - mat(prev_vals)));
dlog << LINFO << "simplify error: "<< err; dlog << LINFO << "simplify error: "<< err;
DLIB_TEST(err < 1e-13); DLIB_TEST(err < 1e-13);
...@@ -189,7 +189,7 @@ namespace ...@@ -189,7 +189,7 @@ namespace
for (unsigned long i = 0; i < dense_samples.size(); ++i) for (unsigned long i = 0; i < dense_samples.size(); ++i)
cur_vals.push_back(dense_df(dense_samples[i])); cur_vals.push_back(dense_df(dense_samples[i]));
const double err = max(abs(vector_to_matrix(cur_vals) - vector_to_matrix(prev_vals))); const double err = max(abs(mat(cur_vals) - mat(prev_vals)));
dlog << LINFO << "simplify error: "<< err; dlog << LINFO << "simplify error: "<< err;
DLIB_TEST(err < 1e-13); DLIB_TEST(err < 1e-13);
} }
...@@ -228,7 +228,7 @@ namespace ...@@ -228,7 +228,7 @@ namespace
for (unsigned long i = 0; i < dense_samples.size(); ++i) for (unsigned long i = 0; i < dense_samples.size(); ++i)
cur_vals.push_back(dense_df(dense_samples[i])); cur_vals.push_back(dense_df(dense_samples[i]));
const double err = max(abs(vector_to_matrix(cur_vals) - vector_to_matrix(prev_vals))); const double err = max(abs(mat(cur_vals) - mat(prev_vals)));
dlog << LINFO << "simplify error: "<< err; dlog << LINFO << "simplify error: "<< err;
DLIB_TEST(err < 1e-13); DLIB_TEST(err < 1e-13);
} }
...@@ -275,7 +275,7 @@ namespace ...@@ -275,7 +275,7 @@ namespace
for (unsigned long i = 0; i < dense_samples.size(); ++i) for (unsigned long i = 0; i < dense_samples.size(); ++i)
cur_vals.push_back(simple_df(dense_samples[i])); cur_vals.push_back(simple_df(dense_samples[i]));
const double err = max(abs(vector_to_matrix(cur_vals) - vector_to_matrix(prev_vals))); const double err = max(abs(mat(cur_vals) - mat(prev_vals)));
dlog << LINFO << "simplify error: "<< err; dlog << LINFO << "simplify error: "<< err;
DLIB_TEST(err < 1e-13); DLIB_TEST(err < 1e-13);
......
...@@ -155,9 +155,9 @@ namespace ...@@ -155,9 +155,9 @@ namespace
} }
DLIB_TEST(cov.in_vector_size() == (long)dims); DLIB_TEST(cov.in_vector_size() == (long)dims);
DLIB_TEST(equal(mean(vector_to_matrix(vects)), cov.mean())); DLIB_TEST(equal(mean(mat(vects)), cov.mean()));
DLIB_TEST_MSG(equal(covariance(vector_to_matrix(vects)), cov.covariance()), DLIB_TEST_MSG(equal(covariance(mat(vects)), cov.covariance()),
max(abs(covariance(vector_to_matrix(vects)) - cov.covariance())) max(abs(covariance(mat(vects)) - cov.covariance()))
<< " dims = " << dims << " samps = " << samps << " dims = " << dims << " samps = " << samps
); );
} }
...@@ -182,9 +182,9 @@ namespace ...@@ -182,9 +182,9 @@ namespace
} }
DLIB_TEST((cov+cov2).in_vector_size() == (long)dims); DLIB_TEST((cov+cov2).in_vector_size() == (long)dims);
DLIB_TEST(equal(mean(vector_to_matrix(vects)), (cov+cov2).mean())); DLIB_TEST(equal(mean(mat(vects)), (cov+cov2).mean()));
DLIB_TEST_MSG(equal(covariance(vector_to_matrix(vects)), (cov+cov2).covariance()), DLIB_TEST_MSG(equal(covariance(mat(vects)), (cov+cov2).covariance()),
max(abs(covariance(vector_to_matrix(vects)) - (cov+cov2).covariance())) max(abs(covariance(mat(vects)) - (cov+cov2).covariance()))
<< " dims = " << dims << " samps = " << samps << " dims = " << dims << " samps = " << samps
); );
} }
...@@ -298,9 +298,9 @@ namespace ...@@ -298,9 +298,9 @@ namespace
a.push_back(i); a.push_back(i);
} }
DLIB_TEST(std::abs(variance(vector_to_matrix(a)) - rs1.variance()) < 1e-13); DLIB_TEST(std::abs(variance(mat(a)) - rs1.variance()) < 1e-13);
DLIB_TEST(std::abs(stddev(vector_to_matrix(a)) - rs1.stddev()) < 1e-13); DLIB_TEST(std::abs(stddev(mat(a)) - rs1.stddev()) < 1e-13);
DLIB_TEST(std::abs(mean(vector_to_matrix(a)) - rs1.mean()) < 1e-13); DLIB_TEST(std::abs(mean(mat(a)) - rs1.mean()) < 1e-13);
for (int i = 10; i < 20; ++i) for (int i = 10; i < 20; ++i)
{ {
...@@ -308,8 +308,8 @@ namespace ...@@ -308,8 +308,8 @@ namespace
a.push_back(i); a.push_back(i);
} }
DLIB_TEST(std::abs(variance(vector_to_matrix(a)) - (rs1+rs2).variance()) < 1e-13); DLIB_TEST(std::abs(variance(mat(a)) - (rs1+rs2).variance()) < 1e-13);
DLIB_TEST(std::abs(mean(vector_to_matrix(a)) - (rs1+rs2).mean()) < 1e-13); DLIB_TEST(std::abs(mean(mat(a)) - (rs1+rs2).mean()) < 1e-13);
DLIB_TEST((rs1+rs2).current_n() == 20); DLIB_TEST((rs1+rs2).current_n() == 20);
running_scalar_covariance<double> rc1, rc2, rc3; running_scalar_covariance<double> rc1, rc2, rc3;
......
...@@ -69,7 +69,7 @@ namespace ...@@ -69,7 +69,7 @@ namespace
psi.push_back(std::make_pair(dims-1,static_cast<scalar_type>(-1))); psi.push_back(std::make_pair(dims-1,static_cast<scalar_type>(-1)));
// Find which distinct label goes with this psi. // Find which distinct label goes with this psi.
const long label_idx = index_of_max(vector_to_matrix(distinct_labels) == labels[idx]); const long label_idx = index_of_max(mat(distinct_labels) == labels[idx]);
offset_feature_vector(psi, dims*label_idx); offset_feature_vector(psi, dims*label_idx);
} }
......
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