traits.hpp 27 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241
  1. // Copyright 2008-2016 Conrad Sanderson (http://conradsanderson.id.au)
  2. // Copyright 2008-2016 National ICT Australia (NICTA)
  3. //
  4. // Licensed under the Apache License, Version 2.0 (the "License");
  5. // you may not use this file except in compliance with the License.
  6. // You may obtain a copy of the License at
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. // ------------------------------------------------------------------------
  15. //! \addtogroup traits
  16. //! @{
  17. template<typename T1>
  18. struct get_pod_type
  19. { typedef T1 result; };
  20. template<typename T2>
  21. struct get_pod_type< std::complex<T2> >
  22. { typedef T2 result; };
  23. template<typename T>
  24. struct is_Mat_fixed_only
  25. {
  26. typedef char yes[1];
  27. typedef char no[2];
  28. template<typename X> static yes& check(typename X::Mat_fixed_type*);
  29. template<typename> static no& check(...);
  30. static const bool value = ( sizeof(check<T>(0)) == sizeof(yes) );
  31. };
  32. template<typename T>
  33. struct is_Row_fixed_only
  34. {
  35. typedef char yes[1];
  36. typedef char no[2];
  37. template<typename X> static yes& check(typename X::Row_fixed_type*);
  38. template<typename> static no& check(...);
  39. static const bool value = ( sizeof(check<T>(0)) == sizeof(yes) );
  40. };
  41. template<typename T>
  42. struct is_Col_fixed_only
  43. {
  44. typedef char yes[1];
  45. typedef char no[2];
  46. template<typename X> static yes& check(typename X::Col_fixed_type*);
  47. template<typename> static no& check(...);
  48. static const bool value = ( sizeof(check<T>(0)) == sizeof(yes) );
  49. };
  50. template<typename T>
  51. struct is_Mat_fixed
  52. { static const bool value = ( is_Mat_fixed_only<T>::value || is_Row_fixed_only<T>::value || is_Col_fixed_only<T>::value ); };
  53. template<typename T>
  54. struct is_Mat_only
  55. { static const bool value = is_Mat_fixed_only<T>::value; };
  56. template<typename eT>
  57. struct is_Mat_only< Mat<eT> >
  58. { static const bool value = true; };
  59. template<typename eT>
  60. struct is_Mat_only< const Mat<eT> >
  61. { static const bool value = true; };
  62. template<typename T>
  63. struct is_Mat
  64. { static const bool value = ( is_Mat_fixed_only<T>::value || is_Row_fixed_only<T>::value || is_Col_fixed_only<T>::value ); };
  65. template<typename eT>
  66. struct is_Mat< Mat<eT> >
  67. { static const bool value = true; };
  68. template<typename eT>
  69. struct is_Mat< const Mat<eT> >
  70. { static const bool value = true; };
  71. template<typename eT>
  72. struct is_Mat< Row<eT> >
  73. { static const bool value = true; };
  74. template<typename eT>
  75. struct is_Mat< const Row<eT> >
  76. { static const bool value = true; };
  77. template<typename eT>
  78. struct is_Mat< Col<eT> >
  79. { static const bool value = true; };
  80. template<typename eT>
  81. struct is_Mat< const Col<eT> >
  82. { static const bool value = true; };
  83. template<typename T>
  84. struct is_Row
  85. { static const bool value = is_Row_fixed_only<T>::value; };
  86. template<typename eT>
  87. struct is_Row< Row<eT> >
  88. { static const bool value = true; };
  89. template<typename eT>
  90. struct is_Row< const Row<eT> >
  91. { static const bool value = true; };
  92. template<typename T>
  93. struct is_Col
  94. { static const bool value = is_Col_fixed_only<T>::value; };
  95. template<typename eT>
  96. struct is_Col< Col<eT> >
  97. { static const bool value = true; };
  98. template<typename eT>
  99. struct is_Col< const Col<eT> >
  100. { static const bool value = true; };
  101. template<typename T>
  102. struct is_diagview
  103. { static const bool value = false; };
  104. template<typename eT>
  105. struct is_diagview< diagview<eT> >
  106. { static const bool value = true; };
  107. template<typename eT>
  108. struct is_diagview< const diagview<eT> >
  109. { static const bool value = true; };
  110. template<typename T>
  111. struct is_subview
  112. { static const bool value = false; };
  113. template<typename eT>
  114. struct is_subview< subview<eT> >
  115. { static const bool value = true; };
  116. template<typename eT>
  117. struct is_subview< const subview<eT> >
  118. { static const bool value = true; };
  119. template<typename T>
  120. struct is_subview_row
  121. { static const bool value = false; };
  122. template<typename eT>
  123. struct is_subview_row< subview_row<eT> >
  124. { static const bool value = true; };
  125. template<typename eT>
  126. struct is_subview_row< const subview_row<eT> >
  127. { static const bool value = true; };
  128. template<typename T>
  129. struct is_subview_col
  130. { static const bool value = false; };
  131. template<typename eT>
  132. struct is_subview_col< subview_col<eT> >
  133. { static const bool value = true; };
  134. template<typename eT>
  135. struct is_subview_col< const subview_col<eT> >
  136. { static const bool value = true; };
  137. template<typename T>
  138. struct is_subview_elem1
  139. { static const bool value = false; };
  140. template<typename eT, typename T1>
  141. struct is_subview_elem1< subview_elem1<eT, T1> >
  142. { static const bool value = true; };
  143. template<typename eT, typename T1>
  144. struct is_subview_elem1< const subview_elem1<eT, T1> >
  145. { static const bool value = true; };
  146. template<typename T>
  147. struct is_subview_elem2
  148. { static const bool value = false; };
  149. template<typename eT, typename T1, typename T2>
  150. struct is_subview_elem2< subview_elem2<eT, T1, T2> >
  151. { static const bool value = true; };
  152. template<typename eT, typename T1, typename T2>
  153. struct is_subview_elem2< const subview_elem2<eT, T1, T2> >
  154. { static const bool value = true; };
  155. //
  156. //
  157. //
  158. template<typename T>
  159. struct is_Cube
  160. { static const bool value = false; };
  161. template<typename eT>
  162. struct is_Cube< Cube<eT> >
  163. { static const bool value = true; };
  164. template<typename eT>
  165. struct is_Cube< const Cube<eT> >
  166. { static const bool value = true; };
  167. template<typename T>
  168. struct is_subview_cube
  169. { static const bool value = false; };
  170. template<typename eT>
  171. struct is_subview_cube< subview_cube<eT> >
  172. { static const bool value = true; };
  173. template<typename eT>
  174. struct is_subview_cube< const subview_cube<eT> >
  175. { static const bool value = true; };
  176. template<typename T>
  177. struct is_subview_cube_slices
  178. { static const bool value = false; };
  179. template<typename eT, typename T1>
  180. struct is_subview_cube_slices< subview_cube_slices<eT,T1> >
  181. { static const bool value = true; };
  182. template<typename eT, typename T1>
  183. struct is_subview_cube_slices< const subview_cube_slices<eT,T1> >
  184. { static const bool value = true; };
  185. //
  186. //
  187. //
  188. template<typename T>
  189. struct is_Gen
  190. { static const bool value = false; };
  191. template<typename T1, typename gen_type>
  192. struct is_Gen< Gen<T1,gen_type> >
  193. { static const bool value = true; };
  194. template<typename T1, typename gen_type>
  195. struct is_Gen< const Gen<T1,gen_type> >
  196. { static const bool value = true; };
  197. template<typename T>
  198. struct is_Op
  199. { static const bool value = false; };
  200. template<typename T1, typename op_type>
  201. struct is_Op< Op<T1,op_type> >
  202. { static const bool value = true; };
  203. template<typename T1, typename op_type>
  204. struct is_Op< const Op<T1,op_type> >
  205. { static const bool value = true; };
  206. template<typename T>
  207. struct is_CubeToMatOp
  208. { static const bool value = false; };
  209. template<typename T1, typename op_type>
  210. struct is_CubeToMatOp< CubeToMatOp<T1,op_type> >
  211. { static const bool value = true; };
  212. template<typename T1, typename op_type>
  213. struct is_CubeToMatOp< const CubeToMatOp<T1,op_type> >
  214. { static const bool value = true; };
  215. template<typename T>
  216. struct is_SpToDOp
  217. { static const bool value = false; };
  218. template<typename T1, typename op_type>
  219. struct is_SpToDOp< SpToDOp<T1,op_type> >
  220. { static const bool value = true; };
  221. template<typename T1, typename op_type>
  222. struct is_SpToDOp< const SpToDOp<T1,op_type> >
  223. { static const bool value = true; };
  224. template<typename T>
  225. struct is_eOp
  226. { static const bool value = false; };
  227. template<typename T1, typename eop_type>
  228. struct is_eOp< eOp<T1,eop_type> >
  229. { static const bool value = true; };
  230. template<typename T1, typename eop_type>
  231. struct is_eOp< const eOp<T1,eop_type> >
  232. { static const bool value = true; };
  233. template<typename T>
  234. struct is_mtOp
  235. { static const bool value = false; };
  236. template<typename eT, typename T1, typename op_type>
  237. struct is_mtOp< mtOp<eT, T1, op_type> >
  238. { static const bool value = true; };
  239. template<typename eT, typename T1, typename op_type>
  240. struct is_mtOp< const mtOp<eT, T1, op_type> >
  241. { static const bool value = true; };
  242. template<typename T>
  243. struct is_Glue
  244. { static const bool value = false; };
  245. template<typename T1, typename T2, typename glue_type>
  246. struct is_Glue< Glue<T1,T2,glue_type> >
  247. { static const bool value = true; };
  248. template<typename T1, typename T2, typename glue_type>
  249. struct is_Glue< const Glue<T1,T2,glue_type> >
  250. { static const bool value = true; };
  251. template<typename T>
  252. struct is_eGlue
  253. { static const bool value = false; };
  254. template<typename T1, typename T2, typename eglue_type>
  255. struct is_eGlue< eGlue<T1,T2,eglue_type> >
  256. { static const bool value = true; };
  257. template<typename T1, typename T2, typename eglue_type>
  258. struct is_eGlue< const eGlue<T1,T2,eglue_type> >
  259. { static const bool value = true; };
  260. template<typename T>
  261. struct is_mtGlue
  262. { static const bool value = false; };
  263. template<typename eT, typename T1, typename T2, typename glue_type>
  264. struct is_mtGlue< mtGlue<eT, T1, T2, glue_type> >
  265. { static const bool value = true; };
  266. template<typename eT, typename T1, typename T2, typename glue_type>
  267. struct is_mtGlue< const mtGlue<eT, T1, T2, glue_type> >
  268. { static const bool value = true; };
  269. //
  270. //
  271. template<typename T>
  272. struct is_glue_times
  273. { static const bool value = false; };
  274. template<typename T1, typename T2>
  275. struct is_glue_times< Glue<T1,T2,glue_times> >
  276. { static const bool value = true; };
  277. template<typename T1, typename T2>
  278. struct is_glue_times< const Glue<T1,T2,glue_times> >
  279. { static const bool value = true; };
  280. template<typename T>
  281. struct is_glue_times_diag
  282. { static const bool value = false; };
  283. template<typename T1, typename T2>
  284. struct is_glue_times_diag< Glue<T1,T2,glue_times_diag> >
  285. { static const bool value = true; };
  286. template<typename T1, typename T2>
  287. struct is_glue_times_diag< const Glue<T1,T2,glue_times_diag> >
  288. { static const bool value = true; };
  289. template<typename T>
  290. struct is_op_diagmat
  291. { static const bool value = false; };
  292. template<typename T1>
  293. struct is_op_diagmat< Op<T1,op_diagmat> >
  294. { static const bool value = true; };
  295. template<typename T1>
  296. struct is_op_diagmat< const Op<T1,op_diagmat> >
  297. { static const bool value = true; };
  298. //
  299. //
  300. template<typename T>
  301. struct is_Mat_trans
  302. { static const bool value = false; };
  303. template<typename T1>
  304. struct is_Mat_trans< Op<T1,op_htrans> >
  305. { static const bool value = is_Mat<T1>::value; };
  306. template<typename T1>
  307. struct is_Mat_trans< Op<T1,op_htrans2> >
  308. { static const bool value = is_Mat<T1>::value; };
  309. //
  310. //
  311. template<typename T>
  312. struct is_GenCube
  313. { static const bool value = false; };
  314. template<typename eT, typename gen_type>
  315. struct is_GenCube< GenCube<eT,gen_type> >
  316. { static const bool value = true; };
  317. template<typename T>
  318. struct is_OpCube
  319. { static const bool value = false; };
  320. template<typename T1, typename op_type>
  321. struct is_OpCube< OpCube<T1,op_type> >
  322. { static const bool value = true; };
  323. template<typename T>
  324. struct is_eOpCube
  325. { static const bool value = false; };
  326. template<typename T1, typename eop_type>
  327. struct is_eOpCube< eOpCube<T1,eop_type> >
  328. { static const bool value = true; };
  329. template<typename T>
  330. struct is_mtOpCube
  331. { static const bool value = false; };
  332. template<typename eT, typename T1, typename op_type>
  333. struct is_mtOpCube< mtOpCube<eT, T1, op_type> >
  334. { static const bool value = true; };
  335. template<typename T>
  336. struct is_GlueCube
  337. { static const bool value = false; };
  338. template<typename T1, typename T2, typename glue_type>
  339. struct is_GlueCube< GlueCube<T1,T2,glue_type> >
  340. { static const bool value = true; };
  341. template<typename T>
  342. struct is_eGlueCube
  343. { static const bool value = false; };
  344. template<typename T1, typename T2, typename eglue_type>
  345. struct is_eGlueCube< eGlueCube<T1,T2,eglue_type> >
  346. { static const bool value = true; };
  347. template<typename T>
  348. struct is_mtGlueCube
  349. { static const bool value = false; };
  350. template<typename eT, typename T1, typename T2, typename glue_type>
  351. struct is_mtGlueCube< mtGlueCube<eT, T1, T2, glue_type> >
  352. { static const bool value = true; };
  353. //
  354. //
  355. //
  356. template<typename T1>
  357. struct is_arma_type2
  358. {
  359. static const bool value
  360. = is_Mat<T1>::value
  361. || is_Gen<T1>::value
  362. || is_Op<T1>::value
  363. || is_CubeToMatOp<T1>::value
  364. || is_SpToDOp<T1>::value
  365. || is_Glue<T1>::value
  366. || is_eOp<T1>::value
  367. || is_eGlue<T1>::value
  368. || is_mtOp<T1>::value
  369. || is_mtGlue<T1>::value
  370. || is_diagview<T1>::value
  371. || is_subview<T1>::value
  372. || is_subview_row<T1>::value
  373. || is_subview_col<T1>::value
  374. || is_subview_elem1<T1>::value
  375. || is_subview_elem2<T1>::value
  376. ;
  377. };
  378. // due to rather baroque C++ rules for proving constant expressions,
  379. // certain compilers may get confused with the combination of conditional inheritance, nested classes and the shenanigans in is_Mat_fixed_only.
  380. // below we explicitly ensure the type is forced to be const, which seems to eliminate the confusion.
  381. template<typename T1>
  382. struct is_arma_type
  383. {
  384. static const bool value = is_arma_type2<const T1>::value;
  385. };
  386. template<typename T1>
  387. struct is_arma_cube_type
  388. {
  389. static const bool value
  390. = is_Cube<T1>::value
  391. || is_GenCube<T1>::value
  392. || is_OpCube<T1>::value
  393. || is_eOpCube<T1>::value
  394. || is_mtOpCube<T1>::value
  395. || is_GlueCube<T1>::value
  396. || is_eGlueCube<T1>::value
  397. || is_mtGlueCube<T1>::value
  398. || is_subview_cube<T1>::value
  399. || is_subview_cube_slices<T1>::value
  400. ;
  401. };
  402. //
  403. //
  404. //
  405. template<typename T>
  406. struct is_SpMat
  407. { static const bool value = false; };
  408. template<typename eT>
  409. struct is_SpMat< SpMat<eT> >
  410. { static const bool value = true; };
  411. template<typename eT>
  412. struct is_SpMat< SpCol<eT> >
  413. { static const bool value = true; };
  414. template<typename eT>
  415. struct is_SpMat< SpRow<eT> >
  416. { static const bool value = true; };
  417. template<typename T>
  418. struct is_SpRow
  419. { static const bool value = false; };
  420. template<typename eT>
  421. struct is_SpRow< SpRow<eT> >
  422. { static const bool value = true; };
  423. template<typename T>
  424. struct is_SpCol
  425. { static const bool value = false; };
  426. template<typename eT>
  427. struct is_SpCol< SpCol<eT> >
  428. { static const bool value = true; };
  429. template<typename T>
  430. struct is_SpSubview
  431. { static const bool value = false; };
  432. template<typename eT>
  433. struct is_SpSubview< SpSubview<eT> >
  434. { static const bool value = true; };
  435. template<typename T>
  436. struct is_SpSubview_col
  437. { static const bool value = false; };
  438. template<typename eT>
  439. struct is_SpSubview_col< SpSubview_col<eT> >
  440. { static const bool value = true; };
  441. template<typename T>
  442. struct is_SpSubview_row
  443. { static const bool value = false; };
  444. template<typename eT>
  445. struct is_SpSubview_row< SpSubview_row<eT> >
  446. { static const bool value = true; };
  447. template<typename T>
  448. struct is_spdiagview
  449. { static const bool value = false; };
  450. template<typename eT>
  451. struct is_spdiagview< spdiagview<eT> >
  452. { static const bool value = true; };
  453. template<typename T>
  454. struct is_SpOp
  455. { static const bool value = false; };
  456. template<typename T1, typename op_type>
  457. struct is_SpOp< SpOp<T1,op_type> >
  458. { static const bool value = true; };
  459. template<typename T>
  460. struct is_SpGlue
  461. { static const bool value = false; };
  462. template<typename T1, typename T2, typename glue_type>
  463. struct is_SpGlue< SpGlue<T1,T2,glue_type> >
  464. { static const bool value = true; };
  465. template<typename T>
  466. struct is_mtSpOp
  467. { static const bool value = false; };
  468. template<typename eT, typename T1, typename spop_type>
  469. struct is_mtSpOp< mtSpOp<eT, T1, spop_type> >
  470. { static const bool value = true; };
  471. template<typename T>
  472. struct is_mtSpGlue
  473. { static const bool value = false; };
  474. template<typename eT, typename T1, typename T2, typename spglue_type>
  475. struct is_mtSpGlue< mtSpGlue<eT, T1, T2, spglue_type> >
  476. { static const bool value = true; };
  477. template<typename T1>
  478. struct is_arma_sparse_type
  479. {
  480. static const bool value
  481. = is_SpMat<T1>::value
  482. || is_SpSubview<T1>::value
  483. || is_SpSubview_col<T1>::value
  484. || is_SpSubview_row<T1>::value
  485. || is_spdiagview<T1>::value
  486. || is_SpOp<T1>::value
  487. || is_SpGlue<T1>::value
  488. || is_mtSpOp<T1>::value
  489. || is_mtSpGlue<T1>::value
  490. ;
  491. };
  492. //
  493. //
  494. //
  495. template<typename T1, typename T2>
  496. struct is_same_type
  497. {
  498. static const bool value = false;
  499. static const bool yes = false;
  500. static const bool no = true;
  501. };
  502. template<typename T1>
  503. struct is_same_type<T1,T1>
  504. {
  505. static const bool value = true;
  506. static const bool yes = true;
  507. static const bool no = false;
  508. };
  509. //
  510. //
  511. //
  512. template<typename T1>
  513. struct is_u8
  514. { static const bool value = false; };
  515. template<>
  516. struct is_u8<u8>
  517. { static const bool value = true; };
  518. template<typename T1>
  519. struct is_s8
  520. { static const bool value = false; };
  521. template<>
  522. struct is_s8<s8>
  523. { static const bool value = true; };
  524. template<typename T1>
  525. struct is_u16
  526. { static const bool value = false; };
  527. template<>
  528. struct is_u16<u16>
  529. { static const bool value = true; };
  530. template<typename T1>
  531. struct is_s16
  532. { static const bool value = false; };
  533. template<>
  534. struct is_s16<s16>
  535. { static const bool value = true; };
  536. template<typename T1>
  537. struct is_u32
  538. { static const bool value = false; };
  539. template<>
  540. struct is_u32<u32>
  541. { static const bool value = true; };
  542. template<typename T1>
  543. struct is_s32
  544. { static const bool value = false; };
  545. template<>
  546. struct is_s32<s32>
  547. { static const bool value = true; };
  548. #if defined(ARMA_USE_U64S64)
  549. template<typename T1>
  550. struct is_u64
  551. { static const bool value = false; };
  552. template<>
  553. struct is_u64<u64>
  554. { static const bool value = true; };
  555. template<typename T1>
  556. struct is_s64
  557. { static const bool value = false; };
  558. template<>
  559. struct is_s64<s64>
  560. { static const bool value = true; };
  561. #endif
  562. template<typename T1>
  563. struct is_ulng_t
  564. { static const bool value = false; };
  565. template<>
  566. struct is_ulng_t<ulng_t>
  567. { static const bool value = true; };
  568. template<typename T1>
  569. struct is_slng_t
  570. { static const bool value = false; };
  571. template<>
  572. struct is_slng_t<slng_t>
  573. { static const bool value = true; };
  574. template<typename T1>
  575. struct is_ulng_t_32
  576. { static const bool value = false; };
  577. template<>
  578. struct is_ulng_t_32<ulng_t>
  579. { static const bool value = (sizeof(ulng_t) == 4); };
  580. template<typename T1>
  581. struct is_slng_t_32
  582. { static const bool value = false; };
  583. template<>
  584. struct is_slng_t_32<slng_t>
  585. { static const bool value = (sizeof(slng_t) == 4); };
  586. template<typename T1>
  587. struct is_ulng_t_64
  588. { static const bool value = false; };
  589. template<>
  590. struct is_ulng_t_64<ulng_t>
  591. { static const bool value = (sizeof(ulng_t) == 8); };
  592. template<typename T1>
  593. struct is_slng_t_64
  594. { static const bool value = false; };
  595. template<>
  596. struct is_slng_t_64<slng_t>
  597. { static const bool value = (sizeof(slng_t) == 8); };
  598. template<typename T1>
  599. struct is_uword
  600. { static const bool value = false; };
  601. template<>
  602. struct is_uword<uword>
  603. { static const bool value = true; };
  604. template<typename T1>
  605. struct is_sword
  606. { static const bool value = false; };
  607. template<>
  608. struct is_sword<sword>
  609. { static const bool value = true; };
  610. template<typename T1>
  611. struct is_float
  612. { static const bool value = false; };
  613. template<>
  614. struct is_float<float>
  615. { static const bool value = true; };
  616. template<typename T1>
  617. struct is_double
  618. { static const bool value = false; };
  619. template<>
  620. struct is_double<double>
  621. { static const bool value = true; };
  622. template<typename T1>
  623. struct is_real
  624. { static const bool value = false; };
  625. template<>
  626. struct is_real<float>
  627. { static const bool value = true; };
  628. template<>
  629. struct is_real<double>
  630. { static const bool value = true; };
  631. template<typename T1>
  632. struct is_cx
  633. {
  634. static const bool value = false;
  635. static const bool yes = false;
  636. static const bool no = true;
  637. };
  638. // template<>
  639. template<typename T>
  640. struct is_cx< std::complex<T> >
  641. {
  642. static const bool value = true;
  643. static const bool yes = true;
  644. static const bool no = false;
  645. };
  646. template<typename T1>
  647. struct is_cx_float
  648. {
  649. static const bool value = false;
  650. static const bool yes = false;
  651. static const bool no = true;
  652. };
  653. template<>
  654. struct is_cx_float< std::complex<float> >
  655. {
  656. static const bool value = true;
  657. static const bool yes = true;
  658. static const bool no = false;
  659. };
  660. template<typename T1>
  661. struct is_cx_double
  662. {
  663. static const bool value = false;
  664. static const bool yes = false;
  665. static const bool no = true;
  666. };
  667. template<>
  668. struct is_cx_double< std::complex<double> >
  669. {
  670. static const bool value = true;
  671. static const bool yes = true;
  672. static const bool no = false;
  673. };
  674. template<typename T1>
  675. struct is_supported_elem_type
  676. {
  677. static const bool value = \
  678. is_u8<T1>::value ||
  679. is_s8<T1>::value ||
  680. is_u16<T1>::value ||
  681. is_s16<T1>::value ||
  682. is_u32<T1>::value ||
  683. is_s32<T1>::value ||
  684. #if defined(ARMA_USE_U64S64)
  685. is_u64<T1>::value ||
  686. is_s64<T1>::value ||
  687. #endif
  688. #if defined(ARMA_ALLOW_LONG)
  689. is_ulng_t<T1>::value ||
  690. is_slng_t<T1>::value ||
  691. #endif
  692. is_float<T1>::value ||
  693. is_double<T1>::value ||
  694. is_cx_float<T1>::value ||
  695. is_cx_double<T1>::value;
  696. };
  697. template<typename T1>
  698. struct is_supported_blas_type
  699. {
  700. static const bool value = \
  701. is_float<T1>::value ||
  702. is_double<T1>::value ||
  703. is_cx_float<T1>::value ||
  704. is_cx_double<T1>::value;
  705. };
  706. template<typename T>
  707. struct is_signed
  708. {
  709. static const bool value = true;
  710. };
  711. template<> struct is_signed<u8> { static const bool value = false; };
  712. template<> struct is_signed<u16> { static const bool value = false; };
  713. template<> struct is_signed<u32> { static const bool value = false; };
  714. #if defined(ARMA_USE_U64S64)
  715. template<> struct is_signed<u64> { static const bool value = false; };
  716. #endif
  717. #if defined(ARMA_ALLOW_LONG)
  718. template<> struct is_signed<ulng_t> { static const bool value = false; };
  719. #endif
  720. template<typename T>
  721. struct is_non_integral
  722. {
  723. static const bool value = false;
  724. };
  725. template<> struct is_non_integral< float > { static const bool value = true; };
  726. template<> struct is_non_integral< double > { static const bool value = true; };
  727. template<> struct is_non_integral< std::complex<float> > { static const bool value = true; };
  728. template<> struct is_non_integral< std::complex<double> > { static const bool value = true; };
  729. //
  730. class arma_junk_class;
  731. template<typename T1, typename T2>
  732. struct force_different_type
  733. {
  734. typedef T1 T1_result;
  735. typedef T2 T2_result;
  736. };
  737. template<typename T1>
  738. struct force_different_type<T1,T1>
  739. {
  740. typedef T1 T1_result;
  741. typedef arma_junk_class T2_result;
  742. };
  743. //
  744. template<typename T1>
  745. struct resolves_to_vector_default
  746. {
  747. static const bool value = false;
  748. static const bool yes = false;
  749. static const bool no = true;
  750. };
  751. template<typename T1>
  752. struct resolves_to_vector_test
  753. {
  754. static const bool value = (T1::is_col || T1::is_row || T1::is_xvec);
  755. static const bool yes = (T1::is_col || T1::is_row || T1::is_xvec);
  756. static const bool no = ((T1::is_col || T1::is_row || T1::is_xvec) == false);
  757. };
  758. template<typename T1, bool condition>
  759. struct resolves_to_vector_redirect {};
  760. template<typename T1>
  761. struct resolves_to_vector_redirect<T1, false> { typedef resolves_to_vector_default<T1> result; };
  762. template<typename T1>
  763. struct resolves_to_vector_redirect<T1, true> { typedef resolves_to_vector_test<T1> result; };
  764. template<typename T1>
  765. struct resolves_to_vector : public resolves_to_vector_redirect<T1, is_arma_type<T1>::value>::result {};
  766. template<typename T1>
  767. struct resolves_to_sparse_vector : public resolves_to_vector_redirect<T1, is_arma_sparse_type<T1>::value>::result {};
  768. //
  769. template<typename T1>
  770. struct resolves_to_rowvector_default { static const bool value = false; };
  771. template<typename T1>
  772. struct resolves_to_rowvector_test { static const bool value = T1::is_row; };
  773. template<typename T1, bool condition>
  774. struct resolves_to_rowvector_redirect {};
  775. template<typename T1>
  776. struct resolves_to_rowvector_redirect<T1, false> { typedef resolves_to_rowvector_default<T1> result; };
  777. template<typename T1>
  778. struct resolves_to_rowvector_redirect<T1, true> { typedef resolves_to_rowvector_test<T1> result; };
  779. template<typename T1>
  780. struct resolves_to_rowvector : public resolves_to_rowvector_redirect<T1, is_arma_type<T1>::value>::result {};
  781. //
  782. template<typename T1>
  783. struct resolves_to_colvector_default { static const bool value = false; };
  784. template<typename T1>
  785. struct resolves_to_colvector_test { static const bool value = T1::is_col; };
  786. template<typename T1, bool condition>
  787. struct resolves_to_colvector_redirect {};
  788. template<typename T1>
  789. struct resolves_to_colvector_redirect<T1, false> { typedef resolves_to_colvector_default<T1> result; };
  790. template<typename T1>
  791. struct resolves_to_colvector_redirect<T1, true> { typedef resolves_to_colvector_test<T1> result; };
  792. template<typename T1>
  793. struct resolves_to_colvector : public resolves_to_colvector_redirect<T1, is_arma_type<T1>::value>::result {};
  794. template<typename T1>
  795. struct is_outer_product
  796. { static const bool value = false; };
  797. template<typename T1, typename T2>
  798. struct is_outer_product< Glue<T1,T2,glue_times> >
  799. { static const bool value = (resolves_to_colvector<T1>::value && resolves_to_rowvector<T2>::value); };
  800. template<typename T1>
  801. struct has_op_inv
  802. { static const bool value = false; };
  803. template<typename T1>
  804. struct has_op_inv< Op<T1,op_inv> >
  805. { static const bool value = true; };
  806. template<typename T1, typename T2>
  807. struct has_op_inv< Glue<Op<T1,op_inv>, T2, glue_times> >
  808. { static const bool value = true; };
  809. template<typename T1, typename T2>
  810. struct has_op_inv< Glue<T1, Op<T2,op_inv>, glue_times> >
  811. { static const bool value = true; };
  812. template<typename T1>
  813. struct has_op_inv_sympd
  814. { static const bool value = false; };
  815. template<typename T1>
  816. struct has_op_inv_sympd< Op<T1,op_inv_sympd> >
  817. { static const bool value = true; };
  818. template<typename T1, typename T2>
  819. struct has_op_inv_sympd< Glue<Op<T1,op_inv_sympd>, T2, glue_times> >
  820. { static const bool value = true; };
  821. template<typename T1, typename T2>
  822. struct has_op_inv_sympd< Glue<T1, Op<T2,op_inv_sympd>, glue_times> >
  823. { static const bool value = true; };
  824. template<typename T>
  825. struct has_nested_op_traits
  826. {
  827. typedef char yes[1];
  828. typedef char no[2];
  829. template<typename X> static yes& check(typename X::template traits<void>*);
  830. template<typename> static no& check(...);
  831. static const bool value = ( sizeof(check<T>(0)) == sizeof(yes) );
  832. };
  833. template<typename T>
  834. struct has_nested_glue_traits
  835. {
  836. typedef char yes[1];
  837. typedef char no[2];
  838. template<typename X> static yes& check(typename X::template traits<void,void>*);
  839. template<typename> static no& check(...);
  840. static const bool value = ( sizeof(check<T>(0)) == sizeof(yes) );
  841. };
  842. //! @}