28 if (i1 == i2)
return false;
29 const base_node &pt1((i1 ==
size_type(-1)) ? *c : (*vbn)[i1]);
30 const base_node &pt2((i2 ==
size_type(-1)) ? *c : (*vbn)[i2]);
31 unsigned d = pt1.size();
32 base_small_vector::const_iterator it = v.begin();
33 base_node::const_iterator it1 = pt1.begin(), it2 = pt2.begin();
35 for (
size_type i = 0; i < d; ++i) a += (*it++) * (*it1++ - *it2++);
36 if (a != scalar_type(0))
return a < 0;
41 node_tab::component_comp::component_comp
42 (
const dal::dynamic_tas<base_node> &vbn_,
const base_node &c_,
unsigned dim)
43 : vbn(&vbn_), c(&c_), v(dim) {
45 gmm::scale(v, scalar_type(1) / gmm::vect_norm2(v) );
48 void node_tab::add_sorter(
void)
const {
49 if (sorters.size() > 1)
50 GMM_WARNING3(
"Multiple sort needed for node tab : " << sorters.size()+1);
51 sorters.push_back(sorter(component_comp(*
this, c, dim_)));
52 for (dal::bv_visitor i(index()); !i.finished(); ++i)
56 size_type node_tab::search_node(
const base_node &pt,
57 const scalar_type radius)
const {
58 if (card() == 0 || radius < 0.)
61 scalar_type eps_radius = std::max(eps, radius);
62 for (size_type is = 0; is < 5; ++is) {
63 if (is >= sorters.size()) add_sorter();
65 c = pt - eps_radius * sorters[is].key_comp().v;
67 sorter::const_iterator it = sorters[is].lower_bound(
size_type(-1));
69 = gmm::vect_sp(pt, sorters[is].key_comp().v) + 2*eps_radius;
72 for (; it != sorters[is].end() && count < 20; ++it, ++count) {
80 if (gmm::vect_dist2(pt, pt2) < eps_radius)
return *it;
81 if (gmm::vect_sp(pt2, sorters[is].key_comp().v) > up_bound)
84 if (it == sorters[is].end())
return size_type(-1);
86 GMM_ASSERT1(
false,
"Problem in node structure !!");
89 void node_tab::clear() {
90 dal::dynamic_tas<base_node>::clear();
91 sorters = std::vector<sorter>();
92 max_radius = scalar_type(1e-60);
93 eps = max_radius * prec_factor;
97 const scalar_type radius,
98 bool remove_duplicated_nodes) {
99 scalar_type npt = gmm::vect_norm2(pt);
100 max_radius = std::max(max_radius, npt);
101 eps = max_radius * prec_factor;
103 if (this->card() == 0)
106 GMM_ASSERT1(dim_ == pt.size(),
"Nodes should have the same dimension");
108 if (remove_duplicated_nodes && radius >= 0.)
109 id = search_node(pt, radius);
111 id = dal::dynamic_tas<base_node>::add(pt);
112 for (size_type i = 0; i < sorters.size(); ++i) {
113 sorters[i].insert(
id);
114 GMM_ASSERT3(sorters[i].size() == card(),
"internal error");
122 bool existi = index().is_in(i), existj = index().is_in(j);
123 for (
size_type is = 0; is < sorters.size(); ++is) {
124 if (existi) sorters[is].erase(i);
125 if (existj) sorters[is].erase(j);
127 dal::dynamic_tas<base_node>::swap(i, j);
128 for (
size_type is = 0; is < sorters.size(); ++is) {
129 if (existi) sorters[is].insert(j);
130 if (existj) sorters[is].insert(i);
131 GMM_ASSERT3(sorters[is].size() == card(),
"internal error");
137 if (index().is_in(i)) {
138 for (
size_type is = 0; is < sorters.size(); ++is) {
139 sorters[is].erase(i);
140 GMM_ASSERT3(sorters[is].size()+1 == card(),
"Internal error");
143 dal::dynamic_tas<base_node>::sup(i);
148 void node_tab::translation(
const base_small_vector &V) {
149 for (dal::bv_visitor i(index()); !i.finished(); ++i) (*
this)[i] += V;
153 void node_tab::transformation(
const base_matrix &M) {
154 base_small_vector w(M.nrows());
155 GMM_ASSERT1(gmm::mat_nrows(M) != 0 && gmm::mat_ncols(M) == dim(),
156 "invalid dimensions for the transformation matrix");
157 dim_ = unsigned(gmm::mat_nrows(M));
158 for (dal::bv_visitor i(index()); !i.finished(); ++i) {
166 node_tab::node_tab(scalar_type prec_loose) {
167 max_radius = scalar_type(1e-60);
169 prec_factor = gmm::default_tol(scalar_type()) * prec_loose;
170 eps = max_radius * prec_factor;
173 node_tab::node_tab(
const node_tab &t)
174 :
dal::dynamic_tas<base_node>(t), sorters(), eps(t.eps),
175 prec_factor(t.prec_factor), max_radius(t.max_radius), dim_(t.dim_) {}
177 node_tab &node_tab::operator =(
const node_tab &t) {
178 dal::dynamic_tas<base_node>::operator =(t);
179 sorters = std::vector<sorter>();
180 eps = t.eps; prec_factor = t.prec_factor;
181 max_radius = t.max_radius; dim_ = t.dim_;
Structure which dynamically collects points identifying points that are nearer than a certain very sm...
void fill_random(L &l)
fill a vector or matrix with random value (uniform [-1,1]).
void resize(V &v, size_type n)
*/
void mult(const L1 &l1, const L2 &l2, L3 &l3)
*/
size_t size_type
used as the common size type in the library