Line data Source code
1 : /*************************************************************************
2 : ALGLIB 3.17.0 (source code generated 2020-12-27)
3 : Copyright (c) Sergey Bochkanov (ALGLIB project).
4 :
5 : >>> SOURCE LICENSE >>>
6 : This program is free software; you can redistribute it and/or modify
7 : it under the terms of the GNU General Public License as published by
8 : the Free Software Foundation (www.fsf.org); either version 2 of the
9 : License, or (at your option) any later version.
10 :
11 : This program is distributed in the hope that it will be useful,
12 : but WITHOUT ANY WARRANTY; without even the implied warranty of
13 : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 : GNU General Public License for more details.
15 :
16 : A copy of the GNU General Public License is available at
17 : http://www.fsf.org/licensing/licenses
18 : >>> END OF LICENSE >>>
19 : *************************************************************************/
20 : #ifdef _MSC_VER
21 : #define _CRT_SECURE_NO_WARNINGS
22 : #endif
23 : #include "stdafx.h"
24 : #include "alglibmisc.h"
25 :
26 : // disable some irrelevant warnings
27 : #if (AE_COMPILER==AE_MSVC) && !defined(AE_ALL_WARNINGS)
28 : #pragma warning(disable:4100)
29 : #pragma warning(disable:4127)
30 : #pragma warning(disable:4611)
31 : #pragma warning(disable:4702)
32 : #pragma warning(disable:4996)
33 : #endif
34 :
35 : /////////////////////////////////////////////////////////////////////////
36 : //
37 : // THIS SECTION CONTAINS IMPLEMENTATION OF C++ INTERFACE
38 : //
39 : /////////////////////////////////////////////////////////////////////////
40 : namespace alglib
41 : {
42 :
43 : #if defined(AE_COMPILE_NEARESTNEIGHBOR) || !defined(AE_PARTIAL_BUILD)
44 :
45 : #endif
46 :
47 : #if defined(AE_COMPILE_HQRND) || !defined(AE_PARTIAL_BUILD)
48 :
49 : #endif
50 :
51 : #if defined(AE_COMPILE_XDEBUG) || !defined(AE_PARTIAL_BUILD)
52 :
53 : #endif
54 :
55 : #if defined(AE_COMPILE_NEARESTNEIGHBOR) || !defined(AE_PARTIAL_BUILD)
56 : /*************************************************************************
57 : Buffer object which is used to perform nearest neighbor requests in the
58 : multithreaded mode (multiple threads working with same KD-tree object).
59 :
60 : This object should be created with KDTreeCreateRequestBuffer().
61 : *************************************************************************/
62 0 : _kdtreerequestbuffer_owner::_kdtreerequestbuffer_owner()
63 : {
64 : jmp_buf _break_jump;
65 : alglib_impl::ae_state _state;
66 :
67 0 : alglib_impl::ae_state_init(&_state);
68 0 : if( setjmp(_break_jump) )
69 : {
70 0 : if( p_struct!=NULL )
71 : {
72 0 : alglib_impl::_kdtreerequestbuffer_destroy(p_struct);
73 0 : alglib_impl::ae_free(p_struct);
74 : }
75 0 : p_struct = NULL;
76 : #if !defined(AE_NO_EXCEPTIONS)
77 0 : _ALGLIB_CPP_EXCEPTION(_state.error_msg);
78 : #else
79 : _ALGLIB_SET_ERROR_FLAG(_state.error_msg);
80 : return;
81 : #endif
82 : }
83 0 : alglib_impl::ae_state_set_break_jump(&_state, &_break_jump);
84 0 : p_struct = NULL;
85 0 : p_struct = (alglib_impl::kdtreerequestbuffer*)alglib_impl::ae_malloc(sizeof(alglib_impl::kdtreerequestbuffer), &_state);
86 0 : memset(p_struct, 0, sizeof(alglib_impl::kdtreerequestbuffer));
87 0 : alglib_impl::_kdtreerequestbuffer_init(p_struct, &_state, ae_false);
88 0 : ae_state_clear(&_state);
89 0 : }
90 :
91 0 : _kdtreerequestbuffer_owner::_kdtreerequestbuffer_owner(const _kdtreerequestbuffer_owner &rhs)
92 : {
93 : jmp_buf _break_jump;
94 : alglib_impl::ae_state _state;
95 :
96 0 : alglib_impl::ae_state_init(&_state);
97 0 : if( setjmp(_break_jump) )
98 : {
99 0 : if( p_struct!=NULL )
100 : {
101 0 : alglib_impl::_kdtreerequestbuffer_destroy(p_struct);
102 0 : alglib_impl::ae_free(p_struct);
103 : }
104 0 : p_struct = NULL;
105 : #if !defined(AE_NO_EXCEPTIONS)
106 0 : _ALGLIB_CPP_EXCEPTION(_state.error_msg);
107 : #else
108 : _ALGLIB_SET_ERROR_FLAG(_state.error_msg);
109 : return;
110 : #endif
111 : }
112 0 : alglib_impl::ae_state_set_break_jump(&_state, &_break_jump);
113 0 : p_struct = NULL;
114 0 : alglib_impl::ae_assert(rhs.p_struct!=NULL, "ALGLIB: kdtreerequestbuffer copy constructor failure (source is not initialized)", &_state);
115 0 : p_struct = (alglib_impl::kdtreerequestbuffer*)alglib_impl::ae_malloc(sizeof(alglib_impl::kdtreerequestbuffer), &_state);
116 0 : memset(p_struct, 0, sizeof(alglib_impl::kdtreerequestbuffer));
117 0 : alglib_impl::_kdtreerequestbuffer_init_copy(p_struct, const_cast<alglib_impl::kdtreerequestbuffer*>(rhs.p_struct), &_state, ae_false);
118 0 : ae_state_clear(&_state);
119 0 : }
120 :
121 0 : _kdtreerequestbuffer_owner& _kdtreerequestbuffer_owner::operator=(const _kdtreerequestbuffer_owner &rhs)
122 : {
123 0 : if( this==&rhs )
124 0 : return *this;
125 : jmp_buf _break_jump;
126 : alglib_impl::ae_state _state;
127 :
128 0 : alglib_impl::ae_state_init(&_state);
129 0 : if( setjmp(_break_jump) )
130 : {
131 : #if !defined(AE_NO_EXCEPTIONS)
132 0 : _ALGLIB_CPP_EXCEPTION(_state.error_msg);
133 : #else
134 : _ALGLIB_SET_ERROR_FLAG(_state.error_msg);
135 : return *this;
136 : #endif
137 : }
138 0 : alglib_impl::ae_state_set_break_jump(&_state, &_break_jump);
139 0 : alglib_impl::ae_assert(p_struct!=NULL, "ALGLIB: kdtreerequestbuffer assignment constructor failure (destination is not initialized)", &_state);
140 0 : alglib_impl::ae_assert(rhs.p_struct!=NULL, "ALGLIB: kdtreerequestbuffer assignment constructor failure (source is not initialized)", &_state);
141 0 : alglib_impl::_kdtreerequestbuffer_destroy(p_struct);
142 0 : memset(p_struct, 0, sizeof(alglib_impl::kdtreerequestbuffer));
143 0 : alglib_impl::_kdtreerequestbuffer_init_copy(p_struct, const_cast<alglib_impl::kdtreerequestbuffer*>(rhs.p_struct), &_state, ae_false);
144 0 : ae_state_clear(&_state);
145 0 : return *this;
146 : }
147 :
148 0 : _kdtreerequestbuffer_owner::~_kdtreerequestbuffer_owner()
149 : {
150 0 : if( p_struct!=NULL )
151 : {
152 0 : alglib_impl::_kdtreerequestbuffer_destroy(p_struct);
153 0 : ae_free(p_struct);
154 : }
155 0 : }
156 :
157 0 : alglib_impl::kdtreerequestbuffer* _kdtreerequestbuffer_owner::c_ptr()
158 : {
159 0 : return p_struct;
160 : }
161 :
162 0 : alglib_impl::kdtreerequestbuffer* _kdtreerequestbuffer_owner::c_ptr() const
163 : {
164 0 : return const_cast<alglib_impl::kdtreerequestbuffer*>(p_struct);
165 : }
166 0 : kdtreerequestbuffer::kdtreerequestbuffer() : _kdtreerequestbuffer_owner()
167 : {
168 0 : }
169 :
170 0 : kdtreerequestbuffer::kdtreerequestbuffer(const kdtreerequestbuffer &rhs):_kdtreerequestbuffer_owner(rhs)
171 : {
172 0 : }
173 :
174 0 : kdtreerequestbuffer& kdtreerequestbuffer::operator=(const kdtreerequestbuffer &rhs)
175 : {
176 0 : if( this==&rhs )
177 0 : return *this;
178 0 : _kdtreerequestbuffer_owner::operator=(rhs);
179 0 : return *this;
180 : }
181 :
182 0 : kdtreerequestbuffer::~kdtreerequestbuffer()
183 : {
184 0 : }
185 :
186 :
187 : /*************************************************************************
188 : KD-tree object.
189 : *************************************************************************/
190 0 : _kdtree_owner::_kdtree_owner()
191 : {
192 : jmp_buf _break_jump;
193 : alglib_impl::ae_state _state;
194 :
195 0 : alglib_impl::ae_state_init(&_state);
196 0 : if( setjmp(_break_jump) )
197 : {
198 0 : if( p_struct!=NULL )
199 : {
200 0 : alglib_impl::_kdtree_destroy(p_struct);
201 0 : alglib_impl::ae_free(p_struct);
202 : }
203 0 : p_struct = NULL;
204 : #if !defined(AE_NO_EXCEPTIONS)
205 0 : _ALGLIB_CPP_EXCEPTION(_state.error_msg);
206 : #else
207 : _ALGLIB_SET_ERROR_FLAG(_state.error_msg);
208 : return;
209 : #endif
210 : }
211 0 : alglib_impl::ae_state_set_break_jump(&_state, &_break_jump);
212 0 : p_struct = NULL;
213 0 : p_struct = (alglib_impl::kdtree*)alglib_impl::ae_malloc(sizeof(alglib_impl::kdtree), &_state);
214 0 : memset(p_struct, 0, sizeof(alglib_impl::kdtree));
215 0 : alglib_impl::_kdtree_init(p_struct, &_state, ae_false);
216 0 : ae_state_clear(&_state);
217 0 : }
218 :
219 0 : _kdtree_owner::_kdtree_owner(const _kdtree_owner &rhs)
220 : {
221 : jmp_buf _break_jump;
222 : alglib_impl::ae_state _state;
223 :
224 0 : alglib_impl::ae_state_init(&_state);
225 0 : if( setjmp(_break_jump) )
226 : {
227 0 : if( p_struct!=NULL )
228 : {
229 0 : alglib_impl::_kdtree_destroy(p_struct);
230 0 : alglib_impl::ae_free(p_struct);
231 : }
232 0 : p_struct = NULL;
233 : #if !defined(AE_NO_EXCEPTIONS)
234 0 : _ALGLIB_CPP_EXCEPTION(_state.error_msg);
235 : #else
236 : _ALGLIB_SET_ERROR_FLAG(_state.error_msg);
237 : return;
238 : #endif
239 : }
240 0 : alglib_impl::ae_state_set_break_jump(&_state, &_break_jump);
241 0 : p_struct = NULL;
242 0 : alglib_impl::ae_assert(rhs.p_struct!=NULL, "ALGLIB: kdtree copy constructor failure (source is not initialized)", &_state);
243 0 : p_struct = (alglib_impl::kdtree*)alglib_impl::ae_malloc(sizeof(alglib_impl::kdtree), &_state);
244 0 : memset(p_struct, 0, sizeof(alglib_impl::kdtree));
245 0 : alglib_impl::_kdtree_init_copy(p_struct, const_cast<alglib_impl::kdtree*>(rhs.p_struct), &_state, ae_false);
246 0 : ae_state_clear(&_state);
247 0 : }
248 :
249 0 : _kdtree_owner& _kdtree_owner::operator=(const _kdtree_owner &rhs)
250 : {
251 0 : if( this==&rhs )
252 0 : return *this;
253 : jmp_buf _break_jump;
254 : alglib_impl::ae_state _state;
255 :
256 0 : alglib_impl::ae_state_init(&_state);
257 0 : if( setjmp(_break_jump) )
258 : {
259 : #if !defined(AE_NO_EXCEPTIONS)
260 0 : _ALGLIB_CPP_EXCEPTION(_state.error_msg);
261 : #else
262 : _ALGLIB_SET_ERROR_FLAG(_state.error_msg);
263 : return *this;
264 : #endif
265 : }
266 0 : alglib_impl::ae_state_set_break_jump(&_state, &_break_jump);
267 0 : alglib_impl::ae_assert(p_struct!=NULL, "ALGLIB: kdtree assignment constructor failure (destination is not initialized)", &_state);
268 0 : alglib_impl::ae_assert(rhs.p_struct!=NULL, "ALGLIB: kdtree assignment constructor failure (source is not initialized)", &_state);
269 0 : alglib_impl::_kdtree_destroy(p_struct);
270 0 : memset(p_struct, 0, sizeof(alglib_impl::kdtree));
271 0 : alglib_impl::_kdtree_init_copy(p_struct, const_cast<alglib_impl::kdtree*>(rhs.p_struct), &_state, ae_false);
272 0 : ae_state_clear(&_state);
273 0 : return *this;
274 : }
275 :
276 0 : _kdtree_owner::~_kdtree_owner()
277 : {
278 0 : if( p_struct!=NULL )
279 : {
280 0 : alglib_impl::_kdtree_destroy(p_struct);
281 0 : ae_free(p_struct);
282 : }
283 0 : }
284 :
285 0 : alglib_impl::kdtree* _kdtree_owner::c_ptr()
286 : {
287 0 : return p_struct;
288 : }
289 :
290 0 : alglib_impl::kdtree* _kdtree_owner::c_ptr() const
291 : {
292 0 : return const_cast<alglib_impl::kdtree*>(p_struct);
293 : }
294 0 : kdtree::kdtree() : _kdtree_owner()
295 : {
296 0 : }
297 :
298 0 : kdtree::kdtree(const kdtree &rhs):_kdtree_owner(rhs)
299 : {
300 0 : }
301 :
302 0 : kdtree& kdtree::operator=(const kdtree &rhs)
303 : {
304 0 : if( this==&rhs )
305 0 : return *this;
306 0 : _kdtree_owner::operator=(rhs);
307 0 : return *this;
308 : }
309 :
310 0 : kdtree::~kdtree()
311 : {
312 0 : }
313 :
314 :
315 : /*************************************************************************
316 : This function serializes data structure to string.
317 :
318 : Important properties of s_out:
319 : * it contains alphanumeric characters, dots, underscores, minus signs
320 : * these symbols are grouped into words, which are separated by spaces
321 : and Windows-style (CR+LF) newlines
322 : * although serializer uses spaces and CR+LF as separators, you can
323 : replace any separator character by arbitrary combination of spaces,
324 : tabs, Windows or Unix newlines. It allows flexible reformatting of
325 : the string in case you want to include it into text or XML file.
326 : But you should not insert separators into the middle of the "words"
327 : nor you should change case of letters.
328 : * s_out can be freely moved between 32-bit and 64-bit systems, little
329 : and big endian machines, and so on. You can serialize structure on
330 : 32-bit machine and unserialize it on 64-bit one (or vice versa), or
331 : serialize it on SPARC and unserialize on x86. You can also
332 : serialize it in C++ version of ALGLIB and unserialize in C# one,
333 : and vice versa.
334 : *************************************************************************/
335 0 : void kdtreeserialize(kdtree &obj, std::string &s_out)
336 : {
337 : jmp_buf _break_jump;
338 : alglib_impl::ae_state state;
339 : alglib_impl::ae_serializer serializer;
340 : alglib_impl::ae_int_t ssize;
341 :
342 0 : alglib_impl::ae_state_init(&state);
343 0 : if( setjmp(_break_jump) )
344 : {
345 : #if !defined(AE_NO_EXCEPTIONS)
346 0 : _ALGLIB_CPP_EXCEPTION(state.error_msg);
347 : #else
348 : _ALGLIB_SET_ERROR_FLAG(state.error_msg);
349 : return;
350 : #endif
351 : }
352 0 : ae_state_set_break_jump(&state, &_break_jump);
353 0 : alglib_impl::ae_serializer_init(&serializer);
354 0 : alglib_impl::ae_serializer_alloc_start(&serializer);
355 0 : alglib_impl::kdtreealloc(&serializer, obj.c_ptr(), &state);
356 0 : ssize = alglib_impl::ae_serializer_get_alloc_size(&serializer);
357 0 : s_out.clear();
358 0 : s_out.reserve((size_t)(ssize+1));
359 0 : alglib_impl::ae_serializer_sstart_str(&serializer, &s_out);
360 0 : alglib_impl::kdtreeserialize(&serializer, obj.c_ptr(), &state);
361 0 : alglib_impl::ae_serializer_stop(&serializer, &state);
362 0 : alglib_impl::ae_assert( s_out.length()<=(size_t)ssize, "ALGLIB: serialization integrity error", &state);
363 0 : alglib_impl::ae_serializer_clear(&serializer);
364 0 : alglib_impl::ae_state_clear(&state);
365 0 : }
366 : /*************************************************************************
367 : This function unserializes data structure from string.
368 : *************************************************************************/
369 0 : void kdtreeunserialize(const std::string &s_in, kdtree &obj)
370 : {
371 : jmp_buf _break_jump;
372 : alglib_impl::ae_state state;
373 : alglib_impl::ae_serializer serializer;
374 :
375 0 : alglib_impl::ae_state_init(&state);
376 0 : if( setjmp(_break_jump) )
377 : {
378 : #if !defined(AE_NO_EXCEPTIONS)
379 0 : _ALGLIB_CPP_EXCEPTION(state.error_msg);
380 : #else
381 : _ALGLIB_SET_ERROR_FLAG(state.error_msg);
382 : return;
383 : #endif
384 : }
385 0 : ae_state_set_break_jump(&state, &_break_jump);
386 0 : alglib_impl::ae_serializer_init(&serializer);
387 0 : alglib_impl::ae_serializer_ustart_str(&serializer, &s_in);
388 0 : alglib_impl::kdtreeunserialize(&serializer, obj.c_ptr(), &state);
389 0 : alglib_impl::ae_serializer_stop(&serializer, &state);
390 0 : alglib_impl::ae_serializer_clear(&serializer);
391 0 : alglib_impl::ae_state_clear(&state);
392 0 : }
393 :
394 :
395 : /*************************************************************************
396 : This function serializes data structure to C++ stream.
397 :
398 : Data stream generated by this function is same as string representation
399 : generated by string version of serializer - alphanumeric characters,
400 : dots, underscores, minus signs, which are grouped into words separated by
401 : spaces and CR+LF.
402 :
403 : We recommend you to read comments on string version of serializer to find
404 : out more about serialization of AlGLIB objects.
405 : *************************************************************************/
406 0 : void kdtreeserialize(kdtree &obj, std::ostream &s_out)
407 : {
408 : jmp_buf _break_jump;
409 : alglib_impl::ae_state state;
410 : alglib_impl::ae_serializer serializer;
411 :
412 0 : alglib_impl::ae_state_init(&state);
413 0 : if( setjmp(_break_jump) )
414 : {
415 : #if !defined(AE_NO_EXCEPTIONS)
416 0 : _ALGLIB_CPP_EXCEPTION(state.error_msg);
417 : #else
418 : _ALGLIB_SET_ERROR_FLAG(state.error_msg);
419 : return;
420 : #endif
421 : }
422 0 : ae_state_set_break_jump(&state, &_break_jump);
423 0 : alglib_impl::ae_serializer_init(&serializer);
424 0 : alglib_impl::ae_serializer_alloc_start(&serializer);
425 0 : alglib_impl::kdtreealloc(&serializer, obj.c_ptr(), &state);
426 0 : alglib_impl::ae_serializer_get_alloc_size(&serializer); // not actually needed, but we have to ask
427 0 : alglib_impl::ae_serializer_sstart_stream(&serializer, &s_out);
428 0 : alglib_impl::kdtreeserialize(&serializer, obj.c_ptr(), &state);
429 0 : alglib_impl::ae_serializer_stop(&serializer, &state);
430 0 : alglib_impl::ae_serializer_clear(&serializer);
431 0 : alglib_impl::ae_state_clear(&state);
432 0 : }
433 : /*************************************************************************
434 : This function unserializes data structure from stream.
435 : *************************************************************************/
436 0 : void kdtreeunserialize(const std::istream &s_in, kdtree &obj)
437 : {
438 : jmp_buf _break_jump;
439 : alglib_impl::ae_state state;
440 : alglib_impl::ae_serializer serializer;
441 :
442 0 : alglib_impl::ae_state_init(&state);
443 0 : if( setjmp(_break_jump) )
444 : {
445 : #if !defined(AE_NO_EXCEPTIONS)
446 0 : _ALGLIB_CPP_EXCEPTION(state.error_msg);
447 : #else
448 : _ALGLIB_SET_ERROR_FLAG(state.error_msg);
449 : return;
450 : #endif
451 : }
452 0 : ae_state_set_break_jump(&state, &_break_jump);
453 0 : alglib_impl::ae_serializer_init(&serializer);
454 0 : alglib_impl::ae_serializer_ustart_stream(&serializer, &s_in);
455 0 : alglib_impl::kdtreeunserialize(&serializer, obj.c_ptr(), &state);
456 0 : alglib_impl::ae_serializer_stop(&serializer, &state);
457 0 : alglib_impl::ae_serializer_clear(&serializer);
458 0 : alglib_impl::ae_state_clear(&state);
459 0 : }
460 :
461 : /*************************************************************************
462 : KD-tree creation
463 :
464 : This subroutine creates KD-tree from set of X-values and optional Y-values
465 :
466 : INPUT PARAMETERS
467 : XY - dataset, array[0..N-1,0..NX+NY-1].
468 : one row corresponds to one point.
469 : first NX columns contain X-values, next NY (NY may be zero)
470 : columns may contain associated Y-values
471 : N - number of points, N>=0.
472 : NX - space dimension, NX>=1.
473 : NY - number of optional Y-values, NY>=0.
474 : NormType- norm type:
475 : * 0 denotes infinity-norm
476 : * 1 denotes 1-norm
477 : * 2 denotes 2-norm (Euclidean norm)
478 :
479 : OUTPUT PARAMETERS
480 : KDT - KD-tree
481 :
482 :
483 : NOTES
484 :
485 : 1. KD-tree creation have O(N*logN) complexity and O(N*(2*NX+NY)) memory
486 : requirements.
487 : 2. Although KD-trees may be used with any combination of N and NX, they
488 : are more efficient than brute-force search only when N >> 4^NX. So they
489 : are most useful in low-dimensional tasks (NX=2, NX=3). NX=1 is another
490 : inefficient case, because simple binary search (without additional
491 : structures) is much more efficient in such tasks than KD-trees.
492 :
493 : -- ALGLIB --
494 : Copyright 28.02.2010 by Bochkanov Sergey
495 : *************************************************************************/
496 0 : void kdtreebuild(const real_2d_array &xy, const ae_int_t n, const ae_int_t nx, const ae_int_t ny, const ae_int_t normtype, kdtree &kdt, const xparams _xparams)
497 : {
498 : jmp_buf _break_jump;
499 : alglib_impl::ae_state _alglib_env_state;
500 0 : alglib_impl::ae_state_init(&_alglib_env_state);
501 0 : if( setjmp(_break_jump) )
502 : {
503 : #if !defined(AE_NO_EXCEPTIONS)
504 0 : _ALGLIB_CPP_EXCEPTION(_alglib_env_state.error_msg);
505 : #else
506 : _ALGLIB_SET_ERROR_FLAG(_alglib_env_state.error_msg);
507 : return;
508 : #endif
509 : }
510 0 : ae_state_set_break_jump(&_alglib_env_state, &_break_jump);
511 0 : if( _xparams.flags!=0x0 )
512 0 : ae_state_set_flags(&_alglib_env_state, _xparams.flags);
513 0 : alglib_impl::kdtreebuild(const_cast<alglib_impl::ae_matrix*>(xy.c_ptr()), n, nx, ny, normtype, const_cast<alglib_impl::kdtree*>(kdt.c_ptr()), &_alglib_env_state);
514 0 : alglib_impl::ae_state_clear(&_alglib_env_state);
515 0 : return;
516 : }
517 :
518 : /*************************************************************************
519 : KD-tree creation
520 :
521 : This subroutine creates KD-tree from set of X-values and optional Y-values
522 :
523 : INPUT PARAMETERS
524 : XY - dataset, array[0..N-1,0..NX+NY-1].
525 : one row corresponds to one point.
526 : first NX columns contain X-values, next NY (NY may be zero)
527 : columns may contain associated Y-values
528 : N - number of points, N>=0.
529 : NX - space dimension, NX>=1.
530 : NY - number of optional Y-values, NY>=0.
531 : NormType- norm type:
532 : * 0 denotes infinity-norm
533 : * 1 denotes 1-norm
534 : * 2 denotes 2-norm (Euclidean norm)
535 :
536 : OUTPUT PARAMETERS
537 : KDT - KD-tree
538 :
539 :
540 : NOTES
541 :
542 : 1. KD-tree creation have O(N*logN) complexity and O(N*(2*NX+NY)) memory
543 : requirements.
544 : 2. Although KD-trees may be used with any combination of N and NX, they
545 : are more efficient than brute-force search only when N >> 4^NX. So they
546 : are most useful in low-dimensional tasks (NX=2, NX=3). NX=1 is another
547 : inefficient case, because simple binary search (without additional
548 : structures) is much more efficient in such tasks than KD-trees.
549 :
550 : -- ALGLIB --
551 : Copyright 28.02.2010 by Bochkanov Sergey
552 : *************************************************************************/
553 : #if !defined(AE_NO_EXCEPTIONS)
554 0 : void kdtreebuild(const real_2d_array &xy, const ae_int_t nx, const ae_int_t ny, const ae_int_t normtype, kdtree &kdt, const xparams _xparams)
555 : {
556 : jmp_buf _break_jump;
557 : alglib_impl::ae_state _alglib_env_state;
558 : ae_int_t n;
559 :
560 0 : n = xy.rows();
561 0 : alglib_impl::ae_state_init(&_alglib_env_state);
562 0 : if( setjmp(_break_jump) )
563 0 : _ALGLIB_CPP_EXCEPTION(_alglib_env_state.error_msg);
564 0 : ae_state_set_break_jump(&_alglib_env_state, &_break_jump);
565 0 : if( _xparams.flags!=0x0 )
566 0 : ae_state_set_flags(&_alglib_env_state, _xparams.flags);
567 0 : alglib_impl::kdtreebuild(const_cast<alglib_impl::ae_matrix*>(xy.c_ptr()), n, nx, ny, normtype, const_cast<alglib_impl::kdtree*>(kdt.c_ptr()), &_alglib_env_state);
568 :
569 0 : alglib_impl::ae_state_clear(&_alglib_env_state);
570 0 : return;
571 : }
572 : #endif
573 :
574 : /*************************************************************************
575 : KD-tree creation
576 :
577 : This subroutine creates KD-tree from set of X-values, integer tags and
578 : optional Y-values
579 :
580 : INPUT PARAMETERS
581 : XY - dataset, array[0..N-1,0..NX+NY-1].
582 : one row corresponds to one point.
583 : first NX columns contain X-values, next NY (NY may be zero)
584 : columns may contain associated Y-values
585 : Tags - tags, array[0..N-1], contains integer tags associated
586 : with points.
587 : N - number of points, N>=0
588 : NX - space dimension, NX>=1.
589 : NY - number of optional Y-values, NY>=0.
590 : NormType- norm type:
591 : * 0 denotes infinity-norm
592 : * 1 denotes 1-norm
593 : * 2 denotes 2-norm (Euclidean norm)
594 :
595 : OUTPUT PARAMETERS
596 : KDT - KD-tree
597 :
598 : NOTES
599 :
600 : 1. KD-tree creation have O(N*logN) complexity and O(N*(2*NX+NY)) memory
601 : requirements.
602 : 2. Although KD-trees may be used with any combination of N and NX, they
603 : are more efficient than brute-force search only when N >> 4^NX. So they
604 : are most useful in low-dimensional tasks (NX=2, NX=3). NX=1 is another
605 : inefficient case, because simple binary search (without additional
606 : structures) is much more efficient in such tasks than KD-trees.
607 :
608 : -- ALGLIB --
609 : Copyright 28.02.2010 by Bochkanov Sergey
610 : *************************************************************************/
611 0 : void kdtreebuildtagged(const real_2d_array &xy, const integer_1d_array &tags, const ae_int_t n, const ae_int_t nx, const ae_int_t ny, const ae_int_t normtype, kdtree &kdt, const xparams _xparams)
612 : {
613 : jmp_buf _break_jump;
614 : alglib_impl::ae_state _alglib_env_state;
615 0 : alglib_impl::ae_state_init(&_alglib_env_state);
616 0 : if( setjmp(_break_jump) )
617 : {
618 : #if !defined(AE_NO_EXCEPTIONS)
619 0 : _ALGLIB_CPP_EXCEPTION(_alglib_env_state.error_msg);
620 : #else
621 : _ALGLIB_SET_ERROR_FLAG(_alglib_env_state.error_msg);
622 : return;
623 : #endif
624 : }
625 0 : ae_state_set_break_jump(&_alglib_env_state, &_break_jump);
626 0 : if( _xparams.flags!=0x0 )
627 0 : ae_state_set_flags(&_alglib_env_state, _xparams.flags);
628 0 : alglib_impl::kdtreebuildtagged(const_cast<alglib_impl::ae_matrix*>(xy.c_ptr()), const_cast<alglib_impl::ae_vector*>(tags.c_ptr()), n, nx, ny, normtype, const_cast<alglib_impl::kdtree*>(kdt.c_ptr()), &_alglib_env_state);
629 0 : alglib_impl::ae_state_clear(&_alglib_env_state);
630 0 : return;
631 : }
632 :
633 : /*************************************************************************
634 : KD-tree creation
635 :
636 : This subroutine creates KD-tree from set of X-values, integer tags and
637 : optional Y-values
638 :
639 : INPUT PARAMETERS
640 : XY - dataset, array[0..N-1,0..NX+NY-1].
641 : one row corresponds to one point.
642 : first NX columns contain X-values, next NY (NY may be zero)
643 : columns may contain associated Y-values
644 : Tags - tags, array[0..N-1], contains integer tags associated
645 : with points.
646 : N - number of points, N>=0
647 : NX - space dimension, NX>=1.
648 : NY - number of optional Y-values, NY>=0.
649 : NormType- norm type:
650 : * 0 denotes infinity-norm
651 : * 1 denotes 1-norm
652 : * 2 denotes 2-norm (Euclidean norm)
653 :
654 : OUTPUT PARAMETERS
655 : KDT - KD-tree
656 :
657 : NOTES
658 :
659 : 1. KD-tree creation have O(N*logN) complexity and O(N*(2*NX+NY)) memory
660 : requirements.
661 : 2. Although KD-trees may be used with any combination of N and NX, they
662 : are more efficient than brute-force search only when N >> 4^NX. So they
663 : are most useful in low-dimensional tasks (NX=2, NX=3). NX=1 is another
664 : inefficient case, because simple binary search (without additional
665 : structures) is much more efficient in such tasks than KD-trees.
666 :
667 : -- ALGLIB --
668 : Copyright 28.02.2010 by Bochkanov Sergey
669 : *************************************************************************/
670 : #if !defined(AE_NO_EXCEPTIONS)
671 0 : void kdtreebuildtagged(const real_2d_array &xy, const integer_1d_array &tags, const ae_int_t nx, const ae_int_t ny, const ae_int_t normtype, kdtree &kdt, const xparams _xparams)
672 : {
673 : jmp_buf _break_jump;
674 : alglib_impl::ae_state _alglib_env_state;
675 : ae_int_t n;
676 0 : if( (xy.rows()!=tags.length()))
677 0 : _ALGLIB_CPP_EXCEPTION("Error while calling 'kdtreebuildtagged': looks like one of arguments has wrong size");
678 0 : n = xy.rows();
679 0 : alglib_impl::ae_state_init(&_alglib_env_state);
680 0 : if( setjmp(_break_jump) )
681 0 : _ALGLIB_CPP_EXCEPTION(_alglib_env_state.error_msg);
682 0 : ae_state_set_break_jump(&_alglib_env_state, &_break_jump);
683 0 : if( _xparams.flags!=0x0 )
684 0 : ae_state_set_flags(&_alglib_env_state, _xparams.flags);
685 0 : alglib_impl::kdtreebuildtagged(const_cast<alglib_impl::ae_matrix*>(xy.c_ptr()), const_cast<alglib_impl::ae_vector*>(tags.c_ptr()), n, nx, ny, normtype, const_cast<alglib_impl::kdtree*>(kdt.c_ptr()), &_alglib_env_state);
686 :
687 0 : alglib_impl::ae_state_clear(&_alglib_env_state);
688 0 : return;
689 : }
690 : #endif
691 :
692 : /*************************************************************************
693 : This function creates buffer structure which can be used to perform
694 : parallel KD-tree requests.
695 :
696 : KD-tree subpackage provides two sets of request functions - ones which use
697 : internal buffer of KD-tree object (these functions are single-threaded
698 : because they use same buffer, which can not shared between threads), and
699 : ones which use external buffer.
700 :
701 : This function is used to initialize external buffer.
702 :
703 : INPUT PARAMETERS
704 : KDT - KD-tree which is associated with newly created buffer
705 :
706 : OUTPUT PARAMETERS
707 : Buf - external buffer.
708 :
709 :
710 : IMPORTANT: KD-tree buffer should be used only with KD-tree object which
711 : was used to initialize buffer. Any attempt to use buffer with
712 : different object is dangerous - you may get integrity check
713 : failure (exception) because sizes of internal arrays do not fit
714 : to dimensions of KD-tree structure.
715 :
716 : -- ALGLIB --
717 : Copyright 18.03.2016 by Bochkanov Sergey
718 : *************************************************************************/
719 0 : void kdtreecreaterequestbuffer(const kdtree &kdt, kdtreerequestbuffer &buf, const xparams _xparams)
720 : {
721 : jmp_buf _break_jump;
722 : alglib_impl::ae_state _alglib_env_state;
723 0 : alglib_impl::ae_state_init(&_alglib_env_state);
724 0 : if( setjmp(_break_jump) )
725 : {
726 : #if !defined(AE_NO_EXCEPTIONS)
727 0 : _ALGLIB_CPP_EXCEPTION(_alglib_env_state.error_msg);
728 : #else
729 : _ALGLIB_SET_ERROR_FLAG(_alglib_env_state.error_msg);
730 : return;
731 : #endif
732 : }
733 0 : ae_state_set_break_jump(&_alglib_env_state, &_break_jump);
734 0 : if( _xparams.flags!=0x0 )
735 0 : ae_state_set_flags(&_alglib_env_state, _xparams.flags);
736 0 : alglib_impl::kdtreecreaterequestbuffer(const_cast<alglib_impl::kdtree*>(kdt.c_ptr()), const_cast<alglib_impl::kdtreerequestbuffer*>(buf.c_ptr()), &_alglib_env_state);
737 0 : alglib_impl::ae_state_clear(&_alglib_env_state);
738 0 : return;
739 : }
740 :
741 : /*************************************************************************
742 : K-NN query: K nearest neighbors
743 :
744 : IMPORTANT: this function can not be used in multithreaded code because it
745 : uses internal temporary buffer of kd-tree object, which can not
746 : be shared between multiple threads. If you want to perform
747 : parallel requests, use function which uses external request
748 : buffer: KDTreeTsQueryKNN() ("Ts" stands for "thread-safe").
749 :
750 : INPUT PARAMETERS
751 : KDT - KD-tree
752 : X - point, array[0..NX-1].
753 : K - number of neighbors to return, K>=1
754 : SelfMatch - whether self-matches are allowed:
755 : * if True, nearest neighbor may be the point itself
756 : (if it exists in original dataset)
757 : * if False, then only points with non-zero distance
758 : are returned
759 : * if not given, considered True
760 :
761 : RESULT
762 : number of actual neighbors found (either K or N, if K>N).
763 :
764 : This subroutine performs query and stores its result in the internal
765 : structures of the KD-tree. You can use following subroutines to obtain
766 : these results:
767 : * KDTreeQueryResultsX() to get X-values
768 : * KDTreeQueryResultsXY() to get X- and Y-values
769 : * KDTreeQueryResultsTags() to get tag values
770 : * KDTreeQueryResultsDistances() to get distances
771 :
772 : -- ALGLIB --
773 : Copyright 28.02.2010 by Bochkanov Sergey
774 : *************************************************************************/
775 0 : ae_int_t kdtreequeryknn(const kdtree &kdt, const real_1d_array &x, const ae_int_t k, const bool selfmatch, const xparams _xparams)
776 : {
777 : jmp_buf _break_jump;
778 : alglib_impl::ae_state _alglib_env_state;
779 0 : alglib_impl::ae_state_init(&_alglib_env_state);
780 0 : if( setjmp(_break_jump) )
781 : {
782 : #if !defined(AE_NO_EXCEPTIONS)
783 0 : _ALGLIB_CPP_EXCEPTION(_alglib_env_state.error_msg);
784 : #else
785 : _ALGLIB_SET_ERROR_FLAG(_alglib_env_state.error_msg);
786 : return 0;
787 : #endif
788 : }
789 0 : ae_state_set_break_jump(&_alglib_env_state, &_break_jump);
790 0 : if( _xparams.flags!=0x0 )
791 0 : ae_state_set_flags(&_alglib_env_state, _xparams.flags);
792 0 : alglib_impl::ae_int_t result = alglib_impl::kdtreequeryknn(const_cast<alglib_impl::kdtree*>(kdt.c_ptr()), const_cast<alglib_impl::ae_vector*>(x.c_ptr()), k, selfmatch, &_alglib_env_state);
793 0 : alglib_impl::ae_state_clear(&_alglib_env_state);
794 0 : return *(reinterpret_cast<ae_int_t*>(&result));
795 : }
796 :
797 : /*************************************************************************
798 : K-NN query: K nearest neighbors
799 :
800 : IMPORTANT: this function can not be used in multithreaded code because it
801 : uses internal temporary buffer of kd-tree object, which can not
802 : be shared between multiple threads. If you want to perform
803 : parallel requests, use function which uses external request
804 : buffer: KDTreeTsQueryKNN() ("Ts" stands for "thread-safe").
805 :
806 : INPUT PARAMETERS
807 : KDT - KD-tree
808 : X - point, array[0..NX-1].
809 : K - number of neighbors to return, K>=1
810 : SelfMatch - whether self-matches are allowed:
811 : * if True, nearest neighbor may be the point itself
812 : (if it exists in original dataset)
813 : * if False, then only points with non-zero distance
814 : are returned
815 : * if not given, considered True
816 :
817 : RESULT
818 : number of actual neighbors found (either K or N, if K>N).
819 :
820 : This subroutine performs query and stores its result in the internal
821 : structures of the KD-tree. You can use following subroutines to obtain
822 : these results:
823 : * KDTreeQueryResultsX() to get X-values
824 : * KDTreeQueryResultsXY() to get X- and Y-values
825 : * KDTreeQueryResultsTags() to get tag values
826 : * KDTreeQueryResultsDistances() to get distances
827 :
828 : -- ALGLIB --
829 : Copyright 28.02.2010 by Bochkanov Sergey
830 : *************************************************************************/
831 : #if !defined(AE_NO_EXCEPTIONS)
832 0 : ae_int_t kdtreequeryknn(const kdtree &kdt, const real_1d_array &x, const ae_int_t k, const xparams _xparams)
833 : {
834 : jmp_buf _break_jump;
835 : alglib_impl::ae_state _alglib_env_state;
836 : bool selfmatch;
837 :
838 0 : selfmatch = true;
839 0 : alglib_impl::ae_state_init(&_alglib_env_state);
840 0 : if( setjmp(_break_jump) )
841 0 : _ALGLIB_CPP_EXCEPTION(_alglib_env_state.error_msg);
842 0 : ae_state_set_break_jump(&_alglib_env_state, &_break_jump);
843 0 : if( _xparams.flags!=0x0 )
844 0 : ae_state_set_flags(&_alglib_env_state, _xparams.flags);
845 0 : alglib_impl::ae_int_t result = alglib_impl::kdtreequeryknn(const_cast<alglib_impl::kdtree*>(kdt.c_ptr()), const_cast<alglib_impl::ae_vector*>(x.c_ptr()), k, selfmatch, &_alglib_env_state);
846 :
847 0 : alglib_impl::ae_state_clear(&_alglib_env_state);
848 0 : return *(reinterpret_cast<ae_int_t*>(&result));
849 : }
850 : #endif
851 :
852 : /*************************************************************************
853 : K-NN query: K nearest neighbors, using external thread-local buffer.
854 :
855 : You can call this function from multiple threads for same kd-tree instance,
856 : assuming that different instances of buffer object are passed to different
857 : threads.
858 :
859 : INPUT PARAMETERS
860 : KDT - kd-tree
861 : Buf - request buffer object created for this particular
862 : instance of kd-tree structure with kdtreecreaterequestbuffer()
863 : function.
864 : X - point, array[0..NX-1].
865 : K - number of neighbors to return, K>=1
866 : SelfMatch - whether self-matches are allowed:
867 : * if True, nearest neighbor may be the point itself
868 : (if it exists in original dataset)
869 : * if False, then only points with non-zero distance
870 : are returned
871 : * if not given, considered True
872 :
873 : RESULT
874 : number of actual neighbors found (either K or N, if K>N).
875 :
876 : This subroutine performs query and stores its result in the internal
877 : structures of the buffer object. You can use following subroutines to
878 : obtain these results (pay attention to "buf" in their names):
879 : * KDTreeTsQueryResultsX() to get X-values
880 : * KDTreeTsQueryResultsXY() to get X- and Y-values
881 : * KDTreeTsQueryResultsTags() to get tag values
882 : * KDTreeTsQueryResultsDistances() to get distances
883 :
884 : IMPORTANT: kd-tree buffer should be used only with KD-tree object which
885 : was used to initialize buffer. Any attempt to use biffer with
886 : different object is dangerous - you may get integrity check
887 : failure (exception) because sizes of internal arrays do not fit
888 : to dimensions of KD-tree structure.
889 :
890 : -- ALGLIB --
891 : Copyright 18.03.2016 by Bochkanov Sergey
892 : *************************************************************************/
893 0 : ae_int_t kdtreetsqueryknn(const kdtree &kdt, const kdtreerequestbuffer &buf, const real_1d_array &x, const ae_int_t k, const bool selfmatch, const xparams _xparams)
894 : {
895 : jmp_buf _break_jump;
896 : alglib_impl::ae_state _alglib_env_state;
897 0 : alglib_impl::ae_state_init(&_alglib_env_state);
898 0 : if( setjmp(_break_jump) )
899 : {
900 : #if !defined(AE_NO_EXCEPTIONS)
901 0 : _ALGLIB_CPP_EXCEPTION(_alglib_env_state.error_msg);
902 : #else
903 : _ALGLIB_SET_ERROR_FLAG(_alglib_env_state.error_msg);
904 : return 0;
905 : #endif
906 : }
907 0 : ae_state_set_break_jump(&_alglib_env_state, &_break_jump);
908 0 : if( _xparams.flags!=0x0 )
909 0 : ae_state_set_flags(&_alglib_env_state, _xparams.flags);
910 0 : alglib_impl::ae_int_t result = alglib_impl::kdtreetsqueryknn(const_cast<alglib_impl::kdtree*>(kdt.c_ptr()), const_cast<alglib_impl::kdtreerequestbuffer*>(buf.c_ptr()), const_cast<alglib_impl::ae_vector*>(x.c_ptr()), k, selfmatch, &_alglib_env_state);
911 0 : alglib_impl::ae_state_clear(&_alglib_env_state);
912 0 : return *(reinterpret_cast<ae_int_t*>(&result));
913 : }
914 :
915 : /*************************************************************************
916 : K-NN query: K nearest neighbors, using external thread-local buffer.
917 :
918 : You can call this function from multiple threads for same kd-tree instance,
919 : assuming that different instances of buffer object are passed to different
920 : threads.
921 :
922 : INPUT PARAMETERS
923 : KDT - kd-tree
924 : Buf - request buffer object created for this particular
925 : instance of kd-tree structure with kdtreecreaterequestbuffer()
926 : function.
927 : X - point, array[0..NX-1].
928 : K - number of neighbors to return, K>=1
929 : SelfMatch - whether self-matches are allowed:
930 : * if True, nearest neighbor may be the point itself
931 : (if it exists in original dataset)
932 : * if False, then only points with non-zero distance
933 : are returned
934 : * if not given, considered True
935 :
936 : RESULT
937 : number of actual neighbors found (either K or N, if K>N).
938 :
939 : This subroutine performs query and stores its result in the internal
940 : structures of the buffer object. You can use following subroutines to
941 : obtain these results (pay attention to "buf" in their names):
942 : * KDTreeTsQueryResultsX() to get X-values
943 : * KDTreeTsQueryResultsXY() to get X- and Y-values
944 : * KDTreeTsQueryResultsTags() to get tag values
945 : * KDTreeTsQueryResultsDistances() to get distances
946 :
947 : IMPORTANT: kd-tree buffer should be used only with KD-tree object which
948 : was used to initialize buffer. Any attempt to use biffer with
949 : different object is dangerous - you may get integrity check
950 : failure (exception) because sizes of internal arrays do not fit
951 : to dimensions of KD-tree structure.
952 :
953 : -- ALGLIB --
954 : Copyright 18.03.2016 by Bochkanov Sergey
955 : *************************************************************************/
956 : #if !defined(AE_NO_EXCEPTIONS)
957 0 : ae_int_t kdtreetsqueryknn(const kdtree &kdt, const kdtreerequestbuffer &buf, const real_1d_array &x, const ae_int_t k, const xparams _xparams)
958 : {
959 : jmp_buf _break_jump;
960 : alglib_impl::ae_state _alglib_env_state;
961 : bool selfmatch;
962 :
963 0 : selfmatch = true;
964 0 : alglib_impl::ae_state_init(&_alglib_env_state);
965 0 : if( setjmp(_break_jump) )
966 0 : _ALGLIB_CPP_EXCEPTION(_alglib_env_state.error_msg);
967 0 : ae_state_set_break_jump(&_alglib_env_state, &_break_jump);
968 0 : if( _xparams.flags!=0x0 )
969 0 : ae_state_set_flags(&_alglib_env_state, _xparams.flags);
970 0 : alglib_impl::ae_int_t result = alglib_impl::kdtreetsqueryknn(const_cast<alglib_impl::kdtree*>(kdt.c_ptr()), const_cast<alglib_impl::kdtreerequestbuffer*>(buf.c_ptr()), const_cast<alglib_impl::ae_vector*>(x.c_ptr()), k, selfmatch, &_alglib_env_state);
971 :
972 0 : alglib_impl::ae_state_clear(&_alglib_env_state);
973 0 : return *(reinterpret_cast<ae_int_t*>(&result));
974 : }
975 : #endif
976 :
977 : /*************************************************************************
978 : R-NN query: all points within R-sphere centered at X, ordered by distance
979 : between point and X (by ascending).
980 :
981 : NOTE: it is also possible to perform undordered queries performed by means
982 : of kdtreequeryrnnu() and kdtreetsqueryrnnu() functions. Such queries
983 : are faster because we do not have to use heap structure for sorting.
984 :
985 : IMPORTANT: this function can not be used in multithreaded code because it
986 : uses internal temporary buffer of kd-tree object, which can not
987 : be shared between multiple threads. If you want to perform
988 : parallel requests, use function which uses external request
989 : buffer: kdtreetsqueryrnn() ("Ts" stands for "thread-safe").
990 :
991 : INPUT PARAMETERS
992 : KDT - KD-tree
993 : X - point, array[0..NX-1].
994 : R - radius of sphere (in corresponding norm), R>0
995 : SelfMatch - whether self-matches are allowed:
996 : * if True, nearest neighbor may be the point itself
997 : (if it exists in original dataset)
998 : * if False, then only points with non-zero distance
999 : are returned
1000 : * if not given, considered True
1001 :
1002 : RESULT
1003 : number of neighbors found, >=0
1004 :
1005 : This subroutine performs query and stores its result in the internal
1006 : structures of the KD-tree. You can use following subroutines to obtain
1007 : actual results:
1008 : * KDTreeQueryResultsX() to get X-values
1009 : * KDTreeQueryResultsXY() to get X- and Y-values
1010 : * KDTreeQueryResultsTags() to get tag values
1011 : * KDTreeQueryResultsDistances() to get distances
1012 :
1013 : -- ALGLIB --
1014 : Copyright 28.02.2010 by Bochkanov Sergey
1015 : *************************************************************************/
1016 0 : ae_int_t kdtreequeryrnn(const kdtree &kdt, const real_1d_array &x, const double r, const bool selfmatch, const xparams _xparams)
1017 : {
1018 : jmp_buf _break_jump;
1019 : alglib_impl::ae_state _alglib_env_state;
1020 0 : alglib_impl::ae_state_init(&_alglib_env_state);
1021 0 : if( setjmp(_break_jump) )
1022 : {
1023 : #if !defined(AE_NO_EXCEPTIONS)
1024 0 : _ALGLIB_CPP_EXCEPTION(_alglib_env_state.error_msg);
1025 : #else
1026 : _ALGLIB_SET_ERROR_FLAG(_alglib_env_state.error_msg);
1027 : return 0;
1028 : #endif
1029 : }
1030 0 : ae_state_set_break_jump(&_alglib_env_state, &_break_jump);
1031 0 : if( _xparams.flags!=0x0 )
1032 0 : ae_state_set_flags(&_alglib_env_state, _xparams.flags);
1033 0 : alglib_impl::ae_int_t result = alglib_impl::kdtreequeryrnn(const_cast<alglib_impl::kdtree*>(kdt.c_ptr()), const_cast<alglib_impl::ae_vector*>(x.c_ptr()), r, selfmatch, &_alglib_env_state);
1034 0 : alglib_impl::ae_state_clear(&_alglib_env_state);
1035 0 : return *(reinterpret_cast<ae_int_t*>(&result));
1036 : }
1037 :
1038 : /*************************************************************************
1039 : R-NN query: all points within R-sphere centered at X, ordered by distance
1040 : between point and X (by ascending).
1041 :
1042 : NOTE: it is also possible to perform undordered queries performed by means
1043 : of kdtreequeryrnnu() and kdtreetsqueryrnnu() functions. Such queries
1044 : are faster because we do not have to use heap structure for sorting.
1045 :
1046 : IMPORTANT: this function can not be used in multithreaded code because it
1047 : uses internal temporary buffer of kd-tree object, which can not
1048 : be shared between multiple threads. If you want to perform
1049 : parallel requests, use function which uses external request
1050 : buffer: kdtreetsqueryrnn() ("Ts" stands for "thread-safe").
1051 :
1052 : INPUT PARAMETERS
1053 : KDT - KD-tree
1054 : X - point, array[0..NX-1].
1055 : R - radius of sphere (in corresponding norm), R>0
1056 : SelfMatch - whether self-matches are allowed:
1057 : * if True, nearest neighbor may be the point itself
1058 : (if it exists in original dataset)
1059 : * if False, then only points with non-zero distance
1060 : are returned
1061 : * if not given, considered True
1062 :
1063 : RESULT
1064 : number of neighbors found, >=0
1065 :
1066 : This subroutine performs query and stores its result in the internal
1067 : structures of the KD-tree. You can use following subroutines to obtain
1068 : actual results:
1069 : * KDTreeQueryResultsX() to get X-values
1070 : * KDTreeQueryResultsXY() to get X- and Y-values
1071 : * KDTreeQueryResultsTags() to get tag values
1072 : * KDTreeQueryResultsDistances() to get distances
1073 :
1074 : -- ALGLIB --
1075 : Copyright 28.02.2010 by Bochkanov Sergey
1076 : *************************************************************************/
1077 : #if !defined(AE_NO_EXCEPTIONS)
1078 0 : ae_int_t kdtreequeryrnn(const kdtree &kdt, const real_1d_array &x, const double r, const xparams _xparams)
1079 : {
1080 : jmp_buf _break_jump;
1081 : alglib_impl::ae_state _alglib_env_state;
1082 : bool selfmatch;
1083 :
1084 0 : selfmatch = true;
1085 0 : alglib_impl::ae_state_init(&_alglib_env_state);
1086 0 : if( setjmp(_break_jump) )
1087 0 : _ALGLIB_CPP_EXCEPTION(_alglib_env_state.error_msg);
1088 0 : ae_state_set_break_jump(&_alglib_env_state, &_break_jump);
1089 0 : if( _xparams.flags!=0x0 )
1090 0 : ae_state_set_flags(&_alglib_env_state, _xparams.flags);
1091 0 : alglib_impl::ae_int_t result = alglib_impl::kdtreequeryrnn(const_cast<alglib_impl::kdtree*>(kdt.c_ptr()), const_cast<alglib_impl::ae_vector*>(x.c_ptr()), r, selfmatch, &_alglib_env_state);
1092 :
1093 0 : alglib_impl::ae_state_clear(&_alglib_env_state);
1094 0 : return *(reinterpret_cast<ae_int_t*>(&result));
1095 : }
1096 : #endif
1097 :
1098 : /*************************************************************************
1099 : R-NN query: all points within R-sphere centered at X, no ordering by
1100 : distance as undicated by "U" suffix (faster that ordered query, for large
1101 : queries - significantly faster).
1102 :
1103 : IMPORTANT: this function can not be used in multithreaded code because it
1104 : uses internal temporary buffer of kd-tree object, which can not
1105 : be shared between multiple threads. If you want to perform
1106 : parallel requests, use function which uses external request
1107 : buffer: kdtreetsqueryrnn() ("Ts" stands for "thread-safe").
1108 :
1109 : INPUT PARAMETERS
1110 : KDT - KD-tree
1111 : X - point, array[0..NX-1].
1112 : R - radius of sphere (in corresponding norm), R>0
1113 : SelfMatch - whether self-matches are allowed:
1114 : * if True, nearest neighbor may be the point itself
1115 : (if it exists in original dataset)
1116 : * if False, then only points with non-zero distance
1117 : are returned
1118 : * if not given, considered True
1119 :
1120 : RESULT
1121 : number of neighbors found, >=0
1122 :
1123 : This subroutine performs query and stores its result in the internal
1124 : structures of the KD-tree. You can use following subroutines to obtain
1125 : actual results:
1126 : * KDTreeQueryResultsX() to get X-values
1127 : * KDTreeQueryResultsXY() to get X- and Y-values
1128 : * KDTreeQueryResultsTags() to get tag values
1129 : * KDTreeQueryResultsDistances() to get distances
1130 :
1131 : As indicated by "U" suffix, this function returns unordered results.
1132 :
1133 : -- ALGLIB --
1134 : Copyright 01.11.2018 by Bochkanov Sergey
1135 : *************************************************************************/
1136 0 : ae_int_t kdtreequeryrnnu(const kdtree &kdt, const real_1d_array &x, const double r, const bool selfmatch, const xparams _xparams)
1137 : {
1138 : jmp_buf _break_jump;
1139 : alglib_impl::ae_state _alglib_env_state;
1140 0 : alglib_impl::ae_state_init(&_alglib_env_state);
1141 0 : if( setjmp(_break_jump) )
1142 : {
1143 : #if !defined(AE_NO_EXCEPTIONS)
1144 0 : _ALGLIB_CPP_EXCEPTION(_alglib_env_state.error_msg);
1145 : #else
1146 : _ALGLIB_SET_ERROR_FLAG(_alglib_env_state.error_msg);
1147 : return 0;
1148 : #endif
1149 : }
1150 0 : ae_state_set_break_jump(&_alglib_env_state, &_break_jump);
1151 0 : if( _xparams.flags!=0x0 )
1152 0 : ae_state_set_flags(&_alglib_env_state, _xparams.flags);
1153 0 : alglib_impl::ae_int_t result = alglib_impl::kdtreequeryrnnu(const_cast<alglib_impl::kdtree*>(kdt.c_ptr()), const_cast<alglib_impl::ae_vector*>(x.c_ptr()), r, selfmatch, &_alglib_env_state);
1154 0 : alglib_impl::ae_state_clear(&_alglib_env_state);
1155 0 : return *(reinterpret_cast<ae_int_t*>(&result));
1156 : }
1157 :
1158 : /*************************************************************************
1159 : R-NN query: all points within R-sphere centered at X, no ordering by
1160 : distance as undicated by "U" suffix (faster that ordered query, for large
1161 : queries - significantly faster).
1162 :
1163 : IMPORTANT: this function can not be used in multithreaded code because it
1164 : uses internal temporary buffer of kd-tree object, which can not
1165 : be shared between multiple threads. If you want to perform
1166 : parallel requests, use function which uses external request
1167 : buffer: kdtreetsqueryrnn() ("Ts" stands for "thread-safe").
1168 :
1169 : INPUT PARAMETERS
1170 : KDT - KD-tree
1171 : X - point, array[0..NX-1].
1172 : R - radius of sphere (in corresponding norm), R>0
1173 : SelfMatch - whether self-matches are allowed:
1174 : * if True, nearest neighbor may be the point itself
1175 : (if it exists in original dataset)
1176 : * if False, then only points with non-zero distance
1177 : are returned
1178 : * if not given, considered True
1179 :
1180 : RESULT
1181 : number of neighbors found, >=0
1182 :
1183 : This subroutine performs query and stores its result in the internal
1184 : structures of the KD-tree. You can use following subroutines to obtain
1185 : actual results:
1186 : * KDTreeQueryResultsX() to get X-values
1187 : * KDTreeQueryResultsXY() to get X- and Y-values
1188 : * KDTreeQueryResultsTags() to get tag values
1189 : * KDTreeQueryResultsDistances() to get distances
1190 :
1191 : As indicated by "U" suffix, this function returns unordered results.
1192 :
1193 : -- ALGLIB --
1194 : Copyright 01.11.2018 by Bochkanov Sergey
1195 : *************************************************************************/
1196 : #if !defined(AE_NO_EXCEPTIONS)
1197 0 : ae_int_t kdtreequeryrnnu(const kdtree &kdt, const real_1d_array &x, const double r, const xparams _xparams)
1198 : {
1199 : jmp_buf _break_jump;
1200 : alglib_impl::ae_state _alglib_env_state;
1201 : bool selfmatch;
1202 :
1203 0 : selfmatch = true;
1204 0 : alglib_impl::ae_state_init(&_alglib_env_state);
1205 0 : if( setjmp(_break_jump) )
1206 0 : _ALGLIB_CPP_EXCEPTION(_alglib_env_state.error_msg);
1207 0 : ae_state_set_break_jump(&_alglib_env_state, &_break_jump);
1208 0 : if( _xparams.flags!=0x0 )
1209 0 : ae_state_set_flags(&_alglib_env_state, _xparams.flags);
1210 0 : alglib_impl::ae_int_t result = alglib_impl::kdtreequeryrnnu(const_cast<alglib_impl::kdtree*>(kdt.c_ptr()), const_cast<alglib_impl::ae_vector*>(x.c_ptr()), r, selfmatch, &_alglib_env_state);
1211 :
1212 0 : alglib_impl::ae_state_clear(&_alglib_env_state);
1213 0 : return *(reinterpret_cast<ae_int_t*>(&result));
1214 : }
1215 : #endif
1216 :
1217 : /*************************************************************************
1218 : R-NN query: all points within R-sphere centered at X, using external
1219 : thread-local buffer, sorted by distance between point and X (by ascending)
1220 :
1221 : You can call this function from multiple threads for same kd-tree instance,
1222 : assuming that different instances of buffer object are passed to different
1223 : threads.
1224 :
1225 : NOTE: it is also possible to perform undordered queries performed by means
1226 : of kdtreequeryrnnu() and kdtreetsqueryrnnu() functions. Such queries
1227 : are faster because we do not have to use heap structure for sorting.
1228 :
1229 : INPUT PARAMETERS
1230 : KDT - KD-tree
1231 : Buf - request buffer object created for this particular
1232 : instance of kd-tree structure with kdtreecreaterequestbuffer()
1233 : function.
1234 : X - point, array[0..NX-1].
1235 : R - radius of sphere (in corresponding norm), R>0
1236 : SelfMatch - whether self-matches are allowed:
1237 : * if True, nearest neighbor may be the point itself
1238 : (if it exists in original dataset)
1239 : * if False, then only points with non-zero distance
1240 : are returned
1241 : * if not given, considered True
1242 :
1243 : RESULT
1244 : number of neighbors found, >=0
1245 :
1246 : This subroutine performs query and stores its result in the internal
1247 : structures of the buffer object. You can use following subroutines to
1248 : obtain these results (pay attention to "buf" in their names):
1249 : * KDTreeTsQueryResultsX() to get X-values
1250 : * KDTreeTsQueryResultsXY() to get X- and Y-values
1251 : * KDTreeTsQueryResultsTags() to get tag values
1252 : * KDTreeTsQueryResultsDistances() to get distances
1253 :
1254 : IMPORTANT: kd-tree buffer should be used only with KD-tree object which
1255 : was used to initialize buffer. Any attempt to use biffer with
1256 : different object is dangerous - you may get integrity check
1257 : failure (exception) because sizes of internal arrays do not fit
1258 : to dimensions of KD-tree structure.
1259 :
1260 : -- ALGLIB --
1261 : Copyright 18.03.2016 by Bochkanov Sergey
1262 : *************************************************************************/
1263 0 : ae_int_t kdtreetsqueryrnn(const kdtree &kdt, const kdtreerequestbuffer &buf, const real_1d_array &x, const double r, const bool selfmatch, const xparams _xparams)
1264 : {
1265 : jmp_buf _break_jump;
1266 : alglib_impl::ae_state _alglib_env_state;
1267 0 : alglib_impl::ae_state_init(&_alglib_env_state);
1268 0 : if( setjmp(_break_jump) )
1269 : {
1270 : #if !defined(AE_NO_EXCEPTIONS)
1271 0 : _ALGLIB_CPP_EXCEPTION(_alglib_env_state.error_msg);
1272 : #else
1273 : _ALGLIB_SET_ERROR_FLAG(_alglib_env_state.error_msg);
1274 : return 0;
1275 : #endif
1276 : }
1277 0 : ae_state_set_break_jump(&_alglib_env_state, &_break_jump);
1278 0 : if( _xparams.flags!=0x0 )
1279 0 : ae_state_set_flags(&_alglib_env_state, _xparams.flags);
1280 0 : alglib_impl::ae_int_t result = alglib_impl::kdtreetsqueryrnn(const_cast<alglib_impl::kdtree*>(kdt.c_ptr()), const_cast<alglib_impl::kdtreerequestbuffer*>(buf.c_ptr()), const_cast<alglib_impl::ae_vector*>(x.c_ptr()), r, selfmatch, &_alglib_env_state);
1281 0 : alglib_impl::ae_state_clear(&_alglib_env_state);
1282 0 : return *(reinterpret_cast<ae_int_t*>(&result));
1283 : }
1284 :
1285 : /*************************************************************************
1286 : R-NN query: all points within R-sphere centered at X, using external
1287 : thread-local buffer, sorted by distance between point and X (by ascending)
1288 :
1289 : You can call this function from multiple threads for same kd-tree instance,
1290 : assuming that different instances of buffer object are passed to different
1291 : threads.
1292 :
1293 : NOTE: it is also possible to perform undordered queries performed by means
1294 : of kdtreequeryrnnu() and kdtreetsqueryrnnu() functions. Such queries
1295 : are faster because we do not have to use heap structure for sorting.
1296 :
1297 : INPUT PARAMETERS
1298 : KDT - KD-tree
1299 : Buf - request buffer object created for this particular
1300 : instance of kd-tree structure with kdtreecreaterequestbuffer()
1301 : function.
1302 : X - point, array[0..NX-1].
1303 : R - radius of sphere (in corresponding norm), R>0
1304 : SelfMatch - whether self-matches are allowed:
1305 : * if True, nearest neighbor may be the point itself
1306 : (if it exists in original dataset)
1307 : * if False, then only points with non-zero distance
1308 : are returned
1309 : * if not given, considered True
1310 :
1311 : RESULT
1312 : number of neighbors found, >=0
1313 :
1314 : This subroutine performs query and stores its result in the internal
1315 : structures of the buffer object. You can use following subroutines to
1316 : obtain these results (pay attention to "buf" in their names):
1317 : * KDTreeTsQueryResultsX() to get X-values
1318 : * KDTreeTsQueryResultsXY() to get X- and Y-values
1319 : * KDTreeTsQueryResultsTags() to get tag values
1320 : * KDTreeTsQueryResultsDistances() to get distances
1321 :
1322 : IMPORTANT: kd-tree buffer should be used only with KD-tree object which
1323 : was used to initialize buffer. Any attempt to use biffer with
1324 : different object is dangerous - you may get integrity check
1325 : failure (exception) because sizes of internal arrays do not fit
1326 : to dimensions of KD-tree structure.
1327 :
1328 : -- ALGLIB --
1329 : Copyright 18.03.2016 by Bochkanov Sergey
1330 : *************************************************************************/
1331 : #if !defined(AE_NO_EXCEPTIONS)
1332 0 : ae_int_t kdtreetsqueryrnn(const kdtree &kdt, const kdtreerequestbuffer &buf, const real_1d_array &x, const double r, const xparams _xparams)
1333 : {
1334 : jmp_buf _break_jump;
1335 : alglib_impl::ae_state _alglib_env_state;
1336 : bool selfmatch;
1337 :
1338 0 : selfmatch = true;
1339 0 : alglib_impl::ae_state_init(&_alglib_env_state);
1340 0 : if( setjmp(_break_jump) )
1341 0 : _ALGLIB_CPP_EXCEPTION(_alglib_env_state.error_msg);
1342 0 : ae_state_set_break_jump(&_alglib_env_state, &_break_jump);
1343 0 : if( _xparams.flags!=0x0 )
1344 0 : ae_state_set_flags(&_alglib_env_state, _xparams.flags);
1345 0 : alglib_impl::ae_int_t result = alglib_impl::kdtreetsqueryrnn(const_cast<alglib_impl::kdtree*>(kdt.c_ptr()), const_cast<alglib_impl::kdtreerequestbuffer*>(buf.c_ptr()), const_cast<alglib_impl::ae_vector*>(x.c_ptr()), r, selfmatch, &_alglib_env_state);
1346 :
1347 0 : alglib_impl::ae_state_clear(&_alglib_env_state);
1348 0 : return *(reinterpret_cast<ae_int_t*>(&result));
1349 : }
1350 : #endif
1351 :
1352 : /*************************************************************************
1353 : R-NN query: all points within R-sphere centered at X, using external
1354 : thread-local buffer, no ordering by distance as undicated by "U" suffix
1355 : (faster that ordered query, for large queries - significantly faster).
1356 :
1357 : You can call this function from multiple threads for same kd-tree instance,
1358 : assuming that different instances of buffer object are passed to different
1359 : threads.
1360 :
1361 : INPUT PARAMETERS
1362 : KDT - KD-tree
1363 : Buf - request buffer object created for this particular
1364 : instance of kd-tree structure with kdtreecreaterequestbuffer()
1365 : function.
1366 : X - point, array[0..NX-1].
1367 : R - radius of sphere (in corresponding norm), R>0
1368 : SelfMatch - whether self-matches are allowed:
1369 : * if True, nearest neighbor may be the point itself
1370 : (if it exists in original dataset)
1371 : * if False, then only points with non-zero distance
1372 : are returned
1373 : * if not given, considered True
1374 :
1375 : RESULT
1376 : number of neighbors found, >=0
1377 :
1378 : This subroutine performs query and stores its result in the internal
1379 : structures of the buffer object. You can use following subroutines to
1380 : obtain these results (pay attention to "buf" in their names):
1381 : * KDTreeTsQueryResultsX() to get X-values
1382 : * KDTreeTsQueryResultsXY() to get X- and Y-values
1383 : * KDTreeTsQueryResultsTags() to get tag values
1384 : * KDTreeTsQueryResultsDistances() to get distances
1385 :
1386 : As indicated by "U" suffix, this function returns unordered results.
1387 :
1388 : IMPORTANT: kd-tree buffer should be used only with KD-tree object which
1389 : was used to initialize buffer. Any attempt to use biffer with
1390 : different object is dangerous - you may get integrity check
1391 : failure (exception) because sizes of internal arrays do not fit
1392 : to dimensions of KD-tree structure.
1393 :
1394 : -- ALGLIB --
1395 : Copyright 18.03.2016 by Bochkanov Sergey
1396 : *************************************************************************/
1397 0 : ae_int_t kdtreetsqueryrnnu(const kdtree &kdt, const kdtreerequestbuffer &buf, const real_1d_array &x, const double r, const bool selfmatch, const xparams _xparams)
1398 : {
1399 : jmp_buf _break_jump;
1400 : alglib_impl::ae_state _alglib_env_state;
1401 0 : alglib_impl::ae_state_init(&_alglib_env_state);
1402 0 : if( setjmp(_break_jump) )
1403 : {
1404 : #if !defined(AE_NO_EXCEPTIONS)
1405 0 : _ALGLIB_CPP_EXCEPTION(_alglib_env_state.error_msg);
1406 : #else
1407 : _ALGLIB_SET_ERROR_FLAG(_alglib_env_state.error_msg);
1408 : return 0;
1409 : #endif
1410 : }
1411 0 : ae_state_set_break_jump(&_alglib_env_state, &_break_jump);
1412 0 : if( _xparams.flags!=0x0 )
1413 0 : ae_state_set_flags(&_alglib_env_state, _xparams.flags);
1414 0 : alglib_impl::ae_int_t result = alglib_impl::kdtreetsqueryrnnu(const_cast<alglib_impl::kdtree*>(kdt.c_ptr()), const_cast<alglib_impl::kdtreerequestbuffer*>(buf.c_ptr()), const_cast<alglib_impl::ae_vector*>(x.c_ptr()), r, selfmatch, &_alglib_env_state);
1415 0 : alglib_impl::ae_state_clear(&_alglib_env_state);
1416 0 : return *(reinterpret_cast<ae_int_t*>(&result));
1417 : }
1418 :
1419 : /*************************************************************************
1420 : R-NN query: all points within R-sphere centered at X, using external
1421 : thread-local buffer, no ordering by distance as undicated by "U" suffix
1422 : (faster that ordered query, for large queries - significantly faster).
1423 :
1424 : You can call this function from multiple threads for same kd-tree instance,
1425 : assuming that different instances of buffer object are passed to different
1426 : threads.
1427 :
1428 : INPUT PARAMETERS
1429 : KDT - KD-tree
1430 : Buf - request buffer object created for this particular
1431 : instance of kd-tree structure with kdtreecreaterequestbuffer()
1432 : function.
1433 : X - point, array[0..NX-1].
1434 : R - radius of sphere (in corresponding norm), R>0
1435 : SelfMatch - whether self-matches are allowed:
1436 : * if True, nearest neighbor may be the point itself
1437 : (if it exists in original dataset)
1438 : * if False, then only points with non-zero distance
1439 : are returned
1440 : * if not given, considered True
1441 :
1442 : RESULT
1443 : number of neighbors found, >=0
1444 :
1445 : This subroutine performs query and stores its result in the internal
1446 : structures of the buffer object. You can use following subroutines to
1447 : obtain these results (pay attention to "buf" in their names):
1448 : * KDTreeTsQueryResultsX() to get X-values
1449 : * KDTreeTsQueryResultsXY() to get X- and Y-values
1450 : * KDTreeTsQueryResultsTags() to get tag values
1451 : * KDTreeTsQueryResultsDistances() to get distances
1452 :
1453 : As indicated by "U" suffix, this function returns unordered results.
1454 :
1455 : IMPORTANT: kd-tree buffer should be used only with KD-tree object which
1456 : was used to initialize buffer. Any attempt to use biffer with
1457 : different object is dangerous - you may get integrity check
1458 : failure (exception) because sizes of internal arrays do not fit
1459 : to dimensions of KD-tree structure.
1460 :
1461 : -- ALGLIB --
1462 : Copyright 18.03.2016 by Bochkanov Sergey
1463 : *************************************************************************/
1464 : #if !defined(AE_NO_EXCEPTIONS)
1465 0 : ae_int_t kdtreetsqueryrnnu(const kdtree &kdt, const kdtreerequestbuffer &buf, const real_1d_array &x, const double r, const xparams _xparams)
1466 : {
1467 : jmp_buf _break_jump;
1468 : alglib_impl::ae_state _alglib_env_state;
1469 : bool selfmatch;
1470 :
1471 0 : selfmatch = true;
1472 0 : alglib_impl::ae_state_init(&_alglib_env_state);
1473 0 : if( setjmp(_break_jump) )
1474 0 : _ALGLIB_CPP_EXCEPTION(_alglib_env_state.error_msg);
1475 0 : ae_state_set_break_jump(&_alglib_env_state, &_break_jump);
1476 0 : if( _xparams.flags!=0x0 )
1477 0 : ae_state_set_flags(&_alglib_env_state, _xparams.flags);
1478 0 : alglib_impl::ae_int_t result = alglib_impl::kdtreetsqueryrnnu(const_cast<alglib_impl::kdtree*>(kdt.c_ptr()), const_cast<alglib_impl::kdtreerequestbuffer*>(buf.c_ptr()), const_cast<alglib_impl::ae_vector*>(x.c_ptr()), r, selfmatch, &_alglib_env_state);
1479 :
1480 0 : alglib_impl::ae_state_clear(&_alglib_env_state);
1481 0 : return *(reinterpret_cast<ae_int_t*>(&result));
1482 : }
1483 : #endif
1484 :
1485 : /*************************************************************************
1486 : K-NN query: approximate K nearest neighbors
1487 :
1488 : IMPORTANT: this function can not be used in multithreaded code because it
1489 : uses internal temporary buffer of kd-tree object, which can not
1490 : be shared between multiple threads. If you want to perform
1491 : parallel requests, use function which uses external request
1492 : buffer: KDTreeTsQueryAKNN() ("Ts" stands for "thread-safe").
1493 :
1494 : INPUT PARAMETERS
1495 : KDT - KD-tree
1496 : X - point, array[0..NX-1].
1497 : K - number of neighbors to return, K>=1
1498 : SelfMatch - whether self-matches are allowed:
1499 : * if True, nearest neighbor may be the point itself
1500 : (if it exists in original dataset)
1501 : * if False, then only points with non-zero distance
1502 : are returned
1503 : * if not given, considered True
1504 : Eps - approximation factor, Eps>=0. eps-approximate nearest
1505 : neighbor is a neighbor whose distance from X is at
1506 : most (1+eps) times distance of true nearest neighbor.
1507 :
1508 : RESULT
1509 : number of actual neighbors found (either K or N, if K>N).
1510 :
1511 : NOTES
1512 : significant performance gain may be achieved only when Eps is is on
1513 : the order of magnitude of 1 or larger.
1514 :
1515 : This subroutine performs query and stores its result in the internal
1516 : structures of the KD-tree. You can use following subroutines to obtain
1517 : these results:
1518 : * KDTreeQueryResultsX() to get X-values
1519 : * KDTreeQueryResultsXY() to get X- and Y-values
1520 : * KDTreeQueryResultsTags() to get tag values
1521 : * KDTreeQueryResultsDistances() to get distances
1522 :
1523 : -- ALGLIB --
1524 : Copyright 28.02.2010 by Bochkanov Sergey
1525 : *************************************************************************/
1526 0 : ae_int_t kdtreequeryaknn(const kdtree &kdt, const real_1d_array &x, const ae_int_t k, const bool selfmatch, const double eps, const xparams _xparams)
1527 : {
1528 : jmp_buf _break_jump;
1529 : alglib_impl::ae_state _alglib_env_state;
1530 0 : alglib_impl::ae_state_init(&_alglib_env_state);
1531 0 : if( setjmp(_break_jump) )
1532 : {
1533 : #if !defined(AE_NO_EXCEPTIONS)
1534 0 : _ALGLIB_CPP_EXCEPTION(_alglib_env_state.error_msg);
1535 : #else
1536 : _ALGLIB_SET_ERROR_FLAG(_alglib_env_state.error_msg);
1537 : return 0;
1538 : #endif
1539 : }
1540 0 : ae_state_set_break_jump(&_alglib_env_state, &_break_jump);
1541 0 : if( _xparams.flags!=0x0 )
1542 0 : ae_state_set_flags(&_alglib_env_state, _xparams.flags);
1543 0 : alglib_impl::ae_int_t result = alglib_impl::kdtreequeryaknn(const_cast<alglib_impl::kdtree*>(kdt.c_ptr()), const_cast<alglib_impl::ae_vector*>(x.c_ptr()), k, selfmatch, eps, &_alglib_env_state);
1544 0 : alglib_impl::ae_state_clear(&_alglib_env_state);
1545 0 : return *(reinterpret_cast<ae_int_t*>(&result));
1546 : }
1547 :
1548 : /*************************************************************************
1549 : K-NN query: approximate K nearest neighbors
1550 :
1551 : IMPORTANT: this function can not be used in multithreaded code because it
1552 : uses internal temporary buffer of kd-tree object, which can not
1553 : be shared between multiple threads. If you want to perform
1554 : parallel requests, use function which uses external request
1555 : buffer: KDTreeTsQueryAKNN() ("Ts" stands for "thread-safe").
1556 :
1557 : INPUT PARAMETERS
1558 : KDT - KD-tree
1559 : X - point, array[0..NX-1].
1560 : K - number of neighbors to return, K>=1
1561 : SelfMatch - whether self-matches are allowed:
1562 : * if True, nearest neighbor may be the point itself
1563 : (if it exists in original dataset)
1564 : * if False, then only points with non-zero distance
1565 : are returned
1566 : * if not given, considered True
1567 : Eps - approximation factor, Eps>=0. eps-approximate nearest
1568 : neighbor is a neighbor whose distance from X is at
1569 : most (1+eps) times distance of true nearest neighbor.
1570 :
1571 : RESULT
1572 : number of actual neighbors found (either K or N, if K>N).
1573 :
1574 : NOTES
1575 : significant performance gain may be achieved only when Eps is is on
1576 : the order of magnitude of 1 or larger.
1577 :
1578 : This subroutine performs query and stores its result in the internal
1579 : structures of the KD-tree. You can use following subroutines to obtain
1580 : these results:
1581 : * KDTreeQueryResultsX() to get X-values
1582 : * KDTreeQueryResultsXY() to get X- and Y-values
1583 : * KDTreeQueryResultsTags() to get tag values
1584 : * KDTreeQueryResultsDistances() to get distances
1585 :
1586 : -- ALGLIB --
1587 : Copyright 28.02.2010 by Bochkanov Sergey
1588 : *************************************************************************/
1589 : #if !defined(AE_NO_EXCEPTIONS)
1590 0 : ae_int_t kdtreequeryaknn(const kdtree &kdt, const real_1d_array &x, const ae_int_t k, const double eps, const xparams _xparams)
1591 : {
1592 : jmp_buf _break_jump;
1593 : alglib_impl::ae_state _alglib_env_state;
1594 : bool selfmatch;
1595 :
1596 0 : selfmatch = true;
1597 0 : alglib_impl::ae_state_init(&_alglib_env_state);
1598 0 : if( setjmp(_break_jump) )
1599 0 : _ALGLIB_CPP_EXCEPTION(_alglib_env_state.error_msg);
1600 0 : ae_state_set_break_jump(&_alglib_env_state, &_break_jump);
1601 0 : if( _xparams.flags!=0x0 )
1602 0 : ae_state_set_flags(&_alglib_env_state, _xparams.flags);
1603 0 : alglib_impl::ae_int_t result = alglib_impl::kdtreequeryaknn(const_cast<alglib_impl::kdtree*>(kdt.c_ptr()), const_cast<alglib_impl::ae_vector*>(x.c_ptr()), k, selfmatch, eps, &_alglib_env_state);
1604 :
1605 0 : alglib_impl::ae_state_clear(&_alglib_env_state);
1606 0 : return *(reinterpret_cast<ae_int_t*>(&result));
1607 : }
1608 : #endif
1609 :
1610 : /*************************************************************************
1611 : K-NN query: approximate K nearest neighbors, using thread-local buffer.
1612 :
1613 : You can call this function from multiple threads for same kd-tree instance,
1614 : assuming that different instances of buffer object are passed to different
1615 : threads.
1616 :
1617 : INPUT PARAMETERS
1618 : KDT - KD-tree
1619 : Buf - request buffer object created for this particular
1620 : instance of kd-tree structure with kdtreecreaterequestbuffer()
1621 : function.
1622 : X - point, array[0..NX-1].
1623 : K - number of neighbors to return, K>=1
1624 : SelfMatch - whether self-matches are allowed:
1625 : * if True, nearest neighbor may be the point itself
1626 : (if it exists in original dataset)
1627 : * if False, then only points with non-zero distance
1628 : are returned
1629 : * if not given, considered True
1630 : Eps - approximation factor, Eps>=0. eps-approximate nearest
1631 : neighbor is a neighbor whose distance from X is at
1632 : most (1+eps) times distance of true nearest neighbor.
1633 :
1634 : RESULT
1635 : number of actual neighbors found (either K or N, if K>N).
1636 :
1637 : NOTES
1638 : significant performance gain may be achieved only when Eps is is on
1639 : the order of magnitude of 1 or larger.
1640 :
1641 : This subroutine performs query and stores its result in the internal
1642 : structures of the buffer object. You can use following subroutines to
1643 : obtain these results (pay attention to "buf" in their names):
1644 : * KDTreeTsQueryResultsX() to get X-values
1645 : * KDTreeTsQueryResultsXY() to get X- and Y-values
1646 : * KDTreeTsQueryResultsTags() to get tag values
1647 : * KDTreeTsQueryResultsDistances() to get distances
1648 :
1649 : IMPORTANT: kd-tree buffer should be used only with KD-tree object which
1650 : was used to initialize buffer. Any attempt to use biffer with
1651 : different object is dangerous - you may get integrity check
1652 : failure (exception) because sizes of internal arrays do not fit
1653 : to dimensions of KD-tree structure.
1654 :
1655 : -- ALGLIB --
1656 : Copyright 18.03.2016 by Bochkanov Sergey
1657 : *************************************************************************/
1658 0 : ae_int_t kdtreetsqueryaknn(const kdtree &kdt, const kdtreerequestbuffer &buf, const real_1d_array &x, const ae_int_t k, const bool selfmatch, const double eps, const xparams _xparams)
1659 : {
1660 : jmp_buf _break_jump;
1661 : alglib_impl::ae_state _alglib_env_state;
1662 0 : alglib_impl::ae_state_init(&_alglib_env_state);
1663 0 : if( setjmp(_break_jump) )
1664 : {
1665 : #if !defined(AE_NO_EXCEPTIONS)
1666 0 : _ALGLIB_CPP_EXCEPTION(_alglib_env_state.error_msg);
1667 : #else
1668 : _ALGLIB_SET_ERROR_FLAG(_alglib_env_state.error_msg);
1669 : return 0;
1670 : #endif
1671 : }
1672 0 : ae_state_set_break_jump(&_alglib_env_state, &_break_jump);
1673 0 : if( _xparams.flags!=0x0 )
1674 0 : ae_state_set_flags(&_alglib_env_state, _xparams.flags);
1675 0 : alglib_impl::ae_int_t result = alglib_impl::kdtreetsqueryaknn(const_cast<alglib_impl::kdtree*>(kdt.c_ptr()), const_cast<alglib_impl::kdtreerequestbuffer*>(buf.c_ptr()), const_cast<alglib_impl::ae_vector*>(x.c_ptr()), k, selfmatch, eps, &_alglib_env_state);
1676 0 : alglib_impl::ae_state_clear(&_alglib_env_state);
1677 0 : return *(reinterpret_cast<ae_int_t*>(&result));
1678 : }
1679 :
1680 : /*************************************************************************
1681 : K-NN query: approximate K nearest neighbors, using thread-local buffer.
1682 :
1683 : You can call this function from multiple threads for same kd-tree instance,
1684 : assuming that different instances of buffer object are passed to different
1685 : threads.
1686 :
1687 : INPUT PARAMETERS
1688 : KDT - KD-tree
1689 : Buf - request buffer object created for this particular
1690 : instance of kd-tree structure with kdtreecreaterequestbuffer()
1691 : function.
1692 : X - point, array[0..NX-1].
1693 : K - number of neighbors to return, K>=1
1694 : SelfMatch - whether self-matches are allowed:
1695 : * if True, nearest neighbor may be the point itself
1696 : (if it exists in original dataset)
1697 : * if False, then only points with non-zero distance
1698 : are returned
1699 : * if not given, considered True
1700 : Eps - approximation factor, Eps>=0. eps-approximate nearest
1701 : neighbor is a neighbor whose distance from X is at
1702 : most (1+eps) times distance of true nearest neighbor.
1703 :
1704 : RESULT
1705 : number of actual neighbors found (either K or N, if K>N).
1706 :
1707 : NOTES
1708 : significant performance gain may be achieved only when Eps is is on
1709 : the order of magnitude of 1 or larger.
1710 :
1711 : This subroutine performs query and stores its result in the internal
1712 : structures of the buffer object. You can use following subroutines to
1713 : obtain these results (pay attention to "buf" in their names):
1714 : * KDTreeTsQueryResultsX() to get X-values
1715 : * KDTreeTsQueryResultsXY() to get X- and Y-values
1716 : * KDTreeTsQueryResultsTags() to get tag values
1717 : * KDTreeTsQueryResultsDistances() to get distances
1718 :
1719 : IMPORTANT: kd-tree buffer should be used only with KD-tree object which
1720 : was used to initialize buffer. Any attempt to use biffer with
1721 : different object is dangerous - you may get integrity check
1722 : failure (exception) because sizes of internal arrays do not fit
1723 : to dimensions of KD-tree structure.
1724 :
1725 : -- ALGLIB --
1726 : Copyright 18.03.2016 by Bochkanov Sergey
1727 : *************************************************************************/
1728 : #if !defined(AE_NO_EXCEPTIONS)
1729 0 : ae_int_t kdtreetsqueryaknn(const kdtree &kdt, const kdtreerequestbuffer &buf, const real_1d_array &x, const ae_int_t k, const double eps, const xparams _xparams)
1730 : {
1731 : jmp_buf _break_jump;
1732 : alglib_impl::ae_state _alglib_env_state;
1733 : bool selfmatch;
1734 :
1735 0 : selfmatch = true;
1736 0 : alglib_impl::ae_state_init(&_alglib_env_state);
1737 0 : if( setjmp(_break_jump) )
1738 0 : _ALGLIB_CPP_EXCEPTION(_alglib_env_state.error_msg);
1739 0 : ae_state_set_break_jump(&_alglib_env_state, &_break_jump);
1740 0 : if( _xparams.flags!=0x0 )
1741 0 : ae_state_set_flags(&_alglib_env_state, _xparams.flags);
1742 0 : alglib_impl::ae_int_t result = alglib_impl::kdtreetsqueryaknn(const_cast<alglib_impl::kdtree*>(kdt.c_ptr()), const_cast<alglib_impl::kdtreerequestbuffer*>(buf.c_ptr()), const_cast<alglib_impl::ae_vector*>(x.c_ptr()), k, selfmatch, eps, &_alglib_env_state);
1743 :
1744 0 : alglib_impl::ae_state_clear(&_alglib_env_state);
1745 0 : return *(reinterpret_cast<ae_int_t*>(&result));
1746 : }
1747 : #endif
1748 :
1749 : /*************************************************************************
1750 : Box query: all points within user-specified box.
1751 :
1752 : IMPORTANT: this function can not be used in multithreaded code because it
1753 : uses internal temporary buffer of kd-tree object, which can not
1754 : be shared between multiple threads. If you want to perform
1755 : parallel requests, use function which uses external request
1756 : buffer: KDTreeTsQueryBox() ("Ts" stands for "thread-safe").
1757 :
1758 : INPUT PARAMETERS
1759 : KDT - KD-tree
1760 : BoxMin - lower bounds, array[0..NX-1].
1761 : BoxMax - upper bounds, array[0..NX-1].
1762 :
1763 :
1764 : RESULT
1765 : number of actual neighbors found (in [0,N]).
1766 :
1767 : This subroutine performs query and stores its result in the internal
1768 : structures of the KD-tree. You can use following subroutines to obtain
1769 : these results:
1770 : * KDTreeQueryResultsX() to get X-values
1771 : * KDTreeQueryResultsXY() to get X- and Y-values
1772 : * KDTreeQueryResultsTags() to get tag values
1773 : * KDTreeQueryResultsDistances() returns zeros for this request
1774 :
1775 : NOTE: this particular query returns unordered results, because there is no
1776 : meaningful way of ordering points. Furthermore, no 'distance' is
1777 : associated with points - it is either INSIDE or OUTSIDE (so request
1778 : for distances will return zeros).
1779 :
1780 : -- ALGLIB --
1781 : Copyright 14.05.2016 by Bochkanov Sergey
1782 : *************************************************************************/
1783 0 : ae_int_t kdtreequerybox(const kdtree &kdt, const real_1d_array &boxmin, const real_1d_array &boxmax, const xparams _xparams)
1784 : {
1785 : jmp_buf _break_jump;
1786 : alglib_impl::ae_state _alglib_env_state;
1787 0 : alglib_impl::ae_state_init(&_alglib_env_state);
1788 0 : if( setjmp(_break_jump) )
1789 : {
1790 : #if !defined(AE_NO_EXCEPTIONS)
1791 0 : _ALGLIB_CPP_EXCEPTION(_alglib_env_state.error_msg);
1792 : #else
1793 : _ALGLIB_SET_ERROR_FLAG(_alglib_env_state.error_msg);
1794 : return 0;
1795 : #endif
1796 : }
1797 0 : ae_state_set_break_jump(&_alglib_env_state, &_break_jump);
1798 0 : if( _xparams.flags!=0x0 )
1799 0 : ae_state_set_flags(&_alglib_env_state, _xparams.flags);
1800 0 : alglib_impl::ae_int_t result = alglib_impl::kdtreequerybox(const_cast<alglib_impl::kdtree*>(kdt.c_ptr()), const_cast<alglib_impl::ae_vector*>(boxmin.c_ptr()), const_cast<alglib_impl::ae_vector*>(boxmax.c_ptr()), &_alglib_env_state);
1801 0 : alglib_impl::ae_state_clear(&_alglib_env_state);
1802 0 : return *(reinterpret_cast<ae_int_t*>(&result));
1803 : }
1804 :
1805 : /*************************************************************************
1806 : Box query: all points within user-specified box, using thread-local buffer.
1807 :
1808 : You can call this function from multiple threads for same kd-tree instance,
1809 : assuming that different instances of buffer object are passed to different
1810 : threads.
1811 :
1812 : INPUT PARAMETERS
1813 : KDT - KD-tree
1814 : Buf - request buffer object created for this particular
1815 : instance of kd-tree structure with kdtreecreaterequestbuffer()
1816 : function.
1817 : BoxMin - lower bounds, array[0..NX-1].
1818 : BoxMax - upper bounds, array[0..NX-1].
1819 :
1820 : RESULT
1821 : number of actual neighbors found (in [0,N]).
1822 :
1823 : This subroutine performs query and stores its result in the internal
1824 : structures of the buffer object. You can use following subroutines to
1825 : obtain these results (pay attention to "ts" in their names):
1826 : * KDTreeTsQueryResultsX() to get X-values
1827 : * KDTreeTsQueryResultsXY() to get X- and Y-values
1828 : * KDTreeTsQueryResultsTags() to get tag values
1829 : * KDTreeTsQueryResultsDistances() returns zeros for this query
1830 :
1831 : NOTE: this particular query returns unordered results, because there is no
1832 : meaningful way of ordering points. Furthermore, no 'distance' is
1833 : associated with points - it is either INSIDE or OUTSIDE (so request
1834 : for distances will return zeros).
1835 :
1836 : IMPORTANT: kd-tree buffer should be used only with KD-tree object which
1837 : was used to initialize buffer. Any attempt to use biffer with
1838 : different object is dangerous - you may get integrity check
1839 : failure (exception) because sizes of internal arrays do not fit
1840 : to dimensions of KD-tree structure.
1841 :
1842 : -- ALGLIB --
1843 : Copyright 14.05.2016 by Bochkanov Sergey
1844 : *************************************************************************/
1845 0 : ae_int_t kdtreetsquerybox(const kdtree &kdt, const kdtreerequestbuffer &buf, const real_1d_array &boxmin, const real_1d_array &boxmax, const xparams _xparams)
1846 : {
1847 : jmp_buf _break_jump;
1848 : alglib_impl::ae_state _alglib_env_state;
1849 0 : alglib_impl::ae_state_init(&_alglib_env_state);
1850 0 : if( setjmp(_break_jump) )
1851 : {
1852 : #if !defined(AE_NO_EXCEPTIONS)
1853 0 : _ALGLIB_CPP_EXCEPTION(_alglib_env_state.error_msg);
1854 : #else
1855 : _ALGLIB_SET_ERROR_FLAG(_alglib_env_state.error_msg);
1856 : return 0;
1857 : #endif
1858 : }
1859 0 : ae_state_set_break_jump(&_alglib_env_state, &_break_jump);
1860 0 : if( _xparams.flags!=0x0 )
1861 0 : ae_state_set_flags(&_alglib_env_state, _xparams.flags);
1862 0 : alglib_impl::ae_int_t result = alglib_impl::kdtreetsquerybox(const_cast<alglib_impl::kdtree*>(kdt.c_ptr()), const_cast<alglib_impl::kdtreerequestbuffer*>(buf.c_ptr()), const_cast<alglib_impl::ae_vector*>(boxmin.c_ptr()), const_cast<alglib_impl::ae_vector*>(boxmax.c_ptr()), &_alglib_env_state);
1863 0 : alglib_impl::ae_state_clear(&_alglib_env_state);
1864 0 : return *(reinterpret_cast<ae_int_t*>(&result));
1865 : }
1866 :
1867 : /*************************************************************************
1868 : X-values from last query.
1869 :
1870 : This function retuns results stored in the internal buffer of kd-tree
1871 : object. If you performed buffered requests (ones which use instances of
1872 : kdtreerequestbuffer class), you should call buffered version of this
1873 : function - kdtreetsqueryresultsx().
1874 :
1875 : INPUT PARAMETERS
1876 : KDT - KD-tree
1877 : X - possibly pre-allocated buffer. If X is too small to store
1878 : result, it is resized. If size(X) is enough to store
1879 : result, it is left unchanged.
1880 :
1881 : OUTPUT PARAMETERS
1882 : X - rows are filled with X-values
1883 :
1884 : NOTES
1885 : 1. points are ordered by distance from the query point (first = closest)
1886 : 2. if XY is larger than required to store result, only leading part will
1887 : be overwritten; trailing part will be left unchanged. So if on input
1888 : XY = [[A,B],[C,D]], and result is [1,2], then on exit we will get
1889 : XY = [[1,2],[C,D]]. This is done purposely to increase performance; if
1890 : you want function to resize array according to result size, use
1891 : function with same name and suffix 'I'.
1892 :
1893 : SEE ALSO
1894 : * KDTreeQueryResultsXY() X- and Y-values
1895 : * KDTreeQueryResultsTags() tag values
1896 : * KDTreeQueryResultsDistances() distances
1897 :
1898 : -- ALGLIB --
1899 : Copyright 28.02.2010 by Bochkanov Sergey
1900 : *************************************************************************/
1901 0 : void kdtreequeryresultsx(const kdtree &kdt, real_2d_array &x, const xparams _xparams)
1902 : {
1903 : jmp_buf _break_jump;
1904 : alglib_impl::ae_state _alglib_env_state;
1905 0 : alglib_impl::ae_state_init(&_alglib_env_state);
1906 0 : if( setjmp(_break_jump) )
1907 : {
1908 : #if !defined(AE_NO_EXCEPTIONS)
1909 0 : _ALGLIB_CPP_EXCEPTION(_alglib_env_state.error_msg);
1910 : #else
1911 : _ALGLIB_SET_ERROR_FLAG(_alglib_env_state.error_msg);
1912 : return;
1913 : #endif
1914 : }
1915 0 : ae_state_set_break_jump(&_alglib_env_state, &_break_jump);
1916 0 : if( _xparams.flags!=0x0 )
1917 0 : ae_state_set_flags(&_alglib_env_state, _xparams.flags);
1918 0 : alglib_impl::kdtreequeryresultsx(const_cast<alglib_impl::kdtree*>(kdt.c_ptr()), const_cast<alglib_impl::ae_matrix*>(x.c_ptr()), &_alglib_env_state);
1919 0 : alglib_impl::ae_state_clear(&_alglib_env_state);
1920 0 : return;
1921 : }
1922 :
1923 : /*************************************************************************
1924 : X- and Y-values from last query
1925 :
1926 : This function retuns results stored in the internal buffer of kd-tree
1927 : object. If you performed buffered requests (ones which use instances of
1928 : kdtreerequestbuffer class), you should call buffered version of this
1929 : function - kdtreetsqueryresultsxy().
1930 :
1931 : INPUT PARAMETERS
1932 : KDT - KD-tree
1933 : XY - possibly pre-allocated buffer. If XY is too small to store
1934 : result, it is resized. If size(XY) is enough to store
1935 : result, it is left unchanged.
1936 :
1937 : OUTPUT PARAMETERS
1938 : XY - rows are filled with points: first NX columns with
1939 : X-values, next NY columns - with Y-values.
1940 :
1941 : NOTES
1942 : 1. points are ordered by distance from the query point (first = closest)
1943 : 2. if XY is larger than required to store result, only leading part will
1944 : be overwritten; trailing part will be left unchanged. So if on input
1945 : XY = [[A,B],[C,D]], and result is [1,2], then on exit we will get
1946 : XY = [[1,2],[C,D]]. This is done purposely to increase performance; if
1947 : you want function to resize array according to result size, use
1948 : function with same name and suffix 'I'.
1949 :
1950 : SEE ALSO
1951 : * KDTreeQueryResultsX() X-values
1952 : * KDTreeQueryResultsTags() tag values
1953 : * KDTreeQueryResultsDistances() distances
1954 :
1955 : -- ALGLIB --
1956 : Copyright 28.02.2010 by Bochkanov Sergey
1957 : *************************************************************************/
1958 0 : void kdtreequeryresultsxy(const kdtree &kdt, real_2d_array &xy, const xparams _xparams)
1959 : {
1960 : jmp_buf _break_jump;
1961 : alglib_impl::ae_state _alglib_env_state;
1962 0 : alglib_impl::ae_state_init(&_alglib_env_state);
1963 0 : if( setjmp(_break_jump) )
1964 : {
1965 : #if !defined(AE_NO_EXCEPTIONS)
1966 0 : _ALGLIB_CPP_EXCEPTION(_alglib_env_state.error_msg);
1967 : #else
1968 : _ALGLIB_SET_ERROR_FLAG(_alglib_env_state.error_msg);
1969 : return;
1970 : #endif
1971 : }
1972 0 : ae_state_set_break_jump(&_alglib_env_state, &_break_jump);
1973 0 : if( _xparams.flags!=0x0 )
1974 0 : ae_state_set_flags(&_alglib_env_state, _xparams.flags);
1975 0 : alglib_impl::kdtreequeryresultsxy(const_cast<alglib_impl::kdtree*>(kdt.c_ptr()), const_cast<alglib_impl::ae_matrix*>(xy.c_ptr()), &_alglib_env_state);
1976 0 : alglib_impl::ae_state_clear(&_alglib_env_state);
1977 0 : return;
1978 : }
1979 :
1980 : /*************************************************************************
1981 : Tags from last query
1982 :
1983 : This function retuns results stored in the internal buffer of kd-tree
1984 : object. If you performed buffered requests (ones which use instances of
1985 : kdtreerequestbuffer class), you should call buffered version of this
1986 : function - kdtreetsqueryresultstags().
1987 :
1988 : INPUT PARAMETERS
1989 : KDT - KD-tree
1990 : Tags - possibly pre-allocated buffer. If X is too small to store
1991 : result, it is resized. If size(X) is enough to store
1992 : result, it is left unchanged.
1993 :
1994 : OUTPUT PARAMETERS
1995 : Tags - filled with tags associated with points,
1996 : or, when no tags were supplied, with zeros
1997 :
1998 : NOTES
1999 : 1. points are ordered by distance from the query point (first = closest)
2000 : 2. if XY is larger than required to store result, only leading part will
2001 : be overwritten; trailing part will be left unchanged. So if on input
2002 : XY = [[A,B],[C,D]], and result is [1,2], then on exit we will get
2003 : XY = [[1,2],[C,D]]. This is done purposely to increase performance; if
2004 : you want function to resize array according to result size, use
2005 : function with same name and suffix 'I'.
2006 :
2007 : SEE ALSO
2008 : * KDTreeQueryResultsX() X-values
2009 : * KDTreeQueryResultsXY() X- and Y-values
2010 : * KDTreeQueryResultsDistances() distances
2011 :
2012 : -- ALGLIB --
2013 : Copyright 28.02.2010 by Bochkanov Sergey
2014 : *************************************************************************/
2015 0 : void kdtreequeryresultstags(const kdtree &kdt, integer_1d_array &tags, const xparams _xparams)
2016 : {
2017 : jmp_buf _break_jump;
2018 : alglib_impl::ae_state _alglib_env_state;
2019 0 : alglib_impl::ae_state_init(&_alglib_env_state);
2020 0 : if( setjmp(_break_jump) )
2021 : {
2022 : #if !defined(AE_NO_EXCEPTIONS)
2023 0 : _ALGLIB_CPP_EXCEPTION(_alglib_env_state.error_msg);
2024 : #else
2025 : _ALGLIB_SET_ERROR_FLAG(_alglib_env_state.error_msg);
2026 : return;
2027 : #endif
2028 : }
2029 0 : ae_state_set_break_jump(&_alglib_env_state, &_break_jump);
2030 0 : if( _xparams.flags!=0x0 )
2031 0 : ae_state_set_flags(&_alglib_env_state, _xparams.flags);
2032 0 : alglib_impl::kdtreequeryresultstags(const_cast<alglib_impl::kdtree*>(kdt.c_ptr()), const_cast<alglib_impl::ae_vector*>(tags.c_ptr()), &_alglib_env_state);
2033 0 : alglib_impl::ae_state_clear(&_alglib_env_state);
2034 0 : return;
2035 : }
2036 :
2037 : /*************************************************************************
2038 : Distances from last query
2039 :
2040 : This function retuns results stored in the internal buffer of kd-tree
2041 : object. If you performed buffered requests (ones which use instances of
2042 : kdtreerequestbuffer class), you should call buffered version of this
2043 : function - kdtreetsqueryresultsdistances().
2044 :
2045 : INPUT PARAMETERS
2046 : KDT - KD-tree
2047 : R - possibly pre-allocated buffer. If X is too small to store
2048 : result, it is resized. If size(X) is enough to store
2049 : result, it is left unchanged.
2050 :
2051 : OUTPUT PARAMETERS
2052 : R - filled with distances (in corresponding norm)
2053 :
2054 : NOTES
2055 : 1. points are ordered by distance from the query point (first = closest)
2056 : 2. if XY is larger than required to store result, only leading part will
2057 : be overwritten; trailing part will be left unchanged. So if on input
2058 : XY = [[A,B],[C,D]], and result is [1,2], then on exit we will get
2059 : XY = [[1,2],[C,D]]. This is done purposely to increase performance; if
2060 : you want function to resize array according to result size, use
2061 : function with same name and suffix 'I'.
2062 :
2063 : SEE ALSO
2064 : * KDTreeQueryResultsX() X-values
2065 : * KDTreeQueryResultsXY() X- and Y-values
2066 : * KDTreeQueryResultsTags() tag values
2067 :
2068 : -- ALGLIB --
2069 : Copyright 28.02.2010 by Bochkanov Sergey
2070 : *************************************************************************/
2071 0 : void kdtreequeryresultsdistances(const kdtree &kdt, real_1d_array &r, const xparams _xparams)
2072 : {
2073 : jmp_buf _break_jump;
2074 : alglib_impl::ae_state _alglib_env_state;
2075 0 : alglib_impl::ae_state_init(&_alglib_env_state);
2076 0 : if( setjmp(_break_jump) )
2077 : {
2078 : #if !defined(AE_NO_EXCEPTIONS)
2079 0 : _ALGLIB_CPP_EXCEPTION(_alglib_env_state.error_msg);
2080 : #else
2081 : _ALGLIB_SET_ERROR_FLAG(_alglib_env_state.error_msg);
2082 : return;
2083 : #endif
2084 : }
2085 0 : ae_state_set_break_jump(&_alglib_env_state, &_break_jump);
2086 0 : if( _xparams.flags!=0x0 )
2087 0 : ae_state_set_flags(&_alglib_env_state, _xparams.flags);
2088 0 : alglib_impl::kdtreequeryresultsdistances(const_cast<alglib_impl::kdtree*>(kdt.c_ptr()), const_cast<alglib_impl::ae_vector*>(r.c_ptr()), &_alglib_env_state);
2089 0 : alglib_impl::ae_state_clear(&_alglib_env_state);
2090 0 : return;
2091 : }
2092 :
2093 : /*************************************************************************
2094 : X-values from last query associated with kdtreerequestbuffer object.
2095 :
2096 : INPUT PARAMETERS
2097 : KDT - KD-tree
2098 : Buf - request buffer object created for this particular
2099 : instance of kd-tree structure.
2100 : X - possibly pre-allocated buffer. If X is too small to store
2101 : result, it is resized. If size(X) is enough to store
2102 : result, it is left unchanged.
2103 :
2104 : OUTPUT PARAMETERS
2105 : X - rows are filled with X-values
2106 :
2107 : NOTES
2108 : 1. points are ordered by distance from the query point (first = closest)
2109 : 2. if XY is larger than required to store result, only leading part will
2110 : be overwritten; trailing part will be left unchanged. So if on input
2111 : XY = [[A,B],[C,D]], and result is [1,2], then on exit we will get
2112 : XY = [[1,2],[C,D]]. This is done purposely to increase performance; if
2113 : you want function to resize array according to result size, use
2114 : function with same name and suffix 'I'.
2115 :
2116 : SEE ALSO
2117 : * KDTreeQueryResultsXY() X- and Y-values
2118 : * KDTreeQueryResultsTags() tag values
2119 : * KDTreeQueryResultsDistances() distances
2120 :
2121 : -- ALGLIB --
2122 : Copyright 28.02.2010 by Bochkanov Sergey
2123 : *************************************************************************/
2124 0 : void kdtreetsqueryresultsx(const kdtree &kdt, const kdtreerequestbuffer &buf, real_2d_array &x, const xparams _xparams)
2125 : {
2126 : jmp_buf _break_jump;
2127 : alglib_impl::ae_state _alglib_env_state;
2128 0 : alglib_impl::ae_state_init(&_alglib_env_state);
2129 0 : if( setjmp(_break_jump) )
2130 : {
2131 : #if !defined(AE_NO_EXCEPTIONS)
2132 0 : _ALGLIB_CPP_EXCEPTION(_alglib_env_state.error_msg);
2133 : #else
2134 : _ALGLIB_SET_ERROR_FLAG(_alglib_env_state.error_msg);
2135 : return;
2136 : #endif
2137 : }
2138 0 : ae_state_set_break_jump(&_alglib_env_state, &_break_jump);
2139 0 : if( _xparams.flags!=0x0 )
2140 0 : ae_state_set_flags(&_alglib_env_state, _xparams.flags);
2141 0 : alglib_impl::kdtreetsqueryresultsx(const_cast<alglib_impl::kdtree*>(kdt.c_ptr()), const_cast<alglib_impl::kdtreerequestbuffer*>(buf.c_ptr()), const_cast<alglib_impl::ae_matrix*>(x.c_ptr()), &_alglib_env_state);
2142 0 : alglib_impl::ae_state_clear(&_alglib_env_state);
2143 0 : return;
2144 : }
2145 :
2146 : /*************************************************************************
2147 : X- and Y-values from last query associated with kdtreerequestbuffer object.
2148 :
2149 : INPUT PARAMETERS
2150 : KDT - KD-tree
2151 : Buf - request buffer object created for this particular
2152 : instance of kd-tree structure.
2153 : XY - possibly pre-allocated buffer. If XY is too small to store
2154 : result, it is resized. If size(XY) is enough to store
2155 : result, it is left unchanged.
2156 :
2157 : OUTPUT PARAMETERS
2158 : XY - rows are filled with points: first NX columns with
2159 : X-values, next NY columns - with Y-values.
2160 :
2161 : NOTES
2162 : 1. points are ordered by distance from the query point (first = closest)
2163 : 2. if XY is larger than required to store result, only leading part will
2164 : be overwritten; trailing part will be left unchanged. So if on input
2165 : XY = [[A,B],[C,D]], and result is [1,2], then on exit we will get
2166 : XY = [[1,2],[C,D]]. This is done purposely to increase performance; if
2167 : you want function to resize array according to result size, use
2168 : function with same name and suffix 'I'.
2169 :
2170 : SEE ALSO
2171 : * KDTreeQueryResultsX() X-values
2172 : * KDTreeQueryResultsTags() tag values
2173 : * KDTreeQueryResultsDistances() distances
2174 :
2175 : -- ALGLIB --
2176 : Copyright 28.02.2010 by Bochkanov Sergey
2177 : *************************************************************************/
2178 0 : void kdtreetsqueryresultsxy(const kdtree &kdt, const kdtreerequestbuffer &buf, real_2d_array &xy, const xparams _xparams)
2179 : {
2180 : jmp_buf _break_jump;
2181 : alglib_impl::ae_state _alglib_env_state;
2182 0 : alglib_impl::ae_state_init(&_alglib_env_state);
2183 0 : if( setjmp(_break_jump) )
2184 : {
2185 : #if !defined(AE_NO_EXCEPTIONS)
2186 0 : _ALGLIB_CPP_EXCEPTION(_alglib_env_state.error_msg);
2187 : #else
2188 : _ALGLIB_SET_ERROR_FLAG(_alglib_env_state.error_msg);
2189 : return;
2190 : #endif
2191 : }
2192 0 : ae_state_set_break_jump(&_alglib_env_state, &_break_jump);
2193 0 : if( _xparams.flags!=0x0 )
2194 0 : ae_state_set_flags(&_alglib_env_state, _xparams.flags);
2195 0 : alglib_impl::kdtreetsqueryresultsxy(const_cast<alglib_impl::kdtree*>(kdt.c_ptr()), const_cast<alglib_impl::kdtreerequestbuffer*>(buf.c_ptr()), const_cast<alglib_impl::ae_matrix*>(xy.c_ptr()), &_alglib_env_state);
2196 0 : alglib_impl::ae_state_clear(&_alglib_env_state);
2197 0 : return;
2198 : }
2199 :
2200 : /*************************************************************************
2201 : Tags from last query associated with kdtreerequestbuffer object.
2202 :
2203 : This function retuns results stored in the internal buffer of kd-tree
2204 : object. If you performed buffered requests (ones which use instances of
2205 : kdtreerequestbuffer class), you should call buffered version of this
2206 : function - KDTreeTsqueryresultstags().
2207 :
2208 : INPUT PARAMETERS
2209 : KDT - KD-tree
2210 : Buf - request buffer object created for this particular
2211 : instance of kd-tree structure.
2212 : Tags - possibly pre-allocated buffer. If X is too small to store
2213 : result, it is resized. If size(X) is enough to store
2214 : result, it is left unchanged.
2215 :
2216 : OUTPUT PARAMETERS
2217 : Tags - filled with tags associated with points,
2218 : or, when no tags were supplied, with zeros
2219 :
2220 : NOTES
2221 : 1. points are ordered by distance from the query point (first = closest)
2222 : 2. if XY is larger than required to store result, only leading part will
2223 : be overwritten; trailing part will be left unchanged. So if on input
2224 : XY = [[A,B],[C,D]], and result is [1,2], then on exit we will get
2225 : XY = [[1,2],[C,D]]. This is done purposely to increase performance; if
2226 : you want function to resize array according to result size, use
2227 : function with same name and suffix 'I'.
2228 :
2229 : SEE ALSO
2230 : * KDTreeQueryResultsX() X-values
2231 : * KDTreeQueryResultsXY() X- and Y-values
2232 : * KDTreeQueryResultsDistances() distances
2233 :
2234 : -- ALGLIB --
2235 : Copyright 28.02.2010 by Bochkanov Sergey
2236 : *************************************************************************/
2237 0 : void kdtreetsqueryresultstags(const kdtree &kdt, const kdtreerequestbuffer &buf, integer_1d_array &tags, const xparams _xparams)
2238 : {
2239 : jmp_buf _break_jump;
2240 : alglib_impl::ae_state _alglib_env_state;
2241 0 : alglib_impl::ae_state_init(&_alglib_env_state);
2242 0 : if( setjmp(_break_jump) )
2243 : {
2244 : #if !defined(AE_NO_EXCEPTIONS)
2245 0 : _ALGLIB_CPP_EXCEPTION(_alglib_env_state.error_msg);
2246 : #else
2247 : _ALGLIB_SET_ERROR_FLAG(_alglib_env_state.error_msg);
2248 : return;
2249 : #endif
2250 : }
2251 0 : ae_state_set_break_jump(&_alglib_env_state, &_break_jump);
2252 0 : if( _xparams.flags!=0x0 )
2253 0 : ae_state_set_flags(&_alglib_env_state, _xparams.flags);
2254 0 : alglib_impl::kdtreetsqueryresultstags(const_cast<alglib_impl::kdtree*>(kdt.c_ptr()), const_cast<alglib_impl::kdtreerequestbuffer*>(buf.c_ptr()), const_cast<alglib_impl::ae_vector*>(tags.c_ptr()), &_alglib_env_state);
2255 0 : alglib_impl::ae_state_clear(&_alglib_env_state);
2256 0 : return;
2257 : }
2258 :
2259 : /*************************************************************************
2260 : Distances from last query associated with kdtreerequestbuffer object.
2261 :
2262 : This function retuns results stored in the internal buffer of kd-tree
2263 : object. If you performed buffered requests (ones which use instances of
2264 : kdtreerequestbuffer class), you should call buffered version of this
2265 : function - KDTreeTsqueryresultsdistances().
2266 :
2267 : INPUT PARAMETERS
2268 : KDT - KD-tree
2269 : Buf - request buffer object created for this particular
2270 : instance of kd-tree structure.
2271 : R - possibly pre-allocated buffer. If X is too small to store
2272 : result, it is resized. If size(X) is enough to store
2273 : result, it is left unchanged.
2274 :
2275 : OUTPUT PARAMETERS
2276 : R - filled with distances (in corresponding norm)
2277 :
2278 : NOTES
2279 : 1. points are ordered by distance from the query point (first = closest)
2280 : 2. if XY is larger than required to store result, only leading part will
2281 : be overwritten; trailing part will be left unchanged. So if on input
2282 : XY = [[A,B],[C,D]], and result is [1,2], then on exit we will get
2283 : XY = [[1,2],[C,D]]. This is done purposely to increase performance; if
2284 : you want function to resize array according to result size, use
2285 : function with same name and suffix 'I'.
2286 :
2287 : SEE ALSO
2288 : * KDTreeQueryResultsX() X-values
2289 : * KDTreeQueryResultsXY() X- and Y-values
2290 : * KDTreeQueryResultsTags() tag values
2291 :
2292 : -- ALGLIB --
2293 : Copyright 28.02.2010 by Bochkanov Sergey
2294 : *************************************************************************/
2295 0 : void kdtreetsqueryresultsdistances(const kdtree &kdt, const kdtreerequestbuffer &buf, real_1d_array &r, const xparams _xparams)
2296 : {
2297 : jmp_buf _break_jump;
2298 : alglib_impl::ae_state _alglib_env_state;
2299 0 : alglib_impl::ae_state_init(&_alglib_env_state);
2300 0 : if( setjmp(_break_jump) )
2301 : {
2302 : #if !defined(AE_NO_EXCEPTIONS)
2303 0 : _ALGLIB_CPP_EXCEPTION(_alglib_env_state.error_msg);
2304 : #else
2305 : _ALGLIB_SET_ERROR_FLAG(_alglib_env_state.error_msg);
2306 : return;
2307 : #endif
2308 : }
2309 0 : ae_state_set_break_jump(&_alglib_env_state, &_break_jump);
2310 0 : if( _xparams.flags!=0x0 )
2311 0 : ae_state_set_flags(&_alglib_env_state, _xparams.flags);
2312 0 : alglib_impl::kdtreetsqueryresultsdistances(const_cast<alglib_impl::kdtree*>(kdt.c_ptr()), const_cast<alglib_impl::kdtreerequestbuffer*>(buf.c_ptr()), const_cast<alglib_impl::ae_vector*>(r.c_ptr()), &_alglib_env_state);
2313 0 : alglib_impl::ae_state_clear(&_alglib_env_state);
2314 0 : return;
2315 : }
2316 :
2317 : /*************************************************************************
2318 : X-values from last query; 'interactive' variant for languages like Python
2319 : which support constructs like "X = KDTreeQueryResultsXI(KDT)" and
2320 : interactive mode of interpreter.
2321 :
2322 : This function allocates new array on each call, so it is significantly
2323 : slower than its 'non-interactive' counterpart, but it is more convenient
2324 : when you call it from command line.
2325 :
2326 : -- ALGLIB --
2327 : Copyright 28.02.2010 by Bochkanov Sergey
2328 : *************************************************************************/
2329 0 : void kdtreequeryresultsxi(const kdtree &kdt, real_2d_array &x, const xparams _xparams)
2330 : {
2331 : jmp_buf _break_jump;
2332 : alglib_impl::ae_state _alglib_env_state;
2333 0 : alglib_impl::ae_state_init(&_alglib_env_state);
2334 0 : if( setjmp(_break_jump) )
2335 : {
2336 : #if !defined(AE_NO_EXCEPTIONS)
2337 0 : _ALGLIB_CPP_EXCEPTION(_alglib_env_state.error_msg);
2338 : #else
2339 : _ALGLIB_SET_ERROR_FLAG(_alglib_env_state.error_msg);
2340 : return;
2341 : #endif
2342 : }
2343 0 : ae_state_set_break_jump(&_alglib_env_state, &_break_jump);
2344 0 : if( _xparams.flags!=0x0 )
2345 0 : ae_state_set_flags(&_alglib_env_state, _xparams.flags);
2346 0 : alglib_impl::kdtreequeryresultsxi(const_cast<alglib_impl::kdtree*>(kdt.c_ptr()), const_cast<alglib_impl::ae_matrix*>(x.c_ptr()), &_alglib_env_state);
2347 0 : alglib_impl::ae_state_clear(&_alglib_env_state);
2348 0 : return;
2349 : }
2350 :
2351 : /*************************************************************************
2352 : XY-values from last query; 'interactive' variant for languages like Python
2353 : which support constructs like "XY = KDTreeQueryResultsXYI(KDT)" and
2354 : interactive mode of interpreter.
2355 :
2356 : This function allocates new array on each call, so it is significantly
2357 : slower than its 'non-interactive' counterpart, but it is more convenient
2358 : when you call it from command line.
2359 :
2360 : -- ALGLIB --
2361 : Copyright 28.02.2010 by Bochkanov Sergey
2362 : *************************************************************************/
2363 0 : void kdtreequeryresultsxyi(const kdtree &kdt, real_2d_array &xy, const xparams _xparams)
2364 : {
2365 : jmp_buf _break_jump;
2366 : alglib_impl::ae_state _alglib_env_state;
2367 0 : alglib_impl::ae_state_init(&_alglib_env_state);
2368 0 : if( setjmp(_break_jump) )
2369 : {
2370 : #if !defined(AE_NO_EXCEPTIONS)
2371 0 : _ALGLIB_CPP_EXCEPTION(_alglib_env_state.error_msg);
2372 : #else
2373 : _ALGLIB_SET_ERROR_FLAG(_alglib_env_state.error_msg);
2374 : return;
2375 : #endif
2376 : }
2377 0 : ae_state_set_break_jump(&_alglib_env_state, &_break_jump);
2378 0 : if( _xparams.flags!=0x0 )
2379 0 : ae_state_set_flags(&_alglib_env_state, _xparams.flags);
2380 0 : alglib_impl::kdtreequeryresultsxyi(const_cast<alglib_impl::kdtree*>(kdt.c_ptr()), const_cast<alglib_impl::ae_matrix*>(xy.c_ptr()), &_alglib_env_state);
2381 0 : alglib_impl::ae_state_clear(&_alglib_env_state);
2382 0 : return;
2383 : }
2384 :
2385 : /*************************************************************************
2386 : Tags from last query; 'interactive' variant for languages like Python
2387 : which support constructs like "Tags = KDTreeQueryResultsTagsI(KDT)" and
2388 : interactive mode of interpreter.
2389 :
2390 : This function allocates new array on each call, so it is significantly
2391 : slower than its 'non-interactive' counterpart, but it is more convenient
2392 : when you call it from command line.
2393 :
2394 : -- ALGLIB --
2395 : Copyright 28.02.2010 by Bochkanov Sergey
2396 : *************************************************************************/
2397 0 : void kdtreequeryresultstagsi(const kdtree &kdt, integer_1d_array &tags, const xparams _xparams)
2398 : {
2399 : jmp_buf _break_jump;
2400 : alglib_impl::ae_state _alglib_env_state;
2401 0 : alglib_impl::ae_state_init(&_alglib_env_state);
2402 0 : if( setjmp(_break_jump) )
2403 : {
2404 : #if !defined(AE_NO_EXCEPTIONS)
2405 0 : _ALGLIB_CPP_EXCEPTION(_alglib_env_state.error_msg);
2406 : #else
2407 : _ALGLIB_SET_ERROR_FLAG(_alglib_env_state.error_msg);
2408 : return;
2409 : #endif
2410 : }
2411 0 : ae_state_set_break_jump(&_alglib_env_state, &_break_jump);
2412 0 : if( _xparams.flags!=0x0 )
2413 0 : ae_state_set_flags(&_alglib_env_state, _xparams.flags);
2414 0 : alglib_impl::kdtreequeryresultstagsi(const_cast<alglib_impl::kdtree*>(kdt.c_ptr()), const_cast<alglib_impl::ae_vector*>(tags.c_ptr()), &_alglib_env_state);
2415 0 : alglib_impl::ae_state_clear(&_alglib_env_state);
2416 0 : return;
2417 : }
2418 :
2419 : /*************************************************************************
2420 : Distances from last query; 'interactive' variant for languages like Python
2421 : which support constructs like "R = KDTreeQueryResultsDistancesI(KDT)"
2422 : and interactive mode of interpreter.
2423 :
2424 : This function allocates new array on each call, so it is significantly
2425 : slower than its 'non-interactive' counterpart, but it is more convenient
2426 : when you call it from command line.
2427 :
2428 : -- ALGLIB --
2429 : Copyright 28.02.2010 by Bochkanov Sergey
2430 : *************************************************************************/
2431 0 : void kdtreequeryresultsdistancesi(const kdtree &kdt, real_1d_array &r, const xparams _xparams)
2432 : {
2433 : jmp_buf _break_jump;
2434 : alglib_impl::ae_state _alglib_env_state;
2435 0 : alglib_impl::ae_state_init(&_alglib_env_state);
2436 0 : if( setjmp(_break_jump) )
2437 : {
2438 : #if !defined(AE_NO_EXCEPTIONS)
2439 0 : _ALGLIB_CPP_EXCEPTION(_alglib_env_state.error_msg);
2440 : #else
2441 : _ALGLIB_SET_ERROR_FLAG(_alglib_env_state.error_msg);
2442 : return;
2443 : #endif
2444 : }
2445 0 : ae_state_set_break_jump(&_alglib_env_state, &_break_jump);
2446 0 : if( _xparams.flags!=0x0 )
2447 0 : ae_state_set_flags(&_alglib_env_state, _xparams.flags);
2448 0 : alglib_impl::kdtreequeryresultsdistancesi(const_cast<alglib_impl::kdtree*>(kdt.c_ptr()), const_cast<alglib_impl::ae_vector*>(r.c_ptr()), &_alglib_env_state);
2449 0 : alglib_impl::ae_state_clear(&_alglib_env_state);
2450 0 : return;
2451 : }
2452 : #endif
2453 :
2454 : #if defined(AE_COMPILE_HQRND) || !defined(AE_PARTIAL_BUILD)
2455 : /*************************************************************************
2456 : Portable high quality random number generator state.
2457 : Initialized with HQRNDRandomize() or HQRNDSeed().
2458 :
2459 : Fields:
2460 : S1, S2 - seed values
2461 : V - precomputed value
2462 : MagicV - 'magic' value used to determine whether State structure
2463 : was correctly initialized.
2464 : *************************************************************************/
2465 0 : _hqrndstate_owner::_hqrndstate_owner()
2466 : {
2467 : jmp_buf _break_jump;
2468 : alglib_impl::ae_state _state;
2469 :
2470 0 : alglib_impl::ae_state_init(&_state);
2471 0 : if( setjmp(_break_jump) )
2472 : {
2473 0 : if( p_struct!=NULL )
2474 : {
2475 0 : alglib_impl::_hqrndstate_destroy(p_struct);
2476 0 : alglib_impl::ae_free(p_struct);
2477 : }
2478 0 : p_struct = NULL;
2479 : #if !defined(AE_NO_EXCEPTIONS)
2480 0 : _ALGLIB_CPP_EXCEPTION(_state.error_msg);
2481 : #else
2482 : _ALGLIB_SET_ERROR_FLAG(_state.error_msg);
2483 : return;
2484 : #endif
2485 : }
2486 0 : alglib_impl::ae_state_set_break_jump(&_state, &_break_jump);
2487 0 : p_struct = NULL;
2488 0 : p_struct = (alglib_impl::hqrndstate*)alglib_impl::ae_malloc(sizeof(alglib_impl::hqrndstate), &_state);
2489 0 : memset(p_struct, 0, sizeof(alglib_impl::hqrndstate));
2490 0 : alglib_impl::_hqrndstate_init(p_struct, &_state, ae_false);
2491 0 : ae_state_clear(&_state);
2492 0 : }
2493 :
2494 0 : _hqrndstate_owner::_hqrndstate_owner(const _hqrndstate_owner &rhs)
2495 : {
2496 : jmp_buf _break_jump;
2497 : alglib_impl::ae_state _state;
2498 :
2499 0 : alglib_impl::ae_state_init(&_state);
2500 0 : if( setjmp(_break_jump) )
2501 : {
2502 0 : if( p_struct!=NULL )
2503 : {
2504 0 : alglib_impl::_hqrndstate_destroy(p_struct);
2505 0 : alglib_impl::ae_free(p_struct);
2506 : }
2507 0 : p_struct = NULL;
2508 : #if !defined(AE_NO_EXCEPTIONS)
2509 0 : _ALGLIB_CPP_EXCEPTION(_state.error_msg);
2510 : #else
2511 : _ALGLIB_SET_ERROR_FLAG(_state.error_msg);
2512 : return;
2513 : #endif
2514 : }
2515 0 : alglib_impl::ae_state_set_break_jump(&_state, &_break_jump);
2516 0 : p_struct = NULL;
2517 0 : alglib_impl::ae_assert(rhs.p_struct!=NULL, "ALGLIB: hqrndstate copy constructor failure (source is not initialized)", &_state);
2518 0 : p_struct = (alglib_impl::hqrndstate*)alglib_impl::ae_malloc(sizeof(alglib_impl::hqrndstate), &_state);
2519 0 : memset(p_struct, 0, sizeof(alglib_impl::hqrndstate));
2520 0 : alglib_impl::_hqrndstate_init_copy(p_struct, const_cast<alglib_impl::hqrndstate*>(rhs.p_struct), &_state, ae_false);
2521 0 : ae_state_clear(&_state);
2522 0 : }
2523 :
2524 0 : _hqrndstate_owner& _hqrndstate_owner::operator=(const _hqrndstate_owner &rhs)
2525 : {
2526 0 : if( this==&rhs )
2527 0 : return *this;
2528 : jmp_buf _break_jump;
2529 : alglib_impl::ae_state _state;
2530 :
2531 0 : alglib_impl::ae_state_init(&_state);
2532 0 : if( setjmp(_break_jump) )
2533 : {
2534 : #if !defined(AE_NO_EXCEPTIONS)
2535 0 : _ALGLIB_CPP_EXCEPTION(_state.error_msg);
2536 : #else
2537 : _ALGLIB_SET_ERROR_FLAG(_state.error_msg);
2538 : return *this;
2539 : #endif
2540 : }
2541 0 : alglib_impl::ae_state_set_break_jump(&_state, &_break_jump);
2542 0 : alglib_impl::ae_assert(p_struct!=NULL, "ALGLIB: hqrndstate assignment constructor failure (destination is not initialized)", &_state);
2543 0 : alglib_impl::ae_assert(rhs.p_struct!=NULL, "ALGLIB: hqrndstate assignment constructor failure (source is not initialized)", &_state);
2544 0 : alglib_impl::_hqrndstate_destroy(p_struct);
2545 0 : memset(p_struct, 0, sizeof(alglib_impl::hqrndstate));
2546 0 : alglib_impl::_hqrndstate_init_copy(p_struct, const_cast<alglib_impl::hqrndstate*>(rhs.p_struct), &_state, ae_false);
2547 0 : ae_state_clear(&_state);
2548 0 : return *this;
2549 : }
2550 :
2551 0 : _hqrndstate_owner::~_hqrndstate_owner()
2552 : {
2553 0 : if( p_struct!=NULL )
2554 : {
2555 0 : alglib_impl::_hqrndstate_destroy(p_struct);
2556 0 : ae_free(p_struct);
2557 : }
2558 0 : }
2559 :
2560 0 : alglib_impl::hqrndstate* _hqrndstate_owner::c_ptr()
2561 : {
2562 0 : return p_struct;
2563 : }
2564 :
2565 0 : alglib_impl::hqrndstate* _hqrndstate_owner::c_ptr() const
2566 : {
2567 0 : return const_cast<alglib_impl::hqrndstate*>(p_struct);
2568 : }
2569 0 : hqrndstate::hqrndstate() : _hqrndstate_owner()
2570 : {
2571 0 : }
2572 :
2573 0 : hqrndstate::hqrndstate(const hqrndstate &rhs):_hqrndstate_owner(rhs)
2574 : {
2575 0 : }
2576 :
2577 0 : hqrndstate& hqrndstate::operator=(const hqrndstate &rhs)
2578 : {
2579 0 : if( this==&rhs )
2580 0 : return *this;
2581 0 : _hqrndstate_owner::operator=(rhs);
2582 0 : return *this;
2583 : }
2584 :
2585 0 : hqrndstate::~hqrndstate()
2586 : {
2587 0 : }
2588 :
2589 : /*************************************************************************
2590 : HQRNDState initialization with random values which come from standard
2591 : RNG.
2592 :
2593 : -- ALGLIB --
2594 : Copyright 02.12.2009 by Bochkanov Sergey
2595 : *************************************************************************/
2596 0 : void hqrndrandomize(hqrndstate &state, const xparams _xparams)
2597 : {
2598 : jmp_buf _break_jump;
2599 : alglib_impl::ae_state _alglib_env_state;
2600 0 : alglib_impl::ae_state_init(&_alglib_env_state);
2601 0 : if( setjmp(_break_jump) )
2602 : {
2603 : #if !defined(AE_NO_EXCEPTIONS)
2604 0 : _ALGLIB_CPP_EXCEPTION(_alglib_env_state.error_msg);
2605 : #else
2606 : _ALGLIB_SET_ERROR_FLAG(_alglib_env_state.error_msg);
2607 : return;
2608 : #endif
2609 : }
2610 0 : ae_state_set_break_jump(&_alglib_env_state, &_break_jump);
2611 0 : if( _xparams.flags!=0x0 )
2612 0 : ae_state_set_flags(&_alglib_env_state, _xparams.flags);
2613 0 : alglib_impl::hqrndrandomize(const_cast<alglib_impl::hqrndstate*>(state.c_ptr()), &_alglib_env_state);
2614 0 : alglib_impl::ae_state_clear(&_alglib_env_state);
2615 0 : return;
2616 : }
2617 :
2618 : /*************************************************************************
2619 : HQRNDState initialization with seed values
2620 :
2621 : -- ALGLIB --
2622 : Copyright 02.12.2009 by Bochkanov Sergey
2623 : *************************************************************************/
2624 0 : void hqrndseed(const ae_int_t s1, const ae_int_t s2, hqrndstate &state, const xparams _xparams)
2625 : {
2626 : jmp_buf _break_jump;
2627 : alglib_impl::ae_state _alglib_env_state;
2628 0 : alglib_impl::ae_state_init(&_alglib_env_state);
2629 0 : if( setjmp(_break_jump) )
2630 : {
2631 : #if !defined(AE_NO_EXCEPTIONS)
2632 0 : _ALGLIB_CPP_EXCEPTION(_alglib_env_state.error_msg);
2633 : #else
2634 : _ALGLIB_SET_ERROR_FLAG(_alglib_env_state.error_msg);
2635 : return;
2636 : #endif
2637 : }
2638 0 : ae_state_set_break_jump(&_alglib_env_state, &_break_jump);
2639 0 : if( _xparams.flags!=0x0 )
2640 0 : ae_state_set_flags(&_alglib_env_state, _xparams.flags);
2641 0 : alglib_impl::hqrndseed(s1, s2, const_cast<alglib_impl::hqrndstate*>(state.c_ptr()), &_alglib_env_state);
2642 0 : alglib_impl::ae_state_clear(&_alglib_env_state);
2643 0 : return;
2644 : }
2645 :
2646 : /*************************************************************************
2647 : This function generates random real number in (0,1),
2648 : not including interval boundaries
2649 :
2650 : State structure must be initialized with HQRNDRandomize() or HQRNDSeed().
2651 :
2652 : -- ALGLIB --
2653 : Copyright 02.12.2009 by Bochkanov Sergey
2654 : *************************************************************************/
2655 0 : double hqrnduniformr(const hqrndstate &state, const xparams _xparams)
2656 : {
2657 : jmp_buf _break_jump;
2658 : alglib_impl::ae_state _alglib_env_state;
2659 0 : alglib_impl::ae_state_init(&_alglib_env_state);
2660 0 : if( setjmp(_break_jump) )
2661 : {
2662 : #if !defined(AE_NO_EXCEPTIONS)
2663 0 : _ALGLIB_CPP_EXCEPTION(_alglib_env_state.error_msg);
2664 : #else
2665 : _ALGLIB_SET_ERROR_FLAG(_alglib_env_state.error_msg);
2666 : return 0;
2667 : #endif
2668 : }
2669 0 : ae_state_set_break_jump(&_alglib_env_state, &_break_jump);
2670 0 : if( _xparams.flags!=0x0 )
2671 0 : ae_state_set_flags(&_alglib_env_state, _xparams.flags);
2672 0 : double result = alglib_impl::hqrnduniformr(const_cast<alglib_impl::hqrndstate*>(state.c_ptr()), &_alglib_env_state);
2673 0 : alglib_impl::ae_state_clear(&_alglib_env_state);
2674 0 : return *(reinterpret_cast<double*>(&result));
2675 : }
2676 :
2677 : /*************************************************************************
2678 : This function generates random integer number in [0, N)
2679 :
2680 : 1. State structure must be initialized with HQRNDRandomize() or HQRNDSeed()
2681 : 2. N can be any positive number except for very large numbers:
2682 : * close to 2^31 on 32-bit systems
2683 : * close to 2^62 on 64-bit systems
2684 : An exception will be generated if N is too large.
2685 :
2686 : -- ALGLIB --
2687 : Copyright 02.12.2009 by Bochkanov Sergey
2688 : *************************************************************************/
2689 0 : ae_int_t hqrnduniformi(const hqrndstate &state, const ae_int_t n, const xparams _xparams)
2690 : {
2691 : jmp_buf _break_jump;
2692 : alglib_impl::ae_state _alglib_env_state;
2693 0 : alglib_impl::ae_state_init(&_alglib_env_state);
2694 0 : if( setjmp(_break_jump) )
2695 : {
2696 : #if !defined(AE_NO_EXCEPTIONS)
2697 0 : _ALGLIB_CPP_EXCEPTION(_alglib_env_state.error_msg);
2698 : #else
2699 : _ALGLIB_SET_ERROR_FLAG(_alglib_env_state.error_msg);
2700 : return 0;
2701 : #endif
2702 : }
2703 0 : ae_state_set_break_jump(&_alglib_env_state, &_break_jump);
2704 0 : if( _xparams.flags!=0x0 )
2705 0 : ae_state_set_flags(&_alglib_env_state, _xparams.flags);
2706 0 : alglib_impl::ae_int_t result = alglib_impl::hqrnduniformi(const_cast<alglib_impl::hqrndstate*>(state.c_ptr()), n, &_alglib_env_state);
2707 0 : alglib_impl::ae_state_clear(&_alglib_env_state);
2708 0 : return *(reinterpret_cast<ae_int_t*>(&result));
2709 : }
2710 :
2711 : /*************************************************************************
2712 : Random number generator: normal numbers
2713 :
2714 : This function generates one random number from normal distribution.
2715 : Its performance is equal to that of HQRNDNormal2()
2716 :
2717 : State structure must be initialized with HQRNDRandomize() or HQRNDSeed().
2718 :
2719 : -- ALGLIB --
2720 : Copyright 02.12.2009 by Bochkanov Sergey
2721 : *************************************************************************/
2722 0 : double hqrndnormal(const hqrndstate &state, const xparams _xparams)
2723 : {
2724 : jmp_buf _break_jump;
2725 : alglib_impl::ae_state _alglib_env_state;
2726 0 : alglib_impl::ae_state_init(&_alglib_env_state);
2727 0 : if( setjmp(_break_jump) )
2728 : {
2729 : #if !defined(AE_NO_EXCEPTIONS)
2730 0 : _ALGLIB_CPP_EXCEPTION(_alglib_env_state.error_msg);
2731 : #else
2732 : _ALGLIB_SET_ERROR_FLAG(_alglib_env_state.error_msg);
2733 : return 0;
2734 : #endif
2735 : }
2736 0 : ae_state_set_break_jump(&_alglib_env_state, &_break_jump);
2737 0 : if( _xparams.flags!=0x0 )
2738 0 : ae_state_set_flags(&_alglib_env_state, _xparams.flags);
2739 0 : double result = alglib_impl::hqrndnormal(const_cast<alglib_impl::hqrndstate*>(state.c_ptr()), &_alglib_env_state);
2740 0 : alglib_impl::ae_state_clear(&_alglib_env_state);
2741 0 : return *(reinterpret_cast<double*>(&result));
2742 : }
2743 :
2744 : /*************************************************************************
2745 : Random number generator: vector with random entries (normal distribution)
2746 :
2747 : This function generates N random numbers from normal distribution.
2748 :
2749 : State structure must be initialized with HQRNDRandomize() or HQRNDSeed().
2750 :
2751 : -- ALGLIB --
2752 : Copyright 02.12.2009 by Bochkanov Sergey
2753 : *************************************************************************/
2754 0 : void hqrndnormalv(const hqrndstate &state, const ae_int_t n, real_1d_array &x, const xparams _xparams)
2755 : {
2756 : jmp_buf _break_jump;
2757 : alglib_impl::ae_state _alglib_env_state;
2758 0 : alglib_impl::ae_state_init(&_alglib_env_state);
2759 0 : if( setjmp(_break_jump) )
2760 : {
2761 : #if !defined(AE_NO_EXCEPTIONS)
2762 0 : _ALGLIB_CPP_EXCEPTION(_alglib_env_state.error_msg);
2763 : #else
2764 : _ALGLIB_SET_ERROR_FLAG(_alglib_env_state.error_msg);
2765 : return;
2766 : #endif
2767 : }
2768 0 : ae_state_set_break_jump(&_alglib_env_state, &_break_jump);
2769 0 : if( _xparams.flags!=0x0 )
2770 0 : ae_state_set_flags(&_alglib_env_state, _xparams.flags);
2771 0 : alglib_impl::hqrndnormalv(const_cast<alglib_impl::hqrndstate*>(state.c_ptr()), n, const_cast<alglib_impl::ae_vector*>(x.c_ptr()), &_alglib_env_state);
2772 0 : alglib_impl::ae_state_clear(&_alglib_env_state);
2773 0 : return;
2774 : }
2775 :
2776 : /*************************************************************************
2777 : Random number generator: matrix with random entries (normal distribution)
2778 :
2779 : This function generates MxN random matrix.
2780 :
2781 : State structure must be initialized with HQRNDRandomize() or HQRNDSeed().
2782 :
2783 : -- ALGLIB --
2784 : Copyright 02.12.2009 by Bochkanov Sergey
2785 : *************************************************************************/
2786 0 : void hqrndnormalm(const hqrndstate &state, const ae_int_t m, const ae_int_t n, real_2d_array &x, const xparams _xparams)
2787 : {
2788 : jmp_buf _break_jump;
2789 : alglib_impl::ae_state _alglib_env_state;
2790 0 : alglib_impl::ae_state_init(&_alglib_env_state);
2791 0 : if( setjmp(_break_jump) )
2792 : {
2793 : #if !defined(AE_NO_EXCEPTIONS)
2794 0 : _ALGLIB_CPP_EXCEPTION(_alglib_env_state.error_msg);
2795 : #else
2796 : _ALGLIB_SET_ERROR_FLAG(_alglib_env_state.error_msg);
2797 : return;
2798 : #endif
2799 : }
2800 0 : ae_state_set_break_jump(&_alglib_env_state, &_break_jump);
2801 0 : if( _xparams.flags!=0x0 )
2802 0 : ae_state_set_flags(&_alglib_env_state, _xparams.flags);
2803 0 : alglib_impl::hqrndnormalm(const_cast<alglib_impl::hqrndstate*>(state.c_ptr()), m, n, const_cast<alglib_impl::ae_matrix*>(x.c_ptr()), &_alglib_env_state);
2804 0 : alglib_impl::ae_state_clear(&_alglib_env_state);
2805 0 : return;
2806 : }
2807 :
2808 : /*************************************************************************
2809 : Random number generator: random X and Y such that X^2+Y^2=1
2810 :
2811 : State structure must be initialized with HQRNDRandomize() or HQRNDSeed().
2812 :
2813 : -- ALGLIB --
2814 : Copyright 02.12.2009 by Bochkanov Sergey
2815 : *************************************************************************/
2816 0 : void hqrndunit2(const hqrndstate &state, double &x, double &y, const xparams _xparams)
2817 : {
2818 : jmp_buf _break_jump;
2819 : alglib_impl::ae_state _alglib_env_state;
2820 0 : alglib_impl::ae_state_init(&_alglib_env_state);
2821 0 : if( setjmp(_break_jump) )
2822 : {
2823 : #if !defined(AE_NO_EXCEPTIONS)
2824 0 : _ALGLIB_CPP_EXCEPTION(_alglib_env_state.error_msg);
2825 : #else
2826 : _ALGLIB_SET_ERROR_FLAG(_alglib_env_state.error_msg);
2827 : return;
2828 : #endif
2829 : }
2830 0 : ae_state_set_break_jump(&_alglib_env_state, &_break_jump);
2831 0 : if( _xparams.flags!=0x0 )
2832 0 : ae_state_set_flags(&_alglib_env_state, _xparams.flags);
2833 0 : alglib_impl::hqrndunit2(const_cast<alglib_impl::hqrndstate*>(state.c_ptr()), &x, &y, &_alglib_env_state);
2834 0 : alglib_impl::ae_state_clear(&_alglib_env_state);
2835 0 : return;
2836 : }
2837 :
2838 : /*************************************************************************
2839 : Random number generator: normal numbers
2840 :
2841 : This function generates two independent random numbers from normal
2842 : distribution. Its performance is equal to that of HQRNDNormal()
2843 :
2844 : State structure must be initialized with HQRNDRandomize() or HQRNDSeed().
2845 :
2846 : -- ALGLIB --
2847 : Copyright 02.12.2009 by Bochkanov Sergey
2848 : *************************************************************************/
2849 0 : void hqrndnormal2(const hqrndstate &state, double &x1, double &x2, const xparams _xparams)
2850 : {
2851 : jmp_buf _break_jump;
2852 : alglib_impl::ae_state _alglib_env_state;
2853 0 : alglib_impl::ae_state_init(&_alglib_env_state);
2854 0 : if( setjmp(_break_jump) )
2855 : {
2856 : #if !defined(AE_NO_EXCEPTIONS)
2857 0 : _ALGLIB_CPP_EXCEPTION(_alglib_env_state.error_msg);
2858 : #else
2859 : _ALGLIB_SET_ERROR_FLAG(_alglib_env_state.error_msg);
2860 : return;
2861 : #endif
2862 : }
2863 0 : ae_state_set_break_jump(&_alglib_env_state, &_break_jump);
2864 0 : if( _xparams.flags!=0x0 )
2865 0 : ae_state_set_flags(&_alglib_env_state, _xparams.flags);
2866 0 : alglib_impl::hqrndnormal2(const_cast<alglib_impl::hqrndstate*>(state.c_ptr()), &x1, &x2, &_alglib_env_state);
2867 0 : alglib_impl::ae_state_clear(&_alglib_env_state);
2868 0 : return;
2869 : }
2870 :
2871 : /*************************************************************************
2872 : Random number generator: exponential distribution
2873 :
2874 : State structure must be initialized with HQRNDRandomize() or HQRNDSeed().
2875 :
2876 : -- ALGLIB --
2877 : Copyright 11.08.2007 by Bochkanov Sergey
2878 : *************************************************************************/
2879 0 : double hqrndexponential(const hqrndstate &state, const double lambdav, const xparams _xparams)
2880 : {
2881 : jmp_buf _break_jump;
2882 : alglib_impl::ae_state _alglib_env_state;
2883 0 : alglib_impl::ae_state_init(&_alglib_env_state);
2884 0 : if( setjmp(_break_jump) )
2885 : {
2886 : #if !defined(AE_NO_EXCEPTIONS)
2887 0 : _ALGLIB_CPP_EXCEPTION(_alglib_env_state.error_msg);
2888 : #else
2889 : _ALGLIB_SET_ERROR_FLAG(_alglib_env_state.error_msg);
2890 : return 0;
2891 : #endif
2892 : }
2893 0 : ae_state_set_break_jump(&_alglib_env_state, &_break_jump);
2894 0 : if( _xparams.flags!=0x0 )
2895 0 : ae_state_set_flags(&_alglib_env_state, _xparams.flags);
2896 0 : double result = alglib_impl::hqrndexponential(const_cast<alglib_impl::hqrndstate*>(state.c_ptr()), lambdav, &_alglib_env_state);
2897 0 : alglib_impl::ae_state_clear(&_alglib_env_state);
2898 0 : return *(reinterpret_cast<double*>(&result));
2899 : }
2900 :
2901 : /*************************************************************************
2902 : This function generates random number from discrete distribution given by
2903 : finite sample X.
2904 :
2905 : INPUT PARAMETERS
2906 : State - high quality random number generator, must be
2907 : initialized with HQRNDRandomize() or HQRNDSeed().
2908 : X - finite sample
2909 : N - number of elements to use, N>=1
2910 :
2911 : RESULT
2912 : this function returns one of the X[i] for random i=0..N-1
2913 :
2914 : -- ALGLIB --
2915 : Copyright 08.11.2011 by Bochkanov Sergey
2916 : *************************************************************************/
2917 0 : double hqrnddiscrete(const hqrndstate &state, const real_1d_array &x, const ae_int_t n, const xparams _xparams)
2918 : {
2919 : jmp_buf _break_jump;
2920 : alglib_impl::ae_state _alglib_env_state;
2921 0 : alglib_impl::ae_state_init(&_alglib_env_state);
2922 0 : if( setjmp(_break_jump) )
2923 : {
2924 : #if !defined(AE_NO_EXCEPTIONS)
2925 0 : _ALGLIB_CPP_EXCEPTION(_alglib_env_state.error_msg);
2926 : #else
2927 : _ALGLIB_SET_ERROR_FLAG(_alglib_env_state.error_msg);
2928 : return 0;
2929 : #endif
2930 : }
2931 0 : ae_state_set_break_jump(&_alglib_env_state, &_break_jump);
2932 0 : if( _xparams.flags!=0x0 )
2933 0 : ae_state_set_flags(&_alglib_env_state, _xparams.flags);
2934 0 : double result = alglib_impl::hqrnddiscrete(const_cast<alglib_impl::hqrndstate*>(state.c_ptr()), const_cast<alglib_impl::ae_vector*>(x.c_ptr()), n, &_alglib_env_state);
2935 0 : alglib_impl::ae_state_clear(&_alglib_env_state);
2936 0 : return *(reinterpret_cast<double*>(&result));
2937 : }
2938 :
2939 : /*************************************************************************
2940 : This function generates random number from continuous distribution given
2941 : by finite sample X.
2942 :
2943 : INPUT PARAMETERS
2944 : State - high quality random number generator, must be
2945 : initialized with HQRNDRandomize() or HQRNDSeed().
2946 : X - finite sample, array[N] (can be larger, in this case only
2947 : leading N elements are used). THIS ARRAY MUST BE SORTED BY
2948 : ASCENDING.
2949 : N - number of elements to use, N>=1
2950 :
2951 : RESULT
2952 : this function returns random number from continuous distribution which
2953 : tries to approximate X as mush as possible. min(X)<=Result<=max(X).
2954 :
2955 : -- ALGLIB --
2956 : Copyright 08.11.2011 by Bochkanov Sergey
2957 : *************************************************************************/
2958 0 : double hqrndcontinuous(const hqrndstate &state, const real_1d_array &x, const ae_int_t n, const xparams _xparams)
2959 : {
2960 : jmp_buf _break_jump;
2961 : alglib_impl::ae_state _alglib_env_state;
2962 0 : alglib_impl::ae_state_init(&_alglib_env_state);
2963 0 : if( setjmp(_break_jump) )
2964 : {
2965 : #if !defined(AE_NO_EXCEPTIONS)
2966 0 : _ALGLIB_CPP_EXCEPTION(_alglib_env_state.error_msg);
2967 : #else
2968 : _ALGLIB_SET_ERROR_FLAG(_alglib_env_state.error_msg);
2969 : return 0;
2970 : #endif
2971 : }
2972 0 : ae_state_set_break_jump(&_alglib_env_state, &_break_jump);
2973 0 : if( _xparams.flags!=0x0 )
2974 0 : ae_state_set_flags(&_alglib_env_state, _xparams.flags);
2975 0 : double result = alglib_impl::hqrndcontinuous(const_cast<alglib_impl::hqrndstate*>(state.c_ptr()), const_cast<alglib_impl::ae_vector*>(x.c_ptr()), n, &_alglib_env_state);
2976 0 : alglib_impl::ae_state_clear(&_alglib_env_state);
2977 0 : return *(reinterpret_cast<double*>(&result));
2978 : }
2979 : #endif
2980 :
2981 : #if defined(AE_COMPILE_XDEBUG) || !defined(AE_PARTIAL_BUILD)
2982 : /*************************************************************************
2983 :
2984 : *************************************************************************/
2985 0 : _xdebugrecord1_owner::_xdebugrecord1_owner()
2986 : {
2987 : jmp_buf _break_jump;
2988 : alglib_impl::ae_state _state;
2989 :
2990 0 : alglib_impl::ae_state_init(&_state);
2991 0 : if( setjmp(_break_jump) )
2992 : {
2993 0 : if( p_struct!=NULL )
2994 : {
2995 0 : alglib_impl::_xdebugrecord1_destroy(p_struct);
2996 0 : alglib_impl::ae_free(p_struct);
2997 : }
2998 0 : p_struct = NULL;
2999 : #if !defined(AE_NO_EXCEPTIONS)
3000 0 : _ALGLIB_CPP_EXCEPTION(_state.error_msg);
3001 : #else
3002 : _ALGLIB_SET_ERROR_FLAG(_state.error_msg);
3003 : return;
3004 : #endif
3005 : }
3006 0 : alglib_impl::ae_state_set_break_jump(&_state, &_break_jump);
3007 0 : p_struct = NULL;
3008 0 : p_struct = (alglib_impl::xdebugrecord1*)alglib_impl::ae_malloc(sizeof(alglib_impl::xdebugrecord1), &_state);
3009 0 : memset(p_struct, 0, sizeof(alglib_impl::xdebugrecord1));
3010 0 : alglib_impl::_xdebugrecord1_init(p_struct, &_state, ae_false);
3011 0 : ae_state_clear(&_state);
3012 0 : }
3013 :
3014 0 : _xdebugrecord1_owner::_xdebugrecord1_owner(const _xdebugrecord1_owner &rhs)
3015 : {
3016 : jmp_buf _break_jump;
3017 : alglib_impl::ae_state _state;
3018 :
3019 0 : alglib_impl::ae_state_init(&_state);
3020 0 : if( setjmp(_break_jump) )
3021 : {
3022 0 : if( p_struct!=NULL )
3023 : {
3024 0 : alglib_impl::_xdebugrecord1_destroy(p_struct);
3025 0 : alglib_impl::ae_free(p_struct);
3026 : }
3027 0 : p_struct = NULL;
3028 : #if !defined(AE_NO_EXCEPTIONS)
3029 0 : _ALGLIB_CPP_EXCEPTION(_state.error_msg);
3030 : #else
3031 : _ALGLIB_SET_ERROR_FLAG(_state.error_msg);
3032 : return;
3033 : #endif
3034 : }
3035 0 : alglib_impl::ae_state_set_break_jump(&_state, &_break_jump);
3036 0 : p_struct = NULL;
3037 0 : alglib_impl::ae_assert(rhs.p_struct!=NULL, "ALGLIB: xdebugrecord1 copy constructor failure (source is not initialized)", &_state);
3038 0 : p_struct = (alglib_impl::xdebugrecord1*)alglib_impl::ae_malloc(sizeof(alglib_impl::xdebugrecord1), &_state);
3039 0 : memset(p_struct, 0, sizeof(alglib_impl::xdebugrecord1));
3040 0 : alglib_impl::_xdebugrecord1_init_copy(p_struct, const_cast<alglib_impl::xdebugrecord1*>(rhs.p_struct), &_state, ae_false);
3041 0 : ae_state_clear(&_state);
3042 0 : }
3043 :
3044 0 : _xdebugrecord1_owner& _xdebugrecord1_owner::operator=(const _xdebugrecord1_owner &rhs)
3045 : {
3046 0 : if( this==&rhs )
3047 0 : return *this;
3048 : jmp_buf _break_jump;
3049 : alglib_impl::ae_state _state;
3050 :
3051 0 : alglib_impl::ae_state_init(&_state);
3052 0 : if( setjmp(_break_jump) )
3053 : {
3054 : #if !defined(AE_NO_EXCEPTIONS)
3055 0 : _ALGLIB_CPP_EXCEPTION(_state.error_msg);
3056 : #else
3057 : _ALGLIB_SET_ERROR_FLAG(_state.error_msg);
3058 : return *this;
3059 : #endif
3060 : }
3061 0 : alglib_impl::ae_state_set_break_jump(&_state, &_break_jump);
3062 0 : alglib_impl::ae_assert(p_struct!=NULL, "ALGLIB: xdebugrecord1 assignment constructor failure (destination is not initialized)", &_state);
3063 0 : alglib_impl::ae_assert(rhs.p_struct!=NULL, "ALGLIB: xdebugrecord1 assignment constructor failure (source is not initialized)", &_state);
3064 0 : alglib_impl::_xdebugrecord1_destroy(p_struct);
3065 0 : memset(p_struct, 0, sizeof(alglib_impl::xdebugrecord1));
3066 0 : alglib_impl::_xdebugrecord1_init_copy(p_struct, const_cast<alglib_impl::xdebugrecord1*>(rhs.p_struct), &_state, ae_false);
3067 0 : ae_state_clear(&_state);
3068 0 : return *this;
3069 : }
3070 :
3071 0 : _xdebugrecord1_owner::~_xdebugrecord1_owner()
3072 : {
3073 0 : if( p_struct!=NULL )
3074 : {
3075 0 : alglib_impl::_xdebugrecord1_destroy(p_struct);
3076 0 : ae_free(p_struct);
3077 : }
3078 0 : }
3079 :
3080 0 : alglib_impl::xdebugrecord1* _xdebugrecord1_owner::c_ptr()
3081 : {
3082 0 : return p_struct;
3083 : }
3084 :
3085 0 : alglib_impl::xdebugrecord1* _xdebugrecord1_owner::c_ptr() const
3086 : {
3087 0 : return const_cast<alglib_impl::xdebugrecord1*>(p_struct);
3088 : }
3089 0 : xdebugrecord1::xdebugrecord1() : _xdebugrecord1_owner() ,i(p_struct->i),c(*((alglib::complex*)(&p_struct->c))),a(&p_struct->a)
3090 : {
3091 0 : }
3092 :
3093 0 : xdebugrecord1::xdebugrecord1(const xdebugrecord1 &rhs):_xdebugrecord1_owner(rhs) ,i(p_struct->i),c(*((alglib::complex*)(&p_struct->c))),a(&p_struct->a)
3094 : {
3095 0 : }
3096 :
3097 0 : xdebugrecord1& xdebugrecord1::operator=(const xdebugrecord1 &rhs)
3098 : {
3099 0 : if( this==&rhs )
3100 0 : return *this;
3101 0 : _xdebugrecord1_owner::operator=(rhs);
3102 0 : return *this;
3103 : }
3104 :
3105 0 : xdebugrecord1::~xdebugrecord1()
3106 : {
3107 0 : }
3108 :
3109 : /*************************************************************************
3110 : This is debug function intended for testing ALGLIB interface generator.
3111 : Never use it in any real life project.
3112 :
3113 : Creates and returns XDebugRecord1 structure:
3114 : * integer and complex fields of Rec1 are set to 1 and 1+i correspondingly
3115 : * array field of Rec1 is set to [2,3]
3116 :
3117 : -- ALGLIB --
3118 : Copyright 27.05.2014 by Bochkanov Sergey
3119 : *************************************************************************/
3120 0 : void xdebuginitrecord1(xdebugrecord1 &rec1, const xparams _xparams)
3121 : {
3122 : jmp_buf _break_jump;
3123 : alglib_impl::ae_state _alglib_env_state;
3124 0 : alglib_impl::ae_state_init(&_alglib_env_state);
3125 0 : if( setjmp(_break_jump) )
3126 : {
3127 : #if !defined(AE_NO_EXCEPTIONS)
3128 0 : _ALGLIB_CPP_EXCEPTION(_alglib_env_state.error_msg);
3129 : #else
3130 : _ALGLIB_SET_ERROR_FLAG(_alglib_env_state.error_msg);
3131 : return;
3132 : #endif
3133 : }
3134 0 : ae_state_set_break_jump(&_alglib_env_state, &_break_jump);
3135 0 : if( _xparams.flags!=0x0 )
3136 0 : ae_state_set_flags(&_alglib_env_state, _xparams.flags);
3137 0 : alglib_impl::xdebuginitrecord1(const_cast<alglib_impl::xdebugrecord1*>(rec1.c_ptr()), &_alglib_env_state);
3138 0 : alglib_impl::ae_state_clear(&_alglib_env_state);
3139 0 : return;
3140 : }
3141 :
3142 : /*************************************************************************
3143 : This is debug function intended for testing ALGLIB interface generator.
3144 : Never use it in any real life project.
3145 :
3146 : Counts number of True values in the boolean 1D array.
3147 :
3148 : -- ALGLIB --
3149 : Copyright 11.10.2013 by Bochkanov Sergey
3150 : *************************************************************************/
3151 0 : ae_int_t xdebugb1count(const boolean_1d_array &a, const xparams _xparams)
3152 : {
3153 : jmp_buf _break_jump;
3154 : alglib_impl::ae_state _alglib_env_state;
3155 0 : alglib_impl::ae_state_init(&_alglib_env_state);
3156 0 : if( setjmp(_break_jump) )
3157 : {
3158 : #if !defined(AE_NO_EXCEPTIONS)
3159 0 : _ALGLIB_CPP_EXCEPTION(_alglib_env_state.error_msg);
3160 : #else
3161 : _ALGLIB_SET_ERROR_FLAG(_alglib_env_state.error_msg);
3162 : return 0;
3163 : #endif
3164 : }
3165 0 : ae_state_set_break_jump(&_alglib_env_state, &_break_jump);
3166 0 : if( _xparams.flags!=0x0 )
3167 0 : ae_state_set_flags(&_alglib_env_state, _xparams.flags);
3168 0 : alglib_impl::ae_int_t result = alglib_impl::xdebugb1count(const_cast<alglib_impl::ae_vector*>(a.c_ptr()), &_alglib_env_state);
3169 0 : alglib_impl::ae_state_clear(&_alglib_env_state);
3170 0 : return *(reinterpret_cast<ae_int_t*>(&result));
3171 : }
3172 :
3173 : /*************************************************************************
3174 : This is debug function intended for testing ALGLIB interface generator.
3175 : Never use it in any real life project.
3176 :
3177 : Replace all values in array by NOT(a[i]).
3178 : Array is passed using "shared" convention.
3179 :
3180 : -- ALGLIB --
3181 : Copyright 11.10.2013 by Bochkanov Sergey
3182 : *************************************************************************/
3183 0 : void xdebugb1not(const boolean_1d_array &a, const xparams _xparams)
3184 : {
3185 : jmp_buf _break_jump;
3186 : alglib_impl::ae_state _alglib_env_state;
3187 0 : alglib_impl::ae_state_init(&_alglib_env_state);
3188 0 : if( setjmp(_break_jump) )
3189 : {
3190 : #if !defined(AE_NO_EXCEPTIONS)
3191 0 : _ALGLIB_CPP_EXCEPTION(_alglib_env_state.error_msg);
3192 : #else
3193 : _ALGLIB_SET_ERROR_FLAG(_alglib_env_state.error_msg);
3194 : return;
3195 : #endif
3196 : }
3197 0 : ae_state_set_break_jump(&_alglib_env_state, &_break_jump);
3198 0 : if( _xparams.flags!=0x0 )
3199 0 : ae_state_set_flags(&_alglib_env_state, _xparams.flags);
3200 0 : alglib_impl::xdebugb1not(const_cast<alglib_impl::ae_vector*>(a.c_ptr()), &_alglib_env_state);
3201 0 : alglib_impl::ae_state_clear(&_alglib_env_state);
3202 0 : return;
3203 : }
3204 :
3205 : /*************************************************************************
3206 : This is debug function intended for testing ALGLIB interface generator.
3207 : Never use it in any real life project.
3208 :
3209 : Appends copy of array to itself.
3210 : Array is passed using "var" convention.
3211 :
3212 : -- ALGLIB --
3213 : Copyright 11.10.2013 by Bochkanov Sergey
3214 : *************************************************************************/
3215 0 : void xdebugb1appendcopy(boolean_1d_array &a, const xparams _xparams)
3216 : {
3217 : jmp_buf _break_jump;
3218 : alglib_impl::ae_state _alglib_env_state;
3219 0 : alglib_impl::ae_state_init(&_alglib_env_state);
3220 0 : if( setjmp(_break_jump) )
3221 : {
3222 : #if !defined(AE_NO_EXCEPTIONS)
3223 0 : _ALGLIB_CPP_EXCEPTION(_alglib_env_state.error_msg);
3224 : #else
3225 : _ALGLIB_SET_ERROR_FLAG(_alglib_env_state.error_msg);
3226 : return;
3227 : #endif
3228 : }
3229 0 : ae_state_set_break_jump(&_alglib_env_state, &_break_jump);
3230 0 : if( _xparams.flags!=0x0 )
3231 0 : ae_state_set_flags(&_alglib_env_state, _xparams.flags);
3232 0 : alglib_impl::xdebugb1appendcopy(const_cast<alglib_impl::ae_vector*>(a.c_ptr()), &_alglib_env_state);
3233 0 : alglib_impl::ae_state_clear(&_alglib_env_state);
3234 0 : return;
3235 : }
3236 :
3237 : /*************************************************************************
3238 : This is debug function intended for testing ALGLIB interface generator.
3239 : Never use it in any real life project.
3240 :
3241 : Generate N-element array with even-numbered elements set to True.
3242 : Array is passed using "out" convention.
3243 :
3244 : -- ALGLIB --
3245 : Copyright 11.10.2013 by Bochkanov Sergey
3246 : *************************************************************************/
3247 0 : void xdebugb1outeven(const ae_int_t n, boolean_1d_array &a, const xparams _xparams)
3248 : {
3249 : jmp_buf _break_jump;
3250 : alglib_impl::ae_state _alglib_env_state;
3251 0 : alglib_impl::ae_state_init(&_alglib_env_state);
3252 0 : if( setjmp(_break_jump) )
3253 : {
3254 : #if !defined(AE_NO_EXCEPTIONS)
3255 0 : _ALGLIB_CPP_EXCEPTION(_alglib_env_state.error_msg);
3256 : #else
3257 : _ALGLIB_SET_ERROR_FLAG(_alglib_env_state.error_msg);
3258 : return;
3259 : #endif
3260 : }
3261 0 : ae_state_set_break_jump(&_alglib_env_state, &_break_jump);
3262 0 : if( _xparams.flags!=0x0 )
3263 0 : ae_state_set_flags(&_alglib_env_state, _xparams.flags);
3264 0 : alglib_impl::xdebugb1outeven(n, const_cast<alglib_impl::ae_vector*>(a.c_ptr()), &_alglib_env_state);
3265 0 : alglib_impl::ae_state_clear(&_alglib_env_state);
3266 0 : return;
3267 : }
3268 :
3269 : /*************************************************************************
3270 : This is debug function intended for testing ALGLIB interface generator.
3271 : Never use it in any real life project.
3272 :
3273 : Returns sum of elements in the array.
3274 :
3275 : -- ALGLIB --
3276 : Copyright 11.10.2013 by Bochkanov Sergey
3277 : *************************************************************************/
3278 0 : ae_int_t xdebugi1sum(const integer_1d_array &a, const xparams _xparams)
3279 : {
3280 : jmp_buf _break_jump;
3281 : alglib_impl::ae_state _alglib_env_state;
3282 0 : alglib_impl::ae_state_init(&_alglib_env_state);
3283 0 : if( setjmp(_break_jump) )
3284 : {
3285 : #if !defined(AE_NO_EXCEPTIONS)
3286 0 : _ALGLIB_CPP_EXCEPTION(_alglib_env_state.error_msg);
3287 : #else
3288 : _ALGLIB_SET_ERROR_FLAG(_alglib_env_state.error_msg);
3289 : return 0;
3290 : #endif
3291 : }
3292 0 : ae_state_set_break_jump(&_alglib_env_state, &_break_jump);
3293 0 : if( _xparams.flags!=0x0 )
3294 0 : ae_state_set_flags(&_alglib_env_state, _xparams.flags);
3295 0 : alglib_impl::ae_int_t result = alglib_impl::xdebugi1sum(const_cast<alglib_impl::ae_vector*>(a.c_ptr()), &_alglib_env_state);
3296 0 : alglib_impl::ae_state_clear(&_alglib_env_state);
3297 0 : return *(reinterpret_cast<ae_int_t*>(&result));
3298 : }
3299 :
3300 : /*************************************************************************
3301 : This is debug function intended for testing ALGLIB interface generator.
3302 : Never use it in any real life project.
3303 :
3304 : Replace all values in array by -A[I]
3305 : Array is passed using "shared" convention.
3306 :
3307 : -- ALGLIB --
3308 : Copyright 11.10.2013 by Bochkanov Sergey
3309 : *************************************************************************/
3310 0 : void xdebugi1neg(const integer_1d_array &a, const xparams _xparams)
3311 : {
3312 : jmp_buf _break_jump;
3313 : alglib_impl::ae_state _alglib_env_state;
3314 0 : alglib_impl::ae_state_init(&_alglib_env_state);
3315 0 : if( setjmp(_break_jump) )
3316 : {
3317 : #if !defined(AE_NO_EXCEPTIONS)
3318 0 : _ALGLIB_CPP_EXCEPTION(_alglib_env_state.error_msg);
3319 : #else
3320 : _ALGLIB_SET_ERROR_FLAG(_alglib_env_state.error_msg);
3321 : return;
3322 : #endif
3323 : }
3324 0 : ae_state_set_break_jump(&_alglib_env_state, &_break_jump);
3325 0 : if( _xparams.flags!=0x0 )
3326 0 : ae_state_set_flags(&_alglib_env_state, _xparams.flags);
3327 0 : alglib_impl::xdebugi1neg(const_cast<alglib_impl::ae_vector*>(a.c_ptr()), &_alglib_env_state);
3328 0 : alglib_impl::ae_state_clear(&_alglib_env_state);
3329 0 : return;
3330 : }
3331 :
3332 : /*************************************************************************
3333 : This is debug function intended for testing ALGLIB interface generator.
3334 : Never use it in any real life project.
3335 :
3336 : Appends copy of array to itself.
3337 : Array is passed using "var" convention.
3338 :
3339 : -- ALGLIB --
3340 : Copyright 11.10.2013 by Bochkanov Sergey
3341 : *************************************************************************/
3342 0 : void xdebugi1appendcopy(integer_1d_array &a, const xparams _xparams)
3343 : {
3344 : jmp_buf _break_jump;
3345 : alglib_impl::ae_state _alglib_env_state;
3346 0 : alglib_impl::ae_state_init(&_alglib_env_state);
3347 0 : if( setjmp(_break_jump) )
3348 : {
3349 : #if !defined(AE_NO_EXCEPTIONS)
3350 0 : _ALGLIB_CPP_EXCEPTION(_alglib_env_state.error_msg);
3351 : #else
3352 : _ALGLIB_SET_ERROR_FLAG(_alglib_env_state.error_msg);
3353 : return;
3354 : #endif
3355 : }
3356 0 : ae_state_set_break_jump(&_alglib_env_state, &_break_jump);
3357 0 : if( _xparams.flags!=0x0 )
3358 0 : ae_state_set_flags(&_alglib_env_state, _xparams.flags);
3359 0 : alglib_impl::xdebugi1appendcopy(const_cast<alglib_impl::ae_vector*>(a.c_ptr()), &_alglib_env_state);
3360 0 : alglib_impl::ae_state_clear(&_alglib_env_state);
3361 0 : return;
3362 : }
3363 :
3364 : /*************************************************************************
3365 : This is debug function intended for testing ALGLIB interface generator.
3366 : Never use it in any real life project.
3367 :
3368 : Generate N-element array with even-numbered A[I] set to I, and odd-numbered
3369 : ones set to 0.
3370 :
3371 : Array is passed using "out" convention.
3372 :
3373 : -- ALGLIB --
3374 : Copyright 11.10.2013 by Bochkanov Sergey
3375 : *************************************************************************/
3376 0 : void xdebugi1outeven(const ae_int_t n, integer_1d_array &a, const xparams _xparams)
3377 : {
3378 : jmp_buf _break_jump;
3379 : alglib_impl::ae_state _alglib_env_state;
3380 0 : alglib_impl::ae_state_init(&_alglib_env_state);
3381 0 : if( setjmp(_break_jump) )
3382 : {
3383 : #if !defined(AE_NO_EXCEPTIONS)
3384 0 : _ALGLIB_CPP_EXCEPTION(_alglib_env_state.error_msg);
3385 : #else
3386 : _ALGLIB_SET_ERROR_FLAG(_alglib_env_state.error_msg);
3387 : return;
3388 : #endif
3389 : }
3390 0 : ae_state_set_break_jump(&_alglib_env_state, &_break_jump);
3391 0 : if( _xparams.flags!=0x0 )
3392 0 : ae_state_set_flags(&_alglib_env_state, _xparams.flags);
3393 0 : alglib_impl::xdebugi1outeven(n, const_cast<alglib_impl::ae_vector*>(a.c_ptr()), &_alglib_env_state);
3394 0 : alglib_impl::ae_state_clear(&_alglib_env_state);
3395 0 : return;
3396 : }
3397 :
3398 : /*************************************************************************
3399 : This is debug function intended for testing ALGLIB interface generator.
3400 : Never use it in any real life project.
3401 :
3402 : Returns sum of elements in the array.
3403 :
3404 : -- ALGLIB --
3405 : Copyright 11.10.2013 by Bochkanov Sergey
3406 : *************************************************************************/
3407 0 : double xdebugr1sum(const real_1d_array &a, const xparams _xparams)
3408 : {
3409 : jmp_buf _break_jump;
3410 : alglib_impl::ae_state _alglib_env_state;
3411 0 : alglib_impl::ae_state_init(&_alglib_env_state);
3412 0 : if( setjmp(_break_jump) )
3413 : {
3414 : #if !defined(AE_NO_EXCEPTIONS)
3415 0 : _ALGLIB_CPP_EXCEPTION(_alglib_env_state.error_msg);
3416 : #else
3417 : _ALGLIB_SET_ERROR_FLAG(_alglib_env_state.error_msg);
3418 : return 0;
3419 : #endif
3420 : }
3421 0 : ae_state_set_break_jump(&_alglib_env_state, &_break_jump);
3422 0 : if( _xparams.flags!=0x0 )
3423 0 : ae_state_set_flags(&_alglib_env_state, _xparams.flags);
3424 0 : double result = alglib_impl::xdebugr1sum(const_cast<alglib_impl::ae_vector*>(a.c_ptr()), &_alglib_env_state);
3425 0 : alglib_impl::ae_state_clear(&_alglib_env_state);
3426 0 : return *(reinterpret_cast<double*>(&result));
3427 : }
3428 :
3429 : /*************************************************************************
3430 : This is debug function intended for testing ALGLIB interface generator.
3431 : Never use it in any real life project.
3432 :
3433 : Replace all values in array by -A[I]
3434 : Array is passed using "shared" convention.
3435 :
3436 : -- ALGLIB --
3437 : Copyright 11.10.2013 by Bochkanov Sergey
3438 : *************************************************************************/
3439 0 : void xdebugr1neg(const real_1d_array &a, const xparams _xparams)
3440 : {
3441 : jmp_buf _break_jump;
3442 : alglib_impl::ae_state _alglib_env_state;
3443 0 : alglib_impl::ae_state_init(&_alglib_env_state);
3444 0 : if( setjmp(_break_jump) )
3445 : {
3446 : #if !defined(AE_NO_EXCEPTIONS)
3447 0 : _ALGLIB_CPP_EXCEPTION(_alglib_env_state.error_msg);
3448 : #else
3449 : _ALGLIB_SET_ERROR_FLAG(_alglib_env_state.error_msg);
3450 : return;
3451 : #endif
3452 : }
3453 0 : ae_state_set_break_jump(&_alglib_env_state, &_break_jump);
3454 0 : if( _xparams.flags!=0x0 )
3455 0 : ae_state_set_flags(&_alglib_env_state, _xparams.flags);
3456 0 : alglib_impl::xdebugr1neg(const_cast<alglib_impl::ae_vector*>(a.c_ptr()), &_alglib_env_state);
3457 0 : alglib_impl::ae_state_clear(&_alglib_env_state);
3458 0 : return;
3459 : }
3460 :
3461 : /*************************************************************************
3462 : This is debug function intended for testing ALGLIB interface generator.
3463 : Never use it in any real life project.
3464 :
3465 : Appends copy of array to itself.
3466 : Array is passed using "var" convention.
3467 :
3468 : -- ALGLIB --
3469 : Copyright 11.10.2013 by Bochkanov Sergey
3470 : *************************************************************************/
3471 0 : void xdebugr1appendcopy(real_1d_array &a, const xparams _xparams)
3472 : {
3473 : jmp_buf _break_jump;
3474 : alglib_impl::ae_state _alglib_env_state;
3475 0 : alglib_impl::ae_state_init(&_alglib_env_state);
3476 0 : if( setjmp(_break_jump) )
3477 : {
3478 : #if !defined(AE_NO_EXCEPTIONS)
3479 0 : _ALGLIB_CPP_EXCEPTION(_alglib_env_state.error_msg);
3480 : #else
3481 : _ALGLIB_SET_ERROR_FLAG(_alglib_env_state.error_msg);
3482 : return;
3483 : #endif
3484 : }
3485 0 : ae_state_set_break_jump(&_alglib_env_state, &_break_jump);
3486 0 : if( _xparams.flags!=0x0 )
3487 0 : ae_state_set_flags(&_alglib_env_state, _xparams.flags);
3488 0 : alglib_impl::xdebugr1appendcopy(const_cast<alglib_impl::ae_vector*>(a.c_ptr()), &_alglib_env_state);
3489 0 : alglib_impl::ae_state_clear(&_alglib_env_state);
3490 0 : return;
3491 : }
3492 :
3493 : /*************************************************************************
3494 : This is debug function intended for testing ALGLIB interface generator.
3495 : Never use it in any real life project.
3496 :
3497 : Generate N-element array with even-numbered A[I] set to I*0.25,
3498 : and odd-numbered ones are set to 0.
3499 :
3500 : Array is passed using "out" convention.
3501 :
3502 : -- ALGLIB --
3503 : Copyright 11.10.2013 by Bochkanov Sergey
3504 : *************************************************************************/
3505 0 : void xdebugr1outeven(const ae_int_t n, real_1d_array &a, const xparams _xparams)
3506 : {
3507 : jmp_buf _break_jump;
3508 : alglib_impl::ae_state _alglib_env_state;
3509 0 : alglib_impl::ae_state_init(&_alglib_env_state);
3510 0 : if( setjmp(_break_jump) )
3511 : {
3512 : #if !defined(AE_NO_EXCEPTIONS)
3513 0 : _ALGLIB_CPP_EXCEPTION(_alglib_env_state.error_msg);
3514 : #else
3515 : _ALGLIB_SET_ERROR_FLAG(_alglib_env_state.error_msg);
3516 : return;
3517 : #endif
3518 : }
3519 0 : ae_state_set_break_jump(&_alglib_env_state, &_break_jump);
3520 0 : if( _xparams.flags!=0x0 )
3521 0 : ae_state_set_flags(&_alglib_env_state, _xparams.flags);
3522 0 : alglib_impl::xdebugr1outeven(n, const_cast<alglib_impl::ae_vector*>(a.c_ptr()), &_alglib_env_state);
3523 0 : alglib_impl::ae_state_clear(&_alglib_env_state);
3524 0 : return;
3525 : }
3526 :
3527 : /*************************************************************************
3528 : This is debug function intended for testing ALGLIB interface generator.
3529 : Never use it in any real life project.
3530 :
3531 : Returns sum of elements in the array.
3532 :
3533 : -- ALGLIB --
3534 : Copyright 11.10.2013 by Bochkanov Sergey
3535 : *************************************************************************/
3536 0 : alglib::complex xdebugc1sum(const complex_1d_array &a, const xparams _xparams)
3537 : {
3538 : jmp_buf _break_jump;
3539 : alglib_impl::ae_state _alglib_env_state;
3540 0 : alglib_impl::ae_state_init(&_alglib_env_state);
3541 0 : if( setjmp(_break_jump) )
3542 : {
3543 : #if !defined(AE_NO_EXCEPTIONS)
3544 0 : _ALGLIB_CPP_EXCEPTION(_alglib_env_state.error_msg);
3545 : #else
3546 : _ALGLIB_SET_ERROR_FLAG(_alglib_env_state.error_msg);
3547 : return 0;
3548 : #endif
3549 : }
3550 0 : ae_state_set_break_jump(&_alglib_env_state, &_break_jump);
3551 0 : if( _xparams.flags!=0x0 )
3552 0 : ae_state_set_flags(&_alglib_env_state, _xparams.flags);
3553 0 : alglib_impl::ae_complex result = alglib_impl::xdebugc1sum(const_cast<alglib_impl::ae_vector*>(a.c_ptr()), &_alglib_env_state);
3554 0 : alglib_impl::ae_state_clear(&_alglib_env_state);
3555 0 : return *(reinterpret_cast<alglib::complex*>(&result));
3556 : }
3557 :
3558 : /*************************************************************************
3559 : This is debug function intended for testing ALGLIB interface generator.
3560 : Never use it in any real life project.
3561 :
3562 : Replace all values in array by -A[I]
3563 : Array is passed using "shared" convention.
3564 :
3565 : -- ALGLIB --
3566 : Copyright 11.10.2013 by Bochkanov Sergey
3567 : *************************************************************************/
3568 0 : void xdebugc1neg(const complex_1d_array &a, const xparams _xparams)
3569 : {
3570 : jmp_buf _break_jump;
3571 : alglib_impl::ae_state _alglib_env_state;
3572 0 : alglib_impl::ae_state_init(&_alglib_env_state);
3573 0 : if( setjmp(_break_jump) )
3574 : {
3575 : #if !defined(AE_NO_EXCEPTIONS)
3576 0 : _ALGLIB_CPP_EXCEPTION(_alglib_env_state.error_msg);
3577 : #else
3578 : _ALGLIB_SET_ERROR_FLAG(_alglib_env_state.error_msg);
3579 : return;
3580 : #endif
3581 : }
3582 0 : ae_state_set_break_jump(&_alglib_env_state, &_break_jump);
3583 0 : if( _xparams.flags!=0x0 )
3584 0 : ae_state_set_flags(&_alglib_env_state, _xparams.flags);
3585 0 : alglib_impl::xdebugc1neg(const_cast<alglib_impl::ae_vector*>(a.c_ptr()), &_alglib_env_state);
3586 0 : alglib_impl::ae_state_clear(&_alglib_env_state);
3587 0 : return;
3588 : }
3589 :
3590 : /*************************************************************************
3591 : This is debug function intended for testing ALGLIB interface generator.
3592 : Never use it in any real life project.
3593 :
3594 : Appends copy of array to itself.
3595 : Array is passed using "var" convention.
3596 :
3597 : -- ALGLIB --
3598 : Copyright 11.10.2013 by Bochkanov Sergey
3599 : *************************************************************************/
3600 0 : void xdebugc1appendcopy(complex_1d_array &a, const xparams _xparams)
3601 : {
3602 : jmp_buf _break_jump;
3603 : alglib_impl::ae_state _alglib_env_state;
3604 0 : alglib_impl::ae_state_init(&_alglib_env_state);
3605 0 : if( setjmp(_break_jump) )
3606 : {
3607 : #if !defined(AE_NO_EXCEPTIONS)
3608 0 : _ALGLIB_CPP_EXCEPTION(_alglib_env_state.error_msg);
3609 : #else
3610 : _ALGLIB_SET_ERROR_FLAG(_alglib_env_state.error_msg);
3611 : return;
3612 : #endif
3613 : }
3614 0 : ae_state_set_break_jump(&_alglib_env_state, &_break_jump);
3615 0 : if( _xparams.flags!=0x0 )
3616 0 : ae_state_set_flags(&_alglib_env_state, _xparams.flags);
3617 0 : alglib_impl::xdebugc1appendcopy(const_cast<alglib_impl::ae_vector*>(a.c_ptr()), &_alglib_env_state);
3618 0 : alglib_impl::ae_state_clear(&_alglib_env_state);
3619 0 : return;
3620 : }
3621 :
3622 : /*************************************************************************
3623 : This is debug function intended for testing ALGLIB interface generator.
3624 : Never use it in any real life project.
3625 :
3626 : Generate N-element array with even-numbered A[K] set to (x,y) = (K*0.25, K*0.125)
3627 : and odd-numbered ones are set to 0.
3628 :
3629 : Array is passed using "out" convention.
3630 :
3631 : -- ALGLIB --
3632 : Copyright 11.10.2013 by Bochkanov Sergey
3633 : *************************************************************************/
3634 0 : void xdebugc1outeven(const ae_int_t n, complex_1d_array &a, const xparams _xparams)
3635 : {
3636 : jmp_buf _break_jump;
3637 : alglib_impl::ae_state _alglib_env_state;
3638 0 : alglib_impl::ae_state_init(&_alglib_env_state);
3639 0 : if( setjmp(_break_jump) )
3640 : {
3641 : #if !defined(AE_NO_EXCEPTIONS)
3642 0 : _ALGLIB_CPP_EXCEPTION(_alglib_env_state.error_msg);
3643 : #else
3644 : _ALGLIB_SET_ERROR_FLAG(_alglib_env_state.error_msg);
3645 : return;
3646 : #endif
3647 : }
3648 0 : ae_state_set_break_jump(&_alglib_env_state, &_break_jump);
3649 0 : if( _xparams.flags!=0x0 )
3650 0 : ae_state_set_flags(&_alglib_env_state, _xparams.flags);
3651 0 : alglib_impl::xdebugc1outeven(n, const_cast<alglib_impl::ae_vector*>(a.c_ptr()), &_alglib_env_state);
3652 0 : alglib_impl::ae_state_clear(&_alglib_env_state);
3653 0 : return;
3654 : }
3655 :
3656 : /*************************************************************************
3657 : This is debug function intended for testing ALGLIB interface generator.
3658 : Never use it in any real life project.
3659 :
3660 : Counts number of True values in the boolean 2D array.
3661 :
3662 : -- ALGLIB --
3663 : Copyright 11.10.2013 by Bochkanov Sergey
3664 : *************************************************************************/
3665 0 : ae_int_t xdebugb2count(const boolean_2d_array &a, const xparams _xparams)
3666 : {
3667 : jmp_buf _break_jump;
3668 : alglib_impl::ae_state _alglib_env_state;
3669 0 : alglib_impl::ae_state_init(&_alglib_env_state);
3670 0 : if( setjmp(_break_jump) )
3671 : {
3672 : #if !defined(AE_NO_EXCEPTIONS)
3673 0 : _ALGLIB_CPP_EXCEPTION(_alglib_env_state.error_msg);
3674 : #else
3675 : _ALGLIB_SET_ERROR_FLAG(_alglib_env_state.error_msg);
3676 : return 0;
3677 : #endif
3678 : }
3679 0 : ae_state_set_break_jump(&_alglib_env_state, &_break_jump);
3680 0 : if( _xparams.flags!=0x0 )
3681 0 : ae_state_set_flags(&_alglib_env_state, _xparams.flags);
3682 0 : alglib_impl::ae_int_t result = alglib_impl::xdebugb2count(const_cast<alglib_impl::ae_matrix*>(a.c_ptr()), &_alglib_env_state);
3683 0 : alglib_impl::ae_state_clear(&_alglib_env_state);
3684 0 : return *(reinterpret_cast<ae_int_t*>(&result));
3685 : }
3686 :
3687 : /*************************************************************************
3688 : This is debug function intended for testing ALGLIB interface generator.
3689 : Never use it in any real life project.
3690 :
3691 : Replace all values in array by NOT(a[i]).
3692 : Array is passed using "shared" convention.
3693 :
3694 : -- ALGLIB --
3695 : Copyright 11.10.2013 by Bochkanov Sergey
3696 : *************************************************************************/
3697 0 : void xdebugb2not(const boolean_2d_array &a, const xparams _xparams)
3698 : {
3699 : jmp_buf _break_jump;
3700 : alglib_impl::ae_state _alglib_env_state;
3701 0 : alglib_impl::ae_state_init(&_alglib_env_state);
3702 0 : if( setjmp(_break_jump) )
3703 : {
3704 : #if !defined(AE_NO_EXCEPTIONS)
3705 0 : _ALGLIB_CPP_EXCEPTION(_alglib_env_state.error_msg);
3706 : #else
3707 : _ALGLIB_SET_ERROR_FLAG(_alglib_env_state.error_msg);
3708 : return;
3709 : #endif
3710 : }
3711 0 : ae_state_set_break_jump(&_alglib_env_state, &_break_jump);
3712 0 : if( _xparams.flags!=0x0 )
3713 0 : ae_state_set_flags(&_alglib_env_state, _xparams.flags);
3714 0 : alglib_impl::xdebugb2not(const_cast<alglib_impl::ae_matrix*>(a.c_ptr()), &_alglib_env_state);
3715 0 : alglib_impl::ae_state_clear(&_alglib_env_state);
3716 0 : return;
3717 : }
3718 :
3719 : /*************************************************************************
3720 : This is debug function intended for testing ALGLIB interface generator.
3721 : Never use it in any real life project.
3722 :
3723 : Transposes array.
3724 : Array is passed using "var" convention.
3725 :
3726 : -- ALGLIB --
3727 : Copyright 11.10.2013 by Bochkanov Sergey
3728 : *************************************************************************/
3729 0 : void xdebugb2transpose(boolean_2d_array &a, const xparams _xparams)
3730 : {
3731 : jmp_buf _break_jump;
3732 : alglib_impl::ae_state _alglib_env_state;
3733 0 : alglib_impl::ae_state_init(&_alglib_env_state);
3734 0 : if( setjmp(_break_jump) )
3735 : {
3736 : #if !defined(AE_NO_EXCEPTIONS)
3737 0 : _ALGLIB_CPP_EXCEPTION(_alglib_env_state.error_msg);
3738 : #else
3739 : _ALGLIB_SET_ERROR_FLAG(_alglib_env_state.error_msg);
3740 : return;
3741 : #endif
3742 : }
3743 0 : ae_state_set_break_jump(&_alglib_env_state, &_break_jump);
3744 0 : if( _xparams.flags!=0x0 )
3745 0 : ae_state_set_flags(&_alglib_env_state, _xparams.flags);
3746 0 : alglib_impl::xdebugb2transpose(const_cast<alglib_impl::ae_matrix*>(a.c_ptr()), &_alglib_env_state);
3747 0 : alglib_impl::ae_state_clear(&_alglib_env_state);
3748 0 : return;
3749 : }
3750 :
3751 : /*************************************************************************
3752 : This is debug function intended for testing ALGLIB interface generator.
3753 : Never use it in any real life project.
3754 :
3755 : Generate MxN matrix with elements set to "Sin(3*I+5*J)>0"
3756 : Array is passed using "out" convention.
3757 :
3758 : -- ALGLIB --
3759 : Copyright 11.10.2013 by Bochkanov Sergey
3760 : *************************************************************************/
3761 0 : void xdebugb2outsin(const ae_int_t m, const ae_int_t n, boolean_2d_array &a, const xparams _xparams)
3762 : {
3763 : jmp_buf _break_jump;
3764 : alglib_impl::ae_state _alglib_env_state;
3765 0 : alglib_impl::ae_state_init(&_alglib_env_state);
3766 0 : if( setjmp(_break_jump) )
3767 : {
3768 : #if !defined(AE_NO_EXCEPTIONS)
3769 0 : _ALGLIB_CPP_EXCEPTION(_alglib_env_state.error_msg);
3770 : #else
3771 : _ALGLIB_SET_ERROR_FLAG(_alglib_env_state.error_msg);
3772 : return;
3773 : #endif
3774 : }
3775 0 : ae_state_set_break_jump(&_alglib_env_state, &_break_jump);
3776 0 : if( _xparams.flags!=0x0 )
3777 0 : ae_state_set_flags(&_alglib_env_state, _xparams.flags);
3778 0 : alglib_impl::xdebugb2outsin(m, n, const_cast<alglib_impl::ae_matrix*>(a.c_ptr()), &_alglib_env_state);
3779 0 : alglib_impl::ae_state_clear(&_alglib_env_state);
3780 0 : return;
3781 : }
3782 :
3783 : /*************************************************************************
3784 : This is debug function intended for testing ALGLIB interface generator.
3785 : Never use it in any real life project.
3786 :
3787 : Returns sum of elements in the array.
3788 :
3789 : -- ALGLIB --
3790 : Copyright 11.10.2013 by Bochkanov Sergey
3791 : *************************************************************************/
3792 0 : ae_int_t xdebugi2sum(const integer_2d_array &a, const xparams _xparams)
3793 : {
3794 : jmp_buf _break_jump;
3795 : alglib_impl::ae_state _alglib_env_state;
3796 0 : alglib_impl::ae_state_init(&_alglib_env_state);
3797 0 : if( setjmp(_break_jump) )
3798 : {
3799 : #if !defined(AE_NO_EXCEPTIONS)
3800 0 : _ALGLIB_CPP_EXCEPTION(_alglib_env_state.error_msg);
3801 : #else
3802 : _ALGLIB_SET_ERROR_FLAG(_alglib_env_state.error_msg);
3803 : return 0;
3804 : #endif
3805 : }
3806 0 : ae_state_set_break_jump(&_alglib_env_state, &_break_jump);
3807 0 : if( _xparams.flags!=0x0 )
3808 0 : ae_state_set_flags(&_alglib_env_state, _xparams.flags);
3809 0 : alglib_impl::ae_int_t result = alglib_impl::xdebugi2sum(const_cast<alglib_impl::ae_matrix*>(a.c_ptr()), &_alglib_env_state);
3810 0 : alglib_impl::ae_state_clear(&_alglib_env_state);
3811 0 : return *(reinterpret_cast<ae_int_t*>(&result));
3812 : }
3813 :
3814 : /*************************************************************************
3815 : This is debug function intended for testing ALGLIB interface generator.
3816 : Never use it in any real life project.
3817 :
3818 : Replace all values in array by -a[i,j]
3819 : Array is passed using "shared" convention.
3820 :
3821 : -- ALGLIB --
3822 : Copyright 11.10.2013 by Bochkanov Sergey
3823 : *************************************************************************/
3824 0 : void xdebugi2neg(const integer_2d_array &a, const xparams _xparams)
3825 : {
3826 : jmp_buf _break_jump;
3827 : alglib_impl::ae_state _alglib_env_state;
3828 0 : alglib_impl::ae_state_init(&_alglib_env_state);
3829 0 : if( setjmp(_break_jump) )
3830 : {
3831 : #if !defined(AE_NO_EXCEPTIONS)
3832 0 : _ALGLIB_CPP_EXCEPTION(_alglib_env_state.error_msg);
3833 : #else
3834 : _ALGLIB_SET_ERROR_FLAG(_alglib_env_state.error_msg);
3835 : return;
3836 : #endif
3837 : }
3838 0 : ae_state_set_break_jump(&_alglib_env_state, &_break_jump);
3839 0 : if( _xparams.flags!=0x0 )
3840 0 : ae_state_set_flags(&_alglib_env_state, _xparams.flags);
3841 0 : alglib_impl::xdebugi2neg(const_cast<alglib_impl::ae_matrix*>(a.c_ptr()), &_alglib_env_state);
3842 0 : alglib_impl::ae_state_clear(&_alglib_env_state);
3843 0 : return;
3844 : }
3845 :
3846 : /*************************************************************************
3847 : This is debug function intended for testing ALGLIB interface generator.
3848 : Never use it in any real life project.
3849 :
3850 : Transposes array.
3851 : Array is passed using "var" convention.
3852 :
3853 : -- ALGLIB --
3854 : Copyright 11.10.2013 by Bochkanov Sergey
3855 : *************************************************************************/
3856 0 : void xdebugi2transpose(integer_2d_array &a, const xparams _xparams)
3857 : {
3858 : jmp_buf _break_jump;
3859 : alglib_impl::ae_state _alglib_env_state;
3860 0 : alglib_impl::ae_state_init(&_alglib_env_state);
3861 0 : if( setjmp(_break_jump) )
3862 : {
3863 : #if !defined(AE_NO_EXCEPTIONS)
3864 0 : _ALGLIB_CPP_EXCEPTION(_alglib_env_state.error_msg);
3865 : #else
3866 : _ALGLIB_SET_ERROR_FLAG(_alglib_env_state.error_msg);
3867 : return;
3868 : #endif
3869 : }
3870 0 : ae_state_set_break_jump(&_alglib_env_state, &_break_jump);
3871 0 : if( _xparams.flags!=0x0 )
3872 0 : ae_state_set_flags(&_alglib_env_state, _xparams.flags);
3873 0 : alglib_impl::xdebugi2transpose(const_cast<alglib_impl::ae_matrix*>(a.c_ptr()), &_alglib_env_state);
3874 0 : alglib_impl::ae_state_clear(&_alglib_env_state);
3875 0 : return;
3876 : }
3877 :
3878 : /*************************************************************************
3879 : This is debug function intended for testing ALGLIB interface generator.
3880 : Never use it in any real life project.
3881 :
3882 : Generate MxN matrix with elements set to "Sign(Sin(3*I+5*J))"
3883 : Array is passed using "out" convention.
3884 :
3885 : -- ALGLIB --
3886 : Copyright 11.10.2013 by Bochkanov Sergey
3887 : *************************************************************************/
3888 0 : void xdebugi2outsin(const ae_int_t m, const ae_int_t n, integer_2d_array &a, const xparams _xparams)
3889 : {
3890 : jmp_buf _break_jump;
3891 : alglib_impl::ae_state _alglib_env_state;
3892 0 : alglib_impl::ae_state_init(&_alglib_env_state);
3893 0 : if( setjmp(_break_jump) )
3894 : {
3895 : #if !defined(AE_NO_EXCEPTIONS)
3896 0 : _ALGLIB_CPP_EXCEPTION(_alglib_env_state.error_msg);
3897 : #else
3898 : _ALGLIB_SET_ERROR_FLAG(_alglib_env_state.error_msg);
3899 : return;
3900 : #endif
3901 : }
3902 0 : ae_state_set_break_jump(&_alglib_env_state, &_break_jump);
3903 0 : if( _xparams.flags!=0x0 )
3904 0 : ae_state_set_flags(&_alglib_env_state, _xparams.flags);
3905 0 : alglib_impl::xdebugi2outsin(m, n, const_cast<alglib_impl::ae_matrix*>(a.c_ptr()), &_alglib_env_state);
3906 0 : alglib_impl::ae_state_clear(&_alglib_env_state);
3907 0 : return;
3908 : }
3909 :
3910 : /*************************************************************************
3911 : This is debug function intended for testing ALGLIB interface generator.
3912 : Never use it in any real life project.
3913 :
3914 : Returns sum of elements in the array.
3915 :
3916 : -- ALGLIB --
3917 : Copyright 11.10.2013 by Bochkanov Sergey
3918 : *************************************************************************/
3919 0 : double xdebugr2sum(const real_2d_array &a, const xparams _xparams)
3920 : {
3921 : jmp_buf _break_jump;
3922 : alglib_impl::ae_state _alglib_env_state;
3923 0 : alglib_impl::ae_state_init(&_alglib_env_state);
3924 0 : if( setjmp(_break_jump) )
3925 : {
3926 : #if !defined(AE_NO_EXCEPTIONS)
3927 0 : _ALGLIB_CPP_EXCEPTION(_alglib_env_state.error_msg);
3928 : #else
3929 : _ALGLIB_SET_ERROR_FLAG(_alglib_env_state.error_msg);
3930 : return 0;
3931 : #endif
3932 : }
3933 0 : ae_state_set_break_jump(&_alglib_env_state, &_break_jump);
3934 0 : if( _xparams.flags!=0x0 )
3935 0 : ae_state_set_flags(&_alglib_env_state, _xparams.flags);
3936 0 : double result = alglib_impl::xdebugr2sum(const_cast<alglib_impl::ae_matrix*>(a.c_ptr()), &_alglib_env_state);
3937 0 : alglib_impl::ae_state_clear(&_alglib_env_state);
3938 0 : return *(reinterpret_cast<double*>(&result));
3939 : }
3940 :
3941 : /*************************************************************************
3942 : This is debug function intended for testing ALGLIB interface generator.
3943 : Never use it in any real life project.
3944 :
3945 : Replace all values in array by -a[i,j]
3946 : Array is passed using "shared" convention.
3947 :
3948 : -- ALGLIB --
3949 : Copyright 11.10.2013 by Bochkanov Sergey
3950 : *************************************************************************/
3951 0 : void xdebugr2neg(const real_2d_array &a, const xparams _xparams)
3952 : {
3953 : jmp_buf _break_jump;
3954 : alglib_impl::ae_state _alglib_env_state;
3955 0 : alglib_impl::ae_state_init(&_alglib_env_state);
3956 0 : if( setjmp(_break_jump) )
3957 : {
3958 : #if !defined(AE_NO_EXCEPTIONS)
3959 0 : _ALGLIB_CPP_EXCEPTION(_alglib_env_state.error_msg);
3960 : #else
3961 : _ALGLIB_SET_ERROR_FLAG(_alglib_env_state.error_msg);
3962 : return;
3963 : #endif
3964 : }
3965 0 : ae_state_set_break_jump(&_alglib_env_state, &_break_jump);
3966 0 : if( _xparams.flags!=0x0 )
3967 0 : ae_state_set_flags(&_alglib_env_state, _xparams.flags);
3968 0 : alglib_impl::xdebugr2neg(const_cast<alglib_impl::ae_matrix*>(a.c_ptr()), &_alglib_env_state);
3969 0 : alglib_impl::ae_state_clear(&_alglib_env_state);
3970 0 : return;
3971 : }
3972 :
3973 : /*************************************************************************
3974 : This is debug function intended for testing ALGLIB interface generator.
3975 : Never use it in any real life project.
3976 :
3977 : Transposes array.
3978 : Array is passed using "var" convention.
3979 :
3980 : -- ALGLIB --
3981 : Copyright 11.10.2013 by Bochkanov Sergey
3982 : *************************************************************************/
3983 0 : void xdebugr2transpose(real_2d_array &a, const xparams _xparams)
3984 : {
3985 : jmp_buf _break_jump;
3986 : alglib_impl::ae_state _alglib_env_state;
3987 0 : alglib_impl::ae_state_init(&_alglib_env_state);
3988 0 : if( setjmp(_break_jump) )
3989 : {
3990 : #if !defined(AE_NO_EXCEPTIONS)
3991 0 : _ALGLIB_CPP_EXCEPTION(_alglib_env_state.error_msg);
3992 : #else
3993 : _ALGLIB_SET_ERROR_FLAG(_alglib_env_state.error_msg);
3994 : return;
3995 : #endif
3996 : }
3997 0 : ae_state_set_break_jump(&_alglib_env_state, &_break_jump);
3998 0 : if( _xparams.flags!=0x0 )
3999 0 : ae_state_set_flags(&_alglib_env_state, _xparams.flags);
4000 0 : alglib_impl::xdebugr2transpose(const_cast<alglib_impl::ae_matrix*>(a.c_ptr()), &_alglib_env_state);
4001 0 : alglib_impl::ae_state_clear(&_alglib_env_state);
4002 0 : return;
4003 : }
4004 :
4005 : /*************************************************************************
4006 : This is debug function intended for testing ALGLIB interface generator.
4007 : Never use it in any real life project.
4008 :
4009 : Generate MxN matrix with elements set to "Sin(3*I+5*J)"
4010 : Array is passed using "out" convention.
4011 :
4012 : -- ALGLIB --
4013 : Copyright 11.10.2013 by Bochkanov Sergey
4014 : *************************************************************************/
4015 0 : void xdebugr2outsin(const ae_int_t m, const ae_int_t n, real_2d_array &a, const xparams _xparams)
4016 : {
4017 : jmp_buf _break_jump;
4018 : alglib_impl::ae_state _alglib_env_state;
4019 0 : alglib_impl::ae_state_init(&_alglib_env_state);
4020 0 : if( setjmp(_break_jump) )
4021 : {
4022 : #if !defined(AE_NO_EXCEPTIONS)
4023 0 : _ALGLIB_CPP_EXCEPTION(_alglib_env_state.error_msg);
4024 : #else
4025 : _ALGLIB_SET_ERROR_FLAG(_alglib_env_state.error_msg);
4026 : return;
4027 : #endif
4028 : }
4029 0 : ae_state_set_break_jump(&_alglib_env_state, &_break_jump);
4030 0 : if( _xparams.flags!=0x0 )
4031 0 : ae_state_set_flags(&_alglib_env_state, _xparams.flags);
4032 0 : alglib_impl::xdebugr2outsin(m, n, const_cast<alglib_impl::ae_matrix*>(a.c_ptr()), &_alglib_env_state);
4033 0 : alglib_impl::ae_state_clear(&_alglib_env_state);
4034 0 : return;
4035 : }
4036 :
4037 : /*************************************************************************
4038 : This is debug function intended for testing ALGLIB interface generator.
4039 : Never use it in any real life project.
4040 :
4041 : Returns sum of elements in the array.
4042 :
4043 : -- ALGLIB --
4044 : Copyright 11.10.2013 by Bochkanov Sergey
4045 : *************************************************************************/
4046 0 : alglib::complex xdebugc2sum(const complex_2d_array &a, const xparams _xparams)
4047 : {
4048 : jmp_buf _break_jump;
4049 : alglib_impl::ae_state _alglib_env_state;
4050 0 : alglib_impl::ae_state_init(&_alglib_env_state);
4051 0 : if( setjmp(_break_jump) )
4052 : {
4053 : #if !defined(AE_NO_EXCEPTIONS)
4054 0 : _ALGLIB_CPP_EXCEPTION(_alglib_env_state.error_msg);
4055 : #else
4056 : _ALGLIB_SET_ERROR_FLAG(_alglib_env_state.error_msg);
4057 : return 0;
4058 : #endif
4059 : }
4060 0 : ae_state_set_break_jump(&_alglib_env_state, &_break_jump);
4061 0 : if( _xparams.flags!=0x0 )
4062 0 : ae_state_set_flags(&_alglib_env_state, _xparams.flags);
4063 0 : alglib_impl::ae_complex result = alglib_impl::xdebugc2sum(const_cast<alglib_impl::ae_matrix*>(a.c_ptr()), &_alglib_env_state);
4064 0 : alglib_impl::ae_state_clear(&_alglib_env_state);
4065 0 : return *(reinterpret_cast<alglib::complex*>(&result));
4066 : }
4067 :
4068 : /*************************************************************************
4069 : This is debug function intended for testing ALGLIB interface generator.
4070 : Never use it in any real life project.
4071 :
4072 : Replace all values in array by -a[i,j]
4073 : Array is passed using "shared" convention.
4074 :
4075 : -- ALGLIB --
4076 : Copyright 11.10.2013 by Bochkanov Sergey
4077 : *************************************************************************/
4078 0 : void xdebugc2neg(const complex_2d_array &a, const xparams _xparams)
4079 : {
4080 : jmp_buf _break_jump;
4081 : alglib_impl::ae_state _alglib_env_state;
4082 0 : alglib_impl::ae_state_init(&_alglib_env_state);
4083 0 : if( setjmp(_break_jump) )
4084 : {
4085 : #if !defined(AE_NO_EXCEPTIONS)
4086 0 : _ALGLIB_CPP_EXCEPTION(_alglib_env_state.error_msg);
4087 : #else
4088 : _ALGLIB_SET_ERROR_FLAG(_alglib_env_state.error_msg);
4089 : return;
4090 : #endif
4091 : }
4092 0 : ae_state_set_break_jump(&_alglib_env_state, &_break_jump);
4093 0 : if( _xparams.flags!=0x0 )
4094 0 : ae_state_set_flags(&_alglib_env_state, _xparams.flags);
4095 0 : alglib_impl::xdebugc2neg(const_cast<alglib_impl::ae_matrix*>(a.c_ptr()), &_alglib_env_state);
4096 0 : alglib_impl::ae_state_clear(&_alglib_env_state);
4097 0 : return;
4098 : }
4099 :
4100 : /*************************************************************************
4101 : This is debug function intended for testing ALGLIB interface generator.
4102 : Never use it in any real life project.
4103 :
4104 : Transposes array.
4105 : Array is passed using "var" convention.
4106 :
4107 : -- ALGLIB --
4108 : Copyright 11.10.2013 by Bochkanov Sergey
4109 : *************************************************************************/
4110 0 : void xdebugc2transpose(complex_2d_array &a, const xparams _xparams)
4111 : {
4112 : jmp_buf _break_jump;
4113 : alglib_impl::ae_state _alglib_env_state;
4114 0 : alglib_impl::ae_state_init(&_alglib_env_state);
4115 0 : if( setjmp(_break_jump) )
4116 : {
4117 : #if !defined(AE_NO_EXCEPTIONS)
4118 0 : _ALGLIB_CPP_EXCEPTION(_alglib_env_state.error_msg);
4119 : #else
4120 : _ALGLIB_SET_ERROR_FLAG(_alglib_env_state.error_msg);
4121 : return;
4122 : #endif
4123 : }
4124 0 : ae_state_set_break_jump(&_alglib_env_state, &_break_jump);
4125 0 : if( _xparams.flags!=0x0 )
4126 0 : ae_state_set_flags(&_alglib_env_state, _xparams.flags);
4127 0 : alglib_impl::xdebugc2transpose(const_cast<alglib_impl::ae_matrix*>(a.c_ptr()), &_alglib_env_state);
4128 0 : alglib_impl::ae_state_clear(&_alglib_env_state);
4129 0 : return;
4130 : }
4131 :
4132 : /*************************************************************************
4133 : This is debug function intended for testing ALGLIB interface generator.
4134 : Never use it in any real life project.
4135 :
4136 : Generate MxN matrix with elements set to "Sin(3*I+5*J),Cos(3*I+5*J)"
4137 : Array is passed using "out" convention.
4138 :
4139 : -- ALGLIB --
4140 : Copyright 11.10.2013 by Bochkanov Sergey
4141 : *************************************************************************/
4142 0 : void xdebugc2outsincos(const ae_int_t m, const ae_int_t n, complex_2d_array &a, const xparams _xparams)
4143 : {
4144 : jmp_buf _break_jump;
4145 : alglib_impl::ae_state _alglib_env_state;
4146 0 : alglib_impl::ae_state_init(&_alglib_env_state);
4147 0 : if( setjmp(_break_jump) )
4148 : {
4149 : #if !defined(AE_NO_EXCEPTIONS)
4150 0 : _ALGLIB_CPP_EXCEPTION(_alglib_env_state.error_msg);
4151 : #else
4152 : _ALGLIB_SET_ERROR_FLAG(_alglib_env_state.error_msg);
4153 : return;
4154 : #endif
4155 : }
4156 0 : ae_state_set_break_jump(&_alglib_env_state, &_break_jump);
4157 0 : if( _xparams.flags!=0x0 )
4158 0 : ae_state_set_flags(&_alglib_env_state, _xparams.flags);
4159 0 : alglib_impl::xdebugc2outsincos(m, n, const_cast<alglib_impl::ae_matrix*>(a.c_ptr()), &_alglib_env_state);
4160 0 : alglib_impl::ae_state_clear(&_alglib_env_state);
4161 0 : return;
4162 : }
4163 :
4164 : /*************************************************************************
4165 : This is debug function intended for testing ALGLIB interface generator.
4166 : Never use it in any real life project.
4167 :
4168 : Returns sum of a[i,j]*(1+b[i,j]) such that c[i,j] is True
4169 :
4170 : -- ALGLIB --
4171 : Copyright 11.10.2013 by Bochkanov Sergey
4172 : *************************************************************************/
4173 0 : double xdebugmaskedbiasedproductsum(const ae_int_t m, const ae_int_t n, const real_2d_array &a, const real_2d_array &b, const boolean_2d_array &c, const xparams _xparams)
4174 : {
4175 : jmp_buf _break_jump;
4176 : alglib_impl::ae_state _alglib_env_state;
4177 0 : alglib_impl::ae_state_init(&_alglib_env_state);
4178 0 : if( setjmp(_break_jump) )
4179 : {
4180 : #if !defined(AE_NO_EXCEPTIONS)
4181 0 : _ALGLIB_CPP_EXCEPTION(_alglib_env_state.error_msg);
4182 : #else
4183 : _ALGLIB_SET_ERROR_FLAG(_alglib_env_state.error_msg);
4184 : return 0;
4185 : #endif
4186 : }
4187 0 : ae_state_set_break_jump(&_alglib_env_state, &_break_jump);
4188 0 : if( _xparams.flags!=0x0 )
4189 0 : ae_state_set_flags(&_alglib_env_state, _xparams.flags);
4190 0 : double result = alglib_impl::xdebugmaskedbiasedproductsum(m, n, const_cast<alglib_impl::ae_matrix*>(a.c_ptr()), const_cast<alglib_impl::ae_matrix*>(b.c_ptr()), const_cast<alglib_impl::ae_matrix*>(c.c_ptr()), &_alglib_env_state);
4191 0 : alglib_impl::ae_state_clear(&_alglib_env_state);
4192 0 : return *(reinterpret_cast<double*>(&result));
4193 : }
4194 : #endif
4195 : }
4196 :
4197 : /////////////////////////////////////////////////////////////////////////
4198 : //
4199 : // THIS SECTION CONTAINS IMPLEMENTATION OF COMPUTATIONAL CORE
4200 : //
4201 : /////////////////////////////////////////////////////////////////////////
4202 : namespace alglib_impl
4203 : {
4204 : #if defined(AE_COMPILE_NEARESTNEIGHBOR) || !defined(AE_PARTIAL_BUILD)
4205 : static ae_int_t nearestneighbor_splitnodesize = 6;
4206 : static ae_int_t nearestneighbor_kdtreefirstversion = 0;
4207 : static ae_int_t nearestneighbor_tsqueryrnn(kdtree* kdt,
4208 : kdtreerequestbuffer* buf,
4209 : /* Real */ ae_vector* x,
4210 : double r,
4211 : ae_bool selfmatch,
4212 : ae_bool orderedbydist,
4213 : ae_state *_state);
4214 : static void nearestneighbor_kdtreesplit(kdtree* kdt,
4215 : ae_int_t i1,
4216 : ae_int_t i2,
4217 : ae_int_t d,
4218 : double s,
4219 : ae_int_t* i3,
4220 : ae_state *_state);
4221 : static void nearestneighbor_kdtreegeneratetreerec(kdtree* kdt,
4222 : ae_int_t* nodesoffs,
4223 : ae_int_t* splitsoffs,
4224 : ae_int_t i1,
4225 : ae_int_t i2,
4226 : ae_int_t maxleafsize,
4227 : ae_state *_state);
4228 : static void nearestneighbor_kdtreequerynnrec(kdtree* kdt,
4229 : kdtreerequestbuffer* buf,
4230 : ae_int_t offs,
4231 : ae_state *_state);
4232 : static void nearestneighbor_kdtreequeryboxrec(kdtree* kdt,
4233 : kdtreerequestbuffer* buf,
4234 : ae_int_t offs,
4235 : ae_state *_state);
4236 : static void nearestneighbor_kdtreeinitbox(kdtree* kdt,
4237 : /* Real */ ae_vector* x,
4238 : kdtreerequestbuffer* buf,
4239 : ae_state *_state);
4240 : static void nearestneighbor_kdtreeallocdatasetindependent(kdtree* kdt,
4241 : ae_int_t nx,
4242 : ae_int_t ny,
4243 : ae_state *_state);
4244 : static void nearestneighbor_kdtreeallocdatasetdependent(kdtree* kdt,
4245 : ae_int_t n,
4246 : ae_int_t nx,
4247 : ae_int_t ny,
4248 : ae_state *_state);
4249 : static void nearestneighbor_checkrequestbufferconsistency(kdtree* kdt,
4250 : kdtreerequestbuffer* buf,
4251 : ae_state *_state);
4252 :
4253 :
4254 : #endif
4255 : #if defined(AE_COMPILE_HQRND) || !defined(AE_PARTIAL_BUILD)
4256 : static ae_int_t hqrnd_hqrndmax = 2147483561;
4257 : static ae_int_t hqrnd_hqrndm1 = 2147483563;
4258 : static ae_int_t hqrnd_hqrndm2 = 2147483399;
4259 : static ae_int_t hqrnd_hqrndmagic = 1634357784;
4260 : static ae_int_t hqrnd_hqrndintegerbase(hqrndstate* state,
4261 : ae_state *_state);
4262 :
4263 :
4264 : #endif
4265 : #if defined(AE_COMPILE_XDEBUG) || !defined(AE_PARTIAL_BUILD)
4266 :
4267 :
4268 : #endif
4269 :
4270 : #if defined(AE_COMPILE_NEARESTNEIGHBOR) || !defined(AE_PARTIAL_BUILD)
4271 :
4272 :
4273 : /*************************************************************************
4274 : KD-tree creation
4275 :
4276 : This subroutine creates KD-tree from set of X-values and optional Y-values
4277 :
4278 : INPUT PARAMETERS
4279 : XY - dataset, array[0..N-1,0..NX+NY-1].
4280 : one row corresponds to one point.
4281 : first NX columns contain X-values, next NY (NY may be zero)
4282 : columns may contain associated Y-values
4283 : N - number of points, N>=0.
4284 : NX - space dimension, NX>=1.
4285 : NY - number of optional Y-values, NY>=0.
4286 : NormType- norm type:
4287 : * 0 denotes infinity-norm
4288 : * 1 denotes 1-norm
4289 : * 2 denotes 2-norm (Euclidean norm)
4290 :
4291 : OUTPUT PARAMETERS
4292 : KDT - KD-tree
4293 :
4294 :
4295 : NOTES
4296 :
4297 : 1. KD-tree creation have O(N*logN) complexity and O(N*(2*NX+NY)) memory
4298 : requirements.
4299 : 2. Although KD-trees may be used with any combination of N and NX, they
4300 : are more efficient than brute-force search only when N >> 4^NX. So they
4301 : are most useful in low-dimensional tasks (NX=2, NX=3). NX=1 is another
4302 : inefficient case, because simple binary search (without additional
4303 : structures) is much more efficient in such tasks than KD-trees.
4304 :
4305 : -- ALGLIB --
4306 : Copyright 28.02.2010 by Bochkanov Sergey
4307 : *************************************************************************/
4308 0 : void kdtreebuild(/* Real */ ae_matrix* xy,
4309 : ae_int_t n,
4310 : ae_int_t nx,
4311 : ae_int_t ny,
4312 : ae_int_t normtype,
4313 : kdtree* kdt,
4314 : ae_state *_state)
4315 : {
4316 : ae_frame _frame_block;
4317 : ae_vector tags;
4318 : ae_int_t i;
4319 :
4320 0 : ae_frame_make(_state, &_frame_block);
4321 0 : memset(&tags, 0, sizeof(tags));
4322 0 : _kdtree_clear(kdt);
4323 0 : ae_vector_init(&tags, 0, DT_INT, _state, ae_true);
4324 :
4325 0 : ae_assert(n>=0, "KDTreeBuild: N<0", _state);
4326 0 : ae_assert(nx>=1, "KDTreeBuild: NX<1", _state);
4327 0 : ae_assert(ny>=0, "KDTreeBuild: NY<0", _state);
4328 0 : ae_assert(normtype>=0&&normtype<=2, "KDTreeBuild: incorrect NormType", _state);
4329 0 : ae_assert(xy->rows>=n, "KDTreeBuild: rows(X)<N", _state);
4330 0 : ae_assert(xy->cols>=nx+ny||n==0, "KDTreeBuild: cols(X)<NX+NY", _state);
4331 0 : ae_assert(apservisfinitematrix(xy, n, nx+ny, _state), "KDTreeBuild: XY contains infinite or NaN values", _state);
4332 0 : if( n>0 )
4333 : {
4334 0 : ae_vector_set_length(&tags, n, _state);
4335 0 : for(i=0; i<=n-1; i++)
4336 : {
4337 0 : tags.ptr.p_int[i] = 0;
4338 : }
4339 : }
4340 0 : kdtreebuildtagged(xy, &tags, n, nx, ny, normtype, kdt, _state);
4341 0 : ae_frame_leave(_state);
4342 0 : }
4343 :
4344 :
4345 : /*************************************************************************
4346 : KD-tree creation
4347 :
4348 : This subroutine creates KD-tree from set of X-values, integer tags and
4349 : optional Y-values
4350 :
4351 : INPUT PARAMETERS
4352 : XY - dataset, array[0..N-1,0..NX+NY-1].
4353 : one row corresponds to one point.
4354 : first NX columns contain X-values, next NY (NY may be zero)
4355 : columns may contain associated Y-values
4356 : Tags - tags, array[0..N-1], contains integer tags associated
4357 : with points.
4358 : N - number of points, N>=0
4359 : NX - space dimension, NX>=1.
4360 : NY - number of optional Y-values, NY>=0.
4361 : NormType- norm type:
4362 : * 0 denotes infinity-norm
4363 : * 1 denotes 1-norm
4364 : * 2 denotes 2-norm (Euclidean norm)
4365 :
4366 : OUTPUT PARAMETERS
4367 : KDT - KD-tree
4368 :
4369 : NOTES
4370 :
4371 : 1. KD-tree creation have O(N*logN) complexity and O(N*(2*NX+NY)) memory
4372 : requirements.
4373 : 2. Although KD-trees may be used with any combination of N and NX, they
4374 : are more efficient than brute-force search only when N >> 4^NX. So they
4375 : are most useful in low-dimensional tasks (NX=2, NX=3). NX=1 is another
4376 : inefficient case, because simple binary search (without additional
4377 : structures) is much more efficient in such tasks than KD-trees.
4378 :
4379 : -- ALGLIB --
4380 : Copyright 28.02.2010 by Bochkanov Sergey
4381 : *************************************************************************/
4382 0 : void kdtreebuildtagged(/* Real */ ae_matrix* xy,
4383 : /* Integer */ ae_vector* tags,
4384 : ae_int_t n,
4385 : ae_int_t nx,
4386 : ae_int_t ny,
4387 : ae_int_t normtype,
4388 : kdtree* kdt,
4389 : ae_state *_state)
4390 : {
4391 : ae_int_t i;
4392 : ae_int_t j;
4393 : ae_int_t nodesoffs;
4394 : ae_int_t splitsoffs;
4395 :
4396 0 : _kdtree_clear(kdt);
4397 :
4398 0 : ae_assert(n>=0, "KDTreeBuildTagged: N<0", _state);
4399 0 : ae_assert(nx>=1, "KDTreeBuildTagged: NX<1", _state);
4400 0 : ae_assert(ny>=0, "KDTreeBuildTagged: NY<0", _state);
4401 0 : ae_assert(normtype>=0&&normtype<=2, "KDTreeBuildTagged: incorrect NormType", _state);
4402 0 : ae_assert(xy->rows>=n, "KDTreeBuildTagged: rows(X)<N", _state);
4403 0 : ae_assert(xy->cols>=nx+ny||n==0, "KDTreeBuildTagged: cols(X)<NX+NY", _state);
4404 0 : ae_assert(apservisfinitematrix(xy, n, nx+ny, _state), "KDTreeBuildTagged: XY contains infinite or NaN values", _state);
4405 :
4406 : /*
4407 : * initialize
4408 : */
4409 0 : kdt->n = n;
4410 0 : kdt->nx = nx;
4411 0 : kdt->ny = ny;
4412 0 : kdt->normtype = normtype;
4413 0 : kdt->innerbuf.kcur = 0;
4414 :
4415 : /*
4416 : * N=0 => quick exit
4417 : */
4418 0 : if( n==0 )
4419 : {
4420 0 : return;
4421 : }
4422 :
4423 : /*
4424 : * Allocate
4425 : */
4426 0 : nearestneighbor_kdtreeallocdatasetindependent(kdt, nx, ny, _state);
4427 0 : nearestneighbor_kdtreeallocdatasetdependent(kdt, n, nx, ny, _state);
4428 0 : kdtreecreaterequestbuffer(kdt, &kdt->innerbuf, _state);
4429 :
4430 : /*
4431 : * Initial fill
4432 : */
4433 0 : for(i=0; i<=n-1; i++)
4434 : {
4435 0 : ae_v_move(&kdt->xy.ptr.pp_double[i][0], 1, &xy->ptr.pp_double[i][0], 1, ae_v_len(0,nx-1));
4436 0 : ae_v_move(&kdt->xy.ptr.pp_double[i][nx], 1, &xy->ptr.pp_double[i][0], 1, ae_v_len(nx,2*nx+ny-1));
4437 0 : kdt->tags.ptr.p_int[i] = tags->ptr.p_int[i];
4438 : }
4439 :
4440 : /*
4441 : * Determine bounding box
4442 : */
4443 0 : ae_v_move(&kdt->boxmin.ptr.p_double[0], 1, &kdt->xy.ptr.pp_double[0][0], 1, ae_v_len(0,nx-1));
4444 0 : ae_v_move(&kdt->boxmax.ptr.p_double[0], 1, &kdt->xy.ptr.pp_double[0][0], 1, ae_v_len(0,nx-1));
4445 0 : for(i=1; i<=n-1; i++)
4446 : {
4447 0 : for(j=0; j<=nx-1; j++)
4448 : {
4449 0 : kdt->boxmin.ptr.p_double[j] = ae_minreal(kdt->boxmin.ptr.p_double[j], kdt->xy.ptr.pp_double[i][j], _state);
4450 0 : kdt->boxmax.ptr.p_double[j] = ae_maxreal(kdt->boxmax.ptr.p_double[j], kdt->xy.ptr.pp_double[i][j], _state);
4451 : }
4452 : }
4453 :
4454 : /*
4455 : * Generate tree
4456 : */
4457 0 : nodesoffs = 0;
4458 0 : splitsoffs = 0;
4459 0 : ae_v_move(&kdt->innerbuf.curboxmin.ptr.p_double[0], 1, &kdt->boxmin.ptr.p_double[0], 1, ae_v_len(0,nx-1));
4460 0 : ae_v_move(&kdt->innerbuf.curboxmax.ptr.p_double[0], 1, &kdt->boxmax.ptr.p_double[0], 1, ae_v_len(0,nx-1));
4461 0 : nearestneighbor_kdtreegeneratetreerec(kdt, &nodesoffs, &splitsoffs, 0, n, 8, _state);
4462 0 : ivectorresize(&kdt->nodes, nodesoffs, _state);
4463 0 : rvectorresize(&kdt->splits, splitsoffs, _state);
4464 : }
4465 :
4466 :
4467 : /*************************************************************************
4468 : This function creates buffer structure which can be used to perform
4469 : parallel KD-tree requests.
4470 :
4471 : KD-tree subpackage provides two sets of request functions - ones which use
4472 : internal buffer of KD-tree object (these functions are single-threaded
4473 : because they use same buffer, which can not shared between threads), and
4474 : ones which use external buffer.
4475 :
4476 : This function is used to initialize external buffer.
4477 :
4478 : INPUT PARAMETERS
4479 : KDT - KD-tree which is associated with newly created buffer
4480 :
4481 : OUTPUT PARAMETERS
4482 : Buf - external buffer.
4483 :
4484 :
4485 : IMPORTANT: KD-tree buffer should be used only with KD-tree object which
4486 : was used to initialize buffer. Any attempt to use buffer with
4487 : different object is dangerous - you may get integrity check
4488 : failure (exception) because sizes of internal arrays do not fit
4489 : to dimensions of KD-tree structure.
4490 :
4491 : -- ALGLIB --
4492 : Copyright 18.03.2016 by Bochkanov Sergey
4493 : *************************************************************************/
4494 0 : void kdtreecreaterequestbuffer(kdtree* kdt,
4495 : kdtreerequestbuffer* buf,
4496 : ae_state *_state)
4497 : {
4498 :
4499 0 : _kdtreerequestbuffer_clear(buf);
4500 :
4501 0 : ae_vector_set_length(&buf->x, kdt->nx, _state);
4502 0 : ae_vector_set_length(&buf->boxmin, kdt->nx, _state);
4503 0 : ae_vector_set_length(&buf->boxmax, kdt->nx, _state);
4504 0 : ae_vector_set_length(&buf->idx, kdt->n, _state);
4505 0 : ae_vector_set_length(&buf->r, kdt->n, _state);
4506 0 : ae_vector_set_length(&buf->buf, ae_maxint(kdt->n, kdt->nx, _state), _state);
4507 0 : ae_vector_set_length(&buf->curboxmin, kdt->nx, _state);
4508 0 : ae_vector_set_length(&buf->curboxmax, kdt->nx, _state);
4509 0 : buf->kcur = 0;
4510 0 : }
4511 :
4512 :
4513 : /*************************************************************************
4514 : K-NN query: K nearest neighbors
4515 :
4516 : IMPORTANT: this function can not be used in multithreaded code because it
4517 : uses internal temporary buffer of kd-tree object, which can not
4518 : be shared between multiple threads. If you want to perform
4519 : parallel requests, use function which uses external request
4520 : buffer: KDTreeTsQueryKNN() ("Ts" stands for "thread-safe").
4521 :
4522 : INPUT PARAMETERS
4523 : KDT - KD-tree
4524 : X - point, array[0..NX-1].
4525 : K - number of neighbors to return, K>=1
4526 : SelfMatch - whether self-matches are allowed:
4527 : * if True, nearest neighbor may be the point itself
4528 : (if it exists in original dataset)
4529 : * if False, then only points with non-zero distance
4530 : are returned
4531 : * if not given, considered True
4532 :
4533 : RESULT
4534 : number of actual neighbors found (either K or N, if K>N).
4535 :
4536 : This subroutine performs query and stores its result in the internal
4537 : structures of the KD-tree. You can use following subroutines to obtain
4538 : these results:
4539 : * KDTreeQueryResultsX() to get X-values
4540 : * KDTreeQueryResultsXY() to get X- and Y-values
4541 : * KDTreeQueryResultsTags() to get tag values
4542 : * KDTreeQueryResultsDistances() to get distances
4543 :
4544 : -- ALGLIB --
4545 : Copyright 28.02.2010 by Bochkanov Sergey
4546 : *************************************************************************/
4547 0 : ae_int_t kdtreequeryknn(kdtree* kdt,
4548 : /* Real */ ae_vector* x,
4549 : ae_int_t k,
4550 : ae_bool selfmatch,
4551 : ae_state *_state)
4552 : {
4553 : ae_int_t result;
4554 :
4555 :
4556 0 : ae_assert(k>=1, "KDTreeQueryKNN: K<1!", _state);
4557 0 : ae_assert(x->cnt>=kdt->nx, "KDTreeQueryKNN: Length(X)<NX!", _state);
4558 0 : ae_assert(isfinitevector(x, kdt->nx, _state), "KDTreeQueryKNN: X contains infinite or NaN values!", _state);
4559 0 : result = kdtreetsqueryaknn(kdt, &kdt->innerbuf, x, k, selfmatch, 0.0, _state);
4560 0 : return result;
4561 : }
4562 :
4563 :
4564 : /*************************************************************************
4565 : K-NN query: K nearest neighbors, using external thread-local buffer.
4566 :
4567 : You can call this function from multiple threads for same kd-tree instance,
4568 : assuming that different instances of buffer object are passed to different
4569 : threads.
4570 :
4571 : INPUT PARAMETERS
4572 : KDT - kd-tree
4573 : Buf - request buffer object created for this particular
4574 : instance of kd-tree structure with kdtreecreaterequestbuffer()
4575 : function.
4576 : X - point, array[0..NX-1].
4577 : K - number of neighbors to return, K>=1
4578 : SelfMatch - whether self-matches are allowed:
4579 : * if True, nearest neighbor may be the point itself
4580 : (if it exists in original dataset)
4581 : * if False, then only points with non-zero distance
4582 : are returned
4583 : * if not given, considered True
4584 :
4585 : RESULT
4586 : number of actual neighbors found (either K or N, if K>N).
4587 :
4588 : This subroutine performs query and stores its result in the internal
4589 : structures of the buffer object. You can use following subroutines to
4590 : obtain these results (pay attention to "buf" in their names):
4591 : * KDTreeTsQueryResultsX() to get X-values
4592 : * KDTreeTsQueryResultsXY() to get X- and Y-values
4593 : * KDTreeTsQueryResultsTags() to get tag values
4594 : * KDTreeTsQueryResultsDistances() to get distances
4595 :
4596 : IMPORTANT: kd-tree buffer should be used only with KD-tree object which
4597 : was used to initialize buffer. Any attempt to use biffer with
4598 : different object is dangerous - you may get integrity check
4599 : failure (exception) because sizes of internal arrays do not fit
4600 : to dimensions of KD-tree structure.
4601 :
4602 : -- ALGLIB --
4603 : Copyright 18.03.2016 by Bochkanov Sergey
4604 : *************************************************************************/
4605 0 : ae_int_t kdtreetsqueryknn(kdtree* kdt,
4606 : kdtreerequestbuffer* buf,
4607 : /* Real */ ae_vector* x,
4608 : ae_int_t k,
4609 : ae_bool selfmatch,
4610 : ae_state *_state)
4611 : {
4612 : ae_int_t result;
4613 :
4614 :
4615 0 : ae_assert(k>=1, "KDTreeTsQueryKNN: K<1!", _state);
4616 0 : ae_assert(x->cnt>=kdt->nx, "KDTreeTsQueryKNN: Length(X)<NX!", _state);
4617 0 : ae_assert(isfinitevector(x, kdt->nx, _state), "KDTreeTsQueryKNN: X contains infinite or NaN values!", _state);
4618 0 : result = kdtreetsqueryaknn(kdt, buf, x, k, selfmatch, 0.0, _state);
4619 0 : return result;
4620 : }
4621 :
4622 :
4623 : /*************************************************************************
4624 : R-NN query: all points within R-sphere centered at X, ordered by distance
4625 : between point and X (by ascending).
4626 :
4627 : NOTE: it is also possible to perform undordered queries performed by means
4628 : of kdtreequeryrnnu() and kdtreetsqueryrnnu() functions. Such queries
4629 : are faster because we do not have to use heap structure for sorting.
4630 :
4631 : IMPORTANT: this function can not be used in multithreaded code because it
4632 : uses internal temporary buffer of kd-tree object, which can not
4633 : be shared between multiple threads. If you want to perform
4634 : parallel requests, use function which uses external request
4635 : buffer: kdtreetsqueryrnn() ("Ts" stands for "thread-safe").
4636 :
4637 : INPUT PARAMETERS
4638 : KDT - KD-tree
4639 : X - point, array[0..NX-1].
4640 : R - radius of sphere (in corresponding norm), R>0
4641 : SelfMatch - whether self-matches are allowed:
4642 : * if True, nearest neighbor may be the point itself
4643 : (if it exists in original dataset)
4644 : * if False, then only points with non-zero distance
4645 : are returned
4646 : * if not given, considered True
4647 :
4648 : RESULT
4649 : number of neighbors found, >=0
4650 :
4651 : This subroutine performs query and stores its result in the internal
4652 : structures of the KD-tree. You can use following subroutines to obtain
4653 : actual results:
4654 : * KDTreeQueryResultsX() to get X-values
4655 : * KDTreeQueryResultsXY() to get X- and Y-values
4656 : * KDTreeQueryResultsTags() to get tag values
4657 : * KDTreeQueryResultsDistances() to get distances
4658 :
4659 : -- ALGLIB --
4660 : Copyright 28.02.2010 by Bochkanov Sergey
4661 : *************************************************************************/
4662 0 : ae_int_t kdtreequeryrnn(kdtree* kdt,
4663 : /* Real */ ae_vector* x,
4664 : double r,
4665 : ae_bool selfmatch,
4666 : ae_state *_state)
4667 : {
4668 : ae_int_t result;
4669 :
4670 :
4671 0 : ae_assert(ae_fp_greater(r,(double)(0)), "KDTreeQueryRNN: incorrect R!", _state);
4672 0 : ae_assert(x->cnt>=kdt->nx, "KDTreeQueryRNN: Length(X)<NX!", _state);
4673 0 : ae_assert(isfinitevector(x, kdt->nx, _state), "KDTreeQueryRNN: X contains infinite or NaN values!", _state);
4674 0 : result = kdtreetsqueryrnn(kdt, &kdt->innerbuf, x, r, selfmatch, _state);
4675 0 : return result;
4676 : }
4677 :
4678 :
4679 : /*************************************************************************
4680 : R-NN query: all points within R-sphere centered at X, no ordering by
4681 : distance as undicated by "U" suffix (faster that ordered query, for large
4682 : queries - significantly faster).
4683 :
4684 : IMPORTANT: this function can not be used in multithreaded code because it
4685 : uses internal temporary buffer of kd-tree object, which can not
4686 : be shared between multiple threads. If you want to perform
4687 : parallel requests, use function which uses external request
4688 : buffer: kdtreetsqueryrnn() ("Ts" stands for "thread-safe").
4689 :
4690 : INPUT PARAMETERS
4691 : KDT - KD-tree
4692 : X - point, array[0..NX-1].
4693 : R - radius of sphere (in corresponding norm), R>0
4694 : SelfMatch - whether self-matches are allowed:
4695 : * if True, nearest neighbor may be the point itself
4696 : (if it exists in original dataset)
4697 : * if False, then only points with non-zero distance
4698 : are returned
4699 : * if not given, considered True
4700 :
4701 : RESULT
4702 : number of neighbors found, >=0
4703 :
4704 : This subroutine performs query and stores its result in the internal
4705 : structures of the KD-tree. You can use following subroutines to obtain
4706 : actual results:
4707 : * KDTreeQueryResultsX() to get X-values
4708 : * KDTreeQueryResultsXY() to get X- and Y-values
4709 : * KDTreeQueryResultsTags() to get tag values
4710 : * KDTreeQueryResultsDistances() to get distances
4711 :
4712 : As indicated by "U" suffix, this function returns unordered results.
4713 :
4714 : -- ALGLIB --
4715 : Copyright 01.11.2018 by Bochkanov Sergey
4716 : *************************************************************************/
4717 0 : ae_int_t kdtreequeryrnnu(kdtree* kdt,
4718 : /* Real */ ae_vector* x,
4719 : double r,
4720 : ae_bool selfmatch,
4721 : ae_state *_state)
4722 : {
4723 : ae_int_t result;
4724 :
4725 :
4726 0 : ae_assert(ae_fp_greater(r,(double)(0)), "KDTreeQueryRNNU: incorrect R!", _state);
4727 0 : ae_assert(x->cnt>=kdt->nx, "KDTreeQueryRNNU: Length(X)<NX!", _state);
4728 0 : ae_assert(isfinitevector(x, kdt->nx, _state), "KDTreeQueryRNNU: X contains infinite or NaN values!", _state);
4729 0 : result = kdtreetsqueryrnnu(kdt, &kdt->innerbuf, x, r, selfmatch, _state);
4730 0 : return result;
4731 : }
4732 :
4733 :
4734 : /*************************************************************************
4735 : R-NN query: all points within R-sphere centered at X, using external
4736 : thread-local buffer, sorted by distance between point and X (by ascending)
4737 :
4738 : You can call this function from multiple threads for same kd-tree instance,
4739 : assuming that different instances of buffer object are passed to different
4740 : threads.
4741 :
4742 : NOTE: it is also possible to perform undordered queries performed by means
4743 : of kdtreequeryrnnu() and kdtreetsqueryrnnu() functions. Such queries
4744 : are faster because we do not have to use heap structure for sorting.
4745 :
4746 : INPUT PARAMETERS
4747 : KDT - KD-tree
4748 : Buf - request buffer object created for this particular
4749 : instance of kd-tree structure with kdtreecreaterequestbuffer()
4750 : function.
4751 : X - point, array[0..NX-1].
4752 : R - radius of sphere (in corresponding norm), R>0
4753 : SelfMatch - whether self-matches are allowed:
4754 : * if True, nearest neighbor may be the point itself
4755 : (if it exists in original dataset)
4756 : * if False, then only points with non-zero distance
4757 : are returned
4758 : * if not given, considered True
4759 :
4760 : RESULT
4761 : number of neighbors found, >=0
4762 :
4763 : This subroutine performs query and stores its result in the internal
4764 : structures of the buffer object. You can use following subroutines to
4765 : obtain these results (pay attention to "buf" in their names):
4766 : * KDTreeTsQueryResultsX() to get X-values
4767 : * KDTreeTsQueryResultsXY() to get X- and Y-values
4768 : * KDTreeTsQueryResultsTags() to get tag values
4769 : * KDTreeTsQueryResultsDistances() to get distances
4770 :
4771 : IMPORTANT: kd-tree buffer should be used only with KD-tree object which
4772 : was used to initialize buffer. Any attempt to use biffer with
4773 : different object is dangerous - you may get integrity check
4774 : failure (exception) because sizes of internal arrays do not fit
4775 : to dimensions of KD-tree structure.
4776 :
4777 : -- ALGLIB --
4778 : Copyright 18.03.2016 by Bochkanov Sergey
4779 : *************************************************************************/
4780 0 : ae_int_t kdtreetsqueryrnn(kdtree* kdt,
4781 : kdtreerequestbuffer* buf,
4782 : /* Real */ ae_vector* x,
4783 : double r,
4784 : ae_bool selfmatch,
4785 : ae_state *_state)
4786 : {
4787 : ae_int_t result;
4788 :
4789 :
4790 0 : ae_assert(ae_isfinite(r, _state)&&ae_fp_greater(r,(double)(0)), "KDTreeTsQueryRNN: incorrect R!", _state);
4791 0 : ae_assert(x->cnt>=kdt->nx, "KDTreeTsQueryRNN: Length(X)<NX!", _state);
4792 0 : ae_assert(isfinitevector(x, kdt->nx, _state), "KDTreeTsQueryRNN: X contains infinite or NaN values!", _state);
4793 0 : result = nearestneighbor_tsqueryrnn(kdt, buf, x, r, selfmatch, ae_true, _state);
4794 0 : return result;
4795 : }
4796 :
4797 :
4798 : /*************************************************************************
4799 : R-NN query: all points within R-sphere centered at X, using external
4800 : thread-local buffer, no ordering by distance as undicated by "U" suffix
4801 : (faster that ordered query, for large queries - significantly faster).
4802 :
4803 : You can call this function from multiple threads for same kd-tree instance,
4804 : assuming that different instances of buffer object are passed to different
4805 : threads.
4806 :
4807 : INPUT PARAMETERS
4808 : KDT - KD-tree
4809 : Buf - request buffer object created for this particular
4810 : instance of kd-tree structure with kdtreecreaterequestbuffer()
4811 : function.
4812 : X - point, array[0..NX-1].
4813 : R - radius of sphere (in corresponding norm), R>0
4814 : SelfMatch - whether self-matches are allowed:
4815 : * if True, nearest neighbor may be the point itself
4816 : (if it exists in original dataset)
4817 : * if False, then only points with non-zero distance
4818 : are returned
4819 : * if not given, considered True
4820 :
4821 : RESULT
4822 : number of neighbors found, >=0
4823 :
4824 : This subroutine performs query and stores its result in the internal
4825 : structures of the buffer object. You can use following subroutines to
4826 : obtain these results (pay attention to "buf" in their names):
4827 : * KDTreeTsQueryResultsX() to get X-values
4828 : * KDTreeTsQueryResultsXY() to get X- and Y-values
4829 : * KDTreeTsQueryResultsTags() to get tag values
4830 : * KDTreeTsQueryResultsDistances() to get distances
4831 :
4832 : As indicated by "U" suffix, this function returns unordered results.
4833 :
4834 : IMPORTANT: kd-tree buffer should be used only with KD-tree object which
4835 : was used to initialize buffer. Any attempt to use biffer with
4836 : different object is dangerous - you may get integrity check
4837 : failure (exception) because sizes of internal arrays do not fit
4838 : to dimensions of KD-tree structure.
4839 :
4840 : -- ALGLIB --
4841 : Copyright 18.03.2016 by Bochkanov Sergey
4842 : *************************************************************************/
4843 0 : ae_int_t kdtreetsqueryrnnu(kdtree* kdt,
4844 : kdtreerequestbuffer* buf,
4845 : /* Real */ ae_vector* x,
4846 : double r,
4847 : ae_bool selfmatch,
4848 : ae_state *_state)
4849 : {
4850 : ae_int_t result;
4851 :
4852 :
4853 0 : ae_assert(ae_isfinite(r, _state)&&ae_fp_greater(r,(double)(0)), "KDTreeTsQueryRNNU: incorrect R!", _state);
4854 0 : ae_assert(x->cnt>=kdt->nx, "KDTreeTsQueryRNNU: Length(X)<NX!", _state);
4855 0 : ae_assert(isfinitevector(x, kdt->nx, _state), "KDTreeTsQueryRNNU: X contains infinite or NaN values!", _state);
4856 0 : result = nearestneighbor_tsqueryrnn(kdt, buf, x, r, selfmatch, ae_false, _state);
4857 0 : return result;
4858 : }
4859 :
4860 :
4861 : /*************************************************************************
4862 : K-NN query: approximate K nearest neighbors
4863 :
4864 : IMPORTANT: this function can not be used in multithreaded code because it
4865 : uses internal temporary buffer of kd-tree object, which can not
4866 : be shared between multiple threads. If you want to perform
4867 : parallel requests, use function which uses external request
4868 : buffer: KDTreeTsQueryAKNN() ("Ts" stands for "thread-safe").
4869 :
4870 : INPUT PARAMETERS
4871 : KDT - KD-tree
4872 : X - point, array[0..NX-1].
4873 : K - number of neighbors to return, K>=1
4874 : SelfMatch - whether self-matches are allowed:
4875 : * if True, nearest neighbor may be the point itself
4876 : (if it exists in original dataset)
4877 : * if False, then only points with non-zero distance
4878 : are returned
4879 : * if not given, considered True
4880 : Eps - approximation factor, Eps>=0. eps-approximate nearest
4881 : neighbor is a neighbor whose distance from X is at
4882 : most (1+eps) times distance of true nearest neighbor.
4883 :
4884 : RESULT
4885 : number of actual neighbors found (either K or N, if K>N).
4886 :
4887 : NOTES
4888 : significant performance gain may be achieved only when Eps is is on
4889 : the order of magnitude of 1 or larger.
4890 :
4891 : This subroutine performs query and stores its result in the internal
4892 : structures of the KD-tree. You can use following subroutines to obtain
4893 : these results:
4894 : * KDTreeQueryResultsX() to get X-values
4895 : * KDTreeQueryResultsXY() to get X- and Y-values
4896 : * KDTreeQueryResultsTags() to get tag values
4897 : * KDTreeQueryResultsDistances() to get distances
4898 :
4899 : -- ALGLIB --
4900 : Copyright 28.02.2010 by Bochkanov Sergey
4901 : *************************************************************************/
4902 0 : ae_int_t kdtreequeryaknn(kdtree* kdt,
4903 : /* Real */ ae_vector* x,
4904 : ae_int_t k,
4905 : ae_bool selfmatch,
4906 : double eps,
4907 : ae_state *_state)
4908 : {
4909 : ae_int_t result;
4910 :
4911 :
4912 0 : result = kdtreetsqueryaknn(kdt, &kdt->innerbuf, x, k, selfmatch, eps, _state);
4913 0 : return result;
4914 : }
4915 :
4916 :
4917 : /*************************************************************************
4918 : K-NN query: approximate K nearest neighbors, using thread-local buffer.
4919 :
4920 : You can call this function from multiple threads for same kd-tree instance,
4921 : assuming that different instances of buffer object are passed to different
4922 : threads.
4923 :
4924 : INPUT PARAMETERS
4925 : KDT - KD-tree
4926 : Buf - request buffer object created for this particular
4927 : instance of kd-tree structure with kdtreecreaterequestbuffer()
4928 : function.
4929 : X - point, array[0..NX-1].
4930 : K - number of neighbors to return, K>=1
4931 : SelfMatch - whether self-matches are allowed:
4932 : * if True, nearest neighbor may be the point itself
4933 : (if it exists in original dataset)
4934 : * if False, then only points with non-zero distance
4935 : are returned
4936 : * if not given, considered True
4937 : Eps - approximation factor, Eps>=0. eps-approximate nearest
4938 : neighbor is a neighbor whose distance from X is at
4939 : most (1+eps) times distance of true nearest neighbor.
4940 :
4941 : RESULT
4942 : number of actual neighbors found (either K or N, if K>N).
4943 :
4944 : NOTES
4945 : significant performance gain may be achieved only when Eps is is on
4946 : the order of magnitude of 1 or larger.
4947 :
4948 : This subroutine performs query and stores its result in the internal
4949 : structures of the buffer object. You can use following subroutines to
4950 : obtain these results (pay attention to "buf" in their names):
4951 : * KDTreeTsQueryResultsX() to get X-values
4952 : * KDTreeTsQueryResultsXY() to get X- and Y-values
4953 : * KDTreeTsQueryResultsTags() to get tag values
4954 : * KDTreeTsQueryResultsDistances() to get distances
4955 :
4956 : IMPORTANT: kd-tree buffer should be used only with KD-tree object which
4957 : was used to initialize buffer. Any attempt to use biffer with
4958 : different object is dangerous - you may get integrity check
4959 : failure (exception) because sizes of internal arrays do not fit
4960 : to dimensions of KD-tree structure.
4961 :
4962 : -- ALGLIB --
4963 : Copyright 18.03.2016 by Bochkanov Sergey
4964 : *************************************************************************/
4965 0 : ae_int_t kdtreetsqueryaknn(kdtree* kdt,
4966 : kdtreerequestbuffer* buf,
4967 : /* Real */ ae_vector* x,
4968 : ae_int_t k,
4969 : ae_bool selfmatch,
4970 : double eps,
4971 : ae_state *_state)
4972 : {
4973 : ae_int_t i;
4974 : ae_int_t j;
4975 : ae_int_t result;
4976 :
4977 :
4978 0 : ae_assert(k>0, "KDTreeTsQueryAKNN: incorrect K!", _state);
4979 0 : ae_assert(ae_fp_greater_eq(eps,(double)(0)), "KDTreeTsQueryAKNN: incorrect Eps!", _state);
4980 0 : ae_assert(x->cnt>=kdt->nx, "KDTreeTsQueryAKNN: Length(X)<NX!", _state);
4981 0 : ae_assert(isfinitevector(x, kdt->nx, _state), "KDTreeTsQueryAKNN: X contains infinite or NaN values!", _state);
4982 :
4983 : /*
4984 : * Handle special case: KDT.N=0
4985 : */
4986 0 : if( kdt->n==0 )
4987 : {
4988 0 : buf->kcur = 0;
4989 0 : result = 0;
4990 0 : return result;
4991 : }
4992 :
4993 : /*
4994 : * Check consistency of request buffer
4995 : */
4996 0 : nearestneighbor_checkrequestbufferconsistency(kdt, buf, _state);
4997 :
4998 : /*
4999 : * Prepare parameters
5000 : */
5001 0 : k = ae_minint(k, kdt->n, _state);
5002 0 : buf->kneeded = k;
5003 0 : buf->rneeded = (double)(0);
5004 0 : buf->selfmatch = selfmatch;
5005 0 : if( kdt->normtype==2 )
5006 : {
5007 0 : buf->approxf = 1/ae_sqr(1+eps, _state);
5008 : }
5009 : else
5010 : {
5011 0 : buf->approxf = 1/(1+eps);
5012 : }
5013 0 : buf->kcur = 0;
5014 :
5015 : /*
5016 : * calculate distance from point to current bounding box
5017 : */
5018 0 : nearestneighbor_kdtreeinitbox(kdt, x, buf, _state);
5019 :
5020 : /*
5021 : * call recursive search
5022 : * results are returned as heap
5023 : */
5024 0 : nearestneighbor_kdtreequerynnrec(kdt, buf, 0, _state);
5025 :
5026 : /*
5027 : * pop from heap to generate ordered representation
5028 : *
5029 : * last element is non pop'ed because it is already in
5030 : * its place
5031 : */
5032 0 : result = buf->kcur;
5033 0 : j = buf->kcur;
5034 0 : for(i=buf->kcur; i>=2; i--)
5035 : {
5036 0 : tagheappopi(&buf->r, &buf->idx, &j, _state);
5037 : }
5038 0 : return result;
5039 : }
5040 :
5041 :
5042 : /*************************************************************************
5043 : Box query: all points within user-specified box.
5044 :
5045 : IMPORTANT: this function can not be used in multithreaded code because it
5046 : uses internal temporary buffer of kd-tree object, which can not
5047 : be shared between multiple threads. If you want to perform
5048 : parallel requests, use function which uses external request
5049 : buffer: KDTreeTsQueryBox() ("Ts" stands for "thread-safe").
5050 :
5051 : INPUT PARAMETERS
5052 : KDT - KD-tree
5053 : BoxMin - lower bounds, array[0..NX-1].
5054 : BoxMax - upper bounds, array[0..NX-1].
5055 :
5056 :
5057 : RESULT
5058 : number of actual neighbors found (in [0,N]).
5059 :
5060 : This subroutine performs query and stores its result in the internal
5061 : structures of the KD-tree. You can use following subroutines to obtain
5062 : these results:
5063 : * KDTreeQueryResultsX() to get X-values
5064 : * KDTreeQueryResultsXY() to get X- and Y-values
5065 : * KDTreeQueryResultsTags() to get tag values
5066 : * KDTreeQueryResultsDistances() returns zeros for this request
5067 :
5068 : NOTE: this particular query returns unordered results, because there is no
5069 : meaningful way of ordering points. Furthermore, no 'distance' is
5070 : associated with points - it is either INSIDE or OUTSIDE (so request
5071 : for distances will return zeros).
5072 :
5073 : -- ALGLIB --
5074 : Copyright 14.05.2016 by Bochkanov Sergey
5075 : *************************************************************************/
5076 0 : ae_int_t kdtreequerybox(kdtree* kdt,
5077 : /* Real */ ae_vector* boxmin,
5078 : /* Real */ ae_vector* boxmax,
5079 : ae_state *_state)
5080 : {
5081 : ae_int_t result;
5082 :
5083 :
5084 0 : result = kdtreetsquerybox(kdt, &kdt->innerbuf, boxmin, boxmax, _state);
5085 0 : return result;
5086 : }
5087 :
5088 :
5089 : /*************************************************************************
5090 : Box query: all points within user-specified box, using thread-local buffer.
5091 :
5092 : You can call this function from multiple threads for same kd-tree instance,
5093 : assuming that different instances of buffer object are passed to different
5094 : threads.
5095 :
5096 : INPUT PARAMETERS
5097 : KDT - KD-tree
5098 : Buf - request buffer object created for this particular
5099 : instance of kd-tree structure with kdtreecreaterequestbuffer()
5100 : function.
5101 : BoxMin - lower bounds, array[0..NX-1].
5102 : BoxMax - upper bounds, array[0..NX-1].
5103 :
5104 : RESULT
5105 : number of actual neighbors found (in [0,N]).
5106 :
5107 : This subroutine performs query and stores its result in the internal
5108 : structures of the buffer object. You can use following subroutines to
5109 : obtain these results (pay attention to "ts" in their names):
5110 : * KDTreeTsQueryResultsX() to get X-values
5111 : * KDTreeTsQueryResultsXY() to get X- and Y-values
5112 : * KDTreeTsQueryResultsTags() to get tag values
5113 : * KDTreeTsQueryResultsDistances() returns zeros for this query
5114 :
5115 : NOTE: this particular query returns unordered results, because there is no
5116 : meaningful way of ordering points. Furthermore, no 'distance' is
5117 : associated with points - it is either INSIDE or OUTSIDE (so request
5118 : for distances will return zeros).
5119 :
5120 : IMPORTANT: kd-tree buffer should be used only with KD-tree object which
5121 : was used to initialize buffer. Any attempt to use biffer with
5122 : different object is dangerous - you may get integrity check
5123 : failure (exception) because sizes of internal arrays do not fit
5124 : to dimensions of KD-tree structure.
5125 :
5126 : -- ALGLIB --
5127 : Copyright 14.05.2016 by Bochkanov Sergey
5128 : *************************************************************************/
5129 0 : ae_int_t kdtreetsquerybox(kdtree* kdt,
5130 : kdtreerequestbuffer* buf,
5131 : /* Real */ ae_vector* boxmin,
5132 : /* Real */ ae_vector* boxmax,
5133 : ae_state *_state)
5134 : {
5135 : ae_int_t j;
5136 : ae_int_t result;
5137 :
5138 :
5139 0 : ae_assert(boxmin->cnt>=kdt->nx, "KDTreeTsQueryBox: Length(BoxMin)<NX!", _state);
5140 0 : ae_assert(boxmax->cnt>=kdt->nx, "KDTreeTsQueryBox: Length(BoxMax)<NX!", _state);
5141 0 : ae_assert(isfinitevector(boxmin, kdt->nx, _state), "KDTreeTsQueryBox: BoxMin contains infinite or NaN values!", _state);
5142 0 : ae_assert(isfinitevector(boxmax, kdt->nx, _state), "KDTreeTsQueryBox: BoxMax contains infinite or NaN values!", _state);
5143 :
5144 : /*
5145 : * Check consistency of request buffer
5146 : */
5147 0 : nearestneighbor_checkrequestbufferconsistency(kdt, buf, _state);
5148 :
5149 : /*
5150 : * Quick exit for degenerate boxes
5151 : */
5152 0 : for(j=0; j<=kdt->nx-1; j++)
5153 : {
5154 0 : if( ae_fp_greater(boxmin->ptr.p_double[j],boxmax->ptr.p_double[j]) )
5155 : {
5156 0 : buf->kcur = 0;
5157 0 : result = 0;
5158 0 : return result;
5159 : }
5160 : }
5161 :
5162 : /*
5163 : * Prepare parameters
5164 : */
5165 0 : for(j=0; j<=kdt->nx-1; j++)
5166 : {
5167 0 : buf->boxmin.ptr.p_double[j] = boxmin->ptr.p_double[j];
5168 0 : buf->boxmax.ptr.p_double[j] = boxmax->ptr.p_double[j];
5169 0 : buf->curboxmin.ptr.p_double[j] = boxmin->ptr.p_double[j];
5170 0 : buf->curboxmax.ptr.p_double[j] = boxmax->ptr.p_double[j];
5171 : }
5172 0 : buf->kcur = 0;
5173 :
5174 : /*
5175 : * call recursive search
5176 : */
5177 0 : nearestneighbor_kdtreequeryboxrec(kdt, buf, 0, _state);
5178 0 : result = buf->kcur;
5179 0 : return result;
5180 : }
5181 :
5182 :
5183 : /*************************************************************************
5184 : X-values from last query.
5185 :
5186 : This function retuns results stored in the internal buffer of kd-tree
5187 : object. If you performed buffered requests (ones which use instances of
5188 : kdtreerequestbuffer class), you should call buffered version of this
5189 : function - kdtreetsqueryresultsx().
5190 :
5191 : INPUT PARAMETERS
5192 : KDT - KD-tree
5193 : X - possibly pre-allocated buffer. If X is too small to store
5194 : result, it is resized. If size(X) is enough to store
5195 : result, it is left unchanged.
5196 :
5197 : OUTPUT PARAMETERS
5198 : X - rows are filled with X-values
5199 :
5200 : NOTES
5201 : 1. points are ordered by distance from the query point (first = closest)
5202 : 2. if XY is larger than required to store result, only leading part will
5203 : be overwritten; trailing part will be left unchanged. So if on input
5204 : XY = [[A,B],[C,D]], and result is [1,2], then on exit we will get
5205 : XY = [[1,2],[C,D]]. This is done purposely to increase performance; if
5206 : you want function to resize array according to result size, use
5207 : function with same name and suffix 'I'.
5208 :
5209 : SEE ALSO
5210 : * KDTreeQueryResultsXY() X- and Y-values
5211 : * KDTreeQueryResultsTags() tag values
5212 : * KDTreeQueryResultsDistances() distances
5213 :
5214 : -- ALGLIB --
5215 : Copyright 28.02.2010 by Bochkanov Sergey
5216 : *************************************************************************/
5217 0 : void kdtreequeryresultsx(kdtree* kdt,
5218 : /* Real */ ae_matrix* x,
5219 : ae_state *_state)
5220 : {
5221 :
5222 :
5223 0 : kdtreetsqueryresultsx(kdt, &kdt->innerbuf, x, _state);
5224 0 : }
5225 :
5226 :
5227 : /*************************************************************************
5228 : X- and Y-values from last query
5229 :
5230 : This function retuns results stored in the internal buffer of kd-tree
5231 : object. If you performed buffered requests (ones which use instances of
5232 : kdtreerequestbuffer class), you should call buffered version of this
5233 : function - kdtreetsqueryresultsxy().
5234 :
5235 : INPUT PARAMETERS
5236 : KDT - KD-tree
5237 : XY - possibly pre-allocated buffer. If XY is too small to store
5238 : result, it is resized. If size(XY) is enough to store
5239 : result, it is left unchanged.
5240 :
5241 : OUTPUT PARAMETERS
5242 : XY - rows are filled with points: first NX columns with
5243 : X-values, next NY columns - with Y-values.
5244 :
5245 : NOTES
5246 : 1. points are ordered by distance from the query point (first = closest)
5247 : 2. if XY is larger than required to store result, only leading part will
5248 : be overwritten; trailing part will be left unchanged. So if on input
5249 : XY = [[A,B],[C,D]], and result is [1,2], then on exit we will get
5250 : XY = [[1,2],[C,D]]. This is done purposely to increase performance; if
5251 : you want function to resize array according to result size, use
5252 : function with same name and suffix 'I'.
5253 :
5254 : SEE ALSO
5255 : * KDTreeQueryResultsX() X-values
5256 : * KDTreeQueryResultsTags() tag values
5257 : * KDTreeQueryResultsDistances() distances
5258 :
5259 : -- ALGLIB --
5260 : Copyright 28.02.2010 by Bochkanov Sergey
5261 : *************************************************************************/
5262 0 : void kdtreequeryresultsxy(kdtree* kdt,
5263 : /* Real */ ae_matrix* xy,
5264 : ae_state *_state)
5265 : {
5266 :
5267 :
5268 0 : kdtreetsqueryresultsxy(kdt, &kdt->innerbuf, xy, _state);
5269 0 : }
5270 :
5271 :
5272 : /*************************************************************************
5273 : Tags from last query
5274 :
5275 : This function retuns results stored in the internal buffer of kd-tree
5276 : object. If you performed buffered requests (ones which use instances of
5277 : kdtreerequestbuffer class), you should call buffered version of this
5278 : function - kdtreetsqueryresultstags().
5279 :
5280 : INPUT PARAMETERS
5281 : KDT - KD-tree
5282 : Tags - possibly pre-allocated buffer. If X is too small to store
5283 : result, it is resized. If size(X) is enough to store
5284 : result, it is left unchanged.
5285 :
5286 : OUTPUT PARAMETERS
5287 : Tags - filled with tags associated with points,
5288 : or, when no tags were supplied, with zeros
5289 :
5290 : NOTES
5291 : 1. points are ordered by distance from the query point (first = closest)
5292 : 2. if XY is larger than required to store result, only leading part will
5293 : be overwritten; trailing part will be left unchanged. So if on input
5294 : XY = [[A,B],[C,D]], and result is [1,2], then on exit we will get
5295 : XY = [[1,2],[C,D]]. This is done purposely to increase performance; if
5296 : you want function to resize array according to result size, use
5297 : function with same name and suffix 'I'.
5298 :
5299 : SEE ALSO
5300 : * KDTreeQueryResultsX() X-values
5301 : * KDTreeQueryResultsXY() X- and Y-values
5302 : * KDTreeQueryResultsDistances() distances
5303 :
5304 : -- ALGLIB --
5305 : Copyright 28.02.2010 by Bochkanov Sergey
5306 : *************************************************************************/
5307 0 : void kdtreequeryresultstags(kdtree* kdt,
5308 : /* Integer */ ae_vector* tags,
5309 : ae_state *_state)
5310 : {
5311 :
5312 :
5313 0 : kdtreetsqueryresultstags(kdt, &kdt->innerbuf, tags, _state);
5314 0 : }
5315 :
5316 :
5317 : /*************************************************************************
5318 : Distances from last query
5319 :
5320 : This function retuns results stored in the internal buffer of kd-tree
5321 : object. If you performed buffered requests (ones which use instances of
5322 : kdtreerequestbuffer class), you should call buffered version of this
5323 : function - kdtreetsqueryresultsdistances().
5324 :
5325 : INPUT PARAMETERS
5326 : KDT - KD-tree
5327 : R - possibly pre-allocated buffer. If X is too small to store
5328 : result, it is resized. If size(X) is enough to store
5329 : result, it is left unchanged.
5330 :
5331 : OUTPUT PARAMETERS
5332 : R - filled with distances (in corresponding norm)
5333 :
5334 : NOTES
5335 : 1. points are ordered by distance from the query point (first = closest)
5336 : 2. if XY is larger than required to store result, only leading part will
5337 : be overwritten; trailing part will be left unchanged. So if on input
5338 : XY = [[A,B],[C,D]], and result is [1,2], then on exit we will get
5339 : XY = [[1,2],[C,D]]. This is done purposely to increase performance; if
5340 : you want function to resize array according to result size, use
5341 : function with same name and suffix 'I'.
5342 :
5343 : SEE ALSO
5344 : * KDTreeQueryResultsX() X-values
5345 : * KDTreeQueryResultsXY() X- and Y-values
5346 : * KDTreeQueryResultsTags() tag values
5347 :
5348 : -- ALGLIB --
5349 : Copyright 28.02.2010 by Bochkanov Sergey
5350 : *************************************************************************/
5351 0 : void kdtreequeryresultsdistances(kdtree* kdt,
5352 : /* Real */ ae_vector* r,
5353 : ae_state *_state)
5354 : {
5355 :
5356 :
5357 0 : kdtreetsqueryresultsdistances(kdt, &kdt->innerbuf, r, _state);
5358 0 : }
5359 :
5360 :
5361 : /*************************************************************************
5362 : X-values from last query associated with kdtreerequestbuffer object.
5363 :
5364 : INPUT PARAMETERS
5365 : KDT - KD-tree
5366 : Buf - request buffer object created for this particular
5367 : instance of kd-tree structure.
5368 : X - possibly pre-allocated buffer. If X is too small to store
5369 : result, it is resized. If size(X) is enough to store
5370 : result, it is left unchanged.
5371 :
5372 : OUTPUT PARAMETERS
5373 : X - rows are filled with X-values
5374 :
5375 : NOTES
5376 : 1. points are ordered by distance from the query point (first = closest)
5377 : 2. if XY is larger than required to store result, only leading part will
5378 : be overwritten; trailing part will be left unchanged. So if on input
5379 : XY = [[A,B],[C,D]], and result is [1,2], then on exit we will get
5380 : XY = [[1,2],[C,D]]. This is done purposely to increase performance; if
5381 : you want function to resize array according to result size, use
5382 : function with same name and suffix 'I'.
5383 :
5384 : SEE ALSO
5385 : * KDTreeQueryResultsXY() X- and Y-values
5386 : * KDTreeQueryResultsTags() tag values
5387 : * KDTreeQueryResultsDistances() distances
5388 :
5389 : -- ALGLIB --
5390 : Copyright 28.02.2010 by Bochkanov Sergey
5391 : *************************************************************************/
5392 0 : void kdtreetsqueryresultsx(kdtree* kdt,
5393 : kdtreerequestbuffer* buf,
5394 : /* Real */ ae_matrix* x,
5395 : ae_state *_state)
5396 : {
5397 : ae_int_t i;
5398 : ae_int_t k;
5399 :
5400 :
5401 0 : if( buf->kcur==0 )
5402 : {
5403 0 : return;
5404 : }
5405 0 : if( x->rows<buf->kcur||x->cols<kdt->nx )
5406 : {
5407 0 : ae_matrix_set_length(x, buf->kcur, kdt->nx, _state);
5408 : }
5409 0 : k = buf->kcur;
5410 0 : for(i=0; i<=k-1; i++)
5411 : {
5412 0 : ae_v_move(&x->ptr.pp_double[i][0], 1, &kdt->xy.ptr.pp_double[buf->idx.ptr.p_int[i]][kdt->nx], 1, ae_v_len(0,kdt->nx-1));
5413 : }
5414 : }
5415 :
5416 :
5417 : /*************************************************************************
5418 : X- and Y-values from last query associated with kdtreerequestbuffer object.
5419 :
5420 : INPUT PARAMETERS
5421 : KDT - KD-tree
5422 : Buf - request buffer object created for this particular
5423 : instance of kd-tree structure.
5424 : XY - possibly pre-allocated buffer. If XY is too small to store
5425 : result, it is resized. If size(XY) is enough to store
5426 : result, it is left unchanged.
5427 :
5428 : OUTPUT PARAMETERS
5429 : XY - rows are filled with points: first NX columns with
5430 : X-values, next NY columns - with Y-values.
5431 :
5432 : NOTES
5433 : 1. points are ordered by distance from the query point (first = closest)
5434 : 2. if XY is larger than required to store result, only leading part will
5435 : be overwritten; trailing part will be left unchanged. So if on input
5436 : XY = [[A,B],[C,D]], and result is [1,2], then on exit we will get
5437 : XY = [[1,2],[C,D]]. This is done purposely to increase performance; if
5438 : you want function to resize array according to result size, use
5439 : function with same name and suffix 'I'.
5440 :
5441 : SEE ALSO
5442 : * KDTreeQueryResultsX() X-values
5443 : * KDTreeQueryResultsTags() tag values
5444 : * KDTreeQueryResultsDistances() distances
5445 :
5446 : -- ALGLIB --
5447 : Copyright 28.02.2010 by Bochkanov Sergey
5448 : *************************************************************************/
5449 0 : void kdtreetsqueryresultsxy(kdtree* kdt,
5450 : kdtreerequestbuffer* buf,
5451 : /* Real */ ae_matrix* xy,
5452 : ae_state *_state)
5453 : {
5454 : ae_int_t i;
5455 : ae_int_t k;
5456 :
5457 :
5458 0 : if( buf->kcur==0 )
5459 : {
5460 0 : return;
5461 : }
5462 0 : if( xy->rows<buf->kcur||xy->cols<kdt->nx+kdt->ny )
5463 : {
5464 0 : ae_matrix_set_length(xy, buf->kcur, kdt->nx+kdt->ny, _state);
5465 : }
5466 0 : k = buf->kcur;
5467 0 : for(i=0; i<=k-1; i++)
5468 : {
5469 0 : ae_v_move(&xy->ptr.pp_double[i][0], 1, &kdt->xy.ptr.pp_double[buf->idx.ptr.p_int[i]][kdt->nx], 1, ae_v_len(0,kdt->nx+kdt->ny-1));
5470 : }
5471 : }
5472 :
5473 :
5474 : /*************************************************************************
5475 : Tags from last query associated with kdtreerequestbuffer object.
5476 :
5477 : This function retuns results stored in the internal buffer of kd-tree
5478 : object. If you performed buffered requests (ones which use instances of
5479 : kdtreerequestbuffer class), you should call buffered version of this
5480 : function - KDTreeTsqueryresultstags().
5481 :
5482 : INPUT PARAMETERS
5483 : KDT - KD-tree
5484 : Buf - request buffer object created for this particular
5485 : instance of kd-tree structure.
5486 : Tags - possibly pre-allocated buffer. If X is too small to store
5487 : result, it is resized. If size(X) is enough to store
5488 : result, it is left unchanged.
5489 :
5490 : OUTPUT PARAMETERS
5491 : Tags - filled with tags associated with points,
5492 : or, when no tags were supplied, with zeros
5493 :
5494 : NOTES
5495 : 1. points are ordered by distance from the query point (first = closest)
5496 : 2. if XY is larger than required to store result, only leading part will
5497 : be overwritten; trailing part will be left unchanged. So if on input
5498 : XY = [[A,B],[C,D]], and result is [1,2], then on exit we will get
5499 : XY = [[1,2],[C,D]]. This is done purposely to increase performance; if
5500 : you want function to resize array according to result size, use
5501 : function with same name and suffix 'I'.
5502 :
5503 : SEE ALSO
5504 : * KDTreeQueryResultsX() X-values
5505 : * KDTreeQueryResultsXY() X- and Y-values
5506 : * KDTreeQueryResultsDistances() distances
5507 :
5508 : -- ALGLIB --
5509 : Copyright 28.02.2010 by Bochkanov Sergey
5510 : *************************************************************************/
5511 0 : void kdtreetsqueryresultstags(kdtree* kdt,
5512 : kdtreerequestbuffer* buf,
5513 : /* Integer */ ae_vector* tags,
5514 : ae_state *_state)
5515 : {
5516 : ae_int_t i;
5517 : ae_int_t k;
5518 :
5519 :
5520 0 : if( buf->kcur==0 )
5521 : {
5522 0 : return;
5523 : }
5524 0 : if( tags->cnt<buf->kcur )
5525 : {
5526 0 : ae_vector_set_length(tags, buf->kcur, _state);
5527 : }
5528 0 : k = buf->kcur;
5529 0 : for(i=0; i<=k-1; i++)
5530 : {
5531 0 : tags->ptr.p_int[i] = kdt->tags.ptr.p_int[buf->idx.ptr.p_int[i]];
5532 : }
5533 : }
5534 :
5535 :
5536 : /*************************************************************************
5537 : Distances from last query associated with kdtreerequestbuffer object.
5538 :
5539 : This function retuns results stored in the internal buffer of kd-tree
5540 : object. If you performed buffered requests (ones which use instances of
5541 : kdtreerequestbuffer class), you should call buffered version of this
5542 : function - KDTreeTsqueryresultsdistances().
5543 :
5544 : INPUT PARAMETERS
5545 : KDT - KD-tree
5546 : Buf - request buffer object created for this particular
5547 : instance of kd-tree structure.
5548 : R - possibly pre-allocated buffer. If X is too small to store
5549 : result, it is resized. If size(X) is enough to store
5550 : result, it is left unchanged.
5551 :
5552 : OUTPUT PARAMETERS
5553 : R - filled with distances (in corresponding norm)
5554 :
5555 : NOTES
5556 : 1. points are ordered by distance from the query point (first = closest)
5557 : 2. if XY is larger than required to store result, only leading part will
5558 : be overwritten; trailing part will be left unchanged. So if on input
5559 : XY = [[A,B],[C,D]], and result is [1,2], then on exit we will get
5560 : XY = [[1,2],[C,D]]. This is done purposely to increase performance; if
5561 : you want function to resize array according to result size, use
5562 : function with same name and suffix 'I'.
5563 :
5564 : SEE ALSO
5565 : * KDTreeQueryResultsX() X-values
5566 : * KDTreeQueryResultsXY() X- and Y-values
5567 : * KDTreeQueryResultsTags() tag values
5568 :
5569 : -- ALGLIB --
5570 : Copyright 28.02.2010 by Bochkanov Sergey
5571 : *************************************************************************/
5572 0 : void kdtreetsqueryresultsdistances(kdtree* kdt,
5573 : kdtreerequestbuffer* buf,
5574 : /* Real */ ae_vector* r,
5575 : ae_state *_state)
5576 : {
5577 : ae_int_t i;
5578 : ae_int_t k;
5579 :
5580 :
5581 0 : if( buf->kcur==0 )
5582 : {
5583 0 : return;
5584 : }
5585 0 : if( r->cnt<buf->kcur )
5586 : {
5587 0 : ae_vector_set_length(r, buf->kcur, _state);
5588 : }
5589 0 : k = buf->kcur;
5590 :
5591 : /*
5592 : * unload norms
5593 : *
5594 : * Abs() call is used to handle cases with negative norms
5595 : * (generated during KFN requests)
5596 : */
5597 0 : if( kdt->normtype==0 )
5598 : {
5599 0 : for(i=0; i<=k-1; i++)
5600 : {
5601 0 : r->ptr.p_double[i] = ae_fabs(buf->r.ptr.p_double[i], _state);
5602 : }
5603 : }
5604 0 : if( kdt->normtype==1 )
5605 : {
5606 0 : for(i=0; i<=k-1; i++)
5607 : {
5608 0 : r->ptr.p_double[i] = ae_fabs(buf->r.ptr.p_double[i], _state);
5609 : }
5610 : }
5611 0 : if( kdt->normtype==2 )
5612 : {
5613 0 : for(i=0; i<=k-1; i++)
5614 : {
5615 0 : r->ptr.p_double[i] = ae_sqrt(ae_fabs(buf->r.ptr.p_double[i], _state), _state);
5616 : }
5617 : }
5618 : }
5619 :
5620 :
5621 : /*************************************************************************
5622 : X-values from last query; 'interactive' variant for languages like Python
5623 : which support constructs like "X = KDTreeQueryResultsXI(KDT)" and
5624 : interactive mode of interpreter.
5625 :
5626 : This function allocates new array on each call, so it is significantly
5627 : slower than its 'non-interactive' counterpart, but it is more convenient
5628 : when you call it from command line.
5629 :
5630 : -- ALGLIB --
5631 : Copyright 28.02.2010 by Bochkanov Sergey
5632 : *************************************************************************/
5633 0 : void kdtreequeryresultsxi(kdtree* kdt,
5634 : /* Real */ ae_matrix* x,
5635 : ae_state *_state)
5636 : {
5637 :
5638 0 : ae_matrix_clear(x);
5639 :
5640 0 : kdtreequeryresultsx(kdt, x, _state);
5641 0 : }
5642 :
5643 :
5644 : /*************************************************************************
5645 : XY-values from last query; 'interactive' variant for languages like Python
5646 : which support constructs like "XY = KDTreeQueryResultsXYI(KDT)" and
5647 : interactive mode of interpreter.
5648 :
5649 : This function allocates new array on each call, so it is significantly
5650 : slower than its 'non-interactive' counterpart, but it is more convenient
5651 : when you call it from command line.
5652 :
5653 : -- ALGLIB --
5654 : Copyright 28.02.2010 by Bochkanov Sergey
5655 : *************************************************************************/
5656 0 : void kdtreequeryresultsxyi(kdtree* kdt,
5657 : /* Real */ ae_matrix* xy,
5658 : ae_state *_state)
5659 : {
5660 :
5661 0 : ae_matrix_clear(xy);
5662 :
5663 0 : kdtreequeryresultsxy(kdt, xy, _state);
5664 0 : }
5665 :
5666 :
5667 : /*************************************************************************
5668 : Tags from last query; 'interactive' variant for languages like Python
5669 : which support constructs like "Tags = KDTreeQueryResultsTagsI(KDT)" and
5670 : interactive mode of interpreter.
5671 :
5672 : This function allocates new array on each call, so it is significantly
5673 : slower than its 'non-interactive' counterpart, but it is more convenient
5674 : when you call it from command line.
5675 :
5676 : -- ALGLIB --
5677 : Copyright 28.02.2010 by Bochkanov Sergey
5678 : *************************************************************************/
5679 0 : void kdtreequeryresultstagsi(kdtree* kdt,
5680 : /* Integer */ ae_vector* tags,
5681 : ae_state *_state)
5682 : {
5683 :
5684 0 : ae_vector_clear(tags);
5685 :
5686 0 : kdtreequeryresultstags(kdt, tags, _state);
5687 0 : }
5688 :
5689 :
5690 : /*************************************************************************
5691 : Distances from last query; 'interactive' variant for languages like Python
5692 : which support constructs like "R = KDTreeQueryResultsDistancesI(KDT)"
5693 : and interactive mode of interpreter.
5694 :
5695 : This function allocates new array on each call, so it is significantly
5696 : slower than its 'non-interactive' counterpart, but it is more convenient
5697 : when you call it from command line.
5698 :
5699 : -- ALGLIB --
5700 : Copyright 28.02.2010 by Bochkanov Sergey
5701 : *************************************************************************/
5702 0 : void kdtreequeryresultsdistancesi(kdtree* kdt,
5703 : /* Real */ ae_vector* r,
5704 : ae_state *_state)
5705 : {
5706 :
5707 0 : ae_vector_clear(r);
5708 :
5709 0 : kdtreequeryresultsdistances(kdt, r, _state);
5710 0 : }
5711 :
5712 :
5713 : /*************************************************************************
5714 : It is informational function which returns bounding box for entire dataset.
5715 : This function is not visible to ALGLIB users, only ALGLIB itself may use
5716 : it.
5717 :
5718 : This function assumes that output buffers are preallocated by caller.
5719 :
5720 : -- ALGLIB --
5721 : Copyright 20.06.2016 by Bochkanov Sergey
5722 : *************************************************************************/
5723 0 : void kdtreeexplorebox(kdtree* kdt,
5724 : /* Real */ ae_vector* boxmin,
5725 : /* Real */ ae_vector* boxmax,
5726 : ae_state *_state)
5727 : {
5728 : ae_int_t i;
5729 :
5730 :
5731 0 : rvectorsetlengthatleast(boxmin, kdt->nx, _state);
5732 0 : rvectorsetlengthatleast(boxmax, kdt->nx, _state);
5733 0 : for(i=0; i<=kdt->nx-1; i++)
5734 : {
5735 0 : boxmin->ptr.p_double[i] = kdt->boxmin.ptr.p_double[i];
5736 0 : boxmax->ptr.p_double[i] = kdt->boxmax.ptr.p_double[i];
5737 : }
5738 0 : }
5739 :
5740 :
5741 : /*************************************************************************
5742 : It is informational function which allows to get information about node
5743 : type. Node index is given by integer value, with 0 corresponding to root
5744 : node and other node indexes obtained via exploration.
5745 :
5746 : You should not expect that serialization/unserialization will retain node
5747 : indexes. You should keep in mind that future versions of ALGLIB may
5748 : introduce new node types.
5749 :
5750 : OUTPUT VALUES:
5751 : NodeType - node type:
5752 : * 0 corresponds to leaf node, which can be explored by
5753 : kdtreeexploreleaf() function
5754 : * 1 corresponds to split node, which can be explored
5755 : by kdtreeexploresplit() function
5756 :
5757 : -- ALGLIB --
5758 : Copyright 20.06.2016 by Bochkanov Sergey
5759 : *************************************************************************/
5760 0 : void kdtreeexplorenodetype(kdtree* kdt,
5761 : ae_int_t node,
5762 : ae_int_t* nodetype,
5763 : ae_state *_state)
5764 : {
5765 :
5766 0 : *nodetype = 0;
5767 :
5768 0 : ae_assert(node>=0, "KDTreeExploreNodeType: incorrect node", _state);
5769 0 : ae_assert(node<kdt->nodes.cnt, "KDTreeExploreNodeType: incorrect node", _state);
5770 0 : if( kdt->nodes.ptr.p_int[node]>0 )
5771 : {
5772 :
5773 : /*
5774 : * Leaf node
5775 : */
5776 0 : *nodetype = 0;
5777 0 : return;
5778 : }
5779 0 : if( kdt->nodes.ptr.p_int[node]==0 )
5780 : {
5781 :
5782 : /*
5783 : * Split node
5784 : */
5785 0 : *nodetype = 1;
5786 0 : return;
5787 : }
5788 0 : ae_assert(ae_false, "KDTreeExploreNodeType: integrity check failure", _state);
5789 : }
5790 :
5791 :
5792 : /*************************************************************************
5793 : It is informational function which allows to get information about leaf
5794 : node. Node index is given by integer value, with 0 corresponding to root
5795 : node and other node indexes obtained via exploration.
5796 :
5797 : You should not expect that serialization/unserialization will retain node
5798 : indexes. You should keep in mind that future versions of ALGLIB may
5799 : introduce new node types.
5800 :
5801 : OUTPUT VALUES:
5802 : XT - output buffer is reallocated (if too small) and filled by
5803 : XY values
5804 : K - number of rows in XY
5805 :
5806 : -- ALGLIB --
5807 : Copyright 20.06.2016 by Bochkanov Sergey
5808 : *************************************************************************/
5809 0 : void kdtreeexploreleaf(kdtree* kdt,
5810 : ae_int_t node,
5811 : /* Real */ ae_matrix* xy,
5812 : ae_int_t* k,
5813 : ae_state *_state)
5814 : {
5815 : ae_int_t offs;
5816 : ae_int_t i;
5817 : ae_int_t j;
5818 :
5819 0 : *k = 0;
5820 :
5821 0 : ae_assert(node>=0, "KDTreeExploreLeaf: incorrect node index", _state);
5822 0 : ae_assert(node+1<kdt->nodes.cnt, "KDTreeExploreLeaf: incorrect node index", _state);
5823 0 : ae_assert(kdt->nodes.ptr.p_int[node]>0, "KDTreeExploreLeaf: incorrect node index", _state);
5824 0 : *k = kdt->nodes.ptr.p_int[node];
5825 0 : offs = kdt->nodes.ptr.p_int[node+1];
5826 0 : ae_assert(offs>=0, "KDTreeExploreLeaf: integrity error", _state);
5827 0 : ae_assert(offs+(*k)-1<kdt->xy.rows, "KDTreeExploreLeaf: integrity error", _state);
5828 0 : rmatrixsetlengthatleast(xy, *k, kdt->nx+kdt->ny, _state);
5829 0 : for(i=0; i<=*k-1; i++)
5830 : {
5831 0 : for(j=0; j<=kdt->nx+kdt->ny-1; j++)
5832 : {
5833 0 : xy->ptr.pp_double[i][j] = kdt->xy.ptr.pp_double[offs+i][kdt->nx+j];
5834 : }
5835 : }
5836 0 : }
5837 :
5838 :
5839 : /*************************************************************************
5840 : It is informational function which allows to get information about split
5841 : node. Node index is given by integer value, with 0 corresponding to root
5842 : node and other node indexes obtained via exploration.
5843 :
5844 : You should not expect that serialization/unserialization will retain node
5845 : indexes. You should keep in mind that future versions of ALGLIB may
5846 : introduce new node types.
5847 :
5848 : OUTPUT VALUES:
5849 : XT - output buffer is reallocated (if too small) and filled by
5850 : XY values
5851 : K - number of rows in XY
5852 :
5853 : // Nodes[idx+1]=dim dimension to split
5854 : // Nodes[idx+2]=offs offset of splitting point in Splits[]
5855 : // Nodes[idx+3]=left position of left child in Nodes[]
5856 : // Nodes[idx+4]=right position of right child in Nodes[]
5857 :
5858 : -- ALGLIB --
5859 : Copyright 20.06.2016 by Bochkanov Sergey
5860 : *************************************************************************/
5861 0 : void kdtreeexploresplit(kdtree* kdt,
5862 : ae_int_t node,
5863 : ae_int_t* d,
5864 : double* s,
5865 : ae_int_t* nodele,
5866 : ae_int_t* nodege,
5867 : ae_state *_state)
5868 : {
5869 :
5870 0 : *d = 0;
5871 0 : *s = 0;
5872 0 : *nodele = 0;
5873 0 : *nodege = 0;
5874 :
5875 0 : ae_assert(node>=0, "KDTreeExploreSplit: incorrect node index", _state);
5876 0 : ae_assert(node+4<kdt->nodes.cnt, "KDTreeExploreSplit: incorrect node index", _state);
5877 0 : ae_assert(kdt->nodes.ptr.p_int[node]==0, "KDTreeExploreSplit: incorrect node index", _state);
5878 0 : *d = kdt->nodes.ptr.p_int[node+1];
5879 0 : *s = kdt->splits.ptr.p_double[kdt->nodes.ptr.p_int[node+2]];
5880 0 : *nodele = kdt->nodes.ptr.p_int[node+3];
5881 0 : *nodege = kdt->nodes.ptr.p_int[node+4];
5882 0 : ae_assert(*d>=0, "KDTreeExploreSplit: integrity failure", _state);
5883 0 : ae_assert(*d<kdt->nx, "KDTreeExploreSplit: integrity failure", _state);
5884 0 : ae_assert(ae_isfinite(*s, _state), "KDTreeExploreSplit: integrity failure", _state);
5885 0 : ae_assert(*nodele>=0, "KDTreeExploreSplit: integrity failure", _state);
5886 0 : ae_assert(*nodele<kdt->nodes.cnt, "KDTreeExploreSplit: integrity failure", _state);
5887 0 : ae_assert(*nodege>=0, "KDTreeExploreSplit: integrity failure", _state);
5888 0 : ae_assert(*nodege<kdt->nodes.cnt, "KDTreeExploreSplit: integrity failure", _state);
5889 0 : }
5890 :
5891 :
5892 : /*************************************************************************
5893 : Serializer: allocation
5894 :
5895 : -- ALGLIB --
5896 : Copyright 14.03.2011 by Bochkanov Sergey
5897 : *************************************************************************/
5898 0 : void kdtreealloc(ae_serializer* s, kdtree* tree, ae_state *_state)
5899 : {
5900 :
5901 :
5902 :
5903 : /*
5904 : * Header
5905 : */
5906 0 : ae_serializer_alloc_entry(s);
5907 0 : ae_serializer_alloc_entry(s);
5908 :
5909 : /*
5910 : * Data
5911 : */
5912 0 : ae_serializer_alloc_entry(s);
5913 0 : ae_serializer_alloc_entry(s);
5914 0 : ae_serializer_alloc_entry(s);
5915 0 : ae_serializer_alloc_entry(s);
5916 0 : allocrealmatrix(s, &tree->xy, -1, -1, _state);
5917 0 : allocintegerarray(s, &tree->tags, -1, _state);
5918 0 : allocrealarray(s, &tree->boxmin, -1, _state);
5919 0 : allocrealarray(s, &tree->boxmax, -1, _state);
5920 0 : allocintegerarray(s, &tree->nodes, -1, _state);
5921 0 : allocrealarray(s, &tree->splits, -1, _state);
5922 0 : }
5923 :
5924 :
5925 : /*************************************************************************
5926 : Serializer: serialization
5927 :
5928 : -- ALGLIB --
5929 : Copyright 14.03.2011 by Bochkanov Sergey
5930 : *************************************************************************/
5931 0 : void kdtreeserialize(ae_serializer* s, kdtree* tree, ae_state *_state)
5932 : {
5933 :
5934 :
5935 :
5936 : /*
5937 : * Header
5938 : */
5939 0 : ae_serializer_serialize_int(s, getkdtreeserializationcode(_state), _state);
5940 0 : ae_serializer_serialize_int(s, nearestneighbor_kdtreefirstversion, _state);
5941 :
5942 : /*
5943 : * Data
5944 : */
5945 0 : ae_serializer_serialize_int(s, tree->n, _state);
5946 0 : ae_serializer_serialize_int(s, tree->nx, _state);
5947 0 : ae_serializer_serialize_int(s, tree->ny, _state);
5948 0 : ae_serializer_serialize_int(s, tree->normtype, _state);
5949 0 : serializerealmatrix(s, &tree->xy, -1, -1, _state);
5950 0 : serializeintegerarray(s, &tree->tags, -1, _state);
5951 0 : serializerealarray(s, &tree->boxmin, -1, _state);
5952 0 : serializerealarray(s, &tree->boxmax, -1, _state);
5953 0 : serializeintegerarray(s, &tree->nodes, -1, _state);
5954 0 : serializerealarray(s, &tree->splits, -1, _state);
5955 0 : }
5956 :
5957 :
5958 : /*************************************************************************
5959 : Serializer: unserialization
5960 :
5961 : -- ALGLIB --
5962 : Copyright 14.03.2011 by Bochkanov Sergey
5963 : *************************************************************************/
5964 0 : void kdtreeunserialize(ae_serializer* s, kdtree* tree, ae_state *_state)
5965 : {
5966 : ae_int_t i0;
5967 : ae_int_t i1;
5968 :
5969 0 : _kdtree_clear(tree);
5970 :
5971 :
5972 : /*
5973 : * check correctness of header
5974 : */
5975 0 : ae_serializer_unserialize_int(s, &i0, _state);
5976 0 : ae_assert(i0==getkdtreeserializationcode(_state), "KDTreeUnserialize: stream header corrupted", _state);
5977 0 : ae_serializer_unserialize_int(s, &i1, _state);
5978 0 : ae_assert(i1==nearestneighbor_kdtreefirstversion, "KDTreeUnserialize: stream header corrupted", _state);
5979 :
5980 : /*
5981 : * Unserialize data
5982 : */
5983 0 : ae_serializer_unserialize_int(s, &tree->n, _state);
5984 0 : ae_serializer_unserialize_int(s, &tree->nx, _state);
5985 0 : ae_serializer_unserialize_int(s, &tree->ny, _state);
5986 0 : ae_serializer_unserialize_int(s, &tree->normtype, _state);
5987 0 : unserializerealmatrix(s, &tree->xy, _state);
5988 0 : unserializeintegerarray(s, &tree->tags, _state);
5989 0 : unserializerealarray(s, &tree->boxmin, _state);
5990 0 : unserializerealarray(s, &tree->boxmax, _state);
5991 0 : unserializeintegerarray(s, &tree->nodes, _state);
5992 0 : unserializerealarray(s, &tree->splits, _state);
5993 0 : kdtreecreaterequestbuffer(tree, &tree->innerbuf, _state);
5994 0 : }
5995 :
5996 :
5997 : /*************************************************************************
5998 : R-NN query: all points within R-sphere centered at X, using external
5999 : thread-local buffer, sorted by distance between point and X (by ascending)
6000 :
6001 : You can call this function from multiple threads for same kd-tree instance,
6002 : assuming that different instances of buffer object are passed to different
6003 : threads.
6004 :
6005 : NOTE: it is also possible to perform undordered queries performed by means
6006 : of kdtreequeryrnnu() and kdtreetsqueryrnnu() functions. Such queries
6007 : are faster because we do not have to use heap structure for sorting.
6008 :
6009 : INPUT PARAMETERS
6010 : KDT - KD-tree
6011 : Buf - request buffer object created for this particular
6012 : instance of kd-tree structure with kdtreecreaterequestbuffer()
6013 : function.
6014 : X - point, array[0..NX-1].
6015 : R - radius of sphere (in corresponding norm), R>0
6016 : SelfMatch - whether self-matches are allowed:
6017 : * if True, nearest neighbor may be the point itself
6018 : (if it exists in original dataset)
6019 : * if False, then only points with non-zero distance
6020 : are returned
6021 : * if not given, considered True
6022 :
6023 : RESULT
6024 : number of neighbors found, >=0
6025 :
6026 : This subroutine performs query and stores its result in the internal
6027 : structures of the buffer object. You can use following subroutines to
6028 : obtain these results (pay attention to "buf" in their names):
6029 : * KDTreeTsQueryResultsX() to get X-values
6030 : * KDTreeTsQueryResultsXY() to get X- and Y-values
6031 : * KDTreeTsQueryResultsTags() to get tag values
6032 : * KDTreeTsQueryResultsDistances() to get distances
6033 :
6034 : IMPORTANT: kd-tree buffer should be used only with KD-tree object which
6035 : was used to initialize buffer. Any attempt to use biffer with
6036 : different object is dangerous - you may get integrity check
6037 : failure (exception) because sizes of internal arrays do not fit
6038 : to dimensions of KD-tree structure.
6039 :
6040 : -- ALGLIB --
6041 : Copyright 18.03.2016 by Bochkanov Sergey
6042 : *************************************************************************/
6043 0 : static ae_int_t nearestneighbor_tsqueryrnn(kdtree* kdt,
6044 : kdtreerequestbuffer* buf,
6045 : /* Real */ ae_vector* x,
6046 : double r,
6047 : ae_bool selfmatch,
6048 : ae_bool orderedbydist,
6049 : ae_state *_state)
6050 : {
6051 : ae_int_t i;
6052 : ae_int_t j;
6053 : ae_int_t result;
6054 :
6055 :
6056 :
6057 : /*
6058 : * Handle special case: KDT.N=0
6059 : */
6060 0 : if( kdt->n==0 )
6061 : {
6062 0 : buf->kcur = 0;
6063 0 : result = 0;
6064 0 : return result;
6065 : }
6066 :
6067 : /*
6068 : * Check consistency of request buffer
6069 : */
6070 0 : nearestneighbor_checkrequestbufferconsistency(kdt, buf, _state);
6071 :
6072 : /*
6073 : * Prepare parameters
6074 : */
6075 0 : buf->kneeded = 0;
6076 0 : if( kdt->normtype!=2 )
6077 : {
6078 0 : buf->rneeded = r;
6079 : }
6080 : else
6081 : {
6082 0 : buf->rneeded = ae_sqr(r, _state);
6083 : }
6084 0 : buf->selfmatch = selfmatch;
6085 0 : buf->approxf = (double)(1);
6086 0 : buf->kcur = 0;
6087 :
6088 : /*
6089 : * calculate distance from point to current bounding box
6090 : */
6091 0 : nearestneighbor_kdtreeinitbox(kdt, x, buf, _state);
6092 :
6093 : /*
6094 : * call recursive search
6095 : * results are returned as heap
6096 : */
6097 0 : nearestneighbor_kdtreequerynnrec(kdt, buf, 0, _state);
6098 0 : result = buf->kcur;
6099 :
6100 : /*
6101 : * pop from heap to generate ordered representation
6102 : *
6103 : * last element is not pop'ed because it is already in
6104 : * its place
6105 : */
6106 0 : if( orderedbydist )
6107 : {
6108 0 : j = buf->kcur;
6109 0 : for(i=buf->kcur; i>=2; i--)
6110 : {
6111 0 : tagheappopi(&buf->r, &buf->idx, &j, _state);
6112 : }
6113 : }
6114 0 : return result;
6115 : }
6116 :
6117 :
6118 : /*************************************************************************
6119 : Rearranges nodes [I1,I2) using partition in D-th dimension with S as threshold.
6120 : Returns split position I3: [I1,I3) and [I3,I2) are created as result.
6121 :
6122 : This subroutine doesn't create tree structures, just rearranges nodes.
6123 : *************************************************************************/
6124 0 : static void nearestneighbor_kdtreesplit(kdtree* kdt,
6125 : ae_int_t i1,
6126 : ae_int_t i2,
6127 : ae_int_t d,
6128 : double s,
6129 : ae_int_t* i3,
6130 : ae_state *_state)
6131 : {
6132 : ae_int_t i;
6133 : ae_int_t j;
6134 : ae_int_t ileft;
6135 : ae_int_t iright;
6136 : double v;
6137 :
6138 0 : *i3 = 0;
6139 :
6140 0 : ae_assert(kdt->n>0, "KDTreeSplit: internal error", _state);
6141 :
6142 : /*
6143 : * split XY/Tags in two parts:
6144 : * * [ILeft,IRight] is non-processed part of XY/Tags
6145 : *
6146 : * After cycle is done, we have Ileft=IRight. We deal with
6147 : * this element separately.
6148 : *
6149 : * After this, [I1,ILeft) contains left part, and [ILeft,I2)
6150 : * contains right part.
6151 : */
6152 0 : ileft = i1;
6153 0 : iright = i2-1;
6154 0 : while(ileft<iright)
6155 : {
6156 0 : if( kdt->xy.ptr.pp_double[ileft][d]<=s )
6157 : {
6158 :
6159 : /*
6160 : * XY[ILeft] is on its place.
6161 : * Advance ILeft.
6162 : */
6163 0 : ileft = ileft+1;
6164 : }
6165 : else
6166 : {
6167 :
6168 : /*
6169 : * XY[ILeft,..] must be at IRight.
6170 : * Swap and advance IRight.
6171 : */
6172 0 : for(i=0; i<=2*kdt->nx+kdt->ny-1; i++)
6173 : {
6174 0 : v = kdt->xy.ptr.pp_double[ileft][i];
6175 0 : kdt->xy.ptr.pp_double[ileft][i] = kdt->xy.ptr.pp_double[iright][i];
6176 0 : kdt->xy.ptr.pp_double[iright][i] = v;
6177 : }
6178 0 : j = kdt->tags.ptr.p_int[ileft];
6179 0 : kdt->tags.ptr.p_int[ileft] = kdt->tags.ptr.p_int[iright];
6180 0 : kdt->tags.ptr.p_int[iright] = j;
6181 0 : iright = iright-1;
6182 : }
6183 : }
6184 0 : if( kdt->xy.ptr.pp_double[ileft][d]<=s )
6185 : {
6186 0 : ileft = ileft+1;
6187 : }
6188 : else
6189 : {
6190 0 : iright = iright-1;
6191 : }
6192 0 : *i3 = ileft;
6193 0 : }
6194 :
6195 :
6196 : /*************************************************************************
6197 : Recursive kd-tree generation subroutine.
6198 :
6199 : PARAMETERS
6200 : KDT tree
6201 : NodesOffs unused part of Nodes[] which must be filled by tree
6202 : SplitsOffs unused part of Splits[]
6203 : I1, I2 points from [I1,I2) are processed
6204 :
6205 : NodesOffs[] and SplitsOffs[] must be large enough.
6206 :
6207 : -- ALGLIB --
6208 : Copyright 28.02.2010 by Bochkanov Sergey
6209 : *************************************************************************/
6210 0 : static void nearestneighbor_kdtreegeneratetreerec(kdtree* kdt,
6211 : ae_int_t* nodesoffs,
6212 : ae_int_t* splitsoffs,
6213 : ae_int_t i1,
6214 : ae_int_t i2,
6215 : ae_int_t maxleafsize,
6216 : ae_state *_state)
6217 : {
6218 : ae_int_t n;
6219 : ae_int_t nx;
6220 : ae_int_t ny;
6221 : ae_int_t i;
6222 : ae_int_t j;
6223 : ae_int_t oldoffs;
6224 : ae_int_t i3;
6225 : ae_int_t cntless;
6226 : ae_int_t cntgreater;
6227 : double minv;
6228 : double maxv;
6229 : ae_int_t minidx;
6230 : ae_int_t maxidx;
6231 : ae_int_t d;
6232 : double ds;
6233 : double s;
6234 : double v;
6235 : double v0;
6236 : double v1;
6237 :
6238 :
6239 0 : ae_assert(kdt->n>0, "KDTreeGenerateTreeRec: internal error", _state);
6240 0 : ae_assert(i2>i1, "KDTreeGenerateTreeRec: internal error", _state);
6241 :
6242 : /*
6243 : * Generate leaf if needed
6244 : */
6245 0 : if( i2-i1<=maxleafsize )
6246 : {
6247 0 : kdt->nodes.ptr.p_int[*nodesoffs+0] = i2-i1;
6248 0 : kdt->nodes.ptr.p_int[*nodesoffs+1] = i1;
6249 0 : *nodesoffs = *nodesoffs+2;
6250 0 : return;
6251 : }
6252 :
6253 : /*
6254 : * Load values for easier access
6255 : */
6256 0 : nx = kdt->nx;
6257 0 : ny = kdt->ny;
6258 :
6259 : /*
6260 : * Select dimension to split:
6261 : * * D is a dimension number
6262 : * In case bounding box has zero size, we enforce creation of the leaf node.
6263 : */
6264 0 : d = 0;
6265 0 : ds = kdt->innerbuf.curboxmax.ptr.p_double[0]-kdt->innerbuf.curboxmin.ptr.p_double[0];
6266 0 : for(i=1; i<=nx-1; i++)
6267 : {
6268 0 : v = kdt->innerbuf.curboxmax.ptr.p_double[i]-kdt->innerbuf.curboxmin.ptr.p_double[i];
6269 0 : if( v>ds )
6270 : {
6271 0 : ds = v;
6272 0 : d = i;
6273 : }
6274 : }
6275 0 : if( ae_fp_eq(ds,(double)(0)) )
6276 : {
6277 0 : kdt->nodes.ptr.p_int[*nodesoffs+0] = i2-i1;
6278 0 : kdt->nodes.ptr.p_int[*nodesoffs+1] = i1;
6279 0 : *nodesoffs = *nodesoffs+2;
6280 0 : return;
6281 : }
6282 :
6283 : /*
6284 : * Select split position S using sliding midpoint rule,
6285 : * rearrange points into [I1,I3) and [I3,I2).
6286 : *
6287 : * In case all points has same value of D-th component
6288 : * (MinV=MaxV) we enforce D-th dimension of bounding
6289 : * box to become exactly zero and repeat tree construction.
6290 : */
6291 0 : s = kdt->innerbuf.curboxmin.ptr.p_double[d]+0.5*ds;
6292 0 : ae_v_move(&kdt->innerbuf.buf.ptr.p_double[0], 1, &kdt->xy.ptr.pp_double[i1][d], kdt->xy.stride, ae_v_len(0,i2-i1-1));
6293 0 : n = i2-i1;
6294 0 : cntless = 0;
6295 0 : cntgreater = 0;
6296 0 : minv = kdt->innerbuf.buf.ptr.p_double[0];
6297 0 : maxv = kdt->innerbuf.buf.ptr.p_double[0];
6298 0 : minidx = i1;
6299 0 : maxidx = i1;
6300 0 : for(i=0; i<=n-1; i++)
6301 : {
6302 0 : v = kdt->innerbuf.buf.ptr.p_double[i];
6303 0 : if( v<minv )
6304 : {
6305 0 : minv = v;
6306 0 : minidx = i1+i;
6307 : }
6308 0 : if( v>maxv )
6309 : {
6310 0 : maxv = v;
6311 0 : maxidx = i1+i;
6312 : }
6313 0 : if( v<s )
6314 : {
6315 0 : cntless = cntless+1;
6316 : }
6317 0 : if( v>s )
6318 : {
6319 0 : cntgreater = cntgreater+1;
6320 : }
6321 : }
6322 0 : if( minv==maxv )
6323 : {
6324 :
6325 : /*
6326 : * In case all points has same value of D-th component
6327 : * (MinV=MaxV) we enforce D-th dimension of bounding
6328 : * box to become exactly zero and repeat tree construction.
6329 : */
6330 0 : v0 = kdt->innerbuf.curboxmin.ptr.p_double[d];
6331 0 : v1 = kdt->innerbuf.curboxmax.ptr.p_double[d];
6332 0 : kdt->innerbuf.curboxmin.ptr.p_double[d] = minv;
6333 0 : kdt->innerbuf.curboxmax.ptr.p_double[d] = maxv;
6334 0 : nearestneighbor_kdtreegeneratetreerec(kdt, nodesoffs, splitsoffs, i1, i2, maxleafsize, _state);
6335 0 : kdt->innerbuf.curboxmin.ptr.p_double[d] = v0;
6336 0 : kdt->innerbuf.curboxmax.ptr.p_double[d] = v1;
6337 0 : return;
6338 : }
6339 0 : if( cntless>0&&cntgreater>0 )
6340 : {
6341 :
6342 : /*
6343 : * normal midpoint split
6344 : */
6345 0 : nearestneighbor_kdtreesplit(kdt, i1, i2, d, s, &i3, _state);
6346 : }
6347 : else
6348 : {
6349 :
6350 : /*
6351 : * sliding midpoint
6352 : */
6353 0 : if( cntless==0 )
6354 : {
6355 :
6356 : /*
6357 : * 1. move split to MinV,
6358 : * 2. place one point to the left bin (move to I1),
6359 : * others - to the right bin
6360 : */
6361 0 : s = minv;
6362 0 : if( minidx!=i1 )
6363 : {
6364 0 : for(i=0; i<=2*nx+ny-1; i++)
6365 : {
6366 0 : v = kdt->xy.ptr.pp_double[minidx][i];
6367 0 : kdt->xy.ptr.pp_double[minidx][i] = kdt->xy.ptr.pp_double[i1][i];
6368 0 : kdt->xy.ptr.pp_double[i1][i] = v;
6369 : }
6370 0 : j = kdt->tags.ptr.p_int[minidx];
6371 0 : kdt->tags.ptr.p_int[minidx] = kdt->tags.ptr.p_int[i1];
6372 0 : kdt->tags.ptr.p_int[i1] = j;
6373 : }
6374 0 : i3 = i1+1;
6375 : }
6376 : else
6377 : {
6378 :
6379 : /*
6380 : * 1. move split to MaxV,
6381 : * 2. place one point to the right bin (move to I2-1),
6382 : * others - to the left bin
6383 : */
6384 0 : s = maxv;
6385 0 : if( maxidx!=i2-1 )
6386 : {
6387 0 : for(i=0; i<=2*nx+ny-1; i++)
6388 : {
6389 0 : v = kdt->xy.ptr.pp_double[maxidx][i];
6390 0 : kdt->xy.ptr.pp_double[maxidx][i] = kdt->xy.ptr.pp_double[i2-1][i];
6391 0 : kdt->xy.ptr.pp_double[i2-1][i] = v;
6392 : }
6393 0 : j = kdt->tags.ptr.p_int[maxidx];
6394 0 : kdt->tags.ptr.p_int[maxidx] = kdt->tags.ptr.p_int[i2-1];
6395 0 : kdt->tags.ptr.p_int[i2-1] = j;
6396 : }
6397 0 : i3 = i2-1;
6398 : }
6399 : }
6400 :
6401 : /*
6402 : * Generate 'split' node
6403 : */
6404 0 : kdt->nodes.ptr.p_int[*nodesoffs+0] = 0;
6405 0 : kdt->nodes.ptr.p_int[*nodesoffs+1] = d;
6406 0 : kdt->nodes.ptr.p_int[*nodesoffs+2] = *splitsoffs;
6407 0 : kdt->splits.ptr.p_double[*splitsoffs+0] = s;
6408 0 : oldoffs = *nodesoffs;
6409 0 : *nodesoffs = *nodesoffs+nearestneighbor_splitnodesize;
6410 0 : *splitsoffs = *splitsoffs+1;
6411 :
6412 : /*
6413 : * Recursive generation:
6414 : * * update CurBox
6415 : * * call subroutine
6416 : * * restore CurBox
6417 : */
6418 0 : kdt->nodes.ptr.p_int[oldoffs+3] = *nodesoffs;
6419 0 : v = kdt->innerbuf.curboxmax.ptr.p_double[d];
6420 0 : kdt->innerbuf.curboxmax.ptr.p_double[d] = s;
6421 0 : nearestneighbor_kdtreegeneratetreerec(kdt, nodesoffs, splitsoffs, i1, i3, maxleafsize, _state);
6422 0 : kdt->innerbuf.curboxmax.ptr.p_double[d] = v;
6423 0 : kdt->nodes.ptr.p_int[oldoffs+4] = *nodesoffs;
6424 0 : v = kdt->innerbuf.curboxmin.ptr.p_double[d];
6425 0 : kdt->innerbuf.curboxmin.ptr.p_double[d] = s;
6426 0 : nearestneighbor_kdtreegeneratetreerec(kdt, nodesoffs, splitsoffs, i3, i2, maxleafsize, _state);
6427 0 : kdt->innerbuf.curboxmin.ptr.p_double[d] = v;
6428 :
6429 : /*
6430 : * Zero-fill unused portions of the node (avoid false warnings by Valgrind
6431 : * about attempt to serialize uninitialized values)
6432 : */
6433 0 : ae_assert(nearestneighbor_splitnodesize==6, "KDTreeGenerateTreeRec: node size has unexpectedly changed", _state);
6434 0 : kdt->nodes.ptr.p_int[oldoffs+5] = 0;
6435 : }
6436 :
6437 :
6438 : /*************************************************************************
6439 : Recursive subroutine for NN queries.
6440 :
6441 : -- ALGLIB --
6442 : Copyright 28.02.2010 by Bochkanov Sergey
6443 : *************************************************************************/
6444 0 : static void nearestneighbor_kdtreequerynnrec(kdtree* kdt,
6445 : kdtreerequestbuffer* buf,
6446 : ae_int_t offs,
6447 : ae_state *_state)
6448 : {
6449 : double ptdist;
6450 : ae_int_t i;
6451 : ae_int_t j;
6452 : ae_int_t nx;
6453 : ae_int_t i1;
6454 : ae_int_t i2;
6455 : ae_int_t d;
6456 : double s;
6457 : double v;
6458 : double t1;
6459 : ae_int_t childbestoffs;
6460 : ae_int_t childworstoffs;
6461 : ae_int_t childoffs;
6462 : double prevdist;
6463 : ae_bool todive;
6464 : ae_bool bestisleft;
6465 : ae_bool updatemin;
6466 :
6467 :
6468 0 : ae_assert(kdt->n>0, "KDTreeQueryNNRec: internal error", _state);
6469 :
6470 : /*
6471 : * Leaf node.
6472 : * Process points.
6473 : */
6474 0 : if( kdt->nodes.ptr.p_int[offs]>0 )
6475 : {
6476 0 : i1 = kdt->nodes.ptr.p_int[offs+1];
6477 0 : i2 = i1+kdt->nodes.ptr.p_int[offs];
6478 0 : for(i=i1; i<=i2-1; i++)
6479 : {
6480 :
6481 : /*
6482 : * Calculate distance
6483 : */
6484 0 : ptdist = (double)(0);
6485 0 : nx = kdt->nx;
6486 0 : if( kdt->normtype==0 )
6487 : {
6488 0 : for(j=0; j<=nx-1; j++)
6489 : {
6490 0 : ptdist = ae_maxreal(ptdist, ae_fabs(kdt->xy.ptr.pp_double[i][j]-buf->x.ptr.p_double[j], _state), _state);
6491 : }
6492 : }
6493 0 : if( kdt->normtype==1 )
6494 : {
6495 0 : for(j=0; j<=nx-1; j++)
6496 : {
6497 0 : ptdist = ptdist+ae_fabs(kdt->xy.ptr.pp_double[i][j]-buf->x.ptr.p_double[j], _state);
6498 : }
6499 : }
6500 0 : if( kdt->normtype==2 )
6501 : {
6502 0 : for(j=0; j<=nx-1; j++)
6503 : {
6504 0 : ptdist = ptdist+ae_sqr(kdt->xy.ptr.pp_double[i][j]-buf->x.ptr.p_double[j], _state);
6505 : }
6506 : }
6507 :
6508 : /*
6509 : * Skip points with zero distance if self-matches are turned off
6510 : */
6511 0 : if( ptdist==0&&!buf->selfmatch )
6512 : {
6513 0 : continue;
6514 : }
6515 :
6516 : /*
6517 : * We CAN'T process point if R-criterion isn't satisfied,
6518 : * i.e. (RNeeded<>0) AND (PtDist>R).
6519 : */
6520 0 : if( buf->rneeded==0||ptdist<=buf->rneeded )
6521 : {
6522 :
6523 : /*
6524 : * R-criterion is satisfied, we must either:
6525 : * * replace worst point, if (KNeeded<>0) AND (KCur=KNeeded)
6526 : * (or skip, if worst point is better)
6527 : * * add point without replacement otherwise
6528 : */
6529 0 : if( buf->kcur<buf->kneeded||buf->kneeded==0 )
6530 : {
6531 :
6532 : /*
6533 : * add current point to heap without replacement
6534 : */
6535 0 : tagheappushi(&buf->r, &buf->idx, &buf->kcur, ptdist, i, _state);
6536 : }
6537 : else
6538 : {
6539 :
6540 : /*
6541 : * New points are added or not, depending on their distance.
6542 : * If added, they replace element at the top of the heap
6543 : */
6544 0 : if( ptdist<buf->r.ptr.p_double[0] )
6545 : {
6546 0 : if( buf->kneeded==1 )
6547 : {
6548 0 : buf->idx.ptr.p_int[0] = i;
6549 0 : buf->r.ptr.p_double[0] = ptdist;
6550 : }
6551 : else
6552 : {
6553 0 : tagheapreplacetopi(&buf->r, &buf->idx, buf->kneeded, ptdist, i, _state);
6554 : }
6555 : }
6556 : }
6557 : }
6558 : }
6559 0 : return;
6560 : }
6561 :
6562 : /*
6563 : * Simple split
6564 : */
6565 0 : if( kdt->nodes.ptr.p_int[offs]==0 )
6566 : {
6567 :
6568 : /*
6569 : * Load:
6570 : * * D dimension to split
6571 : * * S split position
6572 : */
6573 0 : d = kdt->nodes.ptr.p_int[offs+1];
6574 0 : s = kdt->splits.ptr.p_double[kdt->nodes.ptr.p_int[offs+2]];
6575 :
6576 : /*
6577 : * Calculate:
6578 : * * ChildBestOffs child box with best chances
6579 : * * ChildWorstOffs child box with worst chances
6580 : */
6581 0 : if( buf->x.ptr.p_double[d]<=s )
6582 : {
6583 0 : childbestoffs = kdt->nodes.ptr.p_int[offs+3];
6584 0 : childworstoffs = kdt->nodes.ptr.p_int[offs+4];
6585 0 : bestisleft = ae_true;
6586 : }
6587 : else
6588 : {
6589 0 : childbestoffs = kdt->nodes.ptr.p_int[offs+4];
6590 0 : childworstoffs = kdt->nodes.ptr.p_int[offs+3];
6591 0 : bestisleft = ae_false;
6592 : }
6593 :
6594 : /*
6595 : * Navigate through childs
6596 : */
6597 0 : for(i=0; i<=1; i++)
6598 : {
6599 :
6600 : /*
6601 : * Select child to process:
6602 : * * ChildOffs current child offset in Nodes[]
6603 : * * UpdateMin whether minimum or maximum value
6604 : * of bounding box is changed on update
6605 : */
6606 0 : if( i==0 )
6607 : {
6608 0 : childoffs = childbestoffs;
6609 0 : updatemin = !bestisleft;
6610 : }
6611 : else
6612 : {
6613 0 : updatemin = bestisleft;
6614 0 : childoffs = childworstoffs;
6615 : }
6616 :
6617 : /*
6618 : * Update bounding box and current distance
6619 : */
6620 0 : if( updatemin )
6621 : {
6622 0 : prevdist = buf->curdist;
6623 0 : t1 = buf->x.ptr.p_double[d];
6624 0 : v = buf->curboxmin.ptr.p_double[d];
6625 0 : if( t1<=s )
6626 : {
6627 0 : if( kdt->normtype==0 )
6628 : {
6629 0 : buf->curdist = ae_maxreal(buf->curdist, s-t1, _state);
6630 : }
6631 0 : if( kdt->normtype==1 )
6632 : {
6633 0 : buf->curdist = buf->curdist-ae_maxreal(v-t1, (double)(0), _state)+s-t1;
6634 : }
6635 0 : if( kdt->normtype==2 )
6636 : {
6637 0 : buf->curdist = buf->curdist-ae_sqr(ae_maxreal(v-t1, (double)(0), _state), _state)+ae_sqr(s-t1, _state);
6638 : }
6639 : }
6640 0 : buf->curboxmin.ptr.p_double[d] = s;
6641 : }
6642 : else
6643 : {
6644 0 : prevdist = buf->curdist;
6645 0 : t1 = buf->x.ptr.p_double[d];
6646 0 : v = buf->curboxmax.ptr.p_double[d];
6647 0 : if( t1>=s )
6648 : {
6649 0 : if( kdt->normtype==0 )
6650 : {
6651 0 : buf->curdist = ae_maxreal(buf->curdist, t1-s, _state);
6652 : }
6653 0 : if( kdt->normtype==1 )
6654 : {
6655 0 : buf->curdist = buf->curdist-ae_maxreal(t1-v, (double)(0), _state)+t1-s;
6656 : }
6657 0 : if( kdt->normtype==2 )
6658 : {
6659 0 : buf->curdist = buf->curdist-ae_sqr(ae_maxreal(t1-v, (double)(0), _state), _state)+ae_sqr(t1-s, _state);
6660 : }
6661 : }
6662 0 : buf->curboxmax.ptr.p_double[d] = s;
6663 : }
6664 :
6665 : /*
6666 : * Decide: to dive into cell or not to dive
6667 : */
6668 0 : if( buf->rneeded!=0&&buf->curdist>buf->rneeded )
6669 : {
6670 0 : todive = ae_false;
6671 : }
6672 : else
6673 : {
6674 0 : if( buf->kcur<buf->kneeded||buf->kneeded==0 )
6675 : {
6676 :
6677 : /*
6678 : * KCur<KNeeded (i.e. not all points are found)
6679 : */
6680 0 : todive = ae_true;
6681 : }
6682 : else
6683 : {
6684 :
6685 : /*
6686 : * KCur=KNeeded, decide to dive or not to dive
6687 : * using point position relative to bounding box.
6688 : */
6689 0 : todive = buf->curdist<=buf->r.ptr.p_double[0]*buf->approxf;
6690 : }
6691 : }
6692 0 : if( todive )
6693 : {
6694 0 : nearestneighbor_kdtreequerynnrec(kdt, buf, childoffs, _state);
6695 : }
6696 :
6697 : /*
6698 : * Restore bounding box and distance
6699 : */
6700 0 : if( updatemin )
6701 : {
6702 0 : buf->curboxmin.ptr.p_double[d] = v;
6703 : }
6704 : else
6705 : {
6706 0 : buf->curboxmax.ptr.p_double[d] = v;
6707 : }
6708 0 : buf->curdist = prevdist;
6709 : }
6710 0 : return;
6711 : }
6712 : }
6713 :
6714 :
6715 : /*************************************************************************
6716 : Recursive subroutine for box queries.
6717 :
6718 : -- ALGLIB --
6719 : Copyright 28.02.2010 by Bochkanov Sergey
6720 : *************************************************************************/
6721 0 : static void nearestneighbor_kdtreequeryboxrec(kdtree* kdt,
6722 : kdtreerequestbuffer* buf,
6723 : ae_int_t offs,
6724 : ae_state *_state)
6725 : {
6726 : ae_bool inbox;
6727 : ae_int_t nx;
6728 : ae_int_t i1;
6729 : ae_int_t i2;
6730 : ae_int_t i;
6731 : ae_int_t j;
6732 : ae_int_t d;
6733 : double s;
6734 : double v;
6735 :
6736 :
6737 0 : ae_assert(kdt->n>0, "KDTreeQueryBoxRec: internal error", _state);
6738 0 : nx = kdt->nx;
6739 :
6740 : /*
6741 : * Check that intersection of query box with bounding box is non-empty.
6742 : * This check is performed once for Offs=0 (tree root).
6743 : */
6744 0 : if( offs==0 )
6745 : {
6746 0 : for(j=0; j<=nx-1; j++)
6747 : {
6748 0 : if( buf->boxmin.ptr.p_double[j]>buf->curboxmax.ptr.p_double[j] )
6749 : {
6750 0 : return;
6751 : }
6752 0 : if( buf->boxmax.ptr.p_double[j]<buf->curboxmin.ptr.p_double[j] )
6753 : {
6754 0 : return;
6755 : }
6756 : }
6757 : }
6758 :
6759 : /*
6760 : * Leaf node.
6761 : * Process points.
6762 : */
6763 0 : if( kdt->nodes.ptr.p_int[offs]>0 )
6764 : {
6765 0 : i1 = kdt->nodes.ptr.p_int[offs+1];
6766 0 : i2 = i1+kdt->nodes.ptr.p_int[offs];
6767 0 : for(i=i1; i<=i2-1; i++)
6768 : {
6769 :
6770 : /*
6771 : * Check whether point is in box or not
6772 : */
6773 0 : inbox = ae_true;
6774 0 : for(j=0; j<=nx-1; j++)
6775 : {
6776 0 : inbox = inbox&&kdt->xy.ptr.pp_double[i][j]>=buf->boxmin.ptr.p_double[j];
6777 0 : inbox = inbox&&kdt->xy.ptr.pp_double[i][j]<=buf->boxmax.ptr.p_double[j];
6778 : }
6779 0 : if( !inbox )
6780 : {
6781 0 : continue;
6782 : }
6783 :
6784 : /*
6785 : * Add point to unordered list
6786 : */
6787 0 : buf->r.ptr.p_double[buf->kcur] = 0.0;
6788 0 : buf->idx.ptr.p_int[buf->kcur] = i;
6789 0 : buf->kcur = buf->kcur+1;
6790 : }
6791 0 : return;
6792 : }
6793 :
6794 : /*
6795 : * Simple split
6796 : */
6797 0 : if( kdt->nodes.ptr.p_int[offs]==0 )
6798 : {
6799 :
6800 : /*
6801 : * Load:
6802 : * * D dimension to split
6803 : * * S split position
6804 : */
6805 0 : d = kdt->nodes.ptr.p_int[offs+1];
6806 0 : s = kdt->splits.ptr.p_double[kdt->nodes.ptr.p_int[offs+2]];
6807 :
6808 : /*
6809 : * Check lower split (S is upper bound of new bounding box)
6810 : */
6811 0 : if( s>=buf->boxmin.ptr.p_double[d] )
6812 : {
6813 0 : v = buf->curboxmax.ptr.p_double[d];
6814 0 : buf->curboxmax.ptr.p_double[d] = s;
6815 0 : nearestneighbor_kdtreequeryboxrec(kdt, buf, kdt->nodes.ptr.p_int[offs+3], _state);
6816 0 : buf->curboxmax.ptr.p_double[d] = v;
6817 : }
6818 :
6819 : /*
6820 : * Check upper split (S is lower bound of new bounding box)
6821 : */
6822 0 : if( s<=buf->boxmax.ptr.p_double[d] )
6823 : {
6824 0 : v = buf->curboxmin.ptr.p_double[d];
6825 0 : buf->curboxmin.ptr.p_double[d] = s;
6826 0 : nearestneighbor_kdtreequeryboxrec(kdt, buf, kdt->nodes.ptr.p_int[offs+4], _state);
6827 0 : buf->curboxmin.ptr.p_double[d] = v;
6828 : }
6829 0 : return;
6830 : }
6831 : }
6832 :
6833 :
6834 : /*************************************************************************
6835 : Copies X[] to Buf.X[]
6836 : Loads distance from X[] to bounding box.
6837 : Initializes Buf.CurBox[].
6838 :
6839 : -- ALGLIB --
6840 : Copyright 28.02.2010 by Bochkanov Sergey
6841 : *************************************************************************/
6842 0 : static void nearestneighbor_kdtreeinitbox(kdtree* kdt,
6843 : /* Real */ ae_vector* x,
6844 : kdtreerequestbuffer* buf,
6845 : ae_state *_state)
6846 : {
6847 : ae_int_t i;
6848 : double vx;
6849 : double vmin;
6850 : double vmax;
6851 :
6852 :
6853 0 : ae_assert(kdt->n>0, "KDTreeInitBox: internal error", _state);
6854 :
6855 : /*
6856 : * calculate distance from point to current bounding box
6857 : */
6858 0 : buf->curdist = (double)(0);
6859 0 : if( kdt->normtype==0 )
6860 : {
6861 0 : for(i=0; i<=kdt->nx-1; i++)
6862 : {
6863 0 : vx = x->ptr.p_double[i];
6864 0 : vmin = kdt->boxmin.ptr.p_double[i];
6865 0 : vmax = kdt->boxmax.ptr.p_double[i];
6866 0 : buf->x.ptr.p_double[i] = vx;
6867 0 : buf->curboxmin.ptr.p_double[i] = vmin;
6868 0 : buf->curboxmax.ptr.p_double[i] = vmax;
6869 0 : if( vx<vmin )
6870 : {
6871 0 : buf->curdist = ae_maxreal(buf->curdist, vmin-vx, _state);
6872 : }
6873 : else
6874 : {
6875 0 : if( vx>vmax )
6876 : {
6877 0 : buf->curdist = ae_maxreal(buf->curdist, vx-vmax, _state);
6878 : }
6879 : }
6880 : }
6881 : }
6882 0 : if( kdt->normtype==1 )
6883 : {
6884 0 : for(i=0; i<=kdt->nx-1; i++)
6885 : {
6886 0 : vx = x->ptr.p_double[i];
6887 0 : vmin = kdt->boxmin.ptr.p_double[i];
6888 0 : vmax = kdt->boxmax.ptr.p_double[i];
6889 0 : buf->x.ptr.p_double[i] = vx;
6890 0 : buf->curboxmin.ptr.p_double[i] = vmin;
6891 0 : buf->curboxmax.ptr.p_double[i] = vmax;
6892 0 : if( vx<vmin )
6893 : {
6894 0 : buf->curdist = buf->curdist+vmin-vx;
6895 : }
6896 : else
6897 : {
6898 0 : if( vx>vmax )
6899 : {
6900 0 : buf->curdist = buf->curdist+vx-vmax;
6901 : }
6902 : }
6903 : }
6904 : }
6905 0 : if( kdt->normtype==2 )
6906 : {
6907 0 : for(i=0; i<=kdt->nx-1; i++)
6908 : {
6909 0 : vx = x->ptr.p_double[i];
6910 0 : vmin = kdt->boxmin.ptr.p_double[i];
6911 0 : vmax = kdt->boxmax.ptr.p_double[i];
6912 0 : buf->x.ptr.p_double[i] = vx;
6913 0 : buf->curboxmin.ptr.p_double[i] = vmin;
6914 0 : buf->curboxmax.ptr.p_double[i] = vmax;
6915 0 : if( vx<vmin )
6916 : {
6917 0 : buf->curdist = buf->curdist+ae_sqr(vmin-vx, _state);
6918 : }
6919 : else
6920 : {
6921 0 : if( vx>vmax )
6922 : {
6923 0 : buf->curdist = buf->curdist+ae_sqr(vx-vmax, _state);
6924 : }
6925 : }
6926 : }
6927 : }
6928 0 : }
6929 :
6930 :
6931 : /*************************************************************************
6932 : This function allocates all dataset-independend array fields of KDTree,
6933 : i.e. such array fields that their dimensions do not depend on dataset
6934 : size.
6935 :
6936 : This function do not sets KDT.NX or KDT.NY - it just allocates arrays
6937 :
6938 : -- ALGLIB --
6939 : Copyright 14.03.2011 by Bochkanov Sergey
6940 : *************************************************************************/
6941 0 : static void nearestneighbor_kdtreeallocdatasetindependent(kdtree* kdt,
6942 : ae_int_t nx,
6943 : ae_int_t ny,
6944 : ae_state *_state)
6945 : {
6946 :
6947 :
6948 0 : ae_assert(kdt->n>0, "KDTreeAllocDatasetIndependent: internal error", _state);
6949 0 : ae_vector_set_length(&kdt->boxmin, nx, _state);
6950 0 : ae_vector_set_length(&kdt->boxmax, nx, _state);
6951 0 : }
6952 :
6953 :
6954 : /*************************************************************************
6955 : This function allocates all dataset-dependent array fields of KDTree, i.e.
6956 : such array fields that their dimensions depend on dataset size.
6957 :
6958 : This function do not sets KDT.N, KDT.NX or KDT.NY -
6959 : it just allocates arrays.
6960 :
6961 : -- ALGLIB --
6962 : Copyright 14.03.2011 by Bochkanov Sergey
6963 : *************************************************************************/
6964 0 : static void nearestneighbor_kdtreeallocdatasetdependent(kdtree* kdt,
6965 : ae_int_t n,
6966 : ae_int_t nx,
6967 : ae_int_t ny,
6968 : ae_state *_state)
6969 : {
6970 :
6971 :
6972 0 : ae_assert(n>0, "KDTreeAllocDatasetDependent: internal error", _state);
6973 0 : ae_matrix_set_length(&kdt->xy, n, 2*nx+ny, _state);
6974 0 : ae_vector_set_length(&kdt->tags, n, _state);
6975 0 : ae_vector_set_length(&kdt->nodes, nearestneighbor_splitnodesize*2*n, _state);
6976 0 : ae_vector_set_length(&kdt->splits, 2*n, _state);
6977 0 : }
6978 :
6979 :
6980 : /*************************************************************************
6981 : This function checks consistency of request buffer structure with
6982 : dimensions of kd-tree object.
6983 :
6984 : -- ALGLIB --
6985 : Copyright 02.04.2016 by Bochkanov Sergey
6986 : *************************************************************************/
6987 0 : static void nearestneighbor_checkrequestbufferconsistency(kdtree* kdt,
6988 : kdtreerequestbuffer* buf,
6989 : ae_state *_state)
6990 : {
6991 :
6992 :
6993 0 : ae_assert(buf->x.cnt>=kdt->nx, "KDTree: dimensions of kdtreerequestbuffer are inconsistent with kdtree structure", _state);
6994 0 : ae_assert(buf->idx.cnt>=kdt->n, "KDTree: dimensions of kdtreerequestbuffer are inconsistent with kdtree structure", _state);
6995 0 : ae_assert(buf->r.cnt>=kdt->n, "KDTree: dimensions of kdtreerequestbuffer are inconsistent with kdtree structure", _state);
6996 0 : ae_assert(buf->buf.cnt>=ae_maxint(kdt->n, kdt->nx, _state), "KDTree: dimensions of kdtreerequestbuffer are inconsistent with kdtree structure", _state);
6997 0 : ae_assert(buf->curboxmin.cnt>=kdt->nx, "KDTree: dimensions of kdtreerequestbuffer are inconsistent with kdtree structure", _state);
6998 0 : ae_assert(buf->curboxmax.cnt>=kdt->nx, "KDTree: dimensions of kdtreerequestbuffer are inconsistent with kdtree structure", _state);
6999 0 : }
7000 :
7001 :
7002 0 : void _kdtreerequestbuffer_init(void* _p, ae_state *_state, ae_bool make_automatic)
7003 : {
7004 0 : kdtreerequestbuffer *p = (kdtreerequestbuffer*)_p;
7005 0 : ae_touch_ptr((void*)p);
7006 0 : ae_vector_init(&p->x, 0, DT_REAL, _state, make_automatic);
7007 0 : ae_vector_init(&p->boxmin, 0, DT_REAL, _state, make_automatic);
7008 0 : ae_vector_init(&p->boxmax, 0, DT_REAL, _state, make_automatic);
7009 0 : ae_vector_init(&p->idx, 0, DT_INT, _state, make_automatic);
7010 0 : ae_vector_init(&p->r, 0, DT_REAL, _state, make_automatic);
7011 0 : ae_vector_init(&p->buf, 0, DT_REAL, _state, make_automatic);
7012 0 : ae_vector_init(&p->curboxmin, 0, DT_REAL, _state, make_automatic);
7013 0 : ae_vector_init(&p->curboxmax, 0, DT_REAL, _state, make_automatic);
7014 0 : }
7015 :
7016 :
7017 0 : void _kdtreerequestbuffer_init_copy(void* _dst, void* _src, ae_state *_state, ae_bool make_automatic)
7018 : {
7019 0 : kdtreerequestbuffer *dst = (kdtreerequestbuffer*)_dst;
7020 0 : kdtreerequestbuffer *src = (kdtreerequestbuffer*)_src;
7021 0 : ae_vector_init_copy(&dst->x, &src->x, _state, make_automatic);
7022 0 : ae_vector_init_copy(&dst->boxmin, &src->boxmin, _state, make_automatic);
7023 0 : ae_vector_init_copy(&dst->boxmax, &src->boxmax, _state, make_automatic);
7024 0 : dst->kneeded = src->kneeded;
7025 0 : dst->rneeded = src->rneeded;
7026 0 : dst->selfmatch = src->selfmatch;
7027 0 : dst->approxf = src->approxf;
7028 0 : dst->kcur = src->kcur;
7029 0 : ae_vector_init_copy(&dst->idx, &src->idx, _state, make_automatic);
7030 0 : ae_vector_init_copy(&dst->r, &src->r, _state, make_automatic);
7031 0 : ae_vector_init_copy(&dst->buf, &src->buf, _state, make_automatic);
7032 0 : ae_vector_init_copy(&dst->curboxmin, &src->curboxmin, _state, make_automatic);
7033 0 : ae_vector_init_copy(&dst->curboxmax, &src->curboxmax, _state, make_automatic);
7034 0 : dst->curdist = src->curdist;
7035 0 : }
7036 :
7037 :
7038 0 : void _kdtreerequestbuffer_clear(void* _p)
7039 : {
7040 0 : kdtreerequestbuffer *p = (kdtreerequestbuffer*)_p;
7041 0 : ae_touch_ptr((void*)p);
7042 0 : ae_vector_clear(&p->x);
7043 0 : ae_vector_clear(&p->boxmin);
7044 0 : ae_vector_clear(&p->boxmax);
7045 0 : ae_vector_clear(&p->idx);
7046 0 : ae_vector_clear(&p->r);
7047 0 : ae_vector_clear(&p->buf);
7048 0 : ae_vector_clear(&p->curboxmin);
7049 0 : ae_vector_clear(&p->curboxmax);
7050 0 : }
7051 :
7052 :
7053 0 : void _kdtreerequestbuffer_destroy(void* _p)
7054 : {
7055 0 : kdtreerequestbuffer *p = (kdtreerequestbuffer*)_p;
7056 0 : ae_touch_ptr((void*)p);
7057 0 : ae_vector_destroy(&p->x);
7058 0 : ae_vector_destroy(&p->boxmin);
7059 0 : ae_vector_destroy(&p->boxmax);
7060 0 : ae_vector_destroy(&p->idx);
7061 0 : ae_vector_destroy(&p->r);
7062 0 : ae_vector_destroy(&p->buf);
7063 0 : ae_vector_destroy(&p->curboxmin);
7064 0 : ae_vector_destroy(&p->curboxmax);
7065 0 : }
7066 :
7067 :
7068 0 : void _kdtree_init(void* _p, ae_state *_state, ae_bool make_automatic)
7069 : {
7070 0 : kdtree *p = (kdtree*)_p;
7071 0 : ae_touch_ptr((void*)p);
7072 0 : ae_matrix_init(&p->xy, 0, 0, DT_REAL, _state, make_automatic);
7073 0 : ae_vector_init(&p->tags, 0, DT_INT, _state, make_automatic);
7074 0 : ae_vector_init(&p->boxmin, 0, DT_REAL, _state, make_automatic);
7075 0 : ae_vector_init(&p->boxmax, 0, DT_REAL, _state, make_automatic);
7076 0 : ae_vector_init(&p->nodes, 0, DT_INT, _state, make_automatic);
7077 0 : ae_vector_init(&p->splits, 0, DT_REAL, _state, make_automatic);
7078 0 : _kdtreerequestbuffer_init(&p->innerbuf, _state, make_automatic);
7079 0 : }
7080 :
7081 :
7082 0 : void _kdtree_init_copy(void* _dst, void* _src, ae_state *_state, ae_bool make_automatic)
7083 : {
7084 0 : kdtree *dst = (kdtree*)_dst;
7085 0 : kdtree *src = (kdtree*)_src;
7086 0 : dst->n = src->n;
7087 0 : dst->nx = src->nx;
7088 0 : dst->ny = src->ny;
7089 0 : dst->normtype = src->normtype;
7090 0 : ae_matrix_init_copy(&dst->xy, &src->xy, _state, make_automatic);
7091 0 : ae_vector_init_copy(&dst->tags, &src->tags, _state, make_automatic);
7092 0 : ae_vector_init_copy(&dst->boxmin, &src->boxmin, _state, make_automatic);
7093 0 : ae_vector_init_copy(&dst->boxmax, &src->boxmax, _state, make_automatic);
7094 0 : ae_vector_init_copy(&dst->nodes, &src->nodes, _state, make_automatic);
7095 0 : ae_vector_init_copy(&dst->splits, &src->splits, _state, make_automatic);
7096 0 : _kdtreerequestbuffer_init_copy(&dst->innerbuf, &src->innerbuf, _state, make_automatic);
7097 0 : dst->debugcounter = src->debugcounter;
7098 0 : }
7099 :
7100 :
7101 0 : void _kdtree_clear(void* _p)
7102 : {
7103 0 : kdtree *p = (kdtree*)_p;
7104 0 : ae_touch_ptr((void*)p);
7105 0 : ae_matrix_clear(&p->xy);
7106 0 : ae_vector_clear(&p->tags);
7107 0 : ae_vector_clear(&p->boxmin);
7108 0 : ae_vector_clear(&p->boxmax);
7109 0 : ae_vector_clear(&p->nodes);
7110 0 : ae_vector_clear(&p->splits);
7111 0 : _kdtreerequestbuffer_clear(&p->innerbuf);
7112 0 : }
7113 :
7114 :
7115 0 : void _kdtree_destroy(void* _p)
7116 : {
7117 0 : kdtree *p = (kdtree*)_p;
7118 0 : ae_touch_ptr((void*)p);
7119 0 : ae_matrix_destroy(&p->xy);
7120 0 : ae_vector_destroy(&p->tags);
7121 0 : ae_vector_destroy(&p->boxmin);
7122 0 : ae_vector_destroy(&p->boxmax);
7123 0 : ae_vector_destroy(&p->nodes);
7124 0 : ae_vector_destroy(&p->splits);
7125 0 : _kdtreerequestbuffer_destroy(&p->innerbuf);
7126 0 : }
7127 :
7128 :
7129 : #endif
7130 : #if defined(AE_COMPILE_HQRND) || !defined(AE_PARTIAL_BUILD)
7131 :
7132 :
7133 : /*************************************************************************
7134 : HQRNDState initialization with random values which come from standard
7135 : RNG.
7136 :
7137 : -- ALGLIB --
7138 : Copyright 02.12.2009 by Bochkanov Sergey
7139 : *************************************************************************/
7140 0 : void hqrndrandomize(hqrndstate* state, ae_state *_state)
7141 : {
7142 : ae_int_t s0;
7143 : ae_int_t s1;
7144 :
7145 0 : _hqrndstate_clear(state);
7146 :
7147 0 : s0 = ae_randominteger(hqrnd_hqrndm1, _state);
7148 0 : s1 = ae_randominteger(hqrnd_hqrndm2, _state);
7149 0 : hqrndseed(s0, s1, state, _state);
7150 0 : }
7151 :
7152 :
7153 : /*************************************************************************
7154 : HQRNDState initialization with seed values
7155 :
7156 : -- ALGLIB --
7157 : Copyright 02.12.2009 by Bochkanov Sergey
7158 : *************************************************************************/
7159 0 : void hqrndseed(ae_int_t s1,
7160 : ae_int_t s2,
7161 : hqrndstate* state,
7162 : ae_state *_state)
7163 : {
7164 :
7165 0 : _hqrndstate_clear(state);
7166 :
7167 :
7168 : /*
7169 : * Protection against negative seeds:
7170 : *
7171 : * SEED := -(SEED+1)
7172 : *
7173 : * We can use just "-SEED" because there exists such integer number N
7174 : * that N<0, -N=N<0 too. (This number is equal to 0x800...000). Need
7175 : * to handle such seed correctly forces us to use a bit complicated
7176 : * formula.
7177 : */
7178 0 : if( s1<0 )
7179 : {
7180 0 : s1 = -(s1+1);
7181 : }
7182 0 : if( s2<0 )
7183 : {
7184 0 : s2 = -(s2+1);
7185 : }
7186 0 : state->s1 = s1%(hqrnd_hqrndm1-1)+1;
7187 0 : state->s2 = s2%(hqrnd_hqrndm2-1)+1;
7188 0 : state->magicv = hqrnd_hqrndmagic;
7189 0 : }
7190 :
7191 :
7192 : /*************************************************************************
7193 : This function generates random real number in (0,1),
7194 : not including interval boundaries
7195 :
7196 : State structure must be initialized with HQRNDRandomize() or HQRNDSeed().
7197 :
7198 : -- ALGLIB --
7199 : Copyright 02.12.2009 by Bochkanov Sergey
7200 : *************************************************************************/
7201 0 : double hqrnduniformr(hqrndstate* state, ae_state *_state)
7202 : {
7203 : double result;
7204 :
7205 :
7206 0 : result = (double)(hqrnd_hqrndintegerbase(state, _state)+1)/(double)(hqrnd_hqrndmax+2);
7207 0 : return result;
7208 : }
7209 :
7210 :
7211 : /*************************************************************************
7212 : This function generates random integer number in [0, N)
7213 :
7214 : 1. State structure must be initialized with HQRNDRandomize() or HQRNDSeed()
7215 : 2. N can be any positive number except for very large numbers:
7216 : * close to 2^31 on 32-bit systems
7217 : * close to 2^62 on 64-bit systems
7218 : An exception will be generated if N is too large.
7219 :
7220 : -- ALGLIB --
7221 : Copyright 02.12.2009 by Bochkanov Sergey
7222 : *************************************************************************/
7223 0 : ae_int_t hqrnduniformi(hqrndstate* state, ae_int_t n, ae_state *_state)
7224 : {
7225 : ae_int_t maxcnt;
7226 : ae_int_t mx;
7227 : ae_int_t a;
7228 : ae_int_t b;
7229 : ae_int_t result;
7230 :
7231 :
7232 0 : ae_assert(n>0, "HQRNDUniformI: N<=0!", _state);
7233 0 : maxcnt = hqrnd_hqrndmax+1;
7234 :
7235 : /*
7236 : * Two branches: one for N<=MaxCnt, another for N>MaxCnt.
7237 : */
7238 0 : if( n>maxcnt )
7239 : {
7240 :
7241 : /*
7242 : * N>=MaxCnt.
7243 : *
7244 : * We have two options here:
7245 : * a) N is exactly divisible by MaxCnt
7246 : * b) N is not divisible by MaxCnt
7247 : *
7248 : * In both cases we reduce problem on interval spanning [0,N)
7249 : * to several subproblems on intervals spanning [0,MaxCnt).
7250 : */
7251 0 : if( n%maxcnt==0 )
7252 : {
7253 :
7254 : /*
7255 : * N is exactly divisible by MaxCnt.
7256 : *
7257 : * [0,N) range is dividided into N/MaxCnt bins,
7258 : * each of them having length equal to MaxCnt.
7259 : *
7260 : * We generate:
7261 : * * random bin number B
7262 : * * random offset within bin A
7263 : * Both random numbers are generated by recursively
7264 : * calling HQRNDUniformI().
7265 : *
7266 : * Result is equal to A+MaxCnt*B.
7267 : */
7268 0 : ae_assert(n/maxcnt<=maxcnt, "HQRNDUniformI: N is too large", _state);
7269 0 : a = hqrnduniformi(state, maxcnt, _state);
7270 0 : b = hqrnduniformi(state, n/maxcnt, _state);
7271 0 : result = a+maxcnt*b;
7272 : }
7273 : else
7274 : {
7275 :
7276 : /*
7277 : * N is NOT exactly divisible by MaxCnt.
7278 : *
7279 : * [0,N) range is dividided into Ceil(N/MaxCnt) bins,
7280 : * each of them having length equal to MaxCnt.
7281 : *
7282 : * We generate:
7283 : * * random bin number B in [0, Ceil(N/MaxCnt)-1]
7284 : * * random offset within bin A
7285 : * * if both of what is below is true
7286 : * 1) bin number B is that of the last bin
7287 : * 2) A >= N mod MaxCnt
7288 : * then we repeat generation of A/B.
7289 : * This stage is essential in order to avoid bias in the result.
7290 : * * otherwise, we return A*MaxCnt+N
7291 : */
7292 0 : ae_assert(n/maxcnt+1<=maxcnt, "HQRNDUniformI: N is too large", _state);
7293 0 : result = -1;
7294 0 : do
7295 : {
7296 0 : a = hqrnduniformi(state, maxcnt, _state);
7297 0 : b = hqrnduniformi(state, n/maxcnt+1, _state);
7298 0 : if( b==n/maxcnt&&a>=n%maxcnt )
7299 : {
7300 0 : continue;
7301 : }
7302 0 : result = a+maxcnt*b;
7303 : }
7304 0 : while(result<0);
7305 : }
7306 : }
7307 : else
7308 : {
7309 :
7310 : /*
7311 : * N<=MaxCnt
7312 : *
7313 : * Code below is a bit complicated because we can not simply
7314 : * return "HQRNDIntegerBase() mod N" - it will be skewed for
7315 : * large N's in [0.1*HQRNDMax...HQRNDMax].
7316 : */
7317 0 : mx = maxcnt-maxcnt%n;
7318 0 : do
7319 : {
7320 0 : result = hqrnd_hqrndintegerbase(state, _state);
7321 : }
7322 0 : while(result>=mx);
7323 0 : result = result%n;
7324 : }
7325 0 : return result;
7326 : }
7327 :
7328 :
7329 : /*************************************************************************
7330 : Random number generator: normal numbers
7331 :
7332 : This function generates one random number from normal distribution.
7333 : Its performance is equal to that of HQRNDNormal2()
7334 :
7335 : State structure must be initialized with HQRNDRandomize() or HQRNDSeed().
7336 :
7337 : -- ALGLIB --
7338 : Copyright 02.12.2009 by Bochkanov Sergey
7339 : *************************************************************************/
7340 0 : double hqrndnormal(hqrndstate* state, ae_state *_state)
7341 : {
7342 : double v1;
7343 : double v2;
7344 : double result;
7345 :
7346 :
7347 0 : hqrndnormal2(state, &v1, &v2, _state);
7348 0 : result = v1;
7349 0 : return result;
7350 : }
7351 :
7352 :
7353 : /*************************************************************************
7354 : Random number generator: vector with random entries (normal distribution)
7355 :
7356 : This function generates N random numbers from normal distribution.
7357 :
7358 : State structure must be initialized with HQRNDRandomize() or HQRNDSeed().
7359 :
7360 : -- ALGLIB --
7361 : Copyright 02.12.2009 by Bochkanov Sergey
7362 : *************************************************************************/
7363 0 : void hqrndnormalv(hqrndstate* state,
7364 : ae_int_t n,
7365 : /* Real */ ae_vector* x,
7366 : ae_state *_state)
7367 : {
7368 : ae_int_t i;
7369 : ae_int_t n2;
7370 : double v1;
7371 : double v2;
7372 :
7373 0 : ae_vector_clear(x);
7374 :
7375 0 : n2 = n/2;
7376 0 : rallocv(n, x, _state);
7377 0 : for(i=0; i<=n2-1; i++)
7378 : {
7379 0 : hqrndnormal2(state, &v1, &v2, _state);
7380 0 : x->ptr.p_double[2*i+0] = v1;
7381 0 : x->ptr.p_double[2*i+1] = v2;
7382 : }
7383 0 : if( n%2!=0 )
7384 : {
7385 0 : hqrndnormal2(state, &v1, &v2, _state);
7386 0 : x->ptr.p_double[n-1] = v1;
7387 : }
7388 0 : }
7389 :
7390 :
7391 : /*************************************************************************
7392 : Random number generator: matrix with random entries (normal distribution)
7393 :
7394 : This function generates MxN random matrix.
7395 :
7396 : State structure must be initialized with HQRNDRandomize() or HQRNDSeed().
7397 :
7398 : -- ALGLIB --
7399 : Copyright 02.12.2009 by Bochkanov Sergey
7400 : *************************************************************************/
7401 0 : void hqrndnormalm(hqrndstate* state,
7402 : ae_int_t m,
7403 : ae_int_t n,
7404 : /* Real */ ae_matrix* x,
7405 : ae_state *_state)
7406 : {
7407 : ae_int_t i;
7408 : ae_int_t j;
7409 : ae_int_t n2;
7410 : double v1;
7411 : double v2;
7412 :
7413 0 : ae_matrix_clear(x);
7414 :
7415 0 : n2 = n/2;
7416 0 : ae_matrix_set_length(x, m, n, _state);
7417 0 : for(i=0; i<=m-1; i++)
7418 : {
7419 0 : for(j=0; j<=n2-1; j++)
7420 : {
7421 0 : hqrndnormal2(state, &v1, &v2, _state);
7422 0 : x->ptr.pp_double[i][2*j+0] = v1;
7423 0 : x->ptr.pp_double[i][2*j+1] = v2;
7424 : }
7425 0 : if( n%2!=0 )
7426 : {
7427 0 : hqrndnormal2(state, &v1, &v2, _state);
7428 0 : x->ptr.pp_double[i][n-1] = v1;
7429 : }
7430 : }
7431 0 : }
7432 :
7433 :
7434 : /*************************************************************************
7435 : Random number generator: random X and Y such that X^2+Y^2=1
7436 :
7437 : State structure must be initialized with HQRNDRandomize() or HQRNDSeed().
7438 :
7439 : -- ALGLIB --
7440 : Copyright 02.12.2009 by Bochkanov Sergey
7441 : *************************************************************************/
7442 0 : void hqrndunit2(hqrndstate* state, double* x, double* y, ae_state *_state)
7443 : {
7444 : double v;
7445 : double mx;
7446 : double mn;
7447 :
7448 0 : *x = 0;
7449 0 : *y = 0;
7450 :
7451 0 : do
7452 : {
7453 0 : hqrndnormal2(state, x, y, _state);
7454 : }
7455 0 : while(!(ae_fp_neq(*x,(double)(0))||ae_fp_neq(*y,(double)(0))));
7456 0 : mx = ae_maxreal(ae_fabs(*x, _state), ae_fabs(*y, _state), _state);
7457 0 : mn = ae_minreal(ae_fabs(*x, _state), ae_fabs(*y, _state), _state);
7458 0 : v = mx*ae_sqrt(1+ae_sqr(mn/mx, _state), _state);
7459 0 : *x = *x/v;
7460 0 : *y = *y/v;
7461 0 : }
7462 :
7463 :
7464 : /*************************************************************************
7465 : Random number generator: normal numbers
7466 :
7467 : This function generates two independent random numbers from normal
7468 : distribution. Its performance is equal to that of HQRNDNormal()
7469 :
7470 : State structure must be initialized with HQRNDRandomize() or HQRNDSeed().
7471 :
7472 : -- ALGLIB --
7473 : Copyright 02.12.2009 by Bochkanov Sergey
7474 : *************************************************************************/
7475 0 : void hqrndnormal2(hqrndstate* state,
7476 : double* x1,
7477 : double* x2,
7478 : ae_state *_state)
7479 : {
7480 : double u;
7481 : double v;
7482 : double s;
7483 :
7484 0 : *x1 = 0;
7485 0 : *x2 = 0;
7486 :
7487 : for(;;)
7488 : {
7489 0 : u = 2*hqrnduniformr(state, _state)-1;
7490 0 : v = 2*hqrnduniformr(state, _state)-1;
7491 0 : s = ae_sqr(u, _state)+ae_sqr(v, _state);
7492 0 : if( ae_fp_greater(s,(double)(0))&&ae_fp_less(s,(double)(1)) )
7493 : {
7494 :
7495 : /*
7496 : * two Sqrt's instead of one to
7497 : * avoid overflow when S is too small
7498 : */
7499 0 : s = ae_sqrt(-2*ae_log(s, _state), _state)/ae_sqrt(s, _state);
7500 0 : *x1 = u*s;
7501 0 : *x2 = v*s;
7502 0 : return;
7503 : }
7504 : }
7505 : }
7506 :
7507 :
7508 : /*************************************************************************
7509 : Random number generator: exponential distribution
7510 :
7511 : State structure must be initialized with HQRNDRandomize() or HQRNDSeed().
7512 :
7513 : -- ALGLIB --
7514 : Copyright 11.08.2007 by Bochkanov Sergey
7515 : *************************************************************************/
7516 0 : double hqrndexponential(hqrndstate* state,
7517 : double lambdav,
7518 : ae_state *_state)
7519 : {
7520 : double result;
7521 :
7522 :
7523 0 : ae_assert(ae_fp_greater(lambdav,(double)(0)), "HQRNDExponential: LambdaV<=0!", _state);
7524 0 : result = -ae_log(hqrnduniformr(state, _state), _state)/lambdav;
7525 0 : return result;
7526 : }
7527 :
7528 :
7529 : /*************************************************************************
7530 : This function generates random number from discrete distribution given by
7531 : finite sample X.
7532 :
7533 : INPUT PARAMETERS
7534 : State - high quality random number generator, must be
7535 : initialized with HQRNDRandomize() or HQRNDSeed().
7536 : X - finite sample
7537 : N - number of elements to use, N>=1
7538 :
7539 : RESULT
7540 : this function returns one of the X[i] for random i=0..N-1
7541 :
7542 : -- ALGLIB --
7543 : Copyright 08.11.2011 by Bochkanov Sergey
7544 : *************************************************************************/
7545 0 : double hqrnddiscrete(hqrndstate* state,
7546 : /* Real */ ae_vector* x,
7547 : ae_int_t n,
7548 : ae_state *_state)
7549 : {
7550 : double result;
7551 :
7552 :
7553 0 : ae_assert(n>0, "HQRNDDiscrete: N<=0", _state);
7554 0 : ae_assert(n<=x->cnt, "HQRNDDiscrete: Length(X)<N", _state);
7555 0 : result = x->ptr.p_double[hqrnduniformi(state, n, _state)];
7556 0 : return result;
7557 : }
7558 :
7559 :
7560 : /*************************************************************************
7561 : This function generates random number from continuous distribution given
7562 : by finite sample X.
7563 :
7564 : INPUT PARAMETERS
7565 : State - high quality random number generator, must be
7566 : initialized with HQRNDRandomize() or HQRNDSeed().
7567 : X - finite sample, array[N] (can be larger, in this case only
7568 : leading N elements are used). THIS ARRAY MUST BE SORTED BY
7569 : ASCENDING.
7570 : N - number of elements to use, N>=1
7571 :
7572 : RESULT
7573 : this function returns random number from continuous distribution which
7574 : tries to approximate X as mush as possible. min(X)<=Result<=max(X).
7575 :
7576 : -- ALGLIB --
7577 : Copyright 08.11.2011 by Bochkanov Sergey
7578 : *************************************************************************/
7579 0 : double hqrndcontinuous(hqrndstate* state,
7580 : /* Real */ ae_vector* x,
7581 : ae_int_t n,
7582 : ae_state *_state)
7583 : {
7584 : double mx;
7585 : double mn;
7586 : ae_int_t i;
7587 : double result;
7588 :
7589 :
7590 0 : ae_assert(n>0, "HQRNDContinuous: N<=0", _state);
7591 0 : ae_assert(n<=x->cnt, "HQRNDContinuous: Length(X)<N", _state);
7592 0 : if( n==1 )
7593 : {
7594 0 : result = x->ptr.p_double[0];
7595 0 : return result;
7596 : }
7597 0 : i = hqrnduniformi(state, n-1, _state);
7598 0 : mn = x->ptr.p_double[i];
7599 0 : mx = x->ptr.p_double[i+1];
7600 0 : ae_assert(ae_fp_greater_eq(mx,mn), "HQRNDDiscrete: X is not sorted by ascending", _state);
7601 0 : if( ae_fp_neq(mx,mn) )
7602 : {
7603 0 : result = (mx-mn)*hqrnduniformr(state, _state)+mn;
7604 : }
7605 : else
7606 : {
7607 0 : result = mn;
7608 : }
7609 0 : return result;
7610 : }
7611 :
7612 :
7613 : /*************************************************************************
7614 : This function returns random integer in [0,HQRNDMax]
7615 :
7616 : L'Ecuyer, Efficient and portable combined random number generators
7617 : *************************************************************************/
7618 0 : static ae_int_t hqrnd_hqrndintegerbase(hqrndstate* state,
7619 : ae_state *_state)
7620 : {
7621 : ae_int_t k;
7622 : ae_int_t result;
7623 :
7624 :
7625 0 : ae_assert(state->magicv==hqrnd_hqrndmagic, "HQRNDIntegerBase: State is not correctly initialized!", _state);
7626 0 : k = state->s1/53668;
7627 0 : state->s1 = 40014*(state->s1-k*53668)-k*12211;
7628 0 : if( state->s1<0 )
7629 : {
7630 0 : state->s1 = state->s1+2147483563;
7631 : }
7632 0 : k = state->s2/52774;
7633 0 : state->s2 = 40692*(state->s2-k*52774)-k*3791;
7634 0 : if( state->s2<0 )
7635 : {
7636 0 : state->s2 = state->s2+2147483399;
7637 : }
7638 :
7639 : /*
7640 : * Result
7641 : */
7642 0 : result = state->s1-state->s2;
7643 0 : if( result<1 )
7644 : {
7645 0 : result = result+2147483562;
7646 : }
7647 0 : result = result-1;
7648 0 : return result;
7649 : }
7650 :
7651 :
7652 0 : void _hqrndstate_init(void* _p, ae_state *_state, ae_bool make_automatic)
7653 : {
7654 0 : hqrndstate *p = (hqrndstate*)_p;
7655 0 : ae_touch_ptr((void*)p);
7656 0 : }
7657 :
7658 :
7659 0 : void _hqrndstate_init_copy(void* _dst, void* _src, ae_state *_state, ae_bool make_automatic)
7660 : {
7661 0 : hqrndstate *dst = (hqrndstate*)_dst;
7662 0 : hqrndstate *src = (hqrndstate*)_src;
7663 0 : dst->s1 = src->s1;
7664 0 : dst->s2 = src->s2;
7665 0 : dst->magicv = src->magicv;
7666 0 : }
7667 :
7668 :
7669 0 : void _hqrndstate_clear(void* _p)
7670 : {
7671 0 : hqrndstate *p = (hqrndstate*)_p;
7672 0 : ae_touch_ptr((void*)p);
7673 0 : }
7674 :
7675 :
7676 0 : void _hqrndstate_destroy(void* _p)
7677 : {
7678 0 : hqrndstate *p = (hqrndstate*)_p;
7679 0 : ae_touch_ptr((void*)p);
7680 0 : }
7681 :
7682 :
7683 : #endif
7684 : #if defined(AE_COMPILE_XDEBUG) || !defined(AE_PARTIAL_BUILD)
7685 :
7686 :
7687 : /*************************************************************************
7688 : This is debug function intended for testing ALGLIB interface generator.
7689 : Never use it in any real life project.
7690 :
7691 : Creates and returns XDebugRecord1 structure:
7692 : * integer and complex fields of Rec1 are set to 1 and 1+i correspondingly
7693 : * array field of Rec1 is set to [2,3]
7694 :
7695 : -- ALGLIB --
7696 : Copyright 27.05.2014 by Bochkanov Sergey
7697 : *************************************************************************/
7698 0 : void xdebuginitrecord1(xdebugrecord1* rec1, ae_state *_state)
7699 : {
7700 :
7701 0 : _xdebugrecord1_clear(rec1);
7702 :
7703 0 : rec1->i = 1;
7704 0 : rec1->c.x = (double)(1);
7705 0 : rec1->c.y = (double)(1);
7706 0 : ae_vector_set_length(&rec1->a, 2, _state);
7707 0 : rec1->a.ptr.p_double[0] = (double)(2);
7708 0 : rec1->a.ptr.p_double[1] = (double)(3);
7709 0 : }
7710 :
7711 :
7712 : /*************************************************************************
7713 : This is debug function intended for testing ALGLIB interface generator.
7714 : Never use it in any real life project.
7715 :
7716 : Counts number of True values in the boolean 1D array.
7717 :
7718 : -- ALGLIB --
7719 : Copyright 11.10.2013 by Bochkanov Sergey
7720 : *************************************************************************/
7721 0 : ae_int_t xdebugb1count(/* Boolean */ ae_vector* a, ae_state *_state)
7722 : {
7723 : ae_int_t i;
7724 : ae_int_t result;
7725 :
7726 :
7727 0 : result = 0;
7728 0 : for(i=0; i<=a->cnt-1; i++)
7729 : {
7730 0 : if( a->ptr.p_bool[i] )
7731 : {
7732 0 : result = result+1;
7733 : }
7734 : }
7735 0 : return result;
7736 : }
7737 :
7738 :
7739 : /*************************************************************************
7740 : This is debug function intended for testing ALGLIB interface generator.
7741 : Never use it in any real life project.
7742 :
7743 : Replace all values in array by NOT(a[i]).
7744 : Array is passed using "shared" convention.
7745 :
7746 : -- ALGLIB --
7747 : Copyright 11.10.2013 by Bochkanov Sergey
7748 : *************************************************************************/
7749 0 : void xdebugb1not(/* Boolean */ ae_vector* a, ae_state *_state)
7750 : {
7751 : ae_int_t i;
7752 :
7753 :
7754 0 : for(i=0; i<=a->cnt-1; i++)
7755 : {
7756 0 : a->ptr.p_bool[i] = !a->ptr.p_bool[i];
7757 : }
7758 0 : }
7759 :
7760 :
7761 : /*************************************************************************
7762 : This is debug function intended for testing ALGLIB interface generator.
7763 : Never use it in any real life project.
7764 :
7765 : Appends copy of array to itself.
7766 : Array is passed using "var" convention.
7767 :
7768 : -- ALGLIB --
7769 : Copyright 11.10.2013 by Bochkanov Sergey
7770 : *************************************************************************/
7771 0 : void xdebugb1appendcopy(/* Boolean */ ae_vector* a, ae_state *_state)
7772 : {
7773 : ae_frame _frame_block;
7774 : ae_int_t i;
7775 : ae_vector b;
7776 :
7777 0 : ae_frame_make(_state, &_frame_block);
7778 0 : memset(&b, 0, sizeof(b));
7779 0 : ae_vector_init(&b, 0, DT_BOOL, _state, ae_true);
7780 :
7781 0 : ae_vector_set_length(&b, a->cnt, _state);
7782 0 : for(i=0; i<=b.cnt-1; i++)
7783 : {
7784 0 : b.ptr.p_bool[i] = a->ptr.p_bool[i];
7785 : }
7786 0 : ae_vector_set_length(a, 2*b.cnt, _state);
7787 0 : for(i=0; i<=a->cnt-1; i++)
7788 : {
7789 0 : a->ptr.p_bool[i] = b.ptr.p_bool[i%b.cnt];
7790 : }
7791 0 : ae_frame_leave(_state);
7792 0 : }
7793 :
7794 :
7795 : /*************************************************************************
7796 : This is debug function intended for testing ALGLIB interface generator.
7797 : Never use it in any real life project.
7798 :
7799 : Generate N-element array with even-numbered elements set to True.
7800 : Array is passed using "out" convention.
7801 :
7802 : -- ALGLIB --
7803 : Copyright 11.10.2013 by Bochkanov Sergey
7804 : *************************************************************************/
7805 0 : void xdebugb1outeven(ae_int_t n,
7806 : /* Boolean */ ae_vector* a,
7807 : ae_state *_state)
7808 : {
7809 : ae_int_t i;
7810 :
7811 0 : ae_vector_clear(a);
7812 :
7813 0 : ae_vector_set_length(a, n, _state);
7814 0 : for(i=0; i<=a->cnt-1; i++)
7815 : {
7816 0 : a->ptr.p_bool[i] = i%2==0;
7817 : }
7818 0 : }
7819 :
7820 :
7821 : /*************************************************************************
7822 : This is debug function intended for testing ALGLIB interface generator.
7823 : Never use it in any real life project.
7824 :
7825 : Returns sum of elements in the array.
7826 :
7827 : -- ALGLIB --
7828 : Copyright 11.10.2013 by Bochkanov Sergey
7829 : *************************************************************************/
7830 0 : ae_int_t xdebugi1sum(/* Integer */ ae_vector* a, ae_state *_state)
7831 : {
7832 : ae_int_t i;
7833 : ae_int_t result;
7834 :
7835 :
7836 0 : result = 0;
7837 0 : for(i=0; i<=a->cnt-1; i++)
7838 : {
7839 0 : result = result+a->ptr.p_int[i];
7840 : }
7841 0 : return result;
7842 : }
7843 :
7844 :
7845 : /*************************************************************************
7846 : This is debug function intended for testing ALGLIB interface generator.
7847 : Never use it in any real life project.
7848 :
7849 : Replace all values in array by -A[I]
7850 : Array is passed using "shared" convention.
7851 :
7852 : -- ALGLIB --
7853 : Copyright 11.10.2013 by Bochkanov Sergey
7854 : *************************************************************************/
7855 0 : void xdebugi1neg(/* Integer */ ae_vector* a, ae_state *_state)
7856 : {
7857 : ae_int_t i;
7858 :
7859 :
7860 0 : for(i=0; i<=a->cnt-1; i++)
7861 : {
7862 0 : a->ptr.p_int[i] = -a->ptr.p_int[i];
7863 : }
7864 0 : }
7865 :
7866 :
7867 : /*************************************************************************
7868 : This is debug function intended for testing ALGLIB interface generator.
7869 : Never use it in any real life project.
7870 :
7871 : Appends copy of array to itself.
7872 : Array is passed using "var" convention.
7873 :
7874 : -- ALGLIB --
7875 : Copyright 11.10.2013 by Bochkanov Sergey
7876 : *************************************************************************/
7877 0 : void xdebugi1appendcopy(/* Integer */ ae_vector* a, ae_state *_state)
7878 : {
7879 : ae_frame _frame_block;
7880 : ae_int_t i;
7881 : ae_vector b;
7882 :
7883 0 : ae_frame_make(_state, &_frame_block);
7884 0 : memset(&b, 0, sizeof(b));
7885 0 : ae_vector_init(&b, 0, DT_INT, _state, ae_true);
7886 :
7887 0 : ae_vector_set_length(&b, a->cnt, _state);
7888 0 : for(i=0; i<=b.cnt-1; i++)
7889 : {
7890 0 : b.ptr.p_int[i] = a->ptr.p_int[i];
7891 : }
7892 0 : ae_vector_set_length(a, 2*b.cnt, _state);
7893 0 : for(i=0; i<=a->cnt-1; i++)
7894 : {
7895 0 : a->ptr.p_int[i] = b.ptr.p_int[i%b.cnt];
7896 : }
7897 0 : ae_frame_leave(_state);
7898 0 : }
7899 :
7900 :
7901 : /*************************************************************************
7902 : This is debug function intended for testing ALGLIB interface generator.
7903 : Never use it in any real life project.
7904 :
7905 : Generate N-element array with even-numbered A[I] set to I, and odd-numbered
7906 : ones set to 0.
7907 :
7908 : Array is passed using "out" convention.
7909 :
7910 : -- ALGLIB --
7911 : Copyright 11.10.2013 by Bochkanov Sergey
7912 : *************************************************************************/
7913 0 : void xdebugi1outeven(ae_int_t n,
7914 : /* Integer */ ae_vector* a,
7915 : ae_state *_state)
7916 : {
7917 : ae_int_t i;
7918 :
7919 0 : ae_vector_clear(a);
7920 :
7921 0 : ae_vector_set_length(a, n, _state);
7922 0 : for(i=0; i<=a->cnt-1; i++)
7923 : {
7924 0 : if( i%2==0 )
7925 : {
7926 0 : a->ptr.p_int[i] = i;
7927 : }
7928 : else
7929 : {
7930 0 : a->ptr.p_int[i] = 0;
7931 : }
7932 : }
7933 0 : }
7934 :
7935 :
7936 : /*************************************************************************
7937 : This is debug function intended for testing ALGLIB interface generator.
7938 : Never use it in any real life project.
7939 :
7940 : Returns sum of elements in the array.
7941 :
7942 : -- ALGLIB --
7943 : Copyright 11.10.2013 by Bochkanov Sergey
7944 : *************************************************************************/
7945 0 : double xdebugr1sum(/* Real */ ae_vector* a, ae_state *_state)
7946 : {
7947 : ae_int_t i;
7948 : double result;
7949 :
7950 :
7951 0 : result = (double)(0);
7952 0 : for(i=0; i<=a->cnt-1; i++)
7953 : {
7954 0 : result = result+a->ptr.p_double[i];
7955 : }
7956 0 : return result;
7957 : }
7958 :
7959 :
7960 : /*************************************************************************
7961 : This is debug function intended for testing ALGLIB interface generator.
7962 : Never use it in any real life project.
7963 :
7964 : Replace all values in array by -A[I]
7965 : Array is passed using "shared" convention.
7966 :
7967 : -- ALGLIB --
7968 : Copyright 11.10.2013 by Bochkanov Sergey
7969 : *************************************************************************/
7970 0 : void xdebugr1neg(/* Real */ ae_vector* a, ae_state *_state)
7971 : {
7972 : ae_int_t i;
7973 :
7974 :
7975 0 : for(i=0; i<=a->cnt-1; i++)
7976 : {
7977 0 : a->ptr.p_double[i] = -a->ptr.p_double[i];
7978 : }
7979 0 : }
7980 :
7981 :
7982 : /*************************************************************************
7983 : This is debug function intended for testing ALGLIB interface generator.
7984 : Never use it in any real life project.
7985 :
7986 : Appends copy of array to itself.
7987 : Array is passed using "var" convention.
7988 :
7989 : -- ALGLIB --
7990 : Copyright 11.10.2013 by Bochkanov Sergey
7991 : *************************************************************************/
7992 0 : void xdebugr1appendcopy(/* Real */ ae_vector* a, ae_state *_state)
7993 : {
7994 : ae_frame _frame_block;
7995 : ae_int_t i;
7996 : ae_vector b;
7997 :
7998 0 : ae_frame_make(_state, &_frame_block);
7999 0 : memset(&b, 0, sizeof(b));
8000 0 : ae_vector_init(&b, 0, DT_REAL, _state, ae_true);
8001 :
8002 0 : ae_vector_set_length(&b, a->cnt, _state);
8003 0 : for(i=0; i<=b.cnt-1; i++)
8004 : {
8005 0 : b.ptr.p_double[i] = a->ptr.p_double[i];
8006 : }
8007 0 : ae_vector_set_length(a, 2*b.cnt, _state);
8008 0 : for(i=0; i<=a->cnt-1; i++)
8009 : {
8010 0 : a->ptr.p_double[i] = b.ptr.p_double[i%b.cnt];
8011 : }
8012 0 : ae_frame_leave(_state);
8013 0 : }
8014 :
8015 :
8016 : /*************************************************************************
8017 : This is debug function intended for testing ALGLIB interface generator.
8018 : Never use it in any real life project.
8019 :
8020 : Generate N-element array with even-numbered A[I] set to I*0.25,
8021 : and odd-numbered ones are set to 0.
8022 :
8023 : Array is passed using "out" convention.
8024 :
8025 : -- ALGLIB --
8026 : Copyright 11.10.2013 by Bochkanov Sergey
8027 : *************************************************************************/
8028 0 : void xdebugr1outeven(ae_int_t n,
8029 : /* Real */ ae_vector* a,
8030 : ae_state *_state)
8031 : {
8032 : ae_int_t i;
8033 :
8034 0 : ae_vector_clear(a);
8035 :
8036 0 : ae_vector_set_length(a, n, _state);
8037 0 : for(i=0; i<=a->cnt-1; i++)
8038 : {
8039 0 : if( i%2==0 )
8040 : {
8041 0 : a->ptr.p_double[i] = i*0.25;
8042 : }
8043 : else
8044 : {
8045 0 : a->ptr.p_double[i] = (double)(0);
8046 : }
8047 : }
8048 0 : }
8049 :
8050 :
8051 : /*************************************************************************
8052 : This is debug function intended for testing ALGLIB interface generator.
8053 : Never use it in any real life project.
8054 :
8055 : Returns sum of elements in the array.
8056 :
8057 : -- ALGLIB --
8058 : Copyright 11.10.2013 by Bochkanov Sergey
8059 : *************************************************************************/
8060 0 : ae_complex xdebugc1sum(/* Complex */ ae_vector* a, ae_state *_state)
8061 : {
8062 : ae_int_t i;
8063 : ae_complex result;
8064 :
8065 :
8066 0 : result = ae_complex_from_i(0);
8067 0 : for(i=0; i<=a->cnt-1; i++)
8068 : {
8069 0 : result = ae_c_add(result,a->ptr.p_complex[i]);
8070 : }
8071 0 : return result;
8072 : }
8073 :
8074 :
8075 : /*************************************************************************
8076 : This is debug function intended for testing ALGLIB interface generator.
8077 : Never use it in any real life project.
8078 :
8079 : Replace all values in array by -A[I]
8080 : Array is passed using "shared" convention.
8081 :
8082 : -- ALGLIB --
8083 : Copyright 11.10.2013 by Bochkanov Sergey
8084 : *************************************************************************/
8085 0 : void xdebugc1neg(/* Complex */ ae_vector* a, ae_state *_state)
8086 : {
8087 : ae_int_t i;
8088 :
8089 :
8090 0 : for(i=0; i<=a->cnt-1; i++)
8091 : {
8092 0 : a->ptr.p_complex[i] = ae_c_neg(a->ptr.p_complex[i]);
8093 : }
8094 0 : }
8095 :
8096 :
8097 : /*************************************************************************
8098 : This is debug function intended for testing ALGLIB interface generator.
8099 : Never use it in any real life project.
8100 :
8101 : Appends copy of array to itself.
8102 : Array is passed using "var" convention.
8103 :
8104 : -- ALGLIB --
8105 : Copyright 11.10.2013 by Bochkanov Sergey
8106 : *************************************************************************/
8107 0 : void xdebugc1appendcopy(/* Complex */ ae_vector* a, ae_state *_state)
8108 : {
8109 : ae_frame _frame_block;
8110 : ae_int_t i;
8111 : ae_vector b;
8112 :
8113 0 : ae_frame_make(_state, &_frame_block);
8114 0 : memset(&b, 0, sizeof(b));
8115 0 : ae_vector_init(&b, 0, DT_COMPLEX, _state, ae_true);
8116 :
8117 0 : ae_vector_set_length(&b, a->cnt, _state);
8118 0 : for(i=0; i<=b.cnt-1; i++)
8119 : {
8120 0 : b.ptr.p_complex[i] = a->ptr.p_complex[i];
8121 : }
8122 0 : ae_vector_set_length(a, 2*b.cnt, _state);
8123 0 : for(i=0; i<=a->cnt-1; i++)
8124 : {
8125 0 : a->ptr.p_complex[i] = b.ptr.p_complex[i%b.cnt];
8126 : }
8127 0 : ae_frame_leave(_state);
8128 0 : }
8129 :
8130 :
8131 : /*************************************************************************
8132 : This is debug function intended for testing ALGLIB interface generator.
8133 : Never use it in any real life project.
8134 :
8135 : Generate N-element array with even-numbered A[K] set to (x,y) = (K*0.25, K*0.125)
8136 : and odd-numbered ones are set to 0.
8137 :
8138 : Array is passed using "out" convention.
8139 :
8140 : -- ALGLIB --
8141 : Copyright 11.10.2013 by Bochkanov Sergey
8142 : *************************************************************************/
8143 0 : void xdebugc1outeven(ae_int_t n,
8144 : /* Complex */ ae_vector* a,
8145 : ae_state *_state)
8146 : {
8147 : ae_int_t i;
8148 :
8149 0 : ae_vector_clear(a);
8150 :
8151 0 : ae_vector_set_length(a, n, _state);
8152 0 : for(i=0; i<=a->cnt-1; i++)
8153 : {
8154 0 : if( i%2==0 )
8155 : {
8156 0 : a->ptr.p_complex[i].x = i*0.250;
8157 0 : a->ptr.p_complex[i].y = i*0.125;
8158 : }
8159 : else
8160 : {
8161 0 : a->ptr.p_complex[i] = ae_complex_from_i(0);
8162 : }
8163 : }
8164 0 : }
8165 :
8166 :
8167 : /*************************************************************************
8168 : This is debug function intended for testing ALGLIB interface generator.
8169 : Never use it in any real life project.
8170 :
8171 : Counts number of True values in the boolean 2D array.
8172 :
8173 : -- ALGLIB --
8174 : Copyright 11.10.2013 by Bochkanov Sergey
8175 : *************************************************************************/
8176 0 : ae_int_t xdebugb2count(/* Boolean */ ae_matrix* a, ae_state *_state)
8177 : {
8178 : ae_int_t i;
8179 : ae_int_t j;
8180 : ae_int_t result;
8181 :
8182 :
8183 0 : result = 0;
8184 0 : for(i=0; i<=a->rows-1; i++)
8185 : {
8186 0 : for(j=0; j<=a->cols-1; j++)
8187 : {
8188 0 : if( a->ptr.pp_bool[i][j] )
8189 : {
8190 0 : result = result+1;
8191 : }
8192 : }
8193 : }
8194 0 : return result;
8195 : }
8196 :
8197 :
8198 : /*************************************************************************
8199 : This is debug function intended for testing ALGLIB interface generator.
8200 : Never use it in any real life project.
8201 :
8202 : Replace all values in array by NOT(a[i]).
8203 : Array is passed using "shared" convention.
8204 :
8205 : -- ALGLIB --
8206 : Copyright 11.10.2013 by Bochkanov Sergey
8207 : *************************************************************************/
8208 0 : void xdebugb2not(/* Boolean */ ae_matrix* a, ae_state *_state)
8209 : {
8210 : ae_int_t i;
8211 : ae_int_t j;
8212 :
8213 :
8214 0 : for(i=0; i<=a->rows-1; i++)
8215 : {
8216 0 : for(j=0; j<=a->cols-1; j++)
8217 : {
8218 0 : a->ptr.pp_bool[i][j] = !a->ptr.pp_bool[i][j];
8219 : }
8220 : }
8221 0 : }
8222 :
8223 :
8224 : /*************************************************************************
8225 : This is debug function intended for testing ALGLIB interface generator.
8226 : Never use it in any real life project.
8227 :
8228 : Transposes array.
8229 : Array is passed using "var" convention.
8230 :
8231 : -- ALGLIB --
8232 : Copyright 11.10.2013 by Bochkanov Sergey
8233 : *************************************************************************/
8234 0 : void xdebugb2transpose(/* Boolean */ ae_matrix* a, ae_state *_state)
8235 : {
8236 : ae_frame _frame_block;
8237 : ae_int_t i;
8238 : ae_int_t j;
8239 : ae_matrix b;
8240 :
8241 0 : ae_frame_make(_state, &_frame_block);
8242 0 : memset(&b, 0, sizeof(b));
8243 0 : ae_matrix_init(&b, 0, 0, DT_BOOL, _state, ae_true);
8244 :
8245 0 : ae_matrix_set_length(&b, a->rows, a->cols, _state);
8246 0 : for(i=0; i<=b.rows-1; i++)
8247 : {
8248 0 : for(j=0; j<=b.cols-1; j++)
8249 : {
8250 0 : b.ptr.pp_bool[i][j] = a->ptr.pp_bool[i][j];
8251 : }
8252 : }
8253 0 : ae_matrix_set_length(a, b.cols, b.rows, _state);
8254 0 : for(i=0; i<=b.rows-1; i++)
8255 : {
8256 0 : for(j=0; j<=b.cols-1; j++)
8257 : {
8258 0 : a->ptr.pp_bool[j][i] = b.ptr.pp_bool[i][j];
8259 : }
8260 : }
8261 0 : ae_frame_leave(_state);
8262 0 : }
8263 :
8264 :
8265 : /*************************************************************************
8266 : This is debug function intended for testing ALGLIB interface generator.
8267 : Never use it in any real life project.
8268 :
8269 : Generate MxN matrix with elements set to "Sin(3*I+5*J)>0"
8270 : Array is passed using "out" convention.
8271 :
8272 : -- ALGLIB --
8273 : Copyright 11.10.2013 by Bochkanov Sergey
8274 : *************************************************************************/
8275 0 : void xdebugb2outsin(ae_int_t m,
8276 : ae_int_t n,
8277 : /* Boolean */ ae_matrix* a,
8278 : ae_state *_state)
8279 : {
8280 : ae_int_t i;
8281 : ae_int_t j;
8282 :
8283 0 : ae_matrix_clear(a);
8284 :
8285 0 : ae_matrix_set_length(a, m, n, _state);
8286 0 : for(i=0; i<=a->rows-1; i++)
8287 : {
8288 0 : for(j=0; j<=a->cols-1; j++)
8289 : {
8290 0 : a->ptr.pp_bool[i][j] = ae_fp_greater(ae_sin((double)(3*i+5*j), _state),(double)(0));
8291 : }
8292 : }
8293 0 : }
8294 :
8295 :
8296 : /*************************************************************************
8297 : This is debug function intended for testing ALGLIB interface generator.
8298 : Never use it in any real life project.
8299 :
8300 : Returns sum of elements in the array.
8301 :
8302 : -- ALGLIB --
8303 : Copyright 11.10.2013 by Bochkanov Sergey
8304 : *************************************************************************/
8305 0 : ae_int_t xdebugi2sum(/* Integer */ ae_matrix* a, ae_state *_state)
8306 : {
8307 : ae_int_t i;
8308 : ae_int_t j;
8309 : ae_int_t result;
8310 :
8311 :
8312 0 : result = 0;
8313 0 : for(i=0; i<=a->rows-1; i++)
8314 : {
8315 0 : for(j=0; j<=a->cols-1; j++)
8316 : {
8317 0 : result = result+a->ptr.pp_int[i][j];
8318 : }
8319 : }
8320 0 : return result;
8321 : }
8322 :
8323 :
8324 : /*************************************************************************
8325 : This is debug function intended for testing ALGLIB interface generator.
8326 : Never use it in any real life project.
8327 :
8328 : Replace all values in array by -a[i,j]
8329 : Array is passed using "shared" convention.
8330 :
8331 : -- ALGLIB --
8332 : Copyright 11.10.2013 by Bochkanov Sergey
8333 : *************************************************************************/
8334 0 : void xdebugi2neg(/* Integer */ ae_matrix* a, ae_state *_state)
8335 : {
8336 : ae_int_t i;
8337 : ae_int_t j;
8338 :
8339 :
8340 0 : for(i=0; i<=a->rows-1; i++)
8341 : {
8342 0 : for(j=0; j<=a->cols-1; j++)
8343 : {
8344 0 : a->ptr.pp_int[i][j] = -a->ptr.pp_int[i][j];
8345 : }
8346 : }
8347 0 : }
8348 :
8349 :
8350 : /*************************************************************************
8351 : This is debug function intended for testing ALGLIB interface generator.
8352 : Never use it in any real life project.
8353 :
8354 : Transposes array.
8355 : Array is passed using "var" convention.
8356 :
8357 : -- ALGLIB --
8358 : Copyright 11.10.2013 by Bochkanov Sergey
8359 : *************************************************************************/
8360 0 : void xdebugi2transpose(/* Integer */ ae_matrix* a, ae_state *_state)
8361 : {
8362 : ae_frame _frame_block;
8363 : ae_int_t i;
8364 : ae_int_t j;
8365 : ae_matrix b;
8366 :
8367 0 : ae_frame_make(_state, &_frame_block);
8368 0 : memset(&b, 0, sizeof(b));
8369 0 : ae_matrix_init(&b, 0, 0, DT_INT, _state, ae_true);
8370 :
8371 0 : ae_matrix_set_length(&b, a->rows, a->cols, _state);
8372 0 : for(i=0; i<=b.rows-1; i++)
8373 : {
8374 0 : for(j=0; j<=b.cols-1; j++)
8375 : {
8376 0 : b.ptr.pp_int[i][j] = a->ptr.pp_int[i][j];
8377 : }
8378 : }
8379 0 : ae_matrix_set_length(a, b.cols, b.rows, _state);
8380 0 : for(i=0; i<=b.rows-1; i++)
8381 : {
8382 0 : for(j=0; j<=b.cols-1; j++)
8383 : {
8384 0 : a->ptr.pp_int[j][i] = b.ptr.pp_int[i][j];
8385 : }
8386 : }
8387 0 : ae_frame_leave(_state);
8388 0 : }
8389 :
8390 :
8391 : /*************************************************************************
8392 : This is debug function intended for testing ALGLIB interface generator.
8393 : Never use it in any real life project.
8394 :
8395 : Generate MxN matrix with elements set to "Sign(Sin(3*I+5*J))"
8396 : Array is passed using "out" convention.
8397 :
8398 : -- ALGLIB --
8399 : Copyright 11.10.2013 by Bochkanov Sergey
8400 : *************************************************************************/
8401 0 : void xdebugi2outsin(ae_int_t m,
8402 : ae_int_t n,
8403 : /* Integer */ ae_matrix* a,
8404 : ae_state *_state)
8405 : {
8406 : ae_int_t i;
8407 : ae_int_t j;
8408 :
8409 0 : ae_matrix_clear(a);
8410 :
8411 0 : ae_matrix_set_length(a, m, n, _state);
8412 0 : for(i=0; i<=a->rows-1; i++)
8413 : {
8414 0 : for(j=0; j<=a->cols-1; j++)
8415 : {
8416 0 : a->ptr.pp_int[i][j] = ae_sign(ae_sin((double)(3*i+5*j), _state), _state);
8417 : }
8418 : }
8419 0 : }
8420 :
8421 :
8422 : /*************************************************************************
8423 : This is debug function intended for testing ALGLIB interface generator.
8424 : Never use it in any real life project.
8425 :
8426 : Returns sum of elements in the array.
8427 :
8428 : -- ALGLIB --
8429 : Copyright 11.10.2013 by Bochkanov Sergey
8430 : *************************************************************************/
8431 0 : double xdebugr2sum(/* Real */ ae_matrix* a, ae_state *_state)
8432 : {
8433 : ae_int_t i;
8434 : ae_int_t j;
8435 : double result;
8436 :
8437 :
8438 0 : result = (double)(0);
8439 0 : for(i=0; i<=a->rows-1; i++)
8440 : {
8441 0 : for(j=0; j<=a->cols-1; j++)
8442 : {
8443 0 : result = result+a->ptr.pp_double[i][j];
8444 : }
8445 : }
8446 0 : return result;
8447 : }
8448 :
8449 :
8450 : /*************************************************************************
8451 : This is debug function intended for testing ALGLIB interface generator.
8452 : Never use it in any real life project.
8453 :
8454 : Replace all values in array by -a[i,j]
8455 : Array is passed using "shared" convention.
8456 :
8457 : -- ALGLIB --
8458 : Copyright 11.10.2013 by Bochkanov Sergey
8459 : *************************************************************************/
8460 0 : void xdebugr2neg(/* Real */ ae_matrix* a, ae_state *_state)
8461 : {
8462 : ae_int_t i;
8463 : ae_int_t j;
8464 :
8465 :
8466 0 : for(i=0; i<=a->rows-1; i++)
8467 : {
8468 0 : for(j=0; j<=a->cols-1; j++)
8469 : {
8470 0 : a->ptr.pp_double[i][j] = -a->ptr.pp_double[i][j];
8471 : }
8472 : }
8473 0 : }
8474 :
8475 :
8476 : /*************************************************************************
8477 : This is debug function intended for testing ALGLIB interface generator.
8478 : Never use it in any real life project.
8479 :
8480 : Transposes array.
8481 : Array is passed using "var" convention.
8482 :
8483 : -- ALGLIB --
8484 : Copyright 11.10.2013 by Bochkanov Sergey
8485 : *************************************************************************/
8486 0 : void xdebugr2transpose(/* Real */ ae_matrix* a, ae_state *_state)
8487 : {
8488 : ae_frame _frame_block;
8489 : ae_int_t i;
8490 : ae_int_t j;
8491 : ae_matrix b;
8492 :
8493 0 : ae_frame_make(_state, &_frame_block);
8494 0 : memset(&b, 0, sizeof(b));
8495 0 : ae_matrix_init(&b, 0, 0, DT_REAL, _state, ae_true);
8496 :
8497 0 : ae_matrix_set_length(&b, a->rows, a->cols, _state);
8498 0 : for(i=0; i<=b.rows-1; i++)
8499 : {
8500 0 : for(j=0; j<=b.cols-1; j++)
8501 : {
8502 0 : b.ptr.pp_double[i][j] = a->ptr.pp_double[i][j];
8503 : }
8504 : }
8505 0 : ae_matrix_set_length(a, b.cols, b.rows, _state);
8506 0 : for(i=0; i<=b.rows-1; i++)
8507 : {
8508 0 : for(j=0; j<=b.cols-1; j++)
8509 : {
8510 0 : a->ptr.pp_double[j][i] = b.ptr.pp_double[i][j];
8511 : }
8512 : }
8513 0 : ae_frame_leave(_state);
8514 0 : }
8515 :
8516 :
8517 : /*************************************************************************
8518 : This is debug function intended for testing ALGLIB interface generator.
8519 : Never use it in any real life project.
8520 :
8521 : Generate MxN matrix with elements set to "Sin(3*I+5*J)"
8522 : Array is passed using "out" convention.
8523 :
8524 : -- ALGLIB --
8525 : Copyright 11.10.2013 by Bochkanov Sergey
8526 : *************************************************************************/
8527 0 : void xdebugr2outsin(ae_int_t m,
8528 : ae_int_t n,
8529 : /* Real */ ae_matrix* a,
8530 : ae_state *_state)
8531 : {
8532 : ae_int_t i;
8533 : ae_int_t j;
8534 :
8535 0 : ae_matrix_clear(a);
8536 :
8537 0 : ae_matrix_set_length(a, m, n, _state);
8538 0 : for(i=0; i<=a->rows-1; i++)
8539 : {
8540 0 : for(j=0; j<=a->cols-1; j++)
8541 : {
8542 0 : a->ptr.pp_double[i][j] = ae_sin((double)(3*i+5*j), _state);
8543 : }
8544 : }
8545 0 : }
8546 :
8547 :
8548 : /*************************************************************************
8549 : This is debug function intended for testing ALGLIB interface generator.
8550 : Never use it in any real life project.
8551 :
8552 : Returns sum of elements in the array.
8553 :
8554 : -- ALGLIB --
8555 : Copyright 11.10.2013 by Bochkanov Sergey
8556 : *************************************************************************/
8557 0 : ae_complex xdebugc2sum(/* Complex */ ae_matrix* a, ae_state *_state)
8558 : {
8559 : ae_int_t i;
8560 : ae_int_t j;
8561 : ae_complex result;
8562 :
8563 :
8564 0 : result = ae_complex_from_i(0);
8565 0 : for(i=0; i<=a->rows-1; i++)
8566 : {
8567 0 : for(j=0; j<=a->cols-1; j++)
8568 : {
8569 0 : result = ae_c_add(result,a->ptr.pp_complex[i][j]);
8570 : }
8571 : }
8572 0 : return result;
8573 : }
8574 :
8575 :
8576 : /*************************************************************************
8577 : This is debug function intended for testing ALGLIB interface generator.
8578 : Never use it in any real life project.
8579 :
8580 : Replace all values in array by -a[i,j]
8581 : Array is passed using "shared" convention.
8582 :
8583 : -- ALGLIB --
8584 : Copyright 11.10.2013 by Bochkanov Sergey
8585 : *************************************************************************/
8586 0 : void xdebugc2neg(/* Complex */ ae_matrix* a, ae_state *_state)
8587 : {
8588 : ae_int_t i;
8589 : ae_int_t j;
8590 :
8591 :
8592 0 : for(i=0; i<=a->rows-1; i++)
8593 : {
8594 0 : for(j=0; j<=a->cols-1; j++)
8595 : {
8596 0 : a->ptr.pp_complex[i][j] = ae_c_neg(a->ptr.pp_complex[i][j]);
8597 : }
8598 : }
8599 0 : }
8600 :
8601 :
8602 : /*************************************************************************
8603 : This is debug function intended for testing ALGLIB interface generator.
8604 : Never use it in any real life project.
8605 :
8606 : Transposes array.
8607 : Array is passed using "var" convention.
8608 :
8609 : -- ALGLIB --
8610 : Copyright 11.10.2013 by Bochkanov Sergey
8611 : *************************************************************************/
8612 0 : void xdebugc2transpose(/* Complex */ ae_matrix* a, ae_state *_state)
8613 : {
8614 : ae_frame _frame_block;
8615 : ae_int_t i;
8616 : ae_int_t j;
8617 : ae_matrix b;
8618 :
8619 0 : ae_frame_make(_state, &_frame_block);
8620 0 : memset(&b, 0, sizeof(b));
8621 0 : ae_matrix_init(&b, 0, 0, DT_COMPLEX, _state, ae_true);
8622 :
8623 0 : ae_matrix_set_length(&b, a->rows, a->cols, _state);
8624 0 : for(i=0; i<=b.rows-1; i++)
8625 : {
8626 0 : for(j=0; j<=b.cols-1; j++)
8627 : {
8628 0 : b.ptr.pp_complex[i][j] = a->ptr.pp_complex[i][j];
8629 : }
8630 : }
8631 0 : ae_matrix_set_length(a, b.cols, b.rows, _state);
8632 0 : for(i=0; i<=b.rows-1; i++)
8633 : {
8634 0 : for(j=0; j<=b.cols-1; j++)
8635 : {
8636 0 : a->ptr.pp_complex[j][i] = b.ptr.pp_complex[i][j];
8637 : }
8638 : }
8639 0 : ae_frame_leave(_state);
8640 0 : }
8641 :
8642 :
8643 : /*************************************************************************
8644 : This is debug function intended for testing ALGLIB interface generator.
8645 : Never use it in any real life project.
8646 :
8647 : Generate MxN matrix with elements set to "Sin(3*I+5*J),Cos(3*I+5*J)"
8648 : Array is passed using "out" convention.
8649 :
8650 : -- ALGLIB --
8651 : Copyright 11.10.2013 by Bochkanov Sergey
8652 : *************************************************************************/
8653 0 : void xdebugc2outsincos(ae_int_t m,
8654 : ae_int_t n,
8655 : /* Complex */ ae_matrix* a,
8656 : ae_state *_state)
8657 : {
8658 : ae_int_t i;
8659 : ae_int_t j;
8660 :
8661 0 : ae_matrix_clear(a);
8662 :
8663 0 : ae_matrix_set_length(a, m, n, _state);
8664 0 : for(i=0; i<=a->rows-1; i++)
8665 : {
8666 0 : for(j=0; j<=a->cols-1; j++)
8667 : {
8668 0 : a->ptr.pp_complex[i][j].x = ae_sin((double)(3*i+5*j), _state);
8669 0 : a->ptr.pp_complex[i][j].y = ae_cos((double)(3*i+5*j), _state);
8670 : }
8671 : }
8672 0 : }
8673 :
8674 :
8675 : /*************************************************************************
8676 : This is debug function intended for testing ALGLIB interface generator.
8677 : Never use it in any real life project.
8678 :
8679 : Returns sum of a[i,j]*(1+b[i,j]) such that c[i,j] is True
8680 :
8681 : -- ALGLIB --
8682 : Copyright 11.10.2013 by Bochkanov Sergey
8683 : *************************************************************************/
8684 0 : double xdebugmaskedbiasedproductsum(ae_int_t m,
8685 : ae_int_t n,
8686 : /* Real */ ae_matrix* a,
8687 : /* Real */ ae_matrix* b,
8688 : /* Boolean */ ae_matrix* c,
8689 : ae_state *_state)
8690 : {
8691 : ae_int_t i;
8692 : ae_int_t j;
8693 : double result;
8694 :
8695 :
8696 0 : ae_assert(m>=a->rows, "Assertion failed", _state);
8697 0 : ae_assert(m>=b->rows, "Assertion failed", _state);
8698 0 : ae_assert(m>=c->rows, "Assertion failed", _state);
8699 0 : ae_assert(n>=a->cols, "Assertion failed", _state);
8700 0 : ae_assert(n>=b->cols, "Assertion failed", _state);
8701 0 : ae_assert(n>=c->cols, "Assertion failed", _state);
8702 0 : result = 0.0;
8703 0 : for(i=0; i<=m-1; i++)
8704 : {
8705 0 : for(j=0; j<=n-1; j++)
8706 : {
8707 0 : if( c->ptr.pp_bool[i][j] )
8708 : {
8709 0 : result = result+a->ptr.pp_double[i][j]*(1+b->ptr.pp_double[i][j]);
8710 : }
8711 : }
8712 : }
8713 0 : return result;
8714 : }
8715 :
8716 :
8717 0 : void _xdebugrecord1_init(void* _p, ae_state *_state, ae_bool make_automatic)
8718 : {
8719 0 : xdebugrecord1 *p = (xdebugrecord1*)_p;
8720 0 : ae_touch_ptr((void*)p);
8721 0 : ae_vector_init(&p->a, 0, DT_REAL, _state, make_automatic);
8722 0 : }
8723 :
8724 :
8725 0 : void _xdebugrecord1_init_copy(void* _dst, void* _src, ae_state *_state, ae_bool make_automatic)
8726 : {
8727 0 : xdebugrecord1 *dst = (xdebugrecord1*)_dst;
8728 0 : xdebugrecord1 *src = (xdebugrecord1*)_src;
8729 0 : dst->i = src->i;
8730 0 : dst->c = src->c;
8731 0 : ae_vector_init_copy(&dst->a, &src->a, _state, make_automatic);
8732 0 : }
8733 :
8734 :
8735 0 : void _xdebugrecord1_clear(void* _p)
8736 : {
8737 0 : xdebugrecord1 *p = (xdebugrecord1*)_p;
8738 0 : ae_touch_ptr((void*)p);
8739 0 : ae_vector_clear(&p->a);
8740 0 : }
8741 :
8742 :
8743 0 : void _xdebugrecord1_destroy(void* _p)
8744 : {
8745 0 : xdebugrecord1 *p = (xdebugrecord1*)_p;
8746 0 : ae_touch_ptr((void*)p);
8747 0 : ae_vector_destroy(&p->a);
8748 0 : }
8749 :
8750 :
8751 : #endif
8752 :
8753 : }
8754 :
|