Class documentation of Concepts

Loading...
Searching...
No Matches
ap.h
1/*************************************************************************
2ALGLIB 3.11.0 (source code generated 2017-05-11)
3Copyright (c) Sergey Bochkanov (ALGLIB project).
4
5>>> SOURCE LICENSE >>>
6This program is free software; you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation (www.fsf.org); either version 2 of the
9License, or (at your option) any later version.
10
11This program is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16A copy of the GNU General Public License is available at
17http://www.fsf.org/licensing/licenses
18>>> END OF LICENSE >>>
19*************************************************************************/
20#ifndef _ap_h
21#define _ap_h
22
23#include <stdio.h>
24#include <stdlib.h>
25#include <stddef.h>
26#include <string>
27#include <cstring>
28#include <iostream>
29#include <math.h>
30
31#if defined(__CODEGEARC__)
32#include <list>
33#include <vector>
34#elif defined(__BORLANDC__)
35#include <list.h>
36#include <vector.h>
37#else
38#include <list>
39#include <vector>
40#endif
41
42#define AE_USE_CPP
43/* Definitions */
44#define AE_UNKNOWN 0
45#define AE_MSVC 1
46#define AE_GNUC 2
47#define AE_SUNC 3
48#define AE_INTEL 1
49#define AE_SPARC 2
50#define AE_WINDOWS 1
51#define AE_POSIX 2
52#define AE_LOCK_ALIGNMENT 16
53
54/* in case no OS is defined, use AE_UNKNOWN */
55#ifndef AE_OS
56#define AE_OS AE_UNKNOWN
57#endif
58
59/* automatically determine compiler */
60#define AE_COMPILER AE_UNKNOWN
61#ifdef __GNUC__
62#undef AE_COMPILER
63#define AE_COMPILER AE_GNUC
64#endif
65#if defined(__SUNPRO_C)||defined(__SUNPRO_CC)
66#undef AE_COMPILER
67#define AE_COMPILER AE_SUNC
68#endif
69#ifdef _MSC_VER
70#undef AE_COMPILER
71#define AE_COMPILER AE_MSVC
72#endif
73
74/* compiler-specific definitions */
75#if AE_COMPILER==AE_MSVC
76#define ALIGNED __declspec(align(8))
77#elif AE_COMPILER==AE_GNUC
78#define ALIGNED __attribute__((aligned(8)))
79#else
80#define ALIGNED
81#endif
82
83/* now we are ready to include headers */
84#include <stdlib.h>
85#include <stdio.h>
86#include <string.h>
87#include <setjmp.h>
88#include <math.h>
89#include <stddef.h>
90
91#if defined(AE_HAVE_STDINT)
92#include <stdint.h>
93#endif
94
95/*
96 * SSE2 intrinsics
97 *
98 * Preprocessor directives below:
99 * - include headers for SSE2 intrinsics
100 * - define AE_HAS_SSE2_INTRINSICS definition
101 *
102 * These actions are performed when we have:
103 * - x86 architecture definition (AE_CPU==AE_INTEL)
104 * - compiler which supports intrinsics
105 *
106 * Presence of AE_HAS_SSE2_INTRINSICS does NOT mean that our CPU
107 * actually supports SSE2 - such things should be determined at runtime
108 * with ae_cpuid() call. It means that we are working under Intel and
109 * out compiler can issue SSE2-capable code.
110 *
111 */
112#if defined(AE_CPU)
113#if AE_CPU==AE_INTEL
114#if AE_COMPILER==AE_MSVC
115#include <emmintrin.h>
116#define AE_HAS_SSE2_INTRINSICS
117#endif
118#if AE_COMPILER==AE_GNUC
119#include <xmmintrin.h>
120#define AE_HAS_SSE2_INTRINSICS
121#endif
122#if AE_COMPILER==AE_SUNC
123#include <xmmintrin.h>
124#include <emmintrin.h>
125#define AE_HAS_SSE2_INTRINSICS
126#endif
127#endif
128#endif
129
130
131
133//
134// THIS SECTION CONTAINS DECLARATIONS FOR BASIC FUNCTIONALITY
135// LIKE MEMORY MANAGEMENT FOR VECTORS/MATRICES WHICH IS SHARED
136// BETWEEN C++ AND PURE C LIBRARIES
137//
139namespace alglib_impl
140{
141
142/* if we work under C++ environment, define several conditions */
143#ifdef AE_USE_CPP
144#define AE_USE_CPP_BOOL
145#define AE_USE_CPP_ERROR_HANDLING
146#define AE_USE_CPP_SERIALIZATION
147#include <iostream>
148#endif
149
150/*
151 * define ae_int32_t, ae_int64_t, ae_int_t, ae_bool, ae_complex, ae_error_type and ae_datatype
152 */
153
154#if defined(AE_INT32_T)
155typedef AE_INT32_T ae_int32_t;
156#endif
157#if defined(AE_HAVE_STDINT) && !defined(AE_INT32_T)
158typedef int32_t ae_int32_t;
159#endif
160#if !defined(AE_HAVE_STDINT) && !defined(AE_INT32_T)
161#if AE_COMPILER==AE_MSVC
162typedef __int32 ae_int32_t;
163#endif
164#if (AE_COMPILER==AE_GNUC) || (AE_COMPILER==AE_SUNC) || (AE_COMPILER==AE_UNKNOWN)
165typedef int ae_int32_t;
166#endif
167#endif
168
169#if defined(AE_INT64_T)
170typedef AE_INT64_T ae_int64_t;
171#endif
172#if defined(AE_HAVE_STDINT) && !defined(AE_INT64_T)
173typedef int64_t ae_int64_t;
174#endif
175#if !defined(AE_HAVE_STDINT) && !defined(AE_INT64_T)
176#if AE_COMPILER==AE_MSVC
177typedef __int64 ae_int64_t;
178#endif
179#if (AE_COMPILER==AE_GNUC) || (AE_COMPILER==AE_SUNC) || (AE_COMPILER==AE_UNKNOWN)
180typedef signed long long ae_int64_t;
181#endif
182#endif
183
184#if !defined(AE_INT_T)
185typedef ptrdiff_t ae_int_t;
186#endif
187
188#if !defined(AE_USE_CPP_BOOL)
189#define ae_bool char
190#define ae_true 1
191#define ae_false 0
192#else
193#define ae_bool bool
194#define ae_true true
195#define ae_false false
196#endif
197
198typedef struct { double x, y; } ae_complex;
199
200typedef enum
201{
202 ERR_OK = 0,
203 ERR_OUT_OF_MEMORY = 1,
204 ERR_XARRAY_TOO_LARGE = 2,
205 ERR_ASSERTION_FAILED = 3
206} ae_error_type;
207
208typedef ae_int_t ae_datatype;
209
210/*
211 * other definitions
212 */
213enum { OWN_CALLER=1, OWN_AE=2 };
214enum { ACT_UNCHANGED=1, ACT_SAME_LOCATION=2, ACT_NEW_LOCATION=3 };
215enum { DT_BOOL=1, DT_INT=2, DT_REAL=3, DT_COMPLEX=4 };
216enum { CPU_SSE2=1 };
217
218/************************************************************************
219x-string (zero-terminated):
220 owner OWN_CALLER or OWN_AE. Determines what to do on realloc().
221 If vector is owned by caller, X-interface will just set
222 ptr to NULL before realloc(). If it is owned by X, it
223 will call ae_free/x_free/aligned_free family functions.
224
225 last_action ACT_UNCHANGED, ACT_SAME_LOCATION, ACT_NEW_LOCATION
226 contents is either: unchanged, stored at the same location,
227 stored at the new location.
228 this field is set on return from X.
229
230 ptr pointer to the actual data
231
232Members of this structure are ae_int64_t to avoid alignment problems.
233************************************************************************/
234typedef struct
235{
236 ALIGNED ae_int64_t owner;
237 ALIGNED ae_int64_t last_action;
238 ALIGNED char *ptr;
239} x_string;
240
241/************************************************************************
242x-vector:
243 cnt number of elements
244
245 datatype one of the DT_XXXX values
246
247 owner OWN_CALLER or OWN_AE. Determines what to do on realloc().
248 If vector is owned by caller, X-interface will just set
249 ptr to NULL before realloc(). If it is owned by X, it
250 will call ae_free/x_free/aligned_free family functions.
251
252 last_action ACT_UNCHANGED, ACT_SAME_LOCATION, ACT_NEW_LOCATION
253 contents is either: unchanged, stored at the same location,
254 stored at the new location.
255 this field is set on return from X interface and may be
256 used by caller as hint when deciding what to do with data
257 (if it was ACT_UNCHANGED or ACT_SAME_LOCATION, no array
258 reallocation or copying is required).
259
260 ptr pointer to the actual data
261
262Members of this structure are ae_int64_t to avoid alignment problems.
263************************************************************************/
264typedef struct
265{
266 ALIGNED ae_int64_t cnt;
267 ALIGNED ae_int64_t datatype;
268 ALIGNED ae_int64_t owner;
269 ALIGNED ae_int64_t last_action;
270 ALIGNED void *ptr;
271} x_vector;
272
273
274/************************************************************************
275x-matrix:
276 rows number of rows. may be zero only when cols is zero too.
277
278 cols number of columns. may be zero only when rows is zero too.
279
280 stride stride, i.e. distance between first elements of rows (in bytes)
281
282 datatype one of the DT_XXXX values
283
284 owner OWN_CALLER or OWN_AE. Determines what to do on realloc().
285 If vector is owned by caller, X-interface will just set
286 ptr to NULL before realloc(). If it is owned by X, it
287 will call ae_free/x_free/aligned_free family functions.
288
289 last_action ACT_UNCHANGED, ACT_SAME_LOCATION, ACT_NEW_LOCATION
290 contents is either: unchanged, stored at the same location,
291 stored at the new location.
292 this field is set on return from X interface and may be
293 used by caller as hint when deciding what to do with data
294 (if it was ACT_UNCHANGED or ACT_SAME_LOCATION, no array
295 reallocation or copying is required).
296
297 ptr pointer to the actual data, stored rowwise
298
299Members of this structure are ae_int64_t to avoid alignment problems.
300************************************************************************/
301typedef struct
302{
303 ALIGNED ae_int64_t rows;
304 ALIGNED ae_int64_t cols;
305 ALIGNED ae_int64_t stride;
306 ALIGNED ae_int64_t datatype;
307 ALIGNED ae_int64_t owner;
308 ALIGNED ae_int64_t last_action;
309 ALIGNED void *ptr;
310} x_matrix;
311
312
313/************************************************************************
314dynamic block which may be automatically deallocated during stack unwinding
315
316p_next next block in the stack unwinding list.
317 NULL means that this block is not in the list
318deallocator deallocator function which should be used to deallocate block.
319 NULL for "special" blocks (frame/stack boundaries)
320ptr pointer which should be passed to the deallocator.
321 may be null (for zero-size block), DYN_BOTTOM or DYN_FRAME
322 for "special" blocks (frame/stack boundaries).
323
324************************************************************************/
325typedef struct ae_dyn_block
326{
327 struct ae_dyn_block * volatile p_next;
328 /* void *deallocator; */
329 void (*deallocator)(void*);
330 void * volatile ptr;
332
333typedef void(*ae_deallocator)(void*);
334
335/************************************************************************
336frame marker
337************************************************************************/
338typedef struct ae_frame
339{
340 ae_dyn_block db_marker;
341} ae_frame;
342
343/************************************************************************
344ALGLIB environment state
345************************************************************************/
346typedef struct ae_state
347{
348 /*
349 * endianness type: AE_LITTLE_ENDIAN or AE_BIG_ENDIAN
350 */
351 ae_int_t endianness;
352
353 /*
354 * double value for NAN
355 */
356 double v_nan;
357
358 /*
359 * double value for +INF
360 */
361 double v_posinf;
362
363 /*
364 * double value for -INF
365 */
366 double v_neginf;
367
368 /*
369 * pointer to the top block in a stack of frames
370 * which hold dynamically allocated objects
371 */
372 ae_dyn_block * volatile p_top_block;
373 ae_dyn_block last_block;
374
375 /*
376 * jmp_buf for cases when C-style exception handling is used
377 */
378#ifndef AE_USE_CPP_ERROR_HANDLING
379 jmp_buf * volatile break_jump;
380#endif
381
382 /*
383 * ae_error_type of the last error (filled when exception is thrown)
384 */
385 ae_error_type volatile last_error;
386
387 /*
388 * human-readable message (filled when exception is thrown)
389 */
390 const char* volatile error_msg;
391
392 /*
393 * threading information:
394 * a) current thread pool
395 * b) current worker thread
396 * c) parent task (one we are solving right now)
397 * d) thread exception handler (function which must be called
398 * by ae_assert before raising exception).
399 *
400 * NOTE: we use void* to store pointers in order to avoid explicit dependency on smp.h
401 */
402 void *worker_thread;
403 void *parent_task;
404 void (*thread_exception_handler)(void*);
405
406} ae_state;
407
408/************************************************************************
409Serializer:
410
411* ae_stream_writer type is a function pointer for stream writer method;
412 this pointer is used by X-core for out-of-core serialization (say, to
413 serialize ALGLIB structure directly to managed C# stream).
414
415 This function accepts two parameters: pointer to ANSI (7-bit) string
416 and pointer-sized integer passed to serializer during initialization.
417 String being passed is a part of the data stream; aux paramerer may be
418 arbitrary value intended to be used by actual implementation of stream
419 writer. String parameter may include spaces and linefeed symbols, it
420 should be written to stream as is.
421
422 Return value must be zero for success or non-zero for failure.
423
424* ae_stream_reader type is a function pointer for stream reader method;
425 this pointer is used by X-core for out-of-core unserialization (say, to
426 unserialize ALGLIB structure directly from managed C# stream).
427
428 This function accepts three parameters: pointer-sized integer passed to
429 serializer during initialization; number of symbols to read from
430 stream; pointer to buffer used to store next token read from stream
431 (ANSI encoding is used, buffer is large enough to store all symbols and
432 trailing zero symbol).
433
434 Number of symbols to read is always positive.
435
436 After being called by X-core, this function must:
437 * skip all space and linefeed characters from the current position at
438 the stream and until first non-space non-linefeed character is found
439 * read exactly cnt symbols from stream to buffer; check that all
440 symbols being read are non-space non-linefeed ones
441 * append trailing zero symbol to buffer
442 * return value must be zero on success, non-zero if even one of the
443 conditions above fails. When reader returns non-zero value, contents
444 of buf is not used.
445************************************************************************/
446typedef char(*ae_stream_writer)(const char *p_string, ae_int_t aux);
447typedef char(*ae_stream_reader)(ae_int_t aux, ae_int_t cnt, char *p_buf);
448
449typedef struct
450{
451 ae_int_t mode;
452 ae_int_t entries_needed;
453 ae_int_t entries_saved;
454 ae_int_t bytes_asked;
455 ae_int_t bytes_written;
456
457#ifdef AE_USE_CPP_SERIALIZATION
458 std::string *out_cppstr;
459#endif
460 char *out_str; /* pointer to the current position at the output buffer; advanced with each write operation */
461 const char *in_str; /* pointer to the current position at the input buffer; advanced with each read operation */
462 ae_int_t stream_aux;
463 ae_stream_writer stream_writer;
464 ae_stream_reader stream_reader;
466
467
468typedef struct ae_vector
469{
470 /*
471 * Number of elements in array, cnt>=0
472 */
473 ae_int_t cnt;
474
475 /*
476 * Either DT_BOOL, DT_INT, DT_REAL or DT_COMPLEX
477 */
478 ae_datatype datatype;
479
480 /*
481 * If ptr points to memory owned and managed by ae_vector itself,
482 * this field is ae_false. If vector was attached to x_vector structure
483 * with ae_vector_attach_to_x(), this field is ae_true.
484 */
485 ae_bool is_attached;
486
487 /*
488 * ae_dyn_block structure which manages data in ptr. This structure
489 * is responsible for automatic deletion of object when its frame
490 * is destroyed.
491 */
492 ae_dyn_block data;
493
494 /*
495 * Pointer to data.
496 * User usually works with this field.
497 */
498 union
499 {
500 void *p_ptr;
501 ae_bool *p_bool;
502 ae_int_t *p_int;
503 double *p_double;
504 ae_complex *p_complex;
505 } ptr;
506} ae_vector;
507
508typedef struct ae_matrix
509{
510 ae_int_t rows;
511 ae_int_t cols;
512 ae_int_t stride;
513 ae_datatype datatype;
514
515 /*
516 * If ptr points to memory owned and managed by ae_vector itself,
517 * this field is ae_false. If vector was attached to x_vector structure
518 * with ae_vector_attach_to_x(), this field is ae_true.
519 */
520 ae_bool is_attached;
521
522 ae_dyn_block data;
523 union
524 {
525 void *p_ptr;
526 void **pp_void;
527 ae_bool **pp_bool;
528 ae_int_t **pp_int;
529 double **pp_double;
530 ae_complex **pp_complex;
531 } ptr;
532} ae_matrix;
533
534typedef struct ae_smart_ptr
535{
536 /* pointer to subscriber; all changes in ptr are translated to subscriber */
537 void **subscriber;
538
539 /* pointer to object */
540 void *ptr;
541
542 /* whether smart pointer owns ptr */
543 ae_bool is_owner;
544
545 /* whether object pointed by ptr is dynamic - clearing such object requires BOTH
546 calling destructor function AND calling ae_free for memory occupied by object. */
547 ae_bool is_dynamic;
548
549 /* destructor function for pointer; clears all dynamically allocated memory */
550 void (*destroy)(void*);
551
552 /* frame entry; used to ensure automatic deallocation of smart pointer in case of exception/exit */
553 ae_dyn_block frame_entry;
555
556
557/*************************************************************************
558Lock.
559
560This structure provides OS-independent non-reentrant lock:
561* under Windows/Posix systems it uses system-provided locks
562* under Boost it uses OS-independent lock provided by Boost package
563* when no OS is defined, it uses "fake lock" (just stub which is not thread-safe):
564 a) "fake lock" can be in locked or free mode
565 b) "fake lock" can be used only from one thread - one which created lock
566 c) when thread acquires free lock, it immediately returns
567 d) when thread acquires busy lock, program is terminated
568 (because lock is already acquired and no one else can free it)
569*************************************************************************/
570typedef struct
571{
572 /*
573 * Pointer to _lock structure. This pointer has type void* in order to
574 * make header file OS-independent (lock declaration depends on OS).
575 */
576 void *ptr;
577} ae_lock;
578
579
580/*************************************************************************
581Shared pool: data structure used to provide thread-safe access to pool of
582temporary variables.
583*************************************************************************/
585{
586 void * volatile obj;
587 void * volatile next_entry;
589
590typedef struct ae_shared_pool
591{
592 /* lock object which protects pool */
593 ae_lock pool_lock;
594
595 /* seed object (used to create new instances of temporaries) */
596 void * volatile seed_object;
597
598 /*
599 * list of recycled OBJECTS:
600 * 1. entries in this list store pointers to recycled objects
601 * 2. every time we retrieve object, we retrieve first entry from this list,
602 * move it to recycled_entries and return its obj field to caller/
603 */
604 ae_shared_pool_entry * volatile recycled_objects;
605
606 /*
607 * list of recycled ENTRIES:
608 * 1. this list holds entries which are not used to store recycled objects;
609 * every time recycled object is retrieved, its entry is moved to this list.
610 * 2. every time object is recycled, we try to fetch entry for him from this list
611 * before allocating it with malloc()
612 */
613 ae_shared_pool_entry * volatile recycled_entries;
614
615 /* enumeration pointer, points to current recycled object*/
616 ae_shared_pool_entry * volatile enumeration_counter;
617
618 /* size of object; this field is used when we call malloc() for new objects */
619 ae_int_t size_of_object;
620
621 /* initializer function; accepts pointer to malloc'ed object, initializes its fields */
622 void (*init)(void* dst, ae_state* state);
623
624 /* copy constructor; accepts pointer to malloc'ed, but not initialized object */
625 void (*init_copy)(void* dst, void* src, ae_state* state);
626
627 /* destructor function; */
628 void (*destroy)(void* ptr);
629
630 /* frame entry; contains pointer to the pool object itself */
631 ae_dyn_block frame_entry;
633
634ae_int_t ae_misalignment(const void *ptr, size_t alignment);
635void* ae_align(void *ptr, size_t alignment);
636void* aligned_malloc(size_t size, size_t alignment);
637void aligned_free(void *block);
638
639void* ae_malloc(size_t size, ae_state *state);
640void ae_free(void *p);
641ae_int_t ae_sizeof(ae_datatype datatype);
642void ae_touch_ptr(void *p);
643
644void ae_state_init(ae_state *state);
645void ae_state_clear(ae_state *state);
646#ifndef AE_USE_CPP_ERROR_HANDLING
647void ae_state_set_break_jump(ae_state *state, jmp_buf *buf);
648#endif
649void ae_break(ae_state *state, ae_error_type error_type, const char *msg);
650
651void ae_frame_make(ae_state *state, ae_frame *tmp);
652void ae_frame_leave(ae_state *state);
653
654void ae_db_attach(ae_dyn_block *block, ae_state *state);
655ae_bool ae_db_malloc(ae_dyn_block *block, ae_int_t size, ae_state *state, ae_bool make_automatic);
656ae_bool ae_db_realloc(ae_dyn_block *block, ae_int_t size, ae_state *state);
657void ae_db_free(ae_dyn_block *block);
658void ae_db_swap(ae_dyn_block *block1, ae_dyn_block *block2);
659
660void ae_vector_init(ae_vector *dst, ae_int_t size, ae_datatype datatype, ae_state *state);
661void ae_vector_init_copy(ae_vector *dst, ae_vector *src, ae_state *state);
662void ae_vector_init_from_x(ae_vector *dst, x_vector *src, ae_state *state);
663void ae_vector_attach_to_x(ae_vector *dst, x_vector *src, ae_state *state);
664ae_bool ae_vector_set_length(ae_vector *dst, ae_int_t newsize, ae_state *state);
665void ae_vector_clear(ae_vector *dst);
666void ae_vector_destroy(ae_vector *dst);
667void ae_swap_vectors(ae_vector *vec1, ae_vector *vec2);
668
669void ae_matrix_init(ae_matrix *dst, ae_int_t rows, ae_int_t cols, ae_datatype datatype, ae_state *state);
670void ae_matrix_init_copy(ae_matrix *dst, ae_matrix *src, ae_state *state);
671void ae_matrix_init_from_x(ae_matrix *dst, x_matrix *src, ae_state *state);
672void ae_matrix_attach_to_x(ae_matrix *dst, x_matrix *src, ae_state *state);
673ae_bool ae_matrix_set_length(ae_matrix *dst, ae_int_t rows, ae_int_t cols, ae_state *state);
674void ae_matrix_clear(ae_matrix *dst);
675void ae_matrix_destroy(ae_matrix *dst);
676void ae_swap_matrices(ae_matrix *mat1, ae_matrix *mat2);
677
678void ae_smart_ptr_init(ae_smart_ptr *dst, void **subscriber, ae_state *state);
679void ae_smart_ptr_clear(void *_dst); /* accepts ae_smart_ptr* */
680void ae_smart_ptr_destroy(void *_dst);
681void ae_smart_ptr_assign(ae_smart_ptr *dst, void *new_ptr, ae_bool is_owner, ae_bool is_dynamic, void (*destroy)(void*));
682void ae_smart_ptr_release(ae_smart_ptr *dst);
683
684void ae_yield();
685void ae_init_lock(ae_lock *lock);
686void ae_acquire_lock(ae_lock *lock);
687void ae_release_lock(ae_lock *lock);
688void ae_free_lock(ae_lock *lock);
689
690void ae_shared_pool_init(void *_dst, ae_state *state);
691void ae_shared_pool_init_copy(void *_dst, void *_src, ae_state *state);
692void ae_shared_pool_clear(void *dst);
693void ae_shared_pool_destroy(void *dst);
694ae_bool ae_shared_pool_is_initialized(void *_dst);
695void ae_shared_pool_set_seed(
696 ae_shared_pool *dst,
697 void *seed_object,
698 ae_int_t size_of_object,
699 void (*init)(void* dst, ae_state* state),
700 void (*init_copy)(void* dst, void* src, ae_state* state),
701 void (*destroy)(void* ptr),
702 ae_state *state);
703void ae_shared_pool_retrieve(
704 ae_shared_pool *pool,
705 ae_smart_ptr *pptr,
706 ae_state *state);
707void ae_shared_pool_recycle(
708 ae_shared_pool *pool,
709 ae_smart_ptr *pptr,
710 ae_state *state);
711void ae_shared_pool_clear_recycled(
712 ae_shared_pool *pool,
713 ae_state *state);
714void ae_shared_pool_first_recycled(
715 ae_shared_pool *pool,
716 ae_smart_ptr *pptr,
717 ae_state *state);
718void ae_shared_pool_next_recycled(
719 ae_shared_pool *pool,
720 ae_smart_ptr *pptr,
721 ae_state *state);
722void ae_shared_pool_reset(
723 ae_shared_pool *pool,
724 ae_state *state);
725
726void ae_x_set_vector(x_vector *dst, ae_vector *src, ae_state *state);
727void ae_x_set_matrix(x_matrix *dst, ae_matrix *src, ae_state *state);
728void ae_x_attach_to_vector(x_vector *dst, ae_vector *src);
729void ae_x_attach_to_matrix(x_matrix *dst, ae_matrix *src);
730
731void x_vector_clear(x_vector *dst);
732
733ae_bool x_is_symmetric(x_matrix *a);
734ae_bool x_is_hermitian(x_matrix *a);
735ae_bool x_force_symmetric(x_matrix *a);
736ae_bool x_force_hermitian(x_matrix *a);
737ae_bool ae_is_symmetric(ae_matrix *a);
738ae_bool ae_is_hermitian(ae_matrix *a);
739ae_bool ae_force_symmetric(ae_matrix *a);
740ae_bool ae_force_hermitian(ae_matrix *a);
741
742void ae_serializer_init(ae_serializer *serializer);
743void ae_serializer_clear(ae_serializer *serializer);
744
745void ae_serializer_alloc_start(ae_serializer *serializer);
746void ae_serializer_alloc_entry(ae_serializer *serializer);
747ae_int_t ae_serializer_get_alloc_size(ae_serializer *serializer);
748
749#ifdef AE_USE_CPP_SERIALIZATION
750void ae_serializer_sstart_str(ae_serializer *serializer, std::string *buf);
751void ae_serializer_ustart_str(ae_serializer *serializer, const std::string *buf);
752void ae_serializer_sstart_stream(ae_serializer *serializer, std::ostream *stream);
753void ae_serializer_ustart_stream(ae_serializer *serializer, const std::istream *stream);
754#endif
755void ae_serializer_sstart_str(ae_serializer *serializer, char *buf);
756void ae_serializer_ustart_str(ae_serializer *serializer, const char *buf);
757void ae_serializer_sstart_stream(ae_serializer *serializer, ae_stream_writer writer, ae_int_t aux);
758void ae_serializer_ustart_stream(ae_serializer *serializer, ae_stream_reader reader, ae_int_t aux);
759
760void ae_serializer_serialize_bool(ae_serializer *serializer, ae_bool v, ae_state *state);
761void ae_serializer_serialize_int(ae_serializer *serializer, ae_int_t v, ae_state *state);
762void ae_serializer_serialize_double(ae_serializer *serializer, double v, ae_state *state);
763void ae_serializer_unserialize_bool(ae_serializer *serializer, ae_bool *v, ae_state *state);
764void ae_serializer_unserialize_int(ae_serializer *serializer, ae_int_t *v, ae_state *state);
765void ae_serializer_unserialize_double(ae_serializer *serializer, double *v, ae_state *state);
766
767void ae_serializer_stop(ae_serializer *serializer, ae_state *state);
768
769/************************************************************************
770Service functions
771************************************************************************/
772void ae_assert(ae_bool cond, const char *msg, ae_state *state);
773ae_int_t ae_cpuid();
774
775/************************************************************************
776Real math functions:
777* IEEE-compliant floating point comparisons
778* standard functions
779************************************************************************/
780ae_bool ae_fp_eq(double v1, double v2);
781ae_bool ae_fp_neq(double v1, double v2);
782ae_bool ae_fp_less(double v1, double v2);
783ae_bool ae_fp_less_eq(double v1, double v2);
784ae_bool ae_fp_greater(double v1, double v2);
785ae_bool ae_fp_greater_eq(double v1, double v2);
786
787ae_bool ae_isfinite_stateless(double x, ae_int_t endianness);
788ae_bool ae_isnan_stateless(double x, ae_int_t endianness);
789ae_bool ae_isinf_stateless(double x, ae_int_t endianness);
790ae_bool ae_isposinf_stateless(double x, ae_int_t endianness);
791ae_bool ae_isneginf_stateless(double x, ae_int_t endianness);
792
793ae_int_t ae_get_endianness();
794
795ae_bool ae_isfinite(double x,ae_state *state);
796ae_bool ae_isnan(double x, ae_state *state);
797ae_bool ae_isinf(double x, ae_state *state);
798ae_bool ae_isposinf(double x,ae_state *state);
799ae_bool ae_isneginf(double x,ae_state *state);
800
801double ae_fabs(double x, ae_state *state);
802ae_int_t ae_iabs(ae_int_t x, ae_state *state);
803double ae_sqr(double x, ae_state *state);
804double ae_sqrt(double x, ae_state *state);
805
806ae_int_t ae_sign(double x, ae_state *state);
807ae_int_t ae_round(double x, ae_state *state);
808ae_int_t ae_trunc(double x, ae_state *state);
809ae_int_t ae_ifloor(double x, ae_state *state);
810ae_int_t ae_iceil(double x, ae_state *state);
811
812ae_int_t ae_maxint(ae_int_t m1, ae_int_t m2, ae_state *state);
813ae_int_t ae_minint(ae_int_t m1, ae_int_t m2, ae_state *state);
814double ae_maxreal(double m1, double m2, ae_state *state);
815double ae_minreal(double m1, double m2, ae_state *state);
816double ae_randomreal(ae_state *state);
817ae_int_t ae_randominteger(ae_int_t maxv, ae_state *state);
818
819double ae_sin(double x, ae_state *state);
820double ae_cos(double x, ae_state *state);
821double ae_tan(double x, ae_state *state);
822double ae_sinh(double x, ae_state *state);
823double ae_cosh(double x, ae_state *state);
824double ae_tanh(double x, ae_state *state);
825double ae_asin(double x, ae_state *state);
826double ae_acos(double x, ae_state *state);
827double ae_atan(double x, ae_state *state);
828double ae_atan2(double y, double x, ae_state *state);
829
830double ae_log(double x, ae_state *state);
831double ae_pow(double x, double y, ae_state *state);
832double ae_exp(double x, ae_state *state);
833
834/************************************************************************
835Complex math functions:
836* basic arithmetic operations
837* standard functions
838************************************************************************/
839ae_complex ae_complex_from_i(ae_int_t v);
840ae_complex ae_complex_from_d(double v);
841
842ae_complex ae_c_neg(ae_complex lhs);
843ae_bool ae_c_eq(ae_complex lhs, ae_complex rhs);
844ae_bool ae_c_neq(ae_complex lhs, ae_complex rhs);
845ae_complex ae_c_add(ae_complex lhs, ae_complex rhs);
846ae_complex ae_c_mul(ae_complex lhs, ae_complex rhs);
847ae_complex ae_c_sub(ae_complex lhs, ae_complex rhs);
848ae_complex ae_c_div(ae_complex lhs, ae_complex rhs);
849ae_bool ae_c_eq_d(ae_complex lhs, double rhs);
850ae_bool ae_c_neq_d(ae_complex lhs, double rhs);
851ae_complex ae_c_add_d(ae_complex lhs, double rhs);
852ae_complex ae_c_mul_d(ae_complex lhs, double rhs);
853ae_complex ae_c_sub_d(ae_complex lhs, double rhs);
854ae_complex ae_c_d_sub(double lhs, ae_complex rhs);
855ae_complex ae_c_div_d(ae_complex lhs, double rhs);
856ae_complex ae_c_d_div(double lhs, ae_complex rhs);
857
858ae_complex ae_c_conj(ae_complex lhs, ae_state *state);
859ae_complex ae_c_sqr(ae_complex lhs, ae_state *state);
860double ae_c_abs(ae_complex z, ae_state *state);
861
862/************************************************************************
863Complex BLAS operations
864************************************************************************/
865ae_complex ae_v_cdotproduct(const ae_complex *v0, ae_int_t stride0, const char *conj0, const ae_complex *v1, ae_int_t stride1, const char *conj1, ae_int_t n);
866void ae_v_cmove(ae_complex *vdst, ae_int_t stride_dst, const ae_complex* vsrc, ae_int_t stride_src, const char *conj_src, ae_int_t n);
867void ae_v_cmoveneg(ae_complex *vdst, ae_int_t stride_dst, const ae_complex* vsrc, ae_int_t stride_src, const char *conj_src, ae_int_t n);
868void ae_v_cmoved(ae_complex *vdst, ae_int_t stride_dst, const ae_complex* vsrc, ae_int_t stride_src, const char *conj_src, ae_int_t n, double alpha);
869void ae_v_cmovec(ae_complex *vdst, ae_int_t stride_dst, const ae_complex* vsrc, ae_int_t stride_src, const char *conj_src, ae_int_t n, ae_complex alpha);
870void ae_v_cadd(ae_complex *vdst, ae_int_t stride_dst, const ae_complex *vsrc, ae_int_t stride_src, const char *conj_src, ae_int_t n);
871void ae_v_caddd(ae_complex *vdst, ae_int_t stride_dst, const ae_complex *vsrc, ae_int_t stride_src, const char *conj_src, ae_int_t n, double alpha);
872void ae_v_caddc(ae_complex *vdst, ae_int_t stride_dst, const ae_complex *vsrc, ae_int_t stride_src, const char *conj_src, ae_int_t n, ae_complex alpha);
873void ae_v_csub(ae_complex *vdst, ae_int_t stride_dst, const ae_complex *vsrc, ae_int_t stride_src, const char *conj_src, ae_int_t n);
874void ae_v_csubd(ae_complex *vdst, ae_int_t stride_dst, const ae_complex *vsrc, ae_int_t stride_src, const char *conj_src, ae_int_t n, double alpha);
875void ae_v_csubc(ae_complex *vdst, ae_int_t stride_dst, const ae_complex *vsrc, ae_int_t stride_src, const char *conj_src, ae_int_t n, ae_complex alpha);
876void ae_v_cmuld(ae_complex *vdst, ae_int_t stride_dst, ae_int_t n, double alpha);
877void ae_v_cmulc(ae_complex *vdst, ae_int_t stride_dst, ae_int_t n, ae_complex alpha);
878
879/************************************************************************
880Real BLAS operations
881************************************************************************/
882double ae_v_dotproduct(const double *v0, ae_int_t stride0, const double *v1, ae_int_t stride1, ae_int_t n);
883void ae_v_move(double *vdst, ae_int_t stride_dst, const double* vsrc, ae_int_t stride_src, ae_int_t n);
884void ae_v_moveneg(double *vdst, ae_int_t stride_dst, const double* vsrc, ae_int_t stride_src, ae_int_t n);
885void ae_v_moved(double *vdst, ae_int_t stride_dst, const double* vsrc, ae_int_t stride_src, ae_int_t n, double alpha);
886void ae_v_add(double *vdst, ae_int_t stride_dst, const double *vsrc, ae_int_t stride_src, ae_int_t n);
887void ae_v_addd(double *vdst, ae_int_t stride_dst, const double *vsrc, ae_int_t stride_src, ae_int_t n, double alpha);
888void ae_v_sub(double *vdst, ae_int_t stride_dst, const double *vsrc, ae_int_t stride_src, ae_int_t n);
889void ae_v_subd(double *vdst, ae_int_t stride_dst, const double *vsrc, ae_int_t stride_src, ae_int_t n, double alpha);
890void ae_v_muld(double *vdst, ae_int_t stride_dst, ae_int_t n, double alpha);
891
892/************************************************************************
893Other functions
894************************************************************************/
895ae_int_t ae_v_len(ae_int_t a, ae_int_t b);
896
897/*
898extern const double ae_machineepsilon;
899extern const double ae_maxrealnumber;
900extern const double ae_minrealnumber;
901extern const double ae_pi;
902*/
903#define ae_machineepsilon 5E-16
904#define ae_maxrealnumber 1E300
905#define ae_minrealnumber 1E-300
906#define ae_pi 3.1415926535897932384626433832795
907
908
909/************************************************************************
910RComm functions
911************************************************************************/
912typedef struct rcommstate
913{
914 int stage;
915 ae_vector ia;
916 ae_vector ba;
917 ae_vector ra;
918 ae_vector ca;
919} rcommstate;
920void _rcommstate_init(rcommstate* p, ae_state *_state);
921void _rcommstate_init_copy(rcommstate* dst, rcommstate* src, ae_state *_state);
922void _rcommstate_clear(rcommstate* p);
923void _rcommstate_destroy(rcommstate* p);
924
925/************************************************************************
926Allocation counter, inactive by default.
927Turned on when needed for debugging purposes.
928************************************************************************/
929extern ae_int64_t _alloc_counter;
930extern ae_bool _use_alloc_counter;
931
932
933/************************************************************************
934debug functions (must be turned on by preprocessor definitions):
935* tickcount(), which is wrapper around GetTickCount()
936* flushconsole(), fluches console
937* ae_debugrng(), returns random number generated with high-quality random numbers generator
938* ae_set_seed(), sets seed of the debug RNG (NON-THREAD-SAFE!!!)
939* ae_get_seed(), returns two seed values of the debug RNG (NON-THREAD-SAFE!!!)
940************************************************************************/
941#ifdef AE_DEBUG4WINDOWS
942#define flushconsole(s) fflush(stdout)
943#define tickcount(s) _tickcount()
944int _tickcount();
945#endif
946#ifdef AE_DEBUG4POSIX
947#define flushconsole(s) fflush(stdout)
948#define tickcount(s) _tickcount()
949int _tickcount();
950#endif
951
952
953}
954
955
957//
958// THIS SECTION CONTAINS DECLARATIONS FOR C++ RELATED FUNCTIONALITY
959//
961
962namespace alglib
963{
964
965typedef alglib_impl::ae_int_t ae_int_t;
966
967/********************************************************************
968Class forwards
969********************************************************************/
970class complex;
971
972ae_int_t vlen(ae_int_t n1, ae_int_t n2);
973
974/********************************************************************
975Exception class.
976********************************************************************/
978{
979public:
980 std::string msg;
981
982 ap_error();
983 ap_error(const char *s);
984 static void make_assertion(bool bClause);
985 static void make_assertion(bool bClause, const char *p_msg);
986private:
987};
988
989/********************************************************************
990Complex number with double precision.
991********************************************************************/
993{
994public:
995 complex();
996 complex(const double &_x);
997 complex(const double &_x, const double &_y);
998 complex(const complex &z);
999
1000 complex& operator= (const double& v);
1001 complex& operator+=(const double& v);
1002 complex& operator-=(const double& v);
1003 complex& operator*=(const double& v);
1004 complex& operator/=(const double& v);
1005
1006 complex& operator= (const complex& z);
1007 complex& operator+=(const complex& z);
1008 complex& operator-=(const complex& z);
1009 complex& operator*=(const complex& z);
1010 complex& operator/=(const complex& z);
1011
1012 alglib_impl::ae_complex* c_ptr();
1013 const alglib_impl::ae_complex* c_ptr() const;
1014
1015 std::string tostring(int dps) const;
1016
1017 double x, y;
1018};
1019
1020const alglib::complex operator/(const alglib::complex& lhs, const alglib::complex& rhs);
1021const bool operator==(const alglib::complex& lhs, const alglib::complex& rhs);
1022const bool operator!=(const alglib::complex& lhs, const alglib::complex& rhs);
1023const alglib::complex operator+(const alglib::complex& lhs);
1024const alglib::complex operator-(const alglib::complex& lhs);
1025const alglib::complex operator+(const alglib::complex& lhs, const alglib::complex& rhs);
1026const alglib::complex operator+(const alglib::complex& lhs, const double& rhs);
1027const alglib::complex operator+(const double& lhs, const alglib::complex& rhs);
1028const alglib::complex operator-(const alglib::complex& lhs, const alglib::complex& rhs);
1029const alglib::complex operator-(const alglib::complex& lhs, const double& rhs);
1030const alglib::complex operator-(const double& lhs, const alglib::complex& rhs);
1031const alglib::complex operator*(const alglib::complex& lhs, const alglib::complex& rhs);
1032const alglib::complex operator*(const alglib::complex& lhs, const double& rhs);
1033const alglib::complex operator*(const double& lhs, const alglib::complex& rhs);
1034const alglib::complex operator/(const alglib::complex& lhs, const alglib::complex& rhs);
1035const alglib::complex operator/(const double& lhs, const alglib::complex& rhs);
1036const alglib::complex operator/(const alglib::complex& lhs, const double& rhs);
1037double abscomplex(const alglib::complex &z);
1038alglib::complex conj(const alglib::complex &z);
1039alglib::complex csqr(const alglib::complex &z);
1040void setnworkers(alglib::ae_int_t nworkers);
1041
1042/********************************************************************
1043Level 1 BLAS functions
1044
1045NOTES:
1046* destination and source should NOT overlap
1047* stride is assumed to be positive, but it is not
1048 assert'ed within function
1049* conj_src parameter specifies whether complex source is conjugated
1050 before processing or not. Pass string which starts with 'N' or 'n'
1051 ("No conj", for example) to use unmodified parameter. All other
1052 values will result in conjugation of input, but it is recommended
1053 to use "Conj" in such cases.
1054********************************************************************/
1055double vdotproduct(const double *v0, ae_int_t stride0, const double *v1, ae_int_t stride1, ae_int_t n);
1056double vdotproduct(const double *v1, const double *v2, ae_int_t N);
1057
1058alglib::complex vdotproduct(const alglib::complex *v0, ae_int_t stride0, const char *conj0, const alglib::complex *v1, ae_int_t stride1, const char *conj1, ae_int_t n);
1059alglib::complex vdotproduct(const alglib::complex *v1, const alglib::complex *v2, ae_int_t N);
1060
1061void vmove(double *vdst, ae_int_t stride_dst, const double* vsrc, ae_int_t stride_src, ae_int_t n);
1062void vmove(double *vdst, const double* vsrc, ae_int_t N);
1063
1064void vmove(alglib::complex *vdst, ae_int_t stride_dst, const alglib::complex* vsrc, ae_int_t stride_src, const char *conj_src, ae_int_t n);
1065void vmove(alglib::complex *vdst, const alglib::complex* vsrc, ae_int_t N);
1066
1067void vmoveneg(double *vdst, ae_int_t stride_dst, const double* vsrc, ae_int_t stride_src, ae_int_t n);
1068void vmoveneg(double *vdst, const double *vsrc, ae_int_t N);
1069
1070void vmoveneg(alglib::complex *vdst, ae_int_t stride_dst, const alglib::complex* vsrc, ae_int_t stride_src, const char *conj_src, ae_int_t n);
1071void vmoveneg(alglib::complex *vdst, const alglib::complex *vsrc, ae_int_t N);
1072
1073void vmove(double *vdst, ae_int_t stride_dst, const double* vsrc, ae_int_t stride_src, ae_int_t n, double alpha);
1074void vmove(double *vdst, const double *vsrc, ae_int_t N, double alpha);
1075
1076void vmove(alglib::complex *vdst, ae_int_t stride_dst, const alglib::complex* vsrc, ae_int_t stride_src, const char *conj_src, ae_int_t n, double alpha);
1077void vmove(alglib::complex *vdst, const alglib::complex *vsrc, ae_int_t N, double alpha);
1078
1079void vmove(alglib::complex *vdst, ae_int_t stride_dst, const alglib::complex* vsrc, ae_int_t stride_src, const char *conj_src, ae_int_t n, alglib::complex alpha);
1080void vmove(alglib::complex *vdst, const alglib::complex *vsrc, ae_int_t N, alglib::complex alpha);
1081
1082void vadd(double *vdst, ae_int_t stride_dst, const double *vsrc, ae_int_t stride_src, ae_int_t n);
1083void vadd(double *vdst, const double *vsrc, ae_int_t N);
1084
1085void vadd(alglib::complex *vdst, ae_int_t stride_dst, const alglib::complex *vsrc, ae_int_t stride_src, const char *conj_src, ae_int_t n);
1086void vadd(alglib::complex *vdst, const alglib::complex *vsrc, ae_int_t N);
1087
1088void vadd(double *vdst, ae_int_t stride_dst, const double *vsrc, ae_int_t stride_src, ae_int_t n, double alpha);
1089void vadd(double *vdst, const double *vsrc, ae_int_t N, double alpha);
1090
1091void vadd(alglib::complex *vdst, ae_int_t stride_dst, const alglib::complex *vsrc, ae_int_t stride_src, const char *conj_src, ae_int_t n, double alpha);
1092void vadd(alglib::complex *vdst, const alglib::complex *vsrc, ae_int_t N, double alpha);
1093
1094void vadd(alglib::complex *vdst, ae_int_t stride_dst, const alglib::complex *vsrc, ae_int_t stride_src, const char *conj_src, ae_int_t n, alglib::complex alpha);
1095void vadd(alglib::complex *vdst, const alglib::complex *vsrc, ae_int_t N, alglib::complex alpha);
1096
1097void vsub(double *vdst, ae_int_t stride_dst, const double *vsrc, ae_int_t stride_src, ae_int_t n);
1098void vsub(double *vdst, const double *vsrc, ae_int_t N);
1099
1100void vsub(alglib::complex *vdst, ae_int_t stride_dst, const alglib::complex *vsrc, ae_int_t stride_src, const char *conj_src, ae_int_t n);
1101void vsub(alglib::complex *vdst, const alglib::complex *vsrc, ae_int_t N);
1102
1103void vsub(double *vdst, ae_int_t stride_dst, const double *vsrc, ae_int_t stride_src, ae_int_t n, double alpha);
1104void vsub(double *vdst, const double *vsrc, ae_int_t N, double alpha);
1105
1106void vsub(alglib::complex *vdst, ae_int_t stride_dst, const alglib::complex *vsrc, ae_int_t stride_src, const char *conj_src, ae_int_t n, double alpha);
1107void vsub(alglib::complex *vdst, const alglib::complex *vsrc, ae_int_t N, double alpha);
1108
1109void vsub(alglib::complex *vdst, ae_int_t stride_dst, const alglib::complex *vsrc, ae_int_t stride_src, const char *conj_src, ae_int_t n, alglib::complex alpha);
1110void vsub(alglib::complex *vdst, const alglib::complex *vsrc, ae_int_t N, alglib::complex alpha);
1111
1112void vmul(double *vdst, ae_int_t stride_dst, ae_int_t n, double alpha);
1113void vmul(double *vdst, ae_int_t N, double alpha);
1114
1115void vmul(alglib::complex *vdst, ae_int_t stride_dst, ae_int_t n, double alpha);
1116void vmul(alglib::complex *vdst, ae_int_t N, double alpha);
1117
1118void vmul(alglib::complex *vdst, ae_int_t stride_dst, ae_int_t n, alglib::complex alpha);
1119void vmul(alglib::complex *vdst, ae_int_t N, alglib::complex alpha);
1120
1121
1122
1123/********************************************************************
1124string conversion functions !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1125********************************************************************/
1126
1127/********************************************************************
11281- and 2-dimensional arrays
1129********************************************************************/
1131{
1132public:
1134 virtual ~ae_vector_wrapper();
1135
1136 void setlength(ae_int_t iLen);
1137 ae_int_t length() const;
1138
1139 void attach_to(alglib_impl::ae_vector *ptr);
1140 void allocate_own(ae_int_t size, alglib_impl::ae_datatype datatype);
1141 const alglib_impl::ae_vector* c_ptr() const;
1142 alglib_impl::ae_vector* c_ptr();
1143private:
1145 const ae_vector_wrapper& operator=(const ae_vector_wrapper &rhs);
1146protected:
1147 //
1148 // Copies source vector RHS into current object.
1149 //
1150 // Current object is considered empty (this function should be
1151 // called from copy constructor).
1152 //
1153 void create(const ae_vector_wrapper &rhs);
1154
1155 //
1156 // Copies array given by string into current object. Additional
1157 // parameter DATATYPE contains information about type of the data
1158 // in S and type of the array to create.
1159 //
1160 // Current object is considered empty (this function should be
1161 // called from copy constructor).
1162 //
1163 void create(const char *s, alglib_impl::ae_datatype datatype);
1164
1165 //
1166 // Assigns RHS to current object.
1167 //
1168 // It has several branches depending on target object status:
1169 // * in case it is proxy object, data are copied into memory pointed by
1170 // proxy. Function checks that source has exactly same size as target
1171 // (exception is thrown on failure).
1172 // * in case it is non-proxy object, data allocated by object are cleared
1173 // and a copy of RHS is created in target.
1174 //
1175 // NOTE: this function correctly handles assignments of the object to itself.
1176 //
1177 void assign(const ae_vector_wrapper &rhs);
1178
1181};
1182
1184{
1185public:
1187 boolean_1d_array(const char *s);
1190 const boolean_1d_array& operator=(const boolean_1d_array &rhs);
1191 virtual ~boolean_1d_array() ;
1192
1193 const ae_bool& operator()(ae_int_t i) const;
1194 ae_bool& operator()(ae_int_t i);
1195
1196 const ae_bool& operator[](ae_int_t i) const;
1197 ae_bool& operator[](ae_int_t i);
1198
1199 void setcontent(ae_int_t iLen, const bool *pContent );
1200 ae_bool* getcontent();
1201 const ae_bool* getcontent() const;
1202
1203 std::string tostring() const;
1204};
1205
1207{
1208public:
1210 integer_1d_array(const char *s);
1213 const integer_1d_array& operator=(const integer_1d_array &rhs);
1214 virtual ~integer_1d_array();
1215
1216 const ae_int_t& operator()(ae_int_t i) const;
1217 ae_int_t& operator()(ae_int_t i);
1218
1219 const ae_int_t& operator[](ae_int_t i) const;
1220 ae_int_t& operator[](ae_int_t i);
1221
1222 void setcontent(ae_int_t iLen, const ae_int_t *pContent );
1223
1224 ae_int_t* getcontent();
1225 const ae_int_t* getcontent() const;
1226
1227 std::string tostring() const;
1228};
1229
1231{
1232public:
1233 real_1d_array();
1234 real_1d_array(const char *s);
1235 real_1d_array(const real_1d_array &rhs);
1237 const real_1d_array& operator=(const real_1d_array &rhs);
1238 virtual ~real_1d_array();
1239
1240 const double& operator()(ae_int_t i) const;
1241 double& operator()(ae_int_t i);
1242
1243 const double& operator[](ae_int_t i) const;
1244 double& operator[](ae_int_t i);
1245
1246 void setcontent(ae_int_t iLen, const double *pContent );
1247 double* getcontent();
1248 const double* getcontent() const;
1249
1250 std::string tostring(int dps) const;
1251};
1252
1254{
1255public:
1257 complex_1d_array(const char *s);
1260 const complex_1d_array& operator=(const complex_1d_array &rhs);
1261 virtual ~complex_1d_array();
1262
1263 const alglib::complex& operator()(ae_int_t i) const;
1264 alglib::complex& operator()(ae_int_t i);
1265
1266 const alglib::complex& operator[](ae_int_t i) const;
1267 alglib::complex& operator[](ae_int_t i);
1268
1269 void setcontent(ae_int_t iLen, const alglib::complex *pContent );
1270 alglib::complex* getcontent();
1271 const alglib::complex* getcontent() const;
1272
1273 std::string tostring(int dps) const;
1274};
1275
1277{
1278public:
1280 virtual ~ae_matrix_wrapper();
1281 const ae_matrix_wrapper& operator=(const ae_matrix_wrapper &rhs);
1282
1283 void setlength(ae_int_t rows, ae_int_t cols);
1284 ae_int_t rows() const;
1285 ae_int_t cols() const;
1286 bool isempty() const;
1287 ae_int_t getstride() const;
1288
1289 void attach_to(alglib_impl::ae_matrix *ptr);
1290 void allocate_own(ae_int_t rows, ae_int_t cols, alglib_impl::ae_datatype datatype);
1291 const alglib_impl::ae_matrix* c_ptr() const;
1292 alglib_impl::ae_matrix* c_ptr();
1293private:
1295protected:
1296 //
1297 // Copies source matrix RHS into current object.
1298 //
1299 // Current object is considered empty (this function should be
1300 // called from copy constructor).
1301 //
1302 void create(const ae_matrix_wrapper &rhs);
1303
1304 //
1305 // Copies array given by string into current object. Additional
1306 // parameter DATATYPE contains information about type of the data
1307 // in S and type of the array to create.
1308 //
1309 // Current object is considered empty (this function should be
1310 // called from copy constructor).
1311 //
1312 void create(const char *s, alglib_impl::ae_datatype datatype);
1313
1314 //
1315 // Assigns RHS to current object.
1316 //
1317 // It has several branches depending on target object status:
1318 // * in case it is proxy object, data are copied into memory pointed by
1319 // proxy. Function checks that source has exactly same size as target
1320 // (exception is thrown on failure).
1321 // * in case it is non-proxy object, data allocated by object are cleared
1322 // and a copy of RHS is created in target.
1323 //
1324 // NOTE: this function correctly handles assignments of the object to itself.
1325 //
1326 void assign(const ae_matrix_wrapper &rhs);
1327
1330};
1331
1333{
1334public:
1338 boolean_2d_array(const char *s);
1339 virtual ~boolean_2d_array();
1340
1341 const ae_bool& operator()(ae_int_t i, ae_int_t j) const;
1342 ae_bool& operator()(ae_int_t i, ae_int_t j);
1343
1344 const ae_bool* operator[](ae_int_t i) const;
1345 ae_bool* operator[](ae_int_t i);
1346
1347 void setcontent(ae_int_t irows, ae_int_t icols, const bool *pContent );
1348
1349 std::string tostring() const ;
1350};
1351
1353{
1354public:
1358 integer_2d_array(const char *s);
1359 virtual ~integer_2d_array();
1360
1361 const ae_int_t& operator()(ae_int_t i, ae_int_t j) const;
1362 ae_int_t& operator()(ae_int_t i, ae_int_t j);
1363
1364 const ae_int_t* operator[](ae_int_t i) const;
1365 ae_int_t* operator[](ae_int_t i);
1366
1367 void setcontent(ae_int_t irows, ae_int_t icols, const ae_int_t *pContent );
1368
1369 std::string tostring() const;
1370};
1371
1373{
1374public:
1375 real_2d_array();
1376 real_2d_array(const real_2d_array &rhs);
1378 real_2d_array(const char *s);
1379 virtual ~real_2d_array();
1380
1381 const double& operator()(ae_int_t i, ae_int_t j) const;
1382 double& operator()(ae_int_t i, ae_int_t j);
1383
1384 const double* operator[](ae_int_t i) const;
1385 double* operator[](ae_int_t i);
1386
1387 void setcontent(ae_int_t irows, ae_int_t icols, const double *pContent );
1388
1389 std::string tostring(int dps) const;
1390};
1391
1393{
1394public:
1398 complex_2d_array(const char *s);
1399 virtual ~complex_2d_array();
1400
1401 const alglib::complex& operator()(ae_int_t i, ae_int_t j) const;
1402 alglib::complex& operator()(ae_int_t i, ae_int_t j);
1403
1404 const alglib::complex* operator[](ae_int_t i) const;
1405 alglib::complex* operator[](ae_int_t i);
1406
1407 void setcontent(ae_int_t irows, ae_int_t icols, const alglib::complex *pContent );
1408
1409 std::string tostring(int dps) const;
1410};
1411
1412/********************************************************************
1413CSV operations: reading CSV file to real matrix.
1414
1415This function reads CSV file and stores its contents to double
1416precision 2D array. Format of the data file must conform to RFC 4180
1417specification, with additional notes:
1418* file size should be less than 2GB
1419* ASCI encoding, UTF-8 without BOM (in header names) are supported
1420* any character (comma/tab/space) may be used as field separator, as
1421 long as it is distinct from one used for decimal point
1422* multiple subsequent field separators (say, two spaces) are treated
1423 as MULTIPLE separators, not one big separator
1424* both comma and full stop may be used as decimal point. Parser will
1425 automatically determine specific character being used. Both fixed
1426 and exponential number formats are allowed. Thousand separators
1427 are NOT allowed.
1428* line may end with \n (Unix style) or \r\n (Windows style), parser
1429 will automatically adapt to chosen convention
1430* escaped fields (ones in double quotes) are not supported
1431
1432INPUT PARAMETERS:
1433 filename relative/absolute path
1434 separator character used to separate fields. May be ' ',
1435 ',', '\t'. Other separators are possible too.
1436 flags several values combined with bitwise OR:
1437 * alglib::CSV_SKIP_HEADERS - if present, first row
1438 contains headers and will be skipped. Its
1439 contents is used to determine fields count, and
1440 that's all.
1441 If no flags are specified, default value 0x0 (or
1442 alglib::CSV_DEFAULT, which is same) should be used.
1443
1444OUTPUT PARAMETERS:
1445 out 2D matrix, CSV file parsed with atof()
1446
1447HANDLING OF SPECIAL CASES:
1448* file does not exist - alglib::ap_error exception is thrown
1449* empty file - empty array is returned (no exception)
1450* skip_first_row=true, only one row in file - empty array is returned
1451* field contents is not recognized by atof() - field value is replaced
1452 by 0.0
1453********************************************************************/
1454void read_csv(const char *filename, char separator, int flags, alglib::real_2d_array &out);
1455
1456
1457/********************************************************************
1458dataset information.
1459
1460can store regression dataset, classification dataset, or non-labeled
1461task:
1462* nout==0 means non-labeled task (clustering, for example)
1463* nout>0 && nclasses==0 means regression task
1464* nout>0 && nclasses>0 means classification task
1465********************************************************************/
1466/*class dataset
1467{
1468public:
1469 dataset():nin(0), nout(0), nclasses(0), trnsize(0), valsize(0), tstsize(0), totalsize(0){};
1470
1471 int nin, nout, nclasses;
1472
1473 int trnsize;
1474 int valsize;
1475 int tstsize;
1476 int totalsize;
1477
1478 alglib::real_2d_array trn;
1479 alglib::real_2d_array val;
1480 alglib::real_2d_array tst;
1481 alglib::real_2d_array all;
1482};
1483
1484bool opendataset(std::string file, dataset *pdataset);
1485
1486//
1487// internal functions
1488//
1489std::string strtolower(const std::string &s);
1490bool readstrings(std::string file, std::list<std::string> *pOutput);
1491bool readstrings(std::string file, std::list<std::string> *pOutput, std::string comment);
1492void explodestring(std::string s, char sep, std::vector<std::string> *pOutput);
1493std::string xtrim(std::string s);*/
1494
1495/********************************************************************
1496Constants and functions introduced for compatibility with AlgoPascal
1497********************************************************************/
1498extern const double machineepsilon;
1499extern const double maxrealnumber;
1500extern const double minrealnumber;
1501extern const double fp_nan;
1502extern const double fp_posinf;
1503extern const double fp_neginf;
1504extern const ae_int_t endianness;
1505static const int CSV_DEFAULT = 0x0;
1506static const int CSV_SKIP_HEADERS = 0x1;
1507
1508int sign(double x);
1509double randomreal();
1510ae_int_t randominteger(ae_int_t maxv);
1511int round(double x);
1512int trunc(double x);
1513int ifloor(double x);
1514int iceil(double x);
1515double pi();
1516double sqr(double x);
1517int maxint(int m1, int m2);
1518int minint(int m1, int m2);
1519double maxreal(double m1, double m2);
1520double minreal(double m1, double m2);
1521
1522bool fp_eq(double v1, double v2);
1523bool fp_neq(double v1, double v2);
1524bool fp_less(double v1, double v2);
1525bool fp_less_eq(double v1, double v2);
1526bool fp_greater(double v1, double v2);
1527bool fp_greater_eq(double v1, double v2);
1528
1529bool fp_isnan(double x);
1530bool fp_isposinf(double x);
1531bool fp_isneginf(double x);
1532bool fp_isinf(double x);
1533bool fp_isfinite(double x);
1534
1535
1536}//namespace alglib
1537
1538
1540//
1541// THIS SECTIONS CONTAINS DECLARATIONS FOR OPTIMIZED LINEAR ALGEBRA CODES
1542// IT IS SHARED BETWEEN C++ AND PURE C LIBRARIES
1543//
1545
1546namespace alglib_impl
1547{
1548#define ALGLIB_INTERCEPTS_ABLAS
1549void _ialglib_vzero(ae_int_t n, double *p, ae_int_t stride);
1550void _ialglib_vzero_complex(ae_int_t n, ae_complex *p, ae_int_t stride);
1551void _ialglib_vcopy(ae_int_t n, const double *a, ae_int_t stridea, double *b, ae_int_t strideb);
1552void _ialglib_vcopy_complex(ae_int_t n, const ae_complex *a, ae_int_t stridea, double *b, ae_int_t strideb, const char *conj);
1553void _ialglib_vcopy_dcomplex(ae_int_t n, const double *a, ae_int_t stridea, double *b, ae_int_t strideb, const char *conj);
1554void _ialglib_mcopyblock(ae_int_t m, ae_int_t n, const double *a, ae_int_t op, ae_int_t stride, double *b);
1555void _ialglib_mcopyunblock(ae_int_t m, ae_int_t n, const double *a, ae_int_t op, double *b, ae_int_t stride);
1556void _ialglib_mcopyblock_complex(ae_int_t m, ae_int_t n, const ae_complex *a, ae_int_t op, ae_int_t stride, double *b);
1557void _ialglib_mcopyunblock_complex(ae_int_t m, ae_int_t n, const double *a, ae_int_t op, ae_complex* b, ae_int_t stride);
1558
1559ae_bool _ialglib_i_rmatrixgemmf(ae_int_t m,
1560 ae_int_t n,
1561 ae_int_t k,
1562 double alpha,
1563 ae_matrix *a,
1564 ae_int_t ia,
1565 ae_int_t ja,
1566 ae_int_t optypea,
1567 ae_matrix *b,
1568 ae_int_t ib,
1569 ae_int_t jb,
1570 ae_int_t optypeb,
1571 double beta,
1572 ae_matrix *c,
1573 ae_int_t ic,
1574 ae_int_t jc);
1575ae_bool _ialglib_i_cmatrixgemmf(ae_int_t m,
1576 ae_int_t n,
1577 ae_int_t k,
1578 ae_complex alpha,
1579 ae_matrix *a,
1580 ae_int_t ia,
1581 ae_int_t ja,
1582 ae_int_t optypea,
1583 ae_matrix *b,
1584 ae_int_t ib,
1585 ae_int_t jb,
1586 ae_int_t optypeb,
1587 ae_complex beta,
1588 ae_matrix *c,
1589 ae_int_t ic,
1590 ae_int_t jc);
1591ae_bool _ialglib_i_cmatrixrighttrsmf(ae_int_t m,
1592 ae_int_t n,
1593 ae_matrix *a,
1594 ae_int_t i1,
1595 ae_int_t j1,
1596 ae_bool isupper,
1597 ae_bool isunit,
1598 ae_int_t optype,
1599 ae_matrix *x,
1600 ae_int_t i2,
1601 ae_int_t j2);
1602ae_bool _ialglib_i_rmatrixrighttrsmf(ae_int_t m,
1603 ae_int_t n,
1604 ae_matrix *a,
1605 ae_int_t i1,
1606 ae_int_t j1,
1607 ae_bool isupper,
1608 ae_bool isunit,
1609 ae_int_t optype,
1610 ae_matrix *x,
1611 ae_int_t i2,
1612 ae_int_t j2);
1613ae_bool _ialglib_i_cmatrixlefttrsmf(ae_int_t m,
1614 ae_int_t n,
1615 ae_matrix *a,
1616 ae_int_t i1,
1617 ae_int_t j1,
1618 ae_bool isupper,
1619 ae_bool isunit,
1620 ae_int_t optype,
1621 ae_matrix *x,
1622 ae_int_t i2,
1623 ae_int_t j2);
1624ae_bool _ialglib_i_rmatrixlefttrsmf(ae_int_t m,
1625 ae_int_t n,
1626 ae_matrix *a,
1627 ae_int_t i1,
1628 ae_int_t j1,
1629 ae_bool isupper,
1630 ae_bool isunit,
1631 ae_int_t optype,
1632 ae_matrix *x,
1633 ae_int_t i2,
1634 ae_int_t j2);
1635ae_bool _ialglib_i_cmatrixherkf(ae_int_t n,
1636 ae_int_t k,
1637 double alpha,
1638 ae_matrix *a,
1639 ae_int_t ia,
1640 ae_int_t ja,
1641 ae_int_t optypea,
1642 double beta,
1643 ae_matrix *c,
1644 ae_int_t ic,
1645 ae_int_t jc,
1646 ae_bool isupper);
1647ae_bool _ialglib_i_rmatrixsyrkf(ae_int_t n,
1648 ae_int_t k,
1649 double alpha,
1650 ae_matrix *a,
1651 ae_int_t ia,
1652 ae_int_t ja,
1653 ae_int_t optypea,
1654 double beta,
1655 ae_matrix *c,
1656 ae_int_t ic,
1657 ae_int_t jc,
1658 ae_bool isupper);
1659ae_bool _ialglib_i_cmatrixrank1f(ae_int_t m,
1660 ae_int_t n,
1661 ae_matrix *a,
1662 ae_int_t ia,
1663 ae_int_t ja,
1664 ae_vector *u,
1665 ae_int_t uoffs,
1666 ae_vector *v,
1667 ae_int_t voffs);
1668ae_bool _ialglib_i_rmatrixrank1f(ae_int_t m,
1669 ae_int_t n,
1670 ae_matrix *a,
1671 ae_int_t ia,
1672 ae_int_t ja,
1673 ae_vector *u,
1674 ae_int_t uoffs,
1675 ae_vector *v,
1676 ae_int_t voffs);
1677
1678
1679
1680}
1681
1682
1684//
1685// THIS SECTION CONTAINS PARALLEL SUBROUTINES
1686//
1688
1689namespace alglib_impl
1690{
1691
1692}
1693
1694
1695#endif
1696
Definition ap.h:585