matrix_expression.hpp 165 KB

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