PageRenderTime 56ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/mpqc-2.3.1/src/lib/math/scmat/block.cc

#
C++ | 1125 lines | 905 code | 155 blank | 65 comment | 55 complexity | bdcb8a13cf7171c252f3197137b066ca MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.0
  1. //
  2. // block.cc
  3. //
  4. // Copyright (C) 1996 Limit Point Systems, Inc.
  5. //
  6. // Author: Curtis Janssen <cljanss@limitpt.com>
  7. // Maintainer: LPS
  8. //
  9. // This file is part of the SC Toolkit.
  10. //
  11. // The SC Toolkit is free software; you can redistribute it and/or modify
  12. // it under the terms of the GNU Library General Public License as published by
  13. // the Free Software Foundation; either version 2, or (at your option)
  14. // any later version.
  15. //
  16. // The SC Toolkit is distributed in the hope that it will be useful,
  17. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. // GNU Library General Public License for more details.
  20. //
  21. // You should have received a copy of the GNU Library General Public License
  22. // along with the SC Toolkit; see the file COPYING.LIB. If not, write to
  23. // the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  24. //
  25. // The U.S. Government is granted a limited license as per AL 91-7.
  26. //
  27. #ifdef __GNUC__
  28. #pragma implementation
  29. #endif
  30. #include <iostream>
  31. #include <string.h>
  32. #include <util/state/stateio.h>
  33. #include <math/scmat/block.h>
  34. #include <math/scmat/blkiter.h>
  35. #include <math/scmat/elemop.h>
  36. using namespace std;
  37. using namespace sc;
  38. /////////////////////////////////////////////////////////////////////////////
  39. // SCMatrixBlock member functions
  40. static ClassDesc SCMatrixBlock_cd(
  41. typeid(SCMatrixBlock),"SCMatrixBlock",1,"public SavableState",
  42. 0, 0, 0);
  43. SCMatrixBlock::SCMatrixBlock()
  44. {
  45. blocki = blockj = -1;
  46. }
  47. SCMatrixBlock::SCMatrixBlock(StateIn&s):
  48. SavableState(s)
  49. {
  50. s.get(blocki);
  51. s.get(blockj);
  52. }
  53. void
  54. SCMatrixBlock::save_data_state(StateOut&s)
  55. {
  56. s.put(blocki);
  57. s.put(blockj);
  58. }
  59. SCMatrixBlock::~SCMatrixBlock()
  60. {
  61. }
  62. SCMatrixBlock *
  63. SCMatrixBlock::deepcopy() const
  64. {
  65. ExEnv::errn() << "SCMatrixBlock of type " << class_name()
  66. << " cannot be deep copied" << endl;
  67. abort();
  68. return 0;
  69. }
  70. double *
  71. SCMatrixBlock::dat()
  72. {
  73. ExEnv::errn() << "SCMatrixBlock of type " << class_name()
  74. << " cannot provide internal data" << endl;
  75. abort();
  76. return 0;
  77. }
  78. int
  79. SCMatrixBlock::ndat() const
  80. {
  81. ExEnv::errn() << "SCMatrixBlock of type " << class_name()
  82. << " cannot provide size of internal data" << endl;
  83. abort();
  84. return 0;
  85. }
  86. /////////////////////////////////////////////////////////////////////////////
  87. // SCMatrixBlockListLink member functions
  88. SCMatrixBlockListLink::SCMatrixBlockListLink(SCMatrixBlock* b,
  89. SCMatrixBlockListLink* l)
  90. {
  91. block(b);
  92. next(l);
  93. }
  94. SCMatrixBlockListLink::~SCMatrixBlockListLink()
  95. {
  96. if (_block) _block->dereference();
  97. if (_block->nreference() == 0) delete _block;
  98. for (SCMatrixBlockListLink *nexti, *i=_next; i; i = nexti) {
  99. nexti = i->_next;
  100. i->_next = 0;
  101. delete i;
  102. }
  103. }
  104. void
  105. SCMatrixBlockListLink::block(SCMatrixBlock* b)
  106. {
  107. _block = b;
  108. if (_block) _block->reference();
  109. }
  110. /////////////////////////////////////////////////////////////////////////////
  111. // SCMatrixBlockList member functions
  112. static ClassDesc SCMatrixBlockList_cd(
  113. typeid(SCMatrixBlockList),"SCMatrixBlockList",1,"public SavableState",
  114. 0, 0, create<SCMatrixBlockList>);
  115. SCMatrixBlockList::SCMatrixBlockList()
  116. {
  117. _begin = 0;
  118. }
  119. SCMatrixBlockList::SCMatrixBlockList(StateIn& s):
  120. SavableState(s)
  121. {
  122. int i, count;
  123. Ref<SCMatrixBlock> b;
  124. s.get(count);
  125. _begin = 0;
  126. for (i=0; i<count; i++) {
  127. b << SavableState::restore_state(s);
  128. append(b);
  129. }
  130. }
  131. SCMatrixBlockList::~SCMatrixBlockList()
  132. {
  133. if (_begin) delete _begin;
  134. }
  135. void
  136. SCMatrixBlockList::save_data_state(StateOut&s)
  137. {
  138. int count = 0;
  139. SCMatrixBlockListIter i;
  140. for (i = begin(); i != end(); i++) count++;
  141. s.put(count);
  142. for (i = begin(); i != end(); i++) {
  143. i.block()->save_state(s);
  144. }
  145. }
  146. void
  147. SCMatrixBlockList::insert(SCMatrixBlock* b)
  148. {
  149. _begin = new SCMatrixBlockListLink(b, _begin);
  150. }
  151. void
  152. SCMatrixBlockList::append(SCMatrixBlock* b)
  153. {
  154. if (_begin == 0) {
  155. _begin = new SCMatrixBlockListLink(b);
  156. }
  157. else {
  158. SCMatrixBlockListLink* i;
  159. for (i = _begin; i->next() != 0; i = i->next());
  160. i->next(new SCMatrixBlockListLink(b));
  161. }
  162. }
  163. SCMatrixBlockList *
  164. SCMatrixBlockList::deepcopy()
  165. {
  166. SCMatrixBlockListIter i;
  167. SCMatrixBlockList *ret = new SCMatrixBlockList();
  168. for (i=begin(); i!=end(); i++) {
  169. ret->append(i.block()->deepcopy());
  170. }
  171. return ret;
  172. }
  173. /////////////////////////////////////////////////////////////////////////////
  174. // SCMatrixRectBlock member functions
  175. static ClassDesc SCMatrixRectBlock_cd(
  176. typeid(SCMatrixRectBlock),"SCMatrixRectBlock",1,"public SCMatrixBlock",
  177. 0, 0, create<SCMatrixRectBlock>);
  178. SCMatrixRectBlock::SCMatrixRectBlock(int is, int ie, int js, int je):
  179. istart(is),
  180. jstart(js),
  181. iend(ie),
  182. jend(je)
  183. {
  184. data = new double[(ie-is)*(je-js)];
  185. }
  186. SCMatrixRectBlock::SCMatrixRectBlock(StateIn&s):
  187. SCMatrixBlock(s)
  188. {
  189. s.get(istart);
  190. s.get(jstart);
  191. s.get(iend);
  192. s.get(jend);
  193. s.get(data);
  194. }
  195. void
  196. SCMatrixRectBlock::save_data_state(StateOut&s)
  197. {
  198. SCMatrixBlock::save_data_state(s);
  199. s.put(istart);
  200. s.put(jstart);
  201. s.put(iend);
  202. s.put(jend);
  203. s.put(data,(iend-istart)*(jend-jstart));
  204. }
  205. SCMatrixBlock *
  206. SCMatrixRectBlock::deepcopy() const
  207. {
  208. SCMatrixRectBlock *ret = new SCMatrixRectBlock(istart,iend,jstart,jend);
  209. ret->blocki = blocki;
  210. ret->blockj = blockj;
  211. memcpy(ret->data, data, sizeof(double)*ndat());
  212. return ret;
  213. }
  214. double *
  215. SCMatrixRectBlock::dat()
  216. {
  217. return data;
  218. }
  219. int
  220. SCMatrixRectBlock::ndat() const
  221. {
  222. return (iend-istart)*(jend-jstart);
  223. }
  224. SCMatrixRectBlock::~SCMatrixRectBlock()
  225. {
  226. delete[] data;
  227. }
  228. void
  229. SCMatrixRectBlock::process(SCElementOp*op)
  230. {
  231. SCMatrixRectBlockIter i(this);
  232. op->process(i);
  233. }
  234. void
  235. SCMatrixRectBlock::process(SCElementOp2*op,
  236. SCMatrixBlock* b)
  237. {
  238. SCMatrixRectBlockIter i(this);
  239. SCMatrixRectBlockIter j((SCMatrixRectBlock*)b);
  240. op->process(i,j);
  241. }
  242. void
  243. SCMatrixRectBlock::process(SCElementOp3*op,
  244. SCMatrixBlock* b1, SCMatrixBlock* b2)
  245. {
  246. SCMatrixRectBlockIter i(this);
  247. SCMatrixRectBlockIter j((SCMatrixRectBlock*)b1);
  248. SCMatrixRectBlockIter k((SCMatrixRectBlock*)b2);
  249. op->process(i,j,k);
  250. }
  251. /////////////////////////////////////////////////////////////////////////////
  252. // SCMatrixRectSubBlock member functions
  253. static ClassDesc SCMatrixRectSubBlock_cd(
  254. typeid(SCMatrixRectSubBlock),"SCMatrixRectSubBlock",1,"public SCMatrixBlock",
  255. 0, 0, create<SCMatrixRectSubBlock>);
  256. SCMatrixRectSubBlock::SCMatrixRectSubBlock(int is, int ie, int istr,
  257. int js, int je, double* d):
  258. istart(is),
  259. jstart(js),
  260. iend(ie),
  261. jend(je),
  262. istride(istr),
  263. data(d)
  264. {
  265. }
  266. SCMatrixRectSubBlock::SCMatrixRectSubBlock(StateIn&s):
  267. SCMatrixBlock(s)
  268. {
  269. s.get(istart);
  270. s.get(istride);
  271. s.get(jstart);
  272. s.get(iend);
  273. s.get(jend);
  274. data = 0;
  275. }
  276. void
  277. SCMatrixRectSubBlock::save_data_state(StateOut&s)
  278. {
  279. SCMatrixBlock::save_data_state(s);
  280. s.put(istart);
  281. s.put(istride);
  282. s.put(jstart);
  283. s.put(iend);
  284. s.put(jend);
  285. }
  286. SCMatrixRectSubBlock::~SCMatrixRectSubBlock()
  287. {
  288. }
  289. void
  290. SCMatrixRectSubBlock::process(SCElementOp*op)
  291. {
  292. SCMatrixRectSubBlockIter i(this);
  293. op->process(i);
  294. }
  295. void
  296. SCMatrixRectSubBlock::process(SCElementOp2*op,
  297. SCMatrixBlock* b)
  298. {
  299. SCMatrixRectSubBlockIter i(this);
  300. SCMatrixRectSubBlockIter j((SCMatrixRectSubBlock*)b);
  301. op->process(i,j);
  302. }
  303. void
  304. SCMatrixRectSubBlock::process(SCElementOp3*op,
  305. SCMatrixBlock* b1,
  306. SCMatrixBlock* b2)
  307. {
  308. SCMatrixRectSubBlockIter i(this);
  309. SCMatrixRectSubBlockIter j((SCMatrixRectSubBlock*)b1);
  310. SCMatrixRectSubBlockIter k((SCMatrixRectSubBlock*)b2);
  311. op->process(i,j,k);
  312. }
  313. /////////////////////////////////////////////////////////////////////////////
  314. // SCMatrixLTriBlock member functions
  315. static ClassDesc SCMatrixLTriBlock_cd(
  316. typeid(SCMatrixLTriBlock),"SCMatrixLTriBlock",1,"public SCMatrixBlock",
  317. 0, 0, create<SCMatrixLTriBlock>);
  318. SCMatrixLTriBlock::SCMatrixLTriBlock(int s,int e):
  319. start(s),
  320. end(e)
  321. {
  322. data = new double[((e-s)*(e-s+1))/2];
  323. }
  324. SCMatrixLTriBlock::SCMatrixLTriBlock(StateIn&s):
  325. SCMatrixBlock(s)
  326. {
  327. s.get(start);
  328. s.get(end);
  329. s.get(data);
  330. }
  331. void
  332. SCMatrixLTriBlock::save_data_state(StateOut&s)
  333. {
  334. SCMatrixBlock::save_data_state(s);
  335. s.put(start);
  336. s.put(end);
  337. s.put(data,((end-start)*(end-start+1))/2);
  338. }
  339. SCMatrixBlock *
  340. SCMatrixLTriBlock::deepcopy() const
  341. {
  342. SCMatrixLTriBlock *ret = new SCMatrixLTriBlock(start,end);
  343. ret->blocki = blocki;
  344. ret->blockj = blockj;
  345. memcpy(ret->data, data, sizeof(double)*ndat());
  346. return ret;
  347. }
  348. double *
  349. SCMatrixLTriBlock::dat()
  350. {
  351. return data;
  352. }
  353. int
  354. SCMatrixLTriBlock::ndat() const
  355. {
  356. return ((end-start)*(end-start+1))/2;
  357. }
  358. SCMatrixLTriBlock::~SCMatrixLTriBlock()
  359. {
  360. delete[] data;
  361. }
  362. void
  363. SCMatrixLTriBlock::process(SCElementOp*op)
  364. {
  365. SCMatrixLTriBlockIter i(this);
  366. op->process(i);
  367. }
  368. void
  369. SCMatrixLTriBlock::process(SCElementOp2*op,
  370. SCMatrixBlock* b)
  371. {
  372. SCMatrixLTriBlockIter i(this);
  373. SCMatrixLTriBlockIter j((SCMatrixLTriBlock*)b);
  374. op->process(i,j);
  375. }
  376. void
  377. SCMatrixLTriBlock::process(SCElementOp3*op,
  378. SCMatrixBlock* b1, SCMatrixBlock* b2)
  379. {
  380. SCMatrixLTriBlockIter i(this);
  381. SCMatrixLTriBlockIter j((SCMatrixLTriBlock*)b1);
  382. SCMatrixLTriBlockIter k((SCMatrixLTriBlock*)b2);
  383. op->process(i,j,k);
  384. }
  385. /////////////////////////////////////////////////////////////////////////////
  386. // SCMatrixLTriSubBlock member functions
  387. static ClassDesc SCMatrixLTriSubBlock_cd(
  388. typeid(SCMatrixLTriSubBlock),"SCMatrixLTriSubBlock",1,"public SCMatrixBlock",
  389. 0, 0, create<SCMatrixLTriSubBlock>);
  390. SCMatrixLTriSubBlock::SCMatrixLTriSubBlock(int is, int ie,
  391. int js, int je,
  392. double*d):
  393. istart(is),
  394. iend(ie),
  395. jstart(js),
  396. jend(je),
  397. data(d)
  398. {
  399. }
  400. SCMatrixLTriSubBlock::SCMatrixLTriSubBlock(StateIn&s):
  401. SCMatrixBlock(s)
  402. {
  403. s.get(istart);
  404. s.get(iend);
  405. s.get(jstart);
  406. s.get(jend);
  407. data = 0;
  408. }
  409. void
  410. SCMatrixLTriSubBlock::save_data_state(StateOut&s)
  411. {
  412. SCMatrixBlock::save_data_state(s);
  413. s.put(istart);
  414. s.put(iend);
  415. s.put(jstart);
  416. s.put(jend);
  417. }
  418. SCMatrixLTriSubBlock::~SCMatrixLTriSubBlock()
  419. {
  420. }
  421. void
  422. SCMatrixLTriSubBlock::process(SCElementOp*op)
  423. {
  424. SCMatrixLTriSubBlockIter i(this);
  425. op->process(i);
  426. }
  427. void
  428. SCMatrixLTriSubBlock::process(SCElementOp2*op,
  429. SCMatrixBlock* b)
  430. {
  431. SCMatrixLTriSubBlockIter i(this);
  432. SCMatrixLTriSubBlockIter j((SCMatrixLTriSubBlock*)b);
  433. op->process(i,j);
  434. }
  435. void
  436. SCMatrixLTriSubBlock::process(SCElementOp3*op,
  437. SCMatrixBlock* b1,
  438. SCMatrixBlock* b2)
  439. {
  440. SCMatrixLTriSubBlockIter i(this);
  441. SCMatrixLTriSubBlockIter j((SCMatrixLTriSubBlock*)b1);
  442. SCMatrixLTriSubBlockIter k((SCMatrixLTriSubBlock*)b2);
  443. op->process(i,j,k);
  444. }
  445. /////////////////////////////////////////////////////////////////////////////
  446. // SCMatrixDiagBlock member functions
  447. static ClassDesc SCMatrixDiagBlock_cd(
  448. typeid(SCMatrixDiagBlock),"SCMatrixDiagBlock",1,"public SCMatrixBlock",
  449. 0, 0, create<SCMatrixDiagBlock>);
  450. SCMatrixDiagBlock::SCMatrixDiagBlock(int s, int e):
  451. istart(s),
  452. jstart(s),
  453. iend(e)
  454. {
  455. data = new double[e-s];
  456. }
  457. SCMatrixDiagBlock::SCMatrixDiagBlock(int is, int ie,int js):
  458. istart(is),
  459. jstart(js),
  460. iend(ie)
  461. {
  462. data = new double[ie-is];
  463. }
  464. SCMatrixDiagBlock::SCMatrixDiagBlock(StateIn&s):
  465. SCMatrixBlock(s)
  466. {
  467. s.get(istart);
  468. s.get(jstart);
  469. s.get(iend);
  470. s.get(data);
  471. }
  472. void
  473. SCMatrixDiagBlock::save_data_state(StateOut&s)
  474. {
  475. SCMatrixBlock::save_data_state(s);
  476. s.put(istart);
  477. s.put(jstart);
  478. s.put(iend);
  479. s.put(data,iend-istart);
  480. }
  481. SCMatrixBlock *
  482. SCMatrixDiagBlock::deepcopy() const
  483. {
  484. SCMatrixDiagBlock *ret = new SCMatrixDiagBlock(istart,iend,jstart);
  485. ret->blocki = blocki;
  486. ret->blockj = blockj;
  487. memcpy(ret->data, data, sizeof(double)*ndat());
  488. return ret;
  489. }
  490. double *
  491. SCMatrixDiagBlock::dat()
  492. {
  493. return data;
  494. }
  495. int
  496. SCMatrixDiagBlock::ndat() const
  497. {
  498. return iend-istart;
  499. }
  500. SCMatrixDiagBlock::~SCMatrixDiagBlock()
  501. {
  502. delete[] data;
  503. }
  504. void
  505. SCMatrixDiagBlock::process(SCElementOp*op)
  506. {
  507. SCMatrixDiagBlockIter i(this);
  508. op->process(i);
  509. }
  510. void
  511. SCMatrixDiagBlock::process(SCElementOp2*op,
  512. SCMatrixBlock* b)
  513. {
  514. SCMatrixDiagBlockIter i(this);
  515. SCMatrixDiagBlockIter j((SCMatrixDiagBlock*)b);
  516. op->process(i,j);
  517. }
  518. void
  519. SCMatrixDiagBlock::process(SCElementOp3*op,
  520. SCMatrixBlock* b1, SCMatrixBlock* b2)
  521. {
  522. SCMatrixDiagBlockIter i(this);
  523. SCMatrixDiagBlockIter j((SCMatrixDiagBlock*)b1);
  524. SCMatrixDiagBlockIter k((SCMatrixDiagBlock*)b2);
  525. op->process(i,j,k);
  526. }
  527. /////////////////////////////////////////////////////////////////////////////
  528. // SCMatrixDiagSubBlock member functions
  529. static ClassDesc SCMatrixDiagSubBlock_cd(
  530. typeid(SCMatrixDiagSubBlock),"SCMatrixDiagSubBlock",1,"public SCMatrixBlock",
  531. 0, 0, create<SCMatrixDiagSubBlock>);
  532. SCMatrixDiagSubBlock::SCMatrixDiagSubBlock(int s, int e, int o,
  533. double* d):
  534. istart(s),
  535. jstart(s),
  536. iend(e),
  537. offset(o),
  538. data(d)
  539. {
  540. }
  541. SCMatrixDiagSubBlock::SCMatrixDiagSubBlock(int is, int ie,
  542. int js, int o, double* d):
  543. istart(is),
  544. jstart(js),
  545. iend(ie),
  546. offset(o),
  547. data(d)
  548. {
  549. }
  550. SCMatrixDiagSubBlock::SCMatrixDiagSubBlock(StateIn&s):
  551. SCMatrixBlock(s)
  552. {
  553. s.get(istart);
  554. s.get(jstart);
  555. s.get(iend);
  556. s.get(offset);
  557. data = 0;
  558. }
  559. void
  560. SCMatrixDiagSubBlock::save_data_state(StateOut&s)
  561. {
  562. SCMatrixBlock::save_data_state(s);
  563. s.put(istart);
  564. s.put(jstart);
  565. s.put(iend);
  566. s.put(offset);
  567. }
  568. SCMatrixDiagSubBlock::~SCMatrixDiagSubBlock()
  569. {
  570. }
  571. void
  572. SCMatrixDiagSubBlock::process(SCElementOp*op)
  573. {
  574. SCMatrixDiagSubBlockIter i(this);
  575. op->process(i);
  576. }
  577. void
  578. SCMatrixDiagSubBlock::process(SCElementOp2*op,
  579. SCMatrixBlock* b)
  580. {
  581. SCMatrixDiagSubBlockIter i(this);
  582. SCMatrixDiagSubBlockIter j((SCMatrixDiagSubBlock*)b);
  583. op->process(i,j);
  584. }
  585. void
  586. SCMatrixDiagSubBlock::process(SCElementOp3*op,
  587. SCMatrixBlock* b1,
  588. SCMatrixBlock* b2)
  589. {
  590. SCMatrixDiagSubBlockIter i(this);
  591. SCMatrixDiagSubBlockIter j((SCMatrixDiagSubBlock*)b1);
  592. SCMatrixDiagSubBlockIter k((SCMatrixDiagSubBlock*)b2);
  593. op->process(i,j,k);
  594. }
  595. /////////////////////////////////////////////////////////////////////////////
  596. // SCVectorSimpleBlock member functions
  597. static ClassDesc SCVectorSimpleBlock_cd(
  598. typeid(SCVectorSimpleBlock),"SCVectorSimpleBlock",1,"public SCMatrixBlock",
  599. 0, 0, create<SCVectorSimpleBlock>);
  600. SCVectorSimpleBlock::SCVectorSimpleBlock(int s, int e):
  601. istart(s),
  602. iend(e)
  603. {
  604. data = new double[e-s];
  605. }
  606. SCVectorSimpleBlock::SCVectorSimpleBlock(StateIn&s):
  607. SCMatrixBlock(s)
  608. {
  609. s.get(istart);
  610. s.get(iend);
  611. s.get(data);
  612. }
  613. void
  614. SCVectorSimpleBlock::save_data_state(StateOut&s)
  615. {
  616. SCMatrixBlock::save_data_state(s);
  617. s.put(istart);
  618. s.put(iend);
  619. s.put(data,iend-istart);
  620. }
  621. SCMatrixBlock *
  622. SCVectorSimpleBlock::deepcopy() const
  623. {
  624. SCVectorSimpleBlock *ret = new SCVectorSimpleBlock(istart,iend);
  625. ret->blocki = blocki;
  626. ret->blockj = blockj;
  627. memcpy(ret->data, data, sizeof(double)*ndat());
  628. return ret;
  629. }
  630. double *
  631. SCVectorSimpleBlock::dat()
  632. {
  633. return data;
  634. }
  635. int
  636. SCVectorSimpleBlock::ndat() const
  637. {
  638. return iend-istart;
  639. }
  640. SCVectorSimpleBlock::~SCVectorSimpleBlock()
  641. {
  642. delete[] data;
  643. }
  644. void
  645. SCVectorSimpleBlock::process(SCElementOp*op)
  646. {
  647. SCVectorSimpleBlockIter i(this);
  648. op->process(i);
  649. }
  650. void
  651. SCVectorSimpleBlock::process(SCElementOp2*op,
  652. SCMatrixBlock* b)
  653. {
  654. SCVectorSimpleBlockIter i(this);
  655. SCVectorSimpleBlockIter j((SCVectorSimpleBlock*)b);
  656. op->process(i,j);
  657. }
  658. void
  659. SCVectorSimpleBlock::process(SCElementOp3*op,
  660. SCMatrixBlock* b1,
  661. SCMatrixBlock* b2)
  662. {
  663. SCVectorSimpleBlockIter i(this);
  664. SCVectorSimpleBlockIter j((SCVectorSimpleBlock*)b1);
  665. SCVectorSimpleBlockIter k((SCVectorSimpleBlock*)b2);
  666. op->process(i,j,k);
  667. }
  668. /////////////////////////////////////////////////////////////////////////////
  669. // SCVectorSimpleSubBlock member functions
  670. static ClassDesc SCVectorSimpleSubBlock_cd(
  671. typeid(SCVectorSimpleSubBlock),"SCVectorSimpleSubBlock",1,"public SCMatrixBlock",
  672. 0, 0, create<SCVectorSimpleSubBlock>);
  673. SCVectorSimpleSubBlock::SCVectorSimpleSubBlock(int s, int e, int o,
  674. double* d):
  675. istart(s),
  676. iend(e),
  677. offset(o),
  678. data(d)
  679. {
  680. }
  681. SCVectorSimpleSubBlock::SCVectorSimpleSubBlock(StateIn&s):
  682. SCMatrixBlock(s)
  683. {
  684. s.get(istart);
  685. s.get(iend);
  686. s.get(offset);
  687. data = 0;
  688. }
  689. void
  690. SCVectorSimpleSubBlock::save_data_state(StateOut&s)
  691. {
  692. SCMatrixBlock::save_data_state(s);
  693. s.put(istart);
  694. s.put(iend);
  695. s.put(offset);
  696. }
  697. SCVectorSimpleSubBlock::~SCVectorSimpleSubBlock()
  698. {
  699. }
  700. void
  701. SCVectorSimpleSubBlock::process(SCElementOp*op)
  702. {
  703. SCVectorSimpleSubBlockIter i(this);
  704. op->process(i);
  705. }
  706. void
  707. SCVectorSimpleSubBlock::process(SCElementOp2*op,
  708. SCMatrixBlock* b)
  709. {
  710. SCVectorSimpleSubBlockIter i(this);
  711. SCVectorSimpleSubBlockIter j((SCVectorSimpleSubBlock*)b);
  712. op->process(i,j);
  713. }
  714. void
  715. SCVectorSimpleSubBlock::process(SCElementOp3*op,
  716. SCMatrixBlock* b1,
  717. SCMatrixBlock* b2)
  718. {
  719. SCVectorSimpleSubBlockIter i(this);
  720. SCVectorSimpleSubBlockIter j((SCVectorSimpleSubBlock*)b1);
  721. SCVectorSimpleSubBlockIter k((SCVectorSimpleSubBlock*)b2);
  722. op->process(i,j,k);
  723. }
  724. ///////////////////////////////////////////////////////////////////////
  725. // SCMatrixSubblockIter
  726. SCMatrixSubblockIter::~SCMatrixSubblockIter()
  727. {
  728. }
  729. ///////////////////////////////////////////////////////////////////////
  730. // SCMatrixSimpleSubblockIter
  731. SCMatrixSimpleSubblockIter::SCMatrixSimpleSubblockIter(
  732. Access access_,
  733. const Ref<SCMatrixBlock> &b):
  734. SCMatrixSubblockIter(access_)
  735. {
  736. block_ = b;
  737. }
  738. void
  739. SCMatrixSimpleSubblockIter::begin()
  740. {
  741. if (block_.nonnull()) ready_ = 1;
  742. else ready_ = 0;
  743. }
  744. int
  745. SCMatrixSimpleSubblockIter::ready()
  746. {
  747. return ready_;
  748. }
  749. void
  750. SCMatrixSimpleSubblockIter::next()
  751. {
  752. ready_ = 0;
  753. }
  754. SCMatrixBlock *
  755. SCMatrixSimpleSubblockIter::block()
  756. {
  757. return block_.pointer();
  758. }
  759. ///////////////////////////////////////////////////////////////////////
  760. // SCMatrixListSubblockIter
  761. SCMatrixListSubblockIter::SCMatrixListSubblockIter(
  762. Access access,
  763. const Ref<SCMatrixBlockList> &list
  764. ):
  765. SCMatrixSubblockIter(access),
  766. list_(list)
  767. {
  768. }
  769. void
  770. SCMatrixListSubblockIter::begin()
  771. {
  772. iter_ = list_->begin();
  773. }
  774. int
  775. SCMatrixListSubblockIter::ready()
  776. {
  777. return iter_ != list_->end();
  778. }
  779. void
  780. SCMatrixListSubblockIter::next()
  781. {
  782. iter_++;
  783. }
  784. SCMatrixBlock *
  785. SCMatrixListSubblockIter::block()
  786. {
  787. return iter_.block();
  788. }
  789. ///////////////////////////////////////////////////////////////////////
  790. // SCMatrixNullSubblockIter
  791. SCMatrixNullSubblockIter::SCMatrixNullSubblockIter():
  792. SCMatrixSubblockIter(None)
  793. {
  794. }
  795. SCMatrixNullSubblockIter::SCMatrixNullSubblockIter(Access access):
  796. SCMatrixSubblockIter(access)
  797. {
  798. }
  799. void
  800. SCMatrixNullSubblockIter::begin()
  801. {
  802. }
  803. int
  804. SCMatrixNullSubblockIter::ready()
  805. {
  806. return 0;
  807. }
  808. void
  809. SCMatrixNullSubblockIter::next()
  810. {
  811. }
  812. SCMatrixBlock *
  813. SCMatrixNullSubblockIter::block()
  814. {
  815. return 0;
  816. }
  817. ///////////////////////////////////////////////////////////////////////
  818. // SCMatrixCompositeSubblockIter
  819. SCMatrixCompositeSubblockIter::SCMatrixCompositeSubblockIter(
  820. Ref<SCMatrixSubblockIter>& i1,
  821. Ref<SCMatrixSubblockIter>& i2):
  822. SCMatrixSubblockIter(None)
  823. {
  824. niters_ = 0;
  825. if (i1.nonnull()) { niters_++; }
  826. if (i2.nonnull()) { niters_++; }
  827. iters_ = new Ref<SCMatrixSubblockIter>[niters_];
  828. iiter_ = 0;
  829. if (i1.nonnull()) { iters_[iiter_] = i1; iiter_++; }
  830. if (i2.nonnull()) { iters_[iiter_] = i2; iiter_++; }
  831. if (niters_) access_ = iters_[0]->access();
  832. for (int i=0; i<niters_; i++) {
  833. if (iters_[i]->access() != access_) {
  834. ExEnv::errn() << "SCMatrixCompositeSubblockIter: access not compatible"
  835. << endl;
  836. abort();
  837. }
  838. }
  839. }
  840. SCMatrixCompositeSubblockIter::SCMatrixCompositeSubblockIter(
  841. Access access_,
  842. int niters):
  843. SCMatrixSubblockIter(access_)
  844. {
  845. niters_ = niters;
  846. iters_ = new Ref<SCMatrixSubblockIter>[niters_];
  847. }
  848. SCMatrixCompositeSubblockIter::~SCMatrixCompositeSubblockIter()
  849. {
  850. delete[] iters_;
  851. }
  852. void
  853. SCMatrixCompositeSubblockIter::set_iter(int i,
  854. const Ref<SCMatrixSubblockIter>& iter)
  855. {
  856. iters_[i] = iter;
  857. if (iters_[i]->access() != access_) {
  858. ExEnv::errn() << "SCMatrixCompositeSubblockIter: access not compatible"
  859. << endl;
  860. abort();
  861. }
  862. }
  863. void
  864. SCMatrixCompositeSubblockIter::begin()
  865. {
  866. if (niters_ == 0) return;
  867. iiter_ = 0;
  868. iters_[iiter_]->begin();
  869. while (!iters_[iiter_]->ready()) {
  870. if (iiter_ < niters_-1) {
  871. iiter_++;
  872. iters_[iiter_]->begin();
  873. }
  874. else break;
  875. }
  876. }
  877. int
  878. SCMatrixCompositeSubblockIter::ready()
  879. {
  880. return iters_[iiter_]->ready();
  881. }
  882. void
  883. SCMatrixCompositeSubblockIter::next()
  884. {
  885. iters_[iiter_]->next();
  886. while (!iters_[iiter_]->ready()) {
  887. if (iiter_ < niters_-1) {
  888. iiter_++;
  889. iters_[iiter_]->begin();
  890. }
  891. else break;
  892. }
  893. }
  894. SCMatrixBlock *
  895. SCMatrixCompositeSubblockIter::block()
  896. {
  897. return iters_[iiter_]->block();
  898. }
  899. ///////////////////////////////////////////////////////////////////////
  900. // SCMatrixJointSubblockIter
  901. SCMatrixJointSubblockIter::SCMatrixJointSubblockIter(
  902. const Ref<SCMatrixSubblockIter>& i1,
  903. const Ref<SCMatrixSubblockIter>& i2,
  904. const Ref<SCMatrixSubblockIter>& i3,
  905. const Ref<SCMatrixSubblockIter>& i4,
  906. const Ref<SCMatrixSubblockIter>& i5):
  907. SCMatrixSubblockIter(None)
  908. {
  909. niters_ = 0;
  910. if (i1.nonnull()) { niters_++; }
  911. if (i2.nonnull()) { niters_++; }
  912. if (i3.nonnull()) { niters_++; }
  913. if (i4.nonnull()) { niters_++; }
  914. if (i5.nonnull()) { niters_++; }
  915. iters_ = new Ref<SCMatrixSubblockIter>[niters_];
  916. int i = 0;
  917. if (i1.nonnull()) { iters_[i] = i1; i++; }
  918. if (i2.nonnull()) { iters_[i] = i2; i++; }
  919. if (i3.nonnull()) { iters_[i] = i3; i++; }
  920. if (i4.nonnull()) { iters_[i] = i4; i++; }
  921. if (i5.nonnull()) { iters_[i] = i5; i++; }
  922. }
  923. SCMatrixJointSubblockIter::~SCMatrixJointSubblockIter()
  924. {
  925. delete[] iters_;
  926. }
  927. void
  928. SCMatrixJointSubblockIter::begin()
  929. {
  930. for (int i=0; i<niters_; i++) {
  931. iters_[i]->begin();
  932. }
  933. }
  934. int
  935. SCMatrixJointSubblockIter::ready()
  936. {
  937. int nready = 0;
  938. for (int i=0; i<niters_; i++) {
  939. nready += (iters_[i]->ready()?1:0);
  940. }
  941. if (nready == niters_)
  942. return 1;
  943. else if (!nready)
  944. return 0;
  945. ExEnv::errn() << "SCMatrixJointSubblockIter: incompatible iterators" << endl;
  946. abort();
  947. return 0;
  948. }
  949. void
  950. SCMatrixJointSubblockIter::next()
  951. {
  952. for (int i=0; i<niters_; i++) {
  953. iters_[i]->next();
  954. }
  955. }
  956. SCMatrixBlock *
  957. SCMatrixJointSubblockIter::block()
  958. {
  959. return block(0);
  960. }
  961. SCMatrixBlock *
  962. SCMatrixJointSubblockIter::block(int b)
  963. {
  964. return iters_[b]->block();
  965. }
  966. /////////////////////////////////////////////////////////////////////////////
  967. // Local Variables:
  968. // mode: c++
  969. // c-file-style: "CLJ"
  970. // End: