ap.h   ap.h 
/************************************************************************* /*************************************************************************
AP library 1.3 Copyright (c) Sergey Bochkanov (ALGLIB project).
Copyright (c) 2003-2009 Sergey Bochkanov (ALGLIB project).
>>> LICENSE >>> >>> SOURCE LICENSE >>>
This program is free software; you can redistribute it and/or modify This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
the Free Software Foundation (www.fsf.org); either version 2 of the the Free Software Foundation (www.fsf.org); either version 2 of the
License, or (at your option) any later version. License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. GNU General Public License for more details.
A copy of the GNU General Public License is available at A copy of the GNU General Public License is available at
http://www.fsf.org/licensing/licenses http://www.fsf.org/licensing/licenses
>>> END OF LICENSE >>> >>> END OF LICENSE >>>
*************************************************************************/ *************************************************************************/
#ifndef _ap_h
#ifndef AP_H #define _ap_h
#define AP_H
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <setjmp.h>
#include <string> #include <string>
#include <cstring>
#include <math.h> #include <math.h>
#ifdef __BORLANDC__ #ifdef __BORLANDC__
#include <list.h> #include <list.h>
#include <vector.h> #include <vector.h>
#else #else
#include <list> #include <list>
#include <vector> #include <vector>
#endif #endif
/******************************************************************** #define AE_USE_CPP
Array bounds check
********************************************************************/ /////////////////////////////////////////////////////////////////////////
#define NO_AP_ASSERT //
// THIS SECTION CONTAINS DECLARATIONS FOR BASIC FUNCTIONALITY
// LIKE MEMORY MANAGEMENT FOR VECTORS/MATRICES WHICH IS SHARED
// BETWEEN C++ AND PURE C LIBRARIES
//
/////////////////////////////////////////////////////////////////////////
namespace alglib_impl
{
/*
* automatically determine compiler
*/
#define AE_UNKNOWN 0
#define AE_MSVC 1
#define AE_GNUC 2
#define AE_SUNC 3
#define AE_COMPILER AE_UNKNOWN
#ifdef __GNUC__
#undef AE_COMPILER
#define AE_COMPILER AE_GNUC
#endif
#ifdef __SUNPRO_C
#undef AE_COMPILER
#define AE_COMPILER AE_SUNC
#endif
#ifdef _MSC_VER
#undef AE_COMPILER
#define AE_COMPILER AE_MSVC
#endif
#ifndef AP_ASSERT // /*
#define NO_AP_ASSERT // This code avoids definition of the * if we work under C++ environment, define several conditions
#endif // both AP_ASSERT and NO_AP_ASSERT symbols */
#ifdef NO_AP_ASSERT // #ifdef AE_USE_CPP
#ifdef AP_ASSERT // #define AE_USE_CPP_BOOL
#undef NO_AP_ASSERT // #define AE_USE_CPP_ERROR_HANDLING
#endif // #endif
#endif //
/******************************************************************** /*
Current environment. * define ae_int32_t, ae_int64_t, ae_int_t, ae_bool, ae_complex, ae_error_t
********************************************************************/ ype and ae_datatype
#ifndef AP_WIN32 */
#ifndef AP_UNKNOWN #if defined(AE_HAVE_STDINT)
#define AP_UNKNOWN #include <stdint.h>
#endif
#if defined(AE_INT32_T)
typedef AE_INT32_T ae_int32_t;
#endif
#if defined(AE_HAVE_STDINT) && !defined(AE_INT32_T)
typedef int32_t ae_int32_t;
#endif #endif
#if !defined(AE_HAVE_STDINT) && !defined(AE_INT32_T)
#if AE_COMPILER==AE_MSVC
typedef _int32 ae_int32_t;
#endif #endif
#ifdef AP_WIN32 #if (AE_COMPILER==AE_GNUC) || (AE_COMPILER==AE_SUNC) || (AE_COMPILER==AE_UN
#ifdef AP_UNKNOWN KNOWN)
#error Multiple environments are declared! typedef int ae_int32_t;
#endif #endif
#endif #endif
/******************************************************************** #if defined(AE_INT64_T)
This symbol is used for debugging. Do not define it and do not remove typedef AE_INT64_T ae_int64_t;
comments. #endif
********************************************************************/ #if defined(AE_HAVE_STDINT) && !defined(AE_INT64_T)
//#define UNSAFE_MEM_COPY typedef int64_t ae_int64_t;
#endif
#if !defined(AE_HAVE_STDINT) && !defined(AE_INT64_T)
#if AE_COMPILER==AE_MSVC
typedef _int64 ae_int64_t;
#endif
#if (AE_COMPILER==AE_GNUC) || (AE_COMPILER==AE_SUNC) || (AE_COMPILER==AE_UN
KNOWN)
typedef signed long long ae_int64_t;
#endif
#endif
/******************************************************************** #if !defined(AE_INT_T)
Namespace of a standard library AlgoPascal. #include <stddef.h>
********************************************************************/ typedef ptrdiff_t ae_int_t;
namespace ap #endif
#if !defined(AE_USE_CPP_BOOL)
#define ae_bool char
#define ae_true 1
#define ae_false 0
#else
#define ae_bool bool
#define ae_true true
#define ae_false false
#endif
typedef struct { double x, y; } ae_complex;
typedef enum
{
ERR_OK = 0,
ERR_OUT_OF_MEMORY = 1,
ERR_XARRAY_TOO_LARGE = 2,
ERR_ASSERTION_FAILED = 3
} ae_error_type;
typedef ae_int_t ae_datatype;
/*
* other definitions
*/
enum { OWN_CALLER=1, OWN_AE=2 };
enum { ACT_UNCHANGED=1, ACT_SAME_LOCATION=2, ACT_NEW_LOCATION=3 };
enum { DT_BOOL=1, DT_INT=2, DT_REAL=3, DT_COMPLEX=4 };
/************************************************************************
x-string (zero-terminated):
owner OWN_CALLER or OWN_AE. Determines what to do on realloc().
If vector is owned by caller, X-interface will just set
ptr to NULL before realloc(). If it is owned by X, it
will call ae_free/x_free/aligned_free family functions.
last_action ACT_UNCHANGED, ACT_SAME_LOCATION, ACT_NEW_LOCATION
contents is either: unchanged, stored at the same location,
stored at the new location.
this field is set on return from X.
ptr pointer to the actual data
Members of this structure are ae_int64_t to avoid alignment problems.
************************************************************************/
typedef struct
{
ae_int64_t owner;
ae_int64_t last_action;
char *ptr;
} x_string;
/************************************************************************
x-vector:
cnt number of elements
datatype one of the DT_XXXX values
owner OWN_CALLER or OWN_AE. Determines what to do on realloc().
If vector is owned by caller, X-interface will just set
ptr to NULL before realloc(). If it is owned by X, it
will call ae_free/x_free/aligned_free family functions.
last_action ACT_UNCHANGED, ACT_SAME_LOCATION, ACT_NEW_LOCATION
contents is either: unchanged, stored at the same location,
stored at the new location.
this field is set on return from X interface and may be
used by caller as hint when deciding what to do with data
(if it was ACT_UNCHANGED or ACT_SAME_LOCATION, no array
reallocation or copying is required).
ptr pointer to the actual data
Members of this structure are ae_int64_t to avoid alignment problems.
************************************************************************/
typedef struct
{
ae_int64_t cnt;
ae_int64_t datatype;
ae_int64_t owner;
ae_int64_t last_action;
void *ptr;
} x_vector;
/************************************************************************
x-matrix:
rows number of rows. may be zero only when cols is zero too.
cols number of columns. may be zero only when rows is zero too.
stride stride, i.e. distance between first elements of rows (in by
tes)
datatype one of the DT_XXXX values
owner OWN_CALLER or OWN_AE. Determines what to do on realloc().
If vector is owned by caller, X-interface will just set
ptr to NULL before realloc(). If it is owned by X, it
will call ae_free/x_free/aligned_free family functions.
last_action ACT_UNCHANGED, ACT_SAME_LOCATION, ACT_NEW_LOCATION
contents is either: unchanged, stored at the same location,
stored at the new location.
this field is set on return from X interface and may be
used by caller as hint when deciding what to do with data
(if it was ACT_UNCHANGED or ACT_SAME_LOCATION, no array
reallocation or copying is required).
ptr pointer to the actual data, stored rowwise
Members of this structure are ae_int64_t to avoid alignment problems.
************************************************************************/
typedef struct
{
ae_int64_t rows;
ae_int64_t cols;
ae_int64_t stride;
ae_int64_t datatype;
ae_int64_t owner;
ae_int64_t last_action;
void *ptr;
} x_matrix;
/************************************************************************
dynamic block which may be automatically deallocated during stack unwinding
p_next next block in the stack unwinding list.
NULL means that this block is not in the list
deallocator deallocator function which should be used to deallocate blo
ck.
NULL for "special" blocks (frame/stack boundaries)
ptr pointer which should be passed to the deallocator.
may be null (for zero-size block), DYN_BOTTOM or DYN_FRAME
for "special" blocks (frame/stack boundaries).
************************************************************************/
typedef struct ae_dyn_block
{
struct ae_dyn_block * volatile p_next;
/* void *deallocator; */
void (*deallocator)(void*);
void * volatile ptr;
} ae_dyn_block;
/************************************************************************
frame marker
************************************************************************/
typedef struct ae_frame
{
ae_dyn_block db_marker;
} ae_frame;
typedef struct
{
ae_int_t endianness;
double v_nan;
double v_posinf;
double v_neginf;
ae_dyn_block * volatile p_top_block;
ae_dyn_block last_block;
jmp_buf * volatile break_jump;
ae_error_type volatile last_error;
const char* volatile error_msg;
} ae_state;
typedef void(*ae_deallocator)(void*);
typedef struct ae_vector
{
ae_int_t cnt;
ae_datatype datatype;
ae_dyn_block data;
union
{
void *p_ptr;
ae_bool *p_bool;
ae_int_t *p_int;
double *p_double;
ae_complex *p_complex;
} ptr;
} ae_vector;
typedef struct ae_matrix
{
ae_int_t rows;
ae_int_t cols;
ae_int_t stride;
ae_datatype datatype;
ae_dyn_block data;
union
{
void *p_ptr;
void **pp_void;
ae_bool **pp_bool;
ae_int_t **pp_int;
double **pp_double;
ae_complex **pp_complex;
} ptr;
} ae_matrix;
void* ae_align(void *ptr, size_t alignment);
void* aligned_malloc(size_t size, size_t alignment);
void aligned_free(void *block);
void* ae_malloc(size_t size, ae_state *state);
void ae_free(void *p);
ae_int_t ae_sizeof(ae_datatype datatype);
void ae_state_init(ae_state *state);
void ae_state_clear(ae_state *state);
void ae_state_set_break_jump(ae_state *state, jmp_buf *buf);
void ae_break(ae_state *state, ae_error_type error_type, const char *msg);
void ae_frame_make(ae_state *state, ae_frame *tmp);
void ae_frame_leave(ae_state *state);
void ae_db_attach(ae_dyn_block *block, ae_state *state);
ae_bool ae_db_malloc(ae_dyn_block *block, ae_int_t size, ae_state *state, a
e_bool make_automatic);
ae_bool ae_db_realloc(ae_dyn_block *block, ae_int_t size, ae_state *state);
void ae_db_free(ae_dyn_block *block);
ae_bool ae_vector_init(ae_vector *dst, ae_int_t size, ae_datatype datatype,
ae_state *state, ae_bool make_automatic);
ae_bool ae_vector_init_copy(ae_vector *dst, ae_vector *src, ae_state *state
, ae_bool make_automatic);
void ae_vector_init_from_x(ae_vector *dst, x_vector *src, ae_state *state,
ae_bool make_automatic);
ae_bool ae_vector_set_length(ae_vector *dst, ae_int_t newsize, ae_state *st
ate);
void ae_vector_clear(ae_vector *dst);
ae_bool ae_matrix_init(ae_matrix *dst, ae_int_t rows, ae_int_t cols, ae_dat
atype datatype, ae_state *state, ae_bool make_automatic);
ae_bool ae_matrix_init_copy(ae_matrix *dst, ae_matrix *src, ae_state *state
, ae_bool make_automatic);
void ae_matrix_init_from_x(ae_matrix *dst, x_matrix *src, ae_state *state,
ae_bool make_automatic);
ae_bool ae_matrix_set_length(ae_matrix *dst, ae_int_t rows, ae_int_t cols,
ae_state *state);
void ae_matrix_clear(ae_matrix *dst);
void ae_x_set_vector(x_vector *dst, ae_vector *src, ae_state *state);
void ae_x_set_matrix(x_matrix *dst, ae_matrix *src, ae_state *state);
void ae_x_attach_to_vector(x_vector *dst, ae_vector *src);
void ae_x_attach_to_matrix(x_matrix *dst, ae_matrix *src);
void x_vector_clear(x_vector *dst);
ae_bool x_is_symmetric(x_matrix *a);
ae_bool x_is_hermitian(x_matrix *a);
ae_bool x_force_symmetric(x_matrix *a);
ae_bool x_force_hermitian(x_matrix *a);
ae_bool ae_is_symmetric(ae_matrix *a);
ae_bool ae_is_hermitian(ae_matrix *a);
ae_bool ae_force_symmetric(ae_matrix *a);
ae_bool ae_force_hermitian(ae_matrix *a);
/************************************************************************
Service functions
************************************************************************/
void ae_assert(ae_bool cond, const char *msg, ae_state *state);
/************************************************************************
Real math functions:
* IEEE-compliant floating point comparisons
* standard functions
************************************************************************/
ae_bool ae_fp_eq(double v1, double v2);
ae_bool ae_fp_neq(double v1, double v2);
ae_bool ae_fp_less(double v1, double v2);
ae_bool ae_fp_less_eq(double v1, double v2);
ae_bool ae_fp_greater(double v1, double v2);
ae_bool ae_fp_greater_eq(double v1, double v2);
ae_bool ae_isfinite(double x,ae_state *state);
ae_bool ae_isnan(double x, ae_state *state);
ae_bool ae_isinf(double x, ae_state *state);
ae_bool ae_isposinf(double x,ae_state *state);
ae_bool ae_isneginf(double x,ae_state *state);
double ae_fabs(double x, ae_state *state);
ae_int_t ae_iabs(ae_int_t x, ae_state *state);
double ae_sqr(double x, ae_state *state);
double ae_sqrt(double x, ae_state *state);
ae_int_t ae_sign(double x, ae_state *state);
ae_int_t ae_round(double x, ae_state *state);
ae_int_t ae_trunc(double x, ae_state *state);
ae_int_t ae_ifloor(double x, ae_state *state);
ae_int_t ae_iceil(double x, ae_state *state);
ae_int_t ae_maxint(ae_int_t m1, ae_int_t m2, ae_state *state);
ae_int_t ae_minint(ae_int_t m1, ae_int_t m2, ae_state *state);
double ae_maxreal(double m1, double m2, ae_state *state);
double ae_minreal(double m1, double m2, ae_state *state);
double ae_randomreal(ae_state *state);
ae_int_t ae_randominteger(ae_int_t maxv, ae_state *state);
double ae_sin(double x, ae_state *state);
double ae_cos(double x, ae_state *state);
double ae_tan(double x, ae_state *state);
double ae_sinh(double x, ae_state *state);
double ae_cosh(double x, ae_state *state);
double ae_tanh(double x, ae_state *state);
double ae_asin(double x, ae_state *state);
double ae_acos(double x, ae_state *state);
double ae_atan(double x, ae_state *state);
double ae_atan2(double x, double y, ae_state *state);
double ae_log(double x, ae_state *state);
double ae_pow(double x, double y, ae_state *state);
double ae_exp(double x, ae_state *state);
/************************************************************************
Complex math functions:
* basic arithmetic operations
* standard functions
************************************************************************/
ae_complex ae_complex_from_d(double v);
ae_complex ae_c_neg(ae_complex lhs);
ae_bool ae_c_eq(ae_complex lhs, ae_complex rhs);
ae_bool ae_c_neq(ae_complex lhs, ae_complex rhs);
ae_complex ae_c_add(ae_complex lhs, ae_complex rhs);
ae_complex ae_c_mul(ae_complex lhs, ae_complex rhs);
ae_complex ae_c_sub(ae_complex lhs, ae_complex rhs);
ae_complex ae_c_div(ae_complex lhs, ae_complex rhs);
ae_bool ae_c_eq_d(ae_complex lhs, double rhs);
ae_bool ae_c_neq_d(ae_complex lhs, double rhs);
ae_complex ae_c_add_d(ae_complex lhs, double rhs);
ae_complex ae_c_mul_d(ae_complex lhs, double rhs);
ae_complex ae_c_sub_d(ae_complex lhs, double rhs);
ae_complex ae_c_d_sub(double lhs, ae_complex rhs);
ae_complex ae_c_div_d(ae_complex lhs, double rhs);
ae_complex ae_c_d_div(double lhs, ae_complex rhs);
ae_complex ae_c_conj(ae_complex lhs, ae_state *state);
ae_complex ae_c_sqr(ae_complex lhs, ae_state *state);
double ae_c_abs(ae_complex z, ae_state *state);
/************************************************************************
Complex BLAS operations
************************************************************************/
ae_complex ae_v_cdotproduct(const ae_complex *v0, ae_int_t stride0, const c
har *conj0, const ae_complex *v1, ae_int_t stride1, const char *conj1, ae_i
nt_t n);
void 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);
void 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);
void 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)
;
void 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 al
pha);
void 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);
void 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)
;
void 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 al
pha);
void 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);
void ae_v_csubd(ae_complex *vdst, ae_int_t stride_dst, const ae_complex *vs
rc, ae_int_t stride_src, const char *conj_src, ae_int_t n, double alpha);
void ae_v_csubc(ae_complex *vdst, ae_int_t stride_dst, const ae_complex *vs
rc, ae_int_t stride_src, const char *conj_src, ae_int_t n, ae_complex alpha
);
void ae_v_cmuld(ae_complex *vdst, ae_int_t stride_dst, ae_int_t n, double a
lpha);
void ae_v_cmulc(ae_complex *vdst, ae_int_t stride_dst, ae_int_t n, ae_compl
ex alpha);
/************************************************************************
Real BLAS operations
************************************************************************/
double ae_v_dotproduct(const double *v0, ae_int_t stride0, const double *v1
, ae_int_t stride1, ae_int_t n);
void ae_v_move(double *vdst, ae_int_t stride_dst, const double* vsrc, a
e_int_t stride_src, ae_int_t n);
void ae_v_moveneg(double *vdst, ae_int_t stride_dst, const double* vsrc, a
e_int_t stride_src, ae_int_t n);
void ae_v_moved(double *vdst, ae_int_t stride_dst, const double* vsrc, a
e_int_t stride_src, ae_int_t n, double alpha);
void ae_v_add(double *vdst, ae_int_t stride_dst, const double *vsrc, a
e_int_t stride_src, ae_int_t n);
void ae_v_addd(double *vdst, ae_int_t stride_dst, const double *vsrc, a
e_int_t stride_src, ae_int_t n, double alpha);
void ae_v_sub(double *vdst, ae_int_t stride_dst, const double *vsrc, a
e_int_t stride_src, ae_int_t n);
void ae_v_subd(double *vdst, ae_int_t stride_dst, const double *vsrc, a
e_int_t stride_src, ae_int_t n, double alpha);
void ae_v_muld(double *vdst, ae_int_t stride_dst, ae_int_t n, double alpha
);
/************************************************************************
Other functions
************************************************************************/
ae_int_t ae_v_len(ae_int_t a, ae_int_t b);
/*
extern const double ae_machineepsilon;
extern const double ae_maxrealnumber;
extern const double ae_minrealnumber;
extern const double ae_pi;
*/
#define ae_machineepsilon 5E-16
#define ae_maxrealnumber 1E300
#define ae_minrealnumber 1E-300
#define ae_pi 3.1415926535897932384626433832795
/************************************************************************
RComm functions
************************************************************************/
typedef struct rcommstate
{
int stage;
ae_vector ia;
ae_vector ba;
ae_vector ra;
ae_vector ca;
} rcommstate;
ae_bool _rcommstate_init(rcommstate* p, ae_state *_state, ae_bool make_auto
matic);
ae_bool _rcommstate_init_copy(rcommstate* dst, rcommstate* src, ae_state *_
state, ae_bool make_automatic);
void _rcommstate_clear(rcommstate* p);
#ifdef AE_USE_ALLOC_COUNTER
extern ae_int64_t _alloc_counter;
#endif
}
/////////////////////////////////////////////////////////////////////////
//
// THIS SECTION CONTAINS DECLARATIONS FOR C++ RELATED FUNCTIONALITY
//
/////////////////////////////////////////////////////////////////////////
namespace alglib
{ {
typedef alglib_impl::ae_int_t ae_int_t;
/******************************************************************** /********************************************************************
Service routines: Class forwards
amalloc - allocates an aligned block of size bytes
afree - frees block allocated by amalloc
vlen - just alias for n2-n1+1
********************************************************************/ ********************************************************************/
void* amalloc(size_t size, size_t alignment); class complex;
void afree(void *block);
int vlen(int n1, int n2); ae_int_t vlen(ae_int_t n1, ae_int_t n2);
/******************************************************************** /********************************************************************
Exception class. Exception class.
********************************************************************/ ********************************************************************/
class ap_error class ap_error
{ {
public: public:
ap_error(){};
ap_error(const char *s){ msg = s; };
std::string msg; std::string msg;
static void make_assertion(bool bClause) ap_error();
{ if(!bClause) throw ap_error(); }; ap_error(const char *s);
static void make_assertion(bool bClause, const char *msg) static void make_assertion(bool bClause);
{ if(!bClause) throw ap_error(msg); }; static void make_assertion(bool bClause, const char *msg);
private: private:
}; };
/******************************************************************** /********************************************************************
Class defining a complex number with double precision. Complex number with double precision.
********************************************************************/ ********************************************************************/
class complex;
class complex class complex
{ {
public: public:
complex():x(0.0),y(0.0){}; complex();
complex(const double &_x):x(_x),y(0.0){}; complex(const double &_x);
complex(const double &_x, const double &_y):x(_x),y(_y){}; complex(const double &_x, const double &_y);
complex(const complex &z):x(z.x),y(z.y){}; complex(const complex &z);
complex& operator= (const double& v){ x = v; y = 0.0; return *this; }; complex& operator= (const double& v);
complex& operator+=(const double& v){ x += v; return *this; }; complex& operator+=(const double& v);
complex& operator-=(const double& v){ x -= v; return *this; }; complex& operator-=(const double& v);
complex& operator*=(const double& v){ x *= v; y *= v; return *this; }; complex& operator*=(const double& v);
complex& operator/=(const double& v){ x /= v; y /= v; return *this; }; complex& operator/=(const double& v);
complex& operator= (const complex& z){ x = z.x; y = z.y; return *this complex& operator= (const complex& z);
; }; complex& operator+=(const complex& z);
complex& operator+=(const complex& z){ x += z.x; y += z.y; return *this complex& operator-=(const complex& z);
; }; complex& operator*=(const complex& z);
complex& operator-=(const complex& z){ x -= z.x; y -= z.y; return *this complex& operator/=(const complex& z);
; };
complex& operator*=(const complex& z){ double t = x*z.x-y*z.y; y = x*z. alglib_impl::ae_complex* c_ptr();
y+y*z.x; x = t; return *this; }; const alglib_impl::ae_complex* c_ptr() const;
complex& operator/=(const complex& z)
{ std::string tostring(int dps) const;
ap::complex result;
double e;
double f;
if( fabs(z.y)<fabs(z.x) )
{
e = z.y/z.x;
f = z.x+z.y*e;
result.x = (x+y*e)/f;
result.y = (y-x*e)/f;
}
else
{
e = z.x/z.y;
f = z.y+z.x*e;
result.x = (y+x*e)/f;
result.y = (-x+y*e)/f;
}
*this = result;
return *this;
};
double x, y; double x, y;
}; };
const complex operator/(const complex& lhs, const complex& rhs); const alglib::complex operator/(const alglib::complex& lhs, const alglib::c
const bool operator==(const complex& lhs, const complex& rhs); omplex& rhs);
const bool operator!=(const complex& lhs, const complex& rhs); const bool operator==(const alglib::complex& lhs, const alglib::complex& rh
const complex operator+(const complex& lhs); s);
const complex operator-(const complex& lhs); const bool operator!=(const alglib::complex& lhs, const alglib::complex& rh
const complex operator+(const complex& lhs, const complex& rhs); s);
const complex operator+(const complex& lhs, const double& rhs); const alglib::complex operator+(const alglib::complex& lhs);
const complex operator+(const double& lhs, const complex& rhs); const alglib::complex operator-(const alglib::complex& lhs);
const complex operator-(const complex& lhs, const complex& rhs); const alglib::complex operator+(const alglib::complex& lhs, const alglib::c
const complex operator-(const complex& lhs, const double& rhs); omplex& rhs);
const complex operator-(const double& lhs, const complex& rhs); const alglib::complex operator+(const alglib::complex& lhs, const double& r
const complex operator*(const complex& lhs, const complex& rhs); hs);
const complex operator*(const complex& lhs, const double& rhs); const alglib::complex operator+(const double& lhs, const alglib::complex& r
const complex operator*(const double& lhs, const complex& rhs); hs);
const complex operator/(const complex& lhs, const complex& rhs); const alglib::complex operator-(const alglib::complex& lhs, const alglib::c
const complex operator/(const double& lhs, const complex& rhs); omplex& rhs);
const complex operator/(const complex& lhs, const double& rhs); const alglib::complex operator-(const alglib::complex& lhs, const double& r
const double abscomplex(const complex &z); hs);
const complex conj(const complex &z); const alglib::complex operator-(const double& lhs, const alglib::complex& r
const complex csqr(const complex &z); hs);
const alglib::complex operator*(const alglib::complex& lhs, const alglib::c
/******************************************************************** omplex& rhs);
Templates for vector operations const alglib::complex operator*(const alglib::complex& lhs, const double& r
********************************************************************/ hs);
#include "apvt.h" const alglib::complex operator*(const double& lhs, const alglib::complex& r
hs);
const alglib::complex operator/(const alglib::complex& lhs, const alglib::c
omplex& rhs);
const alglib::complex operator/(const double& lhs, const alglib::complex& r
hs);
const alglib::complex operator/(const alglib::complex& lhs, const double& r
hs);
double abscomplex(const alglib::complex &z);
alglib::complex conj(const alglib::complex &z);
alglib::complex csqr(const alglib::complex &z);
/******************************************************************** /********************************************************************
Level 1 BLAS functions Level 1 BLAS functions
NOTES:
* destination and source should NOT overlap
* stride is assumed to be positive, but it is not
assert'ed within function
* conj_src parameter specifies whether complex source is conjugated
before processing or not. Pass string which starts with 'N' or 'n'
("No conj", for example) to use unmodified parameter. All other
values will result in conjugation of input, but it is recommended
to use "Conj" in such cases.
********************************************************************/ ********************************************************************/
double vdotproduct(const double *v0, int stride0, const double *v1, int str double vdotproduct(const double *v0, ae_int_t stride0, const double *v1, ae
ide1, int n); _int_t stride1, ae_int_t n);
complex vdotproduct(const complex *v0, int stride0, const char *conj0, cons double vdotproduct(const double *v1, const double *v2, ae_int_t N);
t complex *v1, int stride1, const char *conj1, int n);
void vmove(double *vdst, int stride_dst, const double* vsrc, int stride_s alglib::complex vdotproduct(const alglib::complex *v0, ae_int_t stride0, co
rc, int n); nst char *conj0, const alglib::complex *v1, ae_int_t stride1, const char *c
void vmove(complex *vdst, int stride_dst, const complex* vsrc, int stride_s onj1, ae_int_t n);
rc, const char *conj_src, int n); alglib::complex vdotproduct(const alglib::complex *v1, const alglib::comple
x *v2, ae_int_t N);
void vmoveneg(double *vdst, int stride_dst, const double* vsrc, int strid void vmove(double *vdst, ae_int_t stride_dst, const double* vsrc, ae_int_
e_src, int n); t stride_src, ae_int_t n);
void vmoveneg(complex *vdst, int stride_dst, const complex* vsrc, int strid void vmove(double *vdst, const double* vsrc, ae_int_t N);
e_src, const char *conj_src, int n);
void vmove(double *vdst, int stride_dst, const double* vsrc, int stride_s void vmove(alglib::complex *vdst, ae_int_t stride_dst, const alglib::comple
rc, int n, double alpha); x* vsrc, ae_int_t stride_src, const char *conj_src, ae_int_t n);
void vmove(complex *vdst, int stride_dst, const complex* vsrc, int stride_s void vmove(alglib::complex *vdst, const alglib::complex* vsrc, ae_int_t N);
rc, const char *conj_src, int n, double alpha);
void vmove(complex *vdst, int stride_dst, const complex* vsrc, int stride_s
rc, const char *conj_src, int n, complex alpha);
void vadd(double *vdst, int stride_dst, const double *vsrc, int stride_sr void vmoveneg(double *vdst, ae_int_t stride_dst, const double* vsrc, ae_i
c, int n); nt_t stride_src, ae_int_t n);
void vadd(complex *vdst, int stride_dst, const complex *vsrc, int stride_sr void vmoveneg(double *vdst, const double *vsrc, ae_int_t N);
c, const char *conj_src, int n);
void vadd(double *vdst, int stride_dst, const double *vsrc, int stride_sr void vmoveneg(alglib::complex *vdst, ae_int_t stride_dst, const alglib::com
c, int n, double alpha); plex* vsrc, ae_int_t stride_src, const char *conj_src, ae_int_t n);
void vadd(complex *vdst, int stride_dst, const complex *vsrc, int stride_sr void vmoveneg(alglib::complex *vdst, const alglib::complex *vsrc, ae_int_t
c, const char *conj_src, int n, double alpha); N);
void vadd(complex *vdst, int stride_dst, const complex *vsrc, int stride_sr
c, const char *conj_src, int n, complex alpha);
void vsub(double *vdst, int stride_dst, const double *vsrc, int stride_sr void vmove(double *vdst, ae_int_t stride_dst, const double* vsrc, ae_int_
c, int n); t stride_src, ae_int_t n, double alpha);
void vsub(complex *vdst, int stride_dst, const complex *vsrc, int stride_sr void vmove(double *vdst, const double *vsrc, ae_int_t N, double alpha);
c, const char *conj_src, int n);
void vsub(double *vdst, int stride_dst, const double *vsrc, int stride_sr void vmove(alglib::complex *vdst, ae_int_t stride_dst, const alglib::comple
c, int n, double alpha); x* vsrc, ae_int_t stride_src, const char *conj_src, ae_int_t n, double alph
void vsub(complex *vdst, int stride_dst, const complex *vsrc, int stride_sr a);
c, const char *conj_src, int n, double alpha); void vmove(alglib::complex *vdst, const alglib::complex *vsrc, ae_int_t N,
void vsub(complex *vdst, int stride_dst, const complex *vsrc, int stride_sr double alpha);
c, const char *conj_src, int n, complex alpha);
void vmul(double *vdst, int stride_dst, int n, double alpha); void vmove(alglib::complex *vdst, ae_int_t stride_dst, const alglib::comple
void vmul(complex *vdst, int stride_dst, int n, double alpha); x* vsrc, ae_int_t stride_src, const char *conj_src, ae_int_t n, alglib::com
void vmul(complex *vdst, int stride_dst, int n, complex alpha); plex alpha);
void vmove(alglib::complex *vdst, const alglib::complex *vsrc, ae_int_t N,
alglib::complex alpha);
/******************************************************************** void vadd(double *vdst, ae_int_t stride_dst, const double *vsrc, ae_int_t
Obsolete BLAS functions stride_src, ae_int_t n);
********************************************************************/ void vadd(double *vdst, const double *vsrc, ae_int_t N);
double vdotproduct(const double *v1, const double *v2, int N);
complex vdotproduct(const complex *v1, const complex *v2, int N); void 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);
void vadd(alglib::complex *vdst, const alglib::complex *vsrc, ae_int_t N);
void vadd(double *vdst, ae_int_t stride_dst, const double *vsrc, ae_int_t
stride_src, ae_int_t n, double alpha);
void vadd(double *vdst, const double *vsrc, ae_int_t N, double alpha);
void 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
);
void vadd(alglib::complex *vdst, const alglib::complex *vsrc, ae_int_t N, d
ouble alpha);
void 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::comp
lex alpha);
void vadd(alglib::complex *vdst, const alglib::complex *vsrc, ae_int_t N, a
lglib::complex alpha);
void vmove(double *vdst, const double* vsrc, int N); void vsub(double *vdst, ae_int_t stride_dst, const double *vsrc, ae_int_t
void vmove(complex *vdst, const complex* vsrc, int N); stride_src, ae_int_t n);
void vsub(double *vdst, const double *vsrc, ae_int_t N);
void vmoveneg(double *vdst, const double *vsrc, int N); void vsub(alglib::complex *vdst, ae_int_t stride_dst, const alglib::complex
void vmoveneg(complex *vdst, const complex *vsrc, int N); *vsrc, ae_int_t stride_src, const char *conj_src, ae_int_t n);
void vsub(alglib::complex *vdst, const alglib::complex *vsrc, ae_int_t N);
void vmove(double *vdst, const double *vsrc, int N, double alpha); void vsub(double *vdst, ae_int_t stride_dst, const double *vsrc, ae_int_t
void vmove(complex *vdst, const complex *vsrc, int N, double alpha); stride_src, ae_int_t n, double alpha);
void vmove(complex *vdst, const complex *vsrc, int N, complex alpha); void vsub(double *vdst, const double *vsrc, ae_int_t N, double alpha);
void vadd(double *vdst, const double *vsrc, int N); void vsub(alglib::complex *vdst, ae_int_t stride_dst, const alglib::complex
void vadd(complex *vdst, const complex *vsrc, int N); *vsrc, ae_int_t stride_src, const char *conj_src, ae_int_t n, double alpha
);
void vsub(alglib::complex *vdst, const alglib::complex *vsrc, ae_int_t N, d
ouble alpha);
void vadd(double *vdst, const double *vsrc, int N, double alpha); void vsub(alglib::complex *vdst, ae_int_t stride_dst, const alglib::complex
void vadd(complex *vdst, const complex *vsrc, int N, double alpha); *vsrc, ae_int_t stride_src, const char *conj_src, ae_int_t n, alglib::comp
void vadd(complex *vdst, const complex *vsrc, int N, complex alpha); lex alpha);
void vsub(alglib::complex *vdst, const alglib::complex *vsrc, ae_int_t N, a
lglib::complex alpha);
void vsub(double *vdst, const double *vsrc, int N); void vmul(double *vdst, ae_int_t stride_dst, ae_int_t n, double alpha);
void vsub(complex *vdst, const complex *vsrc, int N); void vmul(double *vdst, ae_int_t N, double alpha);
void vsub(double *vdst, const double *vsrc, int N, double alpha); void vmul(alglib::complex *vdst, ae_int_t stride_dst, ae_int_t n, double al
void vsub(complex *vdst, const complex *vsrc, int N, double alpha); pha);
void vsub(complex *vdst, const complex *vsrc, int N, complex alpha); void vmul(alglib::complex *vdst, ae_int_t N, double alpha);
void vmul(double *vdst, int N, double alpha); void vmul(alglib::complex *vdst, ae_int_t stride_dst, ae_int_t n, alglib::c
void vmul(complex *vdst, int N, double alpha); omplex alpha);
void vmul(complex *vdst, int N, complex alpha); void vmul(alglib::complex *vdst, ae_int_t N, alglib::complex alpha);
/******************************************************************** /********************************************************************
Template of a dynamical one-dimensional array string conversion functions !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
********************************************************************/ ********************************************************************/
template<class T, bool Aligned = false>
class template_1d_array /********************************************************************
1- and 2-dimensional arrays
********************************************************************/
class ae_vector_wrapper
{ {
public: public:
template_1d_array() ae_vector_wrapper();
{ virtual ~ae_vector_wrapper();
m_Vec=0; ae_vector_wrapper(const ae_vector_wrapper &rhs);
m_iVecSize = 0; const ae_vector_wrapper& operator=(const ae_vector_wrapper &rhs);
m_iLow = 0;
m_iHigh = -1; void setlength(ae_int_t iLen);
}; ae_int_t length() const;
void attach_to(alglib_impl::ae_vector *ptr);
void allocate_own(ae_int_t size, alglib_impl::ae_datatype datatype);
const alglib_impl::ae_vector* c_ptr() const;
alglib_impl::ae_vector* c_ptr();
protected:
alglib_impl::ae_vector *p_vec;
alglib_impl::ae_vector vec;
};
~template_1d_array() class boolean_1d_array : public ae_vector_wrapper
{ {
if(m_Vec) public:
{ boolean_1d_array();
if( Aligned ) boolean_1d_array(const char *s);
ap::afree(m_Vec); boolean_1d_array(alglib_impl::ae_vector *p);
else virtual ~boolean_1d_array() ;
delete[] m_Vec;
} const ae_bool& operator()(ae_int_t i) const;
}; ae_bool& operator()(ae_int_t i);
const ae_bool& operator[](ae_int_t i) const;
ae_bool& operator[](ae_int_t i);
void setcontent(ae_int_t iLen, const bool *pContent );
ae_bool* getcontent();
const ae_bool* getcontent() const;
template_1d_array(const template_1d_array &rhs) std::string tostring() const;
{ };
m_Vec=0;
m_iVecSize = 0;
m_iLow = 0;
m_iHigh = -1;
if( rhs.m_iVecSize!=0 )
setcontent(rhs.m_iLow, rhs.m_iHigh, rhs.getcontent());
};
const template_1d_array& operator=(const template_1d_array &rhs) class integer_1d_array : public ae_vector_wrapper
{ {
if( this==&rhs ) public:
return *this; integer_1d_array();
integer_1d_array(alglib_impl::ae_vector *p);
integer_1d_array(const char *s);
virtual ~integer_1d_array();
if( rhs.m_iVecSize!=0 ) const ae_int_t& operator()(ae_int_t i) const;
setcontent(rhs.m_iLow, rhs.m_iHigh, rhs.getcontent()); ae_int_t& operator()(ae_int_t i);
else
{
m_Vec=0;
m_iVecSize = 0;
m_iLow = 0;
m_iHigh = -1;
}
return *this;
};
const T& operator()(int i) const const ae_int_t& operator[](ae_int_t i) const;
{ ae_int_t& operator[](ae_int_t i);
#ifndef NO_AP_ASSERT
ap_error::make_assertion(i>=m_iLow && i<=m_iHigh);
#endif
return m_Vec[ i-m_iLow ];
};
T& operator()(int i) void setcontent(ae_int_t iLen, const ae_int_t *pContent );
{
#ifndef NO_AP_ASSERT
ap_error::make_assertion(i>=m_iLow && i<=m_iHigh);
#endif
return m_Vec[ i-m_iLow ];
};
void setbounds( int iLow, int iHigh ) ae_int_t* getcontent();
{ const ae_int_t* getcontent() const;
if(m_Vec)
{
if( Aligned )
ap::afree(m_Vec);
else
delete[] m_Vec;
}
m_iLow = iLow;
m_iHigh = iHigh;
m_iVecSize = iHigh-iLow+1;
if( Aligned )
m_Vec = (T*)ap::amalloc((size_t)(m_iVecSize*sizeof(T)), 16);
else
m_Vec = new T[(size_t)m_iVecSize];
};
void setlength(int iLen) std::string tostring() const;
{ };
setbounds(0, iLen-1);
}
void setcontent( int iLow, int iHigh, const T *pContent ) class real_1d_array : public ae_vector_wrapper
{ {
setbounds(iLow, iHigh); public:
for(int i=0; i<m_iVecSize; i++) real_1d_array();
m_Vec[i] = pContent[i]; real_1d_array(alglib_impl::ae_vector *p);
}; real_1d_array(const char *s);
virtual ~real_1d_array();
const double& operator()(ae_int_t i) const;
double& operator()(ae_int_t i);
const double& operator[](ae_int_t i) const;
double& operator[](ae_int_t i);
void setcontent(ae_int_t iLen, const double *pContent );
double* getcontent();
const double* getcontent() const;
T* getcontent() std::string tostring(int dps) const;
{ };
return m_Vec;
};
const T* getcontent() const class complex_1d_array : public ae_vector_wrapper
{ {
return m_Vec; public:
}; complex_1d_array();
complex_1d_array(alglib_impl::ae_vector *p);
complex_1d_array(const char *s);
virtual ~complex_1d_array();
const alglib::complex& operator()(ae_int_t i) const;
alglib::complex& operator()(ae_int_t i);
const alglib::complex& operator[](ae_int_t i) const;
alglib::complex& operator[](ae_int_t i);
void setcontent(ae_int_t iLen, const alglib::complex *pContent );
alglib::complex* getcontent();
const alglib::complex* getcontent() const;
int getlowbound(int iBoundNum = 0) const std::string tostring(int dps) const;
{ };
return m_iLow;
};
int gethighbound(int iBoundNum = 0) const class ae_matrix_wrapper
{ {
return m_iHigh; public:
}; ae_matrix_wrapper();
virtual ~ae_matrix_wrapper();
ae_matrix_wrapper(const ae_matrix_wrapper &rhs);
const ae_matrix_wrapper& operator=(const ae_matrix_wrapper &rhs);
void setlength(ae_int_t rows, ae_int_t cols);
ae_int_t rows() const;
ae_int_t cols() const;
bool isempty() const;
ae_int_t getstride() const;
void attach_to(alglib_impl::ae_matrix *ptr);
void allocate_own(ae_int_t rows, ae_int_t cols, alglib_impl::ae_datatyp
e datatype);
const alglib_impl::ae_matrix* c_ptr() const;
alglib_impl::ae_matrix* c_ptr();
protected:
alglib_impl::ae_matrix *p_mat;
alglib_impl::ae_matrix mat;
};
raw_vector<T> getvector(int iStart, int iEnd) class boolean_2d_array : public ae_matrix_wrapper
{ {
if( iStart>iEnd || wrongIdx(iStart) || wrongIdx(iEnd) ) public:
return raw_vector<T>(0, 0, 1); boolean_2d_array();
else boolean_2d_array(alglib_impl::ae_matrix *p);
return raw_vector<T>(m_Vec+iStart-m_iLow, iEnd-iStart+1, 1); boolean_2d_array(const char *s);
}; virtual ~boolean_2d_array();
const_raw_vector<T> getvector(int iStart, int iEnd) const const ae_bool& operator()(ae_int_t i, ae_int_t j) const;
{ ae_bool& operator()(ae_int_t i, ae_int_t j);
if( iStart>iEnd || wrongIdx(iStart) || wrongIdx(iEnd) )
return const_raw_vector<T>(0, 0, 1); const ae_bool* operator[](ae_int_t i) const;
else ae_bool* operator[](ae_int_t i);
return const_raw_vector<T>(m_Vec+iStart-m_iLow, iEnd-iStart+1,
1); void setcontent(ae_int_t irows, ae_int_t icols, const bool *pContent );
};
private:
bool wrongIdx(int i) const { return i<m_iLow || i>m_iHigh; };
T *m_Vec; std::string tostring() const ;
long m_iVecSize;
long m_iLow, m_iHigh;
}; };
/******************************************************************** class integer_2d_array : public ae_matrix_wrapper
Template of a dynamical two-dimensional array
********************************************************************/
template<class T, bool Aligned = false>
class template_2d_array
{ {
public: public:
template_2d_array() integer_2d_array();
{ integer_2d_array(alglib_impl::ae_matrix *p);
m_Vec=0; integer_2d_array(const char *s);
m_iVecSize=0; virtual ~integer_2d_array();
m_iLow1 = 0;
m_iHigh1 = -1;
m_iLow2 = 0;
m_iHigh2 = -1;
};
~template_2d_array() const ae_int_t& operator()(ae_int_t i, ae_int_t j) const;
{ ae_int_t& operator()(ae_int_t i, ae_int_t j);
if(m_Vec)
{
if( Aligned )
ap::afree(m_Vec);
else
delete[] m_Vec;
}
};
template_2d_array(const template_2d_array &rhs) const ae_int_t* operator[](ae_int_t i) const;
{ ae_int_t* operator[](ae_int_t i);
m_Vec=0;
m_iVecSize=0;
m_iLow1 = 0;
m_iHigh1 = -1;
m_iLow2 = 0;
m_iHigh2 = -1;
if( rhs.m_iVecSize!=0 )
{
setbounds(rhs.m_iLow1, rhs.m_iHigh1, rhs.m_iLow2, rhs.m_iHigh2)
;
for(int i=m_iLow1; i<=m_iHigh1; i++)
for(int j=m_iLow2; j<=m_iHigh2; j++)
operator()(i,j) = rhs(i,j);
//vmove(&(operator()(i,m_iLow2)), &(rhs(i,m_iLow2)), m_iHig
h2-m_iLow2+1);
}
};
const template_2d_array& operator=(const template_2d_array &rhs)
{
if( this==&rhs )
return *this;
if( rhs.m_iVecSize!=0 )
{
setbounds(rhs.m_iLow1, rhs.m_iHigh1, rhs.m_iLow2, rhs.m_iHigh2)
;
for(int i=m_iLow1; i<=m_iHigh1; i++)
for(int j=m_iLow2; j<=m_iHigh2; j++)
operator()(i,j) = rhs(i,j);
//vmove(&(operator()(i,m_iLow2)), &(rhs(i,m_iLow2)), m_iHig
h2-m_iLow2+1);
}
else
{
if(m_Vec)
{
if( Aligned )
ap::afree(m_Vec);
else
delete[] m_Vec;
}
m_Vec=0;
m_iVecSize=0;
m_iLow1 = 0;
m_iHigh1 = -1;
m_iLow2 = 0;
m_iHigh2 = -1;
}
return *this;
};
const T& operator()(int i1, int i2) const
{
#ifndef NO_AP_ASSERT
ap_error::make_assertion(i1>=m_iLow1 && i1<=m_iHigh1);
ap_error::make_assertion(i2>=m_iLow2 && i2<=m_iHigh2);
#endif
return m_Vec[ m_iConstOffset + i2 +i1*m_iLinearMember];
};
T& operator()(int i1, int i2) void setcontent(ae_int_t irows, ae_int_t icols, const ae_int_t *pConten
{ t );
#ifndef NO_AP_ASSERT
ap_error::make_assertion(i1>=m_iLow1 && i1<=m_iHigh1);
ap_error::make_assertion(i2>=m_iLow2 && i2<=m_iHigh2);
#endif
return m_Vec[ m_iConstOffset + i2 +i1*m_iLinearMember];
};
void setbounds( int iLow1, int iHigh1, int iLow2, int iHigh2 ) std::string tostring() const;
{ };
if(m_Vec)
{
if( Aligned )
ap::afree(m_Vec);
else
delete[] m_Vec;
}
int n1 = iHigh1-iLow1+1;
int n2 = iHigh2-iLow2+1;
m_iVecSize = n1*n2;
if( Aligned )
{
//if( n2%2!=0 )
while( (n2*sizeof(T))%16!=0 )
{
n2++;
m_iVecSize += n1;
}
m_Vec = (T*)ap::amalloc((size_t)(m_iVecSize*sizeof(T)), 16);
}
else
m_Vec = new T[(size_t)m_iVecSize];
m_iLow1 = iLow1;
m_iHigh1 = iHigh1;
m_iLow2 = iLow2;
m_iHigh2 = iHigh2;
m_iConstOffset = -m_iLow2-m_iLow1*n2;
m_iLinearMember = n2;
};
void setlength(int iLen1, int iLen2) class real_2d_array : public ae_matrix_wrapper
{ {
setbounds(0, iLen1-1, 0, iLen2-1); public:
} real_2d_array();
real_2d_array(alglib_impl::ae_matrix *p);
real_2d_array(const char *s);
virtual ~real_2d_array();
void setcontent( int iLow1, int iHigh1, int iLow2, int iHigh2, const T const double& operator()(ae_int_t i, ae_int_t j) const;
*pContent ) double& operator()(ae_int_t i, ae_int_t j);
{
setbounds(iLow1, iHigh1, iLow2, iHigh2);
for(int i=m_iLow1; i<=m_iHigh1; i++, pContent += m_iHigh2-m_iLow2+1
)
for(int j=m_iLow2; j<=m_iHigh2; j++)
operator()(i,j) = pContent[j-m_iLow2];
//vmove(&(operator()(i,m_iLow2)), pContent, m_iHigh2-m_iLow2+1)
;
};
int getlowbound(int iBoundNum) const const double* operator[](ae_int_t i) const;
{ double* operator[](ae_int_t i);
return iBoundNum==1 ? m_iLow1 : m_iLow2;
};
int gethighbound(int iBoundNum) const void setcontent(ae_int_t irows, ae_int_t icols, const double *pContent
{ );
return iBoundNum==1 ? m_iHigh1 : m_iHigh2;
};
raw_vector<T> getcolumn(int iColumn, int iRowStart, int iRowEnd) std::string tostring(int dps) const;
{ };
if( (iRowStart>iRowEnd) || wrongColumn(iColumn) || wrongRow(iRowSta
rt) ||wrongRow(iRowEnd) )
return raw_vector<T>(0, 0, 1);
else
return raw_vector<T>(&((*this)(iRowStart, iColumn)), iRowEnd-iR
owStart+1, m_iLinearMember);
};
raw_vector<T> getrow(int iRow, int iColumnStart, int iColumnEnd) class complex_2d_array : public ae_matrix_wrapper
{ {
if( (iColumnStart>iColumnEnd) || wrongRow(iRow) || wrongColumn(iCol public:
umnStart) || wrongColumn(iColumnEnd)) complex_2d_array();
return raw_vector<T>(0, 0, 1); complex_2d_array(alglib_impl::ae_matrix *p);
else complex_2d_array(const char *s);
return raw_vector<T>(&((*this)(iRow, iColumnStart)), iColumnEnd virtual ~complex_2d_array();
-iColumnStart+1, 1);
};
const_raw_vector<T> getcolumn(int iColumn, int iRowStart, int iRowEnd) const alglib::complex& operator()(ae_int_t i, ae_int_t j) const;
const alglib::complex& operator()(ae_int_t i, ae_int_t j);
{
if( (iRowStart>iRowEnd) || wrongColumn(iColumn) || wrongRow(iRowSta
rt) ||wrongRow(iRowEnd) )
return const_raw_vector<T>(0, 0, 1);
else
return const_raw_vector<T>(&((*this)(iRowStart, iColumn)), iRow
End-iRowStart+1, m_iLinearMember);
};
const_raw_vector<T> getrow(int iRow, int iColumnStart, int iColumnEnd) const alglib::complex* operator[](ae_int_t i) const;
const alglib::complex* operator[](ae_int_t i);
{
if( (iColumnStart>iColumnEnd) || wrongRow(iRow) || wrongColumn(iCol
umnStart) || wrongColumn(iColumnEnd))
return const_raw_vector<T>(0, 0, 1);
else
return const_raw_vector<T>(&((*this)(iRow, iColumnStart)), iCol
umnEnd-iColumnStart+1, 1);
};
int getstride() const void setcontent(ae_int_t irows, ae_int_t icols, const alglib::complex *
{ pContent );
return m_iLinearMember;
};
private:
bool wrongRow(int i) const { return i<m_iLow1 || i>m_iHigh1; };
bool wrongColumn(int j) const { return j<m_iLow2 || j>m_iHigh2; };
T *m_Vec; std::string tostring(int dps) const;
long m_iVecSize; };
long m_iLow1, m_iLow2, m_iHigh1, m_iHigh2;
long m_iConstOffset, m_iLinearMember;
};
typedef template_1d_array<int> integer_1d_array;
typedef template_1d_array<double,true> real_1d_array;
typedef template_1d_array<complex> complex_1d_array;
typedef template_1d_array<bool> boolean_1d_array;
typedef template_2d_array<int> integer_2d_array;
typedef template_2d_array<double,true> real_2d_array;
typedef template_2d_array<complex> complex_2d_array;
typedef template_2d_array<bool> boolean_2d_array;
/******************************************************************** /********************************************************************
dataset information. dataset information.
can store regression dataset, classification dataset, or non-labeled can store regression dataset, classification dataset, or non-labeled
task: task:
* nout==0 means non-labeled task (clustering, for example) * nout==0 means non-labeled task (clustering, for example)
* nout>0 && nclasses==0 means regression task * nout>0 && nclasses==0 means regression task
* nout>0 && nclasses>0 means classification task * nout>0 && nclasses>0 means classification task
********************************************************************/ ********************************************************************/
skipping to change at line 619 skipping to change at line 913
public: public:
dataset():nin(0), nout(0), nclasses(0), trnsize(0), valsize(0), tstsize (0), totalsize(0){}; dataset():nin(0), nout(0), nclasses(0), trnsize(0), valsize(0), tstsize (0), totalsize(0){};
int nin, nout, nclasses; int nin, nout, nclasses;
int trnsize; int trnsize;
int valsize; int valsize;
int tstsize; int tstsize;
int totalsize; int totalsize;
ap::real_2d_array trn; alglib::real_2d_array trn;
ap::real_2d_array val; alglib::real_2d_array val;
ap::real_2d_array tst; alglib::real_2d_array tst;
ap::real_2d_array all; alglib::real_2d_array all;
}; };
bool opendataset(std::string file, dataset *pdataset); bool opendataset(std::string file, dataset *pdataset);
// //
// internal functions // internal functions
// //
std::string strtolower(const std::string &s); std::string strtolower(const std::string &s);
bool readstrings(std::string file, std::list<std::string> *pOutput); bool readstrings(std::string file, std::list<std::string> *pOutput);
bool readstrings(std::string file, std::list<std::string> *pOutput, std::st ring comment); bool readstrings(std::string file, std::list<std::string> *pOutput, std::st ring comment);
void explodestring(std::string s, char sep, std::vector<std::string> *pOutp ut); void explodestring(std::string s, char sep, std::vector<std::string> *pOutp ut);
std::string xtrim(std::string s);*/ std::string xtrim(std::string s);*/
/******************************************************************** /********************************************************************
reverse communication state
********************************************************************/
struct rcommstate
{
int stage;
ap::integer_1d_array ia;
ap::boolean_1d_array ba;
ap::real_1d_array ra;
ap::complex_1d_array ca;
};
/********************************************************************
Constants and functions introduced for compatibility with AlgoPascal Constants and functions introduced for compatibility with AlgoPascal
********************************************************************/ ********************************************************************/
extern const double machineepsilon; extern const double machineepsilon;
extern const double maxrealnumber; extern const double maxrealnumber;
extern const double minrealnumber; extern const double minrealnumber;
extern const double fp_nan;
extern const double fp_posinf;
extern const double fp_neginf;
int sign(double x); int sign(double x);
double randomreal(); double randomreal();
int randominteger(int maxv); int randominteger(int maxv);
int round(double x); int round(double x);
int trunc(double x); int trunc(double x);
int ifloor(double x); int ifloor(double x);
int iceil(double x); int iceil(double x);
double pi(); double pi();
double sqr(double x); double sqr(double x);
int maxint(int m1, int m2); int maxint(int m1, int m2);
int minint(int m1, int m2); int minint(int m1, int m2);
double maxreal(double m1, double m2); double maxreal(double m1, double m2);
double minreal(double m1, double m2); double minreal(double m1, double m2);
bool fp_eq(double v1, double v2); bool fp_eq(double v1, double v2);
bool fp_neq(double v1, double v2); bool fp_neq(double v1, double v2);
bool fp_less(double v1, double v2); bool fp_less(double v1, double v2);
bool fp_less_eq(double v1, double v2); bool fp_less_eq(double v1, double v2);
bool fp_greater(double v1, double v2); bool fp_greater(double v1, double v2);
bool fp_greater_eq(double v1, double v2); bool fp_greater_eq(double v1, double v2);
}//namespace ap bool fp_isnan(double x);
bool fp_isposinf(double x);
bool fp_isneginf(double x);
bool fp_isinf(double x);
bool fp_isfinite(double x);
}//namespace alglib
/////////////////////////////////////////////////////////////////////////
//
// THIS SECTIONS CONTAINS DECLARATIONS FOR OPTIMIZED LINEAR ALGEBRA CODES
// IT IS SHARED BETWEEN C++ AND PURE C LIBRARIES
//
/////////////////////////////////////////////////////////////////////////
namespace alglib_impl
{
#define ALGLIB_INTERCEPTS_ABLAS
void _ialglib_mv_32(const double *a, const double *x, double *y, ae_int_t s
tride, double alpha, double beta);
void _ialglib_mv(ae_int_t m, ae_int_t n, const double *a, const double *x,
double *y, ae_int_t stride, double alpha, double beta);
void _ialglib_mv_generic(ae_int_t m, ae_int_t n, const double *a, const dou
ble *x, double *y, ae_int_t stride, double alpha, double beta);
void _ialglib_mv_complex(ae_int_t m, ae_int_t n, const double *a, const dou
ble *x, ae_complex *cy, double *dy, ae_int_t stride, ae_complex alpha, ae_c
omplex beta);
void _ialglib_mv_complex_generic(ae_int_t m, ae_int_t n, const double *a, c
onst double *x, ae_complex *cy, double *dy, ae_int_t stride, ae_complex alp
ha, ae_complex beta);
void _ialglib_vzero(ae_int_t n, double *p, ae_int_t stride);
void _ialglib_vzero_complex(ae_int_t n, ae_complex *p, ae_int_t stride);
void _ialglib_vcopy(ae_int_t n, const double *a, ae_int_t stridea, double *
b, ae_int_t strideb);
void _ialglib_vcopy_complex(ae_int_t n, const ae_complex *a, ae_int_t strid
ea, double *b, ae_int_t strideb, char *conj);
void _ialglib_vcopy_complex(ae_int_t n, const double *a, ae_int_t stridea,
double *b, ae_int_t strideb, char *conj);
void _ialglib_mcopyblock(ae_int_t m, ae_int_t n, const double *a, ae_int_t
op, ae_int_t stride, double *b);
void _ialglib_mcopyunblock(ae_int_t m, ae_int_t n, const double *a, ae_int_
t op, double *b, ae_int_t stride);
void _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);
void _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);
bool _ialglib_i_rmatrixgemmf(ae_int_t m,
ae_int_t n,
ae_int_t k,
double alpha,
ae_matrix *a,
ae_int_t ia,
ae_int_t ja,
ae_int_t optypea,
ae_matrix *b,
ae_int_t ib,
ae_int_t jb,
ae_int_t optypeb,
double beta,
ae_matrix *c,
ae_int_t ic,
ae_int_t jc);
bool _ialglib_i_cmatrixgemmf(ae_int_t m,
ae_int_t n,
ae_int_t k,
ae_complex alpha,
ae_matrix *a,
ae_int_t ia,
ae_int_t ja,
ae_int_t optypea,
ae_matrix *b,
ae_int_t ib,
ae_int_t jb,
ae_int_t optypeb,
ae_complex beta,
ae_matrix *c,
ae_int_t ic,
ae_int_t jc);
bool _ialglib_i_cmatrixrighttrsmf(ae_int_t m,
ae_int_t n,
ae_matrix *a,
ae_int_t i1,
ae_int_t j1,
bool isupper,
bool isunit,
ae_int_t optype,
ae_matrix *x,
ae_int_t i2,
ae_int_t j2);
bool _ialglib_i_rmatrixrighttrsmf(ae_int_t m,
ae_int_t n,
ae_matrix *a,
ae_int_t i1,
ae_int_t j1,
bool isupper,
bool isunit,
ae_int_t optype,
ae_matrix *x,
ae_int_t i2,
ae_int_t j2);
bool _ialglib_i_cmatrixlefttrsmf(ae_int_t m,
ae_int_t n,
ae_matrix *a,
ae_int_t i1,
ae_int_t j1,
bool isupper,
bool isunit,
ae_int_t optype,
ae_matrix *x,
ae_int_t i2,
ae_int_t j2);
bool _ialglib_i_rmatrixlefttrsmf(ae_int_t m,
ae_int_t n,
ae_matrix *a,
ae_int_t i1,
ae_int_t j1,
bool isupper,
bool isunit,
ae_int_t optype,
ae_matrix *x,
ae_int_t i2,
ae_int_t j2);
bool _ialglib_i_cmatrixsyrkf(ae_int_t n,
ae_int_t k,
double alpha,
ae_matrix *a,
ae_int_t ia,
ae_int_t ja,
ae_int_t optypea,
double beta,
ae_matrix *c,
ae_int_t ic,
ae_int_t jc,
bool isupper);
bool _ialglib_i_rmatrixsyrkf(ae_int_t n,
ae_int_t k,
double alpha,
ae_matrix *a,
ae_int_t ia,
ae_int_t ja,
ae_int_t optypea,
double beta,
ae_matrix *c,
ae_int_t ic,
ae_int_t jc,
bool isupper);
bool _ialglib_i_cmatrixrank1f(ae_int_t m,
ae_int_t n,
ae_matrix *a,
ae_int_t ia,
ae_int_t ja,
ae_vector *u,
ae_int_t uoffs,
ae_vector *v,
ae_int_t voffs);
bool _ialglib_i_rmatrixrank1f(ae_int_t m,
ae_int_t n,
ae_matrix *a,
ae_int_t ia,
ae_int_t ja,
ae_vector *u,
ae_int_t uoffs,
ae_vector *v,
ae_int_t voffs);
}
#endif #endif
 End of changes. 81 change blocks. 
531 lines changed or deleted 1042 lines changed or added

This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/