PageRenderTime 46ms CodeModel.GetById 14ms RepoModel.GetById 1ms app.codeStats 0ms

/Utilities/otbossim/src/ossim/matrix/newmat2.cpp

https://bitbucket.org/olahlou/otb
C++ | 642 lines | 521 code | 80 blank | 41 comment | 247 complexity | 51de66722ebd9c5d4fdfdbb32fbff095 MD5 | raw file
Possible License(s): LGPL-3.0, Apache-2.0, LGPL-2.0, CC-BY-SA-3.0, BSD-3-Clause, LGPL-2.1
  1. //$$ newmat2.cpp Matrix row and column operations
  2. // Copyright (C) 1991,2,3,4: R B Davies
  3. #define WANT_MATH
  4. #include <cmath>
  5. #include <ossim/matrix/include.h>
  6. #include <ossim/matrix/newmat.h>
  7. #include <ossim/matrix/newmatrc.h>
  8. #ifdef use_namespace
  9. namespace NEWMAT {
  10. #endif
  11. #ifdef DO_REPORT
  12. #define REPORT { static ExeCounter ExeCount(__LINE__,2); ++ExeCount; }
  13. #else
  14. #define REPORT {}
  15. #endif
  16. //#define MONITOR(what,storage,store) { cout << what << " " << storage << " at " << (long)store << "\n"; }
  17. #define MONITOR(what,store,storage) {}
  18. /************************** Matrix Row/Col functions ************************/
  19. void MatrixRowCol::Add(const MatrixRowCol& mrc)
  20. {
  21. // THIS += mrc
  22. REPORT
  23. int f = mrc.skip; int l = f + mrc.storage; int lx = skip + storage;
  24. if (f < skip) f = skip; if (l > lx) l = lx; l -= f;
  25. if (l<=0) return;
  26. Real* elx=data+(f-skip); Real* el=mrc.data+(f-mrc.skip);
  27. while (l--) *elx++ += *el++;
  28. }
  29. void MatrixRowCol::AddScaled(const MatrixRowCol& mrc, Real x)
  30. {
  31. REPORT
  32. // THIS += (mrc * x)
  33. int f = mrc.skip; int l = f + mrc.storage; int lx = skip + storage;
  34. if (f < skip) f = skip; if (l > lx) l = lx; l -= f;
  35. if (l<=0) return;
  36. Real* elx=data+(f-skip); Real* el=mrc.data+(f-mrc.skip);
  37. while (l--) *elx++ += *el++ * x;
  38. }
  39. void MatrixRowCol::Sub(const MatrixRowCol& mrc)
  40. {
  41. REPORT
  42. // THIS -= mrc
  43. int f = mrc.skip; int l = f + mrc.storage; int lx = skip + storage;
  44. if (f < skip) f = skip; if (l > lx) l = lx; l -= f;
  45. if (l<=0) return;
  46. Real* elx=data+(f-skip); Real* el=mrc.data+(f-mrc.skip);
  47. while (l--) *elx++ -= *el++;
  48. }
  49. void MatrixRowCol::Inject(const MatrixRowCol& mrc)
  50. // copy stored elements only
  51. {
  52. REPORT
  53. int f = mrc.skip; int l = f + mrc.storage; int lx = skip + storage;
  54. if (f < skip) f = skip; if (l > lx) l = lx; l -= f;
  55. if (l<=0) return;
  56. Real* elx=data+(f-skip); Real* ely=mrc.data+(f-mrc.skip);
  57. while (l--) *elx++ = *ely++;
  58. }
  59. Real DotProd(const MatrixRowCol& mrc1, const MatrixRowCol& mrc2)
  60. {
  61. REPORT // not accessed
  62. int f = mrc1.skip; int f2 = mrc2.skip;
  63. int l = f + mrc1.storage; int l2 = f2 + mrc2.storage;
  64. if (f < f2) f = f2; if (l > l2) l = l2; l -= f;
  65. if (l<=0) return 0.0;
  66. Real* el1=mrc1.data+(f-mrc1.skip); Real* el2=mrc2.data+(f-mrc2.skip);
  67. Real sum = 0.0;
  68. while (l--) sum += *el1++ * *el2++;
  69. return sum;
  70. }
  71. void MatrixRowCol::Add(const MatrixRowCol& mrc1, const MatrixRowCol& mrc2)
  72. {
  73. // THIS = mrc1 + mrc2
  74. int f = skip; int l = skip + storage;
  75. int f1 = mrc1.skip; int l1 = f1 + mrc1.storage;
  76. if (f1<f) f1=f; if (l1>l) l1=l;
  77. int f2 = mrc2.skip; int l2 = f2 + mrc2.storage;
  78. if (f2<f) f2=f; if (l2>l) l2=l;
  79. Real* el = data + (f-skip);
  80. Real* el1 = mrc1.data+(f1-mrc1.skip); Real* el2 = mrc2.data+(f2-mrc2.skip);
  81. if (f1<f2)
  82. {
  83. int i = f1-f; while (i--) *el++ = 0.0;
  84. if (l1<=f2) // disjoint
  85. {
  86. REPORT // not accessed
  87. i = l1-f1; while (i--) *el++ = *el1++;
  88. i = f2-l1; while (i--) *el++ = 0.0;
  89. i = l2-f2; while (i--) *el++ = *el2++;
  90. i = l-l2; while (i--) *el++ = 0.0;
  91. }
  92. else
  93. {
  94. i = f2-f1; while (i--) *el++ = *el1++;
  95. if (l1<=l2)
  96. {
  97. REPORT
  98. i = l1-f2; while (i--) *el++ = *el1++ + *el2++;
  99. i = l2-l1; while (i--) *el++ = *el2++;
  100. i = l-l2; while (i--) *el++ = 0.0;
  101. }
  102. else
  103. {
  104. REPORT
  105. i = l2-f2; while (i--) *el++ = *el1++ + *el2++;
  106. i = l1-l2; while (i--) *el++ = *el1++;
  107. i = l-l1; while (i--) *el++ = 0.0;
  108. }
  109. }
  110. }
  111. else
  112. {
  113. int i = f2-f; while (i--) *el++ = 0.0;
  114. if (l2<=f1) // disjoint
  115. {
  116. REPORT // not accessed
  117. i = l2-f2; while (i--) *el++ = *el2++;
  118. i = f1-l2; while (i--) *el++ = 0.0;
  119. i = l1-f1; while (i--) *el++ = *el1++;
  120. i = l-l1; while (i--) *el++ = 0.0;
  121. }
  122. else
  123. {
  124. i = f1-f2; while (i--) *el++ = *el2++;
  125. if (l2<=l1)
  126. {
  127. REPORT
  128. i = l2-f1; while (i--) *el++ = *el1++ + *el2++;
  129. i = l1-l2; while (i--) *el++ = *el1++;
  130. i = l-l1; while (i--) *el++ = 0.0;
  131. }
  132. else
  133. {
  134. REPORT
  135. i = l1-f1; while (i--) *el++ = *el1++ + *el2++;
  136. i = l2-l1; while (i--) *el++ = *el2++;
  137. i = l-l2; while (i--) *el++ = 0.0;
  138. }
  139. }
  140. }
  141. }
  142. void MatrixRowCol::Sub(const MatrixRowCol& mrc1, const MatrixRowCol& mrc2)
  143. {
  144. // THIS = mrc1 - mrc2
  145. int f = skip; int l = skip + storage;
  146. int f1 = mrc1.skip; int l1 = f1 + mrc1.storage;
  147. if (f1<f) f1=f; if (l1>l) l1=l;
  148. int f2 = mrc2.skip; int l2 = f2 + mrc2.storage;
  149. if (f2<f) f2=f; if (l2>l) l2=l;
  150. Real* el = data + (f-skip);
  151. Real* el1 = mrc1.data+(f1-mrc1.skip); Real* el2 = mrc2.data+(f2-mrc2.skip);
  152. if (f1<f2)
  153. {
  154. int i = f1-f; while (i--) *el++ = 0.0;
  155. if (l1<=f2) // disjoint
  156. {
  157. REPORT // not accessed
  158. i = l1-f1; while (i--) *el++ = *el1++;
  159. i = f2-l1; while (i--) *el++ = 0.0;
  160. i = l2-f2; while (i--) *el++ = - *el2++;
  161. i = l-l2; while (i--) *el++ = 0.0;
  162. }
  163. else
  164. {
  165. i = f2-f1; while (i--) *el++ = *el1++;
  166. if (l1<=l2)
  167. {
  168. REPORT
  169. i = l1-f2; while (i--) *el++ = *el1++ - *el2++;
  170. i = l2-l1; while (i--) *el++ = - *el2++;
  171. i = l-l2; while (i--) *el++ = 0.0;
  172. }
  173. else
  174. {
  175. REPORT
  176. i = l2-f2; while (i--) *el++ = *el1++ - *el2++;
  177. i = l1-l2; while (i--) *el++ = *el1++;
  178. i = l-l1; while (i--) *el++ = 0.0;
  179. }
  180. }
  181. }
  182. else
  183. {
  184. int i = f2-f; while (i--) *el++ = 0.0;
  185. if (l2<=f1) // disjoint
  186. {
  187. REPORT // not accessed
  188. i = l2-f2; while (i--) *el++ = - *el2++;
  189. i = f1-l2; while (i--) *el++ = 0.0;
  190. i = l1-f1; while (i--) *el++ = *el1++;
  191. i = l-l1; while (i--) *el++ = 0.0;
  192. }
  193. else
  194. {
  195. i = f1-f2; while (i--) *el++ = - *el2++;
  196. if (l2<=l1)
  197. {
  198. REPORT
  199. i = l2-f1; while (i--) *el++ = *el1++ - *el2++;
  200. i = l1-l2; while (i--) *el++ = *el1++;
  201. i = l-l1; while (i--) *el++ = 0.0;
  202. }
  203. else
  204. {
  205. REPORT
  206. i = l1-f1; while (i--) *el++ = *el1++ - *el2++;
  207. i = l2-l1; while (i--) *el++ = - *el2++;
  208. i = l-l2; while (i--) *el++ = 0.0;
  209. }
  210. }
  211. }
  212. }
  213. void MatrixRowCol::Add(const MatrixRowCol& mrc1, Real x)
  214. {
  215. // THIS = mrc1 + x
  216. REPORT
  217. if (!storage) return;
  218. int f = mrc1.skip; int l = f + mrc1.storage; int lx = skip + storage;
  219. if (f < skip) { f = skip; if (l < f) l = f; }
  220. if (l > lx) { l = lx; if (f > lx) f = lx; }
  221. Real* elx = data; Real* ely = mrc1.data+(f-mrc1.skip);
  222. int l1 = f-skip; while (l1--) *elx++ = x;
  223. l1 = l-f; while (l1--) *elx++ = *ely++ + x;
  224. lx -= l; while (lx--) *elx++ = x;
  225. }
  226. void MatrixRowCol::NegAdd(const MatrixRowCol& mrc1, Real x)
  227. {
  228. // THIS = x - mrc1
  229. REPORT
  230. if (!storage) return;
  231. int f = mrc1.skip; int l = f + mrc1.storage; int lx = skip + storage;
  232. if (f < skip) { f = skip; if (l < f) l = f; }
  233. if (l > lx) { l = lx; if (f > lx) f = lx; }
  234. Real* elx = data; Real* ely = mrc1.data+(f-mrc1.skip);
  235. int l1 = f-skip; while (l1--) *elx++ = x;
  236. l1 = l-f; while (l1--) *elx++ = x - *ely++;
  237. lx -= l; while (lx--) *elx++ = x;
  238. }
  239. void MatrixRowCol::RevSub(const MatrixRowCol& mrc1)
  240. {
  241. // THIS = mrc - THIS
  242. REPORT
  243. if (!storage) return;
  244. int f = mrc1.skip; int l = f + mrc1.storage; int lx = skip + storage;
  245. if (f < skip) { f = skip; if (l < f) l = f; }
  246. if (l > lx) { l = lx; if (f > lx) f = lx; }
  247. Real* elx = data; Real* ely = mrc1.data+(f-mrc1.skip);
  248. int l1 = f-skip; while (l1--) { *elx = - *elx; elx++; }
  249. l1 = l-f; while (l1--) { *elx = *ely++ - *elx; elx++; }
  250. lx -= l; while (lx--) { *elx = - *elx; elx++; }
  251. }
  252. void MatrixRowCol::ConCat(const MatrixRowCol& mrc1, const MatrixRowCol& mrc2)
  253. {
  254. // THIS = mrc1 | mrc2
  255. REPORT
  256. int f1 = mrc1.skip; int l1 = f1 + mrc1.storage; int lx = skip + storage;
  257. if (f1 < skip) { f1 = skip; if (l1 < f1) l1 = f1; }
  258. if (l1 > lx) { l1 = lx; if (f1 > lx) f1 = lx; }
  259. Real* elx = data;
  260. int i = f1-skip; while (i--) *elx++ =0.0;
  261. i = l1-f1;
  262. if (i) // in case f1 would take ely out of range
  263. { Real* ely = mrc1.data+(f1-mrc1.skip); while (i--) *elx++ = *ely++; }
  264. int f2 = mrc2.skip; int l2 = f2 + mrc2.storage; i = mrc1.length;
  265. int skipx = l1 - i; lx -= i; // addresses rel to second seg, maybe -ve
  266. if (f2 < skipx) { f2 = skipx; if (l2 < f2) l2 = f2; }
  267. if (l2 > lx) { l2 = lx; if (f2 > lx) f2 = lx; }
  268. i = f2-skipx; while (i--) *elx++ = 0.0;
  269. i = l2-f2;
  270. if (i) // in case f2 would take ely out of range
  271. { Real* ely = mrc2.data+(f2-mrc2.skip); while (i--) *elx++ = *ely++; }
  272. lx -= l2; while (lx--) *elx++ = 0.0;
  273. }
  274. void MatrixRowCol::Multiply(const MatrixRowCol& mrc1)
  275. // element by element multiply into
  276. {
  277. REPORT
  278. if (!storage) return;
  279. int f = mrc1.skip; int l = f + mrc1.storage; int lx = skip + storage;
  280. if (f < skip) { f = skip; if (l < f) l = f; }
  281. if (l > lx) { l = lx; if (f > lx) f = lx; }
  282. Real* elx = data; Real* ely = mrc1.data+(f-mrc1.skip);
  283. int l1 = f-skip; while (l1--) *elx++ = 0;
  284. l1 = l-f; while (l1--) *elx++ *= *ely++;
  285. lx -= l; while (lx--) *elx++ = 0;
  286. }
  287. void MatrixRowCol::Multiply(const MatrixRowCol& mrc1, const MatrixRowCol& mrc2)
  288. // element by element multiply
  289. {
  290. int f = skip; int l = skip + storage;
  291. int f1 = mrc1.skip; int l1 = f1 + mrc1.storage;
  292. if (f1<f) f1=f; if (l1>l) l1=l;
  293. int f2 = mrc2.skip; int l2 = f2 + mrc2.storage;
  294. if (f2<f) f2=f; if (l2>l) l2=l;
  295. Real* el = data + (f-skip); int i;
  296. if (f1<f2) f1 = f2; if (l1>l2) l1 = l2;
  297. if (l1<=f1) { REPORT i = l-f; while (i--) *el++ = 0.0; } // disjoint
  298. else
  299. {
  300. REPORT
  301. Real* el1 = mrc1.data+(f1-mrc1.skip);
  302. Real* el2 = mrc2.data+(f1-mrc2.skip);
  303. i = f1-f ; while (i--) *el++ = 0.0;
  304. i = l1-f1; while (i--) *el++ = *el1++ * *el2++;
  305. i = l-l1; while (i--) *el++ = 0.0;
  306. }
  307. }
  308. void MatrixRowCol::KP(const MatrixRowCol& mrc1, const MatrixRowCol& mrc2)
  309. // row for Kronecker product
  310. {
  311. int f = skip; int s = storage; Real* el = data; int i;
  312. i = mrc1.skip * mrc2.length;
  313. if (i > f)
  314. {
  315. i -= f; f = 0; if (i > s) { i = s; s = 0; } else s -= i;
  316. while (i--) *el++ = 0.0;
  317. if (s == 0) return;
  318. }
  319. else f -= i;
  320. i = mrc1.storage; Real* el1 = mrc1.data;
  321. int mrc2_skip = mrc2.skip; int mrc2_storage = mrc2.storage;
  322. int mrc2_length = mrc2.length;
  323. int mrc2_remain = mrc2_length - mrc2_skip - mrc2_storage;
  324. while (i--)
  325. {
  326. int j; Real* el2 = mrc2.data; Real vel1 = *el1;
  327. if (f == 0 && mrc2_length <= s)
  328. {
  329. j = mrc2_skip; s -= j; while (j--) *el++ = 0.0;
  330. j = mrc2_storage; s -= j; while (j--) *el++ = vel1 * *el2++;
  331. j = mrc2_remain; s -= j; while (j--) *el++ = 0.0;
  332. }
  333. else if (f >= mrc2_length) f -= mrc2_length;
  334. else
  335. {
  336. j = mrc2_skip;
  337. if (j > f)
  338. {
  339. j -= f; f = 0; if (j > s) { j = s; s = 0; } else s -= j;
  340. while (j--) *el++ = 0.0;
  341. }
  342. else f -= j;
  343. j = mrc2_storage;
  344. if (j > f)
  345. {
  346. j -= f; el2 += f; f = 0; if (j > s) { j = s; s = 0; } else s -= j;
  347. while (j--) *el++ = vel1 * *el2++;
  348. }
  349. else f -= j;
  350. j = mrc2_remain;
  351. if (j > f)
  352. {
  353. j -= f; f = 0; if (j > s) { j = s; s = 0; } else s -= j;
  354. while (j--) *el++ = 0.0;
  355. }
  356. else f -= j;
  357. }
  358. if (s == 0) return;
  359. ++el1;
  360. }
  361. i = (mrc1.length - mrc1.skip - mrc1.storage) * mrc2.length;
  362. if (i > f)
  363. {
  364. i -= f; if (i > s) i = s;
  365. while (i--) *el++ = 0.0;
  366. }
  367. }
  368. void MatrixRowCol::Copy(const MatrixRowCol& mrc1)
  369. {
  370. // THIS = mrc1
  371. REPORT
  372. if (!storage) return;
  373. int f = mrc1.skip; int l = f + mrc1.storage; int lx = skip + storage;
  374. if (f < skip) { f = skip; if (l < f) l = f; }
  375. if (l > lx) { l = lx; if (f > lx) f = lx; }
  376. Real* elx = data; Real* ely = 0;
  377. if (l-f) ely = mrc1.data+(f-mrc1.skip);
  378. int l1 = f-skip; while (l1--) *elx++ = 0.0;
  379. l1 = l-f; while (l1--) *elx++ = *ely++;
  380. lx -= l; while (lx--) *elx++ = 0.0;
  381. }
  382. void MatrixRowCol::CopyCheck(const MatrixRowCol& mrc1)
  383. // Throw an exception if this would lead to a loss of data
  384. {
  385. REPORT
  386. if (!storage) return;
  387. int f = mrc1.skip; int l = f + mrc1.storage; int lx = skip + storage;
  388. if (f < skip || l > lx) Throw(ProgramException("Illegal Conversion"));
  389. Real* elx = data; Real* ely = mrc1.data+(f-mrc1.skip);
  390. int l1 = f-skip; while (l1--) *elx++ = 0.0;
  391. l1 = l-f; while (l1--) *elx++ = *ely++;
  392. lx -= l; while (lx--) *elx++ = 0.0;
  393. }
  394. void MatrixRowCol::Check(const MatrixRowCol& mrc1)
  395. // Throw an exception if +=, -=, copy etc would lead to a loss of data
  396. {
  397. REPORT
  398. int f = mrc1.skip; int l = f + mrc1.storage; int lx = skip + storage;
  399. if (f < skip || l > lx) Throw(ProgramException("Illegal Conversion"));
  400. }
  401. void MatrixRowCol::Check()
  402. // Throw an exception if +=, -= of constant would lead to a loss of data
  403. // that is: check full row is present
  404. // may not be appropriate for symmetric matrices
  405. {
  406. REPORT
  407. if (skip!=0 || storage!=length)
  408. Throw(ProgramException("Illegal Conversion"));
  409. }
  410. void MatrixRowCol::Negate(const MatrixRowCol& mrc1)
  411. {
  412. // THIS = -mrc1
  413. REPORT
  414. if (!storage) return;
  415. int f = mrc1.skip; int l = f + mrc1.storage; int lx = skip + storage;
  416. if (f < skip) { f = skip; if (l < f) l = f; }
  417. if (l > lx) { l = lx; if (f > lx) f = lx; }
  418. Real* elx = data; Real* ely = mrc1.data+(f-mrc1.skip);
  419. int l1 = f-skip; while (l1--) *elx++ = 0.0;
  420. l1 = l-f; while (l1--) *elx++ = - *ely++;
  421. lx -= l; while (lx--) *elx++ = 0.0;
  422. }
  423. void MatrixRowCol::Multiply(const MatrixRowCol& mrc1, Real s)
  424. {
  425. // THIS = mrc1 * s
  426. REPORT
  427. if (!storage) return;
  428. int f = mrc1.skip; int l = f + mrc1.storage; int lx = skip + storage;
  429. if (f < skip) { f = skip; if (l < f) l = f; }
  430. if (l > lx) { l = lx; if (f > lx) f = lx; }
  431. Real* elx = data; Real* ely = mrc1.data+(f-mrc1.skip);
  432. int l1 = f-skip; while (l1--) *elx++ = 0.0;
  433. l1 = l-f; while (l1--) *elx++ = *ely++ * s;
  434. lx -= l; while (lx--) *elx++ = 0.0;
  435. }
  436. void DiagonalMatrix::Solver(MatrixColX& mrc, const MatrixColX& mrc1)
  437. {
  438. // mrc = mrc / mrc1 (elementwise)
  439. REPORT
  440. int f = mrc1.skip; int f0 = mrc.skip;
  441. int l = f + mrc1.storage; int lx = f0 + mrc.storage;
  442. if (f < f0) { f = f0; if (l < f) l = f; }
  443. if (l > lx) { l = lx; if (f > lx) f = lx; }
  444. Real* elx = mrc.data; Real* eld = store+f;
  445. int l1 = f-f0; while (l1--) *elx++ = 0.0;
  446. l1 = l-f; while (l1--) *elx++ /= *eld++;
  447. lx -= l; while (lx--) *elx++ = 0.0;
  448. // Solver makes sure input and output point to same memory
  449. }
  450. void IdentityMatrix::Solver(MatrixColX& mrc, const MatrixColX& mrc1)
  451. {
  452. // mrc = mrc / mrc1 (elementwise)
  453. REPORT
  454. int f = mrc1.skip; int f0 = mrc.skip;
  455. int l = f + mrc1.storage; int lx = f0 + mrc.storage;
  456. if (f < f0) { f = f0; if (l < f) l = f; }
  457. if (l > lx) { l = lx; if (f > lx) f = lx; }
  458. Real* elx = mrc.data; Real eldv = *store;
  459. int l1 = f-f0; while (l1--) *elx++ = 0.0;
  460. l1 = l-f; while (l1--) *elx++ /= eldv;
  461. lx -= l; while (lx--) *elx++ = 0.0;
  462. // Solver makes sure input and output point to same memory
  463. }
  464. void MatrixRowCol::Copy(const Real*& r)
  465. {
  466. // THIS = *r
  467. REPORT
  468. Real* elx = data; const Real* ely = r+skip; r += length;
  469. int l = storage; while (l--) *elx++ = *ely++;
  470. }
  471. void MatrixRowCol::Copy(const int*& r)
  472. {
  473. // THIS = *r
  474. REPORT
  475. Real* elx = data; const int* ely = r+skip; r += length;
  476. int l = storage; while (l--) *elx++ = *ely++;
  477. }
  478. void MatrixRowCol::Copy(Real r)
  479. {
  480. // THIS = r
  481. REPORT Real* elx = data; int l = storage; while (l--) *elx++ = r;
  482. }
  483. void MatrixRowCol::Zero()
  484. {
  485. // THIS = 0
  486. REPORT Real* elx = data; int l = storage; while (l--) *elx++ = 0;
  487. }
  488. void MatrixRowCol::Multiply(Real r)
  489. {
  490. // THIS *= r
  491. REPORT Real* elx = data; int l = storage; while (l--) *elx++ *= r;
  492. }
  493. void MatrixRowCol::Add(Real r)
  494. {
  495. // THIS += r
  496. REPORT
  497. Real* elx = data; int l = storage; while (l--) *elx++ += r;
  498. }
  499. Real MatrixRowCol::SumAbsoluteValue()
  500. {
  501. REPORT
  502. Real sum = 0.0; Real* elx = data; int l = storage;
  503. while (l--) sum += std::fabs(*elx++);
  504. return sum;
  505. }
  506. // max absolute value of r and elements of row/col
  507. // we use <= or >= in all of these so we are sure of getting
  508. // r reset at least once.
  509. Real MatrixRowCol::MaximumAbsoluteValue1(Real r, int& i)
  510. {
  511. REPORT
  512. Real* elx = data; int l = storage; int li = -1;
  513. while (l--) { Real f = std::fabs(*elx++); if (r <= f) { r = f; li = l; } }
  514. i = (li >= 0) ? storage - li + skip : 0;
  515. return r;
  516. }
  517. // min absolute value of r and elements of row/col
  518. Real MatrixRowCol::MinimumAbsoluteValue1(Real r, int& i)
  519. {
  520. REPORT
  521. Real* elx = data; int l = storage; int li = -1;
  522. while (l--) { Real f = std::fabs(*elx++); if (r >= f) { r = f; li = l; } }
  523. i = (li >= 0) ? storage - li + skip : 0;
  524. return r;
  525. }
  526. // max value of r and elements of row/col
  527. Real MatrixRowCol::Maximum1(Real r, int& i)
  528. {
  529. REPORT
  530. Real* elx = data; int l = storage; int li = -1;
  531. while (l--) { Real f = *elx++; if (r <= f) { r = f; li = l; } }
  532. i = (li >= 0) ? storage - li + skip : 0;
  533. return r;
  534. }
  535. // min value of r and elements of row/col
  536. Real MatrixRowCol::Minimum1(Real r, int& i)
  537. {
  538. REPORT
  539. Real* elx = data; int l = storage; int li = -1;
  540. while (l--) { Real f = *elx++; if (r >= f) { r = f; li = l; } }
  541. i = (li >= 0) ? storage - li + skip : 0;
  542. return r;
  543. }
  544. Real MatrixRowCol::Sum()
  545. {
  546. REPORT
  547. Real sum = 0.0; Real* elx = data; int l = storage;
  548. while (l--) sum += *elx++;
  549. return sum;
  550. }
  551. void MatrixRowCol::SubRowCol(MatrixRowCol& mrc, int skip1, int l1) const
  552. {
  553. mrc.length = l1; int d = skip - skip1;
  554. if (d<0) { mrc.skip = 0; mrc.data = data - d; }
  555. else { mrc.skip = d; mrc.data = data; }
  556. d = skip + storage - skip1;
  557. d = ((l1 < d) ? l1 : d) - mrc.skip; mrc.storage = (d < 0) ? 0 : d;
  558. mrc.cw = 0;
  559. }
  560. #ifdef use_namespace
  561. }
  562. #endif