1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931 |
- // Copyright 2008-2016 Conrad Sanderson (http://conradsanderson.id.au)
- // Copyright 2008-2016 National ICT Australia (NICTA)
- //
- // Licensed under the Apache License, Version 2.0 (the "License");
- // you may not use this file except in compliance with the License.
- // You may obtain a copy of the License at
- // http://www.apache.org/licenses/LICENSE-2.0
- //
- // Unless required by applicable law or agreed to in writing, software
- // distributed under the License is distributed on an "AS IS" BASIS,
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- // See the License for the specific language governing permissions and
- // limitations under the License.
- // ------------------------------------------------------------------------
- //! \addtogroup Mat
- //! @{
- template<typename eT>
- inline
- Mat<eT>::~Mat()
- {
- arma_extra_debug_sigprint_this(this);
-
- if( (mem_state == 0) && (n_elem > arma_config::mat_prealloc) )
- {
- arma_extra_debug_print("Mat::destructor: releasing memory");
- memory::release( access::rw(mem) );
- }
-
- // try to expose buggy user code that accesses deleted objects
- if(arma_config::debug) { access::rw(mem) = 0; }
-
- arma_type_check(( is_supported_elem_type<eT>::value == false ));
- }
- template<typename eT>
- inline
- Mat<eT>::Mat()
- : n_rows(0)
- , n_cols(0)
- , n_elem(0)
- , vec_state(0)
- , mem_state(0)
- , mem()
- {
- arma_extra_debug_sigprint_this(this);
- }
- //! construct the matrix to have user specified dimensions
- template<typename eT>
- inline
- Mat<eT>::Mat(const uword in_n_rows, const uword in_n_cols)
- : n_rows(in_n_rows)
- , n_cols(in_n_cols)
- , n_elem(in_n_rows*in_n_cols)
- , vec_state(0)
- , mem_state(0)
- , mem()
- {
- arma_extra_debug_sigprint_this(this);
-
- init_cold();
- }
- template<typename eT>
- inline
- Mat<eT>::Mat(const SizeMat& s)
- : n_rows(s.n_rows)
- , n_cols(s.n_cols)
- , n_elem(s.n_rows*s.n_cols)
- , vec_state(0)
- , mem_state(0)
- , mem()
- {
- arma_extra_debug_sigprint_this(this);
-
- init_cold();
- }
- //! construct the matrix to have user specified dimensions and fill with specified pattern
- template<typename eT>
- template<typename fill_type>
- inline
- Mat<eT>::Mat(const uword in_n_rows, const uword in_n_cols, const fill::fill_class<fill_type>& f)
- : n_rows(in_n_rows)
- , n_cols(in_n_cols)
- , n_elem(in_n_rows*in_n_cols)
- , vec_state(0)
- , mem_state(0)
- , mem()
- {
- arma_extra_debug_sigprint_this(this);
-
- init_cold();
-
- (*this).fill(f);
- }
- template<typename eT>
- template<typename fill_type>
- inline
- Mat<eT>::Mat(const SizeMat& s, const fill::fill_class<fill_type>& f)
- : n_rows(s.n_rows)
- , n_cols(s.n_cols)
- , n_elem(s.n_rows*s.n_cols)
- , vec_state(0)
- , mem_state(0)
- , mem()
- {
- arma_extra_debug_sigprint_this(this);
-
- init_cold();
-
- (*this).fill(f);
- }
- //! constructor used by Row and Col classes
- template<typename eT>
- inline
- Mat<eT>::Mat(const arma_vec_indicator&, const uhword in_vec_state)
- : n_rows( (in_vec_state == 2) ? 1 : 0 )
- , n_cols( (in_vec_state == 1) ? 1 : 0 )
- , n_elem(0)
- , vec_state(in_vec_state)
- , mem_state(0)
- , mem()
- {
- arma_extra_debug_sigprint_this(this);
- }
- //! constructor used by Row and Col classes
- template<typename eT>
- inline
- Mat<eT>::Mat(const arma_vec_indicator&, const uword in_n_rows, const uword in_n_cols, const uhword in_vec_state)
- : n_rows(in_n_rows)
- , n_cols(in_n_cols)
- , n_elem(in_n_rows*in_n_cols)
- , vec_state(in_vec_state)
- , mem_state(0)
- , mem()
- {
- arma_extra_debug_sigprint_this(this);
-
- init_cold();
- }
- template<typename eT>
- inline
- Mat<eT>::Mat(const arma_fixed_indicator&, const uword in_n_rows, const uword in_n_cols, const uhword in_vec_state, const eT* in_mem)
- : n_rows (in_n_rows)
- , n_cols (in_n_cols)
- , n_elem (in_n_rows*in_n_cols)
- , vec_state (in_vec_state)
- , mem_state (3)
- , mem (in_mem)
- {
- arma_extra_debug_sigprint_this(this);
- }
- template<typename eT>
- inline
- void
- Mat<eT>::init_cold()
- {
- arma_extra_debug_sigprint( arma_str::format("n_rows = %d, n_cols = %d") % n_rows % n_cols );
-
- // ensure that n_elem can hold the result of (n_rows * n_cols)
-
- #if defined(ARMA_64BIT_WORD)
- const char* error_message = "Mat::init(): requested size is too large";
- #else
- const char* error_message = "Mat::init(): requested size is too large; suggest to compile in C++11 mode and/or enable ARMA_64BIT_WORD";
- #endif
-
- arma_debug_check
- (
- (
- ( (n_rows > ARMA_MAX_UHWORD) || (n_cols > ARMA_MAX_UHWORD) )
- ? ( (double(n_rows) * double(n_cols)) > double(ARMA_MAX_UWORD) )
- : false
- ),
- error_message
- );
-
- if(n_elem <= arma_config::mat_prealloc)
- {
- if(n_elem == 0)
- {
- access::rw(mem) = NULL;
- }
- else
- {
- arma_extra_debug_print("Mat::init(): using local memory");
- access::rw(mem) = mem_local;
- }
- }
- else
- {
- arma_extra_debug_print("Mat::init(): acquiring memory");
- access::rw(mem) = memory::acquire<eT>(n_elem);
- }
- }
- template<typename eT>
- inline
- void
- Mat<eT>::init_warm(uword in_n_rows, uword in_n_cols)
- {
- arma_extra_debug_sigprint( arma_str::format("in_n_rows = %d, in_n_cols = %d") % in_n_rows % in_n_cols );
-
- if( (n_rows == in_n_rows) && (n_cols == in_n_cols) ) { return; }
-
- bool err_state = false;
- char* err_msg = 0;
-
- const uhword t_vec_state = vec_state;
- const uhword t_mem_state = mem_state;
-
- arma_debug_set_error( err_state, err_msg, (t_mem_state == 3), "Mat::init(): size is fixed and hence cannot be changed" );
-
- if(t_vec_state > 0)
- {
- if( (in_n_rows == 0) && (in_n_cols == 0) )
- {
- if(t_vec_state == 1) { in_n_cols = 1; }
- if(t_vec_state == 2) { in_n_rows = 1; }
- }
- else
- {
- if(t_vec_state == 1) { arma_debug_set_error( err_state, err_msg, (in_n_cols != 1), "Mat::init(): requested size is not compatible with column vector layout" ); }
- if(t_vec_state == 2) { arma_debug_set_error( err_state, err_msg, (in_n_rows != 1), "Mat::init(): requested size is not compatible with row vector layout" ); }
- }
- }
-
- // ensure that n_elem can hold the result of (n_rows * n_cols)
-
- #if defined(ARMA_64BIT_WORD)
- const char* error_message = "Mat::init(): requested size is too large";
- #else
- const char* error_message = "Mat::init(): requested size is too large; suggest to compile in C++11 mode and/or enable ARMA_64BIT_WORD";
- #endif
-
- arma_debug_set_error
- (
- err_state,
- err_msg,
- (
- ( (in_n_rows > ARMA_MAX_UHWORD) || (in_n_cols > ARMA_MAX_UHWORD) )
- ? ( (double(in_n_rows) * double(in_n_cols)) > double(ARMA_MAX_UWORD) )
- : false
- ),
- error_message
- );
-
- arma_debug_check(err_state, err_msg);
-
- const uword old_n_elem = n_elem;
- const uword new_n_elem = in_n_rows * in_n_cols;
-
- if(old_n_elem == new_n_elem)
- {
- arma_extra_debug_print("Mat::init(): reusing memory");
- access::rw(n_rows) = in_n_rows;
- access::rw(n_cols) = in_n_cols;
- }
- else // condition: old_n_elem != new_n_elem
- {
- arma_debug_check( (t_mem_state == 2), "Mat::init(): mismatch between size of auxiliary memory and requested size" );
-
- if(new_n_elem < old_n_elem) // reuse existing memory if possible
- {
- if( (t_mem_state == 0) && (new_n_elem <= arma_config::mat_prealloc) )
- {
- if(old_n_elem > arma_config::mat_prealloc)
- {
- arma_extra_debug_print("Mat::init(): releasing memory");
- memory::release( access::rw(mem) );
- }
-
- if(new_n_elem == 0)
- {
- access::rw(mem) = NULL;
- }
- else
- {
- arma_extra_debug_print("Mat::init(): using local memory");
- access::rw(mem) = mem_local;
- }
- }
- else
- {
- arma_extra_debug_print("Mat::init(): reusing memory");
- }
- }
- else // condition: new_n_elem > old_n_elem
- {
- if( (t_mem_state == 0) && (old_n_elem > arma_config::mat_prealloc) )
- {
- arma_extra_debug_print("Mat::init(): releasing memory");
- memory::release( access::rw(mem) );
- }
-
- if(new_n_elem <= arma_config::mat_prealloc)
- {
- arma_extra_debug_print("Mat::init(): using local memory");
- access::rw(mem) = mem_local;
- }
- else
- {
- arma_extra_debug_print("Mat::init(): acquiring memory");
- access::rw(mem) = memory::acquire<eT>(new_n_elem);
- }
-
- access::rw(mem_state) = 0;
- }
-
- access::rw(n_rows) = in_n_rows;
- access::rw(n_cols) = in_n_cols;
- access::rw(n_elem) = new_n_elem;
- }
- }
- //! create the matrix from a textual description
- template<typename eT>
- inline
- arma_cold
- Mat<eT>::Mat(const char* text)
- : n_rows(0)
- , n_cols(0)
- , n_elem(0)
- , vec_state(0)
- , mem_state(0)
- , mem()
- {
- arma_extra_debug_sigprint_this(this);
-
- init( std::string(text) );
- }
-
-
-
- //! create the matrix from a textual description
- template<typename eT>
- inline
- arma_cold
- Mat<eT>&
- Mat<eT>::operator=(const char* text)
- {
- arma_extra_debug_sigprint();
-
- init( std::string(text) );
- return *this;
- }
-
-
- //! create the matrix from a textual description
- template<typename eT>
- inline
- arma_cold
- Mat<eT>::Mat(const std::string& text)
- : n_rows(0)
- , n_cols(0)
- , n_elem(0)
- , vec_state(0)
- , mem_state(0)
- , mem()
- {
- arma_extra_debug_sigprint_this(this);
-
- init(text);
- }
-
-
-
- //! create the matrix from a textual description
- template<typename eT>
- inline
- arma_cold
- Mat<eT>&
- Mat<eT>::operator=(const std::string& text)
- {
- arma_extra_debug_sigprint();
-
- init(text);
- return *this;
- }
- //! internal function to create the matrix from a textual description
- template<typename eT>
- inline
- arma_cold
- void
- Mat<eT>::init(const std::string& text_orig)
- {
- arma_extra_debug_sigprint();
-
- const bool replace_commas = (is_cx<eT>::yes) ? false : ( text_orig.find(',') != std::string::npos );
-
- std::string text_mod;
-
- if(replace_commas) { text_mod = text_orig; std::replace(text_mod.begin(), text_mod.end(), ',', ' '); }
-
- const std::string& text = (replace_commas) ? text_mod : text_orig;
-
- //
- // work out the size
-
- uword t_n_rows = 0;
- uword t_n_cols = 0;
-
- bool has_semicolon = false;
- bool has_token = false;
-
- std::string token;
-
- std::string::size_type line_start = 0;
- std::string::size_type line_end = 0;
- std::string::size_type line_len = 0;
-
- std::stringstream line_stream;
-
- while( line_start < text.length() )
- {
- line_end = text.find(';', line_start);
-
- if(line_end == std::string::npos)
- {
- has_semicolon = false;
- line_end = text.length()-1;
- line_len = line_end - line_start + 1;
- }
- else
- {
- has_semicolon = true;
- line_len = line_end - line_start; // omit the ';' character
- }
-
- line_stream.clear();
- line_stream.str( text.substr(line_start,line_len) );
-
- has_token = false;
-
- uword line_n_cols = 0;
-
- while(line_stream >> token) { has_token = true; ++line_n_cols; }
-
- if(t_n_rows == 0)
- {
- t_n_cols = line_n_cols;
- }
- else
- {
- if(has_semicolon || has_token) { arma_check( (line_n_cols != t_n_cols), "Mat::init(): inconsistent number of columns in given string"); }
- }
-
- ++t_n_rows;
-
- line_start = line_end+1;
- }
-
- // if the last line was empty, ignore it
- if( (has_semicolon == false) && (has_token == false) && (t_n_rows >= 1) ) { --t_n_rows; }
-
- Mat<eT>& x = (*this);
- x.set_size(t_n_rows, t_n_cols);
-
- if(x.is_empty()) { return; }
-
- line_start = 0;
- line_end = 0;
- line_len = 0;
-
- uword urow = 0;
-
- while( line_start < text.length() )
- {
- line_end = text.find(';', line_start);
-
- if(line_end == std::string::npos)
- {
- line_end = text.length()-1;
- line_len = line_end - line_start + 1;
- }
- else
- {
- line_len = line_end - line_start; // omit the ';' character
- }
-
- line_stream.clear();
- line_stream.str( text.substr(line_start,line_len) );
-
- uword ucol = 0;
- while(line_stream >> token)
- {
- diskio::convert_token( x.at(urow,ucol), token );
- ++ucol;
- }
-
- ++urow;
- line_start = line_end+1;
- }
- }
- //! create the matrix from std::vector
- template<typename eT>
- inline
- Mat<eT>::Mat(const std::vector<eT>& x)
- : n_rows(uword(x.size()))
- , n_cols(1)
- , n_elem(uword(x.size()))
- , vec_state(0)
- , mem_state(0)
- , mem()
- {
- arma_extra_debug_sigprint_this(this);
-
- init_cold();
-
- if(n_elem > 0)
- {
- arrayops::copy( memptr(), &(x[0]), n_elem );
- }
- }
-
-
-
- //! create the matrix from std::vector
- template<typename eT>
- inline
- Mat<eT>&
- Mat<eT>::operator=(const std::vector<eT>& x)
- {
- arma_extra_debug_sigprint();
-
- init_warm(uword(x.size()), 1);
-
- if(x.size() > 0)
- {
- arrayops::copy( memptr(), &(x[0]), uword(x.size()) );
- }
-
- return *this;
- }
- #if defined(ARMA_USE_CXX11)
-
- template<typename eT>
- inline
- Mat<eT>::Mat(const std::initializer_list<eT>& list)
- : n_rows(0)
- , n_cols(0)
- , n_elem(0)
- , vec_state(0)
- , mem_state(0)
- , mem()
- {
- arma_extra_debug_sigprint_this(this);
-
- init(list);
- }
-
-
-
- template<typename eT>
- inline
- Mat<eT>&
- Mat<eT>::operator=(const std::initializer_list<eT>& list)
- {
- arma_extra_debug_sigprint();
-
- init(list);
-
- return *this;
- }
-
-
-
- template<typename eT>
- inline
- Mat<eT>::Mat(const std::initializer_list< std::initializer_list<eT> >& list)
- : n_rows(0)
- , n_cols(0)
- , n_elem(0)
- , vec_state(0)
- , mem_state(0)
- , mem()
- {
- arma_extra_debug_sigprint_this(this);
-
- init(list);
- }
-
-
-
- template<typename eT>
- inline
- Mat<eT>&
- Mat<eT>::operator=(const std::initializer_list< std::initializer_list<eT> >& list)
- {
- arma_extra_debug_sigprint();
-
- init(list);
-
- return *this;
- }
- template<typename eT>
- inline
- Mat<eT>::Mat(Mat<eT>&& X)
- : n_rows (X.n_rows)
- , n_cols (X.n_cols)
- , n_elem (X.n_elem)
- , vec_state(0 )
- , mem_state(0 )
- , mem ( )
- {
- arma_extra_debug_sigprint(arma_str::format("this = %x X = %x") % this % &X);
-
- if( ((X.mem_state == 0) && (X.n_elem > arma_config::mat_prealloc)) || (X.mem_state == 1) || (X.mem_state == 2) )
- {
- access::rw(mem_state) = X.mem_state;
- access::rw(mem) = X.mem;
-
- access::rw(X.n_rows) = 0;
- access::rw(X.n_cols) = 0;
- access::rw(X.n_elem) = 0;
- access::rw(X.mem_state) = 0;
- access::rw(X.mem) = 0;
- }
- else
- {
- init_cold();
-
- arrayops::copy( memptr(), X.mem, X.n_elem );
-
- if( (X.mem_state == 0) && (X.n_elem <= arma_config::mat_prealloc) )
- {
- access::rw(X.n_rows) = 0;
- access::rw(X.n_cols) = 0;
- access::rw(X.n_elem) = 0;
- access::rw(X.mem) = 0;
- }
- }
- }
-
-
-
- template<typename eT>
- inline
- Mat<eT>&
- Mat<eT>::operator=(Mat<eT>&& X)
- {
- arma_extra_debug_sigprint(arma_str::format("this = %x X = %x") % this % &X);
-
- (*this).steal_mem(X);
-
- if( (X.mem_state == 0) && (X.n_elem <= arma_config::mat_prealloc) && (this != &X) )
- {
- access::rw(X.n_rows) = 0;
- access::rw(X.n_cols) = 0;
- access::rw(X.n_elem) = 0;
- access::rw(X.mem) = 0;
- }
-
- return *this;
- }
-
- #endif
-
- //! Set the matrix to be equal to the specified scalar.
- //! NOTE: the size of the matrix will be 1x1
- template<typename eT>
- inline
- Mat<eT>&
- Mat<eT>::operator=(const eT val)
- {
- arma_extra_debug_sigprint();
-
- init_warm(1,1);
- access::rw(mem[0]) = val;
- return *this;
- }
- //! In-place addition of a scalar to all elements of the matrix
- template<typename eT>
- inline
- Mat<eT>&
- Mat<eT>::operator+=(const eT val)
- {
- arma_extra_debug_sigprint();
-
- arrayops::inplace_plus( memptr(), val, n_elem );
-
- return *this;
- }
- //! In-place subtraction of a scalar from all elements of the matrix
- template<typename eT>
- inline
- Mat<eT>&
- Mat<eT>::operator-=(const eT val)
- {
- arma_extra_debug_sigprint();
-
- arrayops::inplace_minus( memptr(), val, n_elem );
-
- return *this;
- }
- //! In-place multiplication of all elements of the matrix with a scalar
- template<typename eT>
- inline
- Mat<eT>&
- Mat<eT>::operator*=(const eT val)
- {
- arma_extra_debug_sigprint();
-
- arrayops::inplace_mul( memptr(), val, n_elem );
-
- return *this;
- }
- //! In-place division of all elements of the matrix with a scalar
- template<typename eT>
- inline
- Mat<eT>&
- Mat<eT>::operator/=(const eT val)
- {
- arma_extra_debug_sigprint();
-
- arrayops::inplace_div( memptr(), val, n_elem );
-
- return *this;
- }
- //! construct a matrix from a given matrix
- template<typename eT>
- inline
- Mat<eT>::Mat(const Mat<eT>& in_mat)
- : n_rows(in_mat.n_rows)
- , n_cols(in_mat.n_cols)
- , n_elem(in_mat.n_elem)
- , vec_state(0)
- , mem_state(0)
- , mem()
- {
- arma_extra_debug_sigprint(arma_str::format("this = %x in_mat = %x") % this % &in_mat);
-
- init_cold();
-
- arrayops::copy( memptr(), in_mat.mem, in_mat.n_elem );
- }
- //! construct a matrix from a given matrix
- template<typename eT>
- inline
- Mat<eT>&
- Mat<eT>::operator=(const Mat<eT>& in_mat)
- {
- arma_extra_debug_sigprint(arma_str::format("this = %x in_mat = %x") % this % &in_mat);
-
- if(this != &in_mat)
- {
- init_warm(in_mat.n_rows, in_mat.n_cols);
-
- arrayops::copy( memptr(), in_mat.mem, in_mat.n_elem );
- }
-
- return *this;
- }
- #if defined(ARMA_USE_CXX11)
-
- template<typename eT>
- inline
- void
- Mat<eT>::init(const std::initializer_list<eT>& list)
- {
- arma_extra_debug_sigprint();
-
- const uword N = uword(list.size());
-
- set_size(1, N);
-
- arrayops::copy( memptr(), list.begin(), N );
- }
-
-
-
- template<typename eT>
- inline
- void
- Mat<eT>::init(const std::initializer_list< std::initializer_list<eT> >& list)
- {
- arma_extra_debug_sigprint();
-
- uword x_n_rows = uword(list.size());
- uword x_n_cols = 0;
-
- bool x_n_cols_found = false;
-
- auto it = list.begin();
- auto it_end = list.end();
-
- for(; it != it_end; ++it)
- {
- if(x_n_cols_found == false)
- {
- x_n_cols = uword((*it).size());
- x_n_cols_found = true;
- }
- else
- {
- arma_check( (uword((*it).size()) != x_n_cols), "Mat::init(): inconsistent number of columns in initialiser list" );
- }
- }
-
- Mat<eT>& t = (*this);
-
- if(t.mem_state == 3)
- {
- arma_debug_check( ((x_n_rows != t.n_rows) || (x_n_cols != t.n_cols)), "Mat::init(): size mismatch between fixed size matrix and initialiser list" );
- }
- else
- {
- t.set_size(x_n_rows, x_n_cols);
- }
-
- uword row_num = 0;
-
- auto row_it = list.begin();
- auto row_it_end = list.end();
-
- for(; row_it != row_it_end; ++row_it)
- {
- uword col_num = 0;
-
- auto col_it = (*row_it).begin();
- auto col_it_end = (*row_it).end();
-
- for(; col_it != col_it_end; ++col_it)
- {
- t.at(row_num, col_num) = (*col_it);
- ++col_num;
- }
-
- ++row_num;
- }
- }
-
- #endif
- //! for constructing a complex matrix out of two non-complex matrices
- template<typename eT>
- template<typename T1, typename T2>
- inline
- void
- Mat<eT>::init
- (
- const Base<typename Mat<eT>::pod_type, T1>& X,
- const Base<typename Mat<eT>::pod_type, T2>& Y
- )
- {
- arma_extra_debug_sigprint();
-
- typedef typename T1::elem_type T;
-
- arma_type_check(( is_cx<eT>::no )); //!< compile-time abort if eT is not std::complex
- arma_type_check(( is_cx< T>::yes )); //!< compile-time abort if T is std::complex
-
- arma_type_check(( is_same_type< std::complex<T>, eT >::no )); //!< compile-time abort if types are not compatible
-
- const Proxy<T1> PX(X.get_ref());
- const Proxy<T2> PY(Y.get_ref());
-
- arma_debug_assert_same_size(PX, PY, "Mat()");
-
- const uword local_n_rows = PX.get_n_rows();
- const uword local_n_cols = PX.get_n_cols();
-
- init_warm(local_n_rows, local_n_cols);
-
- eT* out_mem = (*this).memptr();
-
- const bool use_at = ( Proxy<T1>::use_at || Proxy<T2>::use_at );
-
- if(use_at == false)
- {
- typedef typename Proxy<T1>::ea_type ea_type1;
- typedef typename Proxy<T2>::ea_type ea_type2;
-
- const uword N = n_elem;
-
- ea_type1 A = PX.get_ea();
- ea_type2 B = PY.get_ea();
-
- for(uword ii=0; ii < N; ++ii)
- {
- out_mem[ii] = std::complex<T>(A[ii], B[ii]);
- }
- }
- else
- {
- for(uword ucol=0; ucol < local_n_cols; ++ucol)
- for(uword urow=0; urow < local_n_rows; ++urow)
- {
- *out_mem = std::complex<T>(PX.at(urow,ucol), PY.at(urow,ucol));
- out_mem++;
- }
- }
- }
- //! swap the contents of this matrix, denoted as matrix A, with given matrix B
- template<typename eT>
- inline
- void
- Mat<eT>::swap(Mat<eT>& B)
- {
- Mat<eT>& A = (*this);
-
- arma_extra_debug_sigprint(arma_str::format("A = %x B = %x") % &A % &B);
- bool layout_ok = false;
-
- if(A.vec_state == B.vec_state)
- {
- layout_ok = true;
- }
- else
- {
- const uhword A_vec_state = A.vec_state;
- const uhword B_vec_state = B.vec_state;
-
- const bool A_absorbs_B = (A_vec_state == 0) || ( (A_vec_state == 1) && (B.n_cols == 1) ) || ( (A_vec_state == 2) && (B.n_rows == 1) );
- const bool B_absorbs_A = (B_vec_state == 0) || ( (B_vec_state == 1) && (A.n_cols == 1) ) || ( (B_vec_state == 2) && (A.n_rows == 1) );
-
- layout_ok = A_absorbs_B && B_absorbs_A;
- }
-
- const uhword A_mem_state = A.mem_state;
- const uhword B_mem_state = B.mem_state;
-
- if( (A_mem_state == 0) && (B_mem_state == 0) && layout_ok )
- {
- const uword A_n_elem = A.n_elem;
- const uword B_n_elem = B.n_elem;
-
- const bool A_use_local_mem = (A_n_elem <= arma_config::mat_prealloc);
- const bool B_use_local_mem = (B_n_elem <= arma_config::mat_prealloc);
-
- if( (A_use_local_mem == false) && (B_use_local_mem == false) )
- {
- std::swap( access::rw(A.mem), access::rw(B.mem) );
- }
- else
- if( (A_use_local_mem == true) && (B_use_local_mem == true) )
- {
- eT* A_mem_local = &(A.mem_local[0]);
- eT* B_mem_local = &(B.mem_local[0]);
-
- access::rw(A.mem) = A_mem_local;
- access::rw(B.mem) = B_mem_local;
-
- const uword N = (std::max)(A_n_elem, B_n_elem);
-
- for(uword ii=0; ii < N; ++ii) { std::swap( A_mem_local[ii], B_mem_local[ii] ); }
- }
- else
- if( (A_use_local_mem == true) && (B_use_local_mem == false) )
- {
- eT* A_mem_local = &(A.mem_local[0]);
- eT* B_mem_local = &(B.mem_local[0]);
-
- arrayops::copy(B_mem_local, A_mem_local, A_n_elem);
-
- access::rw(A.mem) = B.mem;
- access::rw(B.mem) = B_mem_local;
- }
- else
- if( (A_use_local_mem == false) && (B_use_local_mem == true) )
- {
- eT* A_mem_local = &(A.mem_local[0]);
- eT* B_mem_local = &(B.mem_local[0]);
-
- arrayops::copy(A_mem_local, B_mem_local, B_n_elem);
-
- access::rw(B.mem) = A.mem;
- access::rw(A.mem) = A_mem_local;
- }
-
- std::swap( access::rw(A.n_rows), access::rw(B.n_rows) );
- std::swap( access::rw(A.n_cols), access::rw(B.n_cols) );
- std::swap( access::rw(A.n_elem), access::rw(B.n_elem) );
- }
- else
- if( (A_mem_state <= 2) && (B_mem_state <= 2) && (A.n_elem == B.n_elem) && layout_ok )
- {
- std::swap( access::rw(A.n_rows), access::rw(B.n_rows) );
- std::swap( access::rw(A.n_cols), access::rw(B.n_cols) );
-
- const uword N = A.n_elem;
-
- eT* A_mem = A.memptr();
- eT* B_mem = B.memptr();
-
- for(uword ii=0; ii < N; ++ii) { std::swap(A_mem[ii], B_mem[ii]); }
- }
- else
- if( (A.n_rows == B.n_rows) && (A.n_cols == B.n_cols) )
- {
- const uword N = A.n_elem;
-
- eT* A_mem = A.memptr();
- eT* B_mem = B.memptr();
-
- for(uword ii=0; ii < N; ++ii) { std::swap(A_mem[ii], B_mem[ii]); }
- }
- else
- {
- // generic swap to handle remaining cases
-
- if(A.n_elem <= B.n_elem)
- {
- Mat<eT> C = A;
-
- A.steal_mem(B);
- B.steal_mem(C);
- }
- else
- {
- Mat<eT> C = B;
-
- B.steal_mem(A);
- A.steal_mem(C);
- }
- }
- }
- //! try to steal the memory from a given matrix;
- //! if memory can't be stolen, copy the given matrix
- template<typename eT>
- inline
- void
- Mat<eT>::steal_mem(Mat<eT>& x)
- {
- arma_extra_debug_sigprint();
-
- if(this == &x) { return; }
-
- const uword x_n_rows = x.n_rows;
- const uword x_n_cols = x.n_cols;
- const uword x_n_elem = x.n_elem;
- const uhword x_vec_state = x.vec_state;
- const uhword x_mem_state = x.mem_state;
-
- const uhword t_vec_state = vec_state;
- const uhword t_mem_state = mem_state;
-
- bool layout_ok = false;
-
- if(t_vec_state == x_vec_state)
- {
- layout_ok = true;
- }
- else
- {
- if( (t_vec_state == 1) && (x_n_cols == 1) ) { layout_ok = true; }
- if( (t_vec_state == 2) && (x_n_rows == 1) ) { layout_ok = true; }
- }
-
-
- if( (t_mem_state <= 1) && ( ((x_mem_state == 0) && (x_n_elem > arma_config::mat_prealloc)) || (x_mem_state == 1) ) && layout_ok )
- {
- reset();
-
- access::rw(n_rows) = x_n_rows;
- access::rw(n_cols) = x_n_cols;
- access::rw(n_elem) = x_n_elem;
- access::rw(mem_state) = x_mem_state;
- access::rw(mem) = x.mem;
-
- access::rw(x.n_rows) = 0;
- access::rw(x.n_cols) = 0;
- access::rw(x.n_elem) = 0;
- access::rw(x.mem_state) = 0;
- access::rw(x.mem) = 0;
- }
- else
- {
- (*this).operator=(x);
- }
- }
- template<typename eT>
- inline
- void
- Mat<eT>::steal_mem_col(Mat<eT>& x, const uword max_n_rows)
- {
- arma_extra_debug_sigprint();
-
- const uword x_n_elem = x.n_elem;
- const uhword x_mem_state = x.mem_state;
-
- const uhword t_vec_state = vec_state;
- const uhword t_mem_state = mem_state;
-
- const uword alt_n_rows = (std::min)(x.n_rows, max_n_rows);
-
- if((x_n_elem == 0) || (alt_n_rows == 0))
- {
- (*this).set_size(0,1);
-
- return;
- }
-
- if( (this != &x) && (t_vec_state <= 1) && (t_mem_state <= 1) && (x_mem_state <= 1) )
- {
- if( (x_mem_state == 0) && ((x_n_elem <= arma_config::mat_prealloc) || (alt_n_rows <= arma_config::mat_prealloc)) )
- {
- (*this).set_size(alt_n_rows, uword(1));
-
- arrayops::copy( (*this).memptr(), x.memptr(), alt_n_rows );
- }
- else
- {
- reset();
-
- access::rw(n_rows) = alt_n_rows;
- access::rw(n_cols) = 1;
- access::rw(n_elem) = alt_n_rows;
- access::rw(mem_state) = x_mem_state;
- access::rw(mem) = x.mem;
-
- access::rw(x.n_rows) = 0;
- access::rw(x.n_cols) = 0;
- access::rw(x.n_elem) = 0;
- access::rw(x.mem_state) = 0;
- access::rw(x.mem) = 0;
- }
- }
- else
- {
- Mat<eT> tmp(alt_n_rows, 1);
-
- arrayops::copy( tmp.memptr(), x.memptr(), alt_n_rows );
-
- steal_mem(tmp);
- }
- }
- //! construct a matrix from a given auxiliary array of eTs.
- //! if copy_aux_mem is true, new memory is allocated and the array is copied.
- //! if copy_aux_mem is false, the auxiliary array is used directly (without allocating memory and copying).
- //! the default is to copy the array.
- template<typename eT>
- inline
- Mat<eT>::Mat(eT* aux_mem, const uword aux_n_rows, const uword aux_n_cols, const bool copy_aux_mem, const bool strict)
- : n_rows ( aux_n_rows )
- , n_cols ( aux_n_cols )
- , n_elem ( aux_n_rows*aux_n_cols )
- , vec_state( 0 )
- , mem_state( copy_aux_mem ? 0 : ( strict ? 2 : 1 ) )
- , mem ( copy_aux_mem ? 0 : aux_mem )
- {
- arma_extra_debug_sigprint_this(this);
-
- if(copy_aux_mem)
- {
- init_cold();
-
- arrayops::copy( memptr(), aux_mem, n_elem );
- }
- }
- //! construct a matrix from a given auxiliary read-only array of eTs.
- //! the array is copied.
- template<typename eT>
- inline
- Mat<eT>::Mat(const eT* aux_mem, const uword aux_n_rows, const uword aux_n_cols)
- : n_rows(aux_n_rows)
- , n_cols(aux_n_cols)
- , n_elem(aux_n_rows*aux_n_cols)
- , vec_state(0)
- , mem_state(0)
- , mem()
- {
- arma_extra_debug_sigprint_this(this);
-
- init_cold();
-
- arrayops::copy( memptr(), aux_mem, n_elem );
- }
- //! DANGEROUS! Construct a temporary matrix, using auxiliary memory.
- //! This constructor is NOT intended for usage by user code.
- //! Its sole purpose is to be used by the Cube class.
- template<typename eT>
- inline
- Mat<eT>::Mat(const char junk, const eT* aux_mem, const uword aux_n_rows, const uword aux_n_cols)
- : n_rows (aux_n_rows )
- , n_cols (aux_n_cols )
- , n_elem (aux_n_rows*aux_n_cols)
- , vec_state(0 )
- , mem_state(3 )
- , mem (aux_mem )
- {
- arma_extra_debug_sigprint_this(this);
- arma_ignore(junk);
- }
- //! in-place matrix addition
- template<typename eT>
- inline
- Mat<eT>&
- Mat<eT>::operator+=(const Mat<eT>& m)
- {
- arma_extra_debug_sigprint();
-
- arma_debug_assert_same_size(*this, m, "addition");
-
- arrayops::inplace_plus( memptr(), m.memptr(), n_elem );
-
- return *this;
- }
- //! in-place matrix subtraction
- template<typename eT>
- inline
- Mat<eT>&
- Mat<eT>::operator-=(const Mat<eT>& m)
- {
- arma_extra_debug_sigprint();
-
- arma_debug_assert_same_size(*this, m, "subtraction");
-
- arrayops::inplace_minus( memptr(), m.memptr(), n_elem );
-
- return *this;
- }
- //! in-place matrix multiplication
- template<typename eT>
- inline
- Mat<eT>&
- Mat<eT>::operator*=(const Mat<eT>& m)
- {
- arma_extra_debug_sigprint();
-
- glue_times::apply_inplace(*this, m);
-
- return *this;
- }
- //! in-place element-wise matrix multiplication
- template<typename eT>
- inline
- Mat<eT>&
- Mat<eT>::operator%=(const Mat<eT>& m)
- {
- arma_extra_debug_sigprint();
-
- arma_debug_assert_same_size(*this, m, "element-wise multiplication");
-
- arrayops::inplace_mul( memptr(), m.memptr(), n_elem );
-
- return *this;
- }
- //! in-place element-wise matrix division
- template<typename eT>
- inline
- Mat<eT>&
- Mat<eT>::operator/=(const Mat<eT>& m)
- {
- arma_extra_debug_sigprint();
-
- arma_debug_assert_same_size(*this, m, "element-wise division");
-
- arrayops::inplace_div( memptr(), m.memptr(), n_elem );
-
- return *this;
- }
- template<typename eT>
- template<typename T1>
- inline
- Mat<eT>::Mat(const BaseCube<eT,T1>& X)
- : n_rows(0)
- , n_cols(0)
- , n_elem(0)
- , vec_state(0)
- , mem_state(0)
- , mem()
- {
- arma_extra_debug_sigprint_this(this);
-
- (*this).operator=(X);
- }
- template<typename eT>
- template<typename T1>
- inline
- Mat<eT>&
- Mat<eT>::operator=(const BaseCube<eT,T1>& X)
- {
- arma_extra_debug_sigprint();
-
- Mat<eT>& out = *this;
-
- const unwrap_cube<T1> tmp(X.get_ref());
- const Cube<eT>& in = tmp.M;
-
- arma_debug_assert_cube_as_mat(out, in, "copy into matrix", false);
-
- const uword in_n_rows = in.n_rows;
- const uword in_n_cols = in.n_cols;
- const uword in_n_slices = in.n_slices;
-
- const uword out_vec_state = out.vec_state;
-
- if(in_n_slices == 1)
- {
- out.set_size(in_n_rows, in_n_cols);
-
- for(uword ucol=0; ucol < in_n_cols; ++ucol)
- {
- arrayops::copy( out.colptr(ucol), in.slice_colptr(0, ucol), in_n_rows );
- }
- }
- else
- {
- if(out_vec_state == 0)
- {
- if(in_n_cols == 1)
- {
- out.set_size(in_n_rows, in_n_slices);
-
- for(uword i=0; i < in_n_slices; ++i)
- {
- arrayops::copy( out.colptr(i), in.slice_colptr(i, 0), in_n_rows );
- }
- }
- else
- if(in_n_rows == 1)
- {
- out.set_size(in_n_cols, in_n_slices);
-
- for(uword slice=0; slice < in_n_slices; ++slice)
- {
- eT* out_colptr = out.colptr(slice);
-
- uword i,j;
- for(i=0, j=1; j < in_n_cols; i+=2, j+=2)
- {
- const eT tmp_i = in.at(0, i, slice);
- const eT tmp_j = in.at(0, j, slice);
-
- out_colptr[i] = tmp_i;
- out_colptr[j] = tmp_j;
- }
-
- if(i < in_n_cols)
- {
- out_colptr[i] = in.at(0, i, slice);
- }
- }
- }
- }
- else
- {
- out.set_size(in_n_slices);
-
- eT* out_mem = out.memptr();
-
- for(uword i=0; i<in_n_slices; ++i)
- {
- out_mem[i] = in.at(0, 0, i);
- }
- }
- }
-
- return *this;
- }
- template<typename eT>
- template<typename T1>
- inline
- Mat<eT>&
- Mat<eT>::operator+=(const BaseCube<eT,T1>& X)
- {
- arma_extra_debug_sigprint();
-
- Mat<eT>& out = *this;
-
- const unwrap_cube<T1> tmp(X.get_ref());
- const Cube<eT>& in = tmp.M;
-
- arma_debug_assert_cube_as_mat(out, in, "addition", true);
-
- const uword in_n_rows = in.n_rows;
- const uword in_n_cols = in.n_cols;
- const uword in_n_slices = in.n_slices;
-
- const uword out_n_rows = out.n_rows;
- const uword out_n_cols = out.n_cols;
- const uword out_vec_state = out.vec_state;
-
- if(in_n_slices == 1)
- {
- for(uword ucol=0; ucol < in_n_cols; ++ucol)
- {
- arrayops::inplace_plus( out.colptr(ucol), in.slice_colptr(0, ucol), in_n_rows );
- }
- }
- else
- {
- if(out_vec_state == 0)
- {
- if( (in_n_rows == out_n_rows) && (in_n_cols == 1) && (in_n_slices == out_n_cols) )
- {
- for(uword i=0; i < in_n_slices; ++i)
- {
- arrayops::inplace_plus( out.colptr(i), in.slice_colptr(i, 0), in_n_rows );
- }
- }
- else
- if( (in_n_rows == 1) && (in_n_cols == out_n_rows) && (in_n_slices == out_n_cols) )
- {
- for(uword slice=0; slice < in_n_slices; ++slice)
- {
- eT* out_colptr = out.colptr(slice);
-
- uword i,j;
- for(i=0, j=1; j < in_n_cols; i+=2, j+=2)
- {
- const eT tmp_i = in.at(0, i, slice);
- const eT tmp_j = in.at(0, j, slice);
-
- out_colptr[i] += tmp_i;
- out_colptr[j] += tmp_j;
- }
-
- if(i < in_n_cols)
- {
- out_colptr[i] += in.at(0, i, slice);
- }
- }
- }
- }
- else
- {
- eT* out_mem = out.memptr();
-
- for(uword i=0; i<in_n_slices; ++i)
- {
- out_mem[i] += in.at(0, 0, i);
- }
- }
- }
-
- return *this;
- }
- template<typename eT>
- template<typename T1>
- inline
- Mat<eT>&
- Mat<eT>::operator-=(const BaseCube<eT,T1>& X)
- {
- arma_extra_debug_sigprint();
-
- Mat<eT>& out = *this;
-
- const unwrap_cube<T1> tmp(X.get_ref());
- const Cube<eT>& in = tmp.M;
-
- arma_debug_assert_cube_as_mat(out, in, "subtraction", true);
-
- const uword in_n_rows = in.n_rows;
- const uword in_n_cols = in.n_cols;
- const uword in_n_slices = in.n_slices;
-
- const uword out_n_rows = out.n_rows;
- const uword out_n_cols = out.n_cols;
- const uword out_vec_state = out.vec_state;
-
- if(in_n_slices == 1)
- {
- for(uword ucol=0; ucol < in_n_cols; ++ucol)
- {
- arrayops::inplace_minus( out.colptr(ucol), in.slice_colptr(0, ucol), in_n_rows );
- }
- }
- else
- {
- if(out_vec_state == 0)
- {
- if( (in_n_rows == out_n_rows) && (in_n_cols == 1) && (in_n_slices == out_n_cols) )
- {
- for(uword i=0; i < in_n_slices; ++i)
- {
- arrayops::inplace_minus( out.colptr(i), in.slice_colptr(i, 0), in_n_rows );
- }
- }
- else
- if( (in_n_rows == 1) && (in_n_cols == out_n_rows) && (in_n_slices == out_n_cols) )
- {
- for(uword slice=0; slice < in_n_slices; ++slice)
- {
- eT* out_colptr = out.colptr(slice);
-
- uword i,j;
- for(i=0, j=1; j < in_n_cols; i+=2, j+=2)
- {
- const eT tmp_i = in.at(0, i, slice);
- const eT tmp_j = in.at(0, j, slice);
-
- out_colptr[i] -= tmp_i;
- out_colptr[j] -= tmp_j;
- }
-
- if(i < in_n_cols)
- {
- out_colptr[i] -= in.at(0, i, slice);
- }
- }
- }
- }
- else
- {
- eT* out_mem = out.memptr();
-
- for(uword i=0; i<in_n_slices; ++i)
- {
- out_mem[i] -= in.at(0, 0, i);
- }
- }
- }
-
- return *this;
- }
- template<typename eT>
- template<typename T1>
- inline
- Mat<eT>&
- Mat<eT>::operator*=(const BaseCube<eT,T1>& X)
- {
- arma_extra_debug_sigprint();
-
- const Mat<eT> B(X);
-
- (*this).operator*=(B);
-
- return *this;
- }
- template<typename eT>
- template<typename T1>
- inline
- Mat<eT>&
- Mat<eT>::operator%=(const BaseCube<eT,T1>& X)
- {
- arma_extra_debug_sigprint();
-
- Mat<eT>& out = *this;
-
- const unwrap_cube<T1> tmp(X.get_ref());
- const Cube<eT>& in = tmp.M;
-
- arma_debug_assert_cube_as_mat(out, in, "element-wise multiplication", true);
-
- const uword in_n_rows = in.n_rows;
- const uword in_n_cols = in.n_cols;
- const uword in_n_slices = in.n_slices;
-
- const uword out_n_rows = out.n_rows;
- const uword out_n_cols = out.n_cols;
- const uword out_vec_state = out.vec_state;
-
- if(in_n_slices == 1)
- {
- for(uword ucol=0; ucol < in_n_cols; ++ucol)
- {
- arrayops::inplace_mul( out.colptr(ucol), in.slice_colptr(0, ucol), in_n_rows );
- }
- }
- else
- {
- if(out_vec_state == 0)
- {
- if( (in_n_rows == out_n_rows) && (in_n_cols == 1) && (in_n_slices == out_n_cols) )
- {
- for(uword i=0; i < in_n_slices; ++i)
- {
- arrayops::inplace_mul( out.colptr(i), in.slice_colptr(i, 0), in_n_rows );
- }
- }
- else
- if( (in_n_rows == 1) && (in_n_cols == out_n_rows) && (in_n_slices == out_n_cols) )
- {
- for(uword slice=0; slice < in_n_slices; ++slice)
- {
- eT* out_colptr = out.colptr(slice);
-
- uword i,j;
- for(i=0, j=1; j < in_n_cols; i+=2, j+=2)
- {
- const eT tmp_i = in.at(0, i, slice);
- const eT tmp_j = in.at(0, j, slice);
-
- out_colptr[i] *= tmp_i;
- out_colptr[j] *= tmp_j;
- }
-
- if(i < in_n_cols)
- {
- out_colptr[i] *= in.at(0, i, slice);
- }
- }
- }
- }
- else
- {
- eT* out_mem = out.memptr();
-
- for(uword i=0; i<in_n_slices; ++i)
- {
- out_mem[i] *= in.at(0, 0, i);
- }
- }
- }
-
- return *this;
- }
- template<typename eT>
- template<typename T1>
- inline
- Mat<eT>&
- Mat<eT>::operator/=(const BaseCube<eT,T1>& X)
- {
- arma_extra_debug_sigprint();
-
- Mat<eT>& out = *this;
-
- const unwrap_cube<T1> tmp(X.get_ref());
- const Cube<eT>& in = tmp.M;
-
- arma_debug_assert_cube_as_mat(out, in, "element-wise division", true);
-
- const uword in_n_rows = in.n_rows;
- const uword in_n_cols = in.n_cols;
- const uword in_n_slices = in.n_slices;
-
- const uword out_n_rows = out.n_rows;
- const uword out_n_cols = out.n_cols;
- const uword out_vec_state = out.vec_state;
-
- if(in_n_slices == 1)
- {
- for(uword ucol=0; ucol < in_n_cols; ++ucol)
- {
- arrayops::inplace_div( out.colptr(ucol), in.slice_colptr(0, ucol), in_n_rows );
- }
- }
- else
- {
- if(out_vec_state == 0)
- {
- if( (in_n_rows == out_n_rows) && (in_n_cols == 1) && (in_n_slices == out_n_cols) )
- {
- for(uword i=0; i < in_n_slices; ++i)
- {
- arrayops::inplace_div( out.colptr(i), in.slice_colptr(i, 0), in_n_rows );
- }
- }
- else
- if( (in_n_rows == 1) && (in_n_cols == out_n_rows) && (in_n_slices == out_n_cols) )
- {
- for(uword slice=0; slice < in_n_slices; ++slice)
- {
- eT* out_colptr = out.colptr(slice);
-
- uword i,j;
- for(i=0, j=1; j < in_n_cols; i+=2, j+=2)
- {
- const eT tmp_i = in.at(0, i, slice);
- const eT tmp_j = in.at(0, j, slice);
-
- out_colptr[i] /= tmp_i;
- out_colptr[j] /= tmp_j;
- }
-
- if(i < in_n_cols)
- {
- out_colptr[i] /= in.at(0, i, slice);
- }
- }
- }
- }
- else
- {
- eT* out_mem = out.memptr();
-
- for(uword i=0; i<in_n_slices; ++i)
- {
- out_mem[i] /= in.at(0, 0, i);
- }
- }
- }
-
- return *this;
- }
- //! for constructing a complex matrix out of two non-complex matrices
- template<typename eT>
- template<typename T1, typename T2>
- inline
- Mat<eT>::Mat
- (
- const Base<typename Mat<eT>::pod_type,T1>& A,
- const Base<typename Mat<eT>::pod_type,T2>& B
- )
- : n_rows(0)
- , n_cols(0)
- , n_elem(0)
- , vec_state(0)
- , mem_state(0)
- , mem()
- {
- arma_extra_debug_sigprint_this(this);
-
- init(A,B);
- }
- template<typename eT>
- inline
- #ifdef LUOYC20220705
- Mat<eT>::Mat(subview<eT>& X, const bool use_colmem)
- #else
- Mat<eT>::Mat(const subview<eT>& X, const bool use_colmem)
- #endif
- : n_rows(X.n_rows)
- , n_cols(X.n_cols)
- , n_elem(X.n_elem)
- , vec_state(0)
- , mem_state(use_colmem ? 3 : 0)
- , mem (use_colmem ? X.colptr(0) : NULL)
- {
- arma_extra_debug_sigprint_this(this);
-
- if(use_colmem)
- {
- arma_extra_debug_print("Mat::Mat(): using existing memory in a submatrix");
- }
- else
- {
- init_cold();
-
- subview<eT>::extract(*this, X);
- }
- }
- //! construct a matrix from subview (e.g. construct a matrix from a delayed submatrix operation)
- template<typename eT>
- inline
- Mat<eT>::Mat(const subview<eT>& X)
- : n_rows(X.n_rows)
- , n_cols(X.n_cols)
- , n_elem(X.n_elem)
- , vec_state(0)
- , mem_state(0)
- , mem()
- {
- arma_extra_debug_sigprint_this(this);
-
- init_cold();
-
- subview<eT>::extract(*this, X);
- }
- //! construct a matrix from subview (e.g. construct a matrix from a delayed submatrix operation)
- template<typename eT>
- inline
- Mat<eT>&
- Mat<eT>::operator=(const subview<eT>& X)
- {
- arma_extra_debug_sigprint();
-
- const bool alias = (this == &(X.m));
-
- if(alias == false)
- {
- init_warm(X.n_rows, X.n_cols);
-
- subview<eT>::extract(*this, X);
- }
- else
- {
- Mat<eT> tmp(X);
-
- steal_mem(tmp);
- }
-
- return *this;
- }
- //! in-place matrix addition (using a submatrix on the right-hand-side)
- template<typename eT>
- inline
- Mat<eT>&
- Mat<eT>::operator+=(const subview<eT>& X)
- {
- arma_extra_debug_sigprint();
-
- subview<eT>::plus_inplace(*this, X);
-
- return *this;
- }
- //! in-place matrix subtraction (using a submatrix on the right-hand-side)
- template<typename eT>
- inline
- Mat<eT>&
- Mat<eT>::operator-=(const subview<eT>& X)
- {
- arma_extra_debug_sigprint();
-
- subview<eT>::minus_inplace(*this, X);
-
- return *this;
- }
- //! in-place matrix mutiplication (using a submatrix on the right-hand-side)
- template<typename eT>
- inline
- Mat<eT>&
- Mat<eT>::operator*=(const subview<eT>& X)
- {
- arma_extra_debug_sigprint();
-
- glue_times::apply_inplace(*this, X);
-
- return *this;
- }
- //! in-place element-wise matrix mutiplication (using a submatrix on the right-hand-side)
- template<typename eT>
- inline
- Mat<eT>&
- Mat<eT>::operator%=(const subview<eT>& X)
- {
- arma_extra_debug_sigprint();
-
- subview<eT>::schur_inplace(*this, X);
-
- return *this;
- }
- //! in-place element-wise matrix division (using a submatrix on the right-hand-side)
- template<typename eT>
- inline
- Mat<eT>&
- Mat<eT>::operator/=(const subview<eT>& X)
- {
- arma_extra_debug_sigprint();
-
- subview<eT>::div_inplace(*this, X);
-
- return *this;
- }
- template<typename eT>
- inline
- Mat<eT>::Mat(const subview_row_strans<eT>& X)
- : n_rows(X.n_rows)
- , n_cols(X.n_cols)
- , n_elem(X.n_elem)
- , vec_state(0)
- , mem_state(0)
- , mem()
- {
- arma_extra_debug_sigprint_this(this);
-
- init_cold();
-
- X.extract(*this);
- }
- template<typename eT>
- inline
- Mat<eT>::Mat(const subview_row_htrans<eT>& X)
- : n_rows(X.n_rows)
- , n_cols(X.n_cols)
- , n_elem(X.n_elem)
- , vec_state(0)
- , mem_state(0)
- , mem()
- {
- arma_extra_debug_sigprint_this(this);
-
- init_cold();
-
- X.extract(*this);
- }
- template<typename eT>
- inline
- Mat<eT>::Mat(const xvec_htrans<eT>& X)
- : n_rows(X.n_rows)
- , n_cols(X.n_cols)
- , n_elem(X.n_elem)
- , vec_state(0)
- , mem_state(0)
- , mem()
- {
- arma_extra_debug_sigprint_this(this);
-
- init_cold();
-
- X.extract(*this);
- }
- template<typename eT>
- template<bool do_conj>
- inline
- Mat<eT>::Mat(const xtrans_mat<eT,do_conj>& X)
- : n_rows(X.n_rows)
- , n_cols(X.n_cols)
- , n_elem(X.n_elem)
- , vec_state(0)
- , mem_state(0)
- , mem()
- {
- arma_extra_debug_sigprint_this(this);
-
- init_cold();
-
- X.extract(*this);
- }
- //! construct a matrix from a subview_cube instance
- template<typename eT>
- inline
- Mat<eT>::Mat(const subview_cube<eT>& x)
- : n_rows(0)
- , n_cols(0)
- , n_elem(0)
- , vec_state(0)
- , mem_state(0)
- , mem()
- {
- arma_extra_debug_sigprint_this(this);
-
- this->operator=(x);
- }
- //! construct a matrix from a subview_cube instance
- template<typename eT>
- inline
- Mat<eT>&
- Mat<eT>::operator=(const subview_cube<eT>& X)
- {
- arma_extra_debug_sigprint();
-
- subview_cube<eT>::extract(*this, X);
-
- return *this;
- }
- //! in-place matrix addition (using a single-slice subcube on the right-hand-side)
- template<typename eT>
- inline
- Mat<eT>&
- Mat<eT>::operator+=(const subview_cube<eT>& X)
- {
- arma_extra_debug_sigprint();
- subview_cube<eT>::plus_inplace(*this, X);
-
- return *this;
- }
- //! in-place matrix subtraction (using a single-slice subcube on the right-hand-side)
- template<typename eT>
- inline
- Mat<eT>&
- Mat<eT>::operator-=(const subview_cube<eT>& X)
- {
- arma_extra_debug_sigprint();
-
- subview_cube<eT>::minus_inplace(*this, X);
-
- return *this;
- }
- //! in-place matrix mutiplication (using a single-slice subcube on the right-hand-side)
- template<typename eT>
- inline
- Mat<eT>&
- Mat<eT>::operator*=(const subview_cube<eT>& X)
- {
- arma_extra_debug_sigprint();
- const Mat<eT> tmp(X);
- glue_times::apply_inplace(*this, tmp);
-
- return *this;
- }
- //! in-place element-wise matrix mutiplication (using a single-slice subcube on the right-hand-side)
- template<typename eT>
- inline
- Mat<eT>&
- Mat<eT>::operator%=(const subview_cube<eT>& X)
- {
- arma_extra_debug_sigprint();
-
- subview_cube<eT>::schur_inplace(*this, X);
-
- return *this;
- }
- //! in-place element-wise matrix division (using a single-slice subcube on the right-hand-side)
- template<typename eT>
- inline
- Mat<eT>&
- Mat<eT>::operator/=(const subview_cube<eT>& X)
- {
- arma_extra_debug_sigprint();
-
- subview_cube<eT>::div_inplace(*this, X);
-
- return *this;
- }
- //! construct a matrix from diagview (e.g. construct a matrix from a delayed diag operation)
- template<typename eT>
- inline
- Mat<eT>::Mat(const diagview<eT>& X)
- : n_rows(X.n_rows)
- , n_cols(X.n_cols)
- , n_elem(X.n_elem)
- , vec_state(0)
- , mem_state(0)
- , mem()
- {
- arma_extra_debug_sigprint_this(this);
-
- init_cold();
-
- diagview<eT>::extract(*this, X);
- }
- //! construct a matrix from diagview (e.g. construct a matrix from a delayed diag operation)
- template<typename eT>
- inline
- Mat<eT>&
- Mat<eT>::operator=(const diagview<eT>& X)
- {
- arma_extra_debug_sigprint();
-
- const bool alias = (this == &(X.m));
-
- if(alias == false)
- {
- init_warm(X.n_rows, X.n_cols);
-
- diagview<eT>::extract(*this, X);
- }
- else
- {
- Mat<eT> tmp(X);
-
- steal_mem(tmp);
- }
-
- return *this;
- }
- //! in-place matrix addition (using a diagview on the right-hand-side)
- template<typename eT>
- inline
- Mat<eT>&
- Mat<eT>::operator+=(const diagview<eT>& X)
- {
- arma_extra_debug_sigprint();
-
- diagview<eT>::plus_inplace(*this, X);
-
- return *this;
- }
- //! in-place matrix subtraction (using a diagview on the right-hand-side)
- template<typename eT>
- inline
- Mat<eT>&
- Mat<eT>::operator-=(const diagview<eT>& X)
- {
- arma_extra_debug_sigprint();
-
- diagview<eT>::minus_inplace(*this, X);
-
- return *this;
- }
- //! in-place matrix mutiplication (using a diagview on the right-hand-side)
- template<typename eT>
- inline
- Mat<eT>&
- Mat<eT>::operator*=(const diagview<eT>& X)
- {
- arma_extra_debug_sigprint();
-
- glue_times::apply_inplace(*this, X);
-
- return *this;
- }
- //! in-place element-wise matrix mutiplication (using a diagview on the right-hand-side)
- template<typename eT>
- inline
- Mat<eT>&
- Mat<eT>::operator%=(const diagview<eT>& X)
- {
- arma_extra_debug_sigprint();
-
- diagview<eT>::schur_inplace(*this, X);
-
- return *this;
- }
- //! in-place element-wise matrix division (using a diagview on the right-hand-side)
- template<typename eT>
- inline
- Mat<eT>&
- Mat<eT>::operator/=(const diagview<eT>& X)
- {
- arma_extra_debug_sigprint();
-
- diagview<eT>::div_inplace(*this, X);
-
- return *this;
- }
- template<typename eT>
- template<typename T1>
- inline
- Mat<eT>::Mat(const subview_elem1<eT,T1>& X)
- : n_rows(0)
- , n_cols(0)
- , n_elem(0)
- , vec_state(0)
- , mem_state(0)
- , mem()
- {
- arma_extra_debug_sigprint_this(this);
-
- this->operator=(X);
- }
- template<typename eT>
- template<typename T1>
- inline
- Mat<eT>&
- Mat<eT>::operator=(const subview_elem1<eT,T1>& X)
- {
- arma_extra_debug_sigprint();
-
- subview_elem1<eT,T1>::extract(*this, X);
-
- return *this;
- }
- template<typename eT>
- template<typename T1>
- inline
- Mat<eT>&
- Mat<eT>::operator+=(const subview_elem1<eT,T1>& X)
- {
- arma_extra_debug_sigprint();
-
- subview_elem1<eT,T1>::plus_inplace(*this, X);
-
- return *this;
- }
- template<typename eT>
- template<typename T1>
- inline
- Mat<eT>&
- Mat<eT>::operator-=(const subview_elem1<eT,T1>& X)
- {
- arma_extra_debug_sigprint();
-
- subview_elem1<eT,T1>::minus_inplace(*this, X);
-
- return *this;
- }
- template<typename eT>
- template<typename T1>
- inline
- Mat<eT>&
- Mat<eT>::operator*=(const subview_elem1<eT,T1>& X)
- {
- arma_extra_debug_sigprint();
-
- glue_times::apply_inplace(*this, X);
-
- return *this;
- }
- template<typename eT>
- template<typename T1>
- inline
- Mat<eT>&
- Mat<eT>::operator%=(const subview_elem1<eT,T1>& X)
- {
- arma_extra_debug_sigprint();
-
- subview_elem1<eT,T1>::schur_inplace(*this, X);
-
- return *this;
- }
- template<typename eT>
- template<typename T1>
- inline
- Mat<eT>&
- Mat<eT>::operator/=(const subview_elem1<eT,T1>& X)
- {
- arma_extra_debug_sigprint();
-
- subview_elem1<eT,T1>::div_inplace(*this, X);
-
- return *this;
- }
- template<typename eT>
- template<typename T1, typename T2>
- inline
- Mat<eT>::Mat(const subview_elem2<eT,T1,T2>& X)
- : n_rows(0)
- , n_cols(0)
- , n_elem(0)
- , vec_state(0)
- , mem_state(0)
- , mem()
- {
- arma_extra_debug_sigprint_this(this);
-
- this->operator=(X);
- }
- template<typename eT>
- template<typename T1, typename T2>
- inline
- Mat<eT>&
- Mat<eT>::operator=(const subview_elem2<eT,T1,T2>& X)
- {
- arma_extra_debug_sigprint();
-
- subview_elem2<eT,T1,T2>::extract(*this, X);
-
- return *this;
- }
- template<typename eT>
- template<typename T1, typename T2>
- inline
- Mat<eT>&
- Mat<eT>::operator+=(const subview_elem2<eT,T1,T2>& X)
- {
- arma_extra_debug_sigprint();
-
- subview_elem2<eT,T1,T2>::plus_inplace(*this, X);
-
- return *this;
- }
- template<typename eT>
- template<typename T1, typename T2>
- inline
- Mat<eT>&
- Mat<eT>::operator-=(const subview_elem2<eT,T1,T2>& X)
- {
- arma_extra_debug_sigprint();
-
- subview_elem2<eT,T1,T2>::minus_inplace(*this, X);
-
- return *this;
- }
- template<typename eT>
- template<typename T1, typename T2>
- inline
- Mat<eT>&
- Mat<eT>::operator*=(const subview_elem2<eT,T1,T2>& X)
- {
- arma_extra_debug_sigprint();
-
- glue_times::apply_inplace(*this, X);
-
- return *this;
- }
- template<typename eT>
- template<typename T1, typename T2>
- inline
- Mat<eT>&
- Mat<eT>::operator%=(const subview_elem2<eT,T1,T2>& X)
- {
- arma_extra_debug_sigprint();
-
- subview_elem2<eT,T1,T2>::schur_inplace(*this, X);
-
- return *this;
- }
- template<typename eT>
- template<typename T1, typename T2>
- inline
- Mat<eT>&
- Mat<eT>::operator/=(const subview_elem2<eT,T1,T2>& X)
- {
- arma_extra_debug_sigprint();
-
- subview_elem2<eT,T1,T2>::div_inplace(*this, X);
-
- return *this;
- }
- template<typename eT>
- template<typename T1>
- inline
- Mat<eT>::Mat(const SpBase<eT, T1>& m)
- : n_rows(0)
- , n_cols(0)
- , n_elem(0)
- , vec_state(0)
- , mem_state(0)
- , mem()
- {
- arma_extra_debug_sigprint_this(this);
-
- (*this).operator=(m);
- }
- template<typename eT>
- template<typename T1>
- inline
- Mat<eT>&
- Mat<eT>::operator=(const SpBase<eT, T1>& m)
- {
- arma_extra_debug_sigprint();
-
- const unwrap_spmat<T1> U(m.get_ref());
- const SpMat<eT>& x = U.M;
-
- const uword x_n_cols = x.n_cols;
-
- (*this).zeros(x.n_rows, x_n_cols);
-
- const eT* x_values = x.values;
- const uword* x_row_indices = x.row_indices;
- const uword* x_col_ptrs = x.col_ptrs;
-
- for(uword x_col = 0; x_col < x_n_cols; ++x_col)
- {
- const uword start = x_col_ptrs[x_col ];
- const uword end = x_col_ptrs[x_col + 1];
-
- for(uword i = start; i < end; ++i)
- {
- const uword x_row = x_row_indices[i];
- const eT x_val = x_values[i];
-
- at(x_row, x_col) = x_val;
- }
- }
-
- return *this;
- }
- template<typename eT>
- template<typename T1>
- inline
- Mat<eT>&
- Mat<eT>::operator+=(const SpBase<eT, T1>& m)
- {
- arma_extra_debug_sigprint();
-
- const SpProxy<T1> p(m.get_ref());
-
- arma_debug_assert_same_size(n_rows, n_cols, p.get_n_rows(), p.get_n_cols(), "addition");
-
- typename SpProxy<T1>::const_iterator_type it = p.begin();
- typename SpProxy<T1>::const_iterator_type it_end = p.end();
-
- while(it != it_end)
- {
- at(it.row(), it.col()) += (*it);
- ++it;
- }
-
- return *this;
- }
- template<typename eT>
- template<typename T1>
- inline
- Mat<eT>&
- Mat<eT>::operator-=(const SpBase<eT, T1>& m)
- {
- arma_extra_debug_sigprint();
-
- const SpProxy<T1> p(m.get_ref());
-
- arma_debug_assert_same_size(n_rows, n_cols, p.get_n_rows(), p.get_n_cols(), "subtraction");
-
- typename SpProxy<T1>::const_iterator_type it = p.begin();
- typename SpProxy<T1>::const_iterator_type it_end = p.end();
-
- while(it != it_end)
- {
- at(it.row(), it.col()) -= (*it);
- ++it;
- }
-
- return *this;
- }
- template<typename eT>
- template<typename T1>
- inline
- Mat<eT>&
- Mat<eT>::operator*=(const SpBase<eT, T1>& m)
- {
- arma_extra_debug_sigprint();
-
- Mat<eT> z = (*this) * m.get_ref();
-
- steal_mem(z);
-
- return *this;
- }
- template<typename eT>
- template<typename T1>
- inline
- Mat<eT>&
- Mat<eT>::operator%=(const SpBase<eT, T1>& m)
- {
- arma_extra_debug_sigprint();
-
- const SpProxy<T1> p(m.get_ref());
-
- arma_debug_assert_same_size(n_rows, n_cols, p.get_n_rows(), p.get_n_cols(), "element-wise multiplication");
-
- typename SpProxy<T1>::const_iterator_type it = p.begin();
- typename SpProxy<T1>::const_iterator_type it_end = p.end();
-
- // We have to zero everything that isn't being used.
- arrayops::inplace_set(memptr(), eT(0), (it.col() * n_rows) + it.row());
-
- while(it != it_end)
- {
- const uword cur_loc = (it.col() * n_rows) + it.row();
-
- access::rw(mem[cur_loc]) *= (*it);
-
- ++it;
-
- const uword next_loc = (it == it_end)
- ? (p.get_n_cols() * n_rows)
- : (it.col() * n_rows) + it.row();
-
- arrayops::inplace_set(memptr() + cur_loc + 1, eT(0), (next_loc - cur_loc - 1));
- }
-
- return *this;
- }
- template<typename eT>
- template<typename T1>
- inline
- Mat<eT>&
- Mat<eT>::operator/=(const SpBase<eT, T1>& m)
- {
- arma_extra_debug_sigprint();
-
- // NOTE: use of this function is not advised; it is implemented only for completeness
-
- const SpProxy<T1> p(m.get_ref());
-
- arma_debug_assert_same_size(n_rows, n_cols, p.get_n_rows(), p.get_n_cols(), "element-wise division");
-
- for(uword c = 0; c < n_cols; ++c)
- for(uword r = 0; r < n_rows; ++r)
- {
- at(r, c) /= p.at(r, c);
- }
-
- return *this;
- }
- template<typename eT>
- inline
- Mat<eT>::Mat(const SpSubview<eT>& X)
- : n_rows(0)
- , n_cols(0)
- , n_elem(0)
- , vec_state(0)
- , mem_state(0)
- , mem()
- {
- arma_extra_debug_sigprint_this(this);
-
- (*this).operator=(X);
- }
- template<typename eT>
- inline
- Mat<eT>&
- Mat<eT>::operator=(const SpSubview<eT>& X)
- {
- arma_extra_debug_sigprint();
-
- (*this).zeros(X.n_rows, X.n_cols);
-
- if(X.n_rows == X.m.n_rows)
- {
- const uword sv_col_start = X.aux_col1;
- const uword sv_col_end = X.aux_col1 + X.n_cols - 1;
-
- const eT* m_values = X.m.values;
- const uword* m_row_indices = X.m.row_indices;
- const uword* m_col_ptrs = X.m.col_ptrs;
-
- for(uword m_col = sv_col_start; m_col <= sv_col_end; ++m_col)
- {
- const uword m_col_adjusted = m_col - sv_col_start;
-
- const uword start = m_col_ptrs[m_col ];
- const uword end = m_col_ptrs[m_col + 1];
-
- for(uword ii = start; ii < end; ++ii)
- {
- const uword m_row = m_row_indices[ii];
- const eT m_val = m_values[ii];
-
- at(m_row, m_col_adjusted) = m_val;
- }
- }
- }
- else
- {
- typename SpSubview<eT>::const_iterator it = X.begin();
- typename SpSubview<eT>::const_iterator it_end = X.end();
-
- while(it != it_end)
- {
- at(it.row(), it.col()) = (*it);
- ++it;
- }
- }
-
- return *this;
- }
- template<typename eT>
- inline
- Mat<eT>::Mat(const spdiagview<eT>& X)
- : n_rows(X.n_rows)
- , n_cols(X.n_cols)
- , n_elem(X.n_elem)
- , vec_state(0)
- , mem_state(0)
- , mem()
- {
- arma_extra_debug_sigprint_this(this);
-
- init_cold();
-
- spdiagview<eT>::extract(*this, X);
- }
- template<typename eT>
- inline
- Mat<eT>&
- Mat<eT>::operator=(const spdiagview<eT>& X)
- {
- arma_extra_debug_sigprint();
-
- init_warm(X.n_rows, X.n_cols);
-
- spdiagview<eT>::extract(*this, X);
-
- return *this;
- }
- template<typename eT>
- inline
- Mat<eT>&
- Mat<eT>::operator+=(const spdiagview<eT>& X)
- {
- arma_extra_debug_sigprint();
-
- const Mat<eT> tmp(X);
-
- (*this).operator+=(tmp);
-
- return *this;
- }
- template<typename eT>
- inline
- Mat<eT>&
- Mat<eT>::operator-=(const spdiagview<eT>& X)
- {
- arma_extra_debug_sigprint();
-
- const Mat<eT> tmp(X);
-
- (*this).operator-=(tmp);
-
- return *this;
- }
- template<typename eT>
- inline
- Mat<eT>&
- Mat<eT>::operator*=(const spdiagview<eT>& X)
- {
- arma_extra_debug_sigprint();
-
- const Mat<eT> tmp(X);
-
- (*this).operator*=(tmp);
-
- return *this;
- }
- template<typename eT>
- inline
- Mat<eT>&
- Mat<eT>::operator%=(const spdiagview<eT>& X)
- {
- arma_extra_debug_sigprint();
-
- const Mat<eT> tmp(X);
-
- (*this).operator%=(tmp);
-
- return *this;
- }
- template<typename eT>
- inline
- Mat<eT>&
- Mat<eT>::operator/=(const spdiagview<eT>& X)
- {
- arma_extra_debug_sigprint();
-
- const Mat<eT> tmp(X);
-
- (*this).operator/=(tmp);
-
- return *this;
- }
- template<typename eT>
- inline
- mat_injector< Mat<eT> >
- Mat<eT>::operator<<(const eT val)
- {
- return mat_injector< Mat<eT> >(*this, val);
- }
- template<typename eT>
- inline
- mat_injector< Mat<eT> >
- Mat<eT>::operator<<(const injector_end_of_row<>& x)
- {
- return mat_injector< Mat<eT> >(*this, x);
- }
- //! creation of subview (row vector)
- template<typename eT>
- arma_inline
- subview_row<eT>
- Mat<eT>::row(const uword row_num)
- {
- arma_extra_debug_sigprint();
-
- arma_debug_check( row_num >= n_rows, "Mat::row(): index out of bounds" );
-
- return subview_row<eT>(*this, row_num);
- }
- //! creation of subview (row vector)
- template<typename eT>
- arma_inline
- const subview_row<eT>
- Mat<eT>::row(const uword row_num) const
- {
- arma_extra_debug_sigprint();
-
- arma_debug_check( row_num >= n_rows, "Mat::row(): index out of bounds" );
-
- return subview_row<eT>(*this, row_num);
- }
- template<typename eT>
- inline
- subview_row<eT>
- Mat<eT>::operator()(const uword row_num, const span& col_span)
- {
- arma_extra_debug_sigprint();
-
- const bool col_all = col_span.whole;
-
- const uword local_n_cols = n_cols;
-
- const uword in_col1 = col_all ? 0 : col_span.a;
- const uword in_col2 = col_span.b;
- const uword submat_n_cols = col_all ? local_n_cols : in_col2 - in_col1 + 1;
-
- arma_debug_check
- (
- (row_num >= n_rows)
- ||
- ( col_all ? false : ((in_col1 > in_col2) || (in_col2 >= local_n_cols)) )
- ,
- "Mat::operator(): indices out of bounds or incorrectly used"
- );
-
- return subview_row<eT>(*this, row_num, in_col1, submat_n_cols);
- }
- template<typename eT>
- inline
- const subview_row<eT>
- Mat<eT>::operator()(const uword row_num, const span& col_span) const
- {
- arma_extra_debug_sigprint();
-
- const bool col_all = col_span.whole;
-
- const uword local_n_cols = n_cols;
-
- const uword in_col1 = col_all ? 0 : col_span.a;
- const uword in_col2 = col_span.b;
- const uword submat_n_cols = col_all ? local_n_cols : in_col2 - in_col1 + 1;
-
- arma_debug_check
- (
- (row_num >= n_rows)
- ||
- ( col_all ? false : ((in_col1 > in_col2) || (in_col2 >= local_n_cols)) )
- ,
- "Mat::operator(): indices out of bounds or incorrectly used"
- );
-
- return subview_row<eT>(*this, row_num, in_col1, submat_n_cols);
- }
- //! creation of subview (column vector)
- template<typename eT>
- arma_inline
- subview_col<eT>
- Mat<eT>::col(const uword col_num)
- {
- arma_extra_debug_sigprint();
-
- arma_debug_check( col_num >= n_cols, "Mat::col(): index out of bounds");
-
- return subview_col<eT>(*this, col_num);
- }
- //! creation of subview (column vector)
- template<typename eT>
- arma_inline
- const subview_col<eT>
- Mat<eT>::col(const uword col_num) const
- {
- arma_extra_debug_sigprint();
-
- arma_debug_check( col_num >= n_cols, "Mat::col(): index out of bounds");
-
- return subview_col<eT>(*this, col_num);
- }
- template<typename eT>
- inline
- subview_col<eT>
- Mat<eT>::operator()(const span& row_span, const uword col_num)
- {
- arma_extra_debug_sigprint();
-
- const bool row_all = row_span.whole;
-
- const uword local_n_rows = n_rows;
-
- const uword in_row1 = row_all ? 0 : row_span.a;
- const uword in_row2 = row_span.b;
- const uword submat_n_rows = row_all ? local_n_rows : in_row2 - in_row1 + 1;
-
- arma_debug_check
- (
- (col_num >= n_cols)
- ||
- ( row_all ? false : ((in_row1 > in_row2) || (in_row2 >= local_n_rows)) )
- ,
- "Mat::operator(): indices out of bounds or incorrectly used"
- );
-
- return subview_col<eT>(*this, col_num, in_row1, submat_n_rows);
- }
- template<typename eT>
- inline
- const subview_col<eT>
- Mat<eT>::operator()(const span& row_span, const uword col_num) const
- {
- arma_extra_debug_sigprint();
-
- const bool row_all = row_span.whole;
-
- const uword local_n_rows = n_rows;
-
- const uword in_row1 = row_all ? 0 : row_span.a;
- const uword in_row2 = row_span.b;
- const uword submat_n_rows = row_all ? local_n_rows : in_row2 - in_row1 + 1;
-
- arma_debug_check
- (
- (col_num >= n_cols)
- ||
- ( row_all ? false : ((in_row1 > in_row2) || (in_row2 >= local_n_rows)) )
- ,
- "Mat::operator(): indices out of bounds or incorrectly used"
- );
-
- return subview_col<eT>(*this, col_num, in_row1, submat_n_rows);
- }
- //! create a Col object which uses memory from an existing matrix object.
- //! this approach is currently not alias safe
- //! and does not take into account that the parent matrix object could be deleted.
- //! if deleted memory is accessed by the created Col object,
- //! it will cause memory corruption and/or a crash
- template<typename eT>
- inline
- Col<eT>
- Mat<eT>::unsafe_col(const uword col_num)
- {
- arma_extra_debug_sigprint();
-
- arma_debug_check( col_num >= n_cols, "Mat::unsafe_col(): index out of bounds");
-
- return Col<eT>(colptr(col_num), n_rows, false, true);
- }
- //! create a Col object which uses memory from an existing matrix object.
- //! this approach is currently not alias safe
- //! and does not take into account that the parent matrix object could be deleted.
- //! if deleted memory is accessed by the created Col object,
- //! it will cause memory corruption and/or a crash
- template<typename eT>
- inline
- const Col<eT>
- Mat<eT>::unsafe_col(const uword col_num) const
- {
- arma_extra_debug_sigprint();
-
- arma_debug_check( col_num >= n_cols, "Mat::unsafe_col(): index out of bounds");
-
- typedef const Col<eT> out_type;
-
- return out_type(const_cast<eT*>(colptr(col_num)), n_rows, false, true);
- }
- //! creation of subview (submatrix comprised of specified row vectors)
- template<typename eT>
- arma_inline
- subview<eT>
- Mat<eT>::rows(const uword in_row1, const uword in_row2)
- {
- arma_extra_debug_sigprint();
-
- arma_debug_check
- (
- (in_row1 > in_row2) || (in_row2 >= n_rows),
- "Mat::rows(): indices out of bounds or incorrectly used"
- );
-
- const uword subview_n_rows = in_row2 - in_row1 + 1;
-
- return subview<eT>(*this, in_row1, 0, subview_n_rows, n_cols );
- }
- //! creation of subview (submatrix comprised of specified row vectors)
- template<typename eT>
- arma_inline
- const subview<eT>
- Mat<eT>::rows(const uword in_row1, const uword in_row2) const
- {
- arma_extra_debug_sigprint();
-
- arma_debug_check
- (
- (in_row1 > in_row2) || (in_row2 >= n_rows),
- "Mat::rows(): indices out of bounds or incorrectly used"
- );
-
- const uword subview_n_rows = in_row2 - in_row1 + 1;
-
- return subview<eT>(*this, in_row1, 0, subview_n_rows, n_cols );
- }
- //! creation of subview (submatrix comprised of specified column vectors)
- template<typename eT>
- arma_inline
- subview<eT>
- Mat<eT>::cols(const uword in_col1, const uword in_col2)
- {
- arma_extra_debug_sigprint();
-
- arma_debug_check
- (
- (in_col1 > in_col2) || (in_col2 >= n_cols),
- "Mat::cols(): indices out of bounds or incorrectly used"
- );
-
- const uword subview_n_cols = in_col2 - in_col1 + 1;
-
- return subview<eT>(*this, 0, in_col1, n_rows, subview_n_cols);
- }
- //! creation of subview (submatrix comprised of specified column vectors)
- template<typename eT>
- arma_inline
- const subview<eT>
- Mat<eT>::cols(const uword in_col1, const uword in_col2) const
- {
- arma_extra_debug_sigprint();
-
- arma_debug_check
- (
- (in_col1 > in_col2) || (in_col2 >= n_cols),
- "Mat::cols(): indices out of bounds or incorrectly used"
- );
-
- const uword subview_n_cols = in_col2 - in_col1 + 1;
-
- return subview<eT>(*this, 0, in_col1, n_rows, subview_n_cols);
- }
- //! creation of subview (submatrix comprised of specified row vectors)
- template<typename eT>
- inline
- subview<eT>
- Mat<eT>::rows(const span& row_span)
- {
- arma_extra_debug_sigprint();
-
- const bool row_all = row_span.whole;
-
- const uword local_n_rows = n_rows;
-
- const uword in_row1 = row_all ? 0 : row_span.a;
- const uword in_row2 = row_span.b;
- const uword submat_n_rows = row_all ? local_n_rows : in_row2 - in_row1 + 1;
-
- arma_debug_check
- (
- ( row_all ? false : ((in_row1 > in_row2) || (in_row2 >= local_n_rows)) )
- ,
- "Mat::rows(): indices out of bounds or incorrectly used"
- );
-
- return subview<eT>(*this, in_row1, 0, submat_n_rows, n_cols);
- }
- //! creation of subview (submatrix comprised of specified row vectors)
- template<typename eT>
- inline
- const subview<eT>
- Mat<eT>::rows(const span& row_span) const
- {
- arma_extra_debug_sigprint();
-
- const bool row_all = row_span.whole;
-
- const uword local_n_rows = n_rows;
-
- const uword in_row1 = row_all ? 0 : row_span.a;
- const uword in_row2 = row_span.b;
- const uword submat_n_rows = row_all ? local_n_rows : in_row2 - in_row1 + 1;
-
- arma_debug_check
- (
- ( row_all ? false : ((in_row1 > in_row2) || (in_row2 >= local_n_rows)) )
- ,
- "Mat::rows(): indices out of bounds or incorrectly used"
- );
-
- return subview<eT>(*this, in_row1, 0, submat_n_rows, n_cols);
- }
- //! creation of subview (submatrix comprised of specified column vectors)
- template<typename eT>
- arma_inline
- subview<eT>
- Mat<eT>::cols(const span& col_span)
- {
- arma_extra_debug_sigprint();
-
- const bool col_all = col_span.whole;
-
- const uword local_n_cols = n_cols;
-
- const uword in_col1 = col_all ? 0 : col_span.a;
- const uword in_col2 = col_span.b;
- const uword submat_n_cols = col_all ? local_n_cols : in_col2 - in_col1 + 1;
-
- arma_debug_check
- (
- ( col_all ? false : ((in_col1 > in_col2) || (in_col2 >= local_n_cols)) )
- ,
- "Mat::cols(): indices out of bounds or incorrectly used"
- );
-
- return subview<eT>(*this, 0, in_col1, n_rows, submat_n_cols);
- }
- //! creation of subview (submatrix comprised of specified column vectors)
- template<typename eT>
- arma_inline
- const subview<eT>
- Mat<eT>::cols(const span& col_span) const
- {
- arma_extra_debug_sigprint();
-
- const bool col_all = col_span.whole;
-
- const uword local_n_cols = n_cols;
-
- const uword in_col1 = col_all ? 0 : col_span.a;
- const uword in_col2 = col_span.b;
- const uword submat_n_cols = col_all ? local_n_cols : in_col2 - in_col1 + 1;
-
- arma_debug_check
- (
- ( col_all ? false : ((in_col1 > in_col2) || (in_col2 >= local_n_cols)) )
- ,
- "Mat::cols(): indices out of bounds or incorrectly used"
- );
-
- return subview<eT>(*this, 0, in_col1, n_rows, submat_n_cols);
- }
- //! creation of subview (submatrix)
- template<typename eT>
- arma_inline
- subview<eT>
- Mat<eT>::submat(const uword in_row1, const uword in_col1, const uword in_row2, const uword in_col2)
- {
- arma_extra_debug_sigprint();
-
- arma_debug_check
- (
- (in_row1 > in_row2) || (in_col1 > in_col2) || (in_row2 >= n_rows) || (in_col2 >= n_cols),
- "Mat::submat(): indices out of bounds or incorrectly used"
- );
-
- const uword subview_n_rows = in_row2 - in_row1 + 1;
- const uword subview_n_cols = in_col2 - in_col1 + 1;
-
- return subview<eT>(*this, in_row1, in_col1, subview_n_rows, subview_n_cols);
- }
- //! creation of subview (generic submatrix)
- template<typename eT>
- arma_inline
- const subview<eT>
- Mat<eT>::submat(const uword in_row1, const uword in_col1, const uword in_row2, const uword in_col2) const
- {
- arma_extra_debug_sigprint();
-
- arma_debug_check
- (
- (in_row1 > in_row2) || (in_col1 > in_col2) || (in_row2 >= n_rows) || (in_col2 >= n_cols),
- "Mat::submat(): indices out of bounds or incorrectly used"
- );
-
- const uword subview_n_rows = in_row2 - in_row1 + 1;
- const uword subview_n_cols = in_col2 - in_col1 + 1;
-
- return subview<eT>(*this, in_row1, in_col1, subview_n_rows, subview_n_cols);
- }
- //! creation of subview (submatrix)
- template<typename eT>
- arma_inline
- subview<eT>
- Mat<eT>::submat(const uword in_row1, const uword in_col1, const SizeMat& s)
- {
- arma_extra_debug_sigprint();
-
- const uword l_n_rows = n_rows;
- const uword l_n_cols = n_cols;
-
- const uword s_n_rows = s.n_rows;
- const uword s_n_cols = s.n_cols;
-
- arma_debug_check
- (
- ((in_row1 >= l_n_rows) || (in_col1 >= l_n_cols) || ((in_row1 + s_n_rows) > l_n_rows) || ((in_col1 + s_n_cols) > l_n_cols)),
- "Mat::submat(): indices or size out of bounds"
- );
-
- return subview<eT>(*this, in_row1, in_col1, s_n_rows, s_n_cols);
- }
- //! creation of subview (submatrix)
- template<typename eT>
- arma_inline
- const subview<eT>
- Mat<eT>::submat(const uword in_row1, const uword in_col1, const SizeMat& s) const
- {
- arma_extra_debug_sigprint();
-
- const uword l_n_rows = n_rows;
- const uword l_n_cols = n_cols;
-
- const uword s_n_rows = s.n_rows;
- const uword s_n_cols = s.n_cols;
-
- arma_debug_check
- (
- ((in_row1 >= l_n_rows) || (in_col1 >= l_n_cols) || ((in_row1 + s_n_rows) > l_n_rows) || ((in_col1 + s_n_cols) > l_n_cols)),
- "Mat::submat(): indices or size out of bounds"
- );
-
- return subview<eT>(*this, in_row1, in_col1, s_n_rows, s_n_cols);
- }
- //! creation of subview (submatrix)
- template<typename eT>
- inline
- subview<eT>
- Mat<eT>::submat(const span& row_span, const span& col_span)
- {
- arma_extra_debug_sigprint();
-
- const bool row_all = row_span.whole;
- const bool col_all = col_span.whole;
-
- const uword local_n_rows = n_rows;
- const uword local_n_cols = n_cols;
-
- const uword in_row1 = row_all ? 0 : row_span.a;
- const uword in_row2 = row_span.b;
- const uword submat_n_rows = row_all ? local_n_rows : in_row2 - in_row1 + 1;
-
- const uword in_col1 = col_all ? 0 : col_span.a;
- const uword in_col2 = col_span.b;
- const uword submat_n_cols = col_all ? local_n_cols : in_col2 - in_col1 + 1;
-
- arma_debug_check
- (
- ( row_all ? false : ((in_row1 > in_row2) || (in_row2 >= local_n_rows)) )
- ||
- ( col_all ? false : ((in_col1 > in_col2) || (in_col2 >= local_n_cols)) )
- ,
- "Mat::submat(): indices out of bounds or incorrectly used"
- );
-
- return subview<eT>(*this, in_row1, in_col1, submat_n_rows, submat_n_cols);
- }
- //! creation of subview (generic submatrix)
- template<typename eT>
- inline
- const subview<eT>
- Mat<eT>::submat(const span& row_span, const span& col_span) const
- {
- arma_extra_debug_sigprint();
-
- const bool row_all = row_span.whole;
- const bool col_all = col_span.whole;
-
- const uword local_n_rows = n_rows;
- const uword local_n_cols = n_cols;
-
- const uword in_row1 = row_all ? 0 : row_span.a;
- const uword in_row2 = row_span.b;
- const uword submat_n_rows = row_all ? local_n_rows : in_row2 - in_row1 + 1;
-
- const uword in_col1 = col_all ? 0 : col_span.a;
- const uword in_col2 = col_span.b;
- const uword submat_n_cols = col_all ? local_n_cols : in_col2 - in_col1 + 1;
-
- arma_debug_check
- (
- ( row_all ? false : ((in_row1 > in_row2) || (in_row2 >= local_n_rows)) )
- ||
- ( col_all ? false : ((in_col1 > in_col2) || (in_col2 >= local_n_cols)) )
- ,
- "Mat::submat(): indices out of bounds or incorrectly used"
- );
-
- return subview<eT>(*this, in_row1, in_col1, submat_n_rows, submat_n_cols);
- }
- template<typename eT>
- inline
- subview<eT>
- Mat<eT>::operator()(const span& row_span, const span& col_span)
- {
- arma_extra_debug_sigprint();
-
- return (*this).submat(row_span, col_span);
- }
- template<typename eT>
- inline
- const subview<eT>
- Mat<eT>::operator()(const span& row_span, const span& col_span) const
- {
- arma_extra_debug_sigprint();
-
- return (*this).submat(row_span, col_span);
- }
- template<typename eT>
- inline
- subview<eT>
- Mat<eT>::operator()(const uword in_row1, const uword in_col1, const SizeMat& s)
- {
- arma_extra_debug_sigprint();
-
- return (*this).submat(in_row1, in_col1, s);
- }
- template<typename eT>
- inline
- const subview<eT>
- Mat<eT>::operator()(const uword in_row1, const uword in_col1, const SizeMat& s) const
- {
- arma_extra_debug_sigprint();
-
- return (*this).submat(in_row1, in_col1, s);
- }
- template<typename eT>
- inline
- subview<eT>
- Mat<eT>::head_rows(const uword N)
- {
- arma_extra_debug_sigprint();
-
- arma_debug_check( (N > n_rows), "Mat::head_rows(): size out of bounds");
-
- return subview<eT>(*this, 0, 0, N, n_cols);
- }
- template<typename eT>
- inline
- const subview<eT>
- Mat<eT>::head_rows(const uword N) const
- {
- arma_extra_debug_sigprint();
-
- arma_debug_check( (N > n_rows), "Mat::head_rows(): size out of bounds");
-
- return subview<eT>(*this, 0, 0, N, n_cols);
- }
- template<typename eT>
- inline
- subview<eT>
- Mat<eT>::tail_rows(const uword N)
- {
- arma_extra_debug_sigprint();
-
- arma_debug_check( (N > n_rows), "Mat::tail_rows(): size out of bounds");
-
- const uword start_row = n_rows - N;
-
- return subview<eT>(*this, start_row, 0, N, n_cols);
- }
- template<typename eT>
- inline
- const subview<eT>
- Mat<eT>::tail_rows(const uword N) const
- {
- arma_extra_debug_sigprint();
-
- arma_debug_check( (N > n_rows), "Mat::tail_rows(): size out of bounds");
-
- const uword start_row = n_rows - N;
-
- return subview<eT>(*this, start_row, 0, N, n_cols);
- }
- template<typename eT>
- inline
- subview<eT>
- Mat<eT>::head_cols(const uword N)
- {
- arma_extra_debug_sigprint();
-
- arma_debug_check( (N > n_cols), "Mat::head_cols(): size out of bounds");
-
- return subview<eT>(*this, 0, 0, n_rows, N);
- }
- template<typename eT>
- inline
- const subview<eT>
- Mat<eT>::head_cols(const uword N) const
- {
- arma_extra_debug_sigprint();
-
- arma_debug_check( (N > n_cols), "Mat::head_cols(): size out of bounds");
-
- return subview<eT>(*this, 0, 0, n_rows, N);
- }
- template<typename eT>
- inline
- subview<eT>
- Mat<eT>::tail_cols(const uword N)
- {
- arma_extra_debug_sigprint();
-
- arma_debug_check( (N > n_cols), "Mat::tail_cols(): size out of bounds");
-
- const uword start_col = n_cols - N;
-
- return subview<eT>(*this, 0, start_col, n_rows, N);
- }
- template<typename eT>
- inline
- const subview<eT>
- Mat<eT>::tail_cols(const uword N) const
- {
- arma_extra_debug_sigprint();
-
- arma_debug_check( (N > n_cols), "Mat::tail_cols(): size out of bounds");
-
- const uword start_col = n_cols - N;
-
- return subview<eT>(*this, 0, start_col, n_rows, N);
- }
- template<typename eT>
- template<typename T1>
- arma_inline
- subview_elem1<eT,T1>
- Mat<eT>::elem(const Base<uword,T1>& a)
- {
- arma_extra_debug_sigprint();
-
- return subview_elem1<eT,T1>(*this, a);
- }
- template<typename eT>
- template<typename T1>
- arma_inline
- const subview_elem1<eT,T1>
- Mat<eT>::elem(const Base<uword,T1>& a) const
- {
- arma_extra_debug_sigprint();
-
- return subview_elem1<eT,T1>(*this, a);
- }
- template<typename eT>
- template<typename T1>
- arma_inline
- subview_elem1<eT,T1>
- Mat<eT>::operator()(const Base<uword,T1>& a)
- {
- arma_extra_debug_sigprint();
-
- return subview_elem1<eT,T1>(*this, a);
- }
- template<typename eT>
- template<typename T1>
- arma_inline
- const subview_elem1<eT,T1>
- Mat<eT>::operator()(const Base<uword,T1>& a) const
- {
- arma_extra_debug_sigprint();
-
- return subview_elem1<eT,T1>(*this, a);
- }
- template<typename eT>
- template<typename T1, typename T2>
- arma_inline
- subview_elem2<eT,T1,T2>
- Mat<eT>::elem(const Base<uword,T1>& ri, const Base<uword,T2>& ci)
- {
- arma_extra_debug_sigprint();
-
- return subview_elem2<eT,T1,T2>(*this, ri, ci, false, false);
- }
- template<typename eT>
- template<typename T1, typename T2>
- arma_inline
- const subview_elem2<eT,T1,T2>
- Mat<eT>::elem(const Base<uword,T1>& ri, const Base<uword,T2>& ci) const
- {
- arma_extra_debug_sigprint();
-
- return subview_elem2<eT,T1,T2>(*this, ri, ci, false, false);
- }
- template<typename eT>
- template<typename T1, typename T2>
- arma_inline
- subview_elem2<eT,T1,T2>
- Mat<eT>::submat(const Base<uword,T1>& ri, const Base<uword,T2>& ci)
- {
- arma_extra_debug_sigprint();
-
- return subview_elem2<eT,T1,T2>(*this, ri, ci, false, false);
- }
- template<typename eT>
- template<typename T1, typename T2>
- arma_inline
- const subview_elem2<eT,T1,T2>
- Mat<eT>::submat(const Base<uword,T1>& ri, const Base<uword,T2>& ci) const
- {
- arma_extra_debug_sigprint();
-
- return subview_elem2<eT,T1,T2>(*this, ri, ci, false, false);
- }
- template<typename eT>
- template<typename T1, typename T2>
- arma_inline
- subview_elem2<eT,T1,T2>
- Mat<eT>::operator()(const Base<uword,T1>& ri, const Base<uword,T2>& ci)
- {
- arma_extra_debug_sigprint();
-
- return subview_elem2<eT,T1,T2>(*this, ri, ci, false, false);
- }
- template<typename eT>
- template<typename T1, typename T2>
- arma_inline
- const subview_elem2<eT,T1,T2>
- Mat<eT>::operator()(const Base<uword,T1>& ri, const Base<uword,T2>& ci) const
- {
- arma_extra_debug_sigprint();
-
- return subview_elem2<eT,T1,T2>(*this, ri, ci, false, false);
- }
- template<typename eT>
- template<typename T1>
- arma_inline
- subview_elem2<eT,T1,T1>
- Mat<eT>::rows(const Base<uword,T1>& ri)
- {
- arma_extra_debug_sigprint();
-
- return subview_elem2<eT,T1,T1>(*this, ri, ri, false, true);
- }
- template<typename eT>
- template<typename T1>
- arma_inline
- const subview_elem2<eT,T1,T1>
- Mat<eT>::rows(const Base<uword,T1>& ri) const
- {
- arma_extra_debug_sigprint();
-
- return subview_elem2<eT,T1,T1>(*this, ri, ri, false, true);
- }
- template<typename eT>
- template<typename T2>
- arma_inline
- subview_elem2<eT,T2,T2>
- Mat<eT>::cols(const Base<uword,T2>& ci)
- {
- arma_extra_debug_sigprint();
-
- return subview_elem2<eT,T2,T2>(*this, ci, ci, true, false);
- }
- template<typename eT>
- template<typename T2>
- arma_inline
- const subview_elem2<eT,T2,T2>
- Mat<eT>::cols(const Base<uword,T2>& ci) const
- {
- arma_extra_debug_sigprint();
-
- return subview_elem2<eT,T2,T2>(*this, ci, ci, true, false);
- }
- template<typename eT>
- arma_inline
- subview_each1< Mat<eT>, 0 >
- Mat<eT>::each_col()
- {
- arma_extra_debug_sigprint();
-
- return subview_each1< Mat<eT>, 0>(*this);
- }
- template<typename eT>
- arma_inline
- subview_each1< Mat<eT>, 1 >
- Mat<eT>::each_row()
- {
- arma_extra_debug_sigprint();
-
- return subview_each1< Mat<eT>, 1>(*this);
- }
- template<typename eT>
- arma_inline
- const subview_each1< Mat<eT>, 0 >
- Mat<eT>::each_col() const
- {
- arma_extra_debug_sigprint();
-
- return subview_each1< Mat<eT>, 0>(*this);
- }
- template<typename eT>
- arma_inline
- const subview_each1< Mat<eT>, 1 >
- Mat<eT>::each_row() const
- {
- arma_extra_debug_sigprint();
-
- return subview_each1< Mat<eT>, 1>(*this);
- }
- template<typename eT>
- template<typename T1>
- inline
- subview_each2< Mat<eT>, 0, T1 >
- Mat<eT>::each_col(const Base<uword, T1>& indices)
- {
- arma_extra_debug_sigprint();
-
- return subview_each2< Mat<eT>, 0, T1 >(*this, indices);
- }
- template<typename eT>
- template<typename T1>
- inline
- subview_each2< Mat<eT>, 1, T1 >
- Mat<eT>::each_row(const Base<uword, T1>& indices)
- {
- arma_extra_debug_sigprint();
-
- return subview_each2< Mat<eT>, 1, T1 >(*this, indices);
- }
- template<typename eT>
- template<typename T1>
- inline
- const subview_each2< Mat<eT>, 0, T1 >
- Mat<eT>::each_col(const Base<uword, T1>& indices) const
- {
- arma_extra_debug_sigprint();
-
- return subview_each2< Mat<eT>, 0, T1 >(*this, indices);
- }
- template<typename eT>
- template<typename T1>
- inline
- const subview_each2< Mat<eT>, 1, T1 >
- Mat<eT>::each_row(const Base<uword, T1>& indices) const
- {
- arma_extra_debug_sigprint();
-
- return subview_each2< Mat<eT>, 1, T1 >(*this, indices);
- }
- #if defined(ARMA_USE_CXX11)
-
- //! apply a lambda function to each column, where each column is interpreted as a column vector
- template<typename eT>
- inline
- const Mat<eT>&
- Mat<eT>::each_col(const std::function< void(Col<eT>&) >& F)
- {
- arma_extra_debug_sigprint();
-
- for(uword ii=0; ii < n_cols; ++ii)
- {
- Col<eT> tmp(colptr(ii), n_rows, false, true);
- F(tmp);
- }
-
- return *this;
- }
-
-
-
- template<typename eT>
- inline
- const Mat<eT>&
- Mat<eT>::each_col(const std::function< void(const Col<eT>&) >& F) const
- {
- arma_extra_debug_sigprint();
-
- for(uword ii=0; ii < n_cols; ++ii)
- {
- const Col<eT> tmp(const_cast<eT*>(colptr(ii)), n_rows, false, true);
- F(tmp);
- }
-
- return *this;
- }
-
-
-
- //! apply a lambda function to each row, where each row is interpreted as a row vector
- template<typename eT>
- inline
- const Mat<eT>&
- Mat<eT>::each_row(const std::function< void(Row<eT>&) >& F)
- {
- arma_extra_debug_sigprint();
-
- podarray<eT> array1(n_cols);
- podarray<eT> array2(n_cols);
-
- Row<eT> tmp1( array1.memptr(), n_cols, false, true );
- Row<eT> tmp2( array2.memptr(), n_cols, false, true );
-
- eT* tmp1_mem = tmp1.memptr();
- eT* tmp2_mem = tmp2.memptr();
-
- uword ii, jj;
-
- for(ii=0, jj=1; jj < n_rows; ii+=2, jj+=2)
- {
- for(uword col_id = 0; col_id < n_cols; ++col_id)
- {
- const eT* col_mem = colptr(col_id);
-
- tmp1_mem[col_id] = col_mem[ii];
- tmp2_mem[col_id] = col_mem[jj];
- }
-
- F(tmp1);
- F(tmp2);
-
- for(uword col_id = 0; col_id < n_cols; ++col_id)
- {
- eT* col_mem = colptr(col_id);
-
- col_mem[ii] = tmp1_mem[col_id];
- col_mem[jj] = tmp2_mem[col_id];
- }
- }
-
- if(ii < n_rows)
- {
- tmp1 = (*this).row(ii);
-
- F(tmp1);
-
- (*this).row(ii) = tmp1;
- }
-
- return *this;
- }
-
-
-
- template<typename eT>
- inline
- const Mat<eT>&
- Mat<eT>::each_row(const std::function< void(const Row<eT>&) >& F) const
- {
- arma_extra_debug_sigprint();
-
- podarray<eT> array1(n_cols);
- podarray<eT> array2(n_cols);
-
- Row<eT> tmp1( array1.memptr(), n_cols, false, true );
- Row<eT> tmp2( array2.memptr(), n_cols, false, true );
-
- eT* tmp1_mem = tmp1.memptr();
- eT* tmp2_mem = tmp2.memptr();
-
- uword ii, jj;
-
- for(ii=0, jj=1; jj < n_rows; ii+=2, jj+=2)
- {
- for(uword col_id = 0; col_id < n_cols; ++col_id)
- {
- const eT* col_mem = colptr(col_id);
-
- tmp1_mem[col_id] = col_mem[ii];
- tmp2_mem[col_id] = col_mem[jj];
- }
-
- F(tmp1);
- F(tmp2);
- }
-
- if(ii < n_rows)
- {
- tmp1 = (*this).row(ii);
-
- F(tmp1);
- }
-
- return *this;
- }
-
- #endif
- //! creation of diagview (diagonal)
- template<typename eT>
- arma_inline
- diagview<eT>
- Mat<eT>::diag(const sword in_id)
- {
- arma_extra_debug_sigprint();
-
- const uword row_offset = (in_id < 0) ? uword(-in_id) : 0;
- const uword col_offset = (in_id > 0) ? uword( in_id) : 0;
-
- arma_debug_check
- (
- ((row_offset > 0) && (row_offset >= n_rows)) || ((col_offset > 0) && (col_offset >= n_cols)),
- "Mat::diag(): requested diagonal out of bounds"
- );
-
- const uword len = (std::min)(n_rows - row_offset, n_cols - col_offset);
-
- return diagview<eT>(*this, row_offset, col_offset, len);
- }
- //! creation of diagview (diagonal)
- template<typename eT>
- arma_inline
- const diagview<eT>
- Mat<eT>::diag(const sword in_id) const
- {
- arma_extra_debug_sigprint();
-
- const uword row_offset = uword( (in_id < 0) ? -in_id : 0 );
- const uword col_offset = uword( (in_id > 0) ? in_id : 0 );
-
- arma_debug_check
- (
- ((row_offset > 0) && (row_offset >= n_rows)) || ((col_offset > 0) && (col_offset >= n_cols)),
- "Mat::diag(): requested diagonal out of bounds"
- );
-
- const uword len = (std::min)(n_rows - row_offset, n_cols - col_offset);
-
- return diagview<eT>(*this, row_offset, col_offset, len);
- }
- template<typename eT>
- inline
- void
- Mat<eT>::swap_rows(const uword in_row1, const uword in_row2)
- {
- arma_extra_debug_sigprint();
-
- const uword local_n_rows = n_rows;
- const uword local_n_cols = n_cols;
-
- arma_debug_check
- (
- (in_row1 >= local_n_rows) || (in_row2 >= local_n_rows),
- "Mat::swap_rows(): index out of bounds"
- );
-
- if(n_elem > 0)
- {
- for(uword ucol=0; ucol < local_n_cols; ++ucol)
- {
- const uword offset = ucol * local_n_rows;
- const uword pos1 = in_row1 + offset;
- const uword pos2 = in_row2 + offset;
-
- std::swap( access::rw(mem[pos1]), access::rw(mem[pos2]) );
- }
- }
- }
- template<typename eT>
- inline
- void
- Mat<eT>::swap_cols(const uword in_colA, const uword in_colB)
- {
- arma_extra_debug_sigprint();
-
- const uword local_n_rows = n_rows;
- const uword local_n_cols = n_cols;
-
- arma_debug_check
- (
- (in_colA >= local_n_cols) || (in_colB >= local_n_cols),
- "Mat::swap_cols(): index out of bounds"
- );
-
- if(n_elem > 0)
- {
- eT* ptrA = colptr(in_colA);
- eT* ptrB = colptr(in_colB);
-
- eT tmp_i;
- eT tmp_j;
-
- uword iq,jq;
- for(iq=0, jq=1; jq < local_n_rows; iq+=2, jq+=2)
- {
- tmp_i = ptrA[iq];
- tmp_j = ptrA[jq];
-
- ptrA[iq] = ptrB[iq];
- ptrA[jq] = ptrB[jq];
-
- ptrB[iq] = tmp_i;
- ptrB[jq] = tmp_j;
- }
-
- if(iq < local_n_rows)
- {
- std::swap( ptrA[iq], ptrB[iq] );
- }
- }
- }
- //! remove specified row
- template<typename eT>
- inline
- void
- Mat<eT>::shed_row(const uword row_num)
- {
- arma_extra_debug_sigprint();
-
- arma_debug_check( row_num >= n_rows, "Mat::shed_row(): index out of bounds");
-
- shed_rows(row_num, row_num);
- }
- //! remove specified column
- template<typename eT>
- inline
- void
- Mat<eT>::shed_col(const uword col_num)
- {
- arma_extra_debug_sigprint();
-
- arma_debug_check( col_num >= n_cols, "Mat::shed_col(): index out of bounds");
-
- shed_cols(col_num, col_num);
- }
- //! remove specified rows
- template<typename eT>
- inline
- void
- Mat<eT>::shed_rows(const uword in_row1, const uword in_row2)
- {
- arma_extra_debug_sigprint();
-
- arma_debug_check
- (
- (in_row1 > in_row2) || (in_row2 >= n_rows),
- "Mat::shed_rows(): indices out of bounds or incorrectly used"
- );
-
- const uword n_keep_front = in_row1;
- const uword n_keep_back = n_rows - (in_row2 + 1);
-
- Mat<eT> X(n_keep_front + n_keep_back, n_cols);
-
- if(n_keep_front > 0)
- {
- X.rows( 0, (n_keep_front-1) ) = rows( 0, (in_row1-1) );
- }
-
- if(n_keep_back > 0)
- {
- X.rows( n_keep_front, (n_keep_front+n_keep_back-1) ) = rows( (in_row2+1), (n_rows-1) );
- }
-
- steal_mem(X);
- }
- //! remove specified columns
- template<typename eT>
- inline
- void
- Mat<eT>::shed_cols(const uword in_col1, const uword in_col2)
- {
- arma_extra_debug_sigprint();
-
- arma_debug_check
- (
- (in_col1 > in_col2) || (in_col2 >= n_cols),
- "Mat::shed_cols(): indices out of bounds or incorrectly used"
- );
-
- const uword n_keep_front = in_col1;
- const uword n_keep_back = n_cols - (in_col2 + 1);
-
- Mat<eT> X(n_rows, n_keep_front + n_keep_back);
-
- if(n_keep_front > 0)
- {
- X.cols( 0, (n_keep_front-1) ) = cols( 0, (in_col1-1) );
- }
-
- if(n_keep_back > 0)
- {
- X.cols( n_keep_front, (n_keep_front+n_keep_back-1) ) = cols( (in_col2+1), (n_cols-1) );
- }
-
- steal_mem(X);
- }
- //! remove specified rows
- template<typename eT>
- template<typename T1>
- inline
- void
- Mat<eT>::shed_rows(const Base<uword, T1>& indices)
- {
- arma_extra_debug_sigprint();
-
- const unwrap_check_mixed<T1> U(indices.get_ref(), *this);
- const Mat<uword>& tmp1 = U.M;
-
- arma_debug_check( ((tmp1.is_vec() == false) && (tmp1.is_empty() == false)), "Mat::shed_rows(): list of indices must be a vector" );
-
- if(tmp1.is_empty()) { return; }
-
- const Col<uword> tmp2(const_cast<uword*>(tmp1.memptr()), tmp1.n_elem, false, false);
-
- const Col<uword>& rows_to_shed = (tmp2.is_sorted("strictascend") == false)
- ? Col<uword>(unique(tmp2))
- : Col<uword>(const_cast<uword*>(tmp2.memptr()), tmp2.n_elem, false, false);
-
- const uword* rows_to_shed_mem = rows_to_shed.memptr();
- const uword N = rows_to_shed.n_elem;
-
- if(arma_config::debug)
- {
- for(uword i=0; i<N; ++i)
- {
- arma_debug_check( (rows_to_shed_mem[i] >= n_rows), "Mat::shed_rows(): indices out of bounds" );
- }
- }
-
- Col<uword> tmp3(n_rows);
-
- uword* tmp3_mem = tmp3.memptr();
-
- uword i = 0;
- uword count = 0;
-
- for(uword j=0; j < n_rows; ++j)
- {
- if(i < N)
- {
- if( j != rows_to_shed_mem[i] )
- {
- tmp3_mem[count] = j;
- ++count;
- }
- else
- {
- ++i;
- }
- }
- else
- {
- tmp3_mem[count] = j;
- ++count;
- }
- }
-
- const Col<uword> rows_to_keep(tmp3.memptr(), count, false, false);
-
- Mat<eT> X = (*this).rows(rows_to_keep);
-
- steal_mem(X);
- }
- //! remove specified columns
- template<typename eT>
- template<typename T1>
- inline
- void
- Mat<eT>::shed_cols(const Base<uword, T1>& indices)
- {
- arma_extra_debug_sigprint();
-
- const unwrap_check_mixed<T1> U(indices.get_ref(), *this);
- const Mat<uword>& tmp1 = U.M;
-
- arma_debug_check( ((tmp1.is_vec() == false) && (tmp1.is_empty() == false)), "Mat::shed_cols(): list of indices must be a vector" );
-
- if(tmp1.is_empty()) { return; }
-
- const Col<uword> tmp2(const_cast<uword*>(tmp1.memptr()), tmp1.n_elem, false, false);
-
- const Col<uword>& cols_to_shed = (tmp2.is_sorted("strictascend") == false)
- ? Col<uword>(unique(tmp2))
- : Col<uword>(const_cast<uword*>(tmp2.memptr()), tmp2.n_elem, false, false);
-
- const uword* cols_to_shed_mem = cols_to_shed.memptr();
- const uword N = cols_to_shed.n_elem;
-
- if(arma_config::debug)
- {
- for(uword i=0; i<N; ++i)
- {
- arma_debug_check( (cols_to_shed_mem[i] >= n_cols), "Mat::shed_cols(): indices out of bounds" );
- }
- }
-
- Col<uword> tmp3(n_cols);
-
- uword* tmp3_mem = tmp3.memptr();
-
- uword i = 0;
- uword count = 0;
-
- for(uword j=0; j < n_cols; ++j)
- {
- if(i < N)
- {
- if( j != cols_to_shed_mem[i] )
- {
- tmp3_mem[count] = j;
- ++count;
- }
- else
- {
- ++i;
- }
- }
- else
- {
- tmp3_mem[count] = j;
- ++count;
- }
- }
-
- const Col<uword> cols_to_keep(tmp3.memptr(), count, false, false);
-
- Mat<eT> X = (*this).cols(cols_to_keep);
-
- steal_mem(X);
- }
- //! insert N rows at the specified row position,
- //! optionally setting the elements of the inserted rows to zero
- template<typename eT>
- inline
- void
- Mat<eT>::insert_rows(const uword row_num, const uword N, const bool set_to_zero)
- {
- arma_extra_debug_sigprint();
-
- const uword t_n_rows = n_rows;
- const uword t_n_cols = n_cols;
-
- const uword A_n_rows = row_num;
- const uword B_n_rows = t_n_rows - row_num;
-
- // insertion at row_num == n_rows is in effect an append operation
- arma_debug_check( (row_num > t_n_rows), "Mat::insert_rows(): index out of bounds");
-
- if(N > 0)
- {
- Mat<eT> out(t_n_rows + N, t_n_cols);
-
- if(A_n_rows > 0)
- {
- out.rows(0, A_n_rows-1) = rows(0, A_n_rows-1);
- }
-
- if(B_n_rows > 0)
- {
- out.rows(row_num + N, t_n_rows + N - 1) = rows(row_num, t_n_rows-1);
- }
-
- if(set_to_zero)
- {
- out.rows(row_num, row_num + N - 1).zeros();
- }
-
- steal_mem(out);
- }
- }
- //! insert N columns at the specified column position,
- //! optionally setting the elements of the inserted columns to zero
- template<typename eT>
- inline
- void
- Mat<eT>::insert_cols(const uword col_num, const uword N, const bool set_to_zero)
- {
- arma_extra_debug_sigprint();
-
- const uword t_n_rows = n_rows;
- const uword t_n_cols = n_cols;
-
- const uword A_n_cols = col_num;
- const uword B_n_cols = t_n_cols - col_num;
-
- // insertion at col_num == n_cols is in effect an append operation
- arma_debug_check( (col_num > t_n_cols), "Mat::insert_cols(): index out of bounds");
-
- if(N > 0)
- {
- Mat<eT> out(t_n_rows, t_n_cols + N);
-
- if(A_n_cols > 0)
- {
- out.cols(0, A_n_cols-1) = cols(0, A_n_cols-1);
- }
-
- if(B_n_cols > 0)
- {
- out.cols(col_num + N, t_n_cols + N - 1) = cols(col_num, t_n_cols-1);
- }
-
- if(set_to_zero)
- {
- out.cols(col_num, col_num + N - 1).zeros();
- }
-
- steal_mem(out);
- }
- }
- //! insert the given object at the specified row position;
- //! the given object must have the same number of columns as the matrix
- template<typename eT>
- template<typename T1>
- inline
- void
- Mat<eT>::insert_rows(const uword row_num, const Base<eT,T1>& X)
- {
- arma_extra_debug_sigprint();
-
- const unwrap<T1> tmp(X.get_ref());
- const Mat<eT>& C = tmp.M;
-
- const uword C_n_rows = C.n_rows;
- const uword C_n_cols = C.n_cols;
-
- const uword t_n_rows = n_rows;
- const uword t_n_cols = n_cols;
-
- const uword A_n_rows = row_num;
- const uword B_n_rows = t_n_rows - row_num;
-
- bool err_state = false;
- char* err_msg = 0;
-
- // insertion at row_num == n_rows is in effect an append operation
-
- arma_debug_set_error
- (
- err_state,
- err_msg,
- (row_num > t_n_rows),
- "Mat::insert_rows(): index out of bounds"
- );
-
- arma_debug_set_error
- (
- err_state,
- err_msg,
- ( (C_n_cols != t_n_cols) && ( (t_n_rows > 0) || (t_n_cols > 0) ) && ( (C_n_rows > 0) || (C_n_cols > 0) ) ),
- "Mat::insert_rows(): given object has an incompatible number of columns"
- );
-
- arma_debug_check(err_state, err_msg);
-
- if(C_n_rows > 0)
- {
- Mat<eT> out( t_n_rows + C_n_rows, (std::max)(t_n_cols, C_n_cols) );
-
- if(t_n_cols > 0)
- {
- if(A_n_rows > 0)
- {
- out.rows(0, A_n_rows-1) = rows(0, A_n_rows-1);
- }
-
- if( (t_n_cols > 0) && (B_n_rows > 0) )
- {
- out.rows(row_num + C_n_rows, t_n_rows + C_n_rows - 1) = rows(row_num, t_n_rows - 1);
- }
- }
-
- if(C_n_cols > 0)
- {
- out.rows(row_num, row_num + C_n_rows - 1) = C;
- }
-
- steal_mem(out);
- }
- }
- //! insert the given object at the specified column position;
- //! the given object must have the same number of rows as the matrix
- template<typename eT>
- template<typename T1>
- inline
- void
- Mat<eT>::insert_cols(const uword col_num, const Base<eT,T1>& X)
- {
- arma_extra_debug_sigprint();
-
- const unwrap<T1> tmp(X.get_ref());
- const Mat<eT>& C = tmp.M;
-
- const uword C_n_rows = C.n_rows;
- const uword C_n_cols = C.n_cols;
-
- const uword t_n_rows = n_rows;
- const uword t_n_cols = n_cols;
-
- const uword A_n_cols = col_num;
- const uword B_n_cols = t_n_cols - col_num;
-
- bool err_state = false;
- char* err_msg = 0;
-
- // insertion at col_num == n_cols is in effect an append operation
-
- arma_debug_set_error
- (
- err_state,
- err_msg,
- (col_num > t_n_cols),
- "Mat::insert_cols(): index out of bounds"
- );
-
- arma_debug_set_error
- (
- err_state,
- err_msg,
- ( (C_n_rows != t_n_rows) && ( (t_n_rows > 0) || (t_n_cols > 0) ) && ( (C_n_rows > 0) || (C_n_cols > 0) ) ),
- "Mat::insert_cols(): given object has an incompatible number of rows"
- );
-
- arma_debug_check(err_state, err_msg);
-
- if(C_n_cols > 0)
- {
- Mat<eT> out( (std::max)(t_n_rows, C_n_rows), t_n_cols + C_n_cols );
-
- if(t_n_rows > 0)
- {
- if(A_n_cols > 0)
- {
- out.cols(0, A_n_cols-1) = cols(0, A_n_cols-1);
- }
-
- if(B_n_cols > 0)
- {
- out.cols(col_num + C_n_cols, t_n_cols + C_n_cols - 1) = cols(col_num, t_n_cols - 1);
- }
- }
-
- if(C_n_rows > 0)
- {
- out.cols(col_num, col_num + C_n_cols - 1) = C;
- }
-
- steal_mem(out);
- }
- }
- template<typename eT>
- template<typename T1, typename gen_type>
- inline
- Mat<eT>::Mat(const Gen<T1, gen_type>& X)
- : n_rows(X.n_rows)
- , n_cols(X.n_cols)
- , n_elem(n_rows*n_cols)
- , vec_state(0)
- , mem_state(0)
- , mem()
- {
- arma_extra_debug_sigprint_this(this);
-
- arma_type_check(( is_same_type< eT, typename T1::elem_type >::no ));
-
- init_cold();
-
- X.apply(*this);
- }
- template<typename eT>
- template<typename T1, typename gen_type>
- inline
- Mat<eT>&
- Mat<eT>::operator=(const Gen<T1, gen_type>& X)
- {
- arma_extra_debug_sigprint();
-
- arma_type_check(( is_same_type< eT, typename T1::elem_type >::no ));
-
- init_warm(X.n_rows, X.n_cols);
-
- X.apply(*this);
-
- return *this;
- }
- template<typename eT>
- template<typename T1, typename gen_type>
- inline
- Mat<eT>&
- Mat<eT>::operator+=(const Gen<T1, gen_type>& X)
- {
- arma_extra_debug_sigprint();
-
- arma_type_check(( is_same_type< eT, typename T1::elem_type >::no ));
-
- X.apply_inplace_plus(*this);
-
- return *this;
- }
- template<typename eT>
- template<typename T1, typename gen_type>
- inline
- Mat<eT>&
- Mat<eT>::operator-=(const Gen<T1, gen_type>& X)
- {
- arma_extra_debug_sigprint();
-
- arma_type_check(( is_same_type< eT, typename T1::elem_type >::no ));
-
- X.apply_inplace_minus(*this);
-
- return *this;
- }
- template<typename eT>
- template<typename T1, typename gen_type>
- inline
- Mat<eT>&
- Mat<eT>::operator*=(const Gen<T1, gen_type>& X)
- {
- arma_extra_debug_sigprint();
-
- arma_type_check(( is_same_type< eT, typename T1::elem_type >::no ));
-
- const Mat<eT> tmp(X);
-
- return (*this).operator*=(tmp);
- }
- template<typename eT>
- template<typename T1, typename gen_type>
- inline
- Mat<eT>&
- Mat<eT>::operator%=(const Gen<T1, gen_type>& X)
- {
- arma_extra_debug_sigprint();
-
- arma_type_check(( is_same_type< eT, typename T1::elem_type >::no ));
-
- X.apply_inplace_schur(*this);
-
- return *this;
- }
- template<typename eT>
- template<typename T1, typename gen_type>
- inline
- Mat<eT>&
- Mat<eT>::operator/=(const Gen<T1, gen_type>& X)
- {
- arma_extra_debug_sigprint();
-
- arma_type_check(( is_same_type< eT, typename T1::elem_type >::no ));
-
- X.apply_inplace_div(*this);
-
- return *this;
- }
- //! create a matrix from Op, i.e. run the previously delayed unary operations
- template<typename eT>
- template<typename T1, typename op_type>
- inline
- Mat<eT>::Mat(const Op<T1, op_type>& X)
- : n_rows(0)
- , n_cols(0)
- , n_elem(0)
- , vec_state(0)
- , mem_state(0)
- , mem()
- {
- arma_extra_debug_sigprint_this(this);
- arma_type_check(( is_same_type< eT, typename T1::elem_type >::no ));
-
- op_type::apply(*this, X);
- }
- //! create a matrix from Op, i.e. run the previously delayed unary operations
- template<typename eT>
- template<typename T1, typename op_type>
- inline
- Mat<eT>&
- Mat<eT>::operator=(const Op<T1, op_type>& X)
- {
- arma_extra_debug_sigprint();
- arma_type_check(( is_same_type< eT, typename T1::elem_type >::no ));
-
- op_type::apply(*this, X);
-
- return *this;
- }
- //! in-place matrix addition, with the right-hand-side operand having delayed operations
- template<typename eT>
- template<typename T1, typename op_type>
- inline
- Mat<eT>&
- Mat<eT>::operator+=(const Op<T1, op_type>& X)
- {
- arma_extra_debug_sigprint();
-
- arma_type_check(( is_same_type< eT, typename T1::elem_type >::no ));
-
- const Mat<eT> m(X);
-
- return (*this).operator+=(m);
- }
- //! in-place matrix subtraction, with the right-hand-side operand having delayed operations
- template<typename eT>
- template<typename T1, typename op_type>
- inline
- Mat<eT>&
- Mat<eT>::operator-=(const Op<T1, op_type>& X)
- {
- arma_extra_debug_sigprint();
-
- arma_type_check(( is_same_type< eT, typename T1::elem_type >::no ));
-
- const Mat<eT> m(X);
-
- return (*this).operator-=(m);
- }
- //! in-place matrix multiplication, with the right-hand-side operand having delayed operations
- template<typename eT>
- template<typename T1, typename op_type>
- inline
- Mat<eT>&
- Mat<eT>::operator*=(const Op<T1, op_type>& X)
- {
- arma_extra_debug_sigprint();
-
- arma_type_check(( is_same_type< eT, typename T1::elem_type >::no ));
-
- glue_times::apply_inplace(*this, X);
-
- return *this;
- }
- //! in-place matrix element-wise multiplication, with the right-hand-side operand having delayed operations
- template<typename eT>
- template<typename T1, typename op_type>
- inline
- Mat<eT>&
- Mat<eT>::operator%=(const Op<T1, op_type>& X)
- {
- arma_extra_debug_sigprint();
-
- arma_type_check(( is_same_type< eT, typename T1::elem_type >::no ));
-
- const Mat<eT> m(X);
-
- return (*this).operator%=(m);
- }
- //! in-place matrix element-wise division, with the right-hand-side operand having delayed operations
- template<typename eT>
- template<typename T1, typename op_type>
- inline
- Mat<eT>&
- Mat<eT>::operator/=(const Op<T1, op_type>& X)
- {
- arma_extra_debug_sigprint();
-
- arma_type_check(( is_same_type< eT, typename T1::elem_type >::no ));
-
- const Mat<eT> m(X);
-
- return (*this).operator/=(m);
- }
- //! create a matrix from eOp, i.e. run the previously delayed unary operations
- template<typename eT>
- template<typename T1, typename eop_type>
- inline
- Mat<eT>::Mat(const eOp<T1, eop_type>& X)
- : n_rows(X.get_n_rows())
- , n_cols(X.get_n_cols())
- , n_elem(X.get_n_elem())
- , vec_state(0)
- , mem_state(0)
- , mem()
- {
- arma_extra_debug_sigprint_this(this);
-
- arma_type_check(( is_same_type< eT, typename T1::elem_type >::no ));
-
- init_cold();
-
- eop_type::apply(*this, X);
- }
- //! create a matrix from eOp, i.e. run the previously delayed unary operations
- template<typename eT>
- template<typename T1, typename eop_type>
- inline
- Mat<eT>&
- Mat<eT>::operator=(const eOp<T1, eop_type>& X)
- {
- arma_extra_debug_sigprint();
-
- arma_type_check(( is_same_type< eT, typename T1::elem_type >::no ));
-
- const bool bad_alias = (eOp<T1, eop_type>::proxy_type::has_subview && X.P.is_alias(*this));
-
- if(bad_alias == false)
- {
- init_warm(X.get_n_rows(), X.get_n_cols());
-
- eop_type::apply(*this, X);
- }
- else
- {
- arma_extra_debug_print("bad_alias = true");
-
- Mat<eT> tmp(X);
-
- steal_mem(tmp);
- }
-
- return *this;
- }
- template<typename eT>
- template<typename T1, typename eop_type>
- inline
- Mat<eT>&
- Mat<eT>::operator+=(const eOp<T1, eop_type>& X)
- {
- arma_extra_debug_sigprint();
- arma_type_check(( is_same_type< eT, typename T1::elem_type >::no ));
-
- eop_type::apply_inplace_plus(*this, X);
-
- return *this;
- }
- template<typename eT>
- template<typename T1, typename eop_type>
- inline
- Mat<eT>&
- Mat<eT>::operator-=(const eOp<T1, eop_type>& X)
- {
- arma_extra_debug_sigprint();
- arma_type_check(( is_same_type< eT, typename T1::elem_type >::no ));
-
- eop_type::apply_inplace_minus(*this, X);
-
- return *this;
- }
- template<typename eT>
- template<typename T1, typename eop_type>
- inline
- Mat<eT>&
- Mat<eT>::operator*=(const eOp<T1, eop_type>& X)
- {
- arma_extra_debug_sigprint();
-
- arma_type_check(( is_same_type< eT, typename T1::elem_type >::no ));
-
- glue_times::apply_inplace(*this, X);
-
- return *this;
- }
- template<typename eT>
- template<typename T1, typename eop_type>
- inline
- Mat<eT>&
- Mat<eT>::operator%=(const eOp<T1, eop_type>& X)
- {
- arma_extra_debug_sigprint();
- arma_type_check(( is_same_type< eT, typename T1::elem_type >::no ));
-
- eop_type::apply_inplace_schur(*this, X);
-
- return *this;
- }
- template<typename eT>
- template<typename T1, typename eop_type>
- inline
- Mat<eT>&
- Mat<eT>::operator/=(const eOp<T1, eop_type>& X)
- {
- arma_extra_debug_sigprint();
- arma_type_check(( is_same_type< eT, typename T1::elem_type >::no ));
-
- eop_type::apply_inplace_div(*this, X);
-
- return *this;
- }
- template<typename eT>
- template<typename T1, typename op_type>
- inline
- Mat<eT>::Mat(const mtOp<eT, T1, op_type>& X)
- : n_rows(0)
- , n_cols(0)
- , n_elem(0)
- , vec_state(0)
- , mem_state(0)
- , mem()
- {
- arma_extra_debug_sigprint_this(this);
-
- op_type::apply(*this, X);
- }
- template<typename eT>
- template<typename T1, typename op_type>
- inline
- Mat<eT>&
- Mat<eT>::operator=(const mtOp<eT, T1, op_type>& X)
- {
- arma_extra_debug_sigprint();
-
- op_type::apply(*this, X);
-
- return *this;
- }
- template<typename eT>
- template<typename T1, typename op_type>
- inline
- Mat<eT>&
- Mat<eT>::operator+=(const mtOp<eT, T1, op_type>& X)
- {
- arma_extra_debug_sigprint();
-
- const Mat<eT> m(X);
-
- return (*this).operator+=(m);
- }
- template<typename eT>
- template<typename T1, typename op_type>
- inline
- Mat<eT>&
- Mat<eT>::operator-=(const mtOp<eT, T1, op_type>& X)
- {
- arma_extra_debug_sigprint();
-
- const Mat<eT> m(X);
-
- return (*this).operator-=(m);
- }
- template<typename eT>
- template<typename T1, typename op_type>
- inline
- Mat<eT>&
- Mat<eT>::operator*=(const mtOp<eT, T1, op_type>& X)
- {
- arma_extra_debug_sigprint();
-
- const Mat<eT> m(X);
-
- return (*this).operator*=(m);
- }
- template<typename eT>
- template<typename T1, typename op_type>
- inline
- Mat<eT>&
- Mat<eT>::operator%=(const mtOp<eT, T1, op_type>& X)
- {
- arma_extra_debug_sigprint();
-
- const Mat<eT> m(X);
-
- return (*this).operator%=(m);
- }
- template<typename eT>
- template<typename T1, typename op_type>
- inline
- Mat<eT>&
- Mat<eT>::operator/=(const mtOp<eT, T1, op_type>& X)
- {
- arma_extra_debug_sigprint();
-
- const Mat<eT> m(X);
-
- return (*this).operator/=(m);
- }
- template<typename eT>
- template<typename T1, typename op_type>
- inline
- Mat<eT>::Mat(const CubeToMatOp<T1, op_type>& X)
- : n_rows(0)
- , n_cols(0)
- , n_elem(0)
- , vec_state(0)
- , mem_state(0)
- , mem()
- {
- arma_extra_debug_sigprint_this(this);
- arma_type_check(( is_same_type< eT, typename T1::elem_type >::no ));
- op_type::apply(*this, X);
- }
- template<typename eT>
- template<typename T1, typename op_type>
- inline
- Mat<eT>&
- Mat<eT>::operator=(const CubeToMatOp<T1, op_type>& X)
- {
- arma_extra_debug_sigprint();
- arma_type_check(( is_same_type< eT, typename T1::elem_type >::no ));
-
- op_type::apply(*this, X);
-
- return *this;
- }
- template<typename eT>
- template<typename T1, typename op_type>
- inline
- Mat<eT>&
- Mat<eT>::operator+=(const CubeToMatOp<T1, op_type>& X)
- {
- arma_extra_debug_sigprint();
-
- arma_type_check(( is_same_type< eT, typename T1::elem_type >::no ));
-
- (*this) = (*this) + X;
-
- return (*this);
- }
- template<typename eT>
- template<typename T1, typename op_type>
- inline
- Mat<eT>&
- Mat<eT>::operator-=(const CubeToMatOp<T1, op_type>& X)
- {
- arma_extra_debug_sigprint();
-
- arma_type_check(( is_same_type< eT, typename T1::elem_type >::no ));
-
- (*this) = (*this) - X;
-
- return (*this);
- }
- template<typename eT>
- template<typename T1, typename op_type>
- inline
- Mat<eT>&
- Mat<eT>::operator*=(const CubeToMatOp<T1, op_type>& X)
- {
- arma_extra_debug_sigprint();
-
- arma_type_check(( is_same_type< eT, typename T1::elem_type >::no ));
-
- glue_times::apply_inplace(*this, X);
-
- return *this;
- }
- template<typename eT>
- template<typename T1, typename op_type>
- inline
- Mat<eT>&
- Mat<eT>::operator%=(const CubeToMatOp<T1, op_type>& X)
- {
- arma_extra_debug_sigprint();
-
- arma_type_check(( is_same_type< eT, typename T1::elem_type >::no ));
-
- (*this) = (*this) % X;
-
- return (*this);
- }
- template<typename eT>
- template<typename T1, typename op_type>
- inline
- Mat<eT>&
- Mat<eT>::operator/=(const CubeToMatOp<T1, op_type>& X)
- {
- arma_extra_debug_sigprint();
-
- arma_type_check(( is_same_type< eT, typename T1::elem_type >::no ));
-
- (*this) = (*this) / X;
-
- return (*this);
- }
- template<typename eT>
- template<typename T1, typename op_type>
- inline
- Mat<eT>::Mat(const SpToDOp<T1, op_type>& X)
- : n_rows(0)
- , n_cols(0)
- , n_elem(0)
- , vec_state(0)
- , mem_state(0)
- , mem()
- {
- arma_extra_debug_sigprint_this(this);
- arma_type_check(( is_same_type< eT, typename T1::elem_type >::no ));
- op_type::apply(*this, X);
- }
- //! create a matrix from an SpToDOp, i.e. run the previously delayed unary operations
- template<typename eT>
- template<typename T1, typename op_type>
- inline
- Mat<eT>&
- Mat<eT>::operator=(const SpToDOp<T1, op_type>& X)
- {
- arma_extra_debug_sigprint();
- arma_type_check(( is_same_type< eT, typename T1::elem_type >::no ));
-
- op_type::apply(*this, X);
-
- return *this;
- }
- //! in-place matrix addition, with the right-hand-side operand having delayed operations
- template<typename eT>
- template<typename T1, typename op_type>
- inline
- Mat<eT>&
- Mat<eT>::operator+=(const SpToDOp<T1, op_type>& X)
- {
- arma_extra_debug_sigprint();
-
- arma_type_check(( is_same_type< eT, typename T1::elem_type >::no ));
-
- const Mat<eT> m(X);
-
- return (*this).operator+=(m);
- }
- //! in-place matrix subtraction, with the right-hand-side operand having delayed operations
- template<typename eT>
- template<typename T1, typename op_type>
- inline
- Mat<eT>&
- Mat<eT>::operator-=(const SpToDOp<T1, op_type>& X)
- {
- arma_extra_debug_sigprint();
-
- arma_type_check(( is_same_type< eT, typename T1::elem_type >::no ));
-
- const Mat<eT> m(X);
-
- return (*this).operator-=(m);
- }
- //! in-place matrix multiplication, with the right-hand-side operand having delayed operations
- template<typename eT>
- template<typename T1, typename op_type>
- inline
- Mat<eT>&
- Mat<eT>::operator*=(const SpToDOp<T1, op_type>& X)
- {
- arma_extra_debug_sigprint();
-
- arma_type_check(( is_same_type< eT, typename T1::elem_type >::no ));
-
- glue_times::apply_inplace(*this, X);
-
- return *this;
- }
- //! in-place matrix element-wise multiplication, with the right-hand-side operand having delayed operations
- template<typename eT>
- template<typename T1, typename op_type>
- inline
- Mat<eT>&
- Mat<eT>::operator%=(const SpToDOp<T1, op_type>& X)
- {
- arma_extra_debug_sigprint();
-
- arma_type_check(( is_same_type< eT, typename T1::elem_type >::no ));
-
- const Mat<eT> m(X);
-
- return (*this).operator%=(m);
- }
- //! in-place matrix element-wise division, with the right-hand-side operand having delayed operations
- template<typename eT>
- template<typename T1, typename op_type>
- inline
- Mat<eT>&
- Mat<eT>::operator/=(const SpToDOp<T1, op_type>& X)
- {
- arma_extra_debug_sigprint();
-
- arma_type_check(( is_same_type< eT, typename T1::elem_type >::no ));
-
- const Mat<eT> m(X);
-
- return (*this).operator/=(m);
- }
- //! create a matrix from Glue, i.e. run the previously delayed binary operations
- template<typename eT>
- template<typename T1, typename T2, typename glue_type>
- inline
- Mat<eT>::Mat(const Glue<T1, T2, glue_type>& X)
- : n_rows(0)
- , n_cols(0)
- , n_elem(0)
- , vec_state(0)
- , mem_state(0)
- , mem()
- {
- arma_extra_debug_sigprint_this(this);
-
- arma_type_check(( is_same_type< eT, typename T1::elem_type >::no ));
- arma_type_check(( is_same_type< eT, typename T2::elem_type >::no ));
-
- glue_type::apply(*this, X);
- }
- //! create a matrix from Glue, i.e. run the previously delayed binary operations
- template<typename eT>
- template<typename T1, typename T2, typename glue_type>
- inline
- Mat<eT>&
- Mat<eT>::operator=(const Glue<T1, T2, glue_type>& X)
- {
- arma_extra_debug_sigprint();
-
- arma_type_check(( is_same_type< eT, typename T1::elem_type >::no ));
- arma_type_check(( is_same_type< eT, typename T2::elem_type >::no ));
-
- glue_type::apply(*this, X);
-
- return *this;
- }
- //! in-place matrix addition, with the right-hand-side operands having delayed operations
- template<typename eT>
- template<typename T1, typename T2, typename glue_type>
- inline
- Mat<eT>&
- Mat<eT>::operator+=(const Glue<T1, T2, glue_type>& X)
- {
- arma_extra_debug_sigprint();
-
- arma_type_check(( is_same_type< eT, typename T1::elem_type >::no ));
- arma_type_check(( is_same_type< eT, typename T2::elem_type >::no ));
-
- const Mat<eT> m(X);
-
- return (*this).operator+=(m);
- }
- //! in-place matrix subtraction, with the right-hand-side operands having delayed operations
- template<typename eT>
- template<typename T1, typename T2, typename glue_type>
- inline
- Mat<eT>&
- Mat<eT>::operator-=(const Glue<T1, T2, glue_type>& X)
- {
- arma_extra_debug_sigprint();
-
- arma_type_check(( is_same_type< eT, typename T1::elem_type >::no ));
- arma_type_check(( is_same_type< eT, typename T2::elem_type >::no ));
-
- const Mat<eT> m(X);
-
- return (*this).operator-=(m);
- }
- //! in-place matrix multiplications, with the right-hand-side operands having delayed operations
- template<typename eT>
- template<typename T1, typename T2, typename glue_type>
- inline
- Mat<eT>&
- Mat<eT>::operator*=(const Glue<T1, T2, glue_type>& X)
- {
- arma_extra_debug_sigprint();
-
- arma_type_check(( is_same_type< eT, typename T1::elem_type >::no ));
- arma_type_check(( is_same_type< eT, typename T2::elem_type >::no ));
-
- glue_times::apply_inplace(*this, X);
-
- return *this;
- }
- //! in-place matrix element-wise multiplication, with the right-hand-side operands having delayed operations
- template<typename eT>
- template<typename T1, typename T2, typename glue_type>
- inline
- Mat<eT>&
- Mat<eT>::operator%=(const Glue<T1, T2, glue_type>& X)
- {
- arma_extra_debug_sigprint();
-
- arma_type_check(( is_same_type< eT, typename T1::elem_type >::no ));
- arma_type_check(( is_same_type< eT, typename T2::elem_type >::no ));
-
- const Mat<eT> m(X);
-
- return (*this).operator%=(m);
- }
- //! in-place matrix element-wise division, with the right-hand-side operands having delayed operations
- template<typename eT>
- template<typename T1, typename T2, typename glue_type>
- inline
- Mat<eT>&
- Mat<eT>::operator/=(const Glue<T1, T2, glue_type>& X)
- {
- arma_extra_debug_sigprint();
-
- arma_type_check(( is_same_type< eT, typename T1::elem_type >::no ));
- arma_type_check(( is_same_type< eT, typename T2::elem_type >::no ));
-
- const Mat<eT> m(X);
-
- return (*this).operator/=(m);
- }
- template<typename eT>
- template<typename T1, typename T2>
- inline
- Mat<eT>&
- Mat<eT>::operator+=(const Glue<T1, T2, glue_times>& X)
- {
- arma_extra_debug_sigprint();
-
- glue_times::apply_inplace_plus(*this, X, sword(+1));
-
- return *this;
- }
- template<typename eT>
- template<typename T1, typename T2>
- inline
- Mat<eT>&
- Mat<eT>::operator-=(const Glue<T1, T2, glue_times>& X)
- {
- arma_extra_debug_sigprint();
-
- glue_times::apply_inplace_plus(*this, X, sword(-1));
-
- return *this;
- }
- //! create a matrix from eGlue, i.e. run the previously delayed binary operations
- template<typename eT>
- template<typename T1, typename T2, typename eglue_type>
- inline
- Mat<eT>::Mat(const eGlue<T1, T2, eglue_type>& X)
- : n_rows(X.get_n_rows())
- , n_cols(X.get_n_cols())
- , n_elem(X.get_n_elem())
- , vec_state(0)
- , mem_state(0)
- , mem()
- {
- arma_extra_debug_sigprint_this(this);
-
- arma_type_check(( is_same_type< eT, typename T1::elem_type >::no ));
- arma_type_check(( is_same_type< eT, typename T2::elem_type >::no ));
-
- init_cold();
-
- eglue_type::apply(*this, X);
- }
- //! create a matrix from eGlue, i.e. run the previously delayed binary operations
- template<typename eT>
- template<typename T1, typename T2, typename eglue_type>
- inline
- Mat<eT>&
- Mat<eT>::operator=(const eGlue<T1, T2, eglue_type>& X)
- {
- arma_extra_debug_sigprint();
-
- arma_type_check(( is_same_type< eT, typename T1::elem_type >::no ));
- arma_type_check(( is_same_type< eT, typename T2::elem_type >::no ));
-
- const bool bad_alias =
- (
- (eGlue<T1, T2, eglue_type>::proxy1_type::has_subview && X.P1.is_alias(*this))
- ||
- (eGlue<T1, T2, eglue_type>::proxy2_type::has_subview && X.P2.is_alias(*this))
- );
-
- if(bad_alias == false)
- {
- init_warm(X.get_n_rows(), X.get_n_cols());
-
- eglue_type::apply(*this, X);
- }
- else
- {
- arma_extra_debug_print("bad_alias = true");
-
- Mat<eT> tmp(X);
-
- steal_mem(tmp);
- }
-
- return *this;
- }
- //! in-place matrix addition, with the right-hand-side operands having delayed operations
- template<typename eT>
- template<typename T1, typename T2, typename eglue_type>
- inline
- Mat<eT>&
- Mat<eT>::operator+=(const eGlue<T1, T2, eglue_type>& X)
- {
- arma_extra_debug_sigprint();
-
- arma_type_check(( is_same_type< eT, typename T1::elem_type >::no ));
- arma_type_check(( is_same_type< eT, typename T2::elem_type >::no ));
-
- eglue_type::apply_inplace_plus(*this, X);
-
- return *this;
- }
- //! in-place matrix subtraction, with the right-hand-side operands having delayed operations
- template<typename eT>
- template<typename T1, typename T2, typename eglue_type>
- inline
- Mat<eT>&
- Mat<eT>::operator-=(const eGlue<T1, T2, eglue_type>& X)
- {
- arma_extra_debug_sigprint();
-
- arma_type_check(( is_same_type< eT, typename T1::elem_type >::no ));
- arma_type_check(( is_same_type< eT, typename T2::elem_type >::no ));
-
- eglue_type::apply_inplace_minus(*this, X);
-
- return *this;
- }
- template<typename eT>
- template<typename T1, typename T2, typename eglue_type>
- inline
- Mat<eT>&
- Mat<eT>::operator*=(const eGlue<T1, T2, eglue_type>& X)
- {
- arma_extra_debug_sigprint();
-
- arma_type_check(( is_same_type< eT, typename T1::elem_type >::no ));
- arma_type_check(( is_same_type< eT, typename T2::elem_type >::no ));
-
- glue_times::apply_inplace(*this, X);
- return *this;
- }
- template<typename eT>
- template<typename T1, typename T2, typename eglue_type>
- inline
- Mat<eT>&
- Mat<eT>::operator%=(const eGlue<T1, T2, eglue_type>& X)
- {
- arma_extra_debug_sigprint();
-
- arma_type_check(( is_same_type< eT, typename T1::elem_type >::no ));
- arma_type_check(( is_same_type< eT, typename T2::elem_type >::no ));
-
- eglue_type::apply_inplace_schur(*this, X);
- return *this;
- }
- template<typename eT>
- template<typename T1, typename T2, typename eglue_type>
- inline
- Mat<eT>&
- Mat<eT>::operator/=(const eGlue<T1, T2, eglue_type>& X)
- {
- arma_extra_debug_sigprint();
-
- arma_type_check(( is_same_type< eT, typename T1::elem_type >::no ));
- arma_type_check(( is_same_type< eT, typename T2::elem_type >::no ));
-
- eglue_type::apply_inplace_div(*this, X);
- return *this;
- }
- template<typename eT>
- template<typename T1, typename T2, typename glue_type>
- inline
- Mat<eT>::Mat(const mtGlue<eT, T1, T2, glue_type>& X)
- : n_rows(0)
- , n_cols(0)
- , n_elem(0)
- , vec_state(0)
- , mem_state(0)
- , mem()
- {
- arma_extra_debug_sigprint_this(this);
-
- glue_type::apply(*this, X);
- }
- template<typename eT>
- template<typename T1, typename T2, typename glue_type>
- inline
- Mat<eT>&
- Mat<eT>::operator=(const mtGlue<eT, T1, T2, glue_type>& X)
- {
- arma_extra_debug_sigprint();
-
- glue_type::apply(*this, X);
-
- return *this;
- }
- template<typename eT>
- template<typename T1, typename T2, typename glue_type>
- inline
- Mat<eT>&
- Mat<eT>::operator+=(const mtGlue<eT, T1, T2, glue_type>& X)
- {
- arma_extra_debug_sigprint();
-
- const Mat<eT> m(X);
-
- return (*this).operator+=(m);
- }
- template<typename eT>
- template<typename T1, typename T2, typename glue_type>
- inline
- Mat<eT>&
- Mat<eT>::operator-=(const mtGlue<eT, T1, T2, glue_type>& X)
- {
- arma_extra_debug_sigprint();
-
- const Mat<eT> m(X);
-
- return (*this).operator-=(m);
- }
- template<typename eT>
- template<typename T1, typename T2, typename glue_type>
- inline
- Mat<eT>&
- Mat<eT>::operator*=(const mtGlue<eT, T1, T2, glue_type>& X)
- {
- arma_extra_debug_sigprint();
-
- const Mat<eT> m(X);
-
- glue_times::apply_inplace(*this, m);
-
- return *this;
- }
- template<typename eT>
- template<typename T1, typename T2, typename glue_type>
- inline
- Mat<eT>&
- Mat<eT>::operator%=(const mtGlue<eT, T1, T2, glue_type>& X)
- {
- arma_extra_debug_sigprint();
-
- const Mat<eT> m(X);
-
- return (*this).operator%=(m);
- }
- template<typename eT>
- template<typename T1, typename T2, typename glue_type>
- inline
- Mat<eT>&
- Mat<eT>::operator/=(const mtGlue<eT, T1, T2, glue_type>& X)
- {
- arma_extra_debug_sigprint();
-
- const Mat<eT> m(X);
-
- return (*this).operator/=(m);
- }
- //! linear element accessor (treats the matrix as a vector); no bounds check; assumes memory is aligned
- template<typename eT>
- arma_inline
- arma_warn_unused
- const eT&
- Mat<eT>::at_alt(const uword ii) const
- {
- const eT* mem_aligned = mem;
- memory::mark_as_aligned(mem_aligned);
-
- return mem_aligned[ii];
- }
- //! linear element accessor (treats the matrix as a vector); bounds checking not done when ARMA_NO_DEBUG is defined
- template<typename eT>
- arma_inline
- arma_warn_unused
- eT&
- Mat<eT>::operator() (const uword ii)
- {
- arma_debug_check( (ii >= n_elem), "Mat::operator(): index out of bounds");
- return access::rw(mem[ii]);
- }
- //! linear element accessor (treats the matrix as a vector); bounds checking not done when ARMA_NO_DEBUG is defined
- template<typename eT>
- arma_inline
- arma_warn_unused
- const eT&
- Mat<eT>::operator() (const uword ii) const
- {
- arma_debug_check( (ii >= n_elem), "Mat::operator(): index out of bounds");
- return mem[ii];
- }
- //! linear element accessor (treats the matrix as a vector); no bounds check.
- template<typename eT>
- arma_inline
- arma_warn_unused
- eT&
- Mat<eT>::operator[] (const uword ii)
- {
- return access::rw(mem[ii]);
- }
- //! linear element accessor (treats the matrix as a vector); no bounds check
- template<typename eT>
- arma_inline
- arma_warn_unused
- const eT&
- Mat<eT>::operator[] (const uword ii) const
- {
- return mem[ii];
- }
- //! linear element accessor (treats the matrix as a vector); no bounds check.
- template<typename eT>
- arma_inline
- arma_warn_unused
- eT&
- Mat<eT>::at(const uword ii)
- {
- return access::rw(mem[ii]);
- }
- //! linear element accessor (treats the matrix as a vector); no bounds check
- template<typename eT>
- arma_inline
- arma_warn_unused
- const eT&
- Mat<eT>::at(const uword ii) const
- {
- return mem[ii];
- }
- //! element accessor; bounds checking not done when ARMA_NO_DEBUG is defined
- template<typename eT>
- arma_inline
- arma_warn_unused
- eT&
- Mat<eT>::operator() (const uword in_row, const uword in_col)
- {
- arma_debug_check( ((in_row >= n_rows) || (in_col >= n_cols)), "Mat::operator(): index out of bounds");
- return access::rw(mem[in_row + in_col*n_rows]);
- }
- //! element accessor; bounds checking not done when ARMA_NO_DEBUG is defined
- template<typename eT>
- arma_inline
- arma_warn_unused
- const eT&
- Mat<eT>::operator() (const uword in_row, const uword in_col) const
- {
- arma_debug_check( ((in_row >= n_rows) || (in_col >= n_cols)), "Mat::operator(): index out of bounds");
- return mem[in_row + in_col*n_rows];
- }
- //! element accessor; no bounds check
- template<typename eT>
- arma_inline
- arma_warn_unused
- eT&
- Mat<eT>::at(const uword in_row, const uword in_col)
- {
- return access::rw( mem[in_row + in_col*n_rows] );
- }
- //! element accessor; no bounds check
- template<typename eT>
- arma_inline
- arma_warn_unused
- const eT&
- Mat<eT>::at(const uword in_row, const uword in_col) const
- {
- return mem[in_row + in_col*n_rows];
- }
- //! prefix ++
- template<typename eT>
- arma_inline
- const Mat<eT>&
- Mat<eT>::operator++()
- {
- Mat_aux::prefix_pp(*this);
- return *this;
- }
- //! postfix ++ (must not return the object by reference)
- template<typename eT>
- arma_inline
- void
- Mat<eT>::operator++(int)
- {
- Mat_aux::postfix_pp(*this);
- }
- //! prefix --
- template<typename eT>
- arma_inline
- const Mat<eT>&
- Mat<eT>::operator--()
- {
- Mat_aux::prefix_mm(*this);
- return *this;
- }
- //! postfix -- (must not return the object by reference)
- template<typename eT>
- arma_inline
- void
- Mat<eT>::operator--(int)
- {
- Mat_aux::postfix_mm(*this);
- }
- //! returns true if the matrix has no elements
- template<typename eT>
- arma_inline
- arma_warn_unused
- bool
- Mat<eT>::is_empty() const
- {
- return (n_elem == 0);
- }
- //! returns true if the object can be interpreted as a column or row vector
- template<typename eT>
- arma_inline
- arma_warn_unused
- bool
- Mat<eT>::is_vec() const
- {
- return ( (n_rows == 1) || (n_cols == 1) );
- }
- //! returns true if the object can be interpreted as a row vector
- template<typename eT>
- arma_inline
- arma_warn_unused
- bool
- Mat<eT>::is_rowvec() const
- {
- return (n_rows == 1);
- }
- //! returns true if the object can be interpreted as a column vector
- template<typename eT>
- arma_inline
- arma_warn_unused
- bool
- Mat<eT>::is_colvec() const
- {
- return (n_cols == 1);
- }
- //! returns true if the object has the same number of non-zero rows and columnns
- template<typename eT>
- arma_inline
- arma_warn_unused
- bool
- Mat<eT>::is_square() const
- {
- return (n_rows == n_cols);
- }
- //! returns true if all of the elements are finite
- template<typename eT>
- inline
- arma_warn_unused
- bool
- Mat<eT>::is_finite() const
- {
- return arrayops::is_finite( memptr(), n_elem );
- }
- template<typename eT>
- inline
- arma_warn_unused
- bool
- Mat<eT>::has_inf() const
- {
- arma_extra_debug_sigprint();
-
- return arrayops::has_inf(memptr(), n_elem);
- }
- template<typename eT>
- inline
- arma_warn_unused
- bool
- Mat<eT>::has_nan() const
- {
- arma_extra_debug_sigprint();
-
- return arrayops::has_nan(memptr(), n_elem);
- }
- template<typename eT>
- inline
- arma_warn_unused
- bool
- Mat<eT>::is_sorted(const char* direction) const
- {
- arma_extra_debug_sigprint();
-
- return (*this).is_sorted(direction, (((vec_state == 2) || (n_rows == 1)) ? uword(1) : uword(0)));
- }
- template<typename eT>
- inline
- arma_warn_unused
- bool
- Mat<eT>::is_sorted(const char* direction, const uword dim) const
- {
- arma_extra_debug_sigprint();
-
- const char sig1 = (direction != NULL) ? direction[0] : char(0);
-
- // direction is one of:
- // "ascend"
- // "descend"
- // "strictascend"
- // "strictdescend"
-
- arma_debug_check( ((sig1 != 'a') && (sig1 != 'd') && (sig1 != 's')), "Mat::is_sorted(): unknown sort direction" );
-
- // "strictascend"
- // "strictdescend"
- // 0123456
-
- const char sig2 = (sig1 == 's') ? direction[6] : char(0);
-
- if(sig1 == 's') { arma_debug_check( ((sig2 != 'a') && (sig2 != 'd')), "Mat::is_sorted(): unknown sort direction" ); }
-
- arma_debug_check( (dim > 1), "Mat::is_sorted(): parameter 'dim' must be 0 or 1" );
-
- if(sig1 == 'a')
- {
- // case: ascend
-
- // deliberately using the opposite direction comparator,
- // as we need to handle the case of two elements being equal
-
- arma_gt_comparator<eT> comparator;
-
- return (*this).is_sorted_helper(comparator, dim);
- }
- else
- if(sig1 == 'd')
- {
- // case: descend
-
- // deliberately using the opposite direction comparator,
- // as we need to handle the case of two elements being equal
-
- arma_lt_comparator<eT> comparator;
-
- return (*this).is_sorted_helper(comparator, dim);
- }
- else
- if((sig1 == 's') && (sig2 == 'a'))
- {
- // case: strict ascend
-
- arma_geq_comparator<eT> comparator;
-
- return (*this).is_sorted_helper(comparator, dim);
- }
- else
- if((sig1 == 's') && (sig2 == 'd'))
- {
- // case: strict descend
-
- arma_leq_comparator<eT> comparator;
-
- return (*this).is_sorted_helper(comparator, dim);
- }
-
- return true;
- }
- template<typename eT>
- template<typename comparator>
- inline
- arma_warn_unused
- bool
- Mat<eT>::is_sorted_helper(const comparator& comp, const uword dim) const
- {
- arma_extra_debug_sigprint();
-
- if(n_elem <= 1) { return true; }
-
- const uword local_n_cols = n_cols;
- const uword local_n_rows = n_rows;
-
- if(dim == 0)
- {
- if(local_n_rows <= 1u) { return true; }
-
- const uword local_n_rows_m1 = local_n_rows - 1;
-
- for(uword c=0; c < local_n_cols; ++c)
- {
- const eT* coldata = colptr(c);
-
- for(uword r=0; r < local_n_rows_m1; ++r)
- {
- const eT val1 = (*coldata); coldata++;
- const eT val2 = (*coldata);
-
- if(comp(val1,val2)) { return false; }
- }
- }
- }
- else
- if(dim == 1)
- {
- if(local_n_cols <= 1u) { return true; }
-
- const uword local_n_cols_m1 = local_n_cols - 1;
-
- if(local_n_rows == 1)
- {
- const eT* rowdata = memptr();
-
- for(uword c=0; c < local_n_cols_m1; ++c)
- {
- const eT val1 = (*rowdata); rowdata++;
- const eT val2 = (*rowdata);
-
- if(comp(val1,val2)) { return false; }
- }
- }
- else
- {
- for(uword r=0; r < local_n_rows; ++r)
- for(uword c=0; c < local_n_cols_m1; ++c)
- {
- const eT val1 = at(r,c );
- const eT val2 = at(r,c+1);
-
- if(comp(val1,val2)) { return false; }
- }
- }
- }
-
- return true;
- }
- //! returns true if the given index is currently in range
- template<typename eT>
- arma_inline
- arma_warn_unused
- bool
- Mat<eT>::in_range(const uword ii) const
- {
- return (ii < n_elem);
- }
- //! returns true if the given start and end indices are currently in range
- template<typename eT>
- arma_inline
- arma_warn_unused
- bool
- Mat<eT>::in_range(const span& x) const
- {
- arma_extra_debug_sigprint();
-
- if(x.whole)
- {
- return true;
- }
- else
- {
- const uword a = x.a;
- const uword b = x.b;
-
- return ( (a <= b) && (b < n_elem) );
- }
- }
- //! returns true if the given location is currently in range
- template<typename eT>
- arma_inline
- arma_warn_unused
- bool
- Mat<eT>::in_range(const uword in_row, const uword in_col) const
- {
- return ( (in_row < n_rows) && (in_col < n_cols) );
- }
- template<typename eT>
- arma_inline
- arma_warn_unused
- bool
- Mat<eT>::in_range(const span& row_span, const uword in_col) const
- {
- arma_extra_debug_sigprint();
-
- if(row_span.whole)
- {
- return (in_col < n_cols);
- }
- else
- {
- const uword in_row1 = row_span.a;
- const uword in_row2 = row_span.b;
-
- return ( (in_row1 <= in_row2) && (in_row2 < n_rows) && (in_col < n_cols) );
- }
- }
- template<typename eT>
- arma_inline
- arma_warn_unused
- bool
- Mat<eT>::in_range(const uword in_row, const span& col_span) const
- {
- arma_extra_debug_sigprint();
-
- if(col_span.whole)
- {
- return (in_row < n_rows);
- }
- else
- {
- const uword in_col1 = col_span.a;
- const uword in_col2 = col_span.b;
-
- return ( (in_row < n_rows) && (in_col1 <= in_col2) && (in_col2 < n_cols) );
- }
- }
- template<typename eT>
- arma_inline
- arma_warn_unused
- bool
- Mat<eT>::in_range(const span& row_span, const span& col_span) const
- {
- arma_extra_debug_sigprint();
-
- const uword in_row1 = row_span.a;
- const uword in_row2 = row_span.b;
-
- const uword in_col1 = col_span.a;
- const uword in_col2 = col_span.b;
-
- const bool rows_ok = row_span.whole ? true : ( (in_row1 <= in_row2) && (in_row2 < n_rows) );
- const bool cols_ok = col_span.whole ? true : ( (in_col1 <= in_col2) && (in_col2 < n_cols) );
-
- return ( rows_ok && cols_ok );
- }
- template<typename eT>
- arma_inline
- arma_warn_unused
- bool
- Mat<eT>::in_range(const uword in_row, const uword in_col, const SizeMat& s) const
- {
- const uword l_n_rows = n_rows;
- const uword l_n_cols = n_cols;
-
- if( (in_row >= l_n_rows) || (in_col >= l_n_cols) || ((in_row + s.n_rows) > l_n_rows) || ((in_col + s.n_cols) > l_n_cols) )
- {
- return false;
- }
- else
- {
- return true;
- }
- }
- //! returns a pointer to array of eTs for a specified column; no bounds check
- template<typename eT>
- arma_inline
- arma_warn_unused
- eT*
- Mat<eT>::colptr(const uword in_col)
- {
- return & access::rw(mem[in_col*n_rows]);
- }
- //! returns a pointer to array of eTs for a specified column; no bounds check
- template<typename eT>
- arma_inline
- arma_warn_unused
- const eT*
- Mat<eT>::colptr(const uword in_col) const
- {
- return & mem[in_col*n_rows];
- }
- //! returns a pointer to array of eTs used by the matrix
- template<typename eT>
- arma_inline
- arma_warn_unused
- eT*
- Mat<eT>::memptr()
- {
- return const_cast<eT*>(mem);
- }
- //! returns a pointer to array of eTs used by the matrix
- template<typename eT>
- arma_inline
- arma_warn_unused
- const eT*
- Mat<eT>::memptr() const
- {
- return mem;
- }
- //! print contents of the matrix (to the cout stream),
- //! optionally preceding with a user specified line of text.
- //! the precision and cell width are modified.
- //! on return, the stream's state are restored to their original values.
- template<typename eT>
- arma_cold
- inline
- void
- Mat<eT>::impl_print(const std::string& extra_text) const
- {
- arma_extra_debug_sigprint();
-
- if(extra_text.length() != 0)
- {
- const std::streamsize orig_width = get_cout_stream().width();
-
- get_cout_stream() << extra_text << '\n';
-
- get_cout_stream().width(orig_width);
- }
-
- arma_ostream::print(get_cout_stream(), *this, true);
- }
- //! print contents of the matrix to a user specified stream,
- //! optionally preceding with a user specified line of text.
- //! the precision and cell width are modified.
- //! on return, the stream's state are restored to their original values.
- template<typename eT>
- arma_cold
- inline
- void
- Mat<eT>::impl_print(std::ostream& user_stream, const std::string& extra_text) const
- {
- arma_extra_debug_sigprint();
-
- if(extra_text.length() != 0)
- {
- const std::streamsize orig_width = user_stream.width();
-
- user_stream << extra_text << '\n';
-
- user_stream.width(orig_width);
- }
-
- arma_ostream::print(user_stream, *this, true);
- }
- //! print contents of the matrix (to the cout stream),
- //! optionally preceding with a user specified line of text.
- //! the stream's state are used as is and are not modified
- //! (i.e. the precision and cell width are not modified).
- template<typename eT>
- arma_cold
- inline
- void
- Mat<eT>::impl_raw_print(const std::string& extra_text) const
- {
- arma_extra_debug_sigprint();
-
- if(extra_text.length() != 0)
- {
- const std::streamsize orig_width = get_cout_stream().width();
-
- get_cout_stream() << extra_text << '\n';
-
- get_cout_stream().width(orig_width);
- }
-
- arma_ostream::print(get_cout_stream(), *this, false);
- }
- //! print contents of the matrix to a user specified stream,
- //! optionally preceding with a user specified line of text.
- //! the stream's state are used as is and are not modified.
- //! (i.e. the precision and cell width are not modified).
- template<typename eT>
- arma_cold
- inline
- void
- Mat<eT>::impl_raw_print(std::ostream& user_stream, const std::string& extra_text) const
- {
- arma_extra_debug_sigprint();
-
- if(extra_text.length() != 0)
- {
- const std::streamsize orig_width = user_stream.width();
-
- user_stream << extra_text << '\n';
-
- user_stream.width(orig_width);
- }
-
- arma_ostream::print(user_stream, *this, false);
- }
- //! change the matrix to have user specified dimensions (data is not preserved)
- template<typename eT>
- inline
- void
- Mat<eT>::set_size(const uword in_elem)
- {
- arma_extra_debug_sigprint();
-
- switch(vec_state)
- {
- case 0:
- // fallthrough
- case 1:
- init_warm(in_elem, 1);
- break;
-
- case 2:
- init_warm(1, in_elem);
- break;
-
- default:
- ;
- }
- }
- //! change the matrix to have user specified dimensions (data is not preserved)
- template<typename eT>
- inline
- void
- Mat<eT>::set_size(const uword in_rows, const uword in_cols)
- {
- arma_extra_debug_sigprint();
-
- init_warm(in_rows, in_cols);
- }
- template<typename eT>
- inline
- void
- Mat<eT>::set_size(const SizeMat& s)
- {
- arma_extra_debug_sigprint();
-
- init_warm(s.n_rows, s.n_cols);
- }
- //! change the matrix to have user specified dimensions (data is preserved)
- template<typename eT>
- inline
- void
- Mat<eT>::resize(const uword in_elem)
- {
- arma_extra_debug_sigprint();
-
- switch(vec_state)
- {
- case 0:
- // fallthrough
- case 1:
- (*this).resize(in_elem, 1);
- break;
-
- case 2:
- (*this).resize(1, in_elem);
- break;
-
- default:
- ;
- }
- }
- //! change the matrix to have user specified dimensions (data is preserved)
- template<typename eT>
- inline
- void
- Mat<eT>::resize(const uword in_rows, const uword in_cols)
- {
- arma_extra_debug_sigprint();
-
- *this = arma::resize(*this, in_rows, in_cols);
- }
- template<typename eT>
- inline
- void
- Mat<eT>::resize(const SizeMat& s)
- {
- arma_extra_debug_sigprint();
-
- *this = arma::resize(*this, s.n_rows, s.n_cols);
- }
- //! change the matrix to have user specified dimensions (data is preserved)
- template<typename eT>
- inline
- void
- Mat<eT>::reshape(const uword in_rows, const uword in_cols)
- {
- arma_extra_debug_sigprint();
-
- *this = arma::reshape(*this, in_rows, in_cols);
- }
- template<typename eT>
- inline
- void
- Mat<eT>::reshape(const SizeMat& s)
- {
- arma_extra_debug_sigprint();
-
- *this = arma::reshape(*this, s.n_rows, s.n_cols);
- }
- //! NOTE: don't use this form; it's deprecated and will be removed
- template<typename eT>
- arma_deprecated
- inline
- void
- Mat<eT>::reshape(const uword in_rows, const uword in_cols, const uword dim)
- {
- arma_extra_debug_sigprint();
-
- *this = arma::reshape(*this, in_rows, in_cols, dim);
- }
- //! change the matrix (without preserving data) to have the same dimensions as the given expression
- template<typename eT>
- template<typename eT2, typename expr>
- inline
- void
- Mat<eT>::copy_size(const Base<eT2, expr>& X)
- {
- arma_extra_debug_sigprint();
-
- const Proxy<expr> P(X.get_ref());
-
- const uword X_n_rows = P.get_n_rows();
- const uword X_n_cols = P.get_n_cols();
-
- init_warm(X_n_rows, X_n_cols);
- }
- //! apply a functor to each element
- template<typename eT>
- template<typename functor>
- inline
- const Mat<eT>&
- Mat<eT>::for_each(functor F)
- {
- arma_extra_debug_sigprint();
-
- eT* data = memptr();
-
- const uword N = n_elem;
-
- uword ii, jj;
-
- for(ii=0, jj=1; jj < N; ii+=2, jj+=2)
- {
- F(data[ii]);
- F(data[jj]);
- }
-
- if(ii < N)
- {
- F(data[ii]);
- }
-
- return *this;
- }
- template<typename eT>
- template<typename functor>
- inline
- const Mat<eT>&
- Mat<eT>::for_each(functor F) const
- {
- arma_extra_debug_sigprint();
-
- const eT* data = memptr();
-
- const uword N = n_elem;
-
- uword ii, jj;
-
- for(ii=0, jj=1; jj < N; ii+=2, jj+=2)
- {
- F(data[ii]);
- F(data[jj]);
- }
-
- if(ii < N)
- {
- F(data[ii]);
- }
-
- return *this;
- }
- //! transform each element in the matrix using a functor
- template<typename eT>
- template<typename functor>
- inline
- const Mat<eT>&
- Mat<eT>::transform(functor F)
- {
- arma_extra_debug_sigprint();
-
- eT* out_mem = memptr();
-
- const uword N = n_elem;
-
- uword ii, jj;
-
- for(ii=0, jj=1; jj < N; ii+=2, jj+=2)
- {
- eT tmp_ii = out_mem[ii];
- eT tmp_jj = out_mem[jj];
-
- tmp_ii = eT( F(tmp_ii) );
- tmp_jj = eT( F(tmp_jj) );
-
- out_mem[ii] = tmp_ii;
- out_mem[jj] = tmp_jj;
- }
-
- if(ii < N)
- {
- out_mem[ii] = eT( F(out_mem[ii]) );
- }
-
- return *this;
- }
- //! imbue (fill) the matrix with values provided by a functor
- template<typename eT>
- template<typename functor>
- inline
- const Mat<eT>&
- Mat<eT>::imbue(functor F)
- {
- arma_extra_debug_sigprint();
-
- eT* out_mem = memptr();
-
- const uword N = n_elem;
-
- uword ii, jj;
-
- for(ii=0, jj=1; jj < N; ii+=2, jj+=2)
- {
- const eT tmp_ii = eT( F() );
- const eT tmp_jj = eT( F() );
-
- out_mem[ii] = tmp_ii;
- out_mem[jj] = tmp_jj;
- }
-
- if(ii < N)
- {
- out_mem[ii] = eT( F() );
- }
-
- return *this;
- }
- template<typename eT>
- inline
- const Mat<eT>&
- Mat<eT>::replace(const eT old_val, const eT new_val)
- {
- arma_extra_debug_sigprint();
-
- arrayops::replace(memptr(), n_elem, old_val, new_val);
-
- return *this;
- }
- template<typename eT>
- inline
- const Mat<eT>&
- Mat<eT>::clean(const typename get_pod_type<eT>::result threshold)
- {
- arma_extra_debug_sigprint();
-
- arrayops::clean(memptr(), n_elem, threshold);
-
- return *this;
- }
- //! fill the matrix with the specified value
- template<typename eT>
- inline
- const Mat<eT>&
- Mat<eT>::fill(const eT val)
- {
- arma_extra_debug_sigprint();
-
- arrayops::inplace_set( memptr(), val, n_elem );
-
- return *this;
- }
- //! fill the matrix with the specified pattern
- template<typename eT>
- template<typename fill_type>
- inline
- const Mat<eT>&
- Mat<eT>::fill(const fill::fill_class<fill_type>&)
- {
- arma_extra_debug_sigprint();
-
- if(is_same_type<fill_type, fill::fill_zeros>::yes) (*this).zeros();
- if(is_same_type<fill_type, fill::fill_ones >::yes) (*this).ones();
- if(is_same_type<fill_type, fill::fill_eye >::yes) (*this).eye();
- if(is_same_type<fill_type, fill::fill_randu>::yes) (*this).randu();
- if(is_same_type<fill_type, fill::fill_randn>::yes) (*this).randn();
-
- return *this;
- }
- template<typename eT>
- inline
- const Mat<eT>&
- Mat<eT>::zeros()
- {
- arma_extra_debug_sigprint();
-
- arrayops::fill_zeros(memptr(), n_elem);
-
- return *this;
- }
- template<typename eT>
- inline
- const Mat<eT>&
- Mat<eT>::zeros(const uword in_elem)
- {
- arma_extra_debug_sigprint();
-
- set_size(in_elem);
-
- return (*this).zeros();
- }
- template<typename eT>
- inline
- const Mat<eT>&
- Mat<eT>::zeros(const uword in_n_rows, const uword in_n_cols)
- {
- arma_extra_debug_sigprint();
-
- set_size(in_n_rows, in_n_cols);
-
- return (*this).zeros();
- }
- template<typename eT>
- inline
- const Mat<eT>&
- Mat<eT>::zeros(const SizeMat& s)
- {
- arma_extra_debug_sigprint();
-
- return (*this).zeros(s.n_rows, s.n_cols);
- }
- template<typename eT>
- inline
- const Mat<eT>&
- Mat<eT>::ones()
- {
- arma_extra_debug_sigprint();
-
- return fill(eT(1));
- }
- template<typename eT>
- inline
- const Mat<eT>&
- Mat<eT>::ones(const uword in_elem)
- {
- arma_extra_debug_sigprint();
-
- set_size(in_elem);
-
- return fill(eT(1));
- }
- template<typename eT>
- inline
- const Mat<eT>&
- Mat<eT>::ones(const uword in_rows, const uword in_cols)
- {
- arma_extra_debug_sigprint();
-
- set_size(in_rows, in_cols);
-
- return fill(eT(1));
- }
- template<typename eT>
- inline
- const Mat<eT>&
- Mat<eT>::ones(const SizeMat& s)
- {
- arma_extra_debug_sigprint();
-
- return (*this).ones(s.n_rows, s.n_cols);
- }
- template<typename eT>
- inline
- const Mat<eT>&
- Mat<eT>::randu()
- {
- arma_extra_debug_sigprint();
-
- arma_rng::randu<eT>::fill( memptr(), n_elem );
-
- return *this;
- }
- template<typename eT>
- inline
- const Mat<eT>&
- Mat<eT>::randu(const uword in_elem)
- {
- arma_extra_debug_sigprint();
-
- set_size(in_elem);
-
- return (*this).randu();
- }
- template<typename eT>
- inline
- const Mat<eT>&
- Mat<eT>::randu(const uword in_rows, const uword in_cols)
- {
- arma_extra_debug_sigprint();
-
- set_size(in_rows, in_cols);
-
- return (*this).randu();
- }
- template<typename eT>
- inline
- const Mat<eT>&
- Mat<eT>::randu(const SizeMat& s)
- {
- arma_extra_debug_sigprint();
-
- return (*this).randu(s.n_rows, s.n_cols);
- }
- template<typename eT>
- inline
- const Mat<eT>&
- Mat<eT>::randn()
- {
- arma_extra_debug_sigprint();
-
- arma_rng::randn<eT>::fill( memptr(), n_elem );
-
- return *this;
- }
- template<typename eT>
- inline
- const Mat<eT>&
- Mat<eT>::randn(const uword in_elem)
- {
- arma_extra_debug_sigprint();
-
- set_size(in_elem);
-
- return (*this).randn();
- }
- template<typename eT>
- inline
- const Mat<eT>&
- Mat<eT>::randn(const uword in_rows, const uword in_cols)
- {
- arma_extra_debug_sigprint();
-
- set_size(in_rows, in_cols);
-
- return (*this).randn();
- }
- template<typename eT>
- inline
- const Mat<eT>&
- Mat<eT>::randn(const SizeMat& s)
- {
- arma_extra_debug_sigprint();
-
- return (*this).randn(s.n_rows, s.n_cols);
- }
- template<typename eT>
- inline
- const Mat<eT>&
- Mat<eT>::eye()
- {
- arma_extra_debug_sigprint();
-
- (*this).zeros();
-
- const uword N = (std::min)(n_rows, n_cols);
-
- for(uword ii=0; ii<N; ++ii)
- {
- at(ii,ii) = eT(1);
- }
-
- return *this;
- }
- template<typename eT>
- inline
- const Mat<eT>&
- Mat<eT>::eye(const uword in_rows, const uword in_cols)
- {
- arma_extra_debug_sigprint();
-
- set_size(in_rows, in_cols);
-
- return (*this).eye();
- }
- template<typename eT>
- inline
- const Mat<eT>&
- Mat<eT>::eye(const SizeMat& s)
- {
- arma_extra_debug_sigprint();
-
- return (*this).eye(s.n_rows, s.n_cols);
- }
- template<typename eT>
- inline
- arma_cold
- void
- Mat<eT>::reset()
- {
- arma_extra_debug_sigprint();
-
- switch(vec_state)
- {
- default:
- init_warm(0, 0);
- break;
-
- case 1:
- init_warm(0, 1);
- break;
-
- case 2:
- init_warm(1, 0);
- break;
- }
- }
- template<typename eT>
- inline
- arma_cold
- void
- Mat<eT>::soft_reset()
- {
- arma_extra_debug_sigprint();
-
- // don't change the size if the matrix has a fixed size or is a cube slice
- if(mem_state <= 1)
- {
- reset();
- }
- else
- {
- fill(Datum<eT>::nan);
- }
- }
- template<typename eT>
- template<typename T1>
- inline
- void
- Mat<eT>::set_real(const Base<typename Mat<eT>::pod_type,T1>& X)
- {
- arma_extra_debug_sigprint();
-
- Mat_aux::set_real(*this, X);
- }
- template<typename eT>
- template<typename T1>
- inline
- void
- Mat<eT>::set_imag(const Base<typename Mat<eT>::pod_type,T1>& X)
- {
- arma_extra_debug_sigprint();
-
- Mat_aux::set_imag(*this, X);
- }
- template<typename eT>
- inline
- arma_warn_unused
- eT
- Mat<eT>::min() const
- {
- arma_extra_debug_sigprint();
-
- if(n_elem == 0)
- {
- arma_debug_check(true, "Mat::min(): object has no elements");
-
- return Datum<eT>::nan;
- }
-
- return op_min::direct_min(memptr(), n_elem);
- }
- template<typename eT>
- inline
- arma_warn_unused
- eT
- Mat<eT>::max() const
- {
- arma_extra_debug_sigprint();
-
- if(n_elem == 0)
- {
- arma_debug_check(true, "Mat::max(): object has no elements");
-
- return Datum<eT>::nan;
- }
-
- return op_max::direct_max(memptr(), n_elem);
- }
- template<typename eT>
- inline
- eT
- Mat<eT>::min(uword& index_of_min_val) const
- {
- arma_extra_debug_sigprint();
-
- if(n_elem == 0)
- {
- arma_debug_check(true, "Mat::min(): object has no elements");
-
- index_of_min_val = uword(0);
-
- return Datum<eT>::nan;
- }
-
- return op_min::direct_min(memptr(), n_elem, index_of_min_val);
- }
- template<typename eT>
- inline
- eT
- Mat<eT>::max(uword& index_of_max_val) const
- {
- arma_extra_debug_sigprint();
-
- if(n_elem == 0)
- {
- arma_debug_check(true, "Mat::max(): object has no elements");
-
- index_of_max_val = uword(0);
-
- return Datum<eT>::nan;
- }
-
- return op_max::direct_max(memptr(), n_elem, index_of_max_val);
- }
- template<typename eT>
- inline
- eT
- Mat<eT>::min(uword& row_of_min_val, uword& col_of_min_val) const
- {
- arma_extra_debug_sigprint();
-
- if(n_elem == 0)
- {
- arma_debug_check(true, "Mat::min(): object has no elements");
-
- row_of_min_val = uword(0);
- col_of_min_val = uword(0);
-
- return Datum<eT>::nan;
- }
-
- uword iq;
-
- eT val = op_min::direct_min(memptr(), n_elem, iq);
-
- row_of_min_val = iq % n_rows;
- col_of_min_val = iq / n_rows;
-
- return val;
- }
- template<typename eT>
- inline
- eT
- Mat<eT>::max(uword& row_of_max_val, uword& col_of_max_val) const
- {
- arma_extra_debug_sigprint();
-
- if(n_elem == 0)
- {
- arma_debug_check(true, "Mat::max(): object has no elements");
-
- row_of_max_val = uword(0);
- col_of_max_val = uword(0);
-
- return Datum<eT>::nan;
- }
-
- uword iq;
-
- eT val = op_max::direct_max(memptr(), n_elem, iq);
-
- row_of_max_val = iq % n_rows;
- col_of_max_val = iq / n_rows;
-
- return val;
- }
- //! save the matrix to a file
- template<typename eT>
- inline
- arma_cold
- bool
- Mat<eT>::save(const std::string name, const file_type type, const bool print_status) const
- {
- arma_extra_debug_sigprint();
-
- bool save_okay = false;
-
- switch(type)
- {
- case raw_ascii:
- save_okay = diskio::save_raw_ascii(*this, name);
- break;
-
- case arma_ascii:
- save_okay = diskio::save_arma_ascii(*this, name);
- break;
-
- case csv_ascii:
- return (*this).save(csv_name(name), type, print_status);
- break;
-
- case raw_binary:
- save_okay = diskio::save_raw_binary(*this, name);
- break;
-
- case arma_binary:
- save_okay = diskio::save_arma_binary(*this, name);
- break;
-
- case pgm_binary:
- save_okay = diskio::save_pgm_binary(*this, name);
- break;
-
- case hdf5_binary:
- return (*this).save(hdf5_name(name));
- break;
-
- case hdf5_binary_trans: // kept for compatibility with earlier versions of Armadillo
- return (*this).save(hdf5_name(name, std::string(), hdf5_opts::trans));
- break;
-
- default:
- if(print_status) { arma_debug_warn("Mat::save(): unsupported file type"); }
- save_okay = false;
- }
-
- if(print_status && (save_okay == false)) { arma_debug_warn("Mat::save(): couldn't write to ", name); }
-
- return save_okay;
- }
- template<typename eT>
- inline
- arma_cold
- bool
- Mat<eT>::save(const hdf5_name& spec, const file_type type, const bool print_status) const
- {
- arma_extra_debug_sigprint();
-
- // handling of hdf5_binary_trans kept for compatibility with earlier versions of Armadillo
-
- if( (type != hdf5_binary) && (type != hdf5_binary_trans) )
- {
- arma_debug_check(true, "Mat::save(): unsupported file type for hdf5_name()");
- return false;
- }
-
- const bool do_trans = bool(spec.opts.flags & hdf5_opts::flag_trans ) || (type == hdf5_binary_trans);
- const bool append = bool(spec.opts.flags & hdf5_opts::flag_append );
- const bool replace = bool(spec.opts.flags & hdf5_opts::flag_replace);
-
- if(append && replace)
- {
- arma_debug_check(true, "Mat::save(): only one of 'append' or 'replace' options can be used");
- return false;
- }
-
- bool save_okay = false;
- std::string err_msg;
-
- if(do_trans)
- {
- Mat<eT> tmp;
-
- op_strans::apply_mat_noalias(tmp, *this);
-
- save_okay = diskio::save_hdf5_binary(tmp, spec, err_msg);
- }
- else
- {
- save_okay = diskio::save_hdf5_binary(*this, spec, err_msg);
- }
-
- if((print_status == true) && (save_okay == false))
- {
- if(err_msg.length() > 0)
- {
- arma_debug_warn("Mat::save(): ", err_msg, spec.filename);
- }
- else
- {
- arma_debug_warn("Mat::save(): couldn't write to ", spec.filename);
- }
- }
-
- return save_okay;
- }
- template<typename eT>
- inline
- arma_cold
- bool
- Mat<eT>::save(const csv_name& spec, const file_type type, const bool print_status) const
- {
- arma_extra_debug_sigprint();
-
- if(type != csv_ascii)
- {
- arma_debug_check(true, "Mat::save(): unsupported file type for csv_name()");
- return false;
- }
-
- const bool do_trans = bool(spec.opts.flags & csv_opts::flag_trans );
- const bool no_header = bool(spec.opts.flags & csv_opts::flag_no_header );
- bool with_header = bool(spec.opts.flags & csv_opts::flag_with_header);
-
- arma_extra_debug_print("Mat::save(csv_name): enabled flags:");
-
- if(do_trans ) { arma_extra_debug_print("trans"); }
- if(no_header ) { arma_extra_debug_print("no_header"); }
- if(with_header) { arma_extra_debug_print("with_header"); }
-
- if(no_header) { with_header = false; }
-
- if(with_header)
- {
- if( (spec.header_ro.n_cols != 1) && (spec.header_ro.n_rows != 1) )
- {
- if(print_status) { arma_debug_warn("Mat::save(): given header must have a vector layout"); }
- return false;
- }
-
- for(uword i=0; i < spec.header_ro.n_elem; ++i)
- {
- const std::string& token = spec.header_ro.at(i);
-
- if(token.find(',') != std::string::npos)
- {
- if(print_status) { arma_debug_warn("Mat::save(): token within the header contains a comma: '", token, "'"); }
- return false;
- }
- }
-
- const uword save_n_cols = (do_trans) ? (*this).n_rows : (*this).n_cols;
-
- if(spec.header_ro.n_elem != save_n_cols)
- {
- if(print_status) { arma_debug_warn("Mat::save(): size mistmach between header and matrix"); }
- return false;
- }
- }
-
- bool save_okay = false;
-
- if(do_trans)
- {
- const Mat<eT> tmp = (*this).st();
-
- save_okay = diskio::save_csv_ascii(tmp, spec.filename, spec.header_ro, with_header);
- }
- else
- {
- save_okay = diskio::save_csv_ascii(*this, spec.filename, spec.header_ro, with_header);
- }
-
- if((print_status == true) && (save_okay == false))
- {
- arma_debug_warn("Mat::save(): couldn't write to ", spec.filename);
- }
-
- return save_okay;
- }
- //! save the matrix to a stream
- template<typename eT>
- inline
- arma_cold
- bool
- Mat<eT>::save(std::ostream& os, const file_type type, const bool print_status) const
- {
- arma_extra_debug_sigprint();
-
- bool save_okay = false;
-
- switch(type)
- {
- case raw_ascii:
- save_okay = diskio::save_raw_ascii(*this, os);
- break;
-
- case arma_ascii:
- save_okay = diskio::save_arma_ascii(*this, os);
- break;
-
- case csv_ascii:
- save_okay = diskio::save_csv_ascii(*this, os);
- break;
-
- case raw_binary:
- save_okay = diskio::save_raw_binary(*this, os);
- break;
-
- case arma_binary:
- save_okay = diskio::save_arma_binary(*this, os);
- break;
-
- case pgm_binary:
- save_okay = diskio::save_pgm_binary(*this, os);
- break;
-
- default:
- if(print_status) { arma_debug_warn("Mat::save(): unsupported file type"); }
- save_okay = false;
- }
-
- if(print_status && (save_okay == false)) { arma_debug_warn("Mat::save(): couldn't write to the given stream"); }
-
- return save_okay;
- }
- //! load a matrix from a file
- template<typename eT>
- inline
- arma_cold
- bool
- Mat<eT>::load(const std::string name, const file_type type, const bool print_status)
- {
- arma_extra_debug_sigprint();
-
- bool load_okay = false;
- std::string err_msg;
-
- switch(type)
- {
- case auto_detect:
- load_okay = diskio::load_auto_detect(*this, name, err_msg);
- break;
-
- case raw_ascii:
- load_okay = diskio::load_raw_ascii(*this, name, err_msg);
- break;
-
- case arma_ascii:
- load_okay = diskio::load_arma_ascii(*this, name, err_msg);
- break;
-
- case csv_ascii:
- return (*this).load(csv_name(name), type, print_status);
- break;
-
- case raw_binary:
- load_okay = diskio::load_raw_binary(*this, name, err_msg);
- break;
-
- case arma_binary:
- load_okay = diskio::load_arma_binary(*this, name, err_msg);
- break;
-
- case pgm_binary:
- load_okay = diskio::load_pgm_binary(*this, name, err_msg);
- break;
-
- case hdf5_binary:
- return (*this).load(hdf5_name(name));
- break;
-
- case hdf5_binary_trans: // kept for compatibility with earlier versions of Armadillo
- return (*this).load(hdf5_name(name, std::string(), hdf5_opts::trans));
- break;
-
- default:
- if(print_status) { arma_debug_warn("Mat::load(): unsupported file type"); }
- load_okay = false;
- }
-
- if( (print_status == true) && (load_okay == false) )
- {
- if(err_msg.length() > 0)
- {
- arma_debug_warn("Mat::load(): ", err_msg, name);
- }
- else
- {
- arma_debug_warn("Mat::load(): couldn't read ", name);
- }
- }
-
- if(load_okay == false)
- {
- (*this).soft_reset();
- }
-
- return load_okay;
- }
- template<typename eT>
- inline
- arma_cold
- bool
- Mat<eT>::load(const hdf5_name& spec, const file_type type, const bool print_status)
- {
- arma_extra_debug_sigprint();
-
- if( (type != hdf5_binary) && (type != hdf5_binary_trans) )
- {
- if(print_status) { arma_debug_warn("Mat::load(): unsupported file type for hdf5_name()"); }
- (*this).soft_reset();
- return false;
- }
-
- bool load_okay = false;
- std::string err_msg;
-
- const bool do_trans = bool(spec.opts.flags & hdf5_opts::flag_trans) || (type == hdf5_binary_trans);
-
- if(do_trans)
- {
- Mat<eT> tmp;
-
- load_okay = diskio::load_hdf5_binary(tmp, spec, err_msg);
-
- if(load_okay) { op_strans::apply_mat_noalias(*this, tmp); }
- }
- else
- {
- load_okay = diskio::load_hdf5_binary(*this, spec, err_msg);
- }
-
-
- if( (print_status == true) && (load_okay == false) )
- {
- if(err_msg.length() > 0)
- {
- arma_debug_warn("Mat::load(): ", err_msg, spec.filename);
- }
- else
- {
- arma_debug_warn("Mat::load(): couldn't read ", spec.filename);
- }
- }
-
- if(load_okay == false)
- {
- (*this).soft_reset();
- }
-
- return load_okay;
- }
- template<typename eT>
- inline
- arma_cold
- bool
- Mat<eT>::load(const csv_name& spec, const file_type type, const bool print_status)
- {
- arma_extra_debug_sigprint();
-
- if(type != csv_ascii)
- {
- arma_debug_check(true, "Mat::load(): unsupported file type for csv_name()");
- return false;
- }
-
- const bool do_trans = bool(spec.opts.flags & csv_opts::flag_trans );
- const bool no_header = bool(spec.opts.flags & csv_opts::flag_no_header );
- bool with_header = bool(spec.opts.flags & csv_opts::flag_with_header);
-
- arma_extra_debug_print("Mat::load(csv_name): enabled flags:");
-
- if(do_trans ) { arma_extra_debug_print("trans"); }
- if(no_header ) { arma_extra_debug_print("no_header"); }
- if(with_header) { arma_extra_debug_print("with_header"); }
-
- if(no_header) { with_header = false; }
-
- bool load_okay = false;
- std::string err_msg;
-
- if(do_trans)
- {
- Mat<eT> tmp_mat;
-
- load_okay = diskio::load_csv_ascii(tmp_mat, spec.filename, err_msg, spec.header_rw, with_header);
-
- if(load_okay)
- {
- (*this) = tmp_mat.st();
-
- if(with_header)
- {
- // field::set_size() preserves data if the number of elements hasn't changed
- spec.header_rw.set_size(spec.header_rw.n_elem, 1);
- }
- }
- }
- else
- {
- load_okay = diskio::load_csv_ascii(*this, spec.filename, err_msg, spec.header_rw, with_header);
- }
-
- if(print_status)
- {
- if(load_okay == false)
- {
- if(err_msg.length() > 0)
- {
- arma_debug_warn("Mat::load(): ", err_msg, spec.filename);
- }
- else
- {
- arma_debug_warn("Mat::load(): couldn't read ", spec.filename);
- }
- }
- else
- {
- const uword load_n_cols = (do_trans) ? (*this).n_rows : (*this).n_cols;
-
- if(with_header && (spec.header_rw.n_elem != load_n_cols))
- {
- arma_debug_warn("Mat::load(): size mistmach between header and matrix");
- }
- }
- }
-
- if(load_okay == false)
- {
- (*this).soft_reset();
-
- if(with_header) { spec.header_rw.reset(); }
- }
-
- return load_okay;
- }
- //! load a matrix from a stream
- template<typename eT>
- inline
- arma_cold
- bool
- Mat<eT>::load(std::istream& is, const file_type type, const bool print_status)
- {
- arma_extra_debug_sigprint();
-
- bool load_okay = false;
- std::string err_msg;
-
- switch(type)
- {
- case auto_detect:
- load_okay = diskio::load_auto_detect(*this, is, err_msg);
- break;
-
- case raw_ascii:
- load_okay = diskio::load_raw_ascii(*this, is, err_msg);
- break;
-
- case arma_ascii:
- load_okay = diskio::load_arma_ascii(*this, is, err_msg);
- break;
-
- case csv_ascii:
- load_okay = diskio::load_csv_ascii(*this, is, err_msg);
- break;
-
- case raw_binary:
- load_okay = diskio::load_raw_binary(*this, is, err_msg);
- break;
-
- case arma_binary:
- load_okay = diskio::load_arma_binary(*this, is, err_msg);
- break;
-
- case pgm_binary:
- load_okay = diskio::load_pgm_binary(*this, is, err_msg);
- break;
-
- default:
- if(print_status) { arma_debug_warn("Mat::load(): unsupported file type"); }
- load_okay = false;
- }
-
- if( (print_status == true) && (load_okay == false) )
- {
- if(err_msg.length() > 0)
- {
- arma_debug_warn("Mat::load(): ", err_msg, "the given stream");
- }
- else
- {
- arma_debug_warn("Mat::load(): couldn't load from the given stream");
- }
- }
-
- if(load_okay == false)
- {
- (*this).soft_reset();
- }
-
- return load_okay;
- }
- //! save the matrix to a file, without printing any error messages
- template<typename eT>
- inline
- arma_cold
- bool
- Mat<eT>::quiet_save(const std::string name, const file_type type) const
- {
- arma_extra_debug_sigprint();
-
- return (*this).save(name, type, false);
- }
- template<typename eT>
- inline
- arma_cold
- bool
- Mat<eT>::quiet_save(const hdf5_name& spec, const file_type type) const
- {
- arma_extra_debug_sigprint();
-
- return (*this).save(spec, type, false);
- }
- template<typename eT>
- inline
- arma_cold
- bool
- Mat<eT>::quiet_save(const csv_name& spec, const file_type type) const
- {
- arma_extra_debug_sigprint();
-
- return (*this).save(spec, type, false);
- }
- //! save the matrix to a stream, without printing any error messages
- template<typename eT>
- inline
- arma_cold
- bool
- Mat<eT>::quiet_save(std::ostream& os, const file_type type) const
- {
- arma_extra_debug_sigprint();
-
- return (*this).save(os, type, false);
- }
- //! load a matrix from a file, without printing any error messages
- template<typename eT>
- inline
- arma_cold
- bool
- Mat<eT>::quiet_load(const std::string name, const file_type type)
- {
- arma_extra_debug_sigprint();
-
- return (*this).load(name, type, false);
- }
- template<typename eT>
- inline
- arma_cold
- bool
- Mat<eT>::quiet_load(const hdf5_name& spec, const file_type type)
- {
- arma_extra_debug_sigprint();
-
- return (*this).load(spec, type, false);
- }
- template<typename eT>
- inline
- arma_cold
- bool
- Mat<eT>::quiet_load(const csv_name& spec, const file_type type)
- {
- arma_extra_debug_sigprint();
-
- return (*this).load(spec, type, false);
- }
- //! load a matrix from a stream, without printing any error messages
- template<typename eT>
- inline
- arma_cold
- bool
- Mat<eT>::quiet_load(std::istream& is, const file_type type)
- {
- arma_extra_debug_sigprint();
-
- return (*this).load(is, type, false);
- }
- template<typename eT>
- inline
- Mat<eT>::row_iterator::row_iterator()
- : M (NULL)
- , current_row(0 )
- , current_col(0 )
- {
- arma_extra_debug_sigprint();
- // Technically this iterator is invalid (it does not point to a valid element)
- }
- template<typename eT>
- inline
- Mat<eT>::row_iterator::row_iterator(const row_iterator& X)
- : M (X.M )
- , current_row(X.current_row)
- , current_col(X.current_col)
- {
- arma_extra_debug_sigprint();
- }
- template<typename eT>
- inline
- Mat<eT>::row_iterator::row_iterator(Mat<eT>& in_M, const uword in_row, const uword in_col)
- : M (&in_M )
- , current_row(in_row)
- , current_col(in_col)
- {
- arma_extra_debug_sigprint();
- }
- template<typename eT>
- inline
- arma_warn_unused
- eT&
- Mat<eT>::row_iterator::operator*()
- {
- return M->at(current_row,current_col);
- }
- template<typename eT>
- inline
- typename Mat<eT>::row_iterator&
- Mat<eT>::row_iterator::operator++()
- {
- current_col++;
-
- if(current_col == M->n_cols)
- {
- current_col = 0;
- current_row++;
- }
-
- return *this;
- }
- template<typename eT>
- inline
- arma_warn_unused
- typename Mat<eT>::row_iterator
- Mat<eT>::row_iterator::operator++(int)
- {
- typename Mat<eT>::row_iterator temp(*this);
-
- ++(*this);
-
- return temp;
- }
- template<typename eT>
- inline
- typename Mat<eT>::row_iterator&
- Mat<eT>::row_iterator::operator--()
- {
- if(current_col > 0)
- {
- current_col--;
- }
- else
- {
- if(current_row > 0)
- {
- current_col = M->n_cols - 1;
- current_row--;
- }
- }
-
- return *this;
- }
- template<typename eT>
- inline
- arma_warn_unused
- typename Mat<eT>::row_iterator
- Mat<eT>::row_iterator::operator--(int)
- {
- typename Mat<eT>::row_iterator temp(*this);
-
- --(*this);
-
- return temp;
- }
- template<typename eT>
- inline
- arma_warn_unused
- bool
- Mat<eT>::row_iterator::operator!=(const typename Mat<eT>::row_iterator& X) const
- {
- return ( (current_row != X.current_row) || (current_col != X.current_col) );
- }
- template<typename eT>
- inline
- arma_warn_unused
- bool
- Mat<eT>::row_iterator::operator==(const typename Mat<eT>::row_iterator& X) const
- {
- return ( (current_row == X.current_row) && (current_col == X.current_col) );
- }
- template<typename eT>
- inline
- arma_warn_unused
- bool
- Mat<eT>::row_iterator::operator!=(const typename Mat<eT>::const_row_iterator& X) const
- {
- return ( (current_row != X.current_row) || (current_col != X.current_col) );
- }
- template<typename eT>
- inline
- arma_warn_unused
- bool
- Mat<eT>::row_iterator::operator==(const typename Mat<eT>::const_row_iterator& X) const
- {
- return ( (current_row == X.current_row) && (current_col == X.current_col) );
- }
- template<typename eT>
- inline
- Mat<eT>::const_row_iterator::const_row_iterator()
- : M (NULL)
- , current_row(0 )
- , current_col(0 )
- {
- arma_extra_debug_sigprint();
- // Technically this iterator is invalid (it does not point to a valid element)
- }
- template<typename eT>
- inline
- Mat<eT>::const_row_iterator::const_row_iterator(const typename Mat<eT>::row_iterator& X)
- : M (X.M )
- , current_row(X.current_row)
- , current_col(X.current_col)
- {
- arma_extra_debug_sigprint();
- }
- template<typename eT>
- inline
- Mat<eT>::const_row_iterator::const_row_iterator(const typename Mat<eT>::const_row_iterator& X)
- : M (X.M )
- , current_row(X.current_row)
- , current_col(X.current_col)
- {
- arma_extra_debug_sigprint();
- }
- template<typename eT>
- inline
- Mat<eT>::const_row_iterator::const_row_iterator(const Mat<eT>& in_M, const uword in_row, const uword in_col)
- : M (&in_M )
- , current_row(in_row)
- , current_col(in_col)
- {
- arma_extra_debug_sigprint();
- }
- template<typename eT>
- inline
- arma_warn_unused
- const eT&
- Mat<eT>::const_row_iterator::operator*() const
- {
- return M->at(current_row,current_col);
- }
- template<typename eT>
- inline
- typename Mat<eT>::const_row_iterator&
- Mat<eT>::const_row_iterator::operator++()
- {
- current_col++;
-
- if(current_col == M->n_cols)
- {
- current_col = 0;
- current_row++;
- }
-
- return *this;
- }
- template<typename eT>
- inline
- arma_warn_unused
- typename Mat<eT>::const_row_iterator
- Mat<eT>::const_row_iterator::operator++(int)
- {
- typename Mat<eT>::const_row_iterator temp(*this);
-
- ++(*this);
-
- return temp;
- }
- template<typename eT>
- inline
- typename Mat<eT>::const_row_iterator&
- Mat<eT>::const_row_iterator::operator--()
- {
- if(current_col > 0)
- {
- current_col--;
- }
- else
- {
- if(current_row > 0)
- {
- current_col = M->n_cols - 1;
- current_row--;
- }
- }
-
- return *this;
- }
- template<typename eT>
- inline
- arma_warn_unused
- typename Mat<eT>::const_row_iterator
- Mat<eT>::const_row_iterator::operator--(int)
- {
- typename Mat<eT>::const_row_iterator temp(*this);
-
- --(*this);
-
- return temp;
- }
- template<typename eT>
- inline
- arma_warn_unused
- bool
- Mat<eT>::const_row_iterator::operator!=(const typename Mat<eT>::row_iterator& X) const
- {
- return ( (current_row != X.current_row) || (current_col != X.current_col) );
- }
- template<typename eT>
- inline
- arma_warn_unused
- bool
- Mat<eT>::const_row_iterator::operator==(const typename Mat<eT>::row_iterator& X) const
- {
- return ( (current_row == X.current_row) && (current_col == X.current_col) );
- }
- template<typename eT>
- inline
- arma_warn_unused
- bool
- Mat<eT>::const_row_iterator::operator!=(const typename Mat<eT>::const_row_iterator& X) const
- {
- return ( (current_row != X.current_row) || (current_col != X.current_col) );
- }
- template<typename eT>
- inline
- arma_warn_unused
- bool
- Mat<eT>::const_row_iterator::operator==(const typename Mat<eT>::const_row_iterator& X) const
- {
- return ( (current_row == X.current_row) && (current_col == X.current_col) );
- }
- template<typename eT>
- inline
- Mat<eT>::row_col_iterator::row_col_iterator()
- : M (NULL)
- , current_ptr(NULL)
- , current_col(0 )
- , current_row(0 )
- {
- arma_extra_debug_sigprint();
- // Technically this iterator is invalid (it does not point to a valid element)
- }
- template<typename eT>
- inline
- Mat<eT>::row_col_iterator::row_col_iterator(const row_col_iterator& in_it)
- : M (in_it.M )
- , current_ptr(in_it.current_ptr)
- , current_col(in_it.current_col)
- , current_row(in_it.current_row)
- {
- arma_extra_debug_sigprint();
- }
- template<typename eT>
- inline
- Mat<eT>::row_col_iterator::row_col_iterator(Mat<eT>& in_M, const uword in_row, const uword in_col)
- : M (&in_M )
- , current_ptr(&in_M.at(in_row,in_col))
- , current_col(in_col )
- , current_row(in_row )
- {
- arma_extra_debug_sigprint();
- }
- template<typename eT>
- inline
- arma_warn_unused
- eT&
- Mat<eT>::row_col_iterator::operator*()
- {
- return *current_ptr;
- }
- template<typename eT>
- inline
- typename Mat<eT>::row_col_iterator&
- Mat<eT>::row_col_iterator::operator++()
- {
- if(current_col < M->n_cols)
- {
- current_ptr++;
- current_row++;
-
- // Check to see if we moved a column.
- if(current_row == M->n_rows)
- {
- current_col++;
- current_row = 0;
- }
- }
-
- return *this;
- }
- template<typename eT>
- inline
- arma_warn_unused
- typename Mat<eT>::row_col_iterator
- Mat<eT>::row_col_iterator::operator++(int)
- {
- typename Mat<eT>::row_col_iterator temp(*this);
-
- ++(*this);
-
- return temp;
- }
- template<typename eT>
- inline typename Mat<eT>::row_col_iterator&
- Mat<eT>::row_col_iterator::operator--()
- {
- if(current_row > 0)
- {
- current_ptr--;
- current_row--;
- }
- else
- if(current_col > 0)
- {
- current_ptr--;
- current_col--;
- current_row = M->n_rows - 1;
- }
-
- return *this;
- }
- template<typename eT>
- inline
- arma_warn_unused
- typename Mat<eT>::row_col_iterator
- Mat<eT>::row_col_iterator::operator--(int)
- {
- typename Mat<eT>::row_col_iterator temp(*this);
-
- --(*this);
-
- return temp;
- }
- template<typename eT>
- inline
- arma_warn_unused
- uword
- Mat<eT>::row_col_iterator::row() const
- {
- return current_row;
- }
- template<typename eT>
- inline
- arma_warn_unused
- uword
- Mat<eT>::row_col_iterator::col() const
- {
- return current_col;
- }
- template<typename eT>
- inline
- arma_warn_unused
- bool
- Mat<eT>::row_col_iterator::operator==(const row_col_iterator& rhs) const
- {
- return (current_ptr == rhs.current_ptr);
- }
- template<typename eT>
- inline
- arma_warn_unused
- bool
- Mat<eT>::row_col_iterator::operator!=(const row_col_iterator& rhs) const
- {
- return (current_ptr != rhs.current_ptr);
- }
- template<typename eT>
- inline
- arma_warn_unused
- bool
- Mat<eT>::row_col_iterator::operator==(const const_row_col_iterator& rhs) const
- {
- return (current_ptr == rhs.current_ptr);
- }
- template<typename eT>
- inline
- arma_warn_unused
- bool
- Mat<eT>::row_col_iterator::operator!=(const const_row_col_iterator& rhs) const
- {
- return (current_ptr != rhs.current_ptr);
- }
- template<typename eT>
- inline
- Mat<eT>::const_row_col_iterator::const_row_col_iterator()
- : M (NULL)
- , current_ptr(NULL)
- , current_col(0 )
- , current_row(0 )
- {
- arma_extra_debug_sigprint();
- // Technically this iterator is invalid (it does not point to a valid element)
- }
- template<typename eT>
- inline
- Mat<eT>::const_row_col_iterator::const_row_col_iterator(const row_col_iterator& in_it)
- : M (in_it.M )
- , current_ptr(in_it.current_ptr)
- , current_col(in_it.col() )
- , current_row(in_it.row() )
- {
- arma_extra_debug_sigprint();
- }
- template<typename eT>
- inline
- Mat<eT>::const_row_col_iterator::const_row_col_iterator(const const_row_col_iterator& in_it)
- : M (in_it.M )
- , current_ptr(in_it.current_ptr)
- , current_col(in_it.col() )
- , current_row(in_it.row() )
- {
- arma_extra_debug_sigprint();
- }
- template<typename eT>
- inline
- Mat<eT>::const_row_col_iterator::const_row_col_iterator(const Mat<eT>& in_M, const uword in_row, const uword in_col)
- : M (&in_M )
- , current_ptr(&in_M.at(in_row,in_col))
- , current_col(in_col )
- , current_row(in_row )
- {
- arma_extra_debug_sigprint();
- }
- template<typename eT>
- inline
- arma_warn_unused
- const eT&
- Mat<eT>::const_row_col_iterator::operator*() const
- {
- return *current_ptr;
- }
- template<typename eT>
- inline
- typename Mat<eT>::const_row_col_iterator&
- Mat<eT>::const_row_col_iterator::operator++()
- {
- if(current_col < M->n_cols)
- {
- current_ptr++;
- current_row++;
-
- // Check to see if we moved a column.
- if(current_row == M->n_rows)
- {
- current_col++;
- current_row = 0;
- }
- }
-
- return *this;
- }
- template<typename eT>
- inline
- arma_warn_unused
- typename Mat<eT>::const_row_col_iterator
- Mat<eT>::const_row_col_iterator::operator++(int)
- {
- typename Mat<eT>::const_row_col_iterator temp(*this);
-
- ++(*this);
-
- return temp;
- }
- template<typename eT>
- inline
- typename Mat<eT>::const_row_col_iterator&
- Mat<eT>::const_row_col_iterator::operator--()
- {
- if(current_row > 0)
- {
- current_ptr--;
- current_row--;
- }
- else
- if(current_col > 0)
- {
- current_ptr--;
- current_col--;
- current_row = M->n_rows - 1;
- }
-
- return *this;
- }
- template<typename eT>
- inline
- arma_warn_unused
- typename Mat<eT>::const_row_col_iterator
- Mat<eT>::const_row_col_iterator::operator--(int)
- {
- typename Mat<eT>::const_row_col_iterator temp(*this);
-
- --(*this);
-
- return temp;
- }
- template<typename eT>
- inline
- arma_warn_unused
- uword
- Mat<eT>::const_row_col_iterator::row() const
- {
- return current_row;
- }
- template<typename eT>
- inline
- arma_warn_unused
- uword
- Mat<eT>::const_row_col_iterator::col() const
- {
- return current_col;
- }
- template<typename eT>
- inline
- arma_warn_unused
- bool
- Mat<eT>::const_row_col_iterator::operator==(const const_row_col_iterator& rhs) const
- {
- return (current_ptr == rhs.current_ptr);
- }
- template<typename eT>
- inline
- arma_warn_unused
- bool
- Mat<eT>::const_row_col_iterator::operator!=(const const_row_col_iterator& rhs) const
- {
- return (current_ptr != rhs.current_ptr);
- }
-
- template<typename eT>
- inline
- arma_warn_unused
- bool
- Mat<eT>::const_row_col_iterator::operator==(const row_col_iterator& rhs) const
- {
- return (current_ptr == rhs.current_ptr);
- }
- template<typename eT>
- inline
- arma_warn_unused
- bool
- Mat<eT>::const_row_col_iterator::operator!=(const row_col_iterator& rhs) const
- {
- return (current_ptr != rhs.current_ptr);
- }
- template<typename eT>
- inline
- typename Mat<eT>::iterator
- Mat<eT>::begin()
- {
- arma_extra_debug_sigprint();
-
- return memptr();
- }
- template<typename eT>
- inline
- typename Mat<eT>::const_iterator
- Mat<eT>::begin() const
- {
- arma_extra_debug_sigprint();
-
- return memptr();
- }
- template<typename eT>
- inline
- typename Mat<eT>::const_iterator
- Mat<eT>::cbegin() const
- {
- arma_extra_debug_sigprint();
-
- return memptr();
- }
- template<typename eT>
- inline
- typename Mat<eT>::iterator
- Mat<eT>::end()
- {
- arma_extra_debug_sigprint();
-
- return memptr() + n_elem;
- }
- template<typename eT>
- inline
- typename Mat<eT>::const_iterator
- Mat<eT>::end() const
- {
- arma_extra_debug_sigprint();
-
- return memptr() + n_elem;
- }
- template<typename eT>
- inline
- typename Mat<eT>::const_iterator
- Mat<eT>::cend() const
- {
- arma_extra_debug_sigprint();
-
- return memptr() + n_elem;
- }
- template<typename eT>
- inline
- typename Mat<eT>::col_iterator
- Mat<eT>::begin_col(const uword col_num)
- {
- arma_extra_debug_sigprint();
-
- arma_debug_check( (col_num >= n_cols), "Mat::begin_col(): index out of bounds");
-
- return colptr(col_num);
- }
- template<typename eT>
- inline
- typename Mat<eT>::const_col_iterator
- Mat<eT>::begin_col(const uword col_num) const
- {
- arma_extra_debug_sigprint();
-
- arma_debug_check( (col_num >= n_cols), "Mat::begin_col(): index out of bounds");
-
- return colptr(col_num);
- }
- template<typename eT>
- inline
- typename Mat<eT>::col_iterator
- Mat<eT>::end_col(const uword col_num)
- {
- arma_extra_debug_sigprint();
-
- arma_debug_check( (col_num >= n_cols), "Mat::end_col(): index out of bounds");
-
- return colptr(col_num) + n_rows;
- }
- template<typename eT>
- inline
- typename Mat<eT>::const_col_iterator
- Mat<eT>::end_col(const uword col_num) const
- {
- arma_extra_debug_sigprint();
-
- arma_debug_check( (col_num >= n_cols), "Mat::end_col(): index out of bounds");
-
- return colptr(col_num) + n_rows;
- }
-
- template<typename eT>
- inline
- typename Mat<eT>::row_iterator
- Mat<eT>::begin_row(const uword row_num)
- {
- arma_extra_debug_sigprint();
-
- arma_debug_check( (row_num >= n_rows), "Mat::begin_row(): index out of bounds" );
-
- return typename Mat<eT>::row_iterator(*this, row_num, uword(0));
- }
- template<typename eT>
- inline
- typename Mat<eT>::const_row_iterator
- Mat<eT>::begin_row(const uword row_num) const
- {
- arma_extra_debug_sigprint();
-
- arma_debug_check( (row_num >= n_rows), "Mat::begin_row(): index out of bounds" );
-
- return typename Mat<eT>::const_row_iterator(*this, row_num, uword(0));
- }
- template<typename eT>
- inline
- typename Mat<eT>::row_iterator
- Mat<eT>::end_row(const uword row_num)
- {
- arma_extra_debug_sigprint();
-
- arma_debug_check( (row_num >= n_rows), "Mat::end_row(): index out of bounds" );
-
- return typename Mat<eT>::row_iterator(*this, (row_num + uword(1)), 0);
- }
- template<typename eT>
- inline
- typename Mat<eT>::const_row_iterator
- Mat<eT>::end_row(const uword row_num) const
- {
- arma_extra_debug_sigprint();
-
- arma_debug_check( (row_num >= n_rows), "Mat::end_row(): index out of bounds" );
-
- return typename Mat<eT>::const_row_iterator(*this, (row_num + uword(1)), 0);
- }
- template<typename eT>
- inline
- typename Mat<eT>::row_col_iterator
- Mat<eT>::begin_row_col()
- {
- return row_col_iterator(*this);
- }
- template<typename eT>
- inline
- typename Mat<eT>::const_row_col_iterator
- Mat<eT>::begin_row_col() const
- {
- return const_row_col_iterator(*this);
- }
- template<typename eT>
- inline typename Mat<eT>::row_col_iterator
- Mat<eT>::end_row_col()
- {
- return row_col_iterator(*this, 0, n_cols);
- }
- template<typename eT>
- inline typename Mat<eT>::const_row_col_iterator
- Mat<eT>::end_row_col() const
- {
- return const_row_col_iterator(*this, 0, n_cols);
- }
- //! resets this matrix to an empty matrix
- template<typename eT>
- inline
- void
- Mat<eT>::clear()
- {
- reset();
- }
- //! returns true if the matrix has no elements
- template<typename eT>
- inline
- bool
- Mat<eT>::empty() const
- {
- return (n_elem == 0);
- }
- //! returns the number of elements in this matrix
- template<typename eT>
- inline
- uword
- Mat<eT>::size() const
- {
- return n_elem;
- }
- template<typename eT>
- inline
- eT&
- Mat<eT>::front()
- {
- arma_debug_check( (n_elem == 0), "Mat::front(): matrix is empty" );
-
- return access::rw(mem[0]);
- }
- template<typename eT>
- inline
- const eT&
- Mat<eT>::front() const
- {
- arma_debug_check( (n_elem == 0), "Mat::front(): matrix is empty" );
-
- return mem[0];
- }
- template<typename eT>
- inline
- eT&
- Mat<eT>::back()
- {
- arma_debug_check( (n_elem == 0), "Mat::back(): matrix is empty" );
-
- return access::rw(mem[n_elem-1]);
- }
- template<typename eT>
- inline
- const eT&
- Mat<eT>::back() const
- {
- arma_debug_check( (n_elem == 0), "Mat::back(): matrix is empty" );
-
- return mem[n_elem-1];
- }
- template<typename eT>
- template<uword fixed_n_rows, uword fixed_n_cols>
- arma_inline
- Mat<eT>::fixed<fixed_n_rows, fixed_n_cols>::fixed()
- : Mat<eT>( arma_fixed_indicator(), fixed_n_rows, fixed_n_cols, 0, ((use_extra) ? mem_local_extra : Mat<eT>::mem_local) )
- {
- arma_extra_debug_sigprint_this(this);
- }
- template<typename eT>
- template<uword fixed_n_rows, uword fixed_n_cols>
- arma_inline
- Mat<eT>::fixed<fixed_n_rows, fixed_n_cols>::fixed(const fixed<fixed_n_rows, fixed_n_cols>& X)
- : Mat<eT>( arma_fixed_indicator(), fixed_n_rows, fixed_n_cols, 0, ((use_extra) ? mem_local_extra : Mat<eT>::mem_local) )
- {
- arma_extra_debug_sigprint_this(this);
-
- eT* dest = (use_extra) ? mem_local_extra : mem_local;
- const eT* src = (use_extra) ? X.mem_local_extra : X.mem_local;
-
- arrayops::copy( dest, src, fixed_n_elem );
- }
- template<typename eT>
- template<uword fixed_n_rows, uword fixed_n_cols>
- template<typename fill_type>
- inline
- Mat<eT>::fixed<fixed_n_rows, fixed_n_cols>::fixed(const fill::fill_class<fill_type>&)
- : Mat<eT>( arma_fixed_indicator(), fixed_n_rows, fixed_n_cols, 0, ((use_extra) ? mem_local_extra : Mat<eT>::mem_local) )
- {
- arma_extra_debug_sigprint_this(this);
-
- if(is_same_type<fill_type, fill::fill_zeros>::yes) (*this).zeros();
- if(is_same_type<fill_type, fill::fill_ones >::yes) (*this).ones();
- if(is_same_type<fill_type, fill::fill_eye >::yes) (*this).eye();
- if(is_same_type<fill_type, fill::fill_randu>::yes) (*this).randu();
- if(is_same_type<fill_type, fill::fill_randn>::yes) (*this).randn();
- }
- template<typename eT>
- template<uword fixed_n_rows, uword fixed_n_cols>
- template<typename T1>
- inline
- Mat<eT>::fixed<fixed_n_rows, fixed_n_cols>::fixed(const Base<eT,T1>& A)
- : Mat<eT>( arma_fixed_indicator(), fixed_n_rows, fixed_n_cols, 0, ((use_extra) ? mem_local_extra : Mat<eT>::mem_local) )
- {
- arma_extra_debug_sigprint_this(this);
-
- Mat<eT>::operator=(A.get_ref());
- }
- template<typename eT>
- template<uword fixed_n_rows, uword fixed_n_cols>
- template<typename T1, typename T2>
- inline
- Mat<eT>::fixed<fixed_n_rows, fixed_n_cols>::fixed(const Base<pod_type,T1>& A, const Base<pod_type,T2>& B)
- : Mat<eT>( arma_fixed_indicator(), fixed_n_rows, fixed_n_cols, 0, ((use_extra) ? mem_local_extra : Mat<eT>::mem_local) )
- {
- arma_extra_debug_sigprint_this(this);
-
- Mat<eT>::init(A,B);
- }
- template<typename eT>
- template<uword fixed_n_rows, uword fixed_n_cols>
- inline
- Mat<eT>::fixed<fixed_n_rows, fixed_n_cols>::fixed(const eT* aux_mem)
- : Mat<eT>( arma_fixed_indicator(), fixed_n_rows, fixed_n_cols, 0, ((use_extra) ? mem_local_extra : Mat<eT>::mem_local) )
- {
- arma_extra_debug_sigprint_this(this);
-
- eT* dest = (use_extra) ? mem_local_extra : mem_local;
-
- arrayops::copy( dest, aux_mem, fixed_n_elem );
- }
- template<typename eT>
- template<uword fixed_n_rows, uword fixed_n_cols>
- inline
- Mat<eT>::fixed<fixed_n_rows, fixed_n_cols>::fixed(const char* text)
- : Mat<eT>( arma_fixed_indicator(), fixed_n_rows, fixed_n_cols, 0, ((use_extra) ? mem_local_extra : Mat<eT>::mem_local) )
- {
- arma_extra_debug_sigprint_this(this);
-
- Mat<eT>::operator=(text);
- }
- template<typename eT>
- template<uword fixed_n_rows, uword fixed_n_cols>
- inline
- Mat<eT>::fixed<fixed_n_rows, fixed_n_cols>::fixed(const std::string& text)
- : Mat<eT>( arma_fixed_indicator(), fixed_n_rows, fixed_n_cols, 0, ((use_extra) ? mem_local_extra : Mat<eT>::mem_local) )
- {
- arma_extra_debug_sigprint_this(this);
-
- Mat<eT>::operator=(text);
- }
- #if defined(ARMA_USE_CXX11)
-
- template<typename eT>
- template<uword fixed_n_rows, uword fixed_n_cols>
- inline
- Mat<eT>::fixed<fixed_n_rows, fixed_n_cols>::fixed(const std::initializer_list<eT>& list)
- : Mat<eT>( arma_fixed_indicator(), fixed_n_rows, fixed_n_cols, 0, ((use_extra) ? mem_local_extra : Mat<eT>::mem_local) )
- {
- arma_extra_debug_sigprint_this(this);
-
- (*this).operator=(list);
- }
-
-
-
- template<typename eT>
- template<uword fixed_n_rows, uword fixed_n_cols>
- inline
- Mat<eT>&
- Mat<eT>::fixed<fixed_n_rows, fixed_n_cols>::operator=(const std::initializer_list<eT>& list)
- {
- arma_extra_debug_sigprint();
-
- const uword N = uword(list.size());
-
- arma_debug_check( (N > fixed_n_elem), "Mat::fixed: initialiser list is too long" );
-
- eT* this_mem = (*this).memptr();
-
- arrayops::copy( this_mem, list.begin(), N );
-
- for(uword iq=N; iq < fixed_n_elem; ++iq) { this_mem[iq] = eT(0); }
-
- return *this;
- }
-
-
-
- template<typename eT>
- template<uword fixed_n_rows, uword fixed_n_cols>
- inline
- Mat<eT>::fixed<fixed_n_rows, fixed_n_cols>::fixed(const std::initializer_list< std::initializer_list<eT> >& list)
- : Mat<eT>( arma_fixed_indicator(), fixed_n_rows, fixed_n_cols, 0, ((use_extra) ? mem_local_extra : Mat<eT>::mem_local) )
- {
- arma_extra_debug_sigprint_this(this);
-
- Mat<eT>::init(list);
- }
-
-
-
- template<typename eT>
- template<uword fixed_n_rows, uword fixed_n_cols>
- inline
- Mat<eT>&
- Mat<eT>::fixed<fixed_n_rows, fixed_n_cols>::operator=(const std::initializer_list< std::initializer_list<eT> >& list)
- {
- arma_extra_debug_sigprint();
-
- Mat<eT>::init(list);
-
- return *this;
- }
-
- #endif
- template<typename eT>
- template<uword fixed_n_rows, uword fixed_n_cols>
- arma_inline
- Mat<eT>&
- Mat<eT>::fixed<fixed_n_rows, fixed_n_cols>::operator=(const fixed<fixed_n_rows, fixed_n_cols>& X)
- {
- arma_extra_debug_sigprint();
-
- if(this != &X)
- {
- eT* dest = (use_extra) ? mem_local_extra : mem_local;
- const eT* src = (use_extra) ? X.mem_local_extra : X.mem_local;
-
- arrayops::copy( dest, src, fixed_n_elem );
- }
-
- return *this;
- }
- #if defined(ARMA_GOOD_COMPILER)
-
- template<typename eT>
- template<uword fixed_n_rows, uword fixed_n_cols>
- template<typename T1, typename eop_type>
- inline
- Mat<eT>&
- Mat<eT>::fixed<fixed_n_rows, fixed_n_cols>::operator=(const eOp<T1, eop_type>& X)
- {
- arma_extra_debug_sigprint();
-
- arma_type_check(( is_same_type< eT, typename T1::elem_type >::no ));
-
- const bool bad_alias = (eOp<T1, eop_type>::proxy_type::has_subview && X.P.is_alias(*this));
-
- if(bad_alias == false)
- {
- arma_debug_assert_same_size(fixed_n_rows, fixed_n_cols, X.get_n_rows(), X.get_n_cols(), "Mat::fixed::operator=");
-
- eop_type::apply(*this, X);
- }
- else
- {
- arma_extra_debug_print("bad_alias = true");
-
- Mat<eT> tmp(X);
-
- (*this) = tmp;
- }
-
- return *this;
- }
-
-
-
- template<typename eT>
- template<uword fixed_n_rows, uword fixed_n_cols>
- template<typename T1, typename T2, typename eglue_type>
- inline
- Mat<eT>&
- Mat<eT>::fixed<fixed_n_rows, fixed_n_cols>::operator=(const eGlue<T1, T2, eglue_type>& X)
- {
- arma_extra_debug_sigprint();
-
- arma_type_check(( is_same_type< eT, typename T1::elem_type >::no ));
- arma_type_check(( is_same_type< eT, typename T2::elem_type >::no ));
-
- const bool bad_alias =
- (
- (eGlue<T1, T2, eglue_type>::proxy1_type::has_subview && X.P1.is_alias(*this))
- ||
- (eGlue<T1, T2, eglue_type>::proxy2_type::has_subview && X.P2.is_alias(*this))
- );
-
- if(bad_alias == false)
- {
- arma_debug_assert_same_size(fixed_n_rows, fixed_n_cols, X.get_n_rows(), X.get_n_cols(), "Mat::fixed::operator=");
-
- eglue_type::apply(*this, X);
- }
- else
- {
- arma_extra_debug_print("bad_alias = true");
-
- Mat<eT> tmp(X);
-
- (*this) = tmp;
- }
-
- return *this;
- }
-
- #endif
- template<typename eT>
- template<uword fixed_n_rows, uword fixed_n_cols>
- arma_inline
- const Op< typename Mat<eT>::template fixed<fixed_n_rows, fixed_n_cols>::Mat_fixed_type, op_htrans >
- Mat<eT>::fixed<fixed_n_rows, fixed_n_cols>::t() const
- {
- return Op< typename Mat<eT>::template fixed<fixed_n_rows, fixed_n_cols>::Mat_fixed_type, op_htrans >(*this);
- }
- template<typename eT>
- template<uword fixed_n_rows, uword fixed_n_cols>
- arma_inline
- const Op< typename Mat<eT>::template fixed<fixed_n_rows, fixed_n_cols>::Mat_fixed_type, op_htrans >
- Mat<eT>::fixed<fixed_n_rows, fixed_n_cols>::ht() const
- {
- return Op< typename Mat<eT>::template fixed<fixed_n_rows, fixed_n_cols>::Mat_fixed_type, op_htrans >(*this);
- }
- template<typename eT>
- template<uword fixed_n_rows, uword fixed_n_cols>
- arma_inline
- const Op< typename Mat<eT>::template fixed<fixed_n_rows, fixed_n_cols>::Mat_fixed_type, op_strans >
- Mat<eT>::fixed<fixed_n_rows, fixed_n_cols>::st() const
- {
- return Op< typename Mat<eT>::template fixed<fixed_n_rows, fixed_n_cols>::Mat_fixed_type, op_strans >(*this);
- }
- template<typename eT>
- template<uword fixed_n_rows, uword fixed_n_cols>
- arma_inline
- arma_warn_unused
- const eT&
- Mat<eT>::fixed<fixed_n_rows, fixed_n_cols>::at_alt(const uword ii) const
- {
- #if defined(ARMA_HAVE_ALIGNED_ATTRIBUTE)
-
- return (use_extra) ? mem_local_extra[ii] : mem_local[ii];
-
- #else
- const eT* mem_aligned = (use_extra) ? mem_local_extra : mem_local;
-
- memory::mark_as_aligned(mem_aligned);
-
- return mem_aligned[ii];
- #endif
- }
- template<typename eT>
- template<uword fixed_n_rows, uword fixed_n_cols>
- arma_inline
- arma_warn_unused
- eT&
- Mat<eT>::fixed<fixed_n_rows, fixed_n_cols>::operator[] (const uword ii)
- {
- return (use_extra) ? mem_local_extra[ii] : mem_local[ii];
- }
- template<typename eT>
- template<uword fixed_n_rows, uword fixed_n_cols>
- arma_inline
- arma_warn_unused
- const eT&
- Mat<eT>::fixed<fixed_n_rows, fixed_n_cols>::operator[] (const uword ii) const
- {
- return (use_extra) ? mem_local_extra[ii] : mem_local[ii];
- }
- template<typename eT>
- template<uword fixed_n_rows, uword fixed_n_cols>
- arma_inline
- arma_warn_unused
- eT&
- Mat<eT>::fixed<fixed_n_rows, fixed_n_cols>::at(const uword ii)
- {
- return (use_extra) ? mem_local_extra[ii] : mem_local[ii];
- }
- template<typename eT>
- template<uword fixed_n_rows, uword fixed_n_cols>
- arma_inline
- arma_warn_unused
- const eT&
- Mat<eT>::fixed<fixed_n_rows, fixed_n_cols>::at(const uword ii) const
- {
- return (use_extra) ? mem_local_extra[ii] : mem_local[ii];
- }
- template<typename eT>
- template<uword fixed_n_rows, uword fixed_n_cols>
- arma_inline
- arma_warn_unused
- eT&
- Mat<eT>::fixed<fixed_n_rows, fixed_n_cols>::operator() (const uword ii)
- {
- arma_debug_check( (ii >= fixed_n_elem), "Mat::operator(): index out of bounds");
-
- return (use_extra) ? mem_local_extra[ii] : mem_local[ii];
- }
- template<typename eT>
- template<uword fixed_n_rows, uword fixed_n_cols>
- arma_inline
- arma_warn_unused
- const eT&
- Mat<eT>::fixed<fixed_n_rows, fixed_n_cols>::operator() (const uword ii) const
- {
- arma_debug_check( (ii >= fixed_n_elem), "Mat::operator(): index out of bounds");
-
- return (use_extra) ? mem_local_extra[ii] : mem_local[ii];
- }
- template<typename eT>
- template<uword fixed_n_rows, uword fixed_n_cols>
- arma_inline
- arma_warn_unused
- eT&
- Mat<eT>::fixed<fixed_n_rows, fixed_n_cols>::at(const uword in_row, const uword in_col)
- {
- const uword iq = in_row + in_col*fixed_n_rows;
-
- return (use_extra) ? mem_local_extra[iq] : mem_local[iq];
- }
- template<typename eT>
- template<uword fixed_n_rows, uword fixed_n_cols>
- arma_inline
- arma_warn_unused
- const eT&
- Mat<eT>::fixed<fixed_n_rows, fixed_n_cols>::at(const uword in_row, const uword in_col) const
- {
- const uword iq = in_row + in_col*fixed_n_rows;
-
- return (use_extra) ? mem_local_extra[iq] : mem_local[iq];
- }
- template<typename eT>
- template<uword fixed_n_rows, uword fixed_n_cols>
- arma_inline
- arma_warn_unused
- eT&
- Mat<eT>::fixed<fixed_n_rows, fixed_n_cols>::operator() (const uword in_row, const uword in_col)
- {
- arma_debug_check( ((in_row >= fixed_n_rows) || (in_col >= fixed_n_cols)), "Mat::operator(): index out of bounds");
-
- const uword iq = in_row + in_col*fixed_n_rows;
-
- return (use_extra) ? mem_local_extra[iq] : mem_local[iq];
- }
- template<typename eT>
- template<uword fixed_n_rows, uword fixed_n_cols>
- arma_inline
- arma_warn_unused
- const eT&
- Mat<eT>::fixed<fixed_n_rows, fixed_n_cols>::operator() (const uword in_row, const uword in_col) const
- {
- arma_debug_check( ((in_row >= fixed_n_rows) || (in_col >= fixed_n_cols)), "Mat::operator(): index out of bounds");
-
- const uword iq = in_row + in_col*fixed_n_rows;
-
- return (use_extra) ? mem_local_extra[iq] : mem_local[iq];
- }
- template<typename eT>
- template<uword fixed_n_rows, uword fixed_n_cols>
- arma_inline
- arma_warn_unused
- eT*
- Mat<eT>::fixed<fixed_n_rows, fixed_n_cols>::colptr(const uword in_col)
- {
- eT* mem_actual = (use_extra) ? mem_local_extra : mem_local;
-
- return & access::rw(mem_actual[in_col*fixed_n_rows]);
- }
- template<typename eT>
- template<uword fixed_n_rows, uword fixed_n_cols>
- arma_inline
- arma_warn_unused
- const eT*
- Mat<eT>::fixed<fixed_n_rows, fixed_n_cols>::colptr(const uword in_col) const
- {
- const eT* mem_actual = (use_extra) ? mem_local_extra : mem_local;
-
- return & mem_actual[in_col*fixed_n_rows];
- }
- template<typename eT>
- template<uword fixed_n_rows, uword fixed_n_cols>
- arma_inline
- arma_warn_unused
- eT*
- Mat<eT>::fixed<fixed_n_rows, fixed_n_cols>::memptr()
- {
- return (use_extra) ? mem_local_extra : mem_local;
- }
- template<typename eT>
- template<uword fixed_n_rows, uword fixed_n_cols>
- arma_inline
- arma_warn_unused
- const eT*
- Mat<eT>::fixed<fixed_n_rows, fixed_n_cols>::memptr() const
- {
- return (use_extra) ? mem_local_extra : mem_local;
- }
- template<typename eT>
- template<uword fixed_n_rows, uword fixed_n_cols>
- arma_inline
- arma_warn_unused
- bool
- Mat<eT>::fixed<fixed_n_rows, fixed_n_cols>::is_vec() const
- {
- return ( (fixed_n_rows == 1) || (fixed_n_cols == 1) );
- }
- template<typename eT>
- template<uword fixed_n_rows, uword fixed_n_cols>
- inline
- const Mat<eT>&
- Mat<eT>::fixed<fixed_n_rows, fixed_n_cols>::fill(const eT val)
- {
- arma_extra_debug_sigprint();
-
- eT* mem_use = (use_extra) ? &(mem_local_extra[0]) : &(mem_local[0]);
-
- arrayops::inplace_set_fixed<eT,fixed_n_elem>( mem_use, val );
-
- return *this;
- }
- template<typename eT>
- template<uword fixed_n_rows, uword fixed_n_cols>
- inline
- const Mat<eT>&
- Mat<eT>::fixed<fixed_n_rows, fixed_n_cols>::zeros()
- {
- arma_extra_debug_sigprint();
-
- eT* mem_use = (use_extra) ? &(mem_local_extra[0]) : &(mem_local[0]);
-
- arrayops::inplace_set_fixed<eT,fixed_n_elem>( mem_use, eT(0) );
-
- return *this;
- }
- template<typename eT>
- template<uword fixed_n_rows, uword fixed_n_cols>
- inline
- const Mat<eT>&
- Mat<eT>::fixed<fixed_n_rows, fixed_n_cols>::ones()
- {
- arma_extra_debug_sigprint();
-
- eT* mem_use = (use_extra) ? &(mem_local_extra[0]) : &(mem_local[0]);
-
- arrayops::inplace_set_fixed<eT,fixed_n_elem>( mem_use, eT(1) );
-
- return *this;
- }
- //! prefix ++
- template<typename eT>
- inline
- void
- Mat_aux::prefix_pp(Mat<eT>& x)
- {
- eT* memptr = x.memptr();
- const uword n_elem = x.n_elem;
-
- uword i,j;
- for(i=0, j=1; j<n_elem; i+=2, j+=2)
- {
- ++(memptr[i]);
- ++(memptr[j]);
- }
-
- if(i < n_elem)
- {
- ++(memptr[i]);
- }
- }
- //! prefix ++ for complex numbers (work around for limitations of the std::complex class)
- template<typename T>
- inline
- void
- Mat_aux::prefix_pp(Mat< std::complex<T> >& x)
- {
- x += T(1);
- }
- //! postfix ++
- template<typename eT>
- inline
- void
- Mat_aux::postfix_pp(Mat<eT>& x)
- {
- eT* memptr = x.memptr();
- const uword n_elem = x.n_elem;
-
- uword i,j;
-
- for(i=0, j=1; j<n_elem; i+=2, j+=2)
- {
- (memptr[i])++;
- (memptr[j])++;
- }
-
- if(i < n_elem)
- {
- (memptr[i])++;
- }
- }
- //! postfix ++ for complex numbers (work around for limitations of the std::complex class)
- template<typename T>
- inline
- void
- Mat_aux::postfix_pp(Mat< std::complex<T> >& x)
- {
- x += T(1);
- }
- //! prefix --
- template<typename eT>
- inline
- void
- Mat_aux::prefix_mm(Mat<eT>& x)
- {
- eT* memptr = x.memptr();
- const uword n_elem = x.n_elem;
- uword i,j;
- for(i=0, j=1; j<n_elem; i+=2, j+=2)
- {
- --(memptr[i]);
- --(memptr[j]);
- }
-
- if(i < n_elem)
- {
- --(memptr[i]);
- }
- }
- //! prefix -- for complex numbers (work around for limitations of the std::complex class)
- template<typename T>
- inline
- void
- Mat_aux::prefix_mm(Mat< std::complex<T> >& x)
- {
- x -= T(1);
- }
- //! postfix --
- template<typename eT>
- inline
- void
- Mat_aux::postfix_mm(Mat<eT>& x)
- {
- eT* memptr = x.memptr();
- const uword n_elem = x.n_elem;
- uword i,j;
- for(i=0, j=1; j<n_elem; i+=2, j+=2)
- {
- (memptr[i])--;
- (memptr[j])--;
- }
-
- if(i < n_elem)
- {
- (memptr[i])--;
- }
- }
- //! postfix ++ for complex numbers (work around for limitations of the std::complex class)
- template<typename T>
- inline
- void
- Mat_aux::postfix_mm(Mat< std::complex<T> >& x)
- {
- x -= T(1);
- }
- template<typename eT, typename T1>
- inline
- void
- Mat_aux::set_real(Mat<eT>& out, const Base<eT,T1>& X)
- {
- arma_extra_debug_sigprint();
-
- const unwrap<T1> tmp(X.get_ref());
- const Mat<eT>& A = tmp.M;
-
- arma_debug_assert_same_size( out, A, "Mat::set_real()" );
-
- out = A;
- }
- template<typename eT, typename T1>
- inline
- void
- Mat_aux::set_imag(Mat<eT>&, const Base<eT,T1>&)
- {
- arma_extra_debug_sigprint();
- }
- template<typename T, typename T1>
- inline
- void
- Mat_aux::set_real(Mat< std::complex<T> >& out, const Base<T,T1>& X)
- {
- arma_extra_debug_sigprint();
-
- typedef typename std::complex<T> eT;
-
- const Proxy<T1> P(X.get_ref());
-
- const uword local_n_rows = P.get_n_rows();
- const uword local_n_cols = P.get_n_cols();
-
- arma_debug_assert_same_size( out.n_rows, out.n_cols, local_n_rows, local_n_cols, "Mat::set_real()" );
-
- eT* out_mem = out.memptr();
-
- if(Proxy<T1>::use_at == false)
- {
- typedef typename Proxy<T1>::ea_type ea_type;
-
- ea_type A = P.get_ea();
-
- const uword N = out.n_elem;
-
- for(uword i=0; i<N; ++i)
- {
- out_mem[i] = std::complex<T>( A[i], out_mem[i].imag() );
- }
- }
- else
- {
- for(uword col=0; col < local_n_cols; ++col)
- for(uword row=0; row < local_n_rows; ++row)
- {
- (*out_mem) = std::complex<T>( P.at(row,col), (*out_mem).imag() );
- out_mem++;
- }
- }
- }
- template<typename T, typename T1>
- inline
- void
- Mat_aux::set_imag(Mat< std::complex<T> >& out, const Base<T,T1>& X)
- {
- arma_extra_debug_sigprint();
-
- typedef typename std::complex<T> eT;
-
- const Proxy<T1> P(X.get_ref());
-
- const uword local_n_rows = P.get_n_rows();
- const uword local_n_cols = P.get_n_cols();
-
- arma_debug_assert_same_size( out.n_rows, out.n_cols, local_n_rows, local_n_cols, "Mat::set_imag()" );
-
- eT* out_mem = out.memptr();
-
- if(Proxy<T1>::use_at == false)
- {
- typedef typename Proxy<T1>::ea_type ea_type;
-
- ea_type A = P.get_ea();
-
- const uword N = out.n_elem;
-
- for(uword i=0; i<N; ++i)
- {
- out_mem[i] = std::complex<T>( out_mem[i].real(), A[i] );
- }
- }
- else
- {
- for(uword col=0; col < local_n_cols; ++col)
- for(uword row=0; row < local_n_rows; ++row)
- {
- (*out_mem) = std::complex<T>( (*out_mem).real(), P.at(row,col) );
- out_mem++;
- }
- }
- }
- #ifdef ARMA_EXTRA_MAT_MEAT
- #include ARMA_INCFILE_WRAP(ARMA_EXTRA_MAT_MEAT)
- #endif
- //! @}
|