12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702 |
- // 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 Cube
- //! @{
- template<typename eT>
- inline
- Cube<eT>::~Cube()
- {
- arma_extra_debug_sigprint_this(this);
-
- delete_mat();
-
- if( (mem_state == 0) && (n_elem > Cube_prealloc::mem_n_elem) )
- {
- arma_extra_debug_print("Cube::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;
- access::rw(mat_ptrs) = 0;
- }
-
- arma_type_check(( is_supported_elem_type<eT>::value == false ));
- }
- template<typename eT>
- inline
- Cube<eT>::Cube()
- : n_rows(0)
- , n_cols(0)
- , n_elem_slice(0)
- , n_slices(0)
- , n_elem(0)
- , mem_state(0)
- , mem()
- , mat_ptrs(0)
- {
- arma_extra_debug_sigprint_this(this);
- }
- //! construct the cube to have user specified dimensions
- template<typename eT>
- inline
- Cube<eT>::Cube(const uword in_n_rows, const uword in_n_cols, const uword in_n_slices)
- : n_rows(in_n_rows)
- , n_cols(in_n_cols)
- , n_elem_slice(in_n_rows*in_n_cols)
- , n_slices(in_n_slices)
- , n_elem(in_n_rows*in_n_cols*in_n_slices)
- , mem_state(0)
- , mem()
- , mat_ptrs(0)
- {
- arma_extra_debug_sigprint_this(this);
-
- init_cold();
- }
- template<typename eT>
- inline
- Cube<eT>::Cube(const SizeCube& s)
- : n_rows(s.n_rows)
- , n_cols(s.n_cols)
- , n_elem_slice(s.n_rows*s.n_cols)
- , n_slices(s.n_slices)
- , n_elem(s.n_rows*s.n_cols*s.n_slices)
- , mem_state(0)
- , mem()
- , mat_ptrs(0)
- {
- arma_extra_debug_sigprint_this(this);
-
- init_cold();
- }
- //! construct the cube to have user specified dimensions and fill with specified pattern
- template<typename eT>
- template<typename fill_type>
- inline
- Cube<eT>::Cube(const uword in_n_rows, const uword in_n_cols, const uword in_n_slices, const fill::fill_class<fill_type>&)
- : n_rows(in_n_rows)
- , n_cols(in_n_cols)
- , n_elem_slice(in_n_rows*in_n_cols)
- , n_slices(in_n_slices)
- , n_elem(in_n_rows*in_n_cols*in_n_slices)
- , mem_state(0)
- , mem()
- , mat_ptrs(0)
- {
- arma_extra_debug_sigprint_this(this);
-
- init_cold();
-
- 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_randu>::yes) (*this).randu();
- if(is_same_type<fill_type, fill::fill_randn>::yes) (*this).randn();
-
- if(is_same_type<fill_type, fill::fill_eye >::yes) { arma_debug_check(true, "Cube::Cube(): unsupported fill type"); }
- }
- template<typename eT>
- template<typename fill_type>
- inline
- Cube<eT>::Cube(const SizeCube& s, const fill::fill_class<fill_type>&)
- : n_rows(s.n_rows)
- , n_cols(s.n_cols)
- , n_elem_slice(s.n_rows*s.n_cols)
- , n_slices(s.n_slices)
- , n_elem(s.n_rows*s.n_cols*s.n_slices)
- , mem_state(0)
- , mem()
- , mat_ptrs(0)
- {
- arma_extra_debug_sigprint_this(this);
-
- init_cold();
-
- 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_randu>::yes) (*this).randu();
- if(is_same_type<fill_type, fill::fill_randn>::yes) (*this).randn();
-
- if(is_same_type<fill_type, fill::fill_eye >::yes) { arma_debug_check(true, "Cube::Cube(): unsupported fill type"); }
- }
- #if defined(ARMA_USE_CXX11)
-
- template<typename eT>
- inline
- Cube<eT>::Cube(Cube<eT>&& in_cube)
- : n_rows(0)
- , n_cols(0)
- , n_elem_slice(0)
- , n_slices(0)
- , n_elem(0)
- , mem_state(0)
- , mem()
- , mat_ptrs(0)
- {
- arma_extra_debug_sigprint_this(this);
- arma_extra_debug_sigprint(arma_str::format("this = %x in_cube = %x") % this % &in_cube);
-
- (*this).steal_mem(in_cube);
- }
-
-
-
- template<typename eT>
- inline
- Cube<eT>&
- Cube<eT>::operator=(Cube<eT>&& in_cube)
- {
- arma_extra_debug_sigprint(arma_str::format("this = %x in_cube = %x") % this % &in_cube);
-
- (*this).steal_mem(in_cube);
-
- return *this;
- }
-
- #endif
- template<typename eT>
- inline
- void
- Cube<eT>::init_cold()
- {
- arma_extra_debug_sigprint( arma_str::format("n_rows = %d, n_cols = %d, n_slices = %d") % n_rows % n_cols % n_slices );
-
- #if defined(ARMA_64BIT_WORD)
- const char* error_message = "Cube::init(): requested size is too large";
- #else
- const char* error_message = "Cube::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 > 0x0FFF) || (n_cols > 0x0FFF) || (n_slices > 0xFF) )
- ? ( (double(n_rows) * double(n_cols) * double(n_slices)) > double(ARMA_MAX_UWORD) )
- : false
- ),
- error_message
- );
-
-
- if(n_elem <= Cube_prealloc::mem_n_elem)
- {
- if(n_elem == 0)
- {
- access::rw(mem) = NULL;
- }
- else
- {
- arma_extra_debug_print("Cube::init(): using local memory");
- access::rw(mem) = mem_local;
- }
- }
- else
- {
- arma_extra_debug_print("Cube::init(): acquiring memory");
- access::rw(mem) = memory::acquire<eT>(n_elem);
- }
-
- create_mat();
- }
- template<typename eT>
- inline
- void
- Cube<eT>::init_warm(const uword in_n_rows, const uword in_n_cols, const uword in_n_slices)
- {
- arma_extra_debug_sigprint( arma_str::format("in_n_rows = %d, in_n_cols = %d, in_n_slices = %d") % in_n_rows % in_n_cols % in_n_slices );
-
- if( (n_rows == in_n_rows) && (n_cols == in_n_cols) && (n_slices == in_n_slices) ) { return; }
-
- const uword t_mem_state = mem_state;
-
- bool err_state = false;
- char* err_msg = 0;
-
- arma_debug_set_error( err_state, err_msg, (t_mem_state == 3), "Cube::init(): size is fixed and hence cannot be changed" );
-
- #if defined(ARMA_64BIT_WORD)
- const char* error_message = "Cube::init(): requested size is too large";
- #else
- const char* error_message = "Cube::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 > 0x0FFF) || (in_n_cols > 0x0FFF) || (in_n_slices > 0xFF) )
- ? ( (double(in_n_rows) * double(in_n_cols) * double(in_n_slices)) > 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 * in_n_slices;
-
- if(old_n_elem == new_n_elem)
- {
- arma_extra_debug_print("Cube::init(): reusing memory");
-
- delete_mat();
-
- access::rw(n_rows) = in_n_rows;
- access::rw(n_cols) = in_n_cols;
- access::rw(n_elem_slice) = in_n_rows*in_n_cols;
- access::rw(n_slices) = in_n_slices;
-
- create_mat();
- }
- else // condition: old_n_elem != new_n_elem
- {
- arma_debug_check( (t_mem_state == 2), "Cube::init(): requested size is not compatible with the size of auxiliary memory" );
-
- delete_mat();
-
- if(new_n_elem < old_n_elem) // reuse existing memory if possible
- {
- if( (t_mem_state == 0) && (new_n_elem <= Cube_prealloc::mem_n_elem) )
- {
- if(old_n_elem > Cube_prealloc::mem_n_elem)
- {
- arma_extra_debug_print("Cube::init(): releasing memory");
- memory::release( access::rw(mem) );
- }
-
- if(new_n_elem == 0)
- {
- access::rw(mem) = NULL;
- }
- else
- {
- arma_extra_debug_print("Cube::init(): using local memory");
- access::rw(mem) = mem_local;
- }
- }
- else
- {
- arma_extra_debug_print("Cube::init(): reusing memory");
- }
- }
- else // condition: new_n_elem > old_n_elem
- {
- if( (t_mem_state == 0) && (old_n_elem > Cube_prealloc::mem_n_elem) )
- {
- arma_extra_debug_print("Cube::init(): releasing memory");
- memory::release( access::rw(mem) );
- }
-
- if(new_n_elem <= Cube_prealloc::mem_n_elem)
- {
- arma_extra_debug_print("Cube::init(): using local memory");
- access::rw(mem) = mem_local;
- }
- else
- {
- arma_extra_debug_print("Cube::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_slice) = in_n_rows*in_n_cols;
- access::rw(n_slices) = in_n_slices;
- access::rw(n_elem) = new_n_elem;
-
- create_mat();
- }
- }
- //! for constructing a complex cube out of two non-complex cubes
- template<typename eT>
- template<typename T1, typename T2>
- inline
- void
- Cube<eT>::init
- (
- const BaseCube<typename Cube<eT>::pod_type,T1>& X,
- const BaseCube<typename Cube<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 ProxyCube<T1> PX(X.get_ref());
- const ProxyCube<T2> PY(Y.get_ref());
-
- arma_debug_assert_same_size(PX, PY, "Cube()");
-
- const uword local_n_rows = PX.get_n_rows();
- const uword local_n_cols = PX.get_n_cols();
- const uword local_n_slices = PX.get_n_slices();
-
- init_warm(local_n_rows, local_n_cols, local_n_slices);
-
- eT* out_mem = (*this).memptr();
-
- const bool use_at = ( ProxyCube<T1>::use_at || ProxyCube<T2>::use_at );
-
- if(use_at == false)
- {
- typedef typename ProxyCube<T1>::ea_type ea_type1;
- typedef typename ProxyCube<T2>::ea_type ea_type2;
-
- const uword N = n_elem;
-
- ea_type1 A = PX.get_ea();
- ea_type2 B = PY.get_ea();
-
- for(uword i=0; i<N; ++i)
- {
- out_mem[i] = std::complex<T>(A[i], B[i]);
- }
- }
- else
- {
- for(uword uslice = 0; uslice < local_n_slices; ++uslice)
- 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,uslice), PY.at(urow,ucol,uslice) );
- out_mem++;
- }
- }
- }
- template<typename eT>
- inline
- void
- Cube<eT>::delete_mat()
- {
- arma_extra_debug_sigprint();
-
- if((n_slices > 0) && (mat_ptrs != NULL))
- {
- for(uword uslice = 0; uslice < n_slices; ++uslice)
- {
- if(mat_ptrs[uslice] != NULL) { delete access::rw(mat_ptrs[uslice]); }
- }
-
- if( (mem_state <= 2) && (n_slices > Cube_prealloc::mat_ptrs_size) )
- {
- delete [] mat_ptrs;
- }
- }
- }
- template<typename eT>
- inline
- void
- Cube<eT>::create_mat()
- {
- arma_extra_debug_sigprint();
-
- if(n_slices == 0)
- {
- access::rw(mat_ptrs) = NULL;
- }
- else
- {
- if(mem_state <= 2)
- {
- if(n_slices <= Cube_prealloc::mat_ptrs_size)
- {
- access::rw(mat_ptrs) = const_cast< const Mat<eT>** >(mat_ptrs_local);
- }
- else
- {
- access::rw(mat_ptrs) = new(std::nothrow) const Mat<eT>*[n_slices];
-
- arma_check_bad_alloc( (mat_ptrs == 0), "Cube::create_mat(): out of memory" );
- }
- }
-
- for(uword uslice = 0; uslice < n_slices; ++uslice)
- {
- mat_ptrs[uslice] = NULL;
- }
- }
- }
- //! Set the cube to be equal to the specified scalar.
- //! NOTE: the size of the cube will be 1x1x1
- template<typename eT>
- inline
- Cube<eT>&
- Cube<eT>::operator=(const eT val)
- {
- arma_extra_debug_sigprint();
-
- init_warm(1,1,1);
- access::rw(mem[0]) = val;
- return *this;
- }
- //! In-place addition of a scalar to all elements of the cube
- template<typename eT>
- inline
- Cube<eT>&
- Cube<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 cube
- template<typename eT>
- inline
- Cube<eT>&
- Cube<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 cube with a scalar
- template<typename eT>
- inline
- Cube<eT>&
- Cube<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 cube with a scalar
- template<typename eT>
- inline
- Cube<eT>&
- Cube<eT>::operator/=(const eT val)
- {
- arma_extra_debug_sigprint();
-
- arrayops::inplace_div( memptr(), val, n_elem );
-
- return *this;
- }
- //! construct a cube from a given cube
- template<typename eT>
- inline
- Cube<eT>::Cube(const Cube<eT>& x)
- : n_rows(x.n_rows)
- , n_cols(x.n_cols)
- , n_elem_slice(x.n_elem_slice)
- , n_slices(x.n_slices)
- , n_elem(x.n_elem)
- , mem_state(0)
- , mem()
- , mat_ptrs(0)
- {
- arma_extra_debug_sigprint_this(this);
- arma_extra_debug_sigprint(arma_str::format("this = %x in_cube = %x") % this % &x);
-
- init_cold();
-
- arrayops::copy( memptr(), x.mem, n_elem );
- }
- //! construct a cube from a given cube
- template<typename eT>
- inline
- Cube<eT>&
- Cube<eT>::operator=(const Cube<eT>& x)
- {
- arma_extra_debug_sigprint(arma_str::format("this = %x in_cube = %x") % this % &x);
-
- if(this != &x)
- {
- init_warm(x.n_rows, x.n_cols, x.n_slices);
-
- arrayops::copy( memptr(), x.mem, n_elem );
- }
-
- return *this;
- }
- //! construct a cube 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).
- template<typename eT>
- inline
- Cube<eT>::Cube(eT* aux_mem, const uword aux_n_rows, const uword aux_n_cols, const uword aux_n_slices, const bool copy_aux_mem, const bool strict, const bool prealloc_mat)
- : n_rows ( aux_n_rows )
- , n_cols ( aux_n_cols )
- , n_elem_slice( aux_n_rows*aux_n_cols )
- , n_slices ( aux_n_slices )
- , n_elem ( aux_n_rows*aux_n_cols*aux_n_slices )
- , mem_state ( copy_aux_mem ? 0 : (strict ? 2 : 1) )
- , mem ( copy_aux_mem ? 0 : aux_mem )
- , mat_ptrs ( 0 )
- {
- arma_extra_debug_sigprint_this(this);
-
- if(prealloc_mat == true) { arma_debug_warn("Cube::Cube(): parameter 'prealloc_mat' ignored as it's no longer used"); }
-
- if(copy_aux_mem == true)
- {
- init_cold();
-
- arrayops::copy( memptr(), aux_mem, n_elem );
- }
- else
- {
- create_mat();
- }
- }
- //! construct a cube from a given auxiliary read-only array of eTs.
- //! the array is copied.
- template<typename eT>
- inline
- Cube<eT>::Cube(const eT* aux_mem, const uword aux_n_rows, const uword aux_n_cols, const uword aux_n_slices)
- : n_rows(aux_n_rows)
- , n_cols(aux_n_cols)
- , n_elem_slice(aux_n_rows*aux_n_cols)
- , n_slices(aux_n_slices)
- , n_elem(aux_n_rows*aux_n_cols*aux_n_slices)
- , mem_state(0)
- , mem()
- , mat_ptrs(0)
- {
- arma_extra_debug_sigprint_this(this);
-
- init_cold();
-
- arrayops::copy( memptr(), aux_mem, n_elem );
- }
- //! in-place cube addition
- template<typename eT>
- inline
- Cube<eT>&
- Cube<eT>::operator+=(const Cube<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 cube subtraction
- template<typename eT>
- inline
- Cube<eT>&
- Cube<eT>::operator-=(const Cube<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 element-wise cube multiplication
- template<typename eT>
- inline
- Cube<eT>&
- Cube<eT>::operator%=(const Cube<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 cube division
- template<typename eT>
- inline
- Cube<eT>&
- Cube<eT>::operator/=(const Cube<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;
- }
- //! for constructing a complex cube out of two non-complex cubes
- template<typename eT>
- template<typename T1, typename T2>
- inline
- Cube<eT>::Cube
- (
- const BaseCube<typename Cube<eT>::pod_type,T1>& A,
- const BaseCube<typename Cube<eT>::pod_type,T2>& B
- )
- : n_rows(0)
- , n_cols(0)
- , n_elem_slice(0)
- , n_slices(0)
- , n_elem(0)
- , mem_state(0)
- , mem()
- , mat_ptrs(0)
- {
- arma_extra_debug_sigprint_this(this);
-
- init(A,B);
- }
- //! construct a cube from a subview_cube instance (e.g. construct a cube from a delayed subcube operation)
- template<typename eT>
- inline
- Cube<eT>::Cube(const subview_cube<eT>& X)
- : n_rows(X.n_rows)
- , n_cols(X.n_cols)
- , n_elem_slice(X.n_elem_slice)
- , n_slices(X.n_slices)
- , n_elem(X.n_elem)
- , mem_state(0)
- , mem()
- , mat_ptrs(0)
- {
- arma_extra_debug_sigprint_this(this);
-
- init_cold();
-
- subview_cube<eT>::extract(*this, X);
- }
- //! construct a cube from a subview_cube instance (e.g. construct a cube from a delayed subcube operation)
- template<typename eT>
- inline
- Cube<eT>&
- Cube<eT>::operator=(const subview_cube<eT>& X)
- {
- arma_extra_debug_sigprint();
-
- const bool alias = (this == &(X.m));
-
- if(alias == false)
- {
- init_warm(X.n_rows, X.n_cols, X.n_slices);
-
- subview_cube<eT>::extract(*this, X);
- }
- else
- {
- Cube<eT> tmp(X);
-
- steal_mem(tmp);
- }
-
- return *this;
- }
- //! in-place cube addition (using a subcube on the right-hand-side)
- template<typename eT>
- inline
- Cube<eT>&
- Cube<eT>::operator+=(const subview_cube<eT>& X)
- {
- arma_extra_debug_sigprint();
-
- subview_cube<eT>::plus_inplace(*this, X);
-
- return *this;
- }
- //! in-place cube subtraction (using a subcube on the right-hand-side)
- template<typename eT>
- inline
- Cube<eT>&
- Cube<eT>::operator-=(const subview_cube<eT>& X)
- {
- arma_extra_debug_sigprint();
-
- subview_cube<eT>::minus_inplace(*this, X);
-
- return *this;
- }
- //! in-place element-wise cube mutiplication (using a subcube on the right-hand-side)
- template<typename eT>
- inline
- Cube<eT>&
- Cube<eT>::operator%=(const subview_cube<eT>& X)
- {
- arma_extra_debug_sigprint();
-
- subview_cube<eT>::schur_inplace(*this, X);
-
- return *this;
- }
- //! in-place element-wise cube division (using a subcube on the right-hand-side)
- template<typename eT>
- inline
- Cube<eT>&
- Cube<eT>::operator/=(const subview_cube<eT>& X)
- {
- arma_extra_debug_sigprint();
-
- subview_cube<eT>::div_inplace(*this, X);
-
- return *this;
- }
- template<typename eT>
- template<typename T1>
- inline
- Cube<eT>::Cube(const subview_cube_slices<eT,T1>& X)
- : n_rows(0)
- , n_cols(0)
- , n_elem_slice(0)
- , n_slices(0)
- , n_elem(0)
- , mem_state(0)
- , mem()
- , mat_ptrs(0)
- {
- arma_extra_debug_sigprint_this(this);
-
- subview_cube_slices<eT,T1>::extract(*this, X);
- }
- template<typename eT>
- template<typename T1>
- inline
- Cube<eT>&
- Cube<eT>::operator=(const subview_cube_slices<eT,T1>& X)
- {
- arma_extra_debug_sigprint();
-
- const bool alias = (this == &(X.m));
-
- if(alias == false)
- {
- subview_cube_slices<eT,T1>::extract(*this, X);
- }
- else
- {
- Cube<eT> tmp(X);
-
- steal_mem(tmp);
- }
-
- return *this;
- }
- template<typename eT>
- template<typename T1>
- inline
- Cube<eT>&
- Cube<eT>::operator+=(const subview_cube_slices<eT,T1>& X)
- {
- arma_extra_debug_sigprint();
-
- subview_cube_slices<eT,T1>::plus_inplace(*this, X);
-
- return *this;
- }
- template<typename eT>
- template<typename T1>
- inline
- Cube<eT>&
- Cube<eT>::operator-=(const subview_cube_slices<eT,T1>& X)
- {
- arma_extra_debug_sigprint();
-
- subview_cube_slices<eT,T1>::minus_inplace(*this, X);
-
- return *this;
- }
- template<typename eT>
- template<typename T1>
- inline
- Cube<eT>&
- Cube<eT>::operator%=(const subview_cube_slices<eT,T1>& X)
- {
- arma_extra_debug_sigprint();
-
- subview_cube_slices<eT,T1>::schur_inplace(*this, X);
-
- return *this;
- }
- template<typename eT>
- template<typename T1>
- inline
- Cube<eT>&
- Cube<eT>::operator/=(const subview_cube_slices<eT,T1>& X)
- {
- arma_extra_debug_sigprint();
-
- subview_cube_slices<eT,T1>::div_inplace(*this, X);
-
- return *this;
- }
- //! creation of subview_cube (subcube comprised of specified row)
- template<typename eT>
- arma_inline
- subview_cube<eT>
- Cube<eT>::row(const uword in_row)
- {
- arma_extra_debug_sigprint();
-
- arma_debug_check( (in_row >= n_rows), "Cube::row(): index out of bounds" );
-
- return (*this).rows(in_row, in_row);
- }
- //! creation of subview_cube (subcube comprised of specified row)
- template<typename eT>
- arma_inline
- const subview_cube<eT>
- Cube<eT>::row(const uword in_row) const
- {
- arma_extra_debug_sigprint();
-
- arma_debug_check( (in_row >= n_rows), "Cube::row(): index out of bounds" );
-
- return (*this).rows(in_row, in_row);
- }
- //! creation of subview_cube (subcube comprised of specified column)
- template<typename eT>
- arma_inline
- subview_cube<eT>
- Cube<eT>::col(const uword in_col)
- {
- arma_extra_debug_sigprint();
-
- arma_debug_check( (in_col >= n_cols), "Cube::col(): index out of bounds" );
-
- return (*this).cols(in_col, in_col);
- }
- //! creation of subview_cube (subcube comprised of specified column)
- template<typename eT>
- arma_inline
- const subview_cube<eT>
- Cube<eT>::col(const uword in_col) const
- {
- arma_extra_debug_sigprint();
-
- arma_debug_check( (in_col >= n_cols), "Cube::col(): index out of bounds" );
-
- return (*this).cols(in_col, in_col);
- }
- //! provide the reference to the matrix representing a single slice
- template<typename eT>
- inline
- Mat<eT>&
- Cube<eT>::slice(const uword in_slice)
- {
- arma_extra_debug_sigprint();
-
- arma_debug_check( (in_slice >= n_slices), "Cube::slice(): index out of bounds" );
-
- if(mat_ptrs[in_slice] == NULL)
- {
- const eT* ptr = (n_elem_slice > 0) ? slice_memptr(in_slice) : NULL;
-
- mat_ptrs[in_slice] = new Mat<eT>('j', ptr, n_rows, n_cols);
- }
-
- return const_cast< Mat<eT>& >( *(mat_ptrs[in_slice]) );
- }
- //! provide the reference to the matrix representing a single slice
- template<typename eT>
- inline
- const Mat<eT>&
- Cube<eT>::slice(const uword in_slice) const
- {
- arma_extra_debug_sigprint();
-
- arma_debug_check( (in_slice >= n_slices), "Cube::slice(): index out of bounds" );
-
- if(mat_ptrs[in_slice] == NULL)
- {
- const eT* ptr = (n_elem_slice > 0) ? slice_memptr(in_slice) : NULL;
-
- mat_ptrs[in_slice] = new Mat<eT>('j', ptr, n_rows, n_cols);
- }
-
- return *(mat_ptrs[in_slice]);
- }
- //! creation of subview_cube (subcube comprised of specified rows)
- template<typename eT>
- arma_inline
- subview_cube<eT>
- Cube<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),
- "Cube::rows(): indices out of bounds or incorrectly used"
- );
-
- const uword subcube_n_rows = in_row2 - in_row1 + 1;
-
- return subview_cube<eT>(*this, in_row1, 0, 0, subcube_n_rows, n_cols, n_slices);
- }
- //! creation of subview_cube (subcube comprised of specified rows)
- template<typename eT>
- arma_inline
- const subview_cube<eT>
- Cube<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),
- "Cube::rows(): indices out of bounds or incorrectly used"
- );
-
- const uword subcube_n_rows = in_row2 - in_row1 + 1;
-
- return subview_cube<eT>(*this, in_row1, 0, 0, subcube_n_rows, n_cols, n_slices);
- }
- //! creation of subview_cube (subcube comprised of specified columns)
- template<typename eT>
- arma_inline
- subview_cube<eT>
- Cube<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),
- "Cube::cols(): indices out of bounds or incorrectly used"
- );
-
- const uword subcube_n_cols = in_col2 - in_col1 + 1;
-
- return subview_cube<eT>(*this, 0, in_col1, 0, n_rows, subcube_n_cols, n_slices);
- }
- //! creation of subview_cube (subcube comprised of specified columns)
- template<typename eT>
- arma_inline
- const subview_cube<eT>
- Cube<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),
- "Cube::cols(): indices out of bounds or incorrectly used"
- );
-
- const uword subcube_n_cols = in_col2 - in_col1 + 1;
-
- return subview_cube<eT>(*this, 0, in_col1, 0, n_rows, subcube_n_cols, n_slices);
- }
- //! creation of subview_cube (subcube comprised of specified slices)
- template<typename eT>
- arma_inline
- subview_cube<eT>
- Cube<eT>::slices(const uword in_slice1, const uword in_slice2)
- {
- arma_extra_debug_sigprint();
-
- arma_debug_check
- (
- (in_slice1 > in_slice2) || (in_slice2 >= n_slices),
- "Cube::slices(): indices out of bounds or incorrectly used"
- );
-
- const uword subcube_n_slices = in_slice2 - in_slice1 + 1;
-
- return subview_cube<eT>(*this, 0, 0, in_slice1, n_rows, n_cols, subcube_n_slices);
- }
- //! creation of subview_cube (subcube comprised of specified slices)
- template<typename eT>
- arma_inline
- const subview_cube<eT>
- Cube<eT>::slices(const uword in_slice1, const uword in_slice2) const
- {
- arma_extra_debug_sigprint();
-
- arma_debug_check
- (
- (in_slice1 > in_slice2) || (in_slice2 >= n_slices),
- "Cube::slices(): indices out of bounds or incorrectly used"
- );
-
- const uword subcube_n_slices = in_slice2 - in_slice1 + 1;
-
- return subview_cube<eT>(*this, 0, 0, in_slice1, n_rows, n_cols, subcube_n_slices);
- }
- //! creation of subview_cube (generic subcube)
- template<typename eT>
- arma_inline
- subview_cube<eT>
- Cube<eT>::subcube(const uword in_row1, const uword in_col1, const uword in_slice1, const uword in_row2, const uword in_col2, const uword in_slice2)
- {
- arma_extra_debug_sigprint();
-
- arma_debug_check
- (
- (in_row1 > in_row2) || (in_col1 > in_col2) || (in_slice1 > in_slice2) ||
- (in_row2 >= n_rows) || (in_col2 >= n_cols) || (in_slice2 >= n_slices),
- "Cube::subcube(): indices out of bounds or incorrectly used"
- );
-
- const uword subcube_n_rows = in_row2 - in_row1 + 1;
- const uword subcube_n_cols = in_col2 - in_col1 + 1;
- const uword subcube_n_slices = in_slice2 - in_slice1 + 1;
-
- return subview_cube<eT>(*this, in_row1, in_col1, in_slice1, subcube_n_rows, subcube_n_cols, subcube_n_slices);
- }
- //! creation of subview_cube (generic subcube)
- template<typename eT>
- arma_inline
- const subview_cube<eT>
- Cube<eT>::subcube(const uword in_row1, const uword in_col1, const uword in_slice1, const uword in_row2, const uword in_col2, const uword in_slice2) const
- {
- arma_extra_debug_sigprint();
-
- arma_debug_check
- (
- (in_row1 > in_row2) || (in_col1 > in_col2) || (in_slice1 > in_slice2) ||
- (in_row2 >= n_rows) || (in_col2 >= n_cols) || (in_slice2 >= n_slices),
- "Cube::subcube(): indices out of bounds or incorrectly used"
- );
-
- const uword subcube_n_rows = in_row2 - in_row1 + 1;
- const uword subcube_n_cols = in_col2 - in_col1 + 1;
- const uword subcube_n_slices = in_slice2 - in_slice1 + 1;
-
- return subview_cube<eT>(*this, in_row1, in_col1, in_slice1, subcube_n_rows, subcube_n_cols, subcube_n_slices);
- }
- //! creation of subview_cube (generic subcube)
- template<typename eT>
- inline
- subview_cube<eT>
- Cube<eT>::subcube(const uword in_row1, const uword in_col1, const uword in_slice1, const SizeCube& s)
- {
- arma_extra_debug_sigprint();
-
- const uword l_n_rows = n_rows;
- const uword l_n_cols = n_cols;
- const uword l_n_slices = n_slices;
-
- const uword s_n_rows = s.n_rows;
- const uword s_n_cols = s.n_cols;
- const uword s_n_slices = s.n_slices;
-
- arma_debug_check
- (
- ( in_row1 >= l_n_rows) || ( in_col1 >= l_n_cols) || ( in_slice1 >= l_n_slices)
- || ((in_row1 + s_n_rows) > l_n_rows) || ((in_col1 + s_n_cols) > l_n_cols) || ((in_slice1 + s_n_slices) > l_n_slices),
- "Cube::subcube(): indices or size out of bounds"
- );
-
- return subview_cube<eT>(*this, in_row1, in_col1, in_slice1, s_n_rows, s_n_cols, s_n_slices);
- }
- //! creation of subview_cube (generic subcube)
- template<typename eT>
- inline
- const subview_cube<eT>
- Cube<eT>::subcube(const uword in_row1, const uword in_col1, const uword in_slice1, const SizeCube& s) const
- {
- arma_extra_debug_sigprint();
-
- const uword l_n_rows = n_rows;
- const uword l_n_cols = n_cols;
- const uword l_n_slices = n_slices;
-
- const uword s_n_rows = s.n_rows;
- const uword s_n_cols = s.n_cols;
- const uword s_n_slices = s.n_slices;
-
- arma_debug_check
- (
- ( in_row1 >= l_n_rows) || ( in_col1 >= l_n_cols) || ( in_slice1 >= l_n_slices)
- || ((in_row1 + s_n_rows) > l_n_rows) || ((in_col1 + s_n_cols) > l_n_cols) || ((in_slice1 + s_n_slices) > l_n_slices),
- "Cube::subcube(): indices or size out of bounds"
- );
-
- return subview_cube<eT>(*this, in_row1, in_col1, in_slice1, s_n_rows, s_n_cols, s_n_slices);
- }
- //! creation of subview_cube (generic subcube)
- template<typename eT>
- inline
- subview_cube<eT>
- Cube<eT>::subcube(const span& row_span, const span& col_span, const span& slice_span)
- {
- arma_extra_debug_sigprint();
-
- const bool row_all = row_span.whole;
- const bool col_all = col_span.whole;
- const bool slice_all = slice_span.whole;
-
- const uword local_n_rows = n_rows;
- const uword local_n_cols = n_cols;
- const uword local_n_slices = n_slices;
-
- const uword in_row1 = row_all ? 0 : row_span.a;
- const uword in_row2 = row_span.b;
- const uword subcube_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 subcube_n_cols = col_all ? local_n_cols : in_col2 - in_col1 + 1;
-
- const uword in_slice1 = slice_all ? 0 : slice_span.a;
- const uword in_slice2 = slice_span.b;
- const uword subcube_n_slices = slice_all ? local_n_slices : in_slice2 - in_slice1 + 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)) )
- ||
- ( slice_all ? false : ((in_slice1 > in_slice2) || (in_slice2 >= local_n_slices)) )
- ,
- "Cube::subcube(): indices out of bounds or incorrectly used"
- );
-
- return subview_cube<eT>(*this, in_row1, in_col1, in_slice1, subcube_n_rows, subcube_n_cols, subcube_n_slices);
- }
- //! creation of subview_cube (generic subcube)
- template<typename eT>
- inline
- const subview_cube<eT>
- Cube<eT>::subcube(const span& row_span, const span& col_span, const span& slice_span) const
- {
- arma_extra_debug_sigprint();
-
- const bool row_all = row_span.whole;
- const bool col_all = col_span.whole;
- const bool slice_all = slice_span.whole;
-
- const uword local_n_rows = n_rows;
- const uword local_n_cols = n_cols;
- const uword local_n_slices = n_slices;
-
- const uword in_row1 = row_all ? 0 : row_span.a;
- const uword in_row2 = row_span.b;
- const uword subcube_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 subcube_n_cols = col_all ? local_n_cols : in_col2 - in_col1 + 1;
-
- const uword in_slice1 = slice_all ? 0 : slice_span.a;
- const uword in_slice2 = slice_span.b;
- const uword subcube_n_slices = slice_all ? local_n_slices : in_slice2 - in_slice1 + 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)) )
- ||
- ( slice_all ? false : ((in_slice1 > in_slice2) || (in_slice2 >= local_n_slices)) )
- ,
- "Cube::subcube(): indices out of bounds or incorrectly used"
- );
-
- return subview_cube<eT>(*this, in_row1, in_col1, in_slice1, subcube_n_rows, subcube_n_cols, subcube_n_slices);
- }
- template<typename eT>
- inline
- subview_cube<eT>
- Cube<eT>::operator()(const span& row_span, const span& col_span, const span& slice_span)
- {
- arma_extra_debug_sigprint();
-
- return (*this).subcube(row_span, col_span, slice_span);
- }
- template<typename eT>
- inline
- const subview_cube<eT>
- Cube<eT>::operator()(const span& row_span, const span& col_span, const span& slice_span) const
- {
- arma_extra_debug_sigprint();
-
- return (*this).subcube(row_span, col_span, slice_span);
- }
- template<typename eT>
- inline
- subview_cube<eT>
- Cube<eT>::operator()(const uword in_row1, const uword in_col1, const uword in_slice1, const SizeCube& s)
- {
- arma_extra_debug_sigprint();
-
- return (*this).subcube(in_row1, in_col1, in_slice1, s);
- }
- template<typename eT>
- inline
- const subview_cube<eT>
- Cube<eT>::operator()(const uword in_row1, const uword in_col1, const uword in_slice1, const SizeCube& s) const
- {
- arma_extra_debug_sigprint();
-
- return (*this).subcube(in_row1, in_col1, in_slice1, s);
- }
- template<typename eT>
- arma_inline
- subview_cube<eT>
- Cube<eT>::tube(const uword in_row1, const uword in_col1)
- {
- arma_extra_debug_sigprint();
-
- arma_debug_check
- (
- ((in_row1 >= n_rows) || (in_col1 >= n_cols)),
- "Cube::tube(): indices out of bounds"
- );
-
- return subview_cube<eT>(*this, in_row1, in_col1, 0, 1, 1, n_slices);
- }
- template<typename eT>
- arma_inline
- const subview_cube<eT>
- Cube<eT>::tube(const uword in_row1, const uword in_col1) const
- {
- arma_extra_debug_sigprint();
-
- arma_debug_check
- (
- ((in_row1 >= n_rows) || (in_col1 >= n_cols)),
- "Cube::tube(): indices out of bounds"
- );
-
- return subview_cube<eT>(*this, in_row1, in_col1, 0, 1, 1, n_slices);
- }
- template<typename eT>
- arma_inline
- subview_cube<eT>
- Cube<eT>::tube(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),
- "Cube::tube(): indices out of bounds or incorrectly used"
- );
-
- const uword subcube_n_rows = in_row2 - in_row1 + 1;
- const uword subcube_n_cols = in_col2 - in_col1 + 1;
-
- return subview_cube<eT>(*this, in_row1, in_col1, 0, subcube_n_rows, subcube_n_cols, n_slices);
- }
- template<typename eT>
- arma_inline
- const subview_cube<eT>
- Cube<eT>::tube(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),
- "Cube::tube(): indices out of bounds or incorrectly used"
- );
-
- const uword subcube_n_rows = in_row2 - in_row1 + 1;
- const uword subcube_n_cols = in_col2 - in_col1 + 1;
-
- return subview_cube<eT>(*this, in_row1, in_col1, 0, subcube_n_rows, subcube_n_cols, n_slices);
- }
- template<typename eT>
- arma_inline
- subview_cube<eT>
- Cube<eT>::tube(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)),
- "Cube::tube(): indices or size out of bounds"
- );
-
- return subview_cube<eT>(*this, in_row1, in_col1, 0, s_n_rows, s_n_cols, n_slices);
- }
- template<typename eT>
- arma_inline
- const subview_cube<eT>
- Cube<eT>::tube(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)),
- "Cube::tube(): indices or size out of bounds"
- );
-
- return subview_cube<eT>(*this, in_row1, in_col1, 0, s_n_rows, s_n_cols, n_slices);
- }
- template<typename eT>
- inline
- subview_cube<eT>
- Cube<eT>::tube(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 subcube_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 subcube_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)) )
- ,
- "Cube::tube(): indices out of bounds or incorrectly used"
- );
-
- return subview_cube<eT>(*this, in_row1, in_col1, 0, subcube_n_rows, subcube_n_cols, n_slices);
- }
- template<typename eT>
- inline
- const subview_cube<eT>
- Cube<eT>::tube(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 subcube_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 subcube_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)) )
- ,
- "Cube::tube(): indices out of bounds or incorrectly used"
- );
-
- return subview_cube<eT>(*this, in_row1, in_col1, 0, subcube_n_rows, subcube_n_cols, n_slices);
- }
- template<typename eT>
- inline
- subview_cube<eT>
- Cube<eT>::head_slices(const uword N)
- {
- arma_extra_debug_sigprint();
-
- arma_debug_check( (N > n_slices), "Cube::head_slices(): size out of bounds" );
-
- return subview_cube<eT>(*this, 0, 0, 0, n_rows, n_cols, N);
- }
- template<typename eT>
- inline
- const subview_cube<eT>
- Cube<eT>::head_slices(const uword N) const
- {
- arma_extra_debug_sigprint();
-
- arma_debug_check( (N > n_slices), "Cube::head_slices(): size out of bounds" );
-
- return subview_cube<eT>(*this, 0, 0, 0, n_rows, n_cols, N);
- }
- template<typename eT>
- inline
- subview_cube<eT>
- Cube<eT>::tail_slices(const uword N)
- {
- arma_extra_debug_sigprint();
-
- arma_debug_check( (N > n_slices), "Cube::tail_slices(): size out of bounds" );
-
- const uword start_slice = n_slices - N;
-
- return subview_cube<eT>(*this, 0, 0, start_slice, n_rows, n_cols, N);
- }
- template<typename eT>
- inline
- const subview_cube<eT>
- Cube<eT>::tail_slices(const uword N) const
- {
- arma_extra_debug_sigprint();
-
- arma_debug_check( (N > n_slices), "Cube::tail_slices(): size out of bounds" );
-
- const uword start_slice = n_slices - N;
-
- return subview_cube<eT>(*this, 0, 0, start_slice, n_rows, n_cols, N);
- }
- template<typename eT>
- template<typename T1>
- arma_inline
- subview_elem1<eT,T1>
- Cube<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>
- Cube<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>
- Cube<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>
- Cube<eT>::operator()(const Base<uword,T1>& a) const
- {
- arma_extra_debug_sigprint();
-
- return subview_elem1<eT,T1>(*this, a);
- }
- template<typename eT>
- arma_inline
- subview_cube_each1<eT>
- Cube<eT>::each_slice()
- {
- arma_extra_debug_sigprint();
-
- return subview_cube_each1<eT>(*this);
- }
- template<typename eT>
- arma_inline
- const subview_cube_each1<eT>
- Cube<eT>::each_slice() const
- {
- arma_extra_debug_sigprint();
-
- return subview_cube_each1<eT>(*this);
- }
- template<typename eT>
- template<typename T1>
- inline
- subview_cube_each2<eT, T1>
- Cube<eT>::each_slice(const Base<uword, T1>& indices)
- {
- arma_extra_debug_sigprint();
-
- return subview_cube_each2<eT, T1>(*this, indices);
- }
- template<typename eT>
- template<typename T1>
- inline
- const subview_cube_each2<eT, T1>
- Cube<eT>::each_slice(const Base<uword, T1>& indices) const
- {
- arma_extra_debug_sigprint();
-
- return subview_cube_each2<eT, T1>(*this, indices);
- }
- #if defined(ARMA_USE_CXX11)
-
- //! apply a lambda function to each slice, where each slice is interpreted as a matrix
- template<typename eT>
- inline
- const Cube<eT>&
- Cube<eT>::each_slice(const std::function< void(Mat<eT>&) >& F)
- {
- arma_extra_debug_sigprint();
-
- for(uword slice_id=0; slice_id < n_slices; ++slice_id)
- {
- Mat<eT> tmp('j', slice_memptr(slice_id), n_rows, n_cols);
-
- F(tmp);
- }
-
- return *this;
- }
-
-
-
- template<typename eT>
- inline
- const Cube<eT>&
- Cube<eT>::each_slice(const std::function< void(const Mat<eT>&) >& F) const
- {
- arma_extra_debug_sigprint();
-
- for(uword slice_id=0; slice_id < n_slices; ++slice_id)
- {
- const Mat<eT> tmp('j', slice_memptr(slice_id), n_rows, n_cols);
-
- F(tmp);
- }
-
- return *this;
- }
-
-
-
- template<typename eT>
- inline
- const Cube<eT>&
- Cube<eT>::each_slice(const std::function< void(Mat<eT>&) >& F, const bool use_mp)
- {
- arma_extra_debug_sigprint();
-
- if((use_mp == false) || (arma_config::openmp == false))
- {
- return (*this).each_slice(F);
- }
-
- #if defined(ARMA_USE_OPENMP)
- {
- const uword local_n_slices = n_slices;
- const int n_threads = mp_thread_limit::get();
-
- #pragma omp parallel for schedule(static) num_threads(n_threads)
- for(uword slice_id=0; slice_id < local_n_slices; ++slice_id)
- {
- Mat<eT> tmp('j', slice_memptr(slice_id), n_rows, n_cols);
-
- F(tmp);
- }
- }
- #endif
-
- return *this;
- }
-
-
-
- template<typename eT>
- inline
- const Cube<eT>&
- Cube<eT>::each_slice(const std::function< void(const Mat<eT>&) >& F, const bool use_mp) const
- {
- arma_extra_debug_sigprint();
-
- if((use_mp == false) || (arma_config::openmp == false))
- {
- return (*this).each_slice(F);
- }
-
- #if defined(ARMA_USE_OPENMP)
- {
- const uword local_n_slices = n_slices;
- const int n_threads = mp_thread_limit::get();
-
- #pragma omp parallel for schedule(static) num_threads(n_threads)
- for(uword slice_id=0; slice_id < local_n_slices; ++slice_id)
- {
- Mat<eT> tmp('j', slice_memptr(slice_id), n_rows, n_cols);
-
- F(tmp);
- }
- }
- #endif
-
- return *this;
- }
- #endif
- template<typename eT>
- template<typename T1>
- inline
- subview_cube_slices<eT, T1>
- Cube<eT>::slices(const Base<uword, T1>& indices)
- {
- arma_extra_debug_sigprint();
-
- return subview_cube_slices<eT, T1>(*this, indices);
- }
- template<typename eT>
- template<typename T1>
- inline
- const subview_cube_slices<eT, T1>
- Cube<eT>::slices(const Base<uword, T1>& indices) const
- {
- arma_extra_debug_sigprint();
-
- return subview_cube_slices<eT, T1>(*this, indices);
- }
- //! remove specified row
- template<typename eT>
- inline
- void
- Cube<eT>::shed_row(const uword row_num)
- {
- arma_extra_debug_sigprint();
-
- arma_debug_check( row_num >= n_rows, "Cube::shed_row(): index out of bounds");
-
- shed_rows(row_num, row_num);
- }
- //! remove specified column
- template<typename eT>
- inline
- void
- Cube<eT>::shed_col(const uword col_num)
- {
- arma_extra_debug_sigprint();
-
- arma_debug_check( col_num >= n_cols, "Cube::shed_col(): index out of bounds");
-
- shed_cols(col_num, col_num);
- }
- //! remove specified slice
- template<typename eT>
- inline
- void
- Cube<eT>::shed_slice(const uword slice_num)
- {
- arma_extra_debug_sigprint();
-
- arma_debug_check( slice_num >= n_slices, "Cube::shed_slice(): index out of bounds");
-
- shed_slices(slice_num, slice_num);
- }
- //! remove specified rows
- template<typename eT>
- inline
- void
- Cube<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),
- "Cube::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);
-
- Cube<eT> X(n_keep_front + n_keep_back, n_cols, n_slices);
-
- 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
- Cube<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),
- "Cube::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);
-
- Cube<eT> X(n_rows, n_keep_front + n_keep_back, n_slices);
-
- 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 slices
- template<typename eT>
- inline
- void
- Cube<eT>::shed_slices(const uword in_slice1, const uword in_slice2)
- {
- arma_extra_debug_sigprint();
-
- arma_debug_check
- (
- (in_slice1 > in_slice2) || (in_slice2 >= n_slices),
- "Cube::shed_slices(): indices out of bounds or incorrectly used"
- );
-
- const uword n_keep_front = in_slice1;
- const uword n_keep_back = n_slices - (in_slice2 + 1);
-
- Cube<eT> X(n_rows, n_cols, n_keep_front + n_keep_back);
-
- if(n_keep_front > 0)
- {
- X.slices( 0, (n_keep_front-1) ) = slices( 0, (in_slice1-1) );
- }
-
- if(n_keep_back > 0)
- {
- X.slices( n_keep_front, (n_keep_front+n_keep_back-1) ) = slices( (in_slice2+1), (n_slices-1) );
- }
-
- steal_mem(X);
- }
- //! remove specified slices
- template<typename eT>
- template<typename T1>
- inline
- void
- Cube<eT>::shed_slices(const Base<uword, T1>& indices)
- {
- arma_extra_debug_sigprint();
-
- const quasi_unwrap<T1> U(indices.get_ref());
- const Mat<uword>& tmp1 = U.M;
-
- arma_debug_check( ((tmp1.is_vec() == false) && (tmp1.is_empty() == false)), "Cube::shed_slices(): 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>& slices_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* slices_to_shed_mem = slices_to_shed.memptr();
- const uword N = slices_to_shed.n_elem;
-
- if(arma_config::debug)
- {
- for(uword i=0; i<N; ++i)
- {
- arma_debug_check( (slices_to_shed_mem[i] >= n_slices), "Cube::shed_slices(): indices out of bounds" );
- }
- }
-
- Col<uword> tmp3(n_slices);
-
- uword* tmp3_mem = tmp3.memptr();
-
- uword i = 0;
- uword count = 0;
-
- for(uword j=0; j < n_slices; ++j)
- {
- if(i < N)
- {
- if( j != slices_to_shed_mem[i] )
- {
- tmp3_mem[count] = j;
- ++count;
- }
- else
- {
- ++i;
- }
- }
- else
- {
- tmp3_mem[count] = j;
- ++count;
- }
- }
-
- const Col<uword> slices_to_keep(tmp3.memptr(), count, false, false);
-
- Cube<eT> X = (*this).slices(slices_to_keep);
-
- steal_mem(X);
- }
- template<typename eT>
- inline
- void
- Cube<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 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), "Cube::insert_rows(): index out of bounds");
-
- if(N > 0)
- {
- Cube<eT> out(t_n_rows + N, n_cols, n_slices);
-
- 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 == true)
- {
- out.rows(row_num, row_num + N - 1).zeros();
- }
-
- steal_mem(out);
- }
- }
- template<typename eT>
- inline
- void
- Cube<eT>::insert_cols(const uword col_num, const uword N, const bool set_to_zero)
- {
- arma_extra_debug_sigprint();
-
- 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), "Cube::insert_cols(): index out of bounds");
-
- if(N > 0)
- {
- Cube<eT> out(n_rows, t_n_cols + N, n_slices);
-
- 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 == true)
- {
- out.cols(col_num, col_num + N - 1).zeros();
- }
-
- steal_mem(out);
- }
- }
- //! insert N slices at the specified slice position,
- //! optionally setting the elements of the inserted slices to zero
- template<typename eT>
- inline
- void
- Cube<eT>::insert_slices(const uword slice_num, const uword N, const bool set_to_zero)
- {
- arma_extra_debug_sigprint();
-
- const uword t_n_slices = n_slices;
-
- const uword A_n_slices = slice_num;
- const uword B_n_slices = t_n_slices - slice_num;
-
- // insertion at slice_num == n_slices is in effect an append operation
- arma_debug_check( (slice_num > t_n_slices), "Cube::insert_slices(): index out of bounds");
-
- if(N > 0)
- {
- Cube<eT> out(n_rows, n_cols, t_n_slices + N);
-
- if(A_n_slices > 0)
- {
- out.slices(0, A_n_slices-1) = slices(0, A_n_slices-1);
- }
-
- if(B_n_slices > 0)
- {
- out.slices(slice_num + N, t_n_slices + N - 1) = slices(slice_num, t_n_slices-1);
- }
-
- if(set_to_zero == true)
- {
- //out.slices(slice_num, slice_num + N - 1).zeros();
-
- for(uword i=slice_num; i < (slice_num + N); ++i)
- {
- arrayops::fill_zeros(out.slice_memptr(i), out.n_elem_slice);
- }
- }
-
- steal_mem(out);
- }
- }
- template<typename eT>
- template<typename T1>
- inline
- void
- Cube<eT>::insert_rows(const uword row_num, const BaseCube<eT,T1>& X)
- {
- arma_extra_debug_sigprint();
-
- const unwrap_cube<T1> tmp(X.get_ref());
- const Cube<eT>& C = tmp.M;
-
- const uword N = C.n_rows;
-
- const uword t_n_rows = n_rows;
-
- 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), "Cube::insert_rows(): index out of bounds");
-
- arma_debug_check
- (
- ( (C.n_cols != n_cols) || (C.n_slices != n_slices) ),
- "Cube::insert_rows(): given object has incompatible dimensions"
- );
-
- if(N > 0)
- {
- Cube<eT> out(t_n_rows + N, n_cols, n_slices);
-
- 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);
- }
-
- out.rows(row_num, row_num + N - 1) = C;
-
- steal_mem(out);
- }
- }
- template<typename eT>
- template<typename T1>
- inline
- void
- Cube<eT>::insert_cols(const uword col_num, const BaseCube<eT,T1>& X)
- {
- arma_extra_debug_sigprint();
-
- const unwrap_cube<T1> tmp(X.get_ref());
- const Cube<eT>& C = tmp.M;
-
- const uword N = C.n_cols;
-
- 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), "Cube::insert_cols(): index out of bounds");
-
- arma_debug_check
- (
- ( (C.n_rows != n_rows) || (C.n_slices != n_slices) ),
- "Cube::insert_cols(): given object has incompatible dimensions"
- );
-
- if(N > 0)
- {
- Cube<eT> out(n_rows, t_n_cols + N, n_slices);
-
- 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);
- }
-
- out.cols(col_num, col_num + N - 1) = C;
-
- steal_mem(out);
- }
- }
- //! insert the given object at the specified slice position;
- //! the given object must have the same number of rows and columns as the cube
- template<typename eT>
- template<typename T1>
- inline
- void
- Cube<eT>::insert_slices(const uword slice_num, const BaseCube<eT,T1>& X)
- {
- arma_extra_debug_sigprint();
-
- const unwrap_cube<T1> tmp(X.get_ref());
- const Cube<eT>& C = tmp.M;
-
- const uword N = C.n_slices;
-
- const uword t_n_slices = n_slices;
-
- const uword A_n_slices = slice_num;
- const uword B_n_slices = t_n_slices - slice_num;
-
- // insertion at slice_num == n_slices is in effect an append operation
- arma_debug_check( (slice_num > t_n_slices), "Cube::insert_slices(): index out of bounds");
-
- arma_debug_check
- (
- ( (C.n_rows != n_rows) || (C.n_cols != n_cols) ),
- "Cube::insert_slices(): given object has incompatible dimensions"
- );
-
- if(N > 0)
- {
- Cube<eT> out(n_rows, n_cols, t_n_slices + N);
-
- if(A_n_slices > 0)
- {
- out.slices(0, A_n_slices-1) = slices(0, A_n_slices-1);
- }
-
- if(B_n_slices > 0)
- {
- out.slices(slice_num + N, t_n_slices + N - 1) = slices(slice_num, t_n_slices - 1);
- }
-
- out.slices(slice_num, slice_num + N - 1) = C;
-
- steal_mem(out);
- }
- }
- //! create a cube from GenCube, i.e. run the previously delayed element generation operations
- template<typename eT>
- template<typename gen_type>
- inline
- Cube<eT>::Cube(const GenCube<eT, gen_type>& X)
- : n_rows(X.n_rows)
- , n_cols(X.n_cols)
- , n_elem_slice(X.n_rows*X.n_cols)
- , n_slices(X.n_slices)
- , n_elem(X.n_rows*X.n_cols*X.n_slices)
- , mem_state(0)
- , mem()
- , mat_ptrs(0)
- {
- arma_extra_debug_sigprint_this(this);
-
- init_cold();
-
- X.apply(*this);
- }
- template<typename eT>
- template<typename gen_type>
- inline
- Cube<eT>&
- Cube<eT>::operator=(const GenCube<eT, gen_type>& X)
- {
- arma_extra_debug_sigprint();
-
- init_warm(X.n_rows, X.n_cols, X.n_slices);
-
- X.apply(*this);
-
- return *this;
- }
- template<typename eT>
- template<typename gen_type>
- inline
- Cube<eT>&
- Cube<eT>::operator+=(const GenCube<eT, gen_type>& X)
- {
- arma_extra_debug_sigprint();
-
- X.apply_inplace_plus(*this);
-
- return *this;
- }
- template<typename eT>
- template<typename gen_type>
- inline
- Cube<eT>&
- Cube<eT>::operator-=(const GenCube<eT, gen_type>& X)
- {
- arma_extra_debug_sigprint();
-
- X.apply_inplace_minus(*this);
-
- return *this;
- }
- template<typename eT>
- template<typename gen_type>
- inline
- Cube<eT>&
- Cube<eT>::operator%=(const GenCube<eT, gen_type>& X)
- {
- arma_extra_debug_sigprint();
-
- X.apply_inplace_schur(*this);
-
- return *this;
- }
- template<typename eT>
- template<typename gen_type>
- inline
- Cube<eT>&
- Cube<eT>::operator/=(const GenCube<eT, gen_type>& X)
- {
- arma_extra_debug_sigprint();
-
- X.apply_inplace_div(*this);
-
- return *this;
- }
- //! create a cube from OpCube, i.e. run the previously delayed unary operations
- template<typename eT>
- template<typename T1, typename op_type>
- inline
- Cube<eT>::Cube(const OpCube<T1, op_type>& X)
- : n_rows(0)
- , n_cols(0)
- , n_elem_slice(0)
- , n_slices(0)
- , n_elem(0)
- , mem_state(0)
- , mem()
- , mat_ptrs(0)
- {
- 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 cube from OpCube, i.e. run the previously delayed unary operations
- template<typename eT>
- template<typename T1, typename op_type>
- inline
- Cube<eT>&
- Cube<eT>::operator=(const OpCube<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 cube addition, with the right-hand-side operand having delayed operations
- template<typename eT>
- template<typename T1, typename op_type>
- inline
- Cube<eT>&
- Cube<eT>::operator+=(const OpCube<T1, op_type>& X)
- {
- arma_extra_debug_sigprint();
-
- arma_type_check(( is_same_type< eT, typename T1::elem_type >::no ));
-
- const Cube<eT> m(X);
-
- return (*this).operator+=(m);
- }
- //! in-place cube subtraction, with the right-hand-side operand having delayed operations
- template<typename eT>
- template<typename T1, typename op_type>
- inline
- Cube<eT>&
- Cube<eT>::operator-=(const OpCube<T1, op_type>& X)
- {
- arma_extra_debug_sigprint();
-
- arma_type_check(( is_same_type< eT, typename T1::elem_type >::no ));
-
- const Cube<eT> m(X);
-
- return (*this).operator-=(m);
- }
- //! in-place cube element-wise multiplication, with the right-hand-side operand having delayed operations
- template<typename eT>
- template<typename T1, typename op_type>
- inline
- Cube<eT>&
- Cube<eT>::operator%=(const OpCube<T1, op_type>& X)
- {
- arma_extra_debug_sigprint();
-
- arma_type_check(( is_same_type< eT, typename T1::elem_type >::no ));
-
- const Cube<eT> m(X);
-
- return (*this).operator%=(m);
- }
- //! in-place cube element-wise division, with the right-hand-side operand having delayed operations
- template<typename eT>
- template<typename T1, typename op_type>
- inline
- Cube<eT>&
- Cube<eT>::operator/=(const OpCube<T1, op_type>& X)
- {
- arma_extra_debug_sigprint();
-
- arma_type_check(( is_same_type< eT, typename T1::elem_type >::no ));
-
- const Cube<eT> m(X);
-
- return (*this).operator/=(m);
- }
- //! create a cube from eOpCube, i.e. run the previously delayed unary operations
- template<typename eT>
- template<typename T1, typename eop_type>
- inline
- Cube<eT>::Cube(const eOpCube<T1, eop_type>& X)
- : n_rows(X.get_n_rows())
- , n_cols(X.get_n_cols())
- , n_elem_slice(X.get_n_elem_slice())
- , n_slices(X.get_n_slices())
- , n_elem(X.get_n_elem())
- , mem_state(0)
- , mem()
- , mat_ptrs(0)
- {
- 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 cube from eOpCube, i.e. run the previously delayed unary operations
- template<typename eT>
- template<typename T1, typename eop_type>
- inline
- Cube<eT>&
- Cube<eT>::operator=(const eOpCube<T1, eop_type>& X)
- {
- arma_extra_debug_sigprint();
-
- arma_type_check(( is_same_type< eT, typename T1::elem_type >::no ));
-
- const bool bad_alias = ( X.P.has_subview && X.P.is_alias(*this) );
-
- if(bad_alias == false)
- {
- init_warm(X.get_n_rows(), X.get_n_cols(), X.get_n_slices());
-
- eop_type::apply(*this, X);
- }
- else
- {
- Cube<eT> tmp(X);
-
- steal_mem(tmp);
- }
-
- return *this;
- }
- //! in-place cube addition, with the right-hand-side operand having delayed operations
- template<typename eT>
- template<typename T1, typename eop_type>
- inline
- Cube<eT>&
- Cube<eT>::operator+=(const eOpCube<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;
- }
- //! in-place cube subtraction, with the right-hand-side operand having delayed operations
- template<typename eT>
- template<typename T1, typename eop_type>
- inline
- Cube<eT>&
- Cube<eT>::operator-=(const eOpCube<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;
- }
- //! in-place cube element-wise multiplication, with the right-hand-side operand having delayed operations
- template<typename eT>
- template<typename T1, typename eop_type>
- inline
- Cube<eT>&
- Cube<eT>::operator%=(const eOpCube<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;
- }
- //! in-place cube element-wise division, with the right-hand-side operand having delayed operations
- template<typename eT>
- template<typename T1, typename eop_type>
- inline
- Cube<eT>&
- Cube<eT>::operator/=(const eOpCube<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
- Cube<eT>::Cube(const mtOpCube<eT, T1, op_type>& X)
- : n_rows(0)
- , n_cols(0)
- , n_elem_slice(0)
- , n_slices(0)
- , n_elem(0)
- , mem_state(0)
- , mem()
- , mat_ptrs(0)
- {
- arma_extra_debug_sigprint_this(this);
-
- op_type::apply(*this, X);
- }
- template<typename eT>
- template<typename T1, typename op_type>
- inline
- Cube<eT>&
- Cube<eT>::operator=(const mtOpCube<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
- Cube<eT>&
- Cube<eT>::operator+=(const mtOpCube<eT, T1, op_type>& X)
- {
- arma_extra_debug_sigprint();
-
- const Cube<eT> m(X);
-
- return (*this).operator+=(m);
- }
- template<typename eT>
- template<typename T1, typename op_type>
- inline
- Cube<eT>&
- Cube<eT>::operator-=(const mtOpCube<eT, T1, op_type>& X)
- {
- arma_extra_debug_sigprint();
-
- const Cube<eT> m(X);
-
- return (*this).operator-=(m);
- }
- template<typename eT>
- template<typename T1, typename op_type>
- inline
- Cube<eT>&
- Cube<eT>::operator%=(const mtOpCube<eT, T1, op_type>& X)
- {
- arma_extra_debug_sigprint();
-
- const Cube<eT> m(X);
-
- return (*this).operator%=(m);
- }
- template<typename eT>
- template<typename T1, typename op_type>
- inline
- Cube<eT>&
- Cube<eT>::operator/=(const mtOpCube<eT, T1, op_type>& X)
- {
- arma_extra_debug_sigprint();
-
- const Cube<eT> m(X);
-
- return (*this).operator/=(m);
- }
- //! create a cube from GlueCube, i.e. run the previously delayed binary operations
- template<typename eT>
- template<typename T1, typename T2, typename glue_type>
- inline
- Cube<eT>::Cube(const GlueCube<T1, T2, glue_type>& X)
- : n_rows(0)
- , n_cols(0)
- , n_elem_slice(0)
- , n_slices(0)
- , n_elem(0)
- , mem_state(0)
- , mem()
- , mat_ptrs(0)
- {
- arma_extra_debug_sigprint_this(this);
- this->operator=(X);
- }
- //! create a cube from GlueCube, i.e. run the previously delayed binary operations
- template<typename eT>
- template<typename T1, typename T2, typename glue_type>
- inline
- Cube<eT>&
- Cube<eT>::operator=(const GlueCube<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 cube addition, with the right-hand-side operands having delayed operations
- template<typename eT>
- template<typename T1, typename T2, typename glue_type>
- inline
- Cube<eT>&
- Cube<eT>::operator+=(const GlueCube<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 Cube<eT> m(X);
-
- return (*this).operator+=(m);
- }
- //! in-place cube subtraction, with the right-hand-side operands having delayed operations
- template<typename eT>
- template<typename T1, typename T2, typename glue_type>
- inline
- Cube<eT>&
- Cube<eT>::operator-=(const GlueCube<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 Cube<eT> m(X);
-
- return (*this).operator-=(m);
- }
- //! in-place cube element-wise multiplication, with the right-hand-side operands having delayed operations
- template<typename eT>
- template<typename T1, typename T2, typename glue_type>
- inline
- Cube<eT>&
- Cube<eT>::operator%=(const GlueCube<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 Cube<eT> m(X);
-
- return (*this).operator%=(m);
- }
- //! in-place cube element-wise division, with the right-hand-side operands having delayed operations
- template<typename eT>
- template<typename T1, typename T2, typename glue_type>
- inline
- Cube<eT>&
- Cube<eT>::operator/=(const GlueCube<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 Cube<eT> m(X);
-
- return (*this).operator/=(m);
- }
- //! create a cube from eGlueCube, i.e. run the previously delayed binary operations
- template<typename eT>
- template<typename T1, typename T2, typename eglue_type>
- inline
- Cube<eT>::Cube(const eGlueCube<T1, T2, eglue_type>& X)
- : n_rows(X.get_n_rows())
- , n_cols(X.get_n_cols())
- , n_elem_slice(X.get_n_elem_slice())
- , n_slices(X.get_n_slices())
- , n_elem(X.get_n_elem())
- , mem_state(0)
- , mem()
- , mat_ptrs(0)
- {
- 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 cube from eGlueCube, i.e. run the previously delayed binary operations
- template<typename eT>
- template<typename T1, typename T2, typename eglue_type>
- inline
- Cube<eT>&
- Cube<eT>::operator=(const eGlueCube<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 = ( (X.P1.has_subview && X.P1.is_alias(*this)) || (X.P2.has_subview && X.P2.is_alias(*this)) );
-
- if(bad_alias == false)
- {
- init_warm(X.get_n_rows(), X.get_n_cols(), X.get_n_slices());
-
- eglue_type::apply(*this, X);
- }
- else
- {
- Cube<eT> tmp(X);
-
- steal_mem(tmp);
- }
-
- return *this;
- }
- //! in-place cube addition, with the right-hand-side operands having delayed operations
- template<typename eT>
- template<typename T1, typename T2, typename eglue_type>
- inline
- Cube<eT>&
- Cube<eT>::operator+=(const eGlueCube<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 cube subtraction, with the right-hand-side operands having delayed operations
- template<typename eT>
- template<typename T1, typename T2, typename eglue_type>
- inline
- Cube<eT>&
- Cube<eT>::operator-=(const eGlueCube<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;
- }
- //! in-place cube element-wise multiplication, with the right-hand-side operands having delayed operations
- template<typename eT>
- template<typename T1, typename T2, typename eglue_type>
- inline
- Cube<eT>&
- Cube<eT>::operator%=(const eGlueCube<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;
- }
- //! in-place cube element-wise division, with the right-hand-side operands having delayed operations
- template<typename eT>
- template<typename T1, typename T2, typename eglue_type>
- inline
- Cube<eT>&
- Cube<eT>::operator/=(const eGlueCube<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
- Cube<eT>::Cube(const mtGlueCube<eT, T1, T2, glue_type>& X)
- : n_rows(0)
- , n_cols(0)
- , n_elem_slice(0)
- , n_slices(0)
- , n_elem(0)
- , mem_state(0)
- , mem()
- , mat_ptrs(0)
- {
- arma_extra_debug_sigprint_this(this);
-
- glue_type::apply(*this, X);
- }
- template<typename eT>
- template<typename T1, typename T2, typename glue_type>
- inline
- Cube<eT>&
- Cube<eT>::operator=(const mtGlueCube<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
- Cube<eT>&
- Cube<eT>::operator+=(const mtGlueCube<eT, T1, T2, glue_type>& X)
- {
- arma_extra_debug_sigprint();
-
- const Cube<eT> m(X);
-
- return (*this).operator+=(m);
- }
- template<typename eT>
- template<typename T1, typename T2, typename glue_type>
- inline
- Cube<eT>&
- Cube<eT>::operator-=(const mtGlueCube<eT, T1, T2, glue_type>& X)
- {
- arma_extra_debug_sigprint();
-
- const Cube<eT> m(X);
-
- return (*this).operator-=(m);
- }
- template<typename eT>
- template<typename T1, typename T2, typename glue_type>
- inline
- Cube<eT>&
- Cube<eT>::operator%=(const mtGlueCube<eT, T1, T2, glue_type>& X)
- {
- arma_extra_debug_sigprint();
-
- const Cube<eT> m(X);
-
- return (*this).operator%=(m);
- }
- template<typename eT>
- template<typename T1, typename T2, typename glue_type>
- inline
- Cube<eT>&
- Cube<eT>::operator/=(const mtGlueCube<eT, T1, T2, glue_type>& X)
- {
- arma_extra_debug_sigprint();
-
- const Cube<eT> m(X);
-
- return (*this).operator/=(m);
- }
- //! linear element accessor (treats the cube as a vector); no bounds check; assumes memory is aligned
- template<typename eT>
- arma_inline
- arma_warn_unused
- const eT&
- Cube<eT>::at_alt(const uword i) const
- {
- const eT* mem_aligned = mem;
- memory::mark_as_aligned(mem_aligned);
-
- return mem_aligned[i];
- }
- //! linear element accessor (treats the cube as a vector); bounds checking not done when ARMA_NO_DEBUG is defined
- template<typename eT>
- arma_inline
- arma_warn_unused
- eT&
- Cube<eT>::operator() (const uword i)
- {
- arma_debug_check( (i >= n_elem), "Cube::operator(): index out of bounds");
- return access::rw(mem[i]);
- }
- //! linear element accessor (treats the cube as a vector); bounds checking not done when ARMA_NO_DEBUG is defined
- template<typename eT>
- arma_inline
- arma_warn_unused
- const eT&
- Cube<eT>::operator() (const uword i) const
- {
- arma_debug_check( (i >= n_elem), "Cube::operator(): index out of bounds");
- return mem[i];
- }
- //! linear element accessor (treats the cube as a vector); no bounds check.
- template<typename eT>
- arma_inline
- arma_warn_unused
- eT&
- Cube<eT>::operator[] (const uword i)
- {
- return access::rw(mem[i]);
- }
- //! linear element accessor (treats the cube as a vector); no bounds check
- template<typename eT>
- arma_inline
- arma_warn_unused
- const eT&
- Cube<eT>::operator[] (const uword i) const
- {
- return mem[i];
- }
- //! linear element accessor (treats the cube as a vector); no bounds check.
- template<typename eT>
- arma_inline
- arma_warn_unused
- eT&
- Cube<eT>::at(const uword i)
- {
- return access::rw(mem[i]);
- }
- //! linear element accessor (treats the cube as a vector); no bounds check
- template<typename eT>
- arma_inline
- arma_warn_unused
- const eT&
- Cube<eT>::at(const uword i) const
- {
- return mem[i];
- }
- //! element accessor; bounds checking not done when ARMA_NO_DEBUG is defined
- template<typename eT>
- arma_inline
- arma_warn_unused
- eT&
- Cube<eT>::operator() (const uword in_row, const uword in_col, const uword in_slice)
- {
- arma_debug_check
- (
- (in_row >= n_rows) ||
- (in_col >= n_cols) ||
- (in_slice >= n_slices)
- ,
- "Cube::operator(): index out of bounds"
- );
- return access::rw(mem[in_slice*n_elem_slice + in_col*n_rows + in_row]);
- }
- //! element accessor; bounds checking not done when ARMA_NO_DEBUG is defined
- template<typename eT>
- arma_inline
- arma_warn_unused
- const eT&
- Cube<eT>::operator() (const uword in_row, const uword in_col, const uword in_slice) const
- {
- arma_debug_check
- (
- (in_row >= n_rows) ||
- (in_col >= n_cols) ||
- (in_slice >= n_slices)
- ,
- "Cube::operator(): index out of bounds"
- );
- return mem[in_slice*n_elem_slice + in_col*n_rows + in_row];
- }
- //! element accessor; no bounds check
- template<typename eT>
- arma_inline
- arma_warn_unused
- eT&
- Cube<eT>::at(const uword in_row, const uword in_col, const uword in_slice)
- {
- return access::rw( mem[in_slice*n_elem_slice + in_col*n_rows + in_row] );
- }
- //! element accessor; no bounds check
- template<typename eT>
- arma_inline
- arma_warn_unused
- const eT&
- Cube<eT>::at(const uword in_row, const uword in_col, const uword in_slice) const
- {
- return mem[in_slice*n_elem_slice + in_col*n_rows + in_row];
- }
- //! prefix ++
- template<typename eT>
- arma_inline
- const Cube<eT>&
- Cube<eT>::operator++()
- {
- Cube_aux::prefix_pp(*this);
- return *this;
- }
- //! postfix ++ (must not return the object by reference)
- template<typename eT>
- arma_inline
- void
- Cube<eT>::operator++(int)
- {
- Cube_aux::postfix_pp(*this);
- }
- //! prefix --
- template<typename eT>
- arma_inline
- const Cube<eT>&
- Cube<eT>::operator--()
- {
- Cube_aux::prefix_mm(*this);
- return *this;
- }
- //! postfix -- (must not return the object by reference)
- template<typename eT>
- arma_inline
- void
- Cube<eT>::operator--(int)
- {
- Cube_aux::postfix_mm(*this);
- }
- //! returns true if all of the elements are finite
- template<typename eT>
- inline
- arma_warn_unused
- bool
- Cube<eT>::is_finite() const
- {
- arma_extra_debug_sigprint();
-
- return arrayops::is_finite( memptr(), n_elem );
- }
- //! returns true if the cube has no elements
- template<typename eT>
- arma_inline
- arma_warn_unused
- bool
- Cube<eT>::is_empty() const
- {
- return (n_elem == 0);
- }
- template<typename eT>
- inline
- arma_warn_unused
- bool
- Cube<eT>::has_inf() const
- {
- arma_extra_debug_sigprint();
-
- return arrayops::has_inf( memptr(), n_elem );
- }
- template<typename eT>
- inline
- arma_warn_unused
- bool
- Cube<eT>::has_nan() const
- {
- arma_extra_debug_sigprint();
-
- return arrayops::has_nan( memptr(), n_elem );
- }
- //! returns true if the given index is currently in range
- template<typename eT>
- arma_inline
- arma_warn_unused
- bool
- Cube<eT>::in_range(const uword i) const
- {
- return (i < n_elem);
- }
- //! returns true if the given start and end indices are currently in range
- template<typename eT>
- arma_inline
- arma_warn_unused
- bool
- Cube<eT>::in_range(const span& x) const
- {
- arma_extra_debug_sigprint();
-
- if(x.whole == true)
- {
- 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
- Cube<eT>::in_range(const uword in_row, const uword in_col, const uword in_slice) const
- {
- return ( (in_row < n_rows) && (in_col < n_cols) && (in_slice < n_slices) );
- }
- template<typename eT>
- inline
- arma_warn_unused
- bool
- Cube<eT>::in_range(const span& row_span, const span& col_span, const span& slice_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 uword in_slice1 = slice_span.a;
- const uword in_slice2 = slice_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) );
- const bool slices_ok = slice_span.whole ? true : ( (in_slice1 <= in_slice2) && (in_slice2 < n_slices) );
-
-
- return ( (rows_ok == true) && (cols_ok == true) && (slices_ok == true) );
- }
- template<typename eT>
- inline
- arma_warn_unused
- bool
- Cube<eT>::in_range(const uword in_row, const uword in_col, const uword in_slice, const SizeCube& s) const
- {
- const uword l_n_rows = n_rows;
- const uword l_n_cols = n_cols;
- const uword l_n_slices = n_slices;
-
- if(
- ( in_row >= l_n_rows) || ( in_col >= l_n_cols) || ( in_slice >= l_n_slices)
- || ((in_row + s.n_rows) > l_n_rows) || ((in_col + s.n_cols) > l_n_cols) || ((in_slice + s.n_slices) > l_n_slices)
- )
- {
- return false;
- }
- else
- {
- return true;
- }
- }
- //! returns a pointer to array of eTs used by the cube
- template<typename eT>
- arma_inline
- arma_warn_unused
- eT*
- Cube<eT>::memptr()
- {
- return const_cast<eT*>(mem);
- }
- //! returns a pointer to array of eTs used by the cube
- template<typename eT>
- arma_inline
- arma_warn_unused
- const eT*
- Cube<eT>::memptr() const
- {
- return mem;
- }
- //! returns a pointer to array of eTs used by the specified slice in the cube
- template<typename eT>
- arma_inline
- arma_warn_unused
- eT*
- Cube<eT>::slice_memptr(const uword uslice)
- {
- return const_cast<eT*>( &mem[ uslice*n_elem_slice ] );
- }
- //! returns a pointer to array of eTs used by the specified slice in the cube
- template<typename eT>
- arma_inline
- arma_warn_unused
- const eT*
- Cube<eT>::slice_memptr(const uword uslice) const
- {
- return &mem[ uslice*n_elem_slice ];
- }
- //! returns a pointer to array of eTs used by the specified slice in the cube
- template<typename eT>
- arma_inline
- arma_warn_unused
- eT*
- Cube<eT>::slice_colptr(const uword uslice, const uword col)
- {
- return const_cast<eT*>( &mem[ uslice*n_elem_slice + col*n_rows] );
- }
- //! returns a pointer to array of eTs used by the specified slice in the cube
- template<typename eT>
- arma_inline
- arma_warn_unused
- const eT*
- Cube<eT>::slice_colptr(const uword uslice, const uword col) const
- {
- return &mem[ uslice*n_elem_slice + col*n_rows ];
- }
- //! print contents of the cube (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
- Cube<eT>::impl_print(const std::string& extra_text) const
- {
- arma_extra_debug_sigprint();
-
- if(extra_text.length() != 0)
- {
- get_cout_stream() << extra_text << '\n';
- }
-
- arma_ostream::print(get_cout_stream(), *this, true);
- }
- //! print contents of the cube 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
- Cube<eT>::impl_print(std::ostream& user_stream, const std::string& extra_text) const
- {
- arma_extra_debug_sigprint();
-
- if(extra_text.length() != 0)
- {
- user_stream << extra_text << '\n';
- }
-
- arma_ostream::print(user_stream, *this, true);
- }
- //! print contents of the cube (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
- Cube<eT>::impl_raw_print(const std::string& extra_text) const
- {
- arma_extra_debug_sigprint();
-
- if(extra_text.length() != 0)
- {
- get_cout_stream() << extra_text << '\n';
- }
-
- arma_ostream::print(get_cout_stream(), *this, false);
- }
- //! print contents of the cube 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
- Cube<eT>::impl_raw_print(std::ostream& user_stream, const std::string& extra_text) const
- {
- arma_extra_debug_sigprint();
-
- if(extra_text.length() != 0)
- {
- user_stream << extra_text << '\n';
- }
-
- arma_ostream::print(user_stream, *this, false);
- }
- //! change the cube to have user specified dimensions (data is not preserved)
- template<typename eT>
- inline
- void
- Cube<eT>::set_size(const uword in_n_rows, const uword in_n_cols, const uword in_n_slices)
- {
- arma_extra_debug_sigprint();
-
- init_warm(in_n_rows, in_n_cols, in_n_slices);
- }
- //! change the cube to have user specified dimensions (data is preserved)
- template<typename eT>
- inline
- void
- Cube<eT>::reshape(const uword in_rows, const uword in_cols, const uword in_slices)
- {
- arma_extra_debug_sigprint();
-
- *this = arma::reshape(*this, in_rows, in_cols, in_slices);
- }
- //! NOTE: don't use this form; it's deprecated and will be removed
- template<typename eT>
- arma_deprecated
- inline
- void
- Cube<eT>::reshape(const uword in_rows, const uword in_cols, const uword in_slices, const uword dim)
- {
- arma_extra_debug_sigprint();
-
- *this = arma::reshape(*this, in_rows, in_cols, in_slices, dim);
- }
- //! change the cube to have user specified dimensions (data is preserved)
- template<typename eT>
- inline
- void
- Cube<eT>::resize(const uword in_rows, const uword in_cols, const uword in_slices)
- {
- arma_extra_debug_sigprint();
-
- *this = arma::resize(*this, in_rows, in_cols, in_slices);
- }
- template<typename eT>
- inline
- void
- Cube<eT>::set_size(const SizeCube& s)
- {
- arma_extra_debug_sigprint();
-
- init_warm(s.n_rows, s.n_cols, s.n_slices);
- }
- template<typename eT>
- inline
- void
- Cube<eT>::reshape(const SizeCube& s)
- {
- arma_extra_debug_sigprint();
-
- *this = arma::reshape(*this, s.n_rows, s.n_cols, s.n_slices, 0);
- }
- template<typename eT>
- inline
- void
- Cube<eT>::resize(const SizeCube& s)
- {
- arma_extra_debug_sigprint();
-
- *this = arma::resize(*this, s.n_rows, s.n_cols, s.n_slices);
- }
- //! change the cube (without preserving data) to have the same dimensions as the given cube
- template<typename eT>
- template<typename eT2>
- inline
- void
- Cube<eT>::copy_size(const Cube<eT2>& m)
- {
- arma_extra_debug_sigprint();
-
- init_warm(m.n_rows, m.n_cols, m.n_slices);
- }
- //! apply a functor to each element
- template<typename eT>
- template<typename functor>
- inline
- const Cube<eT>&
- Cube<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 Cube<eT>&
- Cube<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 cube using a functor
- template<typename eT>
- template<typename functor>
- inline
- const Cube<eT>&
- Cube<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 cube with values provided by a functor
- template<typename eT>
- template<typename functor>
- inline
- const Cube<eT>&
- Cube<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 Cube<eT>&
- Cube<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 Cube<eT>&
- Cube<eT>::clean(const typename get_pod_type<eT>::result threshold)
- {
- arma_extra_debug_sigprint();
-
- arrayops::clean(memptr(), n_elem, threshold);
-
- return *this;
- }
- //! fill the cube with the specified value
- template<typename eT>
- inline
- const Cube<eT>&
- Cube<eT>::fill(const eT val)
- {
- arma_extra_debug_sigprint();
-
- arrayops::inplace_set( memptr(), val, n_elem );
-
- return *this;
- }
- template<typename eT>
- inline
- const Cube<eT>&
- Cube<eT>::zeros()
- {
- arma_extra_debug_sigprint();
-
- arrayops::fill_zeros(memptr(), n_elem);
-
- return *this;
- }
- template<typename eT>
- inline
- const Cube<eT>&
- Cube<eT>::zeros(const uword in_rows, const uword in_cols, const uword in_slices)
- {
- arma_extra_debug_sigprint();
-
- set_size(in_rows, in_cols, in_slices);
-
- return (*this).zeros();
- }
- template<typename eT>
- inline
- const Cube<eT>&
- Cube<eT>::zeros(const SizeCube& s)
- {
- arma_extra_debug_sigprint();
-
- return (*this).zeros(s.n_rows, s.n_cols, s.n_slices);
- }
- template<typename eT>
- inline
- const Cube<eT>&
- Cube<eT>::ones()
- {
- arma_extra_debug_sigprint();
-
- return (*this).fill(eT(1));
- }
- template<typename eT>
- inline
- const Cube<eT>&
- Cube<eT>::ones(const uword in_rows, const uword in_cols, const uword in_slices)
- {
- arma_extra_debug_sigprint();
-
- set_size(in_rows, in_cols, in_slices);
-
- return (*this).fill(eT(1));
- }
- template<typename eT>
- inline
- const Cube<eT>&
- Cube<eT>::ones(const SizeCube& s)
- {
- arma_extra_debug_sigprint();
-
- return (*this).ones(s.n_rows, s.n_cols, s.n_slices);
- }
- template<typename eT>
- inline
- const Cube<eT>&
- Cube<eT>::randu()
- {
- arma_extra_debug_sigprint();
-
- arma_rng::randu<eT>::fill( memptr(), n_elem );
-
- return *this;
- }
- template<typename eT>
- inline
- const Cube<eT>&
- Cube<eT>::randu(const uword in_rows, const uword in_cols, const uword in_slices)
- {
- arma_extra_debug_sigprint();
-
- set_size(in_rows, in_cols, in_slices);
-
- return (*this).randu();
- }
- template<typename eT>
- inline
- const Cube<eT>&
- Cube<eT>::randu(const SizeCube& s)
- {
- arma_extra_debug_sigprint();
-
- return (*this).randu(s.n_rows, s.n_cols, s.n_slices);
- }
- template<typename eT>
- inline
- const Cube<eT>&
- Cube<eT>::randn()
- {
- arma_extra_debug_sigprint();
-
- arma_rng::randn<eT>::fill( memptr(), n_elem );
-
- return *this;
- }
- template<typename eT>
- inline
- const Cube<eT>&
- Cube<eT>::randn(const uword in_rows, const uword in_cols, const uword in_slices)
- {
- arma_extra_debug_sigprint();
-
- set_size(in_rows, in_cols, in_slices);
-
- return (*this).randn();
- }
- template<typename eT>
- inline
- const Cube<eT>&
- Cube<eT>::randn(const SizeCube& s)
- {
- arma_extra_debug_sigprint();
-
- return (*this).randn(s.n_rows, s.n_cols, s.n_slices);
- }
- template<typename eT>
- inline
- void
- Cube<eT>::reset()
- {
- arma_extra_debug_sigprint();
-
- init_warm(0,0,0);
- }
- template<typename eT>
- inline
- void
- Cube<eT>::soft_reset()
- {
- arma_extra_debug_sigprint();
-
- // don't change the size if the cube has a fixed size
- if(mem_state <= 1)
- {
- reset();
- }
- else
- {
- fill(Datum<eT>::nan);
- }
- }
- template<typename eT>
- template<typename T1>
- inline
- void
- Cube<eT>::set_real(const BaseCube<typename Cube<eT>::pod_type,T1>& X)
- {
- arma_extra_debug_sigprint();
-
- Cube_aux::set_real(*this, X);
- }
- template<typename eT>
- template<typename T1>
- inline
- void
- Cube<eT>::set_imag(const BaseCube<typename Cube<eT>::pod_type,T1>& X)
- {
- arma_extra_debug_sigprint();
-
- Cube_aux::set_imag(*this, X);
- }
- template<typename eT>
- inline
- arma_warn_unused
- eT
- Cube<eT>::min() const
- {
- arma_extra_debug_sigprint();
-
- if(n_elem == 0)
- {
- arma_debug_check(true, "Cube::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
- Cube<eT>::max() const
- {
- arma_extra_debug_sigprint();
-
- if(n_elem == 0)
- {
- arma_debug_check(true, "Cube::max(): object has no elements");
-
- return Datum<eT>::nan;
- }
-
- return op_max::direct_max(memptr(), n_elem);
- }
- template<typename eT>
- inline
- eT
- Cube<eT>::min(uword& index_of_min_val) const
- {
- arma_extra_debug_sigprint();
-
- if(n_elem == 0)
- {
- arma_debug_check(true, "Cube::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
- Cube<eT>::max(uword& index_of_max_val) const
- {
- arma_extra_debug_sigprint();
-
- if(n_elem == 0)
- {
- arma_debug_check(true, "Cube::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
- Cube<eT>::min(uword& row_of_min_val, uword& col_of_min_val, uword& slice_of_min_val) const
- {
- arma_extra_debug_sigprint();
-
- if(n_elem == 0)
- {
- arma_debug_check(true, "Cube::min(): object has no elements");
-
- row_of_min_val = uword(0);
- col_of_min_val = uword(0);
- slice_of_min_val = uword(0);
-
- return Datum<eT>::nan;
- }
-
- uword i;
-
- eT val = op_min::direct_min(memptr(), n_elem, i);
-
- const uword in_slice = i / n_elem_slice;
- const uword offset = in_slice * n_elem_slice;
- const uword j = i - offset;
-
- row_of_min_val = j % n_rows;
- col_of_min_val = j / n_rows;
- slice_of_min_val = in_slice;
-
- return val;
- }
- template<typename eT>
- inline
- eT
- Cube<eT>::max(uword& row_of_max_val, uword& col_of_max_val, uword& slice_of_max_val) const
- {
- arma_extra_debug_sigprint();
-
- if(n_elem == 0)
- {
- arma_debug_check(true, "Cube::max(): object has no elements");
-
- row_of_max_val = uword(0);
- col_of_max_val = uword(0);
- slice_of_max_val = uword(0);
-
- return Datum<eT>::nan;
- }
-
- uword i;
-
- eT val = op_max::direct_max(memptr(), n_elem, i);
-
- const uword in_slice = i / n_elem_slice;
- const uword offset = in_slice * n_elem_slice;
- const uword j = i - offset;
-
- row_of_max_val = j % n_rows;
- col_of_max_val = j / n_rows;
- slice_of_max_val = in_slice;
-
- return val;
- }
- //! save the cube to a file
- template<typename eT>
- inline
- arma_cold
- bool
- Cube<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 raw_binary:
- save_okay = diskio::save_raw_binary(*this, name);
- break;
-
- case arma_binary:
- save_okay = diskio::save_arma_binary(*this, name);
- break;
-
- case ppm_binary:
- save_okay = diskio::save_ppm_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("Cube::save(): unsupported file type"); }
- save_okay = false;
- }
-
- if(print_status && (save_okay == false)) { arma_debug_warn("Cube::save(): couldn't write to ", name); }
-
- return save_okay;
- }
- template<typename eT>
- inline
- arma_cold
- bool
- Cube<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, "Cube::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, "Cube::save(): only one of 'append' or 'replace' options can be used");
- return false;
- }
-
- bool save_okay = false;
- std::string err_msg;
-
- if(do_trans)
- {
- Cube<eT> tmp;
-
- op_strans_cube::apply_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("Cube::save(): ", err_msg, spec.filename);
- }
- else
- {
- arma_debug_warn("Cube::save(): couldn't write to ", spec.filename);
- }
- }
-
- return save_okay;
- }
- //! save the cube to a stream
- template<typename eT>
- inline
- arma_cold
- bool
- Cube<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 raw_binary:
- save_okay = diskio::save_raw_binary(*this, os);
- break;
-
- case arma_binary:
- save_okay = diskio::save_arma_binary(*this, os);
- break;
-
- case ppm_binary:
- save_okay = diskio::save_ppm_binary(*this, os);
- break;
-
- default:
- if(print_status) { arma_debug_warn("Cube::save(): unsupported file type"); }
- save_okay = false;
- }
-
- if(print_status && (save_okay == false)) { arma_debug_warn("Cube::save(): couldn't write to given stream"); }
-
- return save_okay;
- }
- //! load a cube from a file
- template<typename eT>
- inline
- arma_cold
- bool
- Cube<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 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 ppm_binary:
- load_okay = diskio::load_ppm_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("Cube::load(): unsupported file type"); }
- load_okay = false;
- }
-
- if( (print_status == true) && (load_okay == false) )
- {
- if(err_msg.length() > 0)
- {
- arma_debug_warn("Cube::load(): ", err_msg, name);
- }
- else
- {
- arma_debug_warn("Cube::load(): couldn't read ", name);
- }
- }
-
- if(load_okay == false)
- {
- (*this).soft_reset();
- }
-
- return load_okay;
- }
- template<typename eT>
- inline
- arma_cold
- bool
- Cube<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("Cube::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)
- {
- Cube<eT> tmp;
-
- load_okay = diskio::load_hdf5_binary(tmp, spec, err_msg);
-
- if(load_okay) { op_strans_cube::apply_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("Cube::load(): ", err_msg, spec.filename);
- }
- else
- {
- arma_debug_warn("Cube::load(): couldn't read ", spec.filename);
- }
- }
-
- if(load_okay == false)
- {
- (*this).soft_reset();
- }
-
- return load_okay;
- }
- //! load a cube from a stream
- template<typename eT>
- inline
- arma_cold
- bool
- Cube<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 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 ppm_binary:
- load_okay = diskio::load_ppm_binary(*this, is, err_msg);
- break;
-
- default:
- if(print_status) { arma_debug_warn("Cube::load(): unsupported file type"); }
- load_okay = false;
- }
-
- if( (print_status == true) && (load_okay == false) )
- {
- if(err_msg.length() > 0)
- {
- arma_debug_warn("Cube::load(): ", err_msg, "the given stream");
- }
- else
- {
- arma_debug_warn("Cube::load(): couldn't load from the given stream");
- }
- }
-
- if(load_okay == false)
- {
- (*this).soft_reset();
- }
-
- return load_okay;
- }
- //! save the cube to a file, without printing any error messages
- template<typename eT>
- inline
- arma_cold
- bool
- Cube<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
- Cube<eT>::quiet_save(const hdf5_name& spec, const file_type type) const
- {
- arma_extra_debug_sigprint();
-
- return (*this).save(spec, type, false);
- }
- //! save the cube to a stream, without printing any error messages
- template<typename eT>
- inline
- arma_cold
- bool
- Cube<eT>::quiet_save(std::ostream& os, const file_type type) const
- {
- arma_extra_debug_sigprint();
-
- return (*this).save(os, type, false);
- }
- //! load a cube from a file, without printing any error messages
- template<typename eT>
- inline
- arma_cold
- bool
- Cube<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
- Cube<eT>::quiet_load(const hdf5_name& spec, const file_type type)
- {
- arma_extra_debug_sigprint();
-
- return (*this).load(spec, type, false);
- }
- //! load a cube from a stream, without printing any error messages
- template<typename eT>
- inline
- arma_cold
- bool
- Cube<eT>::quiet_load(std::istream& is, const file_type type)
- {
- arma_extra_debug_sigprint();
-
- return (*this).load(is, type, false);
- }
- template<typename eT>
- inline
- typename Cube<eT>::iterator
- Cube<eT>::begin()
- {
- arma_extra_debug_sigprint();
-
- return memptr();
- }
- template<typename eT>
- inline
- typename Cube<eT>::const_iterator
- Cube<eT>::begin() const
- {
- arma_extra_debug_sigprint();
-
- return memptr();
- }
- template<typename eT>
- inline
- typename Cube<eT>::const_iterator
- Cube<eT>::cbegin() const
- {
- arma_extra_debug_sigprint();
-
- return memptr();
- }
- template<typename eT>
- inline
- typename Cube<eT>::iterator
- Cube<eT>::end()
- {
- arma_extra_debug_sigprint();
-
- return memptr() + n_elem;
- }
- template<typename eT>
- inline
- typename Cube<eT>::const_iterator
- Cube<eT>::end() const
- {
- arma_extra_debug_sigprint();
-
- return memptr() + n_elem;
- }
- template<typename eT>
- inline
- typename Cube<eT>::const_iterator
- Cube<eT>::cend() const
- {
- arma_extra_debug_sigprint();
-
- return memptr() + n_elem;
- }
- template<typename eT>
- inline
- typename Cube<eT>::slice_iterator
- Cube<eT>::begin_slice(const uword slice_num)
- {
- arma_extra_debug_sigprint();
-
- arma_debug_check( (slice_num >= n_slices), "begin_slice(): index out of bounds");
-
- return slice_memptr(slice_num);
- }
- template<typename eT>
- inline
- typename Cube<eT>::const_slice_iterator
- Cube<eT>::begin_slice(const uword slice_num) const
- {
- arma_extra_debug_sigprint();
-
- arma_debug_check( (slice_num >= n_slices), "begin_slice(): index out of bounds");
-
- return slice_memptr(slice_num);
- }
- template<typename eT>
- inline
- typename Cube<eT>::slice_iterator
- Cube<eT>::end_slice(const uword slice_num)
- {
- arma_extra_debug_sigprint();
-
- arma_debug_check( (slice_num >= n_slices), "end_slice(): index out of bounds");
-
- return slice_memptr(slice_num) + n_elem_slice;
- }
- template<typename eT>
- inline
- typename Cube<eT>::const_slice_iterator
- Cube<eT>::end_slice(const uword slice_num) const
- {
- arma_extra_debug_sigprint();
-
- arma_debug_check( (slice_num >= n_slices), "end_slice(): index out of bounds");
-
- return slice_memptr(slice_num) + n_elem_slice;
- }
- //! resets this cube to an empty matrix
- template<typename eT>
- inline
- void
- Cube<eT>::clear()
- {
- reset();
- }
- //! returns true if the cube has no elements
- template<typename eT>
- inline
- bool
- Cube<eT>::empty() const
- {
- return (n_elem == 0);
- }
- //! returns the number of elements in this cube
- template<typename eT>
- inline
- uword
- Cube<eT>::size() const
- {
- return n_elem;
- }
- template<typename eT>
- inline
- eT&
- Cube<eT>::front()
- {
- arma_debug_check( (n_elem == 0), "Cube::front(): cube is empty" );
-
- return access::rw(mem[0]);
- }
- template<typename eT>
- inline
- const eT&
- Cube<eT>::front() const
- {
- arma_debug_check( (n_elem == 0), "Cube::front(): cube is empty" );
-
- return mem[0];
- }
- template<typename eT>
- inline
- eT&
- Cube<eT>::back()
- {
- arma_debug_check( (n_elem == 0), "Cube::back(): cube is empty" );
-
- return access::rw(mem[n_elem-1]);
- }
- template<typename eT>
- inline
- const eT&
- Cube<eT>::back() const
- {
- arma_debug_check( (n_elem == 0), "Cube::back(): cube is empty" );
-
- return mem[n_elem-1];
- }
- template<typename eT>
- inline
- void
- Cube<eT>::swap(Cube<eT>& B)
- {
- Cube<eT>& A = (*this);
-
- arma_extra_debug_sigprint(arma_str::format("A = %x B = %x") % &A % &B);
-
- if( (A.mem_state == 0) && (B.mem_state == 0) && (A.n_elem > Cube_prealloc::mem_n_elem) && (B.n_elem > Cube_prealloc::mem_n_elem) )
- {
- A.delete_mat();
- B.delete_mat();
-
- 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_slice), access::rw(B.n_elem_slice) );
- std::swap( access::rw(A.n_slices), access::rw(B.n_slices) );
- std::swap( access::rw(A.n_elem), access::rw(B.n_elem) );
- std::swap( access::rw(A.mem), access::rw(B.mem) );
-
- A.create_mat();
- B.create_mat();
- }
- else
- if( (A.mem_state == 0) && (B.mem_state == 0) && (A.n_elem <= Cube_prealloc::mem_n_elem) && (B.n_elem <= Cube_prealloc::mem_n_elem) )
- {
- A.delete_mat();
- B.delete_mat();
-
- 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_slice), access::rw(B.n_elem_slice) );
- std::swap( access::rw(A.n_slices), access::rw(B.n_slices) );
- std::swap( access::rw(A.n_elem), access::rw(B.n_elem) );
-
- const uword N = (std::max)(A.n_elem, B.n_elem);
-
- eT* A_mem = A.memptr();
- eT* B_mem = B.memptr();
-
- for(uword i=0; i<N; ++i) { std::swap( A_mem[i], B_mem[i] ); }
-
- A.create_mat();
- B.create_mat();
- }
- else
- {
- // generic swap
-
- if(A.n_elem <= B.n_elem)
- {
- Cube<eT> C = A;
-
- A.steal_mem(B);
- B.steal_mem(C);
- }
- else
- {
- Cube<eT> C = B;
-
- B.steal_mem(A);
- A.steal_mem(C);
- }
- }
- }
- //! try to steal the memory from a given cube;
- //! if memory can't be stolen, copy the given cube
- template<typename eT>
- inline
- void
- Cube<eT>::steal_mem(Cube<eT>& x)
- {
- arma_extra_debug_sigprint();
-
- if(this == &x) { return; }
-
- if( (mem_state <= 1) && ( ((x.mem_state == 0) && (x.n_elem > Cube_prealloc::mem_n_elem)) || (x.mem_state == 1) ) )
- {
- reset();
-
- const uword x_n_slices = x.n_slices;
-
- access::rw(n_rows) = x.n_rows;
- access::rw(n_cols) = x.n_cols;
- access::rw(n_elem_slice) = x.n_elem_slice;
- access::rw(n_slices) = x_n_slices;
- access::rw(n_elem) = x.n_elem;
- access::rw(mem_state) = x.mem_state;
- access::rw(mem) = x.mem;
-
- if(x_n_slices > Cube_prealloc::mat_ptrs_size)
- {
- access::rw( mat_ptrs) = x.mat_ptrs;
- access::rw(x.mat_ptrs) = 0;
- }
- else
- {
- access::rw(mat_ptrs) = const_cast< const Mat<eT>** >(mat_ptrs_local);
-
- for(uword i=0; i < x_n_slices; ++i)
- {
- mat_ptrs[i] = x.mat_ptrs[i];
- x.mat_ptrs[i] = 0;
- }
- }
-
- access::rw(x.n_rows) = 0;
- access::rw(x.n_cols) = 0;
- access::rw(x.n_elem_slice) = 0;
- access::rw(x.n_slices) = 0;
- access::rw(x.n_elem) = 0;
- access::rw(x.mem_state) = 0;
- access::rw(x.mem) = 0;
- }
- else
- {
- (*this).operator=(x);
- }
- }
- //
- // Cube::fixed
- template<typename eT>
- template<uword fixed_n_rows, uword fixed_n_cols, uword fixed_n_slices>
- arma_inline
- void
- Cube<eT>::fixed<fixed_n_rows, fixed_n_cols, fixed_n_slices>::mem_setup()
- {
- arma_extra_debug_sigprint();
-
- if(fixed_n_elem > 0)
- {
- access::rw(Cube<eT>::n_rows) = fixed_n_rows;
- access::rw(Cube<eT>::n_cols) = fixed_n_cols;
- access::rw(Cube<eT>::n_elem_slice) = fixed_n_rows * fixed_n_cols;
- access::rw(Cube<eT>::n_slices) = fixed_n_slices;
- access::rw(Cube<eT>::n_elem) = fixed_n_elem;
- access::rw(Cube<eT>::mem_state) = 3;
- access::rw(Cube<eT>::mem) = (fixed_n_elem > Cube_prealloc::mem_n_elem) ? mem_local_extra : mem_local;
- access::rw(Cube<eT>::mat_ptrs) = const_cast< const Mat<eT>** >( \
- (fixed_n_slices > Cube_prealloc::mat_ptrs_size) ? mat_ptrs_local_extra : mat_ptrs_local );
-
- create_mat();
- }
- else
- {
- access::rw(Cube<eT>::n_rows) = 0;
- access::rw(Cube<eT>::n_cols) = 0;
- access::rw(Cube<eT>::n_elem_slice) = 0;
- access::rw(Cube<eT>::n_slices) = 0;
- access::rw(Cube<eT>::n_elem) = 0;
- access::rw(Cube<eT>::mem_state) = 3;
- access::rw(Cube<eT>::mem) = 0;
- access::rw(Cube<eT>::mat_ptrs) = 0;
- }
- }
- template<typename eT>
- template<uword fixed_n_rows, uword fixed_n_cols, uword fixed_n_slices>
- inline
- Cube<eT>::fixed<fixed_n_rows, fixed_n_cols, fixed_n_slices>::fixed()
- {
- arma_extra_debug_sigprint_this(this);
-
- mem_setup();
- }
- template<typename eT>
- template<uword fixed_n_rows, uword fixed_n_cols, uword fixed_n_slices>
- inline
- Cube<eT>::fixed<fixed_n_rows, fixed_n_cols, fixed_n_slices>::fixed(const fixed<fixed_n_rows, fixed_n_cols, fixed_n_slices>& X)
- {
- arma_extra_debug_sigprint_this(this);
-
- mem_setup();
-
- 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, uword fixed_n_slices>
- template<typename fill_type>
- inline
- Cube<eT>::fixed<fixed_n_rows, fixed_n_cols, fixed_n_slices>::fixed(const fill::fill_class<fill_type>&)
- {
- arma_extra_debug_sigprint_this(this);
-
- mem_setup();
-
- 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_randu>::yes) (*this).randu();
- if(is_same_type<fill_type, fill::fill_randn>::yes) (*this).randn();
-
- if(is_same_type<fill_type, fill::fill_eye >::yes) { arma_debug_check(true, "Cube::fixed::fixed(): unsupported fill type"); }
- }
- template<typename eT>
- template<uword fixed_n_rows, uword fixed_n_cols, uword fixed_n_slices>
- template<typename T1>
- inline
- Cube<eT>::fixed<fixed_n_rows, fixed_n_cols, fixed_n_slices>::fixed(const BaseCube<eT,T1>& A)
- {
- arma_extra_debug_sigprint_this(this);
-
- mem_setup();
-
- Cube<eT>::operator=(A.get_ref());
- }
- template<typename eT>
- template<uword fixed_n_rows, uword fixed_n_cols, uword fixed_n_slices>
- template<typename T1, typename T2>
- inline
- Cube<eT>::fixed<fixed_n_rows, fixed_n_cols, fixed_n_slices>::fixed(const BaseCube<pod_type,T1>& A, const BaseCube<pod_type,T2>& B)
- {
- arma_extra_debug_sigprint_this(this);
-
- mem_setup();
-
- Cube<eT>::init(A,B);
- }
- template<typename eT>
- template<uword fixed_n_rows, uword fixed_n_cols, uword fixed_n_slices>
- inline
- Cube<eT>&
- Cube<eT>::fixed<fixed_n_rows, fixed_n_cols, fixed_n_slices>::operator=(const fixed<fixed_n_rows, fixed_n_cols, fixed_n_slices>& X)
- {
- arma_extra_debug_sigprint();
-
- 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;
- }
- template<typename eT>
- template<uword fixed_n_rows, uword fixed_n_cols, uword fixed_n_slices>
- arma_inline
- arma_warn_unused
- eT&
- Cube<eT>::fixed<fixed_n_rows, fixed_n_cols, fixed_n_slices>::operator[] (const uword i)
- {
- return (use_extra) ? mem_local_extra[i] : mem_local[i];
- }
- template<typename eT>
- template<uword fixed_n_rows, uword fixed_n_cols, uword fixed_n_slices>
- arma_inline
- arma_warn_unused
- const eT&
- Cube<eT>::fixed<fixed_n_rows, fixed_n_cols, fixed_n_slices>::operator[] (const uword i) const
- {
- return (use_extra) ? mem_local_extra[i] : mem_local[i];
- }
- template<typename eT>
- template<uword fixed_n_rows, uword fixed_n_cols, uword fixed_n_slices>
- arma_inline
- arma_warn_unused
- eT&
- Cube<eT>::fixed<fixed_n_rows, fixed_n_cols, fixed_n_slices>::at(const uword i)
- {
- return (use_extra) ? mem_local_extra[i] : mem_local[i];
- }
- template<typename eT>
- template<uword fixed_n_rows, uword fixed_n_cols, uword fixed_n_slices>
- arma_inline
- arma_warn_unused
- const eT&
- Cube<eT>::fixed<fixed_n_rows, fixed_n_cols, fixed_n_slices>::at(const uword i) const
- {
- return (use_extra) ? mem_local_extra[i] : mem_local[i];
- }
- template<typename eT>
- template<uword fixed_n_rows, uword fixed_n_cols, uword fixed_n_slices>
- arma_inline
- arma_warn_unused
- eT&
- Cube<eT>::fixed<fixed_n_rows, fixed_n_cols, fixed_n_slices>::operator() (const uword i)
- {
- arma_debug_check( (i >= fixed_n_elem), "Cube::operator(): index out of bounds");
-
- return (use_extra) ? mem_local_extra[i] : mem_local[i];
- }
- template<typename eT>
- template<uword fixed_n_rows, uword fixed_n_cols, uword fixed_n_slices>
- arma_inline
- arma_warn_unused
- const eT&
- Cube<eT>::fixed<fixed_n_rows, fixed_n_cols, fixed_n_slices>::operator() (const uword i) const
- {
- arma_debug_check( (i >= fixed_n_elem), "Cube::operator(): index out of bounds");
-
- return (use_extra) ? mem_local_extra[i] : mem_local[i];
- }
- template<typename eT>
- template<uword fixed_n_rows, uword fixed_n_cols, uword fixed_n_slices>
- arma_inline
- arma_warn_unused
- eT&
- Cube<eT>::fixed<fixed_n_rows, fixed_n_cols, fixed_n_slices>::at(const uword in_row, const uword in_col, const uword in_slice)
- {
- const uword i = in_slice*fixed_n_elem_slice + in_col*fixed_n_rows + in_row;
-
- return (use_extra) ? mem_local_extra[i] : mem_local[i];
- }
- template<typename eT>
- template<uword fixed_n_rows, uword fixed_n_cols, uword fixed_n_slices>
- arma_inline
- arma_warn_unused
- const eT&
- Cube<eT>::fixed<fixed_n_rows, fixed_n_cols, fixed_n_slices>::at(const uword in_row, const uword in_col, const uword in_slice) const
- {
- const uword i = in_slice*fixed_n_elem_slice + in_col*fixed_n_rows + in_row;
-
- return (use_extra) ? mem_local_extra[i] : mem_local[i];
- }
- template<typename eT>
- template<uword fixed_n_rows, uword fixed_n_cols, uword fixed_n_slices>
- arma_inline
- arma_warn_unused
- eT&
- Cube<eT>::fixed<fixed_n_rows, fixed_n_cols, fixed_n_slices>::operator() (const uword in_row, const uword in_col, const uword in_slice)
- {
- arma_debug_check
- (
- (in_row >= fixed_n_rows ) ||
- (in_col >= fixed_n_cols ) ||
- (in_slice >= fixed_n_slices)
- ,
- "operator(): index out of bounds"
- );
-
- const uword i = in_slice*fixed_n_elem_slice + in_col*fixed_n_rows + in_row;
-
- return (use_extra) ? mem_local_extra[i] : mem_local[i];
- }
- template<typename eT>
- template<uword fixed_n_rows, uword fixed_n_cols, uword fixed_n_slices>
- arma_inline
- arma_warn_unused
- const eT&
- Cube<eT>::fixed<fixed_n_rows, fixed_n_cols, fixed_n_slices>::operator() (const uword in_row, const uword in_col, const uword in_slice) const
- {
- arma_debug_check
- (
- (in_row >= fixed_n_rows ) ||
- (in_col >= fixed_n_cols ) ||
- (in_slice >= fixed_n_slices)
- ,
- "Cube::operator(): index out of bounds"
- );
-
- const uword i = in_slice*fixed_n_elem_slice + in_col*fixed_n_rows + in_row;
-
- return (use_extra) ? mem_local_extra[i] : mem_local[i];
- }
- //
- // Cube_aux
- //! prefix ++
- template<typename eT>
- arma_inline
- void
- Cube_aux::prefix_pp(Cube<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>
- arma_inline
- void
- Cube_aux::prefix_pp(Cube< std::complex<T> >& x)
- {
- x += T(1);
- }
- //! postfix ++
- template<typename eT>
- arma_inline
- void
- Cube_aux::postfix_pp(Cube<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>
- arma_inline
- void
- Cube_aux::postfix_pp(Cube< std::complex<T> >& x)
- {
- x += T(1);
- }
- //! prefix --
- template<typename eT>
- arma_inline
- void
- Cube_aux::prefix_mm(Cube<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>
- arma_inline
- void
- Cube_aux::prefix_mm(Cube< std::complex<T> >& x)
- {
- x -= T(1);
- }
- //! postfix --
- template<typename eT>
- arma_inline
- void
- Cube_aux::postfix_mm(Cube<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>
- arma_inline
- void
- Cube_aux::postfix_mm(Cube< std::complex<T> >& x)
- {
- x -= T(1);
- }
- template<typename eT, typename T1>
- inline
- void
- Cube_aux::set_real(Cube<eT>& out, const BaseCube<eT,T1>& X)
- {
- arma_extra_debug_sigprint();
-
- const unwrap_cube<T1> tmp(X.get_ref());
- const Cube<eT>& A = tmp.M;
-
- arma_debug_assert_same_size( out, A, "Cube::set_real()" );
-
- out = A;
- }
- template<typename eT, typename T1>
- inline
- void
- Cube_aux::set_imag(Cube<eT>&, const BaseCube<eT,T1>&)
- {
- arma_extra_debug_sigprint();
- }
- template<typename T, typename T1>
- inline
- void
- Cube_aux::set_real(Cube< std::complex<T> >& out, const BaseCube<T,T1>& X)
- {
- arma_extra_debug_sigprint();
-
- typedef typename std::complex<T> eT;
-
- const ProxyCube<T1> P(X.get_ref());
-
- const uword local_n_rows = P.get_n_rows();
- const uword local_n_cols = P.get_n_cols();
- const uword local_n_slices = P.get_n_slices();
-
- arma_debug_assert_same_size
- (
- out.n_rows, out.n_cols, out.n_slices,
- local_n_rows, local_n_cols, local_n_slices,
- "Cube::set_real()"
- );
-
- eT* out_mem = out.memptr();
-
- if(ProxyCube<T1>::use_at == false)
- {
- typedef typename ProxyCube<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].real() = PA[i];
- out_mem[i] = std::complex<T>( A[i], out_mem[i].imag() );
- }
- }
- else
- {
- for(uword slice = 0; slice < local_n_slices; ++slice)
- 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,slice), (*out_mem).imag() );
- out_mem++;
- }
- }
- }
- template<typename T, typename T1>
- inline
- void
- Cube_aux::set_imag(Cube< std::complex<T> >& out, const BaseCube<T,T1>& X)
- {
- arma_extra_debug_sigprint();
-
- typedef typename std::complex<T> eT;
-
- const ProxyCube<T1> P(X.get_ref());
-
- const uword local_n_rows = P.get_n_rows();
- const uword local_n_cols = P.get_n_cols();
- const uword local_n_slices = P.get_n_slices();
-
- arma_debug_assert_same_size
- (
- out.n_rows, out.n_cols, out.n_slices,
- local_n_rows, local_n_cols, local_n_slices,
- "Cube::set_imag()"
- );
-
- eT* out_mem = out.memptr();
-
- if(ProxyCube<T1>::use_at == false)
- {
- typedef typename ProxyCube<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].imag() = PA[i];
- out_mem[i] = std::complex<T>( out_mem[i].real(), A[i] );
- }
- }
- else
- {
- for(uword slice = 0; slice < local_n_slices; ++slice)
- 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,slice) );
- out_mem++;
- }
- }
- }
- #ifdef ARMA_EXTRA_CUBE_MEAT
- #include ARMA_INCFILE_WRAP(ARMA_EXTRA_CUBE_MEAT)
- #endif
- //! @}
|