alglib 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (255) hide show
  1. data/History.txt +7 -0
  2. data/Manifest.txt +253 -0
  3. data/README.txt +33 -0
  4. data/Rakefile +27 -0
  5. data/ext/Rakefile +24 -0
  6. data/ext/alglib.i +24 -0
  7. data/ext/alglib/Makefile +157 -0
  8. data/ext/alglib/airyf.cpp +372 -0
  9. data/ext/alglib/airyf.h +81 -0
  10. data/ext/alglib/alglib.cpp +8558 -0
  11. data/ext/alglib/alglib_util.cpp +19 -0
  12. data/ext/alglib/alglib_util.h +14 -0
  13. data/ext/alglib/ap.cpp +877 -0
  14. data/ext/alglib/ap.english.html +364 -0
  15. data/ext/alglib/ap.h +666 -0
  16. data/ext/alglib/ap.russian.html +442 -0
  17. data/ext/alglib/apvt.h +754 -0
  18. data/ext/alglib/bdss.cpp +1500 -0
  19. data/ext/alglib/bdss.h +251 -0
  20. data/ext/alglib/bdsvd.cpp +1339 -0
  21. data/ext/alglib/bdsvd.h +164 -0
  22. data/ext/alglib/bessel.cpp +1226 -0
  23. data/ext/alglib/bessel.h +331 -0
  24. data/ext/alglib/betaf.cpp +105 -0
  25. data/ext/alglib/betaf.h +74 -0
  26. data/ext/alglib/bidiagonal.cpp +1328 -0
  27. data/ext/alglib/bidiagonal.h +350 -0
  28. data/ext/alglib/binomialdistr.cpp +247 -0
  29. data/ext/alglib/binomialdistr.h +153 -0
  30. data/ext/alglib/blas.cpp +576 -0
  31. data/ext/alglib/blas.h +132 -0
  32. data/ext/alglib/cblas.cpp +226 -0
  33. data/ext/alglib/cblas.h +57 -0
  34. data/ext/alglib/cdet.cpp +138 -0
  35. data/ext/alglib/cdet.h +92 -0
  36. data/ext/alglib/chebyshev.cpp +216 -0
  37. data/ext/alglib/chebyshev.h +76 -0
  38. data/ext/alglib/chisquaredistr.cpp +157 -0
  39. data/ext/alglib/chisquaredistr.h +144 -0
  40. data/ext/alglib/cholesky.cpp +285 -0
  41. data/ext/alglib/cholesky.h +86 -0
  42. data/ext/alglib/cinverse.cpp +298 -0
  43. data/ext/alglib/cinverse.h +111 -0
  44. data/ext/alglib/clu.cpp +337 -0
  45. data/ext/alglib/clu.h +120 -0
  46. data/ext/alglib/correlation.cpp +280 -0
  47. data/ext/alglib/correlation.h +77 -0
  48. data/ext/alglib/correlationtests.cpp +726 -0
  49. data/ext/alglib/correlationtests.h +134 -0
  50. data/ext/alglib/crcond.cpp +826 -0
  51. data/ext/alglib/crcond.h +148 -0
  52. data/ext/alglib/creflections.cpp +310 -0
  53. data/ext/alglib/creflections.h +165 -0
  54. data/ext/alglib/csolve.cpp +312 -0
  55. data/ext/alglib/csolve.h +99 -0
  56. data/ext/alglib/ctrinverse.cpp +387 -0
  57. data/ext/alglib/ctrinverse.h +98 -0
  58. data/ext/alglib/ctrlinsolve.cpp +297 -0
  59. data/ext/alglib/ctrlinsolve.h +81 -0
  60. data/ext/alglib/dawson.cpp +234 -0
  61. data/ext/alglib/dawson.h +74 -0
  62. data/ext/alglib/descriptivestatistics.cpp +436 -0
  63. data/ext/alglib/descriptivestatistics.h +112 -0
  64. data/ext/alglib/det.cpp +140 -0
  65. data/ext/alglib/det.h +94 -0
  66. data/ext/alglib/dforest.cpp +1819 -0
  67. data/ext/alglib/dforest.h +316 -0
  68. data/ext/alglib/elliptic.cpp +497 -0
  69. data/ext/alglib/elliptic.h +217 -0
  70. data/ext/alglib/estnorm.cpp +429 -0
  71. data/ext/alglib/estnorm.h +107 -0
  72. data/ext/alglib/expintegrals.cpp +422 -0
  73. data/ext/alglib/expintegrals.h +108 -0
  74. data/ext/alglib/faq.english.html +258 -0
  75. data/ext/alglib/faq.russian.html +272 -0
  76. data/ext/alglib/fdistr.cpp +202 -0
  77. data/ext/alglib/fdistr.h +163 -0
  78. data/ext/alglib/fresnel.cpp +211 -0
  79. data/ext/alglib/fresnel.h +91 -0
  80. data/ext/alglib/gammaf.cpp +338 -0
  81. data/ext/alglib/gammaf.h +104 -0
  82. data/ext/alglib/gqgengauss.cpp +235 -0
  83. data/ext/alglib/gqgengauss.h +92 -0
  84. data/ext/alglib/gqgenhermite.cpp +268 -0
  85. data/ext/alglib/gqgenhermite.h +63 -0
  86. data/ext/alglib/gqgenjacobi.cpp +297 -0
  87. data/ext/alglib/gqgenjacobi.h +72 -0
  88. data/ext/alglib/gqgenlaguerre.cpp +265 -0
  89. data/ext/alglib/gqgenlaguerre.h +69 -0
  90. data/ext/alglib/gqgenlegendre.cpp +300 -0
  91. data/ext/alglib/gqgenlegendre.h +62 -0
  92. data/ext/alglib/gqgenlobatto.cpp +305 -0
  93. data/ext/alglib/gqgenlobatto.h +97 -0
  94. data/ext/alglib/gqgenradau.cpp +232 -0
  95. data/ext/alglib/gqgenradau.h +95 -0
  96. data/ext/alglib/hbisinv.cpp +480 -0
  97. data/ext/alglib/hbisinv.h +183 -0
  98. data/ext/alglib/hblas.cpp +228 -0
  99. data/ext/alglib/hblas.h +64 -0
  100. data/ext/alglib/hcholesky.cpp +339 -0
  101. data/ext/alglib/hcholesky.h +91 -0
  102. data/ext/alglib/hermite.cpp +114 -0
  103. data/ext/alglib/hermite.h +49 -0
  104. data/ext/alglib/hessenberg.cpp +370 -0
  105. data/ext/alglib/hessenberg.h +152 -0
  106. data/ext/alglib/hevd.cpp +247 -0
  107. data/ext/alglib/hevd.h +107 -0
  108. data/ext/alglib/hsschur.cpp +1316 -0
  109. data/ext/alglib/hsschur.h +108 -0
  110. data/ext/alglib/htridiagonal.cpp +734 -0
  111. data/ext/alglib/htridiagonal.h +180 -0
  112. data/ext/alglib/ialglib.cpp +6 -0
  113. data/ext/alglib/ialglib.h +9 -0
  114. data/ext/alglib/ibetaf.cpp +960 -0
  115. data/ext/alglib/ibetaf.h +125 -0
  116. data/ext/alglib/igammaf.cpp +430 -0
  117. data/ext/alglib/igammaf.h +157 -0
  118. data/ext/alglib/inv.cpp +274 -0
  119. data/ext/alglib/inv.h +115 -0
  120. data/ext/alglib/inverseupdate.cpp +480 -0
  121. data/ext/alglib/inverseupdate.h +185 -0
  122. data/ext/alglib/jacobianelliptic.cpp +164 -0
  123. data/ext/alglib/jacobianelliptic.h +94 -0
  124. data/ext/alglib/jarquebera.cpp +2271 -0
  125. data/ext/alglib/jarquebera.h +80 -0
  126. data/ext/alglib/kmeans.cpp +356 -0
  127. data/ext/alglib/kmeans.h +76 -0
  128. data/ext/alglib/laguerre.cpp +94 -0
  129. data/ext/alglib/laguerre.h +48 -0
  130. data/ext/alglib/lbfgs.cpp +1167 -0
  131. data/ext/alglib/lbfgs.h +218 -0
  132. data/ext/alglib/lda.cpp +434 -0
  133. data/ext/alglib/lda.h +133 -0
  134. data/ext/alglib/ldlt.cpp +1130 -0
  135. data/ext/alglib/ldlt.h +124 -0
  136. data/ext/alglib/leastsquares.cpp +1252 -0
  137. data/ext/alglib/leastsquares.h +290 -0
  138. data/ext/alglib/legendre.cpp +107 -0
  139. data/ext/alglib/legendre.h +49 -0
  140. data/ext/alglib/linreg.cpp +1185 -0
  141. data/ext/alglib/linreg.h +380 -0
  142. data/ext/alglib/logit.cpp +1523 -0
  143. data/ext/alglib/logit.h +333 -0
  144. data/ext/alglib/lq.cpp +399 -0
  145. data/ext/alglib/lq.h +160 -0
  146. data/ext/alglib/lu.cpp +462 -0
  147. data/ext/alglib/lu.h +119 -0
  148. data/ext/alglib/mannwhitneyu.cpp +4490 -0
  149. data/ext/alglib/mannwhitneyu.h +115 -0
  150. data/ext/alglib/minlm.cpp +918 -0
  151. data/ext/alglib/minlm.h +312 -0
  152. data/ext/alglib/mlpbase.cpp +3375 -0
  153. data/ext/alglib/mlpbase.h +589 -0
  154. data/ext/alglib/mlpe.cpp +1369 -0
  155. data/ext/alglib/mlpe.h +552 -0
  156. data/ext/alglib/mlptrain.cpp +1056 -0
  157. data/ext/alglib/mlptrain.h +283 -0
  158. data/ext/alglib/nearunityunit.cpp +91 -0
  159. data/ext/alglib/nearunityunit.h +17 -0
  160. data/ext/alglib/normaldistr.cpp +377 -0
  161. data/ext/alglib/normaldistr.h +175 -0
  162. data/ext/alglib/nsevd.cpp +1869 -0
  163. data/ext/alglib/nsevd.h +140 -0
  164. data/ext/alglib/pca.cpp +168 -0
  165. data/ext/alglib/pca.h +87 -0
  166. data/ext/alglib/poissondistr.cpp +143 -0
  167. data/ext/alglib/poissondistr.h +130 -0
  168. data/ext/alglib/polinterpolation.cpp +685 -0
  169. data/ext/alglib/polinterpolation.h +206 -0
  170. data/ext/alglib/psif.cpp +173 -0
  171. data/ext/alglib/psif.h +88 -0
  172. data/ext/alglib/qr.cpp +414 -0
  173. data/ext/alglib/qr.h +168 -0
  174. data/ext/alglib/ratinterpolation.cpp +134 -0
  175. data/ext/alglib/ratinterpolation.h +72 -0
  176. data/ext/alglib/rcond.cpp +705 -0
  177. data/ext/alglib/rcond.h +140 -0
  178. data/ext/alglib/reflections.cpp +504 -0
  179. data/ext/alglib/reflections.h +165 -0
  180. data/ext/alglib/rotations.cpp +473 -0
  181. data/ext/alglib/rotations.h +128 -0
  182. data/ext/alglib/rsolve.cpp +221 -0
  183. data/ext/alglib/rsolve.h +99 -0
  184. data/ext/alglib/sbisinv.cpp +217 -0
  185. data/ext/alglib/sbisinv.h +171 -0
  186. data/ext/alglib/sblas.cpp +185 -0
  187. data/ext/alglib/sblas.h +64 -0
  188. data/ext/alglib/schur.cpp +156 -0
  189. data/ext/alglib/schur.h +102 -0
  190. data/ext/alglib/sdet.cpp +193 -0
  191. data/ext/alglib/sdet.h +101 -0
  192. data/ext/alglib/sevd.cpp +116 -0
  193. data/ext/alglib/sevd.h +99 -0
  194. data/ext/alglib/sinverse.cpp +672 -0
  195. data/ext/alglib/sinverse.h +138 -0
  196. data/ext/alglib/spddet.cpp +138 -0
  197. data/ext/alglib/spddet.h +96 -0
  198. data/ext/alglib/spdgevd.cpp +842 -0
  199. data/ext/alglib/spdgevd.h +200 -0
  200. data/ext/alglib/spdinverse.cpp +509 -0
  201. data/ext/alglib/spdinverse.h +122 -0
  202. data/ext/alglib/spdrcond.cpp +421 -0
  203. data/ext/alglib/spdrcond.h +118 -0
  204. data/ext/alglib/spdsolve.cpp +275 -0
  205. data/ext/alglib/spdsolve.h +105 -0
  206. data/ext/alglib/spline2d.cpp +1192 -0
  207. data/ext/alglib/spline2d.h +301 -0
  208. data/ext/alglib/spline3.cpp +1264 -0
  209. data/ext/alglib/spline3.h +290 -0
  210. data/ext/alglib/srcond.cpp +595 -0
  211. data/ext/alglib/srcond.h +127 -0
  212. data/ext/alglib/ssolve.cpp +895 -0
  213. data/ext/alglib/ssolve.h +139 -0
  214. data/ext/alglib/stdafx.h +0 -0
  215. data/ext/alglib/stest.cpp +131 -0
  216. data/ext/alglib/stest.h +94 -0
  217. data/ext/alglib/studenttdistr.cpp +222 -0
  218. data/ext/alglib/studenttdistr.h +115 -0
  219. data/ext/alglib/studentttests.cpp +377 -0
  220. data/ext/alglib/studentttests.h +178 -0
  221. data/ext/alglib/svd.cpp +620 -0
  222. data/ext/alglib/svd.h +126 -0
  223. data/ext/alglib/tdbisinv.cpp +2608 -0
  224. data/ext/alglib/tdbisinv.h +228 -0
  225. data/ext/alglib/tdevd.cpp +1229 -0
  226. data/ext/alglib/tdevd.h +115 -0
  227. data/ext/alglib/tridiagonal.cpp +594 -0
  228. data/ext/alglib/tridiagonal.h +171 -0
  229. data/ext/alglib/trigintegrals.cpp +490 -0
  230. data/ext/alglib/trigintegrals.h +131 -0
  231. data/ext/alglib/trinverse.cpp +345 -0
  232. data/ext/alglib/trinverse.h +98 -0
  233. data/ext/alglib/trlinsolve.cpp +926 -0
  234. data/ext/alglib/trlinsolve.h +73 -0
  235. data/ext/alglib/tsort.cpp +405 -0
  236. data/ext/alglib/tsort.h +54 -0
  237. data/ext/alglib/variancetests.cpp +245 -0
  238. data/ext/alglib/variancetests.h +134 -0
  239. data/ext/alglib/wsr.cpp +6285 -0
  240. data/ext/alglib/wsr.h +96 -0
  241. data/ext/ap.i +97 -0
  242. data/ext/correlation.i +24 -0
  243. data/ext/extconf.rb +6 -0
  244. data/ext/logit.i +89 -0
  245. data/lib/alglib.rb +71 -0
  246. data/lib/alglib/correlation.rb +26 -0
  247. data/lib/alglib/linearregression.rb +63 -0
  248. data/lib/alglib/logit.rb +42 -0
  249. data/test/test_alglib.rb +52 -0
  250. data/test/test_correlation.rb +44 -0
  251. data/test/test_correlationtest.rb +45 -0
  252. data/test/test_linreg.rb +35 -0
  253. data/test/test_logit.rb +43 -0
  254. data/test/test_pca.rb +27 -0
  255. metadata +326 -0
@@ -0,0 +1,364 @@
1
+ <html>
2
+ <head>
3
+
4
+ <title>AP Library adapted for C++</title>
5
+ <style type="text/css">
6
+ <!--
7
+ h1 { font-family: Tahoma,sans-serif; font-size : larger; }
8
+ h2 { font-family: Arial,sans-serif; font-size : 11pt; }
9
+ h3 { font-family: Arial,sans-serif; font-size : 9pt; }
10
+ .cond { color:blue; }
11
+ .const { color:#222222; }
12
+ .func { color:#111111; }
13
+ -->
14
+ </style>
15
+ </head>
16
+ <body>
17
+
18
+ <h1>AP Library adapted for C++</h1>
19
+
20
+ <p align=justify>
21
+ The document describes an AP library adapted for C++. The AP library for C++ contains a basic set of mathematical functions and collection classes needed to run the programs from the <a href="http://www.alglib.net/">ALGLIB</a> website.
22
+ </p>
23
+
24
+ <h1>Compatibility</h1>
25
+
26
+ <p align=justify>
27
+ This library must be compatible with any C++ compiler.
28
+ </p>
29
+
30
+ <h1>Structure and Use</h1>
31
+
32
+ <p align=justify>
33
+ The library includes the only module <code>ap.cpp</code> (with header file <code>ap.h</code>). Just add it to your project.
34
+ </p>
35
+
36
+ <h1>AP Library Description</h1>
37
+
38
+ <font size=-1>
39
+ <a href="#intro">Introduction</a><br>
40
+ <a href="#conditionals">Conditional compilation settings</a><br>
41
+ <a href="#constants">Constants</a><br>
42
+ <a href="#functions">Functions</a><br>
43
+ <a href="#aperror">Class ap_error</a><br>
44
+ <a href="#arrays">Array classes</a><br>
45
+ <a href="#blas">Basic subroutines of linear algebra</a><br>
46
+ <a href="#complex">Class of complex numbers</a><br>
47
+ </font>
48
+
49
+ <a name="intro"><h1>Introduction</h1></a>
50
+
51
+ <p align=justify>
52
+ In the header file <code>ap.h</code> the namespace <code>ap</code> is defined. It must be taken into account that the names of functions, constants and classes listed further should be prefixed by <i>ap::</i>.
53
+ </p>
54
+
55
+ <a name="conditionals"><h1>Conditional Compilation Settings</h1></a>
56
+
57
+ <p align=justify>
58
+ <span class=cond>AP_WIN32</span><br>
59
+ This symbol (<b>if defined by user</b>) indicates that AP library is compiled under Win32. It allows library to use ABLAS (lightweight BLAS-like library with SSE2 support) if ABLAS is present on your system.
60
+ </p>
61
+
62
+ <p align=justify>
63
+ <span class=cond>AP_ASSERT</span><br> This symbol enables checking of the array boundaries. If it is set by the &quot;define&quot; directive, then at each addressing to the dynamic array elements, the transferred index is verified for its correctness. In case of error the <code>ap_error</code> exception is thrown. Checking the array boundaries makes the program more reliable, but slows down the program operation.
64
+ </p>
65
+
66
+ <p align=justify>
67
+ <span class=cond>NO_AP_ASSERT</span><br> This symbol disables checking of the array boundaries. If it is set by the &quot;define&quot; directive, then the index being outside the array boundaries is not checked when the dynamic array elements are addressed.
68
+ </p>
69
+
70
+ <p align=justify>
71
+ <span class=cond>UNSAFE_MEM_COPY</span><br> The &quot;define&quot; directive that sets this symbol is disabled. Do not activate it. The library contains no documentation concerning this symbol.
72
+ </p>
73
+
74
+ <a name="constants"><h1>Constants</h1></a>
75
+
76
+ <p align=justify>
77
+ <span class=const>machineepsilon</span><br> The constant represents the accuracy of machine operations, that is the minimum number for <code>1+machineepsilon&ne;1</code> in the given bit grid. The constant may be taken &quot;oversized&quot;, that is real accuracy can be even higher.
78
+ </p>
79
+
80
+ <p align=justify>
81
+ <span class=const>maxrealnumber</span><br> The constant represents the highest value of the positive real number, which could be represented on this machine. The constant may be taken &quot;oversized&quot;, that is real boundary can be even higher.
82
+ </p>
83
+
84
+ <p align=justify>
85
+ <span class=const>minrealnumber</span><br> The constant represents the lowest value of positive real number, which could be represented on this machine. The constant may be taken &quot;oversized&quot;, that is real boundary can be even lower.
86
+ </p>
87
+
88
+ <a name="functions"><h1>Functions</h1></a>
89
+
90
+ <p align=justify>
91
+ <span class=func><b>int</b> sign(<b>double</b> x)</span><br> Returns:<br> +1, if X&gt;0<br> -1, if X&lt;0<br> 0, if X=0
92
+ </p>
93
+
94
+ <p align=justify>
95
+ <span class=func><b>double</b> randomreal()</span><br> Returns a random real number from half-interval [0,1).
96
+ </p>
97
+
98
+ <p align=justify>
99
+ <span class=func><b>int</b> randominteger(<b>int</b> maxv) </span><br> Returns a random integer between 0 and maxv-1.
100
+ </p>
101
+
102
+ <p align=justify>
103
+ <span class=func><b>double</b> round(<b>double</b> x)</span><br> Returns the nearest integer to x. If x is right in the middle between two integers, then the function result depends on the implementation.
104
+ </p>
105
+
106
+ <p align=justify>
107
+ <span class=func><b>double</b> trunc(<b>double</b> x)</span><br> Truncates the fractional part of x.<br> trunc(1.3) = 1<br> trunc(-1.3)= -1
108
+ </p>
109
+
110
+ <p align=justify>
111
+ <span class=func><b>double</b> pi()</span><br> Returns the constant &pi;
112
+ </p>
113
+
114
+ <p align=justify>
115
+ <span class=func><b>double</b> sqr(<b>double</b> x)</span><br> Returns x<sup>2</sup>.
116
+ </p>
117
+
118
+ <p align=justify>
119
+ <span class=func><b>double</b> maxreal(<b>double</b> m1, <b>double</b> m2)</span><br> Returns the maximum of two real numbers.
120
+ </p>
121
+
122
+ <p align=justify>
123
+ <span class=func><b>double</b> minreal(<b>double</b> m1, <b>double</b> m2)</span><br> Returns the minimum of two real numbers.
124
+ </p>
125
+
126
+ <p align=justify>
127
+ <span class=func><b>int</b> maxint(<b>int</b> m1, <b>int</b> m2)</span><br> Returns the maximum of two integers.
128
+ </p>
129
+
130
+ <p align=justify>
131
+ <span class=func><b>int</b> minint(<b>int</b> m1, <b>int</b> m2)</span><br> Returns the minimum of two integers.
132
+ </p>
133
+
134
+ <a name="aperror"><h1>Class &quot;ap_error&quot;</h1></a>
135
+
136
+ <p align=justify>
137
+ This is a class of exception which is thrown when different errors occur in the AP library, for example - if the array index is found incorrect when the array boundaries check is enabled. The current version of the class contains no fields and doesn't allow to find the cause for the exception generated.
138
+ </p>
139
+
140
+ <a name="arrays"><h1>Array classes</h1></a>
141
+
142
+ <h2>Working with arrays</h2>
143
+
144
+ <p align=justify>
145
+ First we will discuss general principles of working with array classes, then describe the classes and their methods.
146
+ </p>
147
+
148
+ <p align=justify>
149
+ Classes of the standard library allow operations with matrixes and vectors (one-dimensional and two-dimensional arrays) of variable size and with variable numeration of elements, that is, the array numeration can start at any number, end at any number and change dynamically. Because the array classes are templates, the arrays of the same dimension have the same set of member functions. And as the member functions of arrays with different dimensions differ only by the number of arguments, there is little difference between two-dimensional and one-dimenstional arrays.
150
+ </p>
151
+
152
+ <p align=justify>
153
+ Working with an array starts with the array creation. You should distinguish the creation of array class instance and the memory allocation for the array. When creating the class instance, you can use constructor without any parameters, that creates an empty array without any elements, or you can use copy and assignment constructors that copy one array into another. In case the array is created by the default constructor, it contains no elements and an attempt to address them may cause the program failure. If, during the copy operation, the source array has no memory allocated for the array elements, destination array will contain no elements either. If the source array has memory allocated for its elements, destination array will allocate the same amount of memory and copy the elements there. That is, the copy operation yields into two independent arrays with indentical contents.
154
+ </p>
155
+
156
+ <p align=justify>
157
+ After an empty array has been created, you should allocate the memory for its elements, using the <code:>setbounds</code:> method The method parameters set upper and lower boundaries of the array indexes. The upper boundary should be not less than the lower one. When called, memory for corresponding number of elements is allocated. The content of the created array elements is not defined and no suppositions should be made about it. If the <code:>setbounds</code:> method is called for the array with already allocated memory, then, after changing its parameters, the newly allocated elements also become undefined and the old content is deleted.
158
+ </p>
159
+
160
+ <p align=justify>
161
+ To address the array elements, an overloaded <code:>operator()</code:> is used. That is, the code addressing the element of array <code:>a</code:> with indexes <code:>a(i,j,k)</code:> will look like <code:>a(i,j,k)</code:>. Below is given an example of factorial array calculation, illustrating the work with arrays.
162
+ </p>
163
+
164
+ <pre>
165
+ integer_1d_array factarr(<b>int</b> n)
166
+ {
167
+ integer_1d_array result;
168
+ result.setbounds(1,n);
169
+ result(1) = 1;
170
+ <b>for</b>(<b>int</b> i=2; i&lt;=n; i++)
171
+ result(i) = result(i-1)*i;
172
+ <b>return</b> result;
173
+ }
174
+ </pre>
175
+
176
+ <h2>Class &quot;template_1d_array&quot;</h2>
177
+
178
+ <p align=justify>
179
+ This class is a template of dynamical one-dimensional array with variable upper and lower boundaries. Based on this class, the following classes are constructed:
180
+ </p>
181
+
182
+ <pre>
183
+ <b>typedef</b> template_1d_array&lt;<b>int</b>&gt; integer_1d_array;
184
+ <b>typedef</b> template_1d_array&lt;<b>double</b>&gt; real_1d_array;
185
+ <b>typedef</b> template_1d_array&lt;<b>bool</b>&gt; boolean_1d_array;
186
+ <b>typedef</b> template_1d_array&lt;complex&gt; complex_1d_array;
187
+ </pre>
188
+
189
+ <h2>Class member functions</h2>
190
+
191
+ <p align=justify>
192
+ <span class=func>template_1d_array()</span><br> Constructor. Creates an empty array.
193
+ </p>
194
+
195
+ <p align=justify>
196
+ <span class=func>~template_1d_array()</span><br> Destructor. Frees memory, which had been allocated for the array.
197
+ </p>
198
+
199
+ <p align=justify>
200
+ <span class=func>template_1d_array(<b>const</b> template_1d_array &amp;rhs)</span><br> Copy constructor. Allocates the separate storage and copies source array content there.
201
+ </p>
202
+
203
+ <p align=justify>
204
+ <span class=func><b>const</b> template_1d_array&amp; <b>operator=</b>(<b>const</b> template_1d_array &amp;rhs)</span><br> Assignment constructor. Deletes destination array content, frees allocated memory, then allocates a separate storage and copies source array content there.
205
+ </p>
206
+
207
+ <p align=justify>
208
+ <span class=func>T&amp; operator()(<b>int</b> i)</span><br> Addressing the array element number i
209
+ </p>
210
+
211
+ <p align=justify>
212
+ <span class=func><b>void</b> setbounds(<b>int</b> iLow, <b>int</b> iHigh)</span><br> Memory allocation for the array . Deletes the array content, frees allocated memory, then allocates a separate storage for iHigh-iLow+1 elements.<br> The elements numeration in the new array starts with iLow and ends with iHigh The content of the new array is not defined.
213
+ </p>
214
+
215
+ <p align=justify>
216
+ <span class=func><b>void</b> setcontent(<b>int</b> iLow, <b>int</b> iHigh, <b>const</b> T *pContent)</span><br> The method is similar to the setbounds() method, but after allocating a memory for a destination array it copies the content of pContent[] there.
217
+ </p>
218
+
219
+ <p align=justify>
220
+ <span class=func>T* getcontent()</span><br> Gets pointer to the array. The data pointed by the returned pointer can be changed, and the array content will be changed as well.
221
+ </p>
222
+
223
+ <p align=justify>
224
+ <span class=func><b>int</b> getlowbound()<br><b>int</b> gethighbound()</span><br> Get lower and upper boundaries.
225
+ </p>
226
+
227
+ <p align=justify>
228
+ <span class=func>raw_vector&lt;T&gt; getvector(<b>int</b> iStart, <b>int</b> iEnd)</span><br> The method is used by the basic subroutines of linear algebra to get access to the internal memory of the array. The method returns an object, holding the pointer to a vector part (starting from the element with iStart index value and finishing with iEnd index value). If iEnd&lt;iStart, then an empty vector is considered to be set.
229
+ </p>
230
+
231
+ <p align=justify>
232
+ <span class=func>const_raw_vector&lt;T&gt; getvector(<b>int</b> iStart, <b>int</b> iEnd) <b>const</b></span><br> The method is used by the basic subroutines of linear algebra to get access to the internal memory of the array. The method returns an object, holding the pointer to a vector part (starting from the element with iStart index value and finishing with iEnd index value). If iEnd&lt;iStart, then an empty vector is considered to be set. The returned object is for read only.
233
+ </p>
234
+
235
+
236
+ <h2>Class &quot;template_2d_array&quot;</h2>
237
+
238
+ <p align=justify>
239
+ This class is a template of dynamical two-dimensional array with variable upper and lower boundaries. Based on this class, the following classes are constructed:
240
+ </p>
241
+
242
+ <pre>
243
+ <b>typedef</b> template_2d_array&lt;<b>int</b>&gt; integer_2d_array;
244
+ <b>typedef</b> template_2d_array&lt;<b>double</b>&gt; real_2d_array;
245
+ <b>typedef</b> template_2d_array&lt;<b>bool</b>&gt; boolean_2d_array;
246
+ <b>typedef</b> template_2d_array&lt;complex&gt; complex_2d_array;
247
+ </pre>
248
+
249
+ <h2>Class member functions</h2>
250
+
251
+ <p align=justify>
252
+ <span class=func>template_2d_array()</span><br> Constructor. Creates an empty array.
253
+ </p>
254
+
255
+ <p align=justify>
256
+ <span class=func>~template_2d_array()</span><br> Destructor. Frees memory, which had been allocated for the array.
257
+ </p>
258
+
259
+ <p align=justify>
260
+ <span class=func>template_2d_array(<b>const</b> template_2d_array &amp;rhs)</span><br> Copy constructor. Allocates the separate storage and copies source array content there.
261
+ </p>
262
+
263
+ <p align=justify>
264
+ <span class=func><b>const</b> template_2d_array&amp; <b>operator=</b>(<b>const</b> template_2d_array &amp;rhs)</span><br> Assignment constructor. Deletes destination array content, frees allocated memory, then allocates a separate storage and copies source array content there.
265
+ </p>
266
+
267
+ <p align=justify>
268
+ <span class=func>T&amp; operator()(<b>int</b> i1, <b>int</b> i2)</span><br> Addressing the array element with [i1,i2] index value.
269
+ </p>
270
+
271
+ <p align=justify>
272
+ <span class=func><b>void</b> setbounds(<b>int</b> iLow1, <b>int</b> iHigh1, <b>int</b> iLow2, <b>int</b> iHigh2)</span><br> Memory allocation for the array . Deletes the array content, frees allocated memory, then allocates a separate storage for (iHigh1-iLow1+1)*(iHigh2-iLow2+1) elements.<br> The elements numeration in the new array starts with iLow1 and finishes with iHigh1 for the first dimension, and similarly for the second dimension.<br> The content of the new array is not defined.
273
+ </p>
274
+
275
+ <p align=justify>
276
+ <span class=func><b>void</b> setcontent(<b>int</b> iLow1, <b>int</b> iHigh1, <b>int</b> iLow2, <b>int</b> iHigh2, <b>const</b> T *pContent)</span><br> The method is similar to the setbounds() method, but after allocating a memory for a destination array it copies the content of pContent[] there.<br> The pContent array contains two-dimensional array, written in line, that is, the first element is [iLow1, iLow2], then goes [iLow1, iLow2+1], and so on.<br>
277
+ </p>
278
+
279
+ <p align=justify>
280
+ <span class=func><b>int</b> getlowbound(<b>int</b> iBoundNum)<br><b>int</b> gethighbound(<b>int</b> iBoundNum)</span><br> Get lower and upper boundaries of one-dimensional array with number iBoundNum.
281
+ </p>
282
+
283
+ <p align=justify>
284
+ <span class=func>raw_vector<T> getcolumn(<b>int</b> iColumn, <b>int</b> iRowStart, <b>int</b> iRowEnd)<br> const_raw_vector<T> getcolumn(<b>int</b> iColumn, <b>int</b> iRowStart, <b>int</b> iRowEnd) <b>const</b><br></span> The methods are used by the basic subroutines of linear algebra to get access to the internal memory of the array. The methods return the object holding the pointer to the part of column iColumn (starting from the line iRowStart and finishing with the line iRowEnd). <br> The iColumn parameter must be the valid column number (that is be within the boundaries of the array). If iRowEnd&lt;iRowStart, then an empty column is considered to be set.
285
+ </p>
286
+
287
+ <p align=justify>
288
+ <span class=func>raw_vector<T> getrow(<b>int</b> iRow, <b>int</b> iColumnStart, <b>int</b> iColumnEnd)<br> const_raw_vector<T> getrow(<b>int</b> iRow, <b>int</b> iColumnStart, <b>int</b> iColumnEnd) <b>const</b><br></span> The methods are used by the basic subroutines of linear algebra to get access to the internal memory of the array. The methods return the object holding the pointer to the part of line iRow (starting from the column iColumnStart and finishing with the column iColumnEnd). <br> The iRow parameter must be the valid line number (that is be within the boundaries of the array). If iColumnEnd&lt;iColumnStart, then an empty line is considered to be set.
289
+ </p>
290
+
291
+ <a name="blas"><h1>Basic subroutines of linear algebra</h1></a>
292
+
293
+ <p align=justify>
294
+ Basic subroutines of linear algebra included into the AP library are close by their functions to the Level 1 BLAS, allowing to perform the simplest operations with vectors and with the matrix lines and columns.
295
+ </p>
296
+
297
+ <p align=justify>
298
+ Subroutines should be used in the following way. First you need to get an object of the <code>raw_vector</code> type or <code>const_raw_vector</code> type, pointing to the part of the matrix or array being processed using the methods <code>getcolumn</code>/<code>getrow</code> (for the matrix), or <code>getvector</code> (for the array). The object holds the pointer for the line (or column) start, the number of elements in the processed line (column), and the interval between the two adjacent elements. When using a standard scheme for matrixes storage in the memory (that is, by lines), the interval between the elements of one line equals 1, and the interval between the adjacent elements of one column equals the number of columns. The received object is transferred as argument to the corresponding subroutine, which performs operations on the matrix part pointed by the internal object pointer.
299
+ </p>
300
+
301
+ <p align=justify>
302
+ Below is given the list of basic subroutines of linear algebra, available in the AP library.
303
+ </p>
304
+
305
+ <p align=justify>
306
+ <span class=func>template&lt;<b>class</b> T&gt; T vdotproduct(const_raw_vector&lt;T&gt; v1, const_raw_vector&lt;T&gt; v2)</span><br> The subroutine calculates the scalar product of transferred vectors.
307
+ </p>
308
+
309
+ <p align=justify>
310
+ <span class=func>template&lt;<b>class</b> T&gt; <b>void</b> vmove(raw_vector&lt;T&gt; vdst, const_raw_vector&lt;T&gt; vsrc)<br> template&lt;<b>class</b> T&gt; <b>void</b> vmoveneg(raw_vector&lt;T&gt; vdst, const_raw_vector&lt;T&gt; vsrc)<br> template&lt;<b>class</b> T, <b>class</b> T2&gt; <b>void</b> vmove(raw_vector&lt;T&gt; vdst, const_raw_vector&lt;T&gt; vsrc, T2 alpha)<br></span> This subroutine set is used to copy one vector content to another vector using different methods: simple copy, copy multiplied by -1, copy multiplied by a number.
311
+ </p>
312
+
313
+ <p align=justify>
314
+ <span class=func>template&lt;<b>class</b> T&gt; <b>void</b> vadd(raw_vector&lt;T&gt; vdst, const_raw_vector&lt;T&gt; vsrc)<br> template&lt;<b>class</b> T, <b>class</b> T2&gt; <b>void</b> vadd(raw_vector&lt;T&gt; vdst, const_raw_vector&lt;T&gt; vsrc, T2 alpha)<br></span> This subroutine set is used to add one vector to another using different methods: simple addition or addition multiplied by a number.
315
+ </p>
316
+
317
+ <p align=justify>
318
+ <span class=func>template&lt;<b>class</b> T&gt; <b>void</b> vsub(raw_vector&lt;T&gt; vdst, const_raw_vector&lt;T&gt; vsrc)<br> template&lt;<b>class</b> T, <b>class</b> T2&gt; <b>void</b> vsub(raw_vector&lt;T&gt; vdst, const_raw_vector&lt;T&gt; vsrc, T2 alpha)<br></span> This subroutine set is used to subtract one vector from another using different methods: simple subtraction or subtraction multiplied by a number.
319
+ </p>
320
+
321
+ <p align=justify>
322
+ <span class=func>template&lt;<b>class</b> T, <b>class</b> T2&gt; <b>void</b> vmul(raw_vector&lt;T&gt; vdst, T2 alpha)</span><br> Multiplies vector by a number and stores the result in the same place.
323
+ </p>
324
+
325
+ <h2>Alternative syntax</h2>
326
+
327
+ <p align=justify>
328
+ If both operands are vectors/rows with interval between the elements equals 1 and length equals N, alternative syntax can be used.
329
+ </p>
330
+
331
+ <p align=justify>
332
+ <span class=func>
333
+ template&lt;<b>class</b> T&gt; T vdotproduct(<b>const</b> T *v1, <b>const</b> T *v2, <b>int</b> N)<br>
334
+ template&lt;<b>class</b> T&gt; <b>void</b> vmove(T *vdst, <b>const</b> T *vsrc, <b>int</b> N)<br>
335
+ template&lt;<b>class</b> T&gt; <b>void</b> vmoveneg(T *vdst, <b>const</b> T *vsrc, <b>int</b> N)<br>
336
+ template&lt;<b>class</b> T, <b>class</b> T2&gt; <b>void</b> vmove(T *vdst, <b>const</b> T *vsrc, <b>int</b> N, T2 alpha)<br>
337
+ template&lt;<b>class</b> T&gt; <b>void</b> vadd(T *vdst, <b>const</b> T *vsrc, <b>int</b> N)<br>
338
+ template&lt;<b>class</b> T, <b>class</b> T2&gt; <b>void</b> vadd(T *vdst, <b>const</b> T *vsrc, <b>int</b> N, T2 alpha)<br>
339
+ template&lt;<b>class</b> T&gt; <b>void</b> vsub(T *vdst, <b>const</b> T *vsrc, <b>int</b> N)<br>
340
+ template&lt;<b>class</b> T, <b>class</b> T2&gt; <b>void</b> vsub(T *vdst, <b>const</b> T *vsrc, <b>int</b> N, T2 alpha)<br>
341
+ template&lt;<b>class</b> T, <b>class</b> T2> <b>void</b> vmul(T *vdst, <b>int</b> N, T2 alpha)
342
+ </span>
343
+ </p>
344
+
345
+ <a name="complex"><h1>Class of complex numbers</h1></a>
346
+
347
+ <p align=justify>
348
+ AP library includes the <code>ap::complex</code> class that allows operations with compex numbers. Access to real and imaginary parts of complex number is implemented through the public fields <code>x</code> and <code>y</code>. Arithmetical operations are supported, the same as with embedded data types, by overloading of operations: addition, subtraction, multiplication and division. Addition, subtraction and multiplication are performed by a usual way (i.e., according to their definition which can be found in any textdook in algebra), division is performed using so called &quot;safe&quot; algorithm that could never cause overflow when calculating intermediate results. The library also includes several functions performing elementary operations with complex numbers.
349
+ </p>
350
+
351
+ <p align=justify>
352
+ <span class=func><b>const</b> double abscomplex(<b>const</b> complex &amp;z)</span><br> Returns the modulus of complex number z. It should be noted that the modulus calculation is performed using so called &quot;safe&quot; algorithm, that could never cause overflow when calculating intermediate results.
353
+ </p>
354
+
355
+ <p align=justify>
356
+ <span class=func><b>const</b> complex conj(<b>const</b> complex &amp;z)</span><br> Returns complex conjugate to z.
357
+ </p>
358
+
359
+ <p align=justify>
360
+ <span class=func><b>const</b> complex csqr(<b>const</b> complex &amp;z)</span><br> Returns the square of z.
361
+ </p>
362
+
363
+ </body>
364
+ </html>
@@ -0,0 +1,666 @@
1
+ /********************************************************************
2
+ AP Library version 1.3
3
+
4
+ Copyright (c) 2003-2007, Sergey Bochkanov (ALGLIB project).
5
+ See www.alglib.net or alglib.sources.ru for details.
6
+
7
+ Redistribution and use in source and binary forms, with or without
8
+ modification, are permitted provided that the following conditions are
9
+ met:
10
+
11
+ - Redistributions of source code must retain the above copyright
12
+ notice, this list of conditions and the following disclaimer.
13
+
14
+ - Redistributions in binary form must reproduce the above copyright
15
+ notice, this list of conditions and the following disclaimer listed
16
+ in this license in the documentation and/or other materials
17
+ provided with the distribution.
18
+
19
+ - Neither the name of the copyright holders nor the names of its
20
+ contributors may be used to endorse or promote products derived from
21
+ this software without specific prior written permission.
22
+
23
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27
+ OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28
+ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31
+ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34
+ ********************************************************************/
35
+
36
+ #ifndef AP_H
37
+ #define AP_H
38
+
39
+ #include <stdlib.h>
40
+ #include <string>
41
+ #include <cstring>
42
+ #include <math.h>
43
+
44
+ #ifdef __BORLANDC__
45
+ #include <list.h>
46
+ #include <vector.h>
47
+ #else
48
+ #include <list>
49
+ #include <vector>
50
+ #endif
51
+
52
+ /********************************************************************
53
+ Array bounds check
54
+ ********************************************************************/
55
+ #define AP_ASSERT
56
+
57
+ #ifndef AP_ASSERT //
58
+ #define NO_AP_ASSERT // This code avoids definition of the
59
+ #endif // both AP_ASSERT and NO_AP_ASSERT symbols
60
+ #ifdef NO_AP_ASSERT //
61
+ #ifdef AP_ASSERT //
62
+ #undef NO_AP_ASSERT //
63
+ #endif //
64
+ #endif //
65
+
66
+
67
+ /********************************************************************
68
+ Current environment.
69
+ ********************************************************************/
70
+ #ifndef AP_WIN32
71
+ #ifndef AP_UNKNOWN
72
+ #define AP_UNKNOWN
73
+ #endif
74
+ #endif
75
+ #ifdef AP_WIN32
76
+ #ifdef AP_UNKNOWN
77
+ #error Multiple environments are declared!
78
+ #endif
79
+ #endif
80
+
81
+ /********************************************************************
82
+ This symbol is used for debugging. Do not define it and do not remove
83
+ comments.
84
+ ********************************************************************/
85
+ //#define UNSAFE_MEM_COPY
86
+
87
+
88
+ /********************************************************************
89
+ Namespace of a standard library AlgoPascal.
90
+ ********************************************************************/
91
+ namespace ap
92
+ {
93
+
94
+ /********************************************************************
95
+ Service routines:
96
+ amalloc - allocates an aligned block of size bytes
97
+ afree - frees block allocated by amalloc
98
+ vlen - just alias for n2-n1+1
99
+ ********************************************************************/
100
+ void* amalloc(size_t size, size_t alignment);
101
+ void afree(void *block);
102
+ int vlen(int n1, int n2);
103
+
104
+ /********************************************************************
105
+ Exception class.
106
+ ********************************************************************/
107
+ class ap_error
108
+ {
109
+ public:
110
+ ap_error(){};
111
+ ap_error(const char *s){ msg = s; };
112
+
113
+ std::string msg;
114
+
115
+ static void make_assertion(bool bClause)
116
+ { if(!bClause) throw ap_error(); };
117
+ static void make_assertion(bool bClause, const char *msg)
118
+ { if(!bClause) throw ap_error(msg); };
119
+ private:
120
+ };
121
+
122
+ /********************************************************************
123
+ Class defining a complex number with double precision.
124
+ ********************************************************************/
125
+ class complex;
126
+
127
+ class complex
128
+ {
129
+ public:
130
+ complex():x(0.0),y(0.0){};
131
+ complex(const double &_x):x(_x),y(0.0){};
132
+ complex(const double &_x, const double &_y):x(_x),y(_y){};
133
+ complex(const complex &z):x(z.x),y(z.y){};
134
+
135
+ complex& operator= (const double& v){ x = v; y = 0.0; return *this; };
136
+ complex& operator+=(const double& v){ x += v; return *this; };
137
+ complex& operator-=(const double& v){ x -= v; return *this; };
138
+ complex& operator*=(const double& v){ x *= v; y *= v; return *this; };
139
+ complex& operator/=(const double& v){ x /= v; y /= v; return *this; };
140
+
141
+ complex& operator= (const complex& z){ x = z.x; y = z.y; return *this; };
142
+ complex& operator+=(const complex& z){ x += z.x; y += z.y; return *this; };
143
+ complex& operator-=(const complex& z){ x -= z.x; y -= z.y; return *this; };
144
+ complex& operator*=(const complex& z){ double t = x*z.x-y*z.y; y = x*z.y+y*z.x; x = t; return *this; };
145
+ complex& operator/=(const complex& z)
146
+ {
147
+ ap::complex result;
148
+ double e;
149
+ double f;
150
+ if( fabs(z.y)<fabs(z.x) )
151
+ {
152
+ e = z.y/z.x;
153
+ f = z.x+z.y*e;
154
+ result.x = (z.x+z.y*e)/f;
155
+ result.y = (z.y-z.x*e)/f;
156
+ }
157
+ else
158
+ {
159
+ e = z.x/z.y;
160
+ f = z.y+z.x*e;
161
+ result.x = (z.y+z.x*e)/f;
162
+ result.y = (-z.x+z.y*e)/f;
163
+ }
164
+ *this = result;
165
+ return *this;
166
+ };
167
+
168
+ double x, y;
169
+ };
170
+
171
+ const complex operator/(const complex& lhs, const complex& rhs);
172
+ const bool operator==(const complex& lhs, const complex& rhs);
173
+ const bool operator!=(const complex& lhs, const complex& rhs);
174
+ const complex operator+(const complex& lhs);
175
+ const complex operator-(const complex& lhs);
176
+ const complex operator+(const complex& lhs, const complex& rhs);
177
+ const complex operator+(const complex& lhs, const double& rhs);
178
+ const complex operator+(const double& lhs, const complex& rhs);
179
+ const complex operator-(const complex& lhs, const complex& rhs);
180
+ const complex operator-(const complex& lhs, const double& rhs);
181
+ const complex operator-(const double& lhs, const complex& rhs);
182
+ const complex operator*(const complex& lhs, const complex& rhs);
183
+ const complex operator*(const complex& lhs, const double& rhs);
184
+ const complex operator*(const double& lhs, const complex& rhs);
185
+ const complex operator/(const complex& lhs, const complex& rhs);
186
+ const complex operator/(const double& lhs, const complex& rhs);
187
+ const complex operator/(const complex& lhs, const double& rhs);
188
+ const double abscomplex(const complex &z);
189
+ const complex conj(const complex &z);
190
+ const complex csqr(const complex &z);
191
+
192
+
193
+ /********************************************************************
194
+ Templates for vector operations
195
+ ********************************************************************/
196
+ #include "apvt.h"
197
+
198
+ /********************************************************************
199
+ BLAS functions
200
+ ********************************************************************/
201
+ double vdotproduct(const double *v1, const double *v2, int N);
202
+ complex vdotproduct(const complex *v1, const complex *v2, int N);
203
+
204
+ void vmove(double *vdst, const double* vsrc, int N);
205
+ void vmove(complex *vdst, const complex* vsrc, int N);
206
+
207
+ void vmoveneg(double *vdst, const double *vsrc, int N);
208
+ void vmoveneg(complex *vdst, const complex *vsrc, int N);
209
+
210
+ void vmove(double *vdst, const double *vsrc, int N, double alpha);
211
+ void vmove(complex *vdst, const complex *vsrc, int N, double alpha);
212
+ void vmove(complex *vdst, const complex *vsrc, int N, complex alpha);
213
+
214
+ void vadd(double *vdst, const double *vsrc, int N);
215
+ void vadd(complex *vdst, const complex *vsrc, int N);
216
+
217
+ void vadd(double *vdst, const double *vsrc, int N, double alpha);
218
+ void vadd(complex *vdst, const complex *vsrc, int N, double alpha);
219
+ void vadd(complex *vdst, const complex *vsrc, int N, complex alpha);
220
+
221
+ void vsub(double *vdst, const double *vsrc, int N);
222
+ void vsub(complex *vdst, const complex *vsrc, int N);
223
+
224
+ void vsub(double *vdst, const double *vsrc, int N, double alpha);
225
+ void vsub(complex *vdst, const complex *vsrc, int N, double alpha);
226
+ void vsub(complex *vdst, const complex *vsrc, int N, complex alpha);
227
+
228
+ void vmul(double *vdst, int N, double alpha);
229
+ void vmul(complex *vdst, int N, double alpha);
230
+ void vmul(complex *vdst, int N, complex alpha);
231
+
232
+
233
+ /********************************************************************
234
+ Template of a dynamical one-dimensional array
235
+ ********************************************************************/
236
+ template<class T, bool Aligned = false>
237
+ class template_1d_array
238
+ {
239
+ public:
240
+ template_1d_array()
241
+ {
242
+ m_Vec=0;
243
+ m_iVecSize = 0;
244
+ m_iLow = 0;
245
+ m_iHigh = -1;
246
+ };
247
+
248
+ ~template_1d_array()
249
+ {
250
+ if(m_Vec)
251
+ {
252
+ if( Aligned )
253
+ ap::afree(m_Vec);
254
+ else
255
+ delete[] m_Vec;
256
+ }
257
+ };
258
+
259
+ template_1d_array(const template_1d_array &rhs)
260
+ {
261
+ m_Vec=0;
262
+ m_iVecSize = 0;
263
+ m_iLow = 0;
264
+ m_iHigh = -1;
265
+ if( rhs.m_iVecSize!=0 )
266
+ setcontent(rhs.m_iLow, rhs.m_iHigh, rhs.getcontent());
267
+ };
268
+
269
+
270
+ const template_1d_array& operator=(const template_1d_array &rhs)
271
+ {
272
+ if( this==&rhs )
273
+ return *this;
274
+
275
+ if( rhs.m_iVecSize!=0 )
276
+ setcontent(rhs.m_iLow, rhs.m_iHigh, rhs.getcontent());
277
+ else
278
+ {
279
+ m_Vec=0;
280
+ m_iVecSize = 0;
281
+ m_iLow = 0;
282
+ m_iHigh = -1;
283
+ }
284
+ return *this;
285
+ };
286
+
287
+
288
+ const T& operator()(int i) const
289
+ {
290
+ #ifndef NO_AP_ASSERT
291
+ ap_error::make_assertion(i>=m_iLow && i<=m_iHigh);
292
+ #endif
293
+ return m_Vec[ i-m_iLow ];
294
+ };
295
+
296
+
297
+ T& operator()(int i)
298
+ {
299
+ #ifndef NO_AP_ASSERT
300
+ ap_error::make_assertion(i>=m_iLow && i<=m_iHigh);
301
+ #endif
302
+ return m_Vec[ i-m_iLow ];
303
+ };
304
+
305
+
306
+ void setbounds( int iLow, int iHigh )
307
+ {
308
+ if(m_Vec)
309
+ {
310
+ if( Aligned )
311
+ ap::afree(m_Vec);
312
+ else
313
+ delete[] m_Vec;
314
+ }
315
+ m_iLow = iLow;
316
+ m_iHigh = iHigh;
317
+ m_iVecSize = iHigh-iLow+1;
318
+ if( Aligned )
319
+ m_Vec = (T*)ap::amalloc(m_iVecSize*sizeof(T), 16);
320
+ else
321
+ m_Vec = new T[m_iVecSize];
322
+ };
323
+
324
+
325
+ void setlength(int iLen)
326
+ {
327
+ setbounds(0, iLen-1);
328
+ }
329
+
330
+
331
+ void setcontent( int iLow, int iHigh, const T *pContent )
332
+ {
333
+ setbounds(iLow, iHigh);
334
+ for(int i=0; i<m_iVecSize; i++)
335
+ m_Vec[i] = pContent[i];
336
+ };
337
+
338
+
339
+ T* getcontent()
340
+ {
341
+ return m_Vec;
342
+ };
343
+
344
+ const T* getcontent() const
345
+ {
346
+ return m_Vec;
347
+ };
348
+
349
+
350
+ int getlowbound(int iBoundNum = 0) const
351
+ {
352
+ return m_iLow;
353
+ };
354
+
355
+
356
+ int gethighbound(int iBoundNum = 0) const
357
+ {
358
+ return m_iHigh;
359
+ };
360
+
361
+ raw_vector<T> getvector(int iStart, int iEnd)
362
+ {
363
+ if( iStart>iEnd || wrongIdx(iStart) || wrongIdx(iEnd) )
364
+ return raw_vector<T>(0, 0, 1);
365
+ else
366
+ return raw_vector<T>(m_Vec+iStart-m_iLow, iEnd-iStart+1, 1);
367
+ };
368
+
369
+
370
+ const_raw_vector<T> getvector(int iStart, int iEnd) const
371
+ {
372
+ if( iStart>iEnd || wrongIdx(iStart) || wrongIdx(iEnd) )
373
+ return const_raw_vector<T>(0, 0, 1);
374
+ else
375
+ return const_raw_vector<T>(m_Vec+iStart-m_iLow, iEnd-iStart+1, 1);
376
+ };
377
+ private:
378
+ bool wrongIdx(int i) const { return i<m_iLow || i>m_iHigh; };
379
+
380
+ T *m_Vec;
381
+ long m_iVecSize;
382
+ long m_iLow, m_iHigh;
383
+ };
384
+
385
+
386
+
387
+ /********************************************************************
388
+ Template of a dynamical two-dimensional array
389
+ ********************************************************************/
390
+ template<class T, bool Aligned = false>
391
+ class template_2d_array
392
+ {
393
+ public:
394
+ template_2d_array()
395
+ {
396
+ m_Vec=0;
397
+ m_iVecSize=0;
398
+ m_iLow1 = 0;
399
+ m_iHigh1 = -1;
400
+ m_iLow2 = 0;
401
+ m_iHigh2 = -1;
402
+ };
403
+
404
+ ~template_2d_array()
405
+ {
406
+ if(m_Vec)
407
+ {
408
+ if( Aligned )
409
+ ap::afree(m_Vec);
410
+ else
411
+ delete[] m_Vec;
412
+ }
413
+ };
414
+
415
+ template_2d_array(const template_2d_array &rhs)
416
+ {
417
+ m_Vec=0;
418
+ m_iVecSize=0;
419
+ m_iLow1 = 0;
420
+ m_iHigh1 = -1;
421
+ m_iLow2 = 0;
422
+ m_iHigh2 = -1;
423
+ if( rhs.m_iVecSize!=0 )
424
+ {
425
+ setbounds(rhs.m_iLow1, rhs.m_iHigh1, rhs.m_iLow2, rhs.m_iHigh2);
426
+ for(int i=m_iLow1; i<=m_iHigh1; i++)
427
+ for(int j=m_iLow2; j<=m_iHigh2; j++)
428
+ operator()(i,j) = rhs(i,j);
429
+ //vmove(&(operator()(i,m_iLow2)), &(rhs(i,m_iLow2)), m_iHigh2-m_iLow2+1);
430
+ }
431
+ };
432
+ const template_2d_array& operator=(const template_2d_array &rhs)
433
+ {
434
+ if( this==&rhs )
435
+ return *this;
436
+
437
+ if( rhs.m_iVecSize!=0 )
438
+ {
439
+ setbounds(rhs.m_iLow1, rhs.m_iHigh1, rhs.m_iLow2, rhs.m_iHigh2);
440
+ for(int i=m_iLow1; i<=m_iHigh1; i++)
441
+ for(int j=m_iLow2; j<=m_iHigh2; j++)
442
+ operator()(i,j) = rhs(i,j);
443
+ //vmove(&(operator()(i,m_iLow2)), &(rhs(i,m_iLow2)), m_iHigh2-m_iLow2+1);
444
+ }
445
+ else
446
+ {
447
+ if(m_Vec)
448
+ {
449
+ if( Aligned )
450
+ ap::afree(m_Vec);
451
+ else
452
+ delete[] m_Vec;
453
+ }
454
+ m_Vec=0;
455
+ m_iVecSize=0;
456
+ m_iLow1 = 0;
457
+ m_iHigh1 = -1;
458
+ m_iLow2 = 0;
459
+ m_iHigh2 = -1;
460
+ }
461
+ return *this;
462
+ };
463
+
464
+ const T& operator()(int i1, int i2) const
465
+ {
466
+ #ifndef NO_AP_ASSERT
467
+ ap_error::make_assertion(i1>=m_iLow1 && i1<=m_iHigh1);
468
+ ap_error::make_assertion(i2>=m_iLow2 && i2<=m_iHigh2);
469
+ #endif
470
+ return m_Vec[ m_iConstOffset + i2 +i1*m_iLinearMember];
471
+ };
472
+
473
+ T& operator()(int i1, int i2)
474
+ {
475
+ #ifndef NO_AP_ASSERT
476
+ ap_error::make_assertion(i1>=m_iLow1 && i1<=m_iHigh1);
477
+ ap_error::make_assertion(i2>=m_iLow2 && i2<=m_iHigh2);
478
+ #endif
479
+ return m_Vec[ m_iConstOffset + i2 +i1*m_iLinearMember];
480
+ };
481
+
482
+ void setbounds( int iLow1, int iHigh1, int iLow2, int iHigh2 )
483
+ {
484
+ if(m_Vec)
485
+ {
486
+ if( Aligned )
487
+ ap::afree(m_Vec);
488
+ else
489
+ delete[] m_Vec;
490
+ }
491
+ int n1 = iHigh1-iLow1+1;
492
+ int n2 = iHigh2-iLow2+1;
493
+ m_iVecSize = n1*n2;
494
+ if( Aligned )
495
+ {
496
+ //if( n2%2!=0 )
497
+ while( (n2*sizeof(T))%16!=0 )
498
+ {
499
+ n2++;
500
+ m_iVecSize += n1;
501
+ }
502
+ m_Vec = (T*)ap::amalloc(m_iVecSize*sizeof(T), 16);
503
+ }
504
+ else
505
+ m_Vec = new T[m_iVecSize];
506
+ m_iLow1 = iLow1;
507
+ m_iHigh1 = iHigh1;
508
+ m_iLow2 = iLow2;
509
+ m_iHigh2 = iHigh2;
510
+ m_iConstOffset = -m_iLow2-m_iLow1*n2;
511
+ m_iLinearMember = n2;
512
+ };
513
+
514
+ void setlength(int iLen1, int iLen2)
515
+ {
516
+ setbounds(0, iLen1-1, 0, iLen2-1);
517
+ }
518
+
519
+ void setcontent( int iLow1, int iHigh1, int iLow2, int iHigh2, const T *pContent )
520
+ {
521
+ setbounds(iLow1, iHigh1, iLow2, iHigh2);
522
+ for(int i=m_iLow1; i<=m_iHigh1; i++, pContent += m_iHigh2-m_iLow2+1)
523
+ for(int j=m_iLow2; j<=m_iHigh2; j++)
524
+ operator()(i,j) = pContent[j-m_iLow2];
525
+ //vmove(&(operator()(i,m_iLow2)), pContent, m_iHigh2-m_iLow2+1);
526
+ };
527
+
528
+ int getlowbound(int iBoundNum) const
529
+ {
530
+ return iBoundNum==1 ? m_iLow1 : m_iLow2;
531
+ };
532
+
533
+ int gethighbound(int iBoundNum) const
534
+ {
535
+ return iBoundNum==1 ? m_iHigh1 : m_iHigh2;
536
+ };
537
+
538
+ raw_vector<T> getcolumn(int iColumn, int iRowStart, int iRowEnd)
539
+ {
540
+ if( (iRowStart>iRowEnd) || wrongColumn(iColumn) || wrongRow(iRowStart) ||wrongRow(iRowEnd) )
541
+ return raw_vector<T>(0, 0, 1);
542
+ else
543
+ return raw_vector<T>(&((*this)(iRowStart, iColumn)), iRowEnd-iRowStart+1, m_iLinearMember);
544
+ };
545
+
546
+ raw_vector<T> getrow(int iRow, int iColumnStart, int iColumnEnd)
547
+ {
548
+ if( (iColumnStart>iColumnEnd) || wrongRow(iRow) || wrongColumn(iColumnStart) || wrongColumn(iColumnEnd))
549
+ return raw_vector<T>(0, 0, 1);
550
+ else
551
+ return raw_vector<T>(&((*this)(iRow, iColumnStart)), iColumnEnd-iColumnStart+1, 1);
552
+ };
553
+
554
+ const_raw_vector<T> getcolumn(int iColumn, int iRowStart, int iRowEnd) const
555
+ {
556
+ if( (iRowStart>iRowEnd) || wrongColumn(iColumn) || wrongRow(iRowStart) ||wrongRow(iRowEnd) )
557
+ return const_raw_vector<T>(0, 0, 1);
558
+ else
559
+ return const_raw_vector<T>(&((*this)(iRowStart, iColumn)), iRowEnd-iRowStart+1, m_iLinearMember);
560
+ };
561
+
562
+ const_raw_vector<T> getrow(int iRow, int iColumnStart, int iColumnEnd) const
563
+ {
564
+ if( (iColumnStart>iColumnEnd) || wrongRow(iRow) || wrongColumn(iColumnStart) || wrongColumn(iColumnEnd))
565
+ return const_raw_vector<T>(0, 0, 1);
566
+ else
567
+ return const_raw_vector<T>(&((*this)(iRow, iColumnStart)), iColumnEnd-iColumnStart+1, 1);
568
+ };
569
+ private:
570
+ bool wrongRow(int i) const { return i<m_iLow1 || i>m_iHigh1; };
571
+ bool wrongColumn(int j) const { return j<m_iLow2 || j>m_iHigh2; };
572
+
573
+ T *m_Vec;
574
+ long m_iVecSize;
575
+ long m_iLow1, m_iLow2, m_iHigh1, m_iHigh2;
576
+ long m_iConstOffset, m_iLinearMember;
577
+ };
578
+
579
+
580
+ typedef template_1d_array<int> integer_1d_array;
581
+ typedef template_1d_array<double,true> real_1d_array;
582
+ typedef template_1d_array<complex> complex_1d_array;
583
+ typedef template_1d_array<bool> boolean_1d_array;
584
+
585
+ typedef template_2d_array<int> integer_2d_array;
586
+ typedef template_2d_array<double,true> real_2d_array;
587
+ typedef template_2d_array<complex> complex_2d_array;
588
+ typedef template_2d_array<bool> boolean_2d_array;
589
+
590
+
591
+ /********************************************************************
592
+ dataset information.
593
+
594
+ can store regression dataset, classification dataset, or non-labeled
595
+ task:
596
+ * nout==0 means non-labeled task (clustering, for example)
597
+ * nout>0 && nclasses==0 means regression task
598
+ * nout>0 && nclasses>0 means classification task
599
+ ********************************************************************/
600
+ class dataset
601
+ {
602
+ public:
603
+ dataset():nin(0), nout(0), nclasses(0), trnsize(0), valsize(0), tstsize(0), totalsize(0){};
604
+
605
+ int nin, nout, nclasses;
606
+
607
+ int trnsize;
608
+ int valsize;
609
+ int tstsize;
610
+ int totalsize;
611
+
612
+ ap::real_2d_array trn;
613
+ ap::real_2d_array val;
614
+ ap::real_2d_array tst;
615
+ ap::real_2d_array all;
616
+ };
617
+
618
+ bool opendataset(std::string file, dataset *pdataset);
619
+
620
+ //
621
+ // internal functions
622
+ //
623
+ std::string strtolower(const std::string &s);
624
+ bool readstrings(std::string file, std::list<std::string> *pOutput);
625
+ bool readstrings(std::string file, std::list<std::string> *pOutput, std::string comment);
626
+ void explodestring(std::string s, char sep, std::vector<std::string> *pOutput);
627
+ std::string xtrim(std::string s);
628
+
629
+ /********************************************************************
630
+ reverse communication state
631
+ ********************************************************************/
632
+ struct rcommstate
633
+ {
634
+ int stage;
635
+ ap::integer_1d_array ia;
636
+ ap::boolean_1d_array ba;
637
+ ap::real_1d_array ra;
638
+ ap::complex_1d_array ca;
639
+ };
640
+
641
+
642
+ /********************************************************************
643
+ Constants and functions introduced for compatibility with AlgoPascal
644
+ ********************************************************************/
645
+ extern const double machineepsilon;
646
+ extern const double maxrealnumber;
647
+ extern const double minrealnumber;
648
+
649
+ int sign(double x);
650
+ double randomreal();
651
+ int randominteger(int maxv);
652
+ int round(double x);
653
+ int trunc(double x);
654
+ int ifloor(double x);
655
+ int iceil(double x);
656
+ double pi();
657
+ double sqr(double x);
658
+ int maxint(int m1, int m2);
659
+ int minint(int m1, int m2);
660
+ double maxreal(double m1, double m2);
661
+ double minreal(double m1, double m2);
662
+
663
+ }//namespace ap
664
+
665
+
666
+ #endif