matrix_expression.hpp 188 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952
  1. //
  2. // Copyright (c) 2000-2002
  3. // Joerg Walter, Mathias Koch
  4. //
  5. // Distributed under the Boost Software License, Version 1.0. (See
  6. // accompanying file LICENSE_1_0.txt or copy at
  7. // http://www.boost.org/LICENSE_1_0.txt)
  8. //
  9. // The authors gratefully acknowledge the support of
  10. // GeNeSys mbH & Co. KG in producing this work.
  11. //
  12. #ifndef _BOOST_UBLAS_MATRIX_EXPRESSION_
  13. #define _BOOST_UBLAS_MATRIX_EXPRESSION_
  14. #include <boost/numeric/ublas/vector_expression.hpp>
  15. // Expression templates based on ideas of Todd Veldhuizen and Geoffrey Furnish
  16. // Iterators based on ideas of Jeremy Siek
  17. //
  18. // Classes that model the Matrix Expression concept
  19. namespace boost { namespace numeric { namespace ublas {
  20. template<class E>
  21. class matrix_reference:
  22. public matrix_expression<matrix_reference<E> > {
  23. typedef matrix_reference<E> self_type;
  24. public:
  25. #ifdef BOOST_UBLAS_ENABLE_PROXY_SHORTCUTS
  26. using matrix_expression<self_type>::operator ();
  27. #endif
  28. typedef typename E::size_type size_type;
  29. typedef typename E::difference_type difference_type;
  30. typedef typename E::value_type value_type;
  31. typedef typename E::const_reference const_reference;
  32. typedef typename boost::mpl::if_<boost::is_const<E>,
  33. typename E::const_reference,
  34. typename E::reference>::type reference;
  35. typedef E referred_type;
  36. typedef const self_type const_closure_type;
  37. typedef self_type closure_type;
  38. typedef typename E::orientation_category orientation_category;
  39. typedef typename E::storage_category storage_category;
  40. // Construction and destruction
  41. BOOST_UBLAS_INLINE
  42. explicit matrix_reference (referred_type &e):
  43. e_ (e) {}
  44. // Accessors
  45. BOOST_UBLAS_INLINE
  46. size_type size1 () const {
  47. return e_.size1 ();
  48. }
  49. BOOST_UBLAS_INLINE
  50. size_type size2 () const {
  51. return e_.size2 ();
  52. }
  53. public:
  54. // Expression accessors - const correct
  55. BOOST_UBLAS_INLINE
  56. const referred_type &expression () const {
  57. return e_;
  58. }
  59. BOOST_UBLAS_INLINE
  60. referred_type &expression () {
  61. return e_;
  62. }
  63. public:
  64. // Element access
  65. #ifndef BOOST_UBLAS_REFERENCE_CONST_MEMBER
  66. BOOST_UBLAS_INLINE
  67. const_reference operator () (size_type i, size_type j) const {
  68. return expression () (i, j);
  69. }
  70. BOOST_UBLAS_INLINE
  71. reference operator () (size_type i, size_type j) {
  72. return expression () (i, j);
  73. }
  74. #else
  75. BOOST_UBLAS_INLINE
  76. reference operator () (size_type i, size_type j) const {
  77. return expression () (i, j);
  78. }
  79. #endif
  80. // Assignment
  81. BOOST_UBLAS_INLINE
  82. matrix_reference &operator = (const matrix_reference &m) {
  83. expression ().operator = (m);
  84. return *this;
  85. }
  86. template<class AE>
  87. BOOST_UBLAS_INLINE
  88. matrix_reference &operator = (const matrix_expression<AE> &ae) {
  89. expression ().operator = (ae);
  90. return *this;
  91. }
  92. template<class AE>
  93. BOOST_UBLAS_INLINE
  94. matrix_reference &assign (const matrix_expression<AE> &ae) {
  95. expression ().assign (ae);
  96. return *this;
  97. }
  98. template<class AE>
  99. BOOST_UBLAS_INLINE
  100. matrix_reference &operator += (const matrix_expression<AE> &ae) {
  101. expression ().operator += (ae);
  102. return *this;
  103. }
  104. template<class AE>
  105. BOOST_UBLAS_INLINE
  106. matrix_reference &plus_assign (const matrix_expression<AE> &ae) {
  107. expression ().plus_assign (ae);
  108. return *this;
  109. }
  110. template<class AE>
  111. BOOST_UBLAS_INLINE
  112. matrix_reference &operator -= (const matrix_expression<AE> &ae) {
  113. expression ().operator -= (ae);
  114. return *this;
  115. }
  116. template<class AE>
  117. BOOST_UBLAS_INLINE
  118. matrix_reference &minus_assign (const matrix_expression<AE> &ae) {
  119. expression ().minus_assign (ae);
  120. return *this;
  121. }
  122. template<class AT>
  123. BOOST_UBLAS_INLINE
  124. matrix_reference &operator *= (const AT &at) {
  125. expression ().operator *= (at);
  126. return *this;
  127. }
  128. template<class AT>
  129. BOOST_UBLAS_INLINE
  130. matrix_reference &operator /= (const AT &at) {
  131. expression ().operator /= (at);
  132. return *this;
  133. }
  134. // Swapping
  135. BOOST_UBLAS_INLINE
  136. void swap (matrix_reference &m) {
  137. expression ().swap (m.expression ());
  138. }
  139. // Closure comparison
  140. BOOST_UBLAS_INLINE
  141. bool same_closure (const matrix_reference &mr) const {
  142. return &(*this).e_ == &mr.e_;
  143. }
  144. // Iterator types
  145. typedef typename E::const_iterator1 const_iterator1;
  146. typedef typename boost::mpl::if_<boost::is_const<E>,
  147. typename E::const_iterator1,
  148. typename E::iterator1>::type iterator1;
  149. typedef typename E::const_iterator2 const_iterator2;
  150. typedef typename boost::mpl::if_<boost::is_const<E>,
  151. typename E::const_iterator2,
  152. typename E::iterator2>::type iterator2;
  153. // Element lookup
  154. BOOST_UBLAS_INLINE
  155. const_iterator1 find1 (int rank, size_type i, size_type j) const {
  156. return expression ().find1 (rank, i, j);
  157. }
  158. BOOST_UBLAS_INLINE
  159. iterator1 find1 (int rank, size_type i, size_type j) {
  160. return expression ().find1 (rank, i, j);
  161. }
  162. BOOST_UBLAS_INLINE
  163. const_iterator2 find2 (int rank, size_type i, size_type j) const {
  164. return expression ().find2 (rank, i, j);
  165. }
  166. BOOST_UBLAS_INLINE
  167. iterator2 find2 (int rank, size_type i, size_type j) {
  168. return expression ().find2 (rank, i, j);
  169. }
  170. // Iterators are the iterators of the referenced expression.
  171. BOOST_UBLAS_INLINE
  172. const_iterator1 begin1 () const {
  173. return expression ().begin1 ();
  174. }
  175. BOOST_UBLAS_INLINE
  176. const_iterator1 end1 () const {
  177. return expression ().end1 ();
  178. }
  179. BOOST_UBLAS_INLINE
  180. iterator1 begin1 () {
  181. return expression ().begin1 ();
  182. }
  183. BOOST_UBLAS_INLINE
  184. iterator1 end1 () {
  185. return expression ().end1 ();
  186. }
  187. BOOST_UBLAS_INLINE
  188. const_iterator2 begin2 () const {
  189. return expression ().begin2 ();
  190. }
  191. BOOST_UBLAS_INLINE
  192. const_iterator2 end2 () const {
  193. return expression ().end2 ();
  194. }
  195. BOOST_UBLAS_INLINE
  196. iterator2 begin2 () {
  197. return expression ().begin2 ();
  198. }
  199. BOOST_UBLAS_INLINE
  200. iterator2 end2 () {
  201. return expression ().end2 ();
  202. }
  203. // Reverse iterators
  204. typedef reverse_iterator_base1<const_iterator1> const_reverse_iterator1;
  205. typedef reverse_iterator_base1<iterator1> reverse_iterator1;
  206. BOOST_UBLAS_INLINE
  207. const_reverse_iterator1 rbegin1 () const {
  208. return const_reverse_iterator1 (end1 ());
  209. }
  210. BOOST_UBLAS_INLINE
  211. const_reverse_iterator1 rend1 () const {
  212. return const_reverse_iterator1 (begin1 ());
  213. }
  214. BOOST_UBLAS_INLINE
  215. reverse_iterator1 rbegin1 () {
  216. return reverse_iterator1 (end1 ());
  217. }
  218. BOOST_UBLAS_INLINE
  219. reverse_iterator1 rend1 () {
  220. return reverse_iterator1 (begin1 ());
  221. }
  222. typedef reverse_iterator_base2<const_iterator2> const_reverse_iterator2;
  223. typedef reverse_iterator_base2<iterator2> reverse_iterator2;
  224. BOOST_UBLAS_INLINE
  225. const_reverse_iterator2 rbegin2 () const {
  226. return const_reverse_iterator2 (end2 ());
  227. }
  228. BOOST_UBLAS_INLINE
  229. const_reverse_iterator2 rend2 () const {
  230. return const_reverse_iterator2 (begin2 ());
  231. }
  232. BOOST_UBLAS_INLINE
  233. reverse_iterator2 rbegin2 () {
  234. return reverse_iterator2 (end2 ());
  235. }
  236. BOOST_UBLAS_INLINE
  237. reverse_iterator2 rend2 () {
  238. return reverse_iterator2 (begin2 ());
  239. }
  240. private:
  241. referred_type &e_;
  242. };
  243. template<class E1, class E2, class F>
  244. class vector_matrix_binary:
  245. public matrix_expression<vector_matrix_binary<E1, E2, F> > {
  246. typedef E1 expression1_type;
  247. typedef E2 expression2_type;
  248. public:
  249. typedef typename E1::const_closure_type expression1_closure_type;
  250. typedef typename E2::const_closure_type expression2_closure_type;
  251. private:
  252. typedef vector_matrix_binary<E1, E2, F> self_type;
  253. public:
  254. #ifdef BOOST_UBLAS_ENABLE_PROXY_SHORTCUTS
  255. using matrix_expression<self_type>::operator ();
  256. #endif
  257. typedef F functor_type;
  258. typedef typename promote_traits<typename E1::size_type, typename E2::size_type>::promote_type size_type;
  259. typedef typename promote_traits<typename E1::difference_type, typename E2::difference_type>::promote_type difference_type;
  260. typedef typename F::result_type value_type;
  261. typedef value_type const_reference;
  262. typedef const_reference reference;
  263. typedef const self_type const_closure_type;
  264. typedef const_closure_type closure_type;
  265. typedef unknown_orientation_tag orientation_category;
  266. typedef unknown_storage_tag storage_category;
  267. // Construction and destruction
  268. BOOST_UBLAS_INLINE
  269. vector_matrix_binary (const expression1_type &e1, const expression2_type &e2):
  270. e1_ (e1), e2_ (e2) {}
  271. // Accessors
  272. BOOST_UBLAS_INLINE
  273. size_type size1 () const {
  274. return e1_.size ();
  275. }
  276. BOOST_UBLAS_INLINE
  277. size_type size2 () const {
  278. return e2_.size ();
  279. }
  280. public:
  281. // Expression accessors
  282. BOOST_UBLAS_INLINE
  283. const expression1_closure_type &expression1 () const {
  284. return e1_;
  285. }
  286. BOOST_UBLAS_INLINE
  287. const expression2_closure_type &expression2 () const {
  288. return e2_;
  289. }
  290. public:
  291. // Element access
  292. BOOST_UBLAS_INLINE
  293. const_reference operator () (size_type i, size_type j) const {
  294. return functor_type::apply (e1_ (i), e2_ (j));
  295. }
  296. // Closure comparison
  297. BOOST_UBLAS_INLINE
  298. bool same_closure (const vector_matrix_binary &vmb) const {
  299. return (*this).expression1 ().same_closure (vmb.expression1 ()) &&
  300. (*this).expression2 ().same_closure (vmb.expression2 ());
  301. }
  302. // Iterator types
  303. private:
  304. typedef typename E1::const_iterator const_subiterator1_type;
  305. typedef typename E2::const_iterator const_subiterator2_type;
  306. typedef const value_type *const_pointer;
  307. public:
  308. #ifdef BOOST_UBLAS_USE_INDEXED_ITERATOR
  309. typedef typename iterator_restrict_traits<typename const_subiterator1_type::iterator_category,
  310. typename const_subiterator2_type::iterator_category>::iterator_category iterator_category;
  311. typedef indexed_const_iterator1<const_closure_type, iterator_category> const_iterator1;
  312. typedef const_iterator1 iterator1;
  313. typedef indexed_const_iterator2<const_closure_type, iterator_category> const_iterator2;
  314. typedef const_iterator2 iterator2;
  315. #else
  316. class const_iterator1;
  317. typedef const_iterator1 iterator1;
  318. class const_iterator2;
  319. typedef const_iterator2 iterator2;
  320. #endif
  321. typedef reverse_iterator_base1<const_iterator1> const_reverse_iterator1;
  322. typedef reverse_iterator_base2<const_iterator2> const_reverse_iterator2;
  323. // Element lookup
  324. BOOST_UBLAS_INLINE
  325. const_iterator1 find1 (int rank, size_type i, size_type j) const {
  326. const_subiterator1_type it1 (e1_.find (i));
  327. const_subiterator1_type it1_end (e1_.find (size1 ()));
  328. const_subiterator2_type it2 (e2_.find (j));
  329. const_subiterator2_type it2_end (e2_.find (size2 ()));
  330. if (it2 == it2_end || (rank == 1 && (it2.index () != j || *it2 == value_type/*zero*/()))) {
  331. it1 = it1_end;
  332. it2 = it2_end;
  333. }
  334. #ifdef BOOST_UBLAS_USE_INDEXED_ITERATOR
  335. return const_iterator1 (*this, it1.index (), it2.index ());
  336. #else
  337. #ifdef BOOST_UBLAS_USE_INVARIANT_HOISTING
  338. return const_iterator1 (*this, it1, it2, it2 != it2_end ? *it2 : value_type/*zero*/());
  339. #else
  340. return const_iterator1 (*this, it1, it2);
  341. #endif
  342. #endif
  343. }
  344. BOOST_UBLAS_INLINE
  345. const_iterator2 find2 (int rank, size_type i, size_type j) const {
  346. const_subiterator2_type it2 (e2_.find (j));
  347. const_subiterator2_type it2_end (e2_.find (size2 ()));
  348. const_subiterator1_type it1 (e1_.find (i));
  349. const_subiterator1_type it1_end (e1_.find (size1 ()));
  350. if (it1 == it1_end || (rank == 1 && (it1.index () != i || *it1 == value_type/*zero*/()))) {
  351. it2 = it2_end;
  352. it1 = it1_end;
  353. }
  354. #ifdef BOOST_UBLAS_USE_INDEXED_ITERATOR
  355. return const_iterator2 (*this, it1.index (), it2.index ());
  356. #else
  357. #ifdef BOOST_UBLAS_USE_INVARIANT_HOISTING
  358. return const_iterator2 (*this, it1, it2, it1 != it1_end ? *it1 : value_type/*zero*/());
  359. #else
  360. return const_iterator2 (*this, it1, it2);
  361. #endif
  362. #endif
  363. }
  364. // Iterators enhance the iterators of the referenced expressions
  365. // with the binary functor.
  366. #ifndef BOOST_UBLAS_USE_INDEXED_ITERATOR
  367. class const_iterator1:
  368. public container_const_reference<vector_matrix_binary>,
  369. public iterator_base_traits<typename iterator_restrict_traits<typename E1::const_iterator::iterator_category,
  370. typename E2::const_iterator::iterator_category>::iterator_category>::template
  371. iterator_base<const_iterator1, value_type>::type {
  372. public:
  373. typedef typename iterator_restrict_traits<typename E1::const_iterator::iterator_category,
  374. typename E2::const_iterator::iterator_category>::iterator_category iterator_category;
  375. typedef typename vector_matrix_binary::difference_type difference_type;
  376. typedef typename vector_matrix_binary::value_type value_type;
  377. typedef typename vector_matrix_binary::const_reference reference;
  378. typedef typename vector_matrix_binary::const_pointer pointer;
  379. typedef const_iterator2 dual_iterator_type;
  380. typedef const_reverse_iterator2 dual_reverse_iterator_type;
  381. // Construction and destruction
  382. #ifdef BOOST_UBLAS_USE_INVARIANT_HOISTING
  383. BOOST_UBLAS_INLINE
  384. const_iterator1 ():
  385. container_const_reference<self_type> (), it1_ (), it2_ (), t2_ () {}
  386. BOOST_UBLAS_INLINE
  387. const_iterator1 (const self_type &vmb, const const_subiterator1_type &it1, const const_subiterator2_type &it2, value_type t2):
  388. container_const_reference<self_type> (vmb), it1_ (it1), it2_ (it2), t2_ (t2) {}
  389. #else
  390. BOOST_UBLAS_INLINE
  391. const_iterator1 ():
  392. container_const_reference<self_type> (), it1_ (), it2_ () {}
  393. BOOST_UBLAS_INLINE
  394. const_iterator1 (const self_type &vmb, const const_subiterator1_type &it1, const const_subiterator2_type &it2):
  395. container_const_reference<self_type> (vmb), it1_ (it1), it2_ (it2) {}
  396. #endif
  397. // Arithmetic
  398. BOOST_UBLAS_INLINE
  399. const_iterator1 &operator ++ () {
  400. ++ it1_;
  401. return *this;
  402. }
  403. BOOST_UBLAS_INLINE
  404. const_iterator1 &operator -- () {
  405. -- it1_;
  406. return *this;
  407. }
  408. BOOST_UBLAS_INLINE
  409. const_iterator1 &operator += (difference_type n) {
  410. it1_ += n;
  411. return *this;
  412. }
  413. BOOST_UBLAS_INLINE
  414. const_iterator1 &operator -= (difference_type n) {
  415. it1_ -= n;
  416. return *this;
  417. }
  418. BOOST_UBLAS_INLINE
  419. difference_type operator - (const const_iterator1 &it) const {
  420. BOOST_UBLAS_CHECK ((*this) ().same_closure (it ()), external_logic ());
  421. BOOST_UBLAS_CHECK (it2_ == it.it2_, external_logic ());
  422. return it1_ - it.it1_;
  423. }
  424. // Dereference
  425. BOOST_UBLAS_INLINE
  426. const_reference operator * () const {
  427. #ifdef BOOST_UBLAS_USE_INVARIANT_HOISTING
  428. return functor_type::apply (*it1_, t2_);
  429. #else
  430. return functor_type::apply (*it1_, *it2_);
  431. #endif
  432. }
  433. BOOST_UBLAS_INLINE
  434. const_reference operator [] (difference_type n) const {
  435. return *(*this + n);
  436. }
  437. #ifndef BOOST_UBLAS_NO_NESTED_CLASS_RELATION
  438. BOOST_UBLAS_INLINE
  439. #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
  440. typename self_type::
  441. #endif
  442. const_iterator2 begin () const {
  443. return (*this) ().find2 (1, index1 (), 0);
  444. }
  445. BOOST_UBLAS_INLINE
  446. #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
  447. typename self_type::
  448. #endif
  449. const_iterator2 end () const {
  450. return (*this) ().find2 (1, index1 (), (*this) ().size2 ());
  451. }
  452. BOOST_UBLAS_INLINE
  453. #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
  454. typename self_type::
  455. #endif
  456. const_reverse_iterator2 rbegin () const {
  457. return const_reverse_iterator2 (end ());
  458. }
  459. BOOST_UBLAS_INLINE
  460. #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
  461. typename self_type::
  462. #endif
  463. const_reverse_iterator2 rend () const {
  464. return const_reverse_iterator2 (begin ());
  465. }
  466. #endif
  467. // Indices
  468. BOOST_UBLAS_INLINE
  469. size_type index1 () const {
  470. return it1_.index ();
  471. }
  472. BOOST_UBLAS_INLINE
  473. size_type index2 () const {
  474. return it2_.index ();
  475. }
  476. // Assignment
  477. BOOST_UBLAS_INLINE
  478. const_iterator1 &operator = (const const_iterator1 &it) {
  479. container_const_reference<self_type>::assign (&it ());
  480. it1_ = it.it1_;
  481. it2_ = it.it2_;
  482. #ifdef BOOST_UBLAS_USE_INVARIANT_HOISTING
  483. t2_ = it.t2_;
  484. #endif
  485. return *this;
  486. }
  487. // Comparison
  488. BOOST_UBLAS_INLINE
  489. bool operator == (const const_iterator1 &it) const {
  490. BOOST_UBLAS_CHECK ((*this) ().same_closure (it ()), external_logic ());
  491. BOOST_UBLAS_CHECK (it2_ == it.it2_, external_logic ());
  492. return it1_ == it.it1_;
  493. }
  494. BOOST_UBLAS_INLINE
  495. bool operator < (const const_iterator1 &it) const {
  496. BOOST_UBLAS_CHECK ((*this) ().same_closure (it ()), external_logic ());
  497. BOOST_UBLAS_CHECK (it2_ == it.it2_, external_logic ());
  498. return it1_ < it.it1_;
  499. }
  500. private:
  501. #ifdef BOOST_UBLAS_USE_INVARIANT_HOISTING
  502. const_subiterator1_type it1_;
  503. // Mutable due to assignment
  504. /* const */ const_subiterator2_type it2_;
  505. value_type t2_;
  506. #else
  507. const_subiterator1_type it1_;
  508. const_subiterator2_type it2_;
  509. #endif
  510. };
  511. #endif
  512. BOOST_UBLAS_INLINE
  513. const_iterator1 begin1 () const {
  514. return find1 (0, 0, 0);
  515. }
  516. BOOST_UBLAS_INLINE
  517. const_iterator1 end1 () const {
  518. return find1 (0, size1 (), 0);
  519. }
  520. #ifndef BOOST_UBLAS_USE_INDEXED_ITERATOR
  521. class const_iterator2:
  522. public container_const_reference<vector_matrix_binary>,
  523. public iterator_base_traits<typename iterator_restrict_traits<typename E1::const_iterator::iterator_category,
  524. typename E2::const_iterator::iterator_category>::iterator_category>::template
  525. iterator_base<const_iterator2, value_type>::type {
  526. public:
  527. typedef typename iterator_restrict_traits<typename E1::const_iterator::iterator_category,
  528. typename E2::const_iterator::iterator_category>::iterator_category iterator_category;
  529. typedef typename vector_matrix_binary::difference_type difference_type;
  530. typedef typename vector_matrix_binary::value_type value_type;
  531. typedef typename vector_matrix_binary::const_reference reference;
  532. typedef typename vector_matrix_binary::const_pointer pointer;
  533. typedef const_iterator1 dual_iterator_type;
  534. typedef const_reverse_iterator1 dual_reverse_iterator_type;
  535. // Construction and destruction
  536. #ifdef BOOST_UBLAS_USE_INVARIANT_HOISTING
  537. BOOST_UBLAS_INLINE
  538. const_iterator2 ():
  539. container_const_reference<self_type> (), it1_ (), it2_ (), t1_ () {}
  540. BOOST_UBLAS_INLINE
  541. const_iterator2 (const self_type &vmb, const const_subiterator1_type &it1, const const_subiterator2_type &it2, value_type t1):
  542. container_const_reference<self_type> (vmb), it1_ (it1), it2_ (it2), t1_ (t1) {}
  543. #else
  544. BOOST_UBLAS_INLINE
  545. const_iterator2 ():
  546. container_const_reference<self_type> (), it1_ (), it2_ () {}
  547. BOOST_UBLAS_INLINE
  548. const_iterator2 (const self_type &vmb, const const_subiterator1_type &it1, const const_subiterator2_type &it2):
  549. container_const_reference<self_type> (vmb), it1_ (it1), it2_ (it2) {}
  550. #endif
  551. // Arithmetic
  552. BOOST_UBLAS_INLINE
  553. const_iterator2 &operator ++ () {
  554. ++ it2_;
  555. return *this;
  556. }
  557. BOOST_UBLAS_INLINE
  558. const_iterator2 &operator -- () {
  559. -- it2_;
  560. return *this;
  561. }
  562. BOOST_UBLAS_INLINE
  563. const_iterator2 &operator += (difference_type n) {
  564. it2_ += n;
  565. return *this;
  566. }
  567. BOOST_UBLAS_INLINE
  568. const_iterator2 &operator -= (difference_type n) {
  569. it2_ -= n;
  570. return *this;
  571. }
  572. BOOST_UBLAS_INLINE
  573. difference_type operator - (const const_iterator2 &it) const {
  574. BOOST_UBLAS_CHECK ((*this) ().same_closure(it ()), external_logic ());
  575. BOOST_UBLAS_CHECK (it1_ == it.it1_, external_logic ());
  576. return it2_ - it.it2_;
  577. }
  578. // Dereference
  579. BOOST_UBLAS_INLINE
  580. const_reference operator * () const {
  581. #ifdef BOOST_UBLAS_USE_INVARIANT_HOISTING
  582. return functor_type::apply (t1_, *it2_);
  583. #else
  584. return functor_type::apply (*it1_, *it2_);
  585. #endif
  586. }
  587. BOOST_UBLAS_INLINE
  588. const_reference operator [] (difference_type n) const {
  589. return *(*this + n);
  590. }
  591. #ifndef BOOST_UBLAS_NO_NESTED_CLASS_RELATION
  592. BOOST_UBLAS_INLINE
  593. #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
  594. typename self_type::
  595. #endif
  596. const_iterator1 begin () const {
  597. return (*this) ().find1 (1, 0, index2 ());
  598. }
  599. BOOST_UBLAS_INLINE
  600. #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
  601. typename self_type::
  602. #endif
  603. const_iterator1 end () const {
  604. return (*this) ().find1 (1, (*this) ().size1 (), index2 ());
  605. }
  606. BOOST_UBLAS_INLINE
  607. #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
  608. typename self_type::
  609. #endif
  610. const_reverse_iterator1 rbegin () const {
  611. return const_reverse_iterator1 (end ());
  612. }
  613. BOOST_UBLAS_INLINE
  614. #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
  615. typename self_type::
  616. #endif
  617. const_reverse_iterator1 rend () const {
  618. return const_reverse_iterator1 (begin ());
  619. }
  620. #endif
  621. // Indices
  622. BOOST_UBLAS_INLINE
  623. size_type index1 () const {
  624. return it1_.index ();
  625. }
  626. BOOST_UBLAS_INLINE
  627. size_type index2 () const {
  628. return it2_.index ();
  629. }
  630. // Assignment
  631. BOOST_UBLAS_INLINE
  632. const_iterator2 &operator = (const const_iterator2 &it) {
  633. container_const_reference<self_type>::assign (&it ());
  634. it1_ = it.it1_;
  635. it2_ = it.it2_;
  636. #ifdef BOOST_UBLAS_USE_INVARIANT_HOISTING
  637. t1_ = it.t1_;
  638. #endif
  639. return *this;
  640. }
  641. // Comparison
  642. BOOST_UBLAS_INLINE
  643. bool operator == (const const_iterator2 &it) const {
  644. BOOST_UBLAS_CHECK ((*this) ().same_closure( it ()), external_logic ());
  645. BOOST_UBLAS_CHECK (it1_ == it.it1_, external_logic ());
  646. return it2_ == it.it2_;
  647. }
  648. BOOST_UBLAS_INLINE
  649. bool operator < (const const_iterator2 &it) const {
  650. BOOST_UBLAS_CHECK ((*this) ().same_closure (it ()), external_logic ());
  651. BOOST_UBLAS_CHECK (it1_ == it.it1_, external_logic ());
  652. return it2_ < it.it2_;
  653. }
  654. private:
  655. #ifdef BOOST_UBLAS_USE_INVARIANT_HOISTING
  656. // Mutable due to assignment
  657. /* const */ const_subiterator1_type it1_;
  658. const_subiterator2_type it2_;
  659. value_type t1_;
  660. #else
  661. const_subiterator1_type it1_;
  662. const_subiterator2_type it2_;
  663. #endif
  664. };
  665. #endif
  666. BOOST_UBLAS_INLINE
  667. const_iterator2 begin2 () const {
  668. return find2 (0, 0, 0);
  669. }
  670. BOOST_UBLAS_INLINE
  671. const_iterator2 end2 () const {
  672. return find2 (0, 0, size2 ());
  673. }
  674. // Reverse iterators
  675. BOOST_UBLAS_INLINE
  676. const_reverse_iterator1 rbegin1 () const {
  677. return const_reverse_iterator1 (end1 ());
  678. }
  679. BOOST_UBLAS_INLINE
  680. const_reverse_iterator1 rend1 () const {
  681. return const_reverse_iterator1 (begin1 ());
  682. }
  683. BOOST_UBLAS_INLINE
  684. const_reverse_iterator2 rbegin2 () const {
  685. return const_reverse_iterator2 (end2 ());
  686. }
  687. BOOST_UBLAS_INLINE
  688. const_reverse_iterator2 rend2 () const {
  689. return const_reverse_iterator2 (begin2 ());
  690. }
  691. private:
  692. expression1_closure_type e1_;
  693. expression2_closure_type e2_;
  694. };
  695. template<class E1, class E2, class F>
  696. struct vector_matrix_binary_traits {
  697. typedef vector_matrix_binary<E1, E2, F> expression_type;
  698. #ifndef BOOST_UBLAS_SIMPLE_ET_DEBUG
  699. typedef expression_type result_type;
  700. #else
  701. // ISSUE matrix is arbitary temporary type
  702. typedef matrix<typename F::value_type> result_type;
  703. #endif
  704. };
  705. // (outer_prod (v1, v2)) [i] [j] = v1 [i] * v2 [j]
  706. template<class E1, class E2>
  707. BOOST_UBLAS_INLINE
  708. typename vector_matrix_binary_traits<E1, E2, scalar_multiplies<typename E1::value_type, typename E2::value_type> >::result_type
  709. outer_prod (const vector_expression<E1> &e1,
  710. const vector_expression<E2> &e2) {
  711. BOOST_STATIC_ASSERT (E1::complexity == 0 && E2::complexity == 0);
  712. typedef typename vector_matrix_binary_traits<E1, E2, scalar_multiplies<typename E1::value_type, typename E2::value_type> >::expression_type expression_type;
  713. return expression_type (e1 (), e2 ());
  714. }
  715. template<class E, class F>
  716. class matrix_unary1:
  717. public matrix_expression<matrix_unary1<E, F> > {
  718. typedef E expression_type;
  719. typedef F functor_type;
  720. public:
  721. typedef typename E::const_closure_type expression_closure_type;
  722. private:
  723. typedef matrix_unary1<E, F> self_type;
  724. public:
  725. #ifdef BOOST_UBLAS_ENABLE_PROXY_SHORTCUTS
  726. using matrix_expression<self_type>::operator ();
  727. #endif
  728. typedef typename E::size_type size_type;
  729. typedef typename E::difference_type difference_type;
  730. typedef typename F::result_type value_type;
  731. typedef value_type const_reference;
  732. typedef const_reference reference;
  733. typedef const self_type const_closure_type;
  734. typedef const_closure_type closure_type;
  735. typedef typename E::orientation_category orientation_category;
  736. typedef unknown_storage_tag storage_category;
  737. // Construction and destruction
  738. BOOST_UBLAS_INLINE
  739. explicit matrix_unary1 (const expression_type &e):
  740. e_ (e) {}
  741. // Accessors
  742. BOOST_UBLAS_INLINE
  743. size_type size1 () const {
  744. return e_.size1 ();
  745. }
  746. BOOST_UBLAS_INLINE
  747. size_type size2 () const {
  748. return e_.size2 ();
  749. }
  750. public:
  751. // Expression accessors
  752. BOOST_UBLAS_INLINE
  753. const expression_closure_type &expression () const {
  754. return e_;
  755. }
  756. public:
  757. // Element access
  758. BOOST_UBLAS_INLINE
  759. const_reference operator () (size_type i, size_type j) const {
  760. return functor_type::apply (e_ (i, j));
  761. }
  762. // Closure comparison
  763. BOOST_UBLAS_INLINE
  764. bool same_closure (const matrix_unary1 &mu1) const {
  765. return (*this).expression ().same_closure (mu1.expression ());
  766. }
  767. // Iterator types
  768. private:
  769. typedef typename E::const_iterator1 const_subiterator1_type;
  770. typedef typename E::const_iterator2 const_subiterator2_type;
  771. typedef const value_type *const_pointer;
  772. public:
  773. #ifdef BOOST_UBLAS_USE_INDEXED_ITERATOR
  774. typedef indexed_const_iterator1<const_closure_type, typename const_subiterator1_type::iterator_category> const_iterator1;
  775. typedef const_iterator1 iterator1;
  776. typedef indexed_const_iterator2<const_closure_type, typename const_subiterator2_type::iterator_category> const_iterator2;
  777. typedef const_iterator2 iterator2;
  778. #else
  779. class const_iterator1;
  780. typedef const_iterator1 iterator1;
  781. class const_iterator2;
  782. typedef const_iterator2 iterator2;
  783. #endif
  784. typedef reverse_iterator_base1<const_iterator1> const_reverse_iterator1;
  785. typedef reverse_iterator_base2<const_iterator2> const_reverse_iterator2;
  786. // Element lookup
  787. BOOST_UBLAS_INLINE
  788. const_iterator1 find1 (int rank, size_type i, size_type j) const {
  789. const_subiterator1_type it1 (e_.find1 (rank, i, j));
  790. #ifdef BOOST_UBLAS_USE_INDEXED_ITERATOR
  791. return const_iterator1 (*this, it1.index1 (), it1.index2 ());
  792. #else
  793. return const_iterator1 (*this, it1);
  794. #endif
  795. }
  796. BOOST_UBLAS_INLINE
  797. const_iterator2 find2 (int rank, size_type i, size_type j) const {
  798. const_subiterator2_type it2 (e_.find2 (rank, i, j));
  799. #ifdef BOOST_UBLAS_USE_INDEXED_ITERATOR
  800. return const_iterator2 (*this, it2.index1 (), it2.index2 ());
  801. #else
  802. return const_iterator2 (*this, it2);
  803. #endif
  804. }
  805. // Iterators enhance the iterators of the referenced expression
  806. // with the unary functor.
  807. #ifndef BOOST_UBLAS_USE_INDEXED_ITERATOR
  808. class const_iterator1:
  809. public container_const_reference<matrix_unary1>,
  810. public iterator_base_traits<typename E::const_iterator1::iterator_category>::template
  811. iterator_base<const_iterator1, value_type>::type {
  812. public:
  813. typedef typename E::const_iterator1::iterator_category iterator_category;
  814. typedef typename matrix_unary1::difference_type difference_type;
  815. typedef typename matrix_unary1::value_type value_type;
  816. typedef typename matrix_unary1::const_reference reference;
  817. typedef typename matrix_unary1::const_pointer pointer;
  818. typedef const_iterator2 dual_iterator_type;
  819. typedef const_reverse_iterator2 dual_reverse_iterator_type;
  820. // Construction and destruction
  821. BOOST_UBLAS_INLINE
  822. const_iterator1 ():
  823. container_const_reference<self_type> (), it_ () {}
  824. BOOST_UBLAS_INLINE
  825. const_iterator1 (const self_type &mu, const const_subiterator1_type &it):
  826. container_const_reference<self_type> (mu), it_ (it) {}
  827. // Arithmetic
  828. BOOST_UBLAS_INLINE
  829. const_iterator1 &operator ++ () {
  830. ++ it_;
  831. return *this;
  832. }
  833. BOOST_UBLAS_INLINE
  834. const_iterator1 &operator -- () {
  835. -- it_;
  836. return *this;
  837. }
  838. BOOST_UBLAS_INLINE
  839. const_iterator1 &operator += (difference_type n) {
  840. it_ += n;
  841. return *this;
  842. }
  843. BOOST_UBLAS_INLINE
  844. const_iterator1 &operator -= (difference_type n) {
  845. it_ -= n;
  846. return *this;
  847. }
  848. BOOST_UBLAS_INLINE
  849. difference_type operator - (const const_iterator1 &it) const {
  850. BOOST_UBLAS_CHECK ((*this) ().same_closure (it ()), external_logic ());
  851. return it_ - it.it_;
  852. }
  853. // Dereference
  854. BOOST_UBLAS_INLINE
  855. const_reference operator * () const {
  856. return functor_type::apply (*it_);
  857. }
  858. BOOST_UBLAS_INLINE
  859. const_reference operator [] (difference_type n) const {
  860. return *(*this + n);
  861. }
  862. #ifndef BOOST_UBLAS_NO_NESTED_CLASS_RELATION
  863. BOOST_UBLAS_INLINE
  864. #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
  865. typename self_type::
  866. #endif
  867. const_iterator2 begin () const {
  868. return (*this) ().find2 (1, index1 (), 0);
  869. }
  870. BOOST_UBLAS_INLINE
  871. #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
  872. typename self_type::
  873. #endif
  874. const_iterator2 end () const {
  875. return (*this) ().find2 (1, index1 (), (*this) ().size2 ());
  876. }
  877. BOOST_UBLAS_INLINE
  878. #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
  879. typename self_type::
  880. #endif
  881. const_reverse_iterator2 rbegin () const {
  882. return const_reverse_iterator2 (end ());
  883. }
  884. BOOST_UBLAS_INLINE
  885. #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
  886. typename self_type::
  887. #endif
  888. const_reverse_iterator2 rend () const {
  889. return const_reverse_iterator2 (begin ());
  890. }
  891. #endif
  892. // Indices
  893. BOOST_UBLAS_INLINE
  894. size_type index1 () const {
  895. return it_.index1 ();
  896. }
  897. BOOST_UBLAS_INLINE
  898. size_type index2 () const {
  899. return it_.index2 ();
  900. }
  901. // Assignment
  902. BOOST_UBLAS_INLINE
  903. const_iterator1 &operator = (const const_iterator1 &it) {
  904. container_const_reference<self_type>::assign (&it ());
  905. it_ = it.it_;
  906. return *this;
  907. }
  908. // Comparison
  909. BOOST_UBLAS_INLINE
  910. bool operator == (const const_iterator1 &it) const {
  911. BOOST_UBLAS_CHECK ((*this) ().same_closure (it ()), external_logic ());
  912. return it_ == it.it_;
  913. }
  914. BOOST_UBLAS_INLINE
  915. bool operator < (const const_iterator1 &it) const {
  916. BOOST_UBLAS_CHECK ((*this) ().same_closure (it ()), external_logic ());
  917. return it_ < it.it_;
  918. }
  919. private:
  920. const_subiterator1_type it_;
  921. };
  922. #endif
  923. BOOST_UBLAS_INLINE
  924. const_iterator1 begin1 () const {
  925. return find1 (0, 0, 0);
  926. }
  927. BOOST_UBLAS_INLINE
  928. const_iterator1 end1 () const {
  929. return find1 (0, size1 (), 0);
  930. }
  931. #ifndef BOOST_UBLAS_USE_INDEXED_ITERATOR
  932. class const_iterator2:
  933. public container_const_reference<matrix_unary1>,
  934. public iterator_base_traits<typename E::const_iterator2::iterator_category>::template
  935. iterator_base<const_iterator2, value_type>::type {
  936. public:
  937. typedef typename E::const_iterator2::iterator_category iterator_category;
  938. typedef typename matrix_unary1::difference_type difference_type;
  939. typedef typename matrix_unary1::value_type value_type;
  940. typedef typename matrix_unary1::const_reference reference;
  941. typedef typename matrix_unary1::const_pointer pointer;
  942. typedef const_iterator1 dual_iterator_type;
  943. typedef const_reverse_iterator1 dual_reverse_iterator_type;
  944. // Construction and destruction
  945. BOOST_UBLAS_INLINE
  946. const_iterator2 ():
  947. container_const_reference<self_type> (), it_ () {}
  948. BOOST_UBLAS_INLINE
  949. const_iterator2 (const self_type &mu, const const_subiterator2_type &it):
  950. container_const_reference<self_type> (mu), it_ (it) {}
  951. // Arithmetic
  952. BOOST_UBLAS_INLINE
  953. const_iterator2 &operator ++ () {
  954. ++ it_;
  955. return *this;
  956. }
  957. BOOST_UBLAS_INLINE
  958. const_iterator2 &operator -- () {
  959. -- it_;
  960. return *this;
  961. }
  962. BOOST_UBLAS_INLINE
  963. const_iterator2 &operator += (difference_type n) {
  964. it_ += n;
  965. return *this;
  966. }
  967. BOOST_UBLAS_INLINE
  968. const_iterator2 &operator -= (difference_type n) {
  969. it_ -= n;
  970. return *this;
  971. }
  972. BOOST_UBLAS_INLINE
  973. difference_type operator - (const const_iterator2 &it) const {
  974. BOOST_UBLAS_CHECK ((*this) ().same_closure (it ()), external_logic ());
  975. return it_ - it.it_;
  976. }
  977. // Dereference
  978. BOOST_UBLAS_INLINE
  979. const_reference operator * () const {
  980. return functor_type::apply (*it_);
  981. }
  982. BOOST_UBLAS_INLINE
  983. const_reference operator [] (difference_type n) const {
  984. return *(*this + n);
  985. }
  986. #ifndef BOOST_UBLAS_NO_NESTED_CLASS_RELATION
  987. BOOST_UBLAS_INLINE
  988. #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
  989. typename self_type::
  990. #endif
  991. const_iterator1 begin () const {
  992. return (*this) ().find1 (1, 0, index2 ());
  993. }
  994. BOOST_UBLAS_INLINE
  995. #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
  996. typename self_type::
  997. #endif
  998. const_iterator1 end () const {
  999. return (*this) ().find1 (1, (*this) ().size1 (), index2 ());
  1000. }
  1001. BOOST_UBLAS_INLINE
  1002. #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
  1003. typename self_type::
  1004. #endif
  1005. const_reverse_iterator1 rbegin () const {
  1006. return const_reverse_iterator1 (end ());
  1007. }
  1008. BOOST_UBLAS_INLINE
  1009. #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
  1010. typename self_type::
  1011. #endif
  1012. const_reverse_iterator1 rend () const {
  1013. return const_reverse_iterator1 (begin ());
  1014. }
  1015. #endif
  1016. // Indices
  1017. BOOST_UBLAS_INLINE
  1018. size_type index1 () const {
  1019. return it_.index1 ();
  1020. }
  1021. BOOST_UBLAS_INLINE
  1022. size_type index2 () const {
  1023. return it_.index2 ();
  1024. }
  1025. // Assignment
  1026. BOOST_UBLAS_INLINE
  1027. const_iterator2 &operator = (const const_iterator2 &it) {
  1028. container_const_reference<self_type>::assign (&it ());
  1029. it_ = it.it_;
  1030. return *this;
  1031. }
  1032. // Comparison
  1033. BOOST_UBLAS_INLINE
  1034. bool operator == (const const_iterator2 &it) const {
  1035. BOOST_UBLAS_CHECK ((*this) ().same_closure (it ()), external_logic ());
  1036. return it_ == it.it_;
  1037. }
  1038. BOOST_UBLAS_INLINE
  1039. bool operator < (const const_iterator2 &it) const {
  1040. BOOST_UBLAS_CHECK ((*this) ().same_closure (it ()), external_logic ());
  1041. return it_ < it.it_;
  1042. }
  1043. private:
  1044. const_subiterator2_type it_;
  1045. };
  1046. #endif
  1047. BOOST_UBLAS_INLINE
  1048. const_iterator2 begin2 () const {
  1049. return find2 (0, 0, 0);
  1050. }
  1051. BOOST_UBLAS_INLINE
  1052. const_iterator2 end2 () const {
  1053. return find2 (0, 0, size2 ());
  1054. }
  1055. // Reverse iterators
  1056. BOOST_UBLAS_INLINE
  1057. const_reverse_iterator1 rbegin1 () const {
  1058. return const_reverse_iterator1 (end1 ());
  1059. }
  1060. BOOST_UBLAS_INLINE
  1061. const_reverse_iterator1 rend1 () const {
  1062. return const_reverse_iterator1 (begin1 ());
  1063. }
  1064. BOOST_UBLAS_INLINE
  1065. const_reverse_iterator2 rbegin2 () const {
  1066. return const_reverse_iterator2 (end2 ());
  1067. }
  1068. BOOST_UBLAS_INLINE
  1069. const_reverse_iterator2 rend2 () const {
  1070. return const_reverse_iterator2 (begin2 ());
  1071. }
  1072. private:
  1073. expression_closure_type e_;
  1074. };
  1075. template<class E, class F>
  1076. struct matrix_unary1_traits {
  1077. typedef matrix_unary1<E, F> expression_type;
  1078. #ifndef BOOST_UBLAS_SIMPLE_ET_DEBUG
  1079. typedef expression_type result_type;
  1080. #else
  1081. typedef typename E::matrix_temporary_type result_type;
  1082. #endif
  1083. };
  1084. // (- m) [i] [j] = - m [i] [j]
  1085. template<class E>
  1086. BOOST_UBLAS_INLINE
  1087. typename matrix_unary1_traits<E, scalar_negate<typename E::value_type> >::result_type
  1088. operator - (const matrix_expression<E> &e) {
  1089. typedef typename matrix_unary1_traits<E, scalar_negate<typename E::value_type> >::expression_type expression_type;
  1090. return expression_type (e ());
  1091. }
  1092. // (conj m) [i] [j] = conj (m [i] [j])
  1093. template<class E>
  1094. BOOST_UBLAS_INLINE
  1095. typename matrix_unary1_traits<E, scalar_conj<typename E::value_type> >::result_type
  1096. conj (const matrix_expression<E> &e) {
  1097. typedef typename matrix_unary1_traits<E, scalar_conj<typename E::value_type> >::expression_type expression_type;
  1098. return expression_type (e ());
  1099. }
  1100. // (real m) [i] [j] = real (m [i] [j])
  1101. template<class E>
  1102. BOOST_UBLAS_INLINE
  1103. typename matrix_unary1_traits<E, scalar_real<typename E::value_type> >::result_type
  1104. real (const matrix_expression<E> &e) {
  1105. typedef typename matrix_unary1_traits<E, scalar_real<typename E::value_type> >::expression_type expression_type;
  1106. return expression_type (e ());
  1107. }
  1108. // (imag m) [i] [j] = imag (m [i] [j])
  1109. template<class E>
  1110. BOOST_UBLAS_INLINE
  1111. typename matrix_unary1_traits<E, scalar_imag<typename E::value_type> >::result_type
  1112. imag (const matrix_expression<E> &e) {
  1113. typedef typename matrix_unary1_traits<E, scalar_imag<typename E::value_type> >::expression_type expression_type;
  1114. return expression_type (e ());
  1115. }
  1116. template<class E, class F>
  1117. class matrix_unary2:
  1118. public matrix_expression<matrix_unary2<E, F> > {
  1119. typedef typename boost::mpl::if_<boost::is_same<F, scalar_identity<typename E::value_type> >,
  1120. E,
  1121. const E>::type expression_type;
  1122. typedef F functor_type;
  1123. public:
  1124. typedef typename boost::mpl::if_<boost::is_const<expression_type>,
  1125. typename E::const_closure_type,
  1126. typename E::closure_type>::type expression_closure_type;
  1127. private:
  1128. typedef matrix_unary2<E, F> self_type;
  1129. public:
  1130. #ifdef BOOST_UBLAS_ENABLE_PROXY_SHORTCUTS
  1131. using matrix_expression<self_type>::operator ();
  1132. #endif
  1133. typedef typename E::size_type size_type;
  1134. typedef typename E::difference_type difference_type;
  1135. typedef typename F::result_type value_type;
  1136. typedef value_type const_reference;
  1137. typedef typename boost::mpl::if_<boost::is_same<F, scalar_identity<value_type> >,
  1138. typename E::reference,
  1139. value_type>::type reference;
  1140. typedef const self_type const_closure_type;
  1141. typedef self_type closure_type;
  1142. typedef typename boost::mpl::if_<boost::is_same<typename E::orientation_category,
  1143. row_major_tag>,
  1144. column_major_tag,
  1145. typename boost::mpl::if_<boost::is_same<typename E::orientation_category,
  1146. column_major_tag>,
  1147. row_major_tag,
  1148. typename E::orientation_category>::type>::type orientation_category;
  1149. typedef typename E::storage_category storage_category;
  1150. // Construction and destruction
  1151. BOOST_UBLAS_INLINE
  1152. // matrix_unary2 may be used as mutable expression -
  1153. // this is the only non const expression constructor
  1154. explicit matrix_unary2 (expression_type &e):
  1155. e_ (e) {}
  1156. // Accessors
  1157. BOOST_UBLAS_INLINE
  1158. size_type size1 () const {
  1159. return e_.size2 ();
  1160. }
  1161. BOOST_UBLAS_INLINE
  1162. size_type size2 () const {
  1163. return e_.size1 ();
  1164. }
  1165. public:
  1166. // Expression accessors
  1167. BOOST_UBLAS_INLINE
  1168. const expression_closure_type &expression () const {
  1169. return e_;
  1170. }
  1171. public:
  1172. // Element access
  1173. BOOST_UBLAS_INLINE
  1174. const_reference operator () (size_type i, size_type j) const {
  1175. return functor_type::apply (e_ (j, i));
  1176. }
  1177. BOOST_UBLAS_INLINE
  1178. reference operator () (size_type i, size_type j) {
  1179. BOOST_STATIC_ASSERT ((boost::is_same<functor_type, scalar_identity<value_type > >::value));
  1180. return e_ (j, i);
  1181. }
  1182. // Closure comparison
  1183. BOOST_UBLAS_INLINE
  1184. bool same_closure (const matrix_unary2 &mu2) const {
  1185. return (*this).expression ().same_closure (mu2.expression ());
  1186. }
  1187. // Iterator types
  1188. private:
  1189. typedef typename E::const_iterator1 const_subiterator2_type;
  1190. typedef typename E::const_iterator2 const_subiterator1_type;
  1191. typedef const value_type *const_pointer;
  1192. public:
  1193. #ifdef BOOST_UBLAS_USE_INDEXED_ITERATOR
  1194. typedef indexed_const_iterator1<const_closure_type, typename const_subiterator1_type::iterator_category> const_iterator1;
  1195. typedef const_iterator1 iterator1;
  1196. typedef indexed_const_iterator2<const_closure_type, typename const_subiterator2_type::iterator_category> const_iterator2;
  1197. typedef const_iterator2 iterator2;
  1198. #else
  1199. class const_iterator1;
  1200. typedef const_iterator1 iterator1;
  1201. class const_iterator2;
  1202. typedef const_iterator2 iterator2;
  1203. #endif
  1204. typedef reverse_iterator_base1<const_iterator1> const_reverse_iterator1;
  1205. typedef reverse_iterator_base2<const_iterator2> const_reverse_iterator2;
  1206. // Element lookup
  1207. BOOST_UBLAS_INLINE
  1208. const_iterator1 find1 (int rank, size_type i, size_type j) const {
  1209. const_subiterator1_type it1 (e_.find2 (rank, j, i));
  1210. #ifdef BOOST_UBLAS_USE_INDEXED_ITERATOR
  1211. return const_iterator1 (*this, it1.index2 (), it1.index1 ());
  1212. #else
  1213. return const_iterator1 (*this, it1);
  1214. #endif
  1215. }
  1216. BOOST_UBLAS_INLINE
  1217. const_iterator2 find2 (int rank, size_type i, size_type j) const {
  1218. const_subiterator2_type it2 (e_.find1 (rank, j, i));
  1219. #ifdef BOOST_UBLAS_USE_INDEXED_ITERATOR
  1220. return const_iterator2 (*this, it2.index2 (), it2.index1 ());
  1221. #else
  1222. return const_iterator2 (*this, it2);
  1223. #endif
  1224. }
  1225. // Iterators enhance the iterators of the referenced expression
  1226. // with the unary functor.
  1227. #ifndef BOOST_UBLAS_USE_INDEXED_ITERATOR
  1228. class const_iterator1:
  1229. public container_const_reference<matrix_unary2>,
  1230. public iterator_base_traits<typename E::const_iterator2::iterator_category>::template
  1231. iterator_base<const_iterator1, value_type>::type {
  1232. public:
  1233. typedef typename E::const_iterator2::iterator_category iterator_category;
  1234. typedef typename matrix_unary2::difference_type difference_type;
  1235. typedef typename matrix_unary2::value_type value_type;
  1236. typedef typename matrix_unary2::const_reference reference;
  1237. typedef typename matrix_unary2::const_pointer pointer;
  1238. typedef const_iterator2 dual_iterator_type;
  1239. typedef const_reverse_iterator2 dual_reverse_iterator_type;
  1240. // Construction and destruction
  1241. BOOST_UBLAS_INLINE
  1242. const_iterator1 ():
  1243. container_const_reference<self_type> (), it_ () {}
  1244. BOOST_UBLAS_INLINE
  1245. const_iterator1 (const self_type &mu, const const_subiterator1_type &it):
  1246. container_const_reference<self_type> (mu), it_ (it) {}
  1247. // Arithmetic
  1248. BOOST_UBLAS_INLINE
  1249. const_iterator1 &operator ++ () {
  1250. ++ it_;
  1251. return *this;
  1252. }
  1253. BOOST_UBLAS_INLINE
  1254. const_iterator1 &operator -- () {
  1255. -- it_;
  1256. return *this;
  1257. }
  1258. BOOST_UBLAS_INLINE
  1259. const_iterator1 &operator += (difference_type n) {
  1260. it_ += n;
  1261. return *this;
  1262. }
  1263. BOOST_UBLAS_INLINE
  1264. const_iterator1 &operator -= (difference_type n) {
  1265. it_ -= n;
  1266. return *this;
  1267. }
  1268. BOOST_UBLAS_INLINE
  1269. difference_type operator - (const const_iterator1 &it) const {
  1270. BOOST_UBLAS_CHECK ((*this) ().same_closure (it ()), external_logic ());
  1271. return it_ - it.it_;
  1272. }
  1273. // Dereference
  1274. BOOST_UBLAS_INLINE
  1275. const_reference operator * () const {
  1276. return functor_type::apply (*it_);
  1277. }
  1278. BOOST_UBLAS_INLINE
  1279. const_reference operator [] (difference_type n) const {
  1280. return *(*this + n);
  1281. }
  1282. #ifndef BOOST_UBLAS_NO_NESTED_CLASS_RELATION
  1283. BOOST_UBLAS_INLINE
  1284. #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
  1285. typename self_type::
  1286. #endif
  1287. const_iterator2 begin () const {
  1288. return (*this) ().find2 (1, index1 (), 0);
  1289. }
  1290. BOOST_UBLAS_INLINE
  1291. #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
  1292. typename self_type::
  1293. #endif
  1294. const_iterator2 end () const {
  1295. return (*this) ().find2 (1, index1 (), (*this) ().size2 ());
  1296. }
  1297. BOOST_UBLAS_INLINE
  1298. #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
  1299. typename self_type::
  1300. #endif
  1301. const_reverse_iterator2 rbegin () const {
  1302. return const_reverse_iterator2 (end ());
  1303. }
  1304. BOOST_UBLAS_INLINE
  1305. #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
  1306. typename self_type::
  1307. #endif
  1308. const_reverse_iterator2 rend () const {
  1309. return const_reverse_iterator2 (begin ());
  1310. }
  1311. #endif
  1312. // Indices
  1313. BOOST_UBLAS_INLINE
  1314. size_type index1 () const {
  1315. return it_.index2 ();
  1316. }
  1317. BOOST_UBLAS_INLINE
  1318. size_type index2 () const {
  1319. return it_.index1 ();
  1320. }
  1321. // Assignment
  1322. BOOST_UBLAS_INLINE
  1323. const_iterator1 &operator = (const const_iterator1 &it) {
  1324. container_const_reference<self_type>::assign (&it ());
  1325. it_ = it.it_;
  1326. return *this;
  1327. }
  1328. // Comparison
  1329. BOOST_UBLAS_INLINE
  1330. bool operator == (const const_iterator1 &it) const {
  1331. BOOST_UBLAS_CHECK ((*this) ().same_closure (it ()), external_logic ());
  1332. return it_ == it.it_;
  1333. }
  1334. BOOST_UBLAS_INLINE
  1335. bool operator < (const const_iterator1 &it) const {
  1336. BOOST_UBLAS_CHECK ((*this) ().same_closure (it ()), external_logic ());
  1337. return it_ < it.it_;
  1338. }
  1339. private:
  1340. const_subiterator1_type it_;
  1341. };
  1342. #endif
  1343. BOOST_UBLAS_INLINE
  1344. const_iterator1 begin1 () const {
  1345. return find1 (0, 0, 0);
  1346. }
  1347. BOOST_UBLAS_INLINE
  1348. const_iterator1 end1 () const {
  1349. return find1 (0, size1 (), 0);
  1350. }
  1351. #ifndef BOOST_UBLAS_USE_INDEXED_ITERATOR
  1352. class const_iterator2:
  1353. public container_const_reference<matrix_unary2>,
  1354. public iterator_base_traits<typename E::const_iterator1::iterator_category>::template
  1355. iterator_base<const_iterator2, value_type>::type {
  1356. public:
  1357. typedef typename E::const_iterator1::iterator_category iterator_category;
  1358. typedef typename matrix_unary2::difference_type difference_type;
  1359. typedef typename matrix_unary2::value_type value_type;
  1360. typedef typename matrix_unary2::const_reference reference;
  1361. typedef typename matrix_unary2::const_pointer pointer;
  1362. typedef const_iterator1 dual_iterator_type;
  1363. typedef const_reverse_iterator1 dual_reverse_iterator_type;
  1364. // Construction and destruction
  1365. BOOST_UBLAS_INLINE
  1366. const_iterator2 ():
  1367. container_const_reference<self_type> (), it_ () {}
  1368. BOOST_UBLAS_INLINE
  1369. const_iterator2 (const self_type &mu, const const_subiterator2_type &it):
  1370. container_const_reference<self_type> (mu), it_ (it) {}
  1371. // Arithmetic
  1372. BOOST_UBLAS_INLINE
  1373. const_iterator2 &operator ++ () {
  1374. ++ it_;
  1375. return *this;
  1376. }
  1377. BOOST_UBLAS_INLINE
  1378. const_iterator2 &operator -- () {
  1379. -- it_;
  1380. return *this;
  1381. }
  1382. BOOST_UBLAS_INLINE
  1383. const_iterator2 &operator += (difference_type n) {
  1384. it_ += n;
  1385. return *this;
  1386. }
  1387. BOOST_UBLAS_INLINE
  1388. const_iterator2 &operator -= (difference_type n) {
  1389. it_ -= n;
  1390. return *this;
  1391. }
  1392. BOOST_UBLAS_INLINE
  1393. difference_type operator - (const const_iterator2 &it) const {
  1394. BOOST_UBLAS_CHECK ((*this) ().same_closure (it ()), external_logic ());
  1395. return it_ - it.it_;
  1396. }
  1397. // Dereference
  1398. BOOST_UBLAS_INLINE
  1399. const_reference operator * () const {
  1400. return functor_type::apply (*it_);
  1401. }
  1402. BOOST_UBLAS_INLINE
  1403. const_reference operator [] (difference_type n) const {
  1404. return *(*this + n);
  1405. }
  1406. #ifndef BOOST_UBLAS_NO_NESTED_CLASS_RELATION
  1407. BOOST_UBLAS_INLINE
  1408. #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
  1409. typename self_type::
  1410. #endif
  1411. const_iterator1 begin () const {
  1412. return (*this) ().find1 (1, 0, index2 ());
  1413. }
  1414. BOOST_UBLAS_INLINE
  1415. #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
  1416. typename self_type::
  1417. #endif
  1418. const_iterator1 end () const {
  1419. return (*this) ().find1 (1, (*this) ().size1 (), index2 ());
  1420. }
  1421. BOOST_UBLAS_INLINE
  1422. #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
  1423. typename self_type::
  1424. #endif
  1425. const_reverse_iterator1 rbegin () const {
  1426. return const_reverse_iterator1 (end ());
  1427. }
  1428. BOOST_UBLAS_INLINE
  1429. #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
  1430. typename self_type::
  1431. #endif
  1432. const_reverse_iterator1 rend () const {
  1433. return const_reverse_iterator1 (begin ());
  1434. }
  1435. #endif
  1436. // Indices
  1437. BOOST_UBLAS_INLINE
  1438. size_type index1 () const {
  1439. return it_.index2 ();
  1440. }
  1441. BOOST_UBLAS_INLINE
  1442. size_type index2 () const {
  1443. return it_.index1 ();
  1444. }
  1445. // Assignment
  1446. BOOST_UBLAS_INLINE
  1447. const_iterator2 &operator = (const const_iterator2 &it) {
  1448. container_const_reference<self_type>::assign (&it ());
  1449. it_ = it.it_;
  1450. return *this;
  1451. }
  1452. // Comparison
  1453. BOOST_UBLAS_INLINE
  1454. bool operator == (const const_iterator2 &it) const {
  1455. BOOST_UBLAS_CHECK ((*this) ().same_closure (it ()), external_logic ());
  1456. return it_ == it.it_;
  1457. }
  1458. BOOST_UBLAS_INLINE
  1459. bool operator < (const const_iterator2 &it) const {
  1460. BOOST_UBLAS_CHECK ((*this) ().same_closure (it ()), external_logic ());
  1461. return it_ < it.it_;
  1462. }
  1463. private:
  1464. const_subiterator2_type it_;
  1465. };
  1466. #endif
  1467. BOOST_UBLAS_INLINE
  1468. const_iterator2 begin2 () const {
  1469. return find2 (0, 0, 0);
  1470. }
  1471. BOOST_UBLAS_INLINE
  1472. const_iterator2 end2 () const {
  1473. return find2 (0, 0, size2 ());
  1474. }
  1475. // Reverse iterators
  1476. BOOST_UBLAS_INLINE
  1477. const_reverse_iterator1 rbegin1 () const {
  1478. return const_reverse_iterator1 (end1 ());
  1479. }
  1480. BOOST_UBLAS_INLINE
  1481. const_reverse_iterator1 rend1 () const {
  1482. return const_reverse_iterator1 (begin1 ());
  1483. }
  1484. BOOST_UBLAS_INLINE
  1485. const_reverse_iterator2 rbegin2 () const {
  1486. return const_reverse_iterator2 (end2 ());
  1487. }
  1488. BOOST_UBLAS_INLINE
  1489. const_reverse_iterator2 rend2 () const {
  1490. return const_reverse_iterator2 (begin2 ());
  1491. }
  1492. private:
  1493. expression_closure_type e_;
  1494. };
  1495. template<class E, class F>
  1496. struct matrix_unary2_traits {
  1497. typedef matrix_unary2<E, F> expression_type;
  1498. #ifndef BOOST_UBLAS_SIMPLE_ET_DEBUG
  1499. typedef expression_type result_type;
  1500. #else
  1501. typedef typename E::matrix_temporary_type result_type;
  1502. #endif
  1503. };
  1504. // (trans m) [i] [j] = m [j] [i]
  1505. template<class E>
  1506. BOOST_UBLAS_INLINE
  1507. typename matrix_unary2_traits<const E, scalar_identity<typename E::value_type> >::result_type
  1508. trans (const matrix_expression<E> &e) {
  1509. typedef typename matrix_unary2_traits<const E, scalar_identity<typename E::value_type> >::expression_type expression_type;
  1510. return expression_type (e ());
  1511. }
  1512. template<class E>
  1513. BOOST_UBLAS_INLINE
  1514. typename matrix_unary2_traits<E, scalar_identity<typename E::value_type> >::result_type
  1515. trans (matrix_expression<E> &e) {
  1516. typedef typename matrix_unary2_traits<E, scalar_identity<typename E::value_type> >::expression_type expression_type;
  1517. return expression_type (e ());
  1518. }
  1519. // (herm m) [i] [j] = conj (m [j] [i])
  1520. template<class E>
  1521. BOOST_UBLAS_INLINE
  1522. typename matrix_unary2_traits<E, scalar_conj<typename E::value_type> >::result_type
  1523. herm (const matrix_expression<E> &e) {
  1524. typedef typename matrix_unary2_traits<E, scalar_conj<typename E::value_type> >::expression_type expression_type;
  1525. return expression_type (e ());
  1526. }
  1527. template<class E1, class E2, class F>
  1528. class matrix_binary:
  1529. public matrix_expression<matrix_binary<E1, E2, F> > {
  1530. typedef E1 expression1_type;
  1531. typedef E2 expression2_type;
  1532. typedef F functor_type;
  1533. public:
  1534. typedef typename E1::const_closure_type expression1_closure_type;
  1535. typedef typename E2::const_closure_type expression2_closure_type;
  1536. private:
  1537. typedef matrix_binary<E1, E2, F> self_type;
  1538. public:
  1539. #ifdef BOOST_UBLAS_ENABLE_PROXY_SHORTCUTS
  1540. using matrix_expression<self_type>::operator ();
  1541. #endif
  1542. typedef typename promote_traits<typename E1::size_type, typename E2::size_type>::promote_type size_type;
  1543. typedef typename promote_traits<typename E1::difference_type, typename E2::difference_type>::promote_type difference_type;
  1544. typedef typename F::result_type value_type;
  1545. typedef value_type const_reference;
  1546. typedef const_reference reference;
  1547. typedef const self_type const_closure_type;
  1548. typedef const_closure_type closure_type;
  1549. typedef unknown_orientation_tag orientation_category;
  1550. typedef unknown_storage_tag storage_category;
  1551. // Construction and destruction
  1552. BOOST_UBLAS_INLINE
  1553. matrix_binary (const E1 &e1, const E2 &e2):
  1554. e1_ (e1), e2_ (e2) {}
  1555. // Accessors
  1556. BOOST_UBLAS_INLINE
  1557. size_type size1 () const {
  1558. return BOOST_UBLAS_SAME (e1_.size1 (), e2_.size1 ());
  1559. }
  1560. BOOST_UBLAS_INLINE
  1561. size_type size2 () const {
  1562. return BOOST_UBLAS_SAME (e1_.size2 (), e2_.size2 ());
  1563. }
  1564. public:
  1565. // Expression accessors
  1566. BOOST_UBLAS_INLINE
  1567. const expression1_closure_type &expression1 () const {
  1568. return e1_;
  1569. }
  1570. BOOST_UBLAS_INLINE
  1571. const expression2_closure_type &expression2 () const {
  1572. return e2_;
  1573. }
  1574. public:
  1575. // Element access
  1576. BOOST_UBLAS_INLINE
  1577. const_reference operator () (size_type i, size_type j) const {
  1578. return functor_type::apply (e1_ (i, j), e2_ (i, j));
  1579. }
  1580. // Closure comparison
  1581. BOOST_UBLAS_INLINE
  1582. bool same_closure (const matrix_binary &mb) const {
  1583. return (*this).expression1 ().same_closure (mb.expression1 ()) &&
  1584. (*this).expression2 ().same_closure (mb.expression2 ());
  1585. }
  1586. // Iterator types
  1587. private:
  1588. typedef typename E1::const_iterator1 const_iterator11_type;
  1589. typedef typename E1::const_iterator2 const_iterator12_type;
  1590. typedef typename E2::const_iterator1 const_iterator21_type;
  1591. typedef typename E2::const_iterator2 const_iterator22_type;
  1592. typedef const value_type *const_pointer;
  1593. public:
  1594. #ifdef BOOST_UBLAS_USE_INDEXED_ITERATOR
  1595. typedef typename iterator_restrict_traits<typename const_iterator11_type::iterator_category,
  1596. typename const_iterator21_type::iterator_category>::iterator_category iterator_category1;
  1597. typedef indexed_const_iterator1<const_closure_type, iterator_category1> const_iterator1;
  1598. typedef const_iterator1 iterator1;
  1599. typedef typename iterator_restrict_traits<typename const_iterator12_type::iterator_category,
  1600. typename const_iterator22_type::iterator_category>::iterator_category iterator_category2;
  1601. typedef indexed_const_iterator2<const_closure_type, iterator_category2> const_iterator2;
  1602. typedef const_iterator2 iterator2;
  1603. #else
  1604. class const_iterator1;
  1605. typedef const_iterator1 iterator1;
  1606. class const_iterator2;
  1607. typedef const_iterator2 iterator2;
  1608. #endif
  1609. typedef reverse_iterator_base1<const_iterator1> const_reverse_iterator1;
  1610. typedef reverse_iterator_base2<const_iterator2> const_reverse_iterator2;
  1611. // Element lookup
  1612. BOOST_UBLAS_INLINE
  1613. const_iterator1 find1 (int rank, size_type i, size_type j) const {
  1614. const_iterator11_type it11 (e1_.find1 (rank, i, j));
  1615. const_iterator11_type it11_end (e1_.find1 (rank, size1 (), j));
  1616. const_iterator21_type it21 (e2_.find1 (rank, i, j));
  1617. const_iterator21_type it21_end (e2_.find1 (rank, size1 (), j));
  1618. BOOST_UBLAS_CHECK (rank == 0 || it11 == it11_end || it11.index2 () == j, internal_logic ())
  1619. BOOST_UBLAS_CHECK (rank == 0 || it21 == it21_end || it21.index2 () == j, internal_logic ())
  1620. i = (std::min) (it11 != it11_end ? it11.index1 () : size1 (),
  1621. it21 != it21_end ? it21.index1 () : size1 ());
  1622. #ifdef BOOST_UBLAS_USE_INDEXED_ITERATOR
  1623. return const_iterator1 (*this, i, j);
  1624. #else
  1625. return const_iterator1 (*this, i, j, it11, it11_end, it21, it21_end);
  1626. #endif
  1627. }
  1628. BOOST_UBLAS_INLINE
  1629. const_iterator2 find2 (int rank, size_type i, size_type j) const {
  1630. const_iterator12_type it12 (e1_.find2 (rank, i, j));
  1631. const_iterator12_type it12_end (e1_.find2 (rank, i, size2 ()));
  1632. const_iterator22_type it22 (e2_.find2 (rank, i, j));
  1633. const_iterator22_type it22_end (e2_.find2 (rank, i, size2 ()));
  1634. BOOST_UBLAS_CHECK (rank == 0 || it12 == it12_end || it12.index1 () == i, internal_logic ())
  1635. BOOST_UBLAS_CHECK (rank == 0 || it22 == it22_end || it22.index1 () == i, internal_logic ())
  1636. j = (std::min) (it12 != it12_end ? it12.index2 () : size2 (),
  1637. it22 != it22_end ? it22.index2 () : size2 ());
  1638. #ifdef BOOST_UBLAS_USE_INDEXED_ITERATOR
  1639. return const_iterator2 (*this, i, j);
  1640. #else
  1641. return const_iterator2 (*this, i, j, it12, it12_end, it22, it22_end);
  1642. #endif
  1643. }
  1644. // Iterators enhance the iterators of the referenced expression
  1645. // with the binary functor.
  1646. #ifndef BOOST_UBLAS_USE_INDEXED_ITERATOR
  1647. class const_iterator1:
  1648. public container_const_reference<matrix_binary>,
  1649. public iterator_base_traits<typename iterator_restrict_traits<typename E1::const_iterator1::iterator_category,
  1650. typename E2::const_iterator1::iterator_category>::iterator_category>::template
  1651. iterator_base<const_iterator1, value_type>::type {
  1652. public:
  1653. typedef typename iterator_restrict_traits<typename E1::const_iterator1::iterator_category,
  1654. typename E2::const_iterator1::iterator_category>::iterator_category iterator_category;
  1655. typedef typename matrix_binary::difference_type difference_type;
  1656. typedef typename matrix_binary::value_type value_type;
  1657. typedef typename matrix_binary::const_reference reference;
  1658. typedef typename matrix_binary::const_pointer pointer;
  1659. typedef const_iterator2 dual_iterator_type;
  1660. typedef const_reverse_iterator2 dual_reverse_iterator_type;
  1661. // Construction and destruction
  1662. BOOST_UBLAS_INLINE
  1663. const_iterator1 ():
  1664. container_const_reference<self_type> (), i_ (), j_ (), it1_ (), it1_end_ (), it2_ (), it2_end_ () {}
  1665. BOOST_UBLAS_INLINE
  1666. const_iterator1 (const self_type &mb, size_type i, size_type j,
  1667. const const_iterator11_type &it1, const const_iterator11_type &it1_end,
  1668. const const_iterator21_type &it2, const const_iterator21_type &it2_end):
  1669. container_const_reference<self_type> (mb), i_ (i), j_ (j), it1_ (it1), it1_end_ (it1_end), it2_ (it2), it2_end_ (it2_end) {}
  1670. private:
  1671. // Dense specializations
  1672. BOOST_UBLAS_INLINE
  1673. void increment (dense_random_access_iterator_tag) {
  1674. ++ i_; ++ it1_; ++ it2_;
  1675. }
  1676. BOOST_UBLAS_INLINE
  1677. void decrement (dense_random_access_iterator_tag) {
  1678. -- i_; -- it1_; -- it2_;
  1679. }
  1680. BOOST_UBLAS_INLINE
  1681. void increment (dense_random_access_iterator_tag, difference_type n) {
  1682. i_ += n; it1_ += n; it2_ += n;
  1683. }
  1684. BOOST_UBLAS_INLINE
  1685. void decrement (dense_random_access_iterator_tag, difference_type n) {
  1686. i_ -= n; it1_ -= n; it2_ -= n;
  1687. }
  1688. BOOST_UBLAS_INLINE
  1689. value_type dereference (dense_random_access_iterator_tag) const {
  1690. return functor_type::apply (*it1_, *it2_);
  1691. }
  1692. // Packed specializations
  1693. BOOST_UBLAS_INLINE
  1694. void increment (packed_random_access_iterator_tag) {
  1695. if (it1_ != it1_end_)
  1696. if (it1_.index1 () <= i_)
  1697. ++ it1_;
  1698. if (it2_ != it2_end_)
  1699. if (it2_.index1 () <= i_)
  1700. ++ it2_;
  1701. ++ i_;
  1702. }
  1703. BOOST_UBLAS_INLINE
  1704. void decrement (packed_random_access_iterator_tag) {
  1705. if (it1_ != it1_end_)
  1706. if (i_ <= it1_.index1 ())
  1707. -- it1_;
  1708. if (it2_ != it2_end_)
  1709. if (i_ <= it2_.index1 ())
  1710. -- it2_;
  1711. -- i_;
  1712. }
  1713. BOOST_UBLAS_INLINE
  1714. void increment (packed_random_access_iterator_tag, difference_type n) {
  1715. while (n > 0) {
  1716. increment (packed_random_access_iterator_tag ());
  1717. --n;
  1718. }
  1719. while (n < 0) {
  1720. decrement (packed_random_access_iterator_tag ());
  1721. ++n;
  1722. }
  1723. }
  1724. BOOST_UBLAS_INLINE
  1725. void decrement (packed_random_access_iterator_tag, difference_type n) {
  1726. while (n > 0) {
  1727. decrement (packed_random_access_iterator_tag ());
  1728. --n;
  1729. }
  1730. while (n < 0) {
  1731. increment (packed_random_access_iterator_tag ());
  1732. ++n;
  1733. }
  1734. }
  1735. BOOST_UBLAS_INLINE
  1736. value_type dereference (packed_random_access_iterator_tag) const {
  1737. value_type t1 = value_type/*zero*/();
  1738. if (it1_ != it1_end_) {
  1739. BOOST_UBLAS_CHECK (it1_.index2 () == j_, internal_logic ());
  1740. if (it1_.index1 () == i_)
  1741. t1 = *it1_;
  1742. }
  1743. value_type t2 = value_type/*zero*/();
  1744. if (it2_ != it2_end_) {
  1745. BOOST_UBLAS_CHECK (it2_.index2 () == j_, internal_logic ());
  1746. if (it2_.index1 () == i_)
  1747. t2 = *it2_;
  1748. }
  1749. return functor_type::apply (t1, t2);
  1750. }
  1751. // Sparse specializations
  1752. BOOST_UBLAS_INLINE
  1753. void increment (sparse_bidirectional_iterator_tag) {
  1754. size_type index1 = (*this) ().size1 ();
  1755. if (it1_ != it1_end_) {
  1756. if (it1_.index1 () <= i_)
  1757. ++ it1_;
  1758. if (it1_ != it1_end_)
  1759. index1 = it1_.index1 ();
  1760. }
  1761. size_type index2 = (*this) ().size1 ();
  1762. if (it2_ != it2_end_)
  1763. if (it2_.index1 () <= i_)
  1764. ++ it2_;
  1765. if (it2_ != it2_end_) {
  1766. index2 = it2_.index1 ();
  1767. }
  1768. i_ = (std::min) (index1, index2);
  1769. }
  1770. BOOST_UBLAS_INLINE
  1771. void decrement (sparse_bidirectional_iterator_tag) {
  1772. size_type index1 = (*this) ().size1 ();
  1773. if (it1_ != it1_end_) {
  1774. if (i_ <= it1_.index1 ())
  1775. -- it1_;
  1776. if (it1_ != it1_end_)
  1777. index1 = it1_.index1 ();
  1778. }
  1779. size_type index2 = (*this) ().size1 ();
  1780. if (it2_ != it2_end_) {
  1781. if (i_ <= it2_.index1 ())
  1782. -- it2_;
  1783. if (it2_ != it2_end_)
  1784. index2 = it2_.index1 ();
  1785. }
  1786. i_ = (std::max) (index1, index2);
  1787. }
  1788. BOOST_UBLAS_INLINE
  1789. void increment (sparse_bidirectional_iterator_tag, difference_type n) {
  1790. while (n > 0) {
  1791. increment (sparse_bidirectional_iterator_tag ());
  1792. --n;
  1793. }
  1794. while (n < 0) {
  1795. decrement (sparse_bidirectional_iterator_tag ());
  1796. ++n;
  1797. }
  1798. }
  1799. BOOST_UBLAS_INLINE
  1800. void decrement (sparse_bidirectional_iterator_tag, difference_type n) {
  1801. while (n > 0) {
  1802. decrement (sparse_bidirectional_iterator_tag ());
  1803. --n;
  1804. }
  1805. while (n < 0) {
  1806. increment (sparse_bidirectional_iterator_tag ());
  1807. ++n;
  1808. }
  1809. }
  1810. BOOST_UBLAS_INLINE
  1811. value_type dereference (sparse_bidirectional_iterator_tag) const {
  1812. value_type t1 = value_type/*zero*/();
  1813. if (it1_ != it1_end_) {
  1814. BOOST_UBLAS_CHECK (it1_.index2 () == j_, internal_logic ());
  1815. if (it1_.index1 () == i_)
  1816. t1 = *it1_;
  1817. }
  1818. value_type t2 = value_type/*zero*/();
  1819. if (it2_ != it2_end_) {
  1820. BOOST_UBLAS_CHECK (it2_.index2 () == j_, internal_logic ());
  1821. if (it2_.index1 () == i_)
  1822. t2 = *it2_;
  1823. }
  1824. return functor_type::apply (t1, t2);
  1825. }
  1826. public:
  1827. // Arithmetic
  1828. BOOST_UBLAS_INLINE
  1829. const_iterator1 &operator ++ () {
  1830. increment (iterator_category ());
  1831. return *this;
  1832. }
  1833. BOOST_UBLAS_INLINE
  1834. const_iterator1 &operator -- () {
  1835. decrement (iterator_category ());
  1836. return *this;
  1837. }
  1838. BOOST_UBLAS_INLINE
  1839. const_iterator1 &operator += (difference_type n) {
  1840. increment (iterator_category (), n);
  1841. return *this;
  1842. }
  1843. BOOST_UBLAS_INLINE
  1844. const_iterator1 &operator -= (difference_type n) {
  1845. decrement (iterator_category (), n);
  1846. return *this;
  1847. }
  1848. BOOST_UBLAS_INLINE
  1849. difference_type operator - (const const_iterator1 &it) const {
  1850. BOOST_UBLAS_CHECK ((*this) ().same_closure (it ()), external_logic ());
  1851. BOOST_UBLAS_CHECK (index2 () == it.index2 (), external_logic ());
  1852. return index1 () - it.index1 ();
  1853. }
  1854. // Dereference
  1855. BOOST_UBLAS_INLINE
  1856. const_reference operator * () const {
  1857. return dereference (iterator_category ());
  1858. }
  1859. BOOST_UBLAS_INLINE
  1860. const_reference operator [] (difference_type n) const {
  1861. return *(*this + n);
  1862. }
  1863. #ifndef BOOST_UBLAS_NO_NESTED_CLASS_RELATION
  1864. BOOST_UBLAS_INLINE
  1865. #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
  1866. typename self_type::
  1867. #endif
  1868. const_iterator2 begin () const {
  1869. return (*this) ().find2 (1, index1 (), 0);
  1870. }
  1871. BOOST_UBLAS_INLINE
  1872. #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
  1873. typename self_type::
  1874. #endif
  1875. const_iterator2 end () const {
  1876. return (*this) ().find2 (1, index1 (), (*this) ().size2 ());
  1877. }
  1878. BOOST_UBLAS_INLINE
  1879. #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
  1880. typename self_type::
  1881. #endif
  1882. const_reverse_iterator2 rbegin () const {
  1883. return const_reverse_iterator2 (end ());
  1884. }
  1885. BOOST_UBLAS_INLINE
  1886. #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
  1887. typename self_type::
  1888. #endif
  1889. const_reverse_iterator2 rend () const {
  1890. return const_reverse_iterator2 (begin ());
  1891. }
  1892. #endif
  1893. // Indices
  1894. BOOST_UBLAS_INLINE
  1895. size_type index1 () const {
  1896. return i_;
  1897. }
  1898. BOOST_UBLAS_INLINE
  1899. size_type index2 () const {
  1900. // if (it1_ != it1_end_ && it2_ != it2_end_)
  1901. // return BOOST_UBLAS_SAME (it1_.index2 (), it2_.index2 ());
  1902. // else
  1903. return j_;
  1904. }
  1905. // Assignment
  1906. BOOST_UBLAS_INLINE
  1907. const_iterator1 &operator = (const const_iterator1 &it) {
  1908. container_const_reference<self_type>::assign (&it ());
  1909. i_ = it.i_;
  1910. j_ = it.j_;
  1911. it1_ = it.it1_;
  1912. it1_end_ = it.it1_end_;
  1913. it2_ = it.it2_;
  1914. it2_end_ = it.it2_end_;
  1915. return *this;
  1916. }
  1917. // Comparison
  1918. BOOST_UBLAS_INLINE
  1919. bool operator == (const const_iterator1 &it) const {
  1920. BOOST_UBLAS_CHECK ((*this) ().same_closure (it ()), external_logic ());
  1921. BOOST_UBLAS_CHECK (index2 () == it.index2 (), external_logic ());
  1922. return index1 () == it.index1 ();
  1923. }
  1924. BOOST_UBLAS_INLINE
  1925. bool operator < (const const_iterator1 &it) const {
  1926. BOOST_UBLAS_CHECK ((*this) ().same_closure (it ()), external_logic ());
  1927. BOOST_UBLAS_CHECK (index2 () == it.index2 (), external_logic ());
  1928. return index1 () < it.index1 ();
  1929. }
  1930. private:
  1931. size_type i_;
  1932. size_type j_;
  1933. const_iterator11_type it1_;
  1934. const_iterator11_type it1_end_;
  1935. const_iterator21_type it2_;
  1936. const_iterator21_type it2_end_;
  1937. };
  1938. #endif
  1939. BOOST_UBLAS_INLINE
  1940. const_iterator1 begin1 () const {
  1941. return find1 (0, 0, 0);
  1942. }
  1943. BOOST_UBLAS_INLINE
  1944. const_iterator1 end1 () const {
  1945. return find1 (0, size1 (), 0);
  1946. }
  1947. #ifndef BOOST_UBLAS_USE_INDEXED_ITERATOR
  1948. class const_iterator2:
  1949. public container_const_reference<matrix_binary>,
  1950. public iterator_base_traits<typename iterator_restrict_traits<typename E1::const_iterator2::iterator_category,
  1951. typename E2::const_iterator2::iterator_category>::iterator_category>::template
  1952. iterator_base<const_iterator2, value_type>::type {
  1953. public:
  1954. typedef typename iterator_restrict_traits<typename E1::const_iterator2::iterator_category,
  1955. typename E2::const_iterator2::iterator_category>::iterator_category iterator_category;
  1956. typedef typename matrix_binary::difference_type difference_type;
  1957. typedef typename matrix_binary::value_type value_type;
  1958. typedef typename matrix_binary::const_reference reference;
  1959. typedef typename matrix_binary::const_pointer pointer;
  1960. typedef const_iterator1 dual_iterator_type;
  1961. typedef const_reverse_iterator1 dual_reverse_iterator_type;
  1962. // Construction and destruction
  1963. BOOST_UBLAS_INLINE
  1964. const_iterator2 ():
  1965. container_const_reference<self_type> (), i_ (), j_ (), it1_ (), it1_end_ (), it2_ (), it2_end_ () {}
  1966. BOOST_UBLAS_INLINE
  1967. const_iterator2 (const self_type &mb, size_type i, size_type j,
  1968. const const_iterator12_type &it1, const const_iterator12_type &it1_end,
  1969. const const_iterator22_type &it2, const const_iterator22_type &it2_end):
  1970. container_const_reference<self_type> (mb), i_ (i), j_ (j), it1_ (it1), it1_end_ (it1_end), it2_ (it2), it2_end_ (it2_end) {}
  1971. private:
  1972. // Dense access specializations
  1973. BOOST_UBLAS_INLINE
  1974. void increment (dense_random_access_iterator_tag) {
  1975. ++ j_; ++ it1_; ++ it2_;
  1976. }
  1977. BOOST_UBLAS_INLINE
  1978. void decrement (dense_random_access_iterator_tag) {
  1979. -- j_; -- it1_; -- it2_;
  1980. }
  1981. BOOST_UBLAS_INLINE
  1982. void increment (dense_random_access_iterator_tag, difference_type n) {
  1983. j_ += n; it1_ += n; it2_ += n;
  1984. }
  1985. BOOST_UBLAS_INLINE
  1986. void decrement (dense_random_access_iterator_tag, difference_type n) {
  1987. j_ -= n; it1_ -= n; it2_ -= n;
  1988. }
  1989. BOOST_UBLAS_INLINE
  1990. value_type dereference (dense_random_access_iterator_tag) const {
  1991. return functor_type::apply (*it1_, *it2_);
  1992. }
  1993. // Packed specializations
  1994. BOOST_UBLAS_INLINE
  1995. void increment (packed_random_access_iterator_tag) {
  1996. if (it1_ != it1_end_)
  1997. if (it1_.index2 () <= j_)
  1998. ++ it1_;
  1999. if (it2_ != it2_end_)
  2000. if (it2_.index2 () <= j_)
  2001. ++ it2_;
  2002. ++ j_;
  2003. }
  2004. BOOST_UBLAS_INLINE
  2005. void decrement (packed_random_access_iterator_tag) {
  2006. if (it1_ != it1_end_)
  2007. if (j_ <= it1_.index2 ())
  2008. -- it1_;
  2009. if (it2_ != it2_end_)
  2010. if (j_ <= it2_.index2 ())
  2011. -- it2_;
  2012. -- j_;
  2013. }
  2014. BOOST_UBLAS_INLINE
  2015. void increment (packed_random_access_iterator_tag, difference_type n) {
  2016. while (n > 0) {
  2017. increment (packed_random_access_iterator_tag ());
  2018. --n;
  2019. }
  2020. while (n < 0) {
  2021. decrement (packed_random_access_iterator_tag ());
  2022. ++n;
  2023. }
  2024. }
  2025. BOOST_UBLAS_INLINE
  2026. void decrement (packed_random_access_iterator_tag, difference_type n) {
  2027. while (n > 0) {
  2028. decrement (packed_random_access_iterator_tag ());
  2029. --n;
  2030. }
  2031. while (n < 0) {
  2032. increment (packed_random_access_iterator_tag ());
  2033. ++n;
  2034. }
  2035. }
  2036. BOOST_UBLAS_INLINE
  2037. value_type dereference (packed_random_access_iterator_tag) const {
  2038. value_type t1 = value_type/*zero*/();
  2039. if (it1_ != it1_end_) {
  2040. BOOST_UBLAS_CHECK (it1_.index1 () == i_, internal_logic ());
  2041. if (it1_.index2 () == j_)
  2042. t1 = *it1_;
  2043. }
  2044. value_type t2 = value_type/*zero*/();
  2045. if (it2_ != it2_end_) {
  2046. BOOST_UBLAS_CHECK (it2_.index1 () == i_, internal_logic ());
  2047. if (it2_.index2 () == j_)
  2048. t2 = *it2_;
  2049. }
  2050. return functor_type::apply (t1, t2);
  2051. }
  2052. // Sparse specializations
  2053. BOOST_UBLAS_INLINE
  2054. void increment (sparse_bidirectional_iterator_tag) {
  2055. size_type index1 = (*this) ().size2 ();
  2056. if (it1_ != it1_end_) {
  2057. if (it1_.index2 () <= j_)
  2058. ++ it1_;
  2059. if (it1_ != it1_end_)
  2060. index1 = it1_.index2 ();
  2061. }
  2062. size_type index2 = (*this) ().size2 ();
  2063. if (it2_ != it2_end_) {
  2064. if (it2_.index2 () <= j_)
  2065. ++ it2_;
  2066. if (it2_ != it2_end_)
  2067. index2 = it2_.index2 ();
  2068. }
  2069. j_ = (std::min) (index1, index2);
  2070. }
  2071. BOOST_UBLAS_INLINE
  2072. void decrement (sparse_bidirectional_iterator_tag) {
  2073. size_type index1 = (*this) ().size2 ();
  2074. if (it1_ != it1_end_) {
  2075. if (j_ <= it1_.index2 ())
  2076. -- it1_;
  2077. if (it1_ != it1_end_)
  2078. index1 = it1_.index2 ();
  2079. }
  2080. size_type index2 = (*this) ().size2 ();
  2081. if (it2_ != it2_end_) {
  2082. if (j_ <= it2_.index2 ())
  2083. -- it2_;
  2084. if (it2_ != it2_end_)
  2085. index2 = it2_.index2 ();
  2086. }
  2087. j_ = (std::max) (index1, index2);
  2088. }
  2089. BOOST_UBLAS_INLINE
  2090. void increment (sparse_bidirectional_iterator_tag, difference_type n) {
  2091. while (n > 0) {
  2092. increment (sparse_bidirectional_iterator_tag ());
  2093. --n;
  2094. }
  2095. while (n < 0) {
  2096. decrement (sparse_bidirectional_iterator_tag ());
  2097. ++n;
  2098. }
  2099. }
  2100. BOOST_UBLAS_INLINE
  2101. void decrement (sparse_bidirectional_iterator_tag, difference_type n) {
  2102. while (n > 0) {
  2103. decrement (sparse_bidirectional_iterator_tag ());
  2104. --n;
  2105. }
  2106. while (n < 0) {
  2107. increment (sparse_bidirectional_iterator_tag ());
  2108. ++n;
  2109. }
  2110. }
  2111. BOOST_UBLAS_INLINE
  2112. value_type dereference (sparse_bidirectional_iterator_tag) const {
  2113. value_type t1 = value_type/*zero*/();
  2114. if (it1_ != it1_end_) {
  2115. BOOST_UBLAS_CHECK (it1_.index1 () == i_, internal_logic ());
  2116. if (it1_.index2 () == j_)
  2117. t1 = *it1_;
  2118. }
  2119. value_type t2 = value_type/*zero*/();
  2120. if (it2_ != it2_end_) {
  2121. BOOST_UBLAS_CHECK (it2_.index1 () == i_, internal_logic ());
  2122. if (it2_.index2 () == j_)
  2123. t2 = *it2_;
  2124. }
  2125. return functor_type::apply (t1, t2);
  2126. }
  2127. public:
  2128. // Arithmetic
  2129. BOOST_UBLAS_INLINE
  2130. const_iterator2 &operator ++ () {
  2131. increment (iterator_category ());
  2132. return *this;
  2133. }
  2134. BOOST_UBLAS_INLINE
  2135. const_iterator2 &operator -- () {
  2136. decrement (iterator_category ());
  2137. return *this;
  2138. }
  2139. BOOST_UBLAS_INLINE
  2140. const_iterator2 &operator += (difference_type n) {
  2141. increment (iterator_category (), n);
  2142. return *this;
  2143. }
  2144. BOOST_UBLAS_INLINE
  2145. const_iterator2 &operator -= (difference_type n) {
  2146. decrement (iterator_category (), n);
  2147. return *this;
  2148. }
  2149. BOOST_UBLAS_INLINE
  2150. difference_type operator - (const const_iterator2 &it) const {
  2151. BOOST_UBLAS_CHECK ((*this) ().same_closure (it ()), external_logic ());
  2152. BOOST_UBLAS_CHECK (index1 () == it.index1 (), external_logic ());
  2153. return index2 () - it.index2 ();
  2154. }
  2155. // Dereference
  2156. BOOST_UBLAS_INLINE
  2157. const_reference operator * () const {
  2158. return dereference (iterator_category ());
  2159. }
  2160. BOOST_UBLAS_INLINE
  2161. const_reference operator [] (difference_type n) const {
  2162. return *(*this + n);
  2163. }
  2164. #ifndef BOOST_UBLAS_NO_NESTED_CLASS_RELATION
  2165. BOOST_UBLAS_INLINE
  2166. #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
  2167. typename self_type::
  2168. #endif
  2169. const_iterator1 begin () const {
  2170. return (*this) ().find1 (1, 0, index2 ());
  2171. }
  2172. BOOST_UBLAS_INLINE
  2173. #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
  2174. typename self_type::
  2175. #endif
  2176. const_iterator1 end () const {
  2177. return (*this) ().find1 (1, (*this) ().size1 (), index2 ());
  2178. }
  2179. BOOST_UBLAS_INLINE
  2180. #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
  2181. typename self_type::
  2182. #endif
  2183. const_reverse_iterator1 rbegin () const {
  2184. return const_reverse_iterator1 (end ());
  2185. }
  2186. BOOST_UBLAS_INLINE
  2187. #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
  2188. typename self_type::
  2189. #endif
  2190. const_reverse_iterator1 rend () const {
  2191. return const_reverse_iterator1 (begin ());
  2192. }
  2193. #endif
  2194. // Indices
  2195. BOOST_UBLAS_INLINE
  2196. size_type index1 () const {
  2197. // if (it1_ != it1_end_ && it2_ != it2_end_)
  2198. // return BOOST_UBLAS_SAME (it1_.index1 (), it2_.index1 ());
  2199. // else
  2200. return i_;
  2201. }
  2202. BOOST_UBLAS_INLINE
  2203. size_type index2 () const {
  2204. return j_;
  2205. }
  2206. // Assignment
  2207. BOOST_UBLAS_INLINE
  2208. const_iterator2 &operator = (const const_iterator2 &it) {
  2209. container_const_reference<self_type>::assign (&it ());
  2210. i_ = it.i_;
  2211. j_ = it.j_;
  2212. it1_ = it.it1_;
  2213. it1_end_ = it.it1_end_;
  2214. it2_ = it.it2_;
  2215. it2_end_ = it.it2_end_;
  2216. return *this;
  2217. }
  2218. // Comparison
  2219. BOOST_UBLAS_INLINE
  2220. bool operator == (const const_iterator2 &it) const {
  2221. BOOST_UBLAS_CHECK ((*this) ().same_closure (it ()), external_logic ());
  2222. BOOST_UBLAS_CHECK (index1 () == it.index1 (), external_logic ());
  2223. return index2 () == it.index2 ();
  2224. }
  2225. BOOST_UBLAS_INLINE
  2226. bool operator < (const const_iterator2 &it) const {
  2227. BOOST_UBLAS_CHECK ((*this) ().same_closure (it ()), external_logic ());
  2228. BOOST_UBLAS_CHECK (index1 () == it.index1 (), external_logic ());
  2229. return index2 () < it.index2 ();
  2230. }
  2231. private:
  2232. size_type i_;
  2233. size_type j_;
  2234. const_iterator12_type it1_;
  2235. const_iterator12_type it1_end_;
  2236. const_iterator22_type it2_;
  2237. const_iterator22_type it2_end_;
  2238. };
  2239. #endif
  2240. BOOST_UBLAS_INLINE
  2241. const_iterator2 begin2 () const {
  2242. return find2 (0, 0, 0);
  2243. }
  2244. BOOST_UBLAS_INLINE
  2245. const_iterator2 end2 () const {
  2246. return find2 (0, 0, size2 ());
  2247. }
  2248. // Reverse iterators
  2249. BOOST_UBLAS_INLINE
  2250. const_reverse_iterator1 rbegin1 () const {
  2251. return const_reverse_iterator1 (end1 ());
  2252. }
  2253. BOOST_UBLAS_INLINE
  2254. const_reverse_iterator1 rend1 () const {
  2255. return const_reverse_iterator1 (begin1 ());
  2256. }
  2257. BOOST_UBLAS_INLINE
  2258. const_reverse_iterator2 rbegin2 () const {
  2259. return const_reverse_iterator2 (end2 ());
  2260. }
  2261. BOOST_UBLAS_INLINE
  2262. const_reverse_iterator2 rend2 () const {
  2263. return const_reverse_iterator2 (begin2 ());
  2264. }
  2265. private:
  2266. expression1_closure_type e1_;
  2267. expression2_closure_type e2_;
  2268. };
  2269. template<class E1, class E2, class F>
  2270. struct matrix_binary_traits {
  2271. typedef matrix_binary<E1, E2, F> expression_type;
  2272. #ifndef BOOST_UBLAS_SIMPLE_ET_DEBUG
  2273. typedef expression_type result_type;
  2274. #else
  2275. typedef typename E1::matrix_temporary_type result_type;
  2276. #endif
  2277. };
  2278. // (m1 + m2) [i] [j] = m1 [i] [j] + m2 [i] [j]
  2279. template<class E1, class E2>
  2280. BOOST_UBLAS_INLINE
  2281. typename matrix_binary_traits<E1, E2, scalar_plus<typename E1::value_type,
  2282. typename E2::value_type> >::result_type
  2283. operator + (const matrix_expression<E1> &e1,
  2284. const matrix_expression<E2> &e2) {
  2285. typedef typename matrix_binary_traits<E1, E2, scalar_plus<typename E1::value_type,
  2286. typename E2::value_type> >::expression_type expression_type;
  2287. return expression_type (e1 (), e2 ());
  2288. }
  2289. // (m1 - m2) [i] [j] = m1 [i] [j] - m2 [i] [j]
  2290. template<class E1, class E2>
  2291. BOOST_UBLAS_INLINE
  2292. typename matrix_binary_traits<E1, E2, scalar_minus<typename E1::value_type,
  2293. typename E2::value_type> >::result_type
  2294. operator - (const matrix_expression<E1> &e1,
  2295. const matrix_expression<E2> &e2) {
  2296. typedef typename matrix_binary_traits<E1, E2, scalar_minus<typename E1::value_type,
  2297. typename E2::value_type> >::expression_type expression_type;
  2298. return expression_type (e1 (), e2 ());
  2299. }
  2300. // (m1 * m2) [i] [j] = m1 [i] [j] * m2 [i] [j]
  2301. template<class E1, class E2>
  2302. BOOST_UBLAS_INLINE
  2303. typename matrix_binary_traits<E1, E2, scalar_multiplies<typename E1::value_type,
  2304. typename E2::value_type> >::result_type
  2305. element_prod (const matrix_expression<E1> &e1,
  2306. const matrix_expression<E2> &e2) {
  2307. typedef typename matrix_binary_traits<E1, E2, scalar_multiplies<typename E1::value_type,
  2308. typename E2::value_type> >::expression_type expression_type;
  2309. return expression_type (e1 (), e2 ());
  2310. }
  2311. // (m1 / m2) [i] [j] = m1 [i] [j] / m2 [i] [j]
  2312. template<class E1, class E2>
  2313. BOOST_UBLAS_INLINE
  2314. typename matrix_binary_traits<E1, E2, scalar_divides<typename E1::value_type,
  2315. typename E2::value_type> >::result_type
  2316. element_div (const matrix_expression<E1> &e1,
  2317. const matrix_expression<E2> &e2) {
  2318. typedef typename matrix_binary_traits<E1, E2, scalar_divides<typename E1::value_type,
  2319. typename E2::value_type> >::expression_type expression_type;
  2320. return expression_type (e1 (), e2 ());
  2321. }
  2322. template<class E1, class E2, class F>
  2323. class matrix_binary_scalar1:
  2324. public matrix_expression<matrix_binary_scalar1<E1, E2, F> > {
  2325. typedef E1 expression1_type;
  2326. typedef E2 expression2_type;
  2327. typedef F functor_type;
  2328. typedef const E1& expression1_closure_type;
  2329. typedef typename E2::const_closure_type expression2_closure_type;
  2330. typedef matrix_binary_scalar1<E1, E2, F> self_type;
  2331. public:
  2332. #ifdef BOOST_UBLAS_ENABLE_PROXY_SHORTCUTS
  2333. using matrix_expression<self_type>::operator ();
  2334. #endif
  2335. typedef typename E2::size_type size_type;
  2336. typedef typename E2::difference_type difference_type;
  2337. typedef typename F::result_type value_type;
  2338. typedef value_type const_reference;
  2339. typedef const_reference reference;
  2340. typedef const self_type const_closure_type;
  2341. typedef const_closure_type closure_type;
  2342. typedef typename E2::orientation_category orientation_category;
  2343. typedef unknown_storage_tag storage_category;
  2344. // Construction and destruction
  2345. BOOST_UBLAS_INLINE
  2346. matrix_binary_scalar1 (const expression1_type &e1, const expression2_type &e2):
  2347. e1_ (e1), e2_ (e2) {}
  2348. // Accessors
  2349. BOOST_UBLAS_INLINE
  2350. size_type size1 () const {
  2351. return e2_.size1 ();
  2352. }
  2353. BOOST_UBLAS_INLINE
  2354. size_type size2 () const {
  2355. return e2_.size2 ();
  2356. }
  2357. public:
  2358. // Element access
  2359. BOOST_UBLAS_INLINE
  2360. const_reference operator () (size_type i, size_type j) const {
  2361. return functor_type::apply (expression1_type (e1_), e2_ (i, j));
  2362. }
  2363. // Closure comparison
  2364. BOOST_UBLAS_INLINE
  2365. bool same_closure (const matrix_binary_scalar1 &mbs1) const {
  2366. return &e1_ == &(mbs1.e1_) &&
  2367. (*this).e2_.same_closure (mbs1.e2_);
  2368. }
  2369. // Iterator types
  2370. private:
  2371. typedef expression1_type const_subiterator1_type;
  2372. typedef typename E2::const_iterator1 const_iterator21_type;
  2373. typedef typename E2::const_iterator2 const_iterator22_type;
  2374. typedef const value_type *const_pointer;
  2375. public:
  2376. #ifdef BOOST_UBLAS_USE_INDEXED_ITERATOR
  2377. typedef indexed_const_iterator1<const_closure_type, typename const_iterator21_type::iterator_category> const_iterator1;
  2378. typedef const_iterator1 iterator1;
  2379. typedef indexed_const_iterator2<const_closure_type, typename const_iterator22_type::iterator_category> const_iterator2;
  2380. typedef const_iterator2 iterator2;
  2381. #else
  2382. class const_iterator1;
  2383. typedef const_iterator1 iterator1;
  2384. class const_iterator2;
  2385. typedef const_iterator2 iterator2;
  2386. #endif
  2387. typedef reverse_iterator_base1<const_iterator1> const_reverse_iterator1;
  2388. typedef reverse_iterator_base2<const_iterator2> const_reverse_iterator2;
  2389. // Element lookup
  2390. BOOST_UBLAS_INLINE
  2391. const_iterator1 find1 (int rank, size_type i, size_type j) const {
  2392. const_iterator21_type it21 (e2_.find1 (rank, i, j));
  2393. #ifdef BOOST_UBLAS_USE_INDEXED_ITERATOR
  2394. return const_iterator1 (*this, it21.index1 (), it21.index2 ());
  2395. #else
  2396. return const_iterator1 (*this, const_subiterator1_type (e1_), it21);
  2397. #endif
  2398. }
  2399. BOOST_UBLAS_INLINE
  2400. const_iterator2 find2 (int rank, size_type i, size_type j) const {
  2401. const_iterator22_type it22 (e2_.find2 (rank, i, j));
  2402. #ifdef BOOST_UBLAS_USE_INDEXED_ITERATOR
  2403. return const_iterator2 (*this, it22.index1 (), it22.index2 ());
  2404. #else
  2405. return const_iterator2 (*this, const_subiterator1_type (e1_), it22);
  2406. #endif
  2407. }
  2408. // Iterators enhance the iterators of the referenced expression
  2409. // with the binary functor.
  2410. #ifndef BOOST_UBLAS_USE_INDEXED_ITERATOR
  2411. class const_iterator1:
  2412. public container_const_reference<matrix_binary_scalar1>,
  2413. public iterator_base_traits<typename E2::const_iterator1::iterator_category>::template
  2414. iterator_base<const_iterator1, value_type>::type {
  2415. public:
  2416. typedef typename E2::const_iterator1::iterator_category iterator_category;
  2417. typedef typename matrix_binary_scalar1::difference_type difference_type;
  2418. typedef typename matrix_binary_scalar1::value_type value_type;
  2419. typedef typename matrix_binary_scalar1::const_reference reference;
  2420. typedef typename matrix_binary_scalar1::const_pointer pointer;
  2421. typedef const_iterator2 dual_iterator_type;
  2422. typedef const_reverse_iterator2 dual_reverse_iterator_type;
  2423. // Construction and destruction
  2424. BOOST_UBLAS_INLINE
  2425. const_iterator1 ():
  2426. container_const_reference<self_type> (), it1_ (), it2_ () {}
  2427. BOOST_UBLAS_INLINE
  2428. const_iterator1 (const self_type &mbs, const const_subiterator1_type &it1, const const_iterator21_type &it2):
  2429. container_const_reference<self_type> (mbs), it1_ (it1), it2_ (it2) {}
  2430. // Arithmetic
  2431. BOOST_UBLAS_INLINE
  2432. const_iterator1 &operator ++ () {
  2433. ++ it2_;
  2434. return *this;
  2435. }
  2436. BOOST_UBLAS_INLINE
  2437. const_iterator1 &operator -- () {
  2438. -- it2_ ;
  2439. return *this;
  2440. }
  2441. BOOST_UBLAS_INLINE
  2442. const_iterator1 &operator += (difference_type n) {
  2443. it2_ += n;
  2444. return *this;
  2445. }
  2446. BOOST_UBLAS_INLINE
  2447. const_iterator1 &operator -= (difference_type n) {
  2448. it2_ -= n;
  2449. return *this;
  2450. }
  2451. BOOST_UBLAS_INLINE
  2452. difference_type operator - (const const_iterator1 &it) const {
  2453. BOOST_UBLAS_CHECK ((*this) ().same_closure (it ()), external_logic ());
  2454. // FIXME we shouldn't compare floats
  2455. // BOOST_UBLAS_CHECK (it1_ == it.it1_, external_logic ());
  2456. return it2_ - it.it2_;
  2457. }
  2458. // Dereference
  2459. BOOST_UBLAS_INLINE
  2460. const_reference operator * () const {
  2461. return functor_type::apply (it1_, *it2_);
  2462. }
  2463. BOOST_UBLAS_INLINE
  2464. const_reference operator [] (difference_type n) const {
  2465. return *(*this + n);
  2466. }
  2467. #ifndef BOOST_UBLAS_NO_NESTED_CLASS_RELATION
  2468. BOOST_UBLAS_INLINE
  2469. #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
  2470. typename self_type::
  2471. #endif
  2472. const_iterator2 begin () const {
  2473. return (*this) ().find2 (1, index1 (), 0);
  2474. }
  2475. BOOST_UBLAS_INLINE
  2476. #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
  2477. typename self_type::
  2478. #endif
  2479. const_iterator2 end () const {
  2480. return (*this) ().find2 (1, index1 (), (*this) ().size2 ());
  2481. }
  2482. BOOST_UBLAS_INLINE
  2483. #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
  2484. typename self_type::
  2485. #endif
  2486. const_reverse_iterator2 rbegin () const {
  2487. return const_reverse_iterator2 (end ());
  2488. }
  2489. BOOST_UBLAS_INLINE
  2490. #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
  2491. typename self_type::
  2492. #endif
  2493. const_reverse_iterator2 rend () const {
  2494. return const_reverse_iterator2 (begin ());
  2495. }
  2496. #endif
  2497. // Indices
  2498. BOOST_UBLAS_INLINE
  2499. size_type index1 () const {
  2500. return it2_.index1 ();
  2501. }
  2502. BOOST_UBLAS_INLINE
  2503. size_type index2 () const {
  2504. return it2_.index2 ();
  2505. }
  2506. // Assignment
  2507. BOOST_UBLAS_INLINE
  2508. const_iterator1 &operator = (const const_iterator1 &it) {
  2509. container_const_reference<self_type>::assign (&it ());
  2510. it1_ = it.it1_;
  2511. it2_ = it.it2_;
  2512. return *this;
  2513. }
  2514. // Comparison
  2515. BOOST_UBLAS_INLINE
  2516. bool operator == (const const_iterator1 &it) const {
  2517. BOOST_UBLAS_CHECK ((*this) ().same_closure (it ()), external_logic ());
  2518. // FIXME we shouldn't compare floats
  2519. // BOOST_UBLAS_CHECK (it1_ == it.it1_, external_logic ());
  2520. return it2_ == it.it2_;
  2521. }
  2522. BOOST_UBLAS_INLINE
  2523. bool operator < (const const_iterator1 &it) const {
  2524. BOOST_UBLAS_CHECK ((*this) ().same_closure (it ()), external_logic ());
  2525. // FIXME we shouldn't compare floats
  2526. // BOOST_UBLAS_CHECK (it1_ == it.it1_, external_logic ());
  2527. return it2_ < it.it2_;
  2528. }
  2529. private:
  2530. const_subiterator1_type it1_;
  2531. const_iterator21_type it2_;
  2532. };
  2533. #endif
  2534. BOOST_UBLAS_INLINE
  2535. const_iterator1 begin1 () const {
  2536. return find1 (0, 0, 0);
  2537. }
  2538. BOOST_UBLAS_INLINE
  2539. const_iterator1 end1 () const {
  2540. return find1 (0, size1 (), 0);
  2541. }
  2542. #ifndef BOOST_UBLAS_USE_INDEXED_ITERATOR
  2543. class const_iterator2:
  2544. public container_const_reference<matrix_binary_scalar1>,
  2545. public iterator_base_traits<typename E2::const_iterator2::iterator_category>::template
  2546. iterator_base<const_iterator2, value_type>::type {
  2547. public:
  2548. typedef typename E2::const_iterator2::iterator_category iterator_category;
  2549. typedef typename matrix_binary_scalar1::difference_type difference_type;
  2550. typedef typename matrix_binary_scalar1::value_type value_type;
  2551. typedef typename matrix_binary_scalar1::const_reference reference;
  2552. typedef typename matrix_binary_scalar1::const_pointer pointer;
  2553. typedef const_iterator1 dual_iterator_type;
  2554. typedef const_reverse_iterator1 dual_reverse_iterator_type;
  2555. // Construction and destruction
  2556. BOOST_UBLAS_INLINE
  2557. const_iterator2 ():
  2558. container_const_reference<self_type> (), it1_ (), it2_ () {}
  2559. BOOST_UBLAS_INLINE
  2560. const_iterator2 (const self_type &mbs, const const_subiterator1_type &it1, const const_iterator22_type &it2):
  2561. container_const_reference<self_type> (mbs), it1_ (it1), it2_ (it2) {}
  2562. // Arithmetic
  2563. BOOST_UBLAS_INLINE
  2564. const_iterator2 &operator ++ () {
  2565. ++ it2_;
  2566. return *this;
  2567. }
  2568. BOOST_UBLAS_INLINE
  2569. const_iterator2 &operator -- () {
  2570. -- it2_;
  2571. return *this;
  2572. }
  2573. BOOST_UBLAS_INLINE
  2574. const_iterator2 &operator += (difference_type n) {
  2575. it2_ += n;
  2576. return *this;
  2577. }
  2578. BOOST_UBLAS_INLINE
  2579. const_iterator2 &operator -= (difference_type n) {
  2580. it2_ -= n;
  2581. return *this;
  2582. }
  2583. BOOST_UBLAS_INLINE
  2584. difference_type operator - (const const_iterator2 &it) const {
  2585. BOOST_UBLAS_CHECK ((*this) ().same_closure (it ()), external_logic ());
  2586. // FIXME we shouldn't compare floats
  2587. // BOOST_UBLAS_CHECK (it1_ == it.it1_, external_logic ());
  2588. return it2_ - it.it2_;
  2589. }
  2590. // Dereference
  2591. BOOST_UBLAS_INLINE
  2592. const_reference operator * () const {
  2593. return functor_type::apply (it1_, *it2_);
  2594. }
  2595. BOOST_UBLAS_INLINE
  2596. const_reference operator [] (difference_type n) const {
  2597. return *(*this + n);
  2598. }
  2599. #ifndef BOOST_UBLAS_NO_NESTED_CLASS_RELATION
  2600. BOOST_UBLAS_INLINE
  2601. #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
  2602. typename self_type::
  2603. #endif
  2604. const_iterator1 begin () const {
  2605. return (*this) ().find1 (1, 0, index2 ());
  2606. }
  2607. BOOST_UBLAS_INLINE
  2608. #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
  2609. typename self_type::
  2610. #endif
  2611. const_iterator1 end () const {
  2612. return (*this) ().find1 (1, (*this) ().size1 (), index2 ());
  2613. }
  2614. BOOST_UBLAS_INLINE
  2615. #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
  2616. typename self_type::
  2617. #endif
  2618. const_reverse_iterator1 rbegin () const {
  2619. return const_reverse_iterator1 (end ());
  2620. }
  2621. BOOST_UBLAS_INLINE
  2622. #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
  2623. typename self_type::
  2624. #endif
  2625. const_reverse_iterator1 rend () const {
  2626. return const_reverse_iterator1 (begin ());
  2627. }
  2628. #endif
  2629. // Indices
  2630. BOOST_UBLAS_INLINE
  2631. size_type index1 () const {
  2632. return it2_.index1 ();
  2633. }
  2634. BOOST_UBLAS_INLINE
  2635. size_type index2 () const {
  2636. return it2_.index2 ();
  2637. }
  2638. // Assignment
  2639. BOOST_UBLAS_INLINE
  2640. const_iterator2 &operator = (const const_iterator2 &it) {
  2641. container_const_reference<self_type>::assign (&it ());
  2642. it1_ = it.it1_;
  2643. it2_ = it.it2_;
  2644. return *this;
  2645. }
  2646. // Comparison
  2647. BOOST_UBLAS_INLINE
  2648. bool operator == (const const_iterator2 &it) const {
  2649. BOOST_UBLAS_CHECK ((*this) ().same_closure (it ()), external_logic ());
  2650. // FIXME we shouldn't compare floats
  2651. // BOOST_UBLAS_CHECK (it1_ == it.it1_, external_logic ());
  2652. return it2_ == it.it2_;
  2653. }
  2654. BOOST_UBLAS_INLINE
  2655. bool operator < (const const_iterator2 &it) const {
  2656. BOOST_UBLAS_CHECK ((*this) ().same_closure (it ()), external_logic ());
  2657. // FIXME we shouldn't compare floats
  2658. // BOOST_UBLAS_CHECK (it1_ == it.it1_, external_logic ());
  2659. return it2_ < it.it2_;
  2660. }
  2661. private:
  2662. const_subiterator1_type it1_;
  2663. const_iterator22_type it2_;
  2664. };
  2665. #endif
  2666. BOOST_UBLAS_INLINE
  2667. const_iterator2 begin2 () const {
  2668. return find2 (0, 0, 0);
  2669. }
  2670. BOOST_UBLAS_INLINE
  2671. const_iterator2 end2 () const {
  2672. return find2 (0, 0, size2 ());
  2673. }
  2674. // Reverse iterators
  2675. BOOST_UBLAS_INLINE
  2676. const_reverse_iterator1 rbegin1 () const {
  2677. return const_reverse_iterator1 (end1 ());
  2678. }
  2679. BOOST_UBLAS_INLINE
  2680. const_reverse_iterator1 rend1 () const {
  2681. return const_reverse_iterator1 (begin1 ());
  2682. }
  2683. BOOST_UBLAS_INLINE
  2684. const_reverse_iterator2 rbegin2 () const {
  2685. return const_reverse_iterator2 (end2 ());
  2686. }
  2687. BOOST_UBLAS_INLINE
  2688. const_reverse_iterator2 rend2 () const {
  2689. return const_reverse_iterator2 (begin2 ());
  2690. }
  2691. private:
  2692. expression1_closure_type e1_;
  2693. expression2_closure_type e2_;
  2694. };
  2695. template<class E1, class E2, class F>
  2696. struct matrix_binary_scalar1_traits {
  2697. typedef matrix_binary_scalar1<E1, E2, F> expression_type; // allow E1 to be builtin type
  2698. #ifndef BOOST_UBLAS_SIMPLE_ET_DEBUG
  2699. typedef expression_type result_type;
  2700. #else
  2701. typedef typename E2::matrix_temporary_type result_type;
  2702. #endif
  2703. };
  2704. // (t * m) [i] [j] = t * m [i] [j]
  2705. template<class T1, class E2>
  2706. BOOST_UBLAS_INLINE
  2707. typename enable_if< is_convertible<T1, typename E2::value_type >,
  2708. typename matrix_binary_scalar1_traits<const T1, E2, scalar_multiplies<T1, typename E2::value_type> >::result_type
  2709. >::type
  2710. operator * (const T1 &e1,
  2711. const matrix_expression<E2> &e2) {
  2712. typedef typename matrix_binary_scalar1_traits<const T1, E2, scalar_multiplies<T1, typename E2::value_type> >::expression_type expression_type;
  2713. return expression_type (e1, e2 ());
  2714. }
  2715. template<class E1, class E2, class F>
  2716. class matrix_binary_scalar2:
  2717. public matrix_expression<matrix_binary_scalar2<E1, E2, F> > {
  2718. typedef E1 expression1_type;
  2719. typedef E2 expression2_type;
  2720. typedef F functor_type;
  2721. public:
  2722. typedef typename E1::const_closure_type expression1_closure_type;
  2723. typedef const E2& expression2_closure_type;
  2724. private:
  2725. typedef matrix_binary_scalar2<E1, E2, F> self_type;
  2726. public:
  2727. #ifdef BOOST_UBLAS_ENABLE_PROXY_SHORTCUTS
  2728. using matrix_expression<self_type>::operator ();
  2729. #endif
  2730. typedef typename E1::size_type size_type;
  2731. typedef typename E1::difference_type difference_type;
  2732. typedef typename F::result_type value_type;
  2733. typedef value_type const_reference;
  2734. typedef const_reference reference;
  2735. typedef const self_type const_closure_type;
  2736. typedef const_closure_type closure_type;
  2737. typedef typename E1::orientation_category orientation_category;
  2738. typedef unknown_storage_tag storage_category;
  2739. // Construction and destruction
  2740. BOOST_UBLAS_INLINE
  2741. matrix_binary_scalar2 (const expression1_type &e1, const expression2_type &e2):
  2742. e1_ (e1), e2_ (e2) {}
  2743. // Accessors
  2744. BOOST_UBLAS_INLINE
  2745. size_type size1 () const {
  2746. return e1_.size1 ();
  2747. }
  2748. BOOST_UBLAS_INLINE
  2749. size_type size2 () const {
  2750. return e1_.size2 ();
  2751. }
  2752. public:
  2753. // Element access
  2754. BOOST_UBLAS_INLINE
  2755. const_reference operator () (size_type i, size_type j) const {
  2756. return functor_type::apply (e1_ (i, j), expression2_type (e2_));
  2757. }
  2758. // Closure comparison
  2759. BOOST_UBLAS_INLINE
  2760. bool same_closure (const matrix_binary_scalar2 &mbs2) const {
  2761. return (*this).e1_.same_closure (mbs2.e1_) &&
  2762. &e2_ == &(mbs2.e2_);
  2763. }
  2764. // Iterator types
  2765. private:
  2766. typedef typename E1::const_iterator1 const_iterator11_type;
  2767. typedef typename E1::const_iterator2 const_iterator12_type;
  2768. typedef expression2_type const_subiterator2_type;
  2769. typedef const value_type *const_pointer;
  2770. public:
  2771. #ifdef BOOST_UBLAS_USE_INDEXED_ITERATOR
  2772. typedef indexed_const_iterator1<const_closure_type, typename const_iterator11_type::iterator_category> const_iterator1;
  2773. typedef const_iterator1 iterator1;
  2774. typedef indexed_const_iterator2<const_closure_type, typename const_iterator12_type::iterator_category> const_iterator2;
  2775. typedef const_iterator2 iterator2;
  2776. #else
  2777. class const_iterator1;
  2778. typedef const_iterator1 iterator1;
  2779. class const_iterator2;
  2780. typedef const_iterator2 iterator2;
  2781. #endif
  2782. typedef reverse_iterator_base1<const_iterator1> const_reverse_iterator1;
  2783. typedef reverse_iterator_base2<const_iterator2> const_reverse_iterator2;
  2784. // Element lookup
  2785. BOOST_UBLAS_INLINE
  2786. const_iterator1 find1 (int rank, size_type i, size_type j) const {
  2787. const_iterator11_type it11 (e1_.find1 (rank, i, j));
  2788. #ifdef BOOST_UBLAS_USE_INDEXED_ITERATOR
  2789. return const_iterator1 (*this, it11.index1 (), it11.index2 ());
  2790. #else
  2791. return const_iterator1 (*this, it11, const_subiterator2_type (e2_));
  2792. #endif
  2793. }
  2794. BOOST_UBLAS_INLINE
  2795. const_iterator2 find2 (int rank, size_type i, size_type j) const {
  2796. const_iterator12_type it12 (e1_.find2 (rank, i, j));
  2797. #ifdef BOOST_UBLAS_USE_INDEXED_ITERATOR
  2798. return const_iterator2 (*this, it12.index1 (), it12.index2 ());
  2799. #else
  2800. return const_iterator2 (*this, it12, const_subiterator2_type (e2_));
  2801. #endif
  2802. }
  2803. // Iterators enhance the iterators of the referenced expression
  2804. // with the binary functor.
  2805. #ifndef BOOST_UBLAS_USE_INDEXED_ITERATOR
  2806. class const_iterator1:
  2807. public container_const_reference<matrix_binary_scalar2>,
  2808. public iterator_base_traits<typename E1::const_iterator1::iterator_category>::template
  2809. iterator_base<const_iterator1, value_type>::type {
  2810. public:
  2811. typedef typename E1::const_iterator1::iterator_category iterator_category;
  2812. typedef typename matrix_binary_scalar2::difference_type difference_type;
  2813. typedef typename matrix_binary_scalar2::value_type value_type;
  2814. typedef typename matrix_binary_scalar2::const_reference reference;
  2815. typedef typename matrix_binary_scalar2::const_pointer pointer;
  2816. typedef const_iterator2 dual_iterator_type;
  2817. typedef const_reverse_iterator2 dual_reverse_iterator_type;
  2818. // Construction and destruction
  2819. BOOST_UBLAS_INLINE
  2820. const_iterator1 ():
  2821. container_const_reference<self_type> (), it1_ (), it2_ () {}
  2822. BOOST_UBLAS_INLINE
  2823. const_iterator1 (const self_type &mbs, const const_iterator11_type &it1, const const_subiterator2_type &it2):
  2824. container_const_reference<self_type> (mbs), it1_ (it1), it2_ (it2) {}
  2825. // Arithmetic
  2826. BOOST_UBLAS_INLINE
  2827. const_iterator1 &operator ++ () {
  2828. ++ it1_;
  2829. return *this;
  2830. }
  2831. BOOST_UBLAS_INLINE
  2832. const_iterator1 &operator -- () {
  2833. -- it1_ ;
  2834. return *this;
  2835. }
  2836. BOOST_UBLAS_INLINE
  2837. const_iterator1 &operator += (difference_type n) {
  2838. it1_ += n;
  2839. return *this;
  2840. }
  2841. BOOST_UBLAS_INLINE
  2842. const_iterator1 &operator -= (difference_type n) {
  2843. it1_ -= n;
  2844. return *this;
  2845. }
  2846. BOOST_UBLAS_INLINE
  2847. difference_type operator - (const const_iterator1 &it) const {
  2848. BOOST_UBLAS_CHECK ((*this) ().same_closure (it ()), external_logic ());
  2849. // FIXME we shouldn't compare floats
  2850. // BOOST_UBLAS_CHECK (it2_ == it.it2_, external_logic ());
  2851. return it1_ - it.it1_;
  2852. }
  2853. // Dereference
  2854. BOOST_UBLAS_INLINE
  2855. const_reference operator * () const {
  2856. return functor_type::apply (*it1_, it2_);
  2857. }
  2858. BOOST_UBLAS_INLINE
  2859. const_reference operator [] (difference_type n) const {
  2860. return *(*this + n);
  2861. }
  2862. #ifndef BOOST_UBLAS_NO_NESTED_CLASS_RELATION
  2863. BOOST_UBLAS_INLINE
  2864. #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
  2865. typename self_type::
  2866. #endif
  2867. const_iterator2 begin () const {
  2868. return (*this) ().find2 (1, index1 (), 0);
  2869. }
  2870. BOOST_UBLAS_INLINE
  2871. #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
  2872. typename self_type::
  2873. #endif
  2874. const_iterator2 end () const {
  2875. return (*this) ().find2 (1, index1 (), (*this) ().size2 ());
  2876. }
  2877. BOOST_UBLAS_INLINE
  2878. #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
  2879. typename self_type::
  2880. #endif
  2881. const_reverse_iterator2 rbegin () const {
  2882. return const_reverse_iterator2 (end ());
  2883. }
  2884. BOOST_UBLAS_INLINE
  2885. #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
  2886. typename self_type::
  2887. #endif
  2888. const_reverse_iterator2 rend () const {
  2889. return const_reverse_iterator2 (begin ());
  2890. }
  2891. #endif
  2892. // Indices
  2893. BOOST_UBLAS_INLINE
  2894. size_type index1 () const {
  2895. return it1_.index1 ();
  2896. }
  2897. BOOST_UBLAS_INLINE
  2898. size_type index2 () const {
  2899. return it1_.index2 ();
  2900. }
  2901. // Assignment
  2902. BOOST_UBLAS_INLINE
  2903. const_iterator1 &operator = (const const_iterator1 &it) {
  2904. container_const_reference<self_type>::assign (&it ());
  2905. it1_ = it.it1_;
  2906. it2_ = it.it2_;
  2907. return *this;
  2908. }
  2909. // Comparison
  2910. BOOST_UBLAS_INLINE
  2911. bool operator == (const const_iterator1 &it) const {
  2912. BOOST_UBLAS_CHECK ((*this) ().same_closure (it ()), external_logic ());
  2913. // FIXME we shouldn't compare floats
  2914. // BOOST_UBLAS_CHECK (it2_ == it.it2_, external_logic ());
  2915. return it1_ == it.it1_;
  2916. }
  2917. BOOST_UBLAS_INLINE
  2918. bool operator < (const const_iterator1 &it) const {
  2919. BOOST_UBLAS_CHECK ((*this) ().same_closure (it ()), external_logic ());
  2920. // FIXME we shouldn't compare floats
  2921. // BOOST_UBLAS_CHECK (it2_ == it.it2_, external_logic ());
  2922. return it1_ < it.it1_;
  2923. }
  2924. private:
  2925. const_iterator11_type it1_;
  2926. const_subiterator2_type it2_;
  2927. };
  2928. #endif
  2929. BOOST_UBLAS_INLINE
  2930. const_iterator1 begin1 () const {
  2931. return find1 (0, 0, 0);
  2932. }
  2933. BOOST_UBLAS_INLINE
  2934. const_iterator1 end1 () const {
  2935. return find1 (0, size1 (), 0);
  2936. }
  2937. #ifndef BOOST_UBLAS_USE_INDEXED_ITERATOR
  2938. class const_iterator2:
  2939. public container_const_reference<matrix_binary_scalar2>,
  2940. public iterator_base_traits<typename E1::const_iterator2::iterator_category>::template
  2941. iterator_base<const_iterator2, value_type>::type {
  2942. public:
  2943. typedef typename E1::const_iterator2::iterator_category iterator_category;
  2944. typedef typename matrix_binary_scalar2::difference_type difference_type;
  2945. typedef typename matrix_binary_scalar2::value_type value_type;
  2946. typedef typename matrix_binary_scalar2::const_reference reference;
  2947. typedef typename matrix_binary_scalar2::const_pointer pointer;
  2948. typedef const_iterator1 dual_iterator_type;
  2949. typedef const_reverse_iterator1 dual_reverse_iterator_type;
  2950. // Construction and destruction
  2951. BOOST_UBLAS_INLINE
  2952. const_iterator2 ():
  2953. container_const_reference<self_type> (), it1_ (), it2_ () {}
  2954. BOOST_UBLAS_INLINE
  2955. const_iterator2 (const self_type &mbs, const const_iterator12_type &it1, const const_subiterator2_type &it2):
  2956. container_const_reference<self_type> (mbs), it1_ (it1), it2_ (it2) {}
  2957. // Arithmetic
  2958. BOOST_UBLAS_INLINE
  2959. const_iterator2 &operator ++ () {
  2960. ++ it1_;
  2961. return *this;
  2962. }
  2963. BOOST_UBLAS_INLINE
  2964. const_iterator2 &operator -- () {
  2965. -- it1_;
  2966. return *this;
  2967. }
  2968. BOOST_UBLAS_INLINE
  2969. const_iterator2 &operator += (difference_type n) {
  2970. it1_ += n;
  2971. return *this;
  2972. }
  2973. BOOST_UBLAS_INLINE
  2974. const_iterator2 &operator -= (difference_type n) {
  2975. it1_ -= n;
  2976. return *this;
  2977. }
  2978. BOOST_UBLAS_INLINE
  2979. difference_type operator - (const const_iterator2 &it) const {
  2980. BOOST_UBLAS_CHECK ((*this) ().same_closure (it ()), external_logic ());
  2981. // FIXME we shouldn't compare floats
  2982. // BOOST_UBLAS_CHECK (it2_ == it.it2_, external_logic ());
  2983. return it1_ - it.it1_;
  2984. }
  2985. // Dereference
  2986. BOOST_UBLAS_INLINE
  2987. const_reference operator * () const {
  2988. return functor_type::apply (*it1_, it2_);
  2989. }
  2990. BOOST_UBLAS_INLINE
  2991. const_reference operator [] (difference_type n) const {
  2992. return *(*this + n);
  2993. }
  2994. #ifndef BOOST_UBLAS_NO_NESTED_CLASS_RELATION
  2995. BOOST_UBLAS_INLINE
  2996. #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
  2997. typename self_type::
  2998. #endif
  2999. const_iterator1 begin () const {
  3000. return (*this) ().find1 (1, 0, index2 ());
  3001. }
  3002. BOOST_UBLAS_INLINE
  3003. #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
  3004. typename self_type::
  3005. #endif
  3006. const_iterator1 end () const {
  3007. return (*this) ().find1 (1, (*this) ().size1 (), index2 ());
  3008. }
  3009. BOOST_UBLAS_INLINE
  3010. #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
  3011. typename self_type::
  3012. #endif
  3013. const_reverse_iterator1 rbegin () const {
  3014. return const_reverse_iterator1 (end ());
  3015. }
  3016. BOOST_UBLAS_INLINE
  3017. #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
  3018. typename self_type::
  3019. #endif
  3020. const_reverse_iterator1 rend () const {
  3021. return const_reverse_iterator1 (begin ());
  3022. }
  3023. #endif
  3024. // Indices
  3025. BOOST_UBLAS_INLINE
  3026. size_type index1 () const {
  3027. return it1_.index1 ();
  3028. }
  3029. BOOST_UBLAS_INLINE
  3030. size_type index2 () const {
  3031. return it1_.index2 ();
  3032. }
  3033. // Assignment
  3034. BOOST_UBLAS_INLINE
  3035. const_iterator2 &operator = (const const_iterator2 &it) {
  3036. container_const_reference<self_type>::assign (&it ());
  3037. it1_ = it.it1_;
  3038. it2_ = it.it2_;
  3039. return *this;
  3040. }
  3041. // Comparison
  3042. BOOST_UBLAS_INLINE
  3043. bool operator == (const const_iterator2 &it) const {
  3044. BOOST_UBLAS_CHECK ((*this) ().same_closure (it ()), external_logic ());
  3045. // FIXME we shouldn't compare floats
  3046. // BOOST_UBLAS_CHECK (it2_ == it.it2_, external_logic ());
  3047. return it1_ == it.it1_;
  3048. }
  3049. BOOST_UBLAS_INLINE
  3050. bool operator < (const const_iterator2 &it) const {
  3051. BOOST_UBLAS_CHECK ((*this) ().same_closure (it ()), external_logic ());
  3052. // FIXME we shouldn't compare floats
  3053. // BOOST_UBLAS_CHECK (it2_ == it.it2_, external_logic ());
  3054. return it1_ < it.it1_;
  3055. }
  3056. private:
  3057. const_iterator12_type it1_;
  3058. const_subiterator2_type it2_;
  3059. };
  3060. #endif
  3061. BOOST_UBLAS_INLINE
  3062. const_iterator2 begin2 () const {
  3063. return find2 (0, 0, 0);
  3064. }
  3065. BOOST_UBLAS_INLINE
  3066. const_iterator2 end2 () const {
  3067. return find2 (0, 0, size2 ());
  3068. }
  3069. // Reverse iterators
  3070. BOOST_UBLAS_INLINE
  3071. const_reverse_iterator1 rbegin1 () const {
  3072. return const_reverse_iterator1 (end1 ());
  3073. }
  3074. BOOST_UBLAS_INLINE
  3075. const_reverse_iterator1 rend1 () const {
  3076. return const_reverse_iterator1 (begin1 ());
  3077. }
  3078. BOOST_UBLAS_INLINE
  3079. const_reverse_iterator2 rbegin2 () const {
  3080. return const_reverse_iterator2 (end2 ());
  3081. }
  3082. BOOST_UBLAS_INLINE
  3083. const_reverse_iterator2 rend2 () const {
  3084. return const_reverse_iterator2 (begin2 ());
  3085. }
  3086. private:
  3087. expression1_closure_type e1_;
  3088. expression2_closure_type e2_;
  3089. };
  3090. template<class E1, class E2, class F>
  3091. struct matrix_binary_scalar2_traits {
  3092. typedef matrix_binary_scalar2<E1, E2, F> expression_type; // allow E2 to be builtin type
  3093. #ifndef BOOST_UBLAS_SIMPLE_ET_DEBUG
  3094. typedef expression_type result_type;
  3095. #else
  3096. typedef typename E1::matrix_temporary_type result_type;
  3097. #endif
  3098. };
  3099. // (m * t) [i] [j] = m [i] [j] * t
  3100. template<class E1, class T2>
  3101. BOOST_UBLAS_INLINE
  3102. typename enable_if< is_convertible<T2, typename E1::value_type>,
  3103. typename matrix_binary_scalar2_traits<E1, const T2, scalar_multiplies<typename E1::value_type, T2> >::result_type
  3104. >::type
  3105. operator * (const matrix_expression<E1> &e1,
  3106. const T2 &e2) {
  3107. typedef typename matrix_binary_scalar2_traits<E1, const T2, scalar_multiplies<typename E1::value_type, T2> >::expression_type expression_type;
  3108. return expression_type (e1 (), e2);
  3109. }
  3110. // (m / t) [i] [j] = m [i] [j] / t
  3111. template<class E1, class T2>
  3112. BOOST_UBLAS_INLINE
  3113. typename matrix_binary_scalar2_traits<E1, const T2, scalar_divides<typename E1::value_type, T2> >::result_type
  3114. operator / (const matrix_expression<E1> &e1,
  3115. const T2 &e2) {
  3116. typedef typename matrix_binary_scalar2_traits<E1, const T2, scalar_divides<typename E1::value_type, T2> >::expression_type expression_type;
  3117. return expression_type (e1 (), e2);
  3118. }
  3119. template<class E1, class E2, class F>
  3120. class matrix_vector_binary1:
  3121. public vector_expression<matrix_vector_binary1<E1, E2, F> > {
  3122. public:
  3123. typedef E1 expression1_type;
  3124. typedef E2 expression2_type;
  3125. private:
  3126. typedef F functor_type;
  3127. public:
  3128. typedef typename E1::const_closure_type expression1_closure_type;
  3129. typedef typename E2::const_closure_type expression2_closure_type;
  3130. private:
  3131. typedef matrix_vector_binary1<E1, E2, F> self_type;
  3132. public:
  3133. #ifdef BOOST_UBLAS_ENABLE_PROXY_SHORTCUTS
  3134. using vector_expression<self_type>::operator ();
  3135. #endif
  3136. static const unsigned complexity = 1;
  3137. typedef typename promote_traits<typename E1::size_type, typename E2::size_type>::promote_type size_type;
  3138. typedef typename promote_traits<typename E1::difference_type, typename E2::difference_type>::promote_type difference_type;
  3139. typedef typename F::result_type value_type;
  3140. typedef value_type const_reference;
  3141. typedef const_reference reference;
  3142. typedef const self_type const_closure_type;
  3143. typedef const_closure_type closure_type;
  3144. typedef unknown_storage_tag storage_category;
  3145. // Construction and destruction
  3146. BOOST_UBLAS_INLINE
  3147. matrix_vector_binary1 (const expression1_type &e1, const expression2_type &e2):
  3148. e1_ (e1), e2_ (e2) {}
  3149. // Accessors
  3150. BOOST_UBLAS_INLINE
  3151. size_type size () const {
  3152. return e1_.size1 ();
  3153. }
  3154. public:
  3155. // Expression accessors
  3156. BOOST_UBLAS_INLINE
  3157. const expression1_closure_type &expression1 () const {
  3158. return e1_;
  3159. }
  3160. BOOST_UBLAS_INLINE
  3161. const expression2_closure_type &expression2 () const {
  3162. return e2_;
  3163. }
  3164. public:
  3165. // Element access
  3166. BOOST_UBLAS_INLINE
  3167. const_reference operator () (size_type i) const {
  3168. return functor_type::apply (e1_, e2_, i);
  3169. }
  3170. // Closure comparison
  3171. BOOST_UBLAS_INLINE
  3172. bool same_closure (const matrix_vector_binary1 &mvb1) const {
  3173. return (*this).expression1 ().same_closure (mvb1.expression1 ()) &&
  3174. (*this).expression2 ().same_closure (mvb1.expression2 ());
  3175. }
  3176. // Iterator types
  3177. private:
  3178. typedef typename E1::const_iterator1 const_subiterator1_type;
  3179. typedef typename E2::const_iterator const_subiterator2_type;
  3180. typedef const value_type *const_pointer;
  3181. public:
  3182. #ifdef BOOST_UBLAS_USE_INDEXED_ITERATOR
  3183. typedef indexed_const_iterator<const_closure_type, typename const_subiterator1_type::iterator_category> const_iterator;
  3184. typedef const_iterator iterator;
  3185. #else
  3186. class const_iterator;
  3187. typedef const_iterator iterator;
  3188. #endif
  3189. // Element lookup
  3190. BOOST_UBLAS_INLINE
  3191. const_iterator find (size_type i) const {
  3192. #ifdef BOOST_UBLAS_USE_INDEXED_ITERATOR
  3193. const_subiterator1_type it1 (e1_.find1 (0, i, 0));
  3194. return const_iterator (*this, it1.index1 ());
  3195. #else
  3196. return const_iterator (*this, e1_.find1 (0, i, 0));
  3197. #endif
  3198. }
  3199. #ifndef BOOST_UBLAS_USE_INDEXED_ITERATOR
  3200. class const_iterator:
  3201. public container_const_reference<matrix_vector_binary1>,
  3202. public iterator_base_traits<typename iterator_restrict_traits<typename E1::const_iterator1::iterator_category,
  3203. typename E2::const_iterator::iterator_category>::iterator_category>::template
  3204. iterator_base<const_iterator, value_type>::type {
  3205. public:
  3206. typedef typename iterator_restrict_traits<typename E1::const_iterator1::iterator_category,
  3207. typename E2::const_iterator::iterator_category>::iterator_category iterator_category;
  3208. typedef typename matrix_vector_binary1::difference_type difference_type;
  3209. typedef typename matrix_vector_binary1::value_type value_type;
  3210. typedef typename matrix_vector_binary1::const_reference reference;
  3211. typedef typename matrix_vector_binary1::const_pointer pointer;
  3212. // Construction and destruction
  3213. #ifdef BOOST_UBLAS_USE_INVARIANT_HOISTING
  3214. BOOST_UBLAS_INLINE
  3215. const_iterator ():
  3216. container_const_reference<self_type> (), it1_ (), e2_begin_ (), e2_end_ () {}
  3217. BOOST_UBLAS_INLINE
  3218. const_iterator (const self_type &mvb, const const_subiterator1_type &it1):
  3219. container_const_reference<self_type> (mvb), it1_ (it1), e2_begin_ (mvb.expression2 ().begin ()), e2_end_ (mvb.expression2 ().end ()) {}
  3220. #else
  3221. BOOST_UBLAS_INLINE
  3222. const_iterator ():
  3223. container_const_reference<self_type> (), it1_ () {}
  3224. BOOST_UBLAS_INLINE
  3225. const_iterator (const self_type &mvb, const const_subiterator1_type &it1):
  3226. container_const_reference<self_type> (mvb), it1_ (it1) {}
  3227. #endif
  3228. private:
  3229. // Dense random access specialization
  3230. BOOST_UBLAS_INLINE
  3231. value_type dereference (dense_random_access_iterator_tag) const {
  3232. const self_type &mvb = (*this) ();
  3233. #ifdef BOOST_UBLAS_USE_INDEXING
  3234. return mvb (index ());
  3235. #elif BOOST_UBLAS_USE_ITERATING
  3236. difference_type size = BOOST_UBLAS_SAME (mvb.expression1 ().size2 (), mvb.expression2 ().size ());
  3237. #ifdef BOOST_UBLAS_USE_INVARIANT_HOISTING
  3238. return functor_type::apply (size, it1_.begin (), e2_begin_);
  3239. #else
  3240. return functor_type::apply (size, it1_.begin (), mvb.expression2 ().begin ());
  3241. #endif
  3242. #else
  3243. difference_type size = BOOST_UBLAS_SAME (mvb.expression1 ().size2 (), mvb.expression2 ().size ());
  3244. if (size >= BOOST_UBLAS_ITERATOR_THRESHOLD)
  3245. #ifdef BOOST_UBLAS_USE_INVARIANT_HOISTING
  3246. return functor_type::apply (size, it1_.begin (), e2_begin_);
  3247. #else
  3248. return functor_type::apply (size, it1_.begin (), mvb.expression2 ().begin ());
  3249. #endif
  3250. else
  3251. return mvb (index ());
  3252. #endif
  3253. }
  3254. // Packed bidirectional specialization
  3255. BOOST_UBLAS_INLINE
  3256. value_type dereference (packed_random_access_iterator_tag) const {
  3257. #ifdef BOOST_UBLAS_USE_INVARIANT_HOISTING
  3258. return functor_type::apply (it1_.begin (), it1_.end (), e2_begin_, e2_end_);
  3259. #else
  3260. const self_type &mvb = (*this) ();
  3261. #ifndef BOOST_UBLAS_NO_NESTED_CLASS_RELATION
  3262. return functor_type::apply (it1_.begin (), it1_.end (),
  3263. mvb.expression2 ().begin (), mvb.expression2 ().end ());
  3264. #else
  3265. return functor_type::apply (boost::numeric::ublas::begin (it1_, iterator1_tag ()),
  3266. boost::numeric::ublas::end (it1_, iterator1_tag ()),
  3267. mvb.expression2 ().begin (), mvb.expression2 ().end ());
  3268. #endif
  3269. #endif
  3270. }
  3271. // Sparse bidirectional specialization
  3272. BOOST_UBLAS_INLINE
  3273. value_type dereference (sparse_bidirectional_iterator_tag) const {
  3274. #ifdef BOOST_UBLAS_USE_INVARIANT_HOISTING
  3275. return functor_type::apply (it1_.begin (), it1_.end (), e2_begin_, e2_end_, sparse_bidirectional_iterator_tag ());
  3276. #else
  3277. const self_type &mvb = (*this) ();
  3278. #ifndef BOOST_UBLAS_NO_NESTED_CLASS_RELATION
  3279. return functor_type::apply (it1_.begin (), it1_.end (),
  3280. mvb.expression2 ().begin (), mvb.expression2 ().end (), sparse_bidirectional_iterator_tag ());
  3281. #else
  3282. return functor_type::apply (boost::numeric::ublas::begin (it1_, iterator1_tag ()),
  3283. boost::numeric::ublas::end (it1_, iterator1_tag ()),
  3284. mvb.expression2 ().begin (), mvb.expression2 ().end (), sparse_bidirectional_iterator_tag ());
  3285. #endif
  3286. #endif
  3287. }
  3288. public:
  3289. // Arithmetic
  3290. BOOST_UBLAS_INLINE
  3291. const_iterator &operator ++ () {
  3292. ++ it1_;
  3293. return *this;
  3294. }
  3295. BOOST_UBLAS_INLINE
  3296. const_iterator &operator -- () {
  3297. -- it1_;
  3298. return *this;
  3299. }
  3300. BOOST_UBLAS_INLINE
  3301. const_iterator &operator += (difference_type n) {
  3302. it1_ += n;
  3303. return *this;
  3304. }
  3305. BOOST_UBLAS_INLINE
  3306. const_iterator &operator -= (difference_type n) {
  3307. it1_ -= n;
  3308. return *this;
  3309. }
  3310. BOOST_UBLAS_INLINE
  3311. difference_type operator - (const const_iterator &it) const {
  3312. BOOST_UBLAS_CHECK ((*this) ().same_closure (it ()), external_logic ());
  3313. return it1_ - it.it1_;
  3314. }
  3315. // Dereference
  3316. BOOST_UBLAS_INLINE
  3317. const_reference operator * () const {
  3318. return dereference (iterator_category ());
  3319. }
  3320. BOOST_UBLAS_INLINE
  3321. const_reference operator [] (difference_type n) const {
  3322. return *(*this + n);
  3323. }
  3324. // Index
  3325. BOOST_UBLAS_INLINE
  3326. size_type index () const {
  3327. return it1_.index1 ();
  3328. }
  3329. // Assignment
  3330. BOOST_UBLAS_INLINE
  3331. const_iterator &operator = (const const_iterator &it) {
  3332. container_const_reference<self_type>::assign (&it ());
  3333. it1_ = it.it1_;
  3334. #ifdef BOOST_UBLAS_USE_INVARIANT_HOISTING
  3335. e2_begin_ = it.e2_begin_;
  3336. e2_end_ = it.e2_end_;
  3337. #endif
  3338. return *this;
  3339. }
  3340. // Comparison
  3341. BOOST_UBLAS_INLINE
  3342. bool operator == (const const_iterator &it) const {
  3343. BOOST_UBLAS_CHECK ((*this) ().same_closure (it ()), external_logic ());
  3344. return it1_ == it.it1_;
  3345. }
  3346. BOOST_UBLAS_INLINE
  3347. bool operator < (const const_iterator &it) const {
  3348. BOOST_UBLAS_CHECK ((*this) ().same_closure (it ()), external_logic ());
  3349. return it1_ < it.it1_;
  3350. }
  3351. private:
  3352. const_subiterator1_type it1_;
  3353. #ifdef BOOST_UBLAS_USE_INVARIANT_HOISTING
  3354. // Mutable due to assignment
  3355. /* const */ const_subiterator2_type e2_begin_;
  3356. /* const */ const_subiterator2_type e2_end_;
  3357. #endif
  3358. };
  3359. #endif
  3360. BOOST_UBLAS_INLINE
  3361. const_iterator begin () const {
  3362. return find (0);
  3363. }
  3364. BOOST_UBLAS_INLINE
  3365. const_iterator end () const {
  3366. return find (size ());
  3367. }
  3368. // Reverse iterator
  3369. typedef reverse_iterator_base<const_iterator> const_reverse_iterator;
  3370. BOOST_UBLAS_INLINE
  3371. const_reverse_iterator rbegin () const {
  3372. return const_reverse_iterator (end ());
  3373. }
  3374. BOOST_UBLAS_INLINE
  3375. const_reverse_iterator rend () const {
  3376. return const_reverse_iterator (begin ());
  3377. }
  3378. private:
  3379. expression1_closure_type e1_;
  3380. expression2_closure_type e2_;
  3381. };
  3382. template<class T1, class E1, class T2, class E2>
  3383. struct matrix_vector_binary1_traits {
  3384. typedef unknown_storage_tag storage_category;
  3385. typedef row_major_tag orientation_category;
  3386. typedef typename promote_traits<T1, T2>::promote_type promote_type;
  3387. typedef matrix_vector_binary1<E1, E2, matrix_vector_prod1<E1, E2, promote_type> > expression_type;
  3388. #ifndef BOOST_UBLAS_SIMPLE_ET_DEBUG
  3389. typedef expression_type result_type;
  3390. #else
  3391. typedef typename E1::vector_temporary_type result_type;
  3392. #endif
  3393. };
  3394. template<class E1, class E2>
  3395. BOOST_UBLAS_INLINE
  3396. typename matrix_vector_binary1_traits<typename E1::value_type, E1,
  3397. typename E2::value_type, E2>::result_type
  3398. prod (const matrix_expression<E1> &e1,
  3399. const vector_expression<E2> &e2,
  3400. unknown_storage_tag,
  3401. row_major_tag) {
  3402. typedef typename matrix_vector_binary1_traits<typename E1::value_type, E1,
  3403. typename E2::value_type, E2>::expression_type expression_type;
  3404. return expression_type (e1 (), e2 ());
  3405. }
  3406. // Dispatcher
  3407. template<class E1, class E2>
  3408. BOOST_UBLAS_INLINE
  3409. typename matrix_vector_binary1_traits<typename E1::value_type, E1,
  3410. typename E2::value_type, E2>::result_type
  3411. prod (const matrix_expression<E1> &e1,
  3412. const vector_expression<E2> &e2) {
  3413. BOOST_STATIC_ASSERT (E2::complexity == 0);
  3414. typedef typename matrix_vector_binary1_traits<typename E1::value_type, E1,
  3415. typename E2::value_type, E2>::storage_category storage_category;
  3416. typedef typename matrix_vector_binary1_traits<typename E1::value_type, E1,
  3417. typename E2::value_type, E2>::orientation_category orientation_category;
  3418. return prod (e1, e2, storage_category (), orientation_category ());
  3419. }
  3420. template<class E1, class E2>
  3421. BOOST_UBLAS_INLINE
  3422. typename matrix_vector_binary1_traits<typename type_traits<typename E1::value_type>::precision_type, E1,
  3423. typename type_traits<typename E2::value_type>::precision_type, E2>::result_type
  3424. prec_prod (const matrix_expression<E1> &e1,
  3425. const vector_expression<E2> &e2,
  3426. unknown_storage_tag,
  3427. row_major_tag) {
  3428. typedef typename matrix_vector_binary1_traits<typename type_traits<typename E1::value_type>::precision_type, E1,
  3429. typename type_traits<typename E2::value_type>::precision_type, E2>::expression_type expression_type;
  3430. return expression_type (e1 (), e2 ());
  3431. }
  3432. // Dispatcher
  3433. template<class E1, class E2>
  3434. BOOST_UBLAS_INLINE
  3435. typename matrix_vector_binary1_traits<typename type_traits<typename E1::value_type>::precision_type, E1,
  3436. typename type_traits<typename E2::value_type>::precision_type, E2>::result_type
  3437. prec_prod (const matrix_expression<E1> &e1,
  3438. const vector_expression<E2> &e2) {
  3439. BOOST_STATIC_ASSERT (E2::complexity == 0);
  3440. typedef typename matrix_vector_binary1_traits<typename type_traits<typename E1::value_type>::precision_type, E1,
  3441. typename type_traits<typename E2::value_type>::precision_type, E2>::storage_category storage_category;
  3442. typedef typename matrix_vector_binary1_traits<typename type_traits<typename E1::value_type>::precision_type, E1,
  3443. typename type_traits<typename E2::value_type>::precision_type, E2>::orientation_category orientation_category;
  3444. return prec_prod (e1, e2, storage_category (), orientation_category ());
  3445. }
  3446. template<class V, class E1, class E2>
  3447. BOOST_UBLAS_INLINE
  3448. V &
  3449. prod (const matrix_expression<E1> &e1,
  3450. const vector_expression<E2> &e2,
  3451. V &v) {
  3452. return v.assign (prod (e1, e2));
  3453. }
  3454. template<class V, class E1, class E2>
  3455. BOOST_UBLAS_INLINE
  3456. V &
  3457. prec_prod (const matrix_expression<E1> &e1,
  3458. const vector_expression<E2> &e2,
  3459. V &v) {
  3460. return v.assign (prec_prod (e1, e2));
  3461. }
  3462. template<class V, class E1, class E2>
  3463. BOOST_UBLAS_INLINE
  3464. V
  3465. prod (const matrix_expression<E1> &e1,
  3466. const vector_expression<E2> &e2) {
  3467. return V (prod (e1, e2));
  3468. }
  3469. template<class V, class E1, class E2>
  3470. BOOST_UBLAS_INLINE
  3471. V
  3472. prec_prod (const matrix_expression<E1> &e1,
  3473. const vector_expression<E2> &e2) {
  3474. return V (prec_prod (e1, e2));
  3475. }
  3476. template<class E1, class E2, class F>
  3477. class matrix_vector_binary2:
  3478. public vector_expression<matrix_vector_binary2<E1, E2, F> > {
  3479. typedef E1 expression1_type;
  3480. typedef E2 expression2_type;
  3481. typedef F functor_type;
  3482. public:
  3483. typedef typename E1::const_closure_type expression1_closure_type;
  3484. typedef typename E2::const_closure_type expression2_closure_type;
  3485. private:
  3486. typedef matrix_vector_binary2<E1, E2, F> self_type;
  3487. public:
  3488. #ifdef BOOST_UBLAS_ENABLE_PROXY_SHORTCUTS
  3489. using vector_expression<self_type>::operator ();
  3490. #endif
  3491. static const unsigned complexity = 1;
  3492. typedef typename promote_traits<typename E1::size_type, typename E2::size_type>::promote_type size_type;
  3493. typedef typename promote_traits<typename E1::difference_type, typename E2::difference_type>::promote_type difference_type;
  3494. typedef typename F::result_type value_type;
  3495. typedef value_type const_reference;
  3496. typedef const_reference reference;
  3497. typedef const self_type const_closure_type;
  3498. typedef const_closure_type closure_type;
  3499. typedef unknown_storage_tag storage_category;
  3500. // Construction and destruction
  3501. BOOST_UBLAS_INLINE
  3502. matrix_vector_binary2 (const expression1_type &e1, const expression2_type &e2):
  3503. e1_ (e1), e2_ (e2) {}
  3504. // Accessors
  3505. BOOST_UBLAS_INLINE
  3506. size_type size () const {
  3507. return e2_.size2 ();
  3508. }
  3509. public:
  3510. // Expression accessors
  3511. BOOST_UBLAS_INLINE
  3512. const expression1_closure_type &expression1 () const {
  3513. return e1_;
  3514. }
  3515. BOOST_UBLAS_INLINE
  3516. const expression2_closure_type &expression2 () const {
  3517. return e2_;
  3518. }
  3519. public:
  3520. // Element access
  3521. BOOST_UBLAS_INLINE
  3522. const_reference operator () (size_type j) const {
  3523. return functor_type::apply (e1_, e2_, j);
  3524. }
  3525. // Closure comparison
  3526. BOOST_UBLAS_INLINE
  3527. bool same_closure (const matrix_vector_binary2 &mvb2) const {
  3528. return (*this).expression1 ().same_closure (mvb2.expression1 ()) &&
  3529. (*this).expression2 ().same_closure (mvb2.expression2 ());
  3530. }
  3531. // Iterator types
  3532. private:
  3533. typedef typename E1::const_iterator const_subiterator1_type;
  3534. typedef typename E2::const_iterator2 const_subiterator2_type;
  3535. typedef const value_type *const_pointer;
  3536. public:
  3537. #ifdef BOOST_UBLAS_USE_INDEXED_ITERATOR
  3538. typedef indexed_const_iterator<const_closure_type, typename const_subiterator2_type::iterator_category> const_iterator;
  3539. typedef const_iterator iterator;
  3540. #else
  3541. class const_iterator;
  3542. typedef const_iterator iterator;
  3543. #endif
  3544. // Element lookup
  3545. BOOST_UBLAS_INLINE
  3546. const_iterator find (size_type j) const {
  3547. #ifdef BOOST_UBLAS_USE_INDEXED_ITERATOR
  3548. const_subiterator2_type it2 (e2_.find2 (0, 0, j));
  3549. return const_iterator (*this, it2.index2 ());
  3550. #else
  3551. return const_iterator (*this, e2_.find2 (0, 0, j));
  3552. #endif
  3553. }
  3554. #ifndef BOOST_UBLAS_USE_INDEXED_ITERATOR
  3555. class const_iterator:
  3556. public container_const_reference<matrix_vector_binary2>,
  3557. public iterator_base_traits<typename iterator_restrict_traits<typename E1::const_iterator::iterator_category,
  3558. typename E2::const_iterator2::iterator_category>::iterator_category>::template
  3559. iterator_base<const_iterator, value_type>::type {
  3560. public:
  3561. typedef typename iterator_restrict_traits<typename E1::const_iterator::iterator_category,
  3562. typename E2::const_iterator2::iterator_category>::iterator_category iterator_category;
  3563. typedef typename matrix_vector_binary2::difference_type difference_type;
  3564. typedef typename matrix_vector_binary2::value_type value_type;
  3565. typedef typename matrix_vector_binary2::const_reference reference;
  3566. typedef typename matrix_vector_binary2::const_pointer pointer;
  3567. // Construction and destruction
  3568. #ifdef BOOST_UBLAS_USE_INVARIANT_HOISTING
  3569. BOOST_UBLAS_INLINE
  3570. const_iterator ():
  3571. container_const_reference<self_type> (), it2_ (), e1_begin_ (), e1_end_ () {}
  3572. BOOST_UBLAS_INLINE
  3573. const_iterator (const self_type &mvb, const const_subiterator2_type &it2):
  3574. container_const_reference<self_type> (mvb), it2_ (it2), e1_begin_ (mvb.expression1 ().begin ()), e1_end_ (mvb.expression1 ().end ()) {}
  3575. #else
  3576. BOOST_UBLAS_INLINE
  3577. const_iterator ():
  3578. container_const_reference<self_type> (), it2_ () {}
  3579. BOOST_UBLAS_INLINE
  3580. const_iterator (const self_type &mvb, const const_subiterator2_type &it2):
  3581. container_const_reference<self_type> (mvb), it2_ (it2) {}
  3582. #endif
  3583. private:
  3584. // Dense random access specialization
  3585. BOOST_UBLAS_INLINE
  3586. value_type dereference (dense_random_access_iterator_tag) const {
  3587. const self_type &mvb = (*this) ();
  3588. #ifdef BOOST_UBLAS_USE_INDEXING
  3589. return mvb (index ());
  3590. #elif BOOST_UBLAS_USE_ITERATING
  3591. difference_type size = BOOST_UBLAS_SAME (mvb.expression2 ().size1 (), mvb.expression1 ().size ());
  3592. #ifdef BOOST_UBLAS_USE_INVARIANT_HOISTING
  3593. return functor_type::apply (size, e1_begin_, it2_.begin ());
  3594. #else
  3595. return functor_type::apply (size, mvb.expression1 ().begin (), it2_.begin ());
  3596. #endif
  3597. #else
  3598. difference_type size = BOOST_UBLAS_SAME (mvb.expression2 ().size1 (), mvb.expression1 ().size ());
  3599. if (size >= BOOST_UBLAS_ITERATOR_THRESHOLD)
  3600. #ifdef BOOST_UBLAS_USE_INVARIANT_HOISTING
  3601. return functor_type::apply (size, e1_begin_, it2_.begin ());
  3602. #else
  3603. return functor_type::apply (size, mvb.expression1 ().begin (), it2_.begin ());
  3604. #endif
  3605. else
  3606. return mvb (index ());
  3607. #endif
  3608. }
  3609. // Packed bidirectional specialization
  3610. BOOST_UBLAS_INLINE
  3611. value_type dereference (packed_random_access_iterator_tag) const {
  3612. #ifdef BOOST_UBLAS_USE_INVARIANT_HOISTING
  3613. return functor_type::apply (e1_begin_, e1_end_, it2_.begin (), it2_.end ());
  3614. #else
  3615. const self_type &mvb = (*this) ();
  3616. #ifndef BOOST_UBLAS_NO_NESTED_CLASS_RELATION
  3617. return functor_type::apply (mvb.expression1 ().begin (), mvb.expression1 ().end (),
  3618. it2_.begin (), it2_.end ());
  3619. #else
  3620. return functor_type::apply (mvb.expression1 ().begin (), mvb.expression1 ().end (),
  3621. boost::numeric::ublas::begin (it2_, iterator2_tag ()),
  3622. boost::numeric::ublas::end (it2_, iterator2_tag ()));
  3623. #endif
  3624. #endif
  3625. }
  3626. // Sparse bidirectional specialization
  3627. BOOST_UBLAS_INLINE
  3628. value_type dereference (sparse_bidirectional_iterator_tag) const {
  3629. #ifdef BOOST_UBLAS_USE_INVARIANT_HOISTING
  3630. return functor_type::apply (e1_begin_, e1_end_, it2_.begin (), it2_.end (), sparse_bidirectional_iterator_tag ());
  3631. #else
  3632. const self_type &mvb = (*this) ();
  3633. #ifndef BOOST_UBLAS_NO_NESTED_CLASS_RELATION
  3634. return functor_type::apply (mvb.expression1 ().begin (), mvb.expression1 ().end (),
  3635. it2_.begin (), it2_.end (), sparse_bidirectional_iterator_tag ());
  3636. #else
  3637. return functor_type::apply (mvb.expression1 ().begin (), mvb.expression1 ().end (),
  3638. boost::numeric::ublas::begin (it2_, iterator2_tag ()),
  3639. boost::numeric::ublas::end (it2_, iterator2_tag ()), sparse_bidirectional_iterator_tag ());
  3640. #endif
  3641. #endif
  3642. }
  3643. public:
  3644. // Arithmetic
  3645. BOOST_UBLAS_INLINE
  3646. const_iterator &operator ++ () {
  3647. ++ it2_;
  3648. return *this;
  3649. }
  3650. BOOST_UBLAS_INLINE
  3651. const_iterator &operator -- () {
  3652. -- it2_;
  3653. return *this;
  3654. }
  3655. BOOST_UBLAS_INLINE
  3656. const_iterator &operator += (difference_type n) {
  3657. it2_ += n;
  3658. return *this;
  3659. }
  3660. BOOST_UBLAS_INLINE
  3661. const_iterator &operator -= (difference_type n) {
  3662. it2_ -= n;
  3663. return *this;
  3664. }
  3665. BOOST_UBLAS_INLINE
  3666. difference_type operator - (const const_iterator &it) const {
  3667. BOOST_UBLAS_CHECK ((*this) ().same_closure (it ()), external_logic ());
  3668. return it2_ - it.it2_;
  3669. }
  3670. // Dereference
  3671. BOOST_UBLAS_INLINE
  3672. const_reference operator * () const {
  3673. return dereference (iterator_category ());
  3674. }
  3675. BOOST_UBLAS_INLINE
  3676. const_reference operator [] (difference_type n) const {
  3677. return *(*this + n);
  3678. }
  3679. // Index
  3680. BOOST_UBLAS_INLINE
  3681. size_type index () const {
  3682. return it2_.index2 ();
  3683. }
  3684. // Assignment
  3685. BOOST_UBLAS_INLINE
  3686. const_iterator &operator = (const const_iterator &it) {
  3687. container_const_reference<self_type>::assign (&it ());
  3688. it2_ = it.it2_;
  3689. #ifdef BOOST_UBLAS_USE_INVARIANT_HOISTING
  3690. e1_begin_ = it.e1_begin_;
  3691. e1_end_ = it.e1_end_;
  3692. #endif
  3693. return *this;
  3694. }
  3695. // Comparison
  3696. BOOST_UBLAS_INLINE
  3697. bool operator == (const const_iterator &it) const {
  3698. BOOST_UBLAS_CHECK ((*this) ().same_closure (it ()), external_logic ());
  3699. return it2_ == it.it2_;
  3700. }
  3701. BOOST_UBLAS_INLINE
  3702. bool operator < (const const_iterator &it) const {
  3703. BOOST_UBLAS_CHECK ((*this) ().same_closure (it ()), external_logic ());
  3704. return it2_ < it.it2_;
  3705. }
  3706. private:
  3707. const_subiterator2_type it2_;
  3708. #ifdef BOOST_UBLAS_USE_INVARIANT_HOISTING
  3709. // Mutable due to assignment
  3710. /* const */ const_subiterator1_type e1_begin_;
  3711. /* const */ const_subiterator1_type e1_end_;
  3712. #endif
  3713. };
  3714. #endif
  3715. BOOST_UBLAS_INLINE
  3716. const_iterator begin () const {
  3717. return find (0);
  3718. }
  3719. BOOST_UBLAS_INLINE
  3720. const_iterator end () const {
  3721. return find (size ());
  3722. }
  3723. // Reverse iterator
  3724. typedef reverse_iterator_base<const_iterator> const_reverse_iterator;
  3725. BOOST_UBLAS_INLINE
  3726. const_reverse_iterator rbegin () const {
  3727. return const_reverse_iterator (end ());
  3728. }
  3729. BOOST_UBLAS_INLINE
  3730. const_reverse_iterator rend () const {
  3731. return const_reverse_iterator (begin ());
  3732. }
  3733. private:
  3734. expression1_closure_type e1_;
  3735. expression2_closure_type e2_;
  3736. };
  3737. template<class T1, class E1, class T2, class E2>
  3738. struct matrix_vector_binary2_traits {
  3739. typedef unknown_storage_tag storage_category;
  3740. typedef column_major_tag orientation_category;
  3741. typedef typename promote_traits<T1, T2>::promote_type promote_type;
  3742. typedef matrix_vector_binary2<E1, E2, matrix_vector_prod2<E1, E2, promote_type> > expression_type;
  3743. #ifndef BOOST_UBLAS_SIMPLE_ET_DEBUG
  3744. typedef expression_type result_type;
  3745. #else
  3746. typedef typename E2::vector_temporary_type result_type;
  3747. #endif
  3748. };
  3749. template<class E1, class E2>
  3750. BOOST_UBLAS_INLINE
  3751. typename matrix_vector_binary2_traits<typename E1::value_type, E1,
  3752. typename E2::value_type, E2>::result_type
  3753. prod (const vector_expression<E1> &e1,
  3754. const matrix_expression<E2> &e2,
  3755. unknown_storage_tag,
  3756. column_major_tag) {
  3757. typedef typename matrix_vector_binary2_traits<typename E1::value_type, E1,
  3758. typename E2::value_type, E2>::expression_type expression_type;
  3759. return expression_type (e1 (), e2 ());
  3760. }
  3761. // Dispatcher
  3762. template<class E1, class E2>
  3763. BOOST_UBLAS_INLINE
  3764. typename matrix_vector_binary2_traits<typename E1::value_type, E1,
  3765. typename E2::value_type, E2>::result_type
  3766. prod (const vector_expression<E1> &e1,
  3767. const matrix_expression<E2> &e2) {
  3768. BOOST_STATIC_ASSERT (E1::complexity == 0);
  3769. typedef typename matrix_vector_binary2_traits<typename E1::value_type, E1,
  3770. typename E2::value_type, E2>::storage_category storage_category;
  3771. typedef typename matrix_vector_binary2_traits<typename E1::value_type, E1,
  3772. typename E2::value_type, E2>::orientation_category orientation_category;
  3773. return prod (e1, e2, storage_category (), orientation_category ());
  3774. }
  3775. template<class E1, class E2>
  3776. BOOST_UBLAS_INLINE
  3777. typename matrix_vector_binary2_traits<typename type_traits<typename E1::value_type>::precision_type, E1,
  3778. typename type_traits<typename E2::value_type>::precision_type, E2>::result_type
  3779. prec_prod (const vector_expression<E1> &e1,
  3780. const matrix_expression<E2> &e2,
  3781. unknown_storage_tag,
  3782. column_major_tag) {
  3783. typedef typename matrix_vector_binary2_traits<typename type_traits<typename E1::value_type>::precision_type, E1,
  3784. typename type_traits<typename E2::value_type>::precision_type, E2>::expression_type expression_type;
  3785. return expression_type (e1 (), e2 ());
  3786. }
  3787. // Dispatcher
  3788. template<class E1, class E2>
  3789. BOOST_UBLAS_INLINE
  3790. typename matrix_vector_binary2_traits<typename type_traits<typename E1::value_type>::precision_type, E1,
  3791. typename type_traits<typename E2::value_type>::precision_type, E2>::result_type
  3792. prec_prod (const vector_expression<E1> &e1,
  3793. const matrix_expression<E2> &e2) {
  3794. BOOST_STATIC_ASSERT (E1::complexity == 0);
  3795. typedef typename matrix_vector_binary2_traits<typename type_traits<typename E1::value_type>::precision_type, E1,
  3796. typename type_traits<typename E2::value_type>::precision_type, E2>::storage_category storage_category;
  3797. typedef typename matrix_vector_binary2_traits<typename type_traits<typename E1::value_type>::precision_type, E1,
  3798. typename type_traits<typename E2::value_type>::precision_type, E2>::orientation_category orientation_category;
  3799. return prec_prod (e1, e2, storage_category (), orientation_category ());
  3800. }
  3801. template<class V, class E1, class E2>
  3802. BOOST_UBLAS_INLINE
  3803. V &
  3804. prod (const vector_expression<E1> &e1,
  3805. const matrix_expression<E2> &e2,
  3806. V &v) {
  3807. return v.assign (prod (e1, e2));
  3808. }
  3809. template<class V, class E1, class E2>
  3810. BOOST_UBLAS_INLINE
  3811. V &
  3812. prec_prod (const vector_expression<E1> &e1,
  3813. const matrix_expression<E2> &e2,
  3814. V &v) {
  3815. return v.assign (prec_prod (e1, e2));
  3816. }
  3817. template<class V, class E1, class E2>
  3818. BOOST_UBLAS_INLINE
  3819. V
  3820. prod (const vector_expression<E1> &e1,
  3821. const matrix_expression<E2> &e2) {
  3822. return V (prod (e1, e2));
  3823. }
  3824. template<class V, class E1, class E2>
  3825. BOOST_UBLAS_INLINE
  3826. V
  3827. prec_prod (const vector_expression<E1> &e1,
  3828. const matrix_expression<E2> &e2) {
  3829. return V (prec_prod (e1, e2));
  3830. }
  3831. template<class E1, class E2, class F>
  3832. class matrix_matrix_binary:
  3833. public matrix_expression<matrix_matrix_binary<E1, E2, F> > {
  3834. public:
  3835. typedef E1 expression1_type;
  3836. typedef E2 expression2_type;
  3837. private:
  3838. typedef F functor_type;
  3839. public:
  3840. typedef typename E1::const_closure_type expression1_closure_type;
  3841. typedef typename E2::const_closure_type expression2_closure_type;
  3842. private:
  3843. typedef matrix_matrix_binary<E1, E2, F> self_type;
  3844. public:
  3845. #ifdef BOOST_UBLAS_ENABLE_PROXY_SHORTCUTS
  3846. using matrix_expression<self_type>::operator ();
  3847. #endif
  3848. static const unsigned complexity = 1;
  3849. typedef typename promote_traits<typename E1::size_type, typename E2::size_type>::promote_type size_type;
  3850. typedef typename promote_traits<typename E1::difference_type, typename E2::difference_type>::promote_type difference_type;
  3851. typedef typename F::result_type value_type;
  3852. typedef value_type const_reference;
  3853. typedef const_reference reference;
  3854. typedef const self_type const_closure_type;
  3855. typedef const_closure_type closure_type;
  3856. typedef unknown_orientation_tag orientation_category;
  3857. typedef unknown_storage_tag storage_category;
  3858. // Construction and destruction
  3859. BOOST_UBLAS_INLINE
  3860. matrix_matrix_binary (const expression1_type &e1, const expression2_type &e2):
  3861. e1_ (e1), e2_ (e2) {}
  3862. // Accessors
  3863. BOOST_UBLAS_INLINE
  3864. size_type size1 () const {
  3865. return e1_.size1 ();
  3866. }
  3867. BOOST_UBLAS_INLINE
  3868. size_type size2 () const {
  3869. return e2_.size2 ();
  3870. }
  3871. public:
  3872. // Expression accessors
  3873. BOOST_UBLAS_INLINE
  3874. const expression1_closure_type &expression1 () const {
  3875. return e1_;
  3876. }
  3877. BOOST_UBLAS_INLINE
  3878. const expression2_closure_type &expression2 () const {
  3879. return e2_;
  3880. }
  3881. public:
  3882. // Element access
  3883. BOOST_UBLAS_INLINE
  3884. const_reference operator () (size_type i, size_type j) const {
  3885. return functor_type::apply (e1_, e2_, i, j);
  3886. }
  3887. // Closure comparison
  3888. BOOST_UBLAS_INLINE
  3889. bool same_closure (const matrix_matrix_binary &mmb) const {
  3890. return (*this).expression1 ().same_closure (mmb.expression1 ()) &&
  3891. (*this).expression2 ().same_closure (mmb.expression2 ());
  3892. }
  3893. // Iterator types
  3894. private:
  3895. typedef typename E1::const_iterator1 const_iterator11_type;
  3896. typedef typename E1::const_iterator2 const_iterator12_type;
  3897. typedef typename E2::const_iterator1 const_iterator21_type;
  3898. typedef typename E2::const_iterator2 const_iterator22_type;
  3899. typedef const value_type *const_pointer;
  3900. public:
  3901. #ifdef BOOST_UBLAS_USE_INDEXED_ITERATOR
  3902. typedef typename iterator_restrict_traits<typename const_iterator11_type::iterator_category,
  3903. typename const_iterator22_type::iterator_category>::iterator_category iterator_category;
  3904. typedef indexed_const_iterator1<const_closure_type, iterator_category> const_iterator1;
  3905. typedef const_iterator1 iterator1;
  3906. typedef indexed_const_iterator2<const_closure_type, iterator_category> const_iterator2;
  3907. typedef const_iterator2 iterator2;
  3908. #else
  3909. class const_iterator1;
  3910. typedef const_iterator1 iterator1;
  3911. class const_iterator2;
  3912. typedef const_iterator2 iterator2;
  3913. #endif
  3914. typedef reverse_iterator_base1<const_iterator1> const_reverse_iterator1;
  3915. typedef reverse_iterator_base2<const_iterator2> const_reverse_iterator2;
  3916. // Element lookup
  3917. BOOST_UBLAS_INLINE
  3918. const_iterator1 find1 (int /* rank */, size_type i, size_type j) const {
  3919. // FIXME sparse matrix tests fail!
  3920. // const_iterator11_type it11 (e1_.find1 (rank, i, 0));
  3921. const_iterator11_type it11 (e1_.find1 (0, i, 0));
  3922. #ifdef BOOST_UBLAS_USE_INDEXED_ITERATOR
  3923. return const_iterator1 (*this, it11.index1 (), j);
  3924. #else
  3925. // FIXME sparse matrix tests fail!
  3926. // const_iterator22_type it22 (e2_.find2 (rank, 0, j));
  3927. const_iterator22_type it22 (e2_.find2 (0, 0, j));
  3928. return const_iterator1 (*this, it11, it22);
  3929. #endif
  3930. }
  3931. BOOST_UBLAS_INLINE
  3932. const_iterator2 find2 (int /* rank */, size_type i, size_type j) const {
  3933. // FIXME sparse matrix tests fail!
  3934. // const_iterator22_type it22 (e2_.find2 (rank, 0, j));
  3935. const_iterator22_type it22 (e2_.find2 (0, 0, j));
  3936. #ifdef BOOST_UBLAS_USE_INDEXED_ITERATOR
  3937. return const_iterator2 (*this, i, it22.index2 ());
  3938. #else
  3939. // FIXME sparse matrix tests fail!
  3940. // const_iterator11_type it11 (e1_.find1 (rank, i, 0));
  3941. const_iterator11_type it11 (e1_.find1 (0, i, 0));
  3942. return const_iterator2 (*this, it11, it22);
  3943. #endif
  3944. }
  3945. #ifndef BOOST_UBLAS_USE_INDEXED_ITERATOR
  3946. class const_iterator1:
  3947. public container_const_reference<matrix_matrix_binary>,
  3948. public iterator_base_traits<typename iterator_restrict_traits<typename E1::const_iterator1::iterator_category,
  3949. typename E2::const_iterator2::iterator_category>::iterator_category>::template
  3950. iterator_base<const_iterator1, value_type>::type {
  3951. public:
  3952. typedef typename iterator_restrict_traits<typename E1::const_iterator1::iterator_category,
  3953. typename E2::const_iterator2::iterator_category>::iterator_category iterator_category;
  3954. typedef typename matrix_matrix_binary::difference_type difference_type;
  3955. typedef typename matrix_matrix_binary::value_type value_type;
  3956. typedef typename matrix_matrix_binary::const_reference reference;
  3957. typedef typename matrix_matrix_binary::const_pointer pointer;
  3958. typedef const_iterator2 dual_iterator_type;
  3959. typedef const_reverse_iterator2 dual_reverse_iterator_type;
  3960. // Construction and destruction
  3961. #ifdef BOOST_UBLAS_USE_INVARIANT_HOISTING
  3962. BOOST_UBLAS_INLINE
  3963. const_iterator1 ():
  3964. container_const_reference<self_type> (), it1_ (), it2_ (), it2_begin_ (), it2_end_ () {}
  3965. BOOST_UBLAS_INLINE
  3966. const_iterator1 (const self_type &mmb, const const_iterator11_type &it1, const const_iterator22_type &it2):
  3967. container_const_reference<self_type> (mmb), it1_ (it1), it2_ (it2), it2_begin_ (it2.begin ()), it2_end_ (it2.end ()) {}
  3968. #else
  3969. BOOST_UBLAS_INLINE
  3970. const_iterator1 ():
  3971. container_const_reference<self_type> (), it1_ (), it2_ () {}
  3972. BOOST_UBLAS_INLINE
  3973. const_iterator1 (const self_type &mmb, const const_iterator11_type &it1, const const_iterator22_type &it2):
  3974. container_const_reference<self_type> (mmb), it1_ (it1), it2_ (it2) {}
  3975. #endif
  3976. private:
  3977. // Random access specialization
  3978. BOOST_UBLAS_INLINE
  3979. value_type dereference (dense_random_access_iterator_tag) const {
  3980. const self_type &mmb = (*this) ();
  3981. #ifdef BOOST_UBLAS_USE_INDEXING
  3982. return mmb (index1 (), index2 ());
  3983. #elif BOOST_UBLAS_USE_ITERATING
  3984. difference_type size = BOOST_UBLAS_SAME (mmb.expression1 ().size2 (), mmb.expression2 ().size1 ());
  3985. #ifdef BOOST_UBLAS_USE_INVARIANT_HOISTING
  3986. return functor_type::apply (size, it1_.begin (), it2_begin_);
  3987. #else
  3988. return functor_type::apply (size, it1_.begin (), it2_.begin ());
  3989. #endif
  3990. #else
  3991. difference_type size = BOOST_UBLAS_SAME (mmb.expression1 ().size2 (), mmb.expression2 ().size1 ());
  3992. if (size >= BOOST_UBLAS_ITERATOR_THRESHOLD)
  3993. #ifdef BOOST_UBLAS_USE_INVARIANT_HOISTING
  3994. return functor_type::apply (size, it1_.begin (), it2_begin_);
  3995. #else
  3996. return functor_type::apply (size, it1_.begin (), it2_.begin ());
  3997. #endif
  3998. else
  3999. return mmb (index1 (), index2 ());
  4000. #endif
  4001. }
  4002. // Packed bidirectional specialization
  4003. BOOST_UBLAS_INLINE
  4004. value_type dereference (packed_random_access_iterator_tag) const {
  4005. #ifdef BOOST_UBLAS_USE_INVARIANT_HOISTING
  4006. return functor_type::apply (it1_.begin (), it1_.end (),
  4007. it2_begin_, it2_end_, packed_random_access_iterator_tag ());
  4008. #else
  4009. #ifndef BOOST_UBLAS_NO_NESTED_CLASS_RELATION
  4010. return functor_type::apply (it1_.begin (), it1_.end (),
  4011. it2_.begin (), it2_.end (), packed_random_access_iterator_tag ());
  4012. #else
  4013. return functor_type::apply (boost::numeric::ublas::begin (it1_, iterator1_tag ()),
  4014. boost::numeric::ublas::end (it1_, iterator1_tag ()),
  4015. boost::numeric::ublas::begin (it2_, iterator2_tag ()),
  4016. boost::numeric::ublas::end (it2_, iterator2_tag ()), packed_random_access_iterator_tag ());
  4017. #endif
  4018. #endif
  4019. }
  4020. // Sparse bidirectional specialization
  4021. BOOST_UBLAS_INLINE
  4022. value_type dereference (sparse_bidirectional_iterator_tag) const {
  4023. #ifdef BOOST_UBLAS_USE_INVARIANT_HOISTING
  4024. return functor_type::apply (it1_.begin (), it1_.end (),
  4025. it2_begin_, it2_end_, sparse_bidirectional_iterator_tag ());
  4026. #else
  4027. #ifndef BOOST_UBLAS_NO_NESTED_CLASS_RELATION
  4028. return functor_type::apply (it1_.begin (), it1_.end (),
  4029. it2_.begin (), it2_.end (), sparse_bidirectional_iterator_tag ());
  4030. #else
  4031. return functor_type::apply (boost::numeric::ublas::begin (it1_, iterator1_tag ()),
  4032. boost::numeric::ublas::end (it1_, iterator1_tag ()),
  4033. boost::numeric::ublas::begin (it2_, iterator2_tag ()),
  4034. boost::numeric::ublas::end (it2_, iterator2_tag ()), sparse_bidirectional_iterator_tag ());
  4035. #endif
  4036. #endif
  4037. }
  4038. public:
  4039. // Arithmetic
  4040. BOOST_UBLAS_INLINE
  4041. const_iterator1 &operator ++ () {
  4042. ++ it1_;
  4043. return *this;
  4044. }
  4045. BOOST_UBLAS_INLINE
  4046. const_iterator1 &operator -- () {
  4047. -- it1_;
  4048. return *this;
  4049. }
  4050. BOOST_UBLAS_INLINE
  4051. const_iterator1 &operator += (difference_type n) {
  4052. it1_ += n;
  4053. return *this;
  4054. }
  4055. BOOST_UBLAS_INLINE
  4056. const_iterator1 &operator -= (difference_type n) {
  4057. it1_ -= n;
  4058. return *this;
  4059. }
  4060. BOOST_UBLAS_INLINE
  4061. difference_type operator - (const const_iterator1 &it) const {
  4062. BOOST_UBLAS_CHECK ((*this) ().same_closure (it ()), external_logic ());
  4063. BOOST_UBLAS_CHECK (it2_ == it.it2_, external_logic ());
  4064. return it1_ - it.it1_;
  4065. }
  4066. // Dereference
  4067. BOOST_UBLAS_INLINE
  4068. const_reference operator * () const {
  4069. return dereference (iterator_category ());
  4070. }
  4071. BOOST_UBLAS_INLINE
  4072. const_reference operator [] (difference_type n) const {
  4073. return *(*this + n);
  4074. }
  4075. #ifndef BOOST_UBLAS_NO_NESTED_CLASS_RELATION
  4076. BOOST_UBLAS_INLINE
  4077. #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
  4078. typename self_type::
  4079. #endif
  4080. const_iterator2 begin () const {
  4081. return (*this) ().find2 (1, index1 (), 0);
  4082. }
  4083. BOOST_UBLAS_INLINE
  4084. #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
  4085. typename self_type::
  4086. #endif
  4087. const_iterator2 end () const {
  4088. return (*this) ().find2 (1, index1 (), (*this) ().size2 ());
  4089. }
  4090. BOOST_UBLAS_INLINE
  4091. #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
  4092. typename self_type::
  4093. #endif
  4094. const_reverse_iterator2 rbegin () const {
  4095. return const_reverse_iterator2 (end ());
  4096. }
  4097. BOOST_UBLAS_INLINE
  4098. #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
  4099. typename self_type::
  4100. #endif
  4101. const_reverse_iterator2 rend () const {
  4102. return const_reverse_iterator2 (begin ());
  4103. }
  4104. #endif
  4105. // Indices
  4106. BOOST_UBLAS_INLINE
  4107. size_type index1 () const {
  4108. return it1_.index1 ();
  4109. }
  4110. BOOST_UBLAS_INLINE
  4111. size_type index2 () const {
  4112. return it2_.index2 ();
  4113. }
  4114. // Assignment
  4115. BOOST_UBLAS_INLINE
  4116. const_iterator1 &operator = (const const_iterator1 &it) {
  4117. container_const_reference<self_type>::assign (&it ());
  4118. it1_ = it.it1_;
  4119. it2_ = it.it2_;
  4120. #ifdef BOOST_UBLAS_USE_INVARIANT_HOISTING
  4121. it2_begin_ = it.it2_begin_;
  4122. it2_end_ = it.it2_end_;
  4123. #endif
  4124. return *this;
  4125. }
  4126. // Comparison
  4127. BOOST_UBLAS_INLINE
  4128. bool operator == (const const_iterator1 &it) const {
  4129. BOOST_UBLAS_CHECK ((*this) ().same_closure (it ()), external_logic ());
  4130. BOOST_UBLAS_CHECK (it2_ == it.it2_, external_logic ());
  4131. return it1_ == it.it1_;
  4132. }
  4133. BOOST_UBLAS_INLINE
  4134. bool operator < (const const_iterator1 &it) const {
  4135. BOOST_UBLAS_CHECK ((*this) ().same_closure (it ()), external_logic ());
  4136. BOOST_UBLAS_CHECK (it2_ == it.it2_, external_logic ());
  4137. return it1_ < it.it1_;
  4138. }
  4139. private:
  4140. const_iterator11_type it1_;
  4141. // Mutable due to assignment
  4142. /* const */ const_iterator22_type it2_;
  4143. #ifdef BOOST_UBLAS_USE_INVARIANT_HOISTING
  4144. /* const */ const_iterator21_type it2_begin_;
  4145. /* const */ const_iterator21_type it2_end_;
  4146. #endif
  4147. };
  4148. #endif
  4149. BOOST_UBLAS_INLINE
  4150. const_iterator1 begin1 () const {
  4151. return find1 (0, 0, 0);
  4152. }
  4153. BOOST_UBLAS_INLINE
  4154. const_iterator1 end1 () const {
  4155. return find1 (0, size1 (), 0);
  4156. }
  4157. #ifndef BOOST_UBLAS_USE_INDEXED_ITERATOR
  4158. class const_iterator2:
  4159. public container_const_reference<matrix_matrix_binary>,
  4160. public iterator_base_traits<typename iterator_restrict_traits<typename E1::const_iterator1::iterator_category,
  4161. typename E2::const_iterator2::iterator_category>::iterator_category>::template
  4162. iterator_base<const_iterator2, value_type>::type {
  4163. public:
  4164. typedef typename iterator_restrict_traits<typename E1::const_iterator1::iterator_category,
  4165. typename E2::const_iterator2::iterator_category>::iterator_category iterator_category;
  4166. typedef typename matrix_matrix_binary::difference_type difference_type;
  4167. typedef typename matrix_matrix_binary::value_type value_type;
  4168. typedef typename matrix_matrix_binary::const_reference reference;
  4169. typedef typename matrix_matrix_binary::const_pointer pointer;
  4170. typedef const_iterator1 dual_iterator_type;
  4171. typedef const_reverse_iterator1 dual_reverse_iterator_type;
  4172. // Construction and destruction
  4173. #ifdef BOOST_UBLAS_USE_INVARIANT_HOISTING
  4174. BOOST_UBLAS_INLINE
  4175. const_iterator2 ():
  4176. container_const_reference<self_type> (), it1_ (), it2_ (), it1_begin_ (), it1_end_ () {}
  4177. BOOST_UBLAS_INLINE
  4178. const_iterator2 (const self_type &mmb, const const_iterator11_type &it1, const const_iterator22_type &it2):
  4179. container_const_reference<self_type> (mmb), it1_ (it1), it2_ (it2), it1_begin_ (it1.begin ()), it1_end_ (it1.end ()) {}
  4180. #else
  4181. BOOST_UBLAS_INLINE
  4182. const_iterator2 ():
  4183. container_const_reference<self_type> (), it1_ (), it2_ () {}
  4184. BOOST_UBLAS_INLINE
  4185. const_iterator2 (const self_type &mmb, const const_iterator11_type &it1, const const_iterator22_type &it2):
  4186. container_const_reference<self_type> (mmb), it1_ (it1), it2_ (it2) {}
  4187. #endif
  4188. private:
  4189. // Random access specialization
  4190. BOOST_UBLAS_INLINE
  4191. value_type dereference (dense_random_access_iterator_tag) const {
  4192. const self_type &mmb = (*this) ();
  4193. #ifdef BOOST_UBLAS_USE_INDEXING
  4194. return mmb (index1 (), index2 ());
  4195. #elif BOOST_UBLAS_USE_ITERATING
  4196. difference_type size = BOOST_UBLAS_SAME (mmb.expression1 ().size2 (), mmb.expression2 ().size1 ());
  4197. #ifdef BOOST_UBLAS_USE_INVARIANT_HOISTING
  4198. return functor_type::apply (size, it1_begin_, it2_.begin ());
  4199. #else
  4200. return functor_type::apply (size, it1_.begin (), it2_.begin ());
  4201. #endif
  4202. #else
  4203. difference_type size = BOOST_UBLAS_SAME (mmb.expression1 ().size2 (), mmb.expression2 ().size1 ());
  4204. if (size >= BOOST_UBLAS_ITERATOR_THRESHOLD)
  4205. #ifdef BOOST_UBLAS_USE_INVARIANT_HOISTING
  4206. return functor_type::apply (size, it1_begin_, it2_.begin ());
  4207. #else
  4208. return functor_type::apply (size, it1_.begin (), it2_.begin ());
  4209. #endif
  4210. else
  4211. return mmb (index1 (), index2 ());
  4212. #endif
  4213. }
  4214. // Packed bidirectional specialization
  4215. BOOST_UBLAS_INLINE
  4216. value_type dereference (packed_random_access_iterator_tag) const {
  4217. #ifdef BOOST_UBLAS_USE_INVARIANT_HOISTING
  4218. return functor_type::apply (it1_begin_, it1_end_,
  4219. it2_.begin (), it2_.end (), packed_random_access_iterator_tag ());
  4220. #else
  4221. #ifndef BOOST_UBLAS_NO_NESTED_CLASS_RELATION
  4222. return functor_type::apply (it1_.begin (), it1_.end (),
  4223. it2_.begin (), it2_.end (), packed_random_access_iterator_tag ());
  4224. #else
  4225. return functor_type::apply (boost::numeric::ublas::begin (it1_, iterator1_tag ()),
  4226. boost::numeric::ublas::end (it1_, iterator1_tag ()),
  4227. boost::numeric::ublas::begin (it2_, iterator2_tag ()),
  4228. boost::numeric::ublas::end (it2_, iterator2_tag ()), packed_random_access_iterator_tag ());
  4229. #endif
  4230. #endif
  4231. }
  4232. // Sparse bidirectional specialization
  4233. BOOST_UBLAS_INLINE
  4234. value_type dereference (sparse_bidirectional_iterator_tag) const {
  4235. #ifdef BOOST_UBLAS_USE_INVARIANT_HOISTING
  4236. return functor_type::apply (it1_begin_, it1_end_,
  4237. it2_.begin (), it2_.end (), sparse_bidirectional_iterator_tag ());
  4238. #else
  4239. #ifndef BOOST_UBLAS_NO_NESTED_CLASS_RELATION
  4240. return functor_type::apply (it1_.begin (), it1_.end (),
  4241. it2_.begin (), it2_.end (), sparse_bidirectional_iterator_tag ());
  4242. #else
  4243. return functor_type::apply (boost::numeric::ublas::begin (it1_, iterator1_tag ()),
  4244. boost::numeric::ublas::end (it1_, iterator1_tag ()),
  4245. boost::numeric::ublas::begin (it2_, iterator2_tag ()),
  4246. boost::numeric::ublas::end (it2_, iterator2_tag ()), sparse_bidirectional_iterator_tag ());
  4247. #endif
  4248. #endif
  4249. }
  4250. public:
  4251. // Arithmetic
  4252. BOOST_UBLAS_INLINE
  4253. const_iterator2 &operator ++ () {
  4254. ++ it2_;
  4255. return *this;
  4256. }
  4257. BOOST_UBLAS_INLINE
  4258. const_iterator2 &operator -- () {
  4259. -- it2_;
  4260. return *this;
  4261. }
  4262. BOOST_UBLAS_INLINE
  4263. const_iterator2 &operator += (difference_type n) {
  4264. it2_ += n;
  4265. return *this;
  4266. }
  4267. BOOST_UBLAS_INLINE
  4268. const_iterator2 &operator -= (difference_type n) {
  4269. it2_ -= n;
  4270. return *this;
  4271. }
  4272. BOOST_UBLAS_INLINE
  4273. difference_type operator - (const const_iterator2 &it) const {
  4274. BOOST_UBLAS_CHECK ((*this) ().same_closure (it ()), external_logic ());
  4275. BOOST_UBLAS_CHECK (it1_ == it.it1_, external_logic ());
  4276. return it2_ - it.it2_;
  4277. }
  4278. // Dereference
  4279. BOOST_UBLAS_INLINE
  4280. const_reference operator * () const {
  4281. return dereference (iterator_category ());
  4282. }
  4283. BOOST_UBLAS_INLINE
  4284. const_reference operator [] (difference_type n) const {
  4285. return *(*this + n);
  4286. }
  4287. #ifndef BOOST_UBLAS_NO_NESTED_CLASS_RELATION
  4288. BOOST_UBLAS_INLINE
  4289. #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
  4290. typename self_type::
  4291. #endif
  4292. const_iterator1 begin () const {
  4293. return (*this) ().find1 (1, 0, index2 ());
  4294. }
  4295. BOOST_UBLAS_INLINE
  4296. #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
  4297. typename self_type::
  4298. #endif
  4299. const_iterator1 end () const {
  4300. return (*this) ().find1 (1, (*this) ().size1 (), index2 ());
  4301. }
  4302. BOOST_UBLAS_INLINE
  4303. #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
  4304. typename self_type::
  4305. #endif
  4306. const_reverse_iterator1 rbegin () const {
  4307. return const_reverse_iterator1 (end ());
  4308. }
  4309. BOOST_UBLAS_INLINE
  4310. #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
  4311. typename self_type::
  4312. #endif
  4313. const_reverse_iterator1 rend () const {
  4314. return const_reverse_iterator1 (begin ());
  4315. }
  4316. #endif
  4317. // Indices
  4318. BOOST_UBLAS_INLINE
  4319. size_type index1 () const {
  4320. return it1_.index1 ();
  4321. }
  4322. BOOST_UBLAS_INLINE
  4323. size_type index2 () const {
  4324. return it2_.index2 ();
  4325. }
  4326. // Assignment
  4327. BOOST_UBLAS_INLINE
  4328. const_iterator2 &operator = (const const_iterator2 &it) {
  4329. container_const_reference<self_type>::assign (&it ());
  4330. it1_ = it.it1_;
  4331. it2_ = it.it2_;
  4332. #ifdef BOOST_UBLAS_USE_INVARIANT_HOISTING
  4333. it1_begin_ = it.it1_begin_;
  4334. it1_end_ = it.it1_end_;
  4335. #endif
  4336. return *this;
  4337. }
  4338. // Comparison
  4339. BOOST_UBLAS_INLINE
  4340. bool operator == (const const_iterator2 &it) const {
  4341. BOOST_UBLAS_CHECK ((*this) ().same_closure (it ()), external_logic ());
  4342. BOOST_UBLAS_CHECK (it1_ == it.it1_, external_logic ());
  4343. return it2_ == it.it2_;
  4344. }
  4345. BOOST_UBLAS_INLINE
  4346. bool operator < (const const_iterator2 &it) const {
  4347. BOOST_UBLAS_CHECK ((*this) ().same_closure (it ()), external_logic ());
  4348. BOOST_UBLAS_CHECK (it1_ == it.it1_, external_logic ());
  4349. return it2_ < it.it2_;
  4350. }
  4351. private:
  4352. // Mutable due to assignment
  4353. /* const */ const_iterator11_type it1_;
  4354. const_iterator22_type it2_;
  4355. #ifdef BOOST_UBLAS_USE_INVARIANT_HOISTING
  4356. /* const */ const_iterator12_type it1_begin_;
  4357. /* const */ const_iterator12_type it1_end_;
  4358. #endif
  4359. };
  4360. #endif
  4361. BOOST_UBLAS_INLINE
  4362. const_iterator2 begin2 () const {
  4363. return find2 (0, 0, 0);
  4364. }
  4365. BOOST_UBLAS_INLINE
  4366. const_iterator2 end2 () const {
  4367. return find2 (0, 0, size2 ());
  4368. }
  4369. // Reverse iterators
  4370. BOOST_UBLAS_INLINE
  4371. const_reverse_iterator1 rbegin1 () const {
  4372. return const_reverse_iterator1 (end1 ());
  4373. }
  4374. BOOST_UBLAS_INLINE
  4375. const_reverse_iterator1 rend1 () const {
  4376. return const_reverse_iterator1 (begin1 ());
  4377. }
  4378. BOOST_UBLAS_INLINE
  4379. const_reverse_iterator2 rbegin2 () const {
  4380. return const_reverse_iterator2 (end2 ());
  4381. }
  4382. BOOST_UBLAS_INLINE
  4383. const_reverse_iterator2 rend2 () const {
  4384. return const_reverse_iterator2 (begin2 ());
  4385. }
  4386. private:
  4387. expression1_closure_type e1_;
  4388. expression2_closure_type e2_;
  4389. };
  4390. template<class T1, class E1, class T2, class E2>
  4391. struct matrix_matrix_binary_traits {
  4392. typedef unknown_storage_tag storage_category;
  4393. typedef unknown_orientation_tag orientation_category;
  4394. typedef typename promote_traits<T1, T2>::promote_type promote_type;
  4395. typedef matrix_matrix_binary<E1, E2, matrix_matrix_prod<E1, E2, promote_type> > expression_type;
  4396. #ifndef BOOST_UBLAS_SIMPLE_ET_DEBUG
  4397. typedef expression_type result_type;
  4398. #else
  4399. typedef typename E1::matrix_temporary_type result_type;
  4400. #endif
  4401. };
  4402. template<class E1, class E2>
  4403. BOOST_UBLAS_INLINE
  4404. typename matrix_matrix_binary_traits<typename E1::value_type, E1,
  4405. typename E2::value_type, E2>::result_type
  4406. prod (const matrix_expression<E1> &e1,
  4407. const matrix_expression<E2> &e2,
  4408. unknown_storage_tag,
  4409. unknown_orientation_tag) {
  4410. typedef typename matrix_matrix_binary_traits<typename E1::value_type, E1,
  4411. typename E2::value_type, E2>::expression_type expression_type;
  4412. return expression_type (e1 (), e2 ());
  4413. }
  4414. // Dispatcher
  4415. template<class E1, class E2>
  4416. BOOST_UBLAS_INLINE
  4417. typename matrix_matrix_binary_traits<typename E1::value_type, E1,
  4418. typename E2::value_type, E2>::result_type
  4419. prod (const matrix_expression<E1> &e1,
  4420. const matrix_expression<E2> &e2) {
  4421. BOOST_STATIC_ASSERT (E1::complexity == 0 && E2::complexity == 0);
  4422. typedef typename matrix_matrix_binary_traits<typename E1::value_type, E1,
  4423. typename E2::value_type, E2>::storage_category storage_category;
  4424. typedef typename matrix_matrix_binary_traits<typename E1::value_type, E1,
  4425. typename E2::value_type, E2>::orientation_category orientation_category;
  4426. return prod (e1, e2, storage_category (), orientation_category ());
  4427. }
  4428. template<class E1, class E2>
  4429. BOOST_UBLAS_INLINE
  4430. typename matrix_matrix_binary_traits<typename type_traits<typename E1::value_type>::precision_type, E1,
  4431. typename type_traits<typename E2::value_type>::precision_type, E2>::result_type
  4432. prec_prod (const matrix_expression<E1> &e1,
  4433. const matrix_expression<E2> &e2,
  4434. unknown_storage_tag,
  4435. unknown_orientation_tag) {
  4436. typedef typename matrix_matrix_binary_traits<typename type_traits<typename E1::value_type>::precision_type, E1,
  4437. typename type_traits<typename E2::value_type>::precision_type, E2>::expression_type expression_type;
  4438. return expression_type (e1 (), e2 ());
  4439. }
  4440. // Dispatcher
  4441. template<class E1, class E2>
  4442. BOOST_UBLAS_INLINE
  4443. typename matrix_matrix_binary_traits<typename type_traits<typename E1::value_type>::precision_type, E1,
  4444. typename type_traits<typename E2::value_type>::precision_type, E2>::result_type
  4445. prec_prod (const matrix_expression<E1> &e1,
  4446. const matrix_expression<E2> &e2) {
  4447. BOOST_STATIC_ASSERT (E1::complexity == 0 && E2::complexity == 0);
  4448. typedef typename matrix_matrix_binary_traits<typename type_traits<typename E1::value_type>::precision_type, E1,
  4449. typename type_traits<typename E2::value_type>::precision_type, E2>::storage_category storage_category;
  4450. typedef typename matrix_matrix_binary_traits<typename type_traits<typename E1::value_type>::precision_type, E1,
  4451. typename type_traits<typename E2::value_type>::precision_type, E2>::orientation_category orientation_category;
  4452. return prec_prod (e1, e2, storage_category (), orientation_category ());
  4453. }
  4454. template<class M, class E1, class E2>
  4455. BOOST_UBLAS_INLINE
  4456. M &
  4457. prod (const matrix_expression<E1> &e1,
  4458. const matrix_expression<E2> &e2,
  4459. M &m) {
  4460. return m.assign (prod (e1, e2));
  4461. }
  4462. template<class M, class E1, class E2>
  4463. BOOST_UBLAS_INLINE
  4464. M &
  4465. prec_prod (const matrix_expression<E1> &e1,
  4466. const matrix_expression<E2> &e2,
  4467. M &m) {
  4468. return m.assign (prec_prod (e1, e2));
  4469. }
  4470. template<class M, class E1, class E2>
  4471. BOOST_UBLAS_INLINE
  4472. M
  4473. prod (const matrix_expression<E1> &e1,
  4474. const matrix_expression<E2> &e2) {
  4475. return M (prod (e1, e2));
  4476. }
  4477. template<class M, class E1, class E2>
  4478. BOOST_UBLAS_INLINE
  4479. M
  4480. prec_prod (const matrix_expression<E1> &e1,
  4481. const matrix_expression<E2> &e2) {
  4482. return M (prec_prod (e1, e2));
  4483. }
  4484. template<class E, class F>
  4485. class matrix_scalar_unary:
  4486. public scalar_expression<matrix_scalar_unary<E, F> > {
  4487. public:
  4488. typedef E expression_type;
  4489. typedef F functor_type;
  4490. typedef typename F::result_type value_type;
  4491. typedef typename E::const_closure_type expression_closure_type;
  4492. // Construction and destruction
  4493. BOOST_UBLAS_INLINE
  4494. explicit matrix_scalar_unary (const expression_type &e):
  4495. e_ (e) {}
  4496. private:
  4497. // Expression accessors
  4498. BOOST_UBLAS_INLINE
  4499. const expression_closure_type &expression () const {
  4500. return e_;
  4501. }
  4502. public:
  4503. BOOST_UBLAS_INLINE
  4504. operator value_type () const {
  4505. return functor_type::apply (e_);
  4506. }
  4507. private:
  4508. expression_closure_type e_;
  4509. };
  4510. template<class E, class F>
  4511. struct matrix_scalar_unary_traits {
  4512. typedef matrix_scalar_unary<E, F> expression_type;
  4513. #ifndef BOOST_UBLAS_SIMPLE_ET_DEBUG
  4514. typedef expression_type result_type;
  4515. #else
  4516. typedef typename F::result_type result_type;
  4517. #endif
  4518. };
  4519. template<class E>
  4520. BOOST_UBLAS_INLINE
  4521. typename matrix_scalar_unary_traits<E, matrix_norm_1<E> >::result_type
  4522. norm_1 (const matrix_expression<E> &e) {
  4523. typedef typename matrix_scalar_unary_traits<E, matrix_norm_1<E> >::expression_type expression_type;
  4524. return expression_type (e ());
  4525. }
  4526. template<class E>
  4527. BOOST_UBLAS_INLINE
  4528. typename matrix_scalar_unary_traits<E, matrix_norm_frobenius<E> >::result_type
  4529. norm_frobenius (const matrix_expression<E> &e) {
  4530. typedef typename matrix_scalar_unary_traits<E, matrix_norm_frobenius<E> >::expression_type expression_type;
  4531. return expression_type (e ());
  4532. }
  4533. template<class E>
  4534. BOOST_UBLAS_INLINE
  4535. typename matrix_scalar_unary_traits<E, matrix_norm_inf<E> >::result_type
  4536. norm_inf (const matrix_expression<E> &e) {
  4537. typedef typename matrix_scalar_unary_traits<E, matrix_norm_inf<E> >::expression_type expression_type;
  4538. return expression_type (e ());
  4539. }
  4540. }}}
  4541. #endif