Skip to content

Commit c15c3e6

Browse files
committed
Updated / relaxed C++11 check
1 parent d25f83e commit c15c3e6

File tree

8 files changed

+253
-14
lines changed

8 files changed

+253
-14
lines changed

inst/include/armadillo_bits/compiler_check.hpp

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,16 @@
1616
// ------------------------------------------------------------------------
1717

1818

19+
#undef ARMA_HAVE_CXX11
1920
#undef ARMA_HAVE_CXX14
2021
#undef ARMA_HAVE_CXX17
2122
#undef ARMA_HAVE_CXX20
2223
#undef ARMA_HAVE_CXX23
2324

25+
#if (__cplusplus >= 201103L)
26+
#define ARMA_HAVE_CXX11
27+
#endif
28+
2429
#if (__cplusplus >= 201402L)
2530
#define ARMA_HAVE_CXX14
2631
#endif
@@ -42,6 +47,9 @@
4247
#if defined(_MSVC_LANG)
4348

4449
#if (_MSVC_LANG >= 201402L)
50+
#undef ARMA_HAVE_CXX11
51+
#define ARMA_HAVE_CXX11
52+
4553
#undef ARMA_HAVE_CXX14
4654
#define ARMA_HAVE_CXX14
4755
#endif
@@ -70,8 +78,15 @@
7078
#endif
7179

7280

73-
#if !defined(ARMA_HAVE_CXX14)
74-
#error "*** C++14 compiler required; enable C++14 mode in your compiler, or use an earlier version of Armadillo"
81+
#if !defined(ARMA_HAVE_CXX11)
82+
#error "*** C++11 compiler required; enable C++11 mode in your compiler, or use an earlier version of Armadillo"
83+
#endif
84+
85+
86+
#if (!defined(ARMA_HAVE_CXX14))
87+
#if (!defined(ARMA_IGNORE_DEPRECATED_MARKER)) || defined(ARMA_DONT_IGNORE_DEPRECATED_MARKER) || defined(ARMA_DEBUG)
88+
#pragma message ("INFO: support for C++11 is deprecated")
89+
#endif
7590
#endif
7691

7792

inst/include/armadillo_bits/compiler_setup.hpp

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@
3434
#define arma_aligned
3535
#define arma_align_mem
3636
#define arma_warn_unused
37-
#define arma_deprecated [[deprecated]]
38-
#define arma_frown(msg) [[deprecated(msg)]]
37+
#define arma_deprecated
38+
#define arma_frown(msg)
3939
#define arma_malloc
4040
#define arma_inline inline
4141
#define arma_noinline
@@ -175,6 +175,8 @@
175175
#undef arma_aligned
176176
#undef arma_align_mem
177177
#undef arma_warn_unused
178+
#undef arma_deprecated
179+
#undef arma_frown
178180
#undef arma_malloc
179181
#undef arma_inline
180182
#undef arma_noinline
@@ -184,6 +186,8 @@
184186
#define arma_aligned __attribute__((__aligned__))
185187
#define arma_align_mem __attribute__((__aligned__(16)))
186188
#define arma_warn_unused __attribute__((__warn_unused_result__))
189+
#define arma_deprecated __attribute__((__deprecated__))
190+
#define arma_frown(msg) __attribute__((__deprecated__(msg)))
187191
#define arma_malloc __attribute__((__malloc__))
188192
#define arma_inline __attribute__((__always_inline__)) inline
189193
#define arma_noinline __attribute__((__noinline__))
@@ -243,6 +247,16 @@
243247
#define arma_warn_unused __attribute__((__warn_unused_result__))
244248
#endif
245249

250+
#if __has_attribute(__deprecated__)
251+
#undef arma_deprecated
252+
#define arma_deprecated __attribute__((__deprecated__))
253+
#endif
254+
255+
#if __has_attribute(__deprecated__)
256+
#undef arma_frown
257+
#define arma_frown(msg) __attribute__((__deprecated__(msg)))
258+
#endif
259+
246260
#if __has_attribute(__malloc__)
247261
#undef arma_malloc
248262
#define arma_malloc __attribute__((__malloc__))
@@ -302,6 +316,8 @@
302316
#error "*** newer compiler required ***"
303317
#endif
304318

319+
#undef arma_deprecated
320+
#define arma_deprecated __declspec(deprecated)
305321
// #undef arma_inline
306322
// #define arma_inline __forceinline inline
307323

@@ -359,6 +375,15 @@
359375
#endif
360376

361377

378+
#if defined(ARMA_HAVE_CXX14)
379+
#undef arma_deprecated
380+
#define arma_deprecated [[deprecated]]
381+
382+
#undef arma_frown
383+
#define arma_frown(msg) [[deprecated(msg)]]
384+
#endif
385+
386+
362387
#if defined(ARMA_HAVE_CXX17)
363388
#undef arma_warn_unused
364389
#define arma_warn_unused [[nodiscard]]

inst/include/armadillo_bits/debug.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1420,6 +1420,7 @@ inline void arma_debug_check(bool state, const char* msg) { arma_conform_check(
14201420
<< " (" << nickname << ')';
14211421

14221422
out << "\n@ arma_config::wrapper = " << arma_config::wrapper;
1423+
out << "\n@ arma_config::cxx14 = " << arma_config::cxx14;
14231424
out << "\n@ arma_config::cxx17 = " << arma_config::cxx17;
14241425
out << "\n@ arma_config::cxx20 = " << arma_config::cxx20;
14251426
out << "\n@ arma_config::cxx23 = " << arma_config::cxx23;

inst/include/armadillo_bits/fn_accu.hpp

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ accu(const Glue<T1,T2,glue_times>& expr)
314314

315315
arma_conform_assert_mul_size(PA.get_n_rows(), PA.get_n_cols(), PB.get_n_rows(), PB.get_n_cols(), "matrix multiplication");
316316

317-
return op_dot::apply_proxy(PA,PB);
317+
return op_dot::apply_proxy_linear(PA,PB);
318318
}
319319
}
320320

@@ -339,11 +339,42 @@ accu(const eGlue<T1,T2,eglue_schur>& expr)
339339
typedef typename expr_type::proxy1_type::stored_type P1_stored_type;
340340
typedef typename expr_type::proxy2_type::stored_type P2_stored_type;
341341

342+
constexpr bool is_sv = (is_subview<P1_stored_type>::value) || (is_subview<P2_stored_type>::value);
343+
344+
if( (is_sv) && (expr.get_n_rows() >= 4) )
345+
{
346+
arma_debug_print("accu(): eglue_schur subview optimisation");
347+
348+
typedef typename T1::elem_type eT;
349+
350+
const sv_keep_unwrap<P1_stored_type>& UA(expr.P1.Q);
351+
const sv_keep_unwrap<P2_stored_type>& UB(expr.P2.Q);
352+
353+
typedef typename sv_keep_unwrap<T1>::stored_type UA_M_type;
354+
typedef typename sv_keep_unwrap<T2>::stored_type UB_M_type;
355+
356+
const UA_M_type& A = UA.M;
357+
const UB_M_type& B = UB.M;
358+
359+
// A and B have the same size (checked by the eGlue constructor)
360+
361+
const uword A_n_rows = A.n_rows;
362+
const uword A_n_cols = A.n_cols;
363+
364+
eT acc = eT(0);
365+
366+
for(uword c=0; c < A_n_cols; ++c) { acc += op_dot::direct_dot(A_n_rows, A.colptr(c), B.colptr(c)); }
367+
368+
return acc;
369+
}
370+
342371
constexpr bool have_direct_mem_1 = (is_Mat<P1_stored_type>::value) || (is_subview_col<P1_stored_type>::value);
343372
constexpr bool have_direct_mem_2 = (is_Mat<P2_stored_type>::value) || (is_subview_col<P2_stored_type>::value);
344373

345374
if(have_direct_mem_1 && have_direct_mem_2)
346375
{
376+
arma_debug_print("accu(): eglue_schur direct_mem optimisation");
377+
347378
const quasi_unwrap<P1_stored_type> tmp1(expr.P1.Q);
348379
const quasi_unwrap<P2_stored_type> tmp2(expr.P2.Q);
349380

inst/include/armadillo_bits/fn_as_scalar.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ as_scalar_redirect<2>::apply(const Glue<T1, T2, glue_times>& X)
117117
"as_scalar(): incompatible dimensions"
118118
);
119119

120-
return op_dot::apply_proxy(PA,PB);
120+
return op_dot::apply_proxy_linear(PA,PB);
121121
}
122122
}
123123

inst/include/armadillo_bits/op_dot_bones.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,10 @@ class op_dot
5757
arma_hot inline static typename T1::elem_type apply(const T1& X, const T2& Y);
5858

5959
template<typename T1, typename T2>
60-
arma_hot inline static typename arma_not_cx<typename T1::elem_type>::result apply_proxy(const Proxy<T1>& PA, const Proxy<T2>& PB);
60+
arma_hot inline static typename arma_not_cx<typename T1::elem_type>::result apply_proxy_linear(const Proxy<T1>& PA, const Proxy<T2>& PB);
6161

6262
template<typename T1, typename T2>
63-
arma_hot inline static typename arma_cx_only<typename T1::elem_type>::result apply_proxy(const Proxy<T1>& PA, const Proxy<T2>& PB);
63+
arma_hot inline static typename arma_cx_only<typename T1::elem_type>::result apply_proxy_linear(const Proxy<T1>& PA, const Proxy<T2>& PB);
6464
};
6565

6666

inst/include/armadillo_bits/op_dot_meat.hpp

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,8 @@ op_dot::apply(const T1& X, const T2& Y)
216216

217217
if( (A.m.n_rows == 1) && (B.m.n_rows == 1) )
218218
{
219+
arma_debug_print("op_dot::apply(): subview_row optimisation");
220+
219221
arma_conform_check( (A.n_elem != B.n_elem), "dot(): objects must have the same number of elements" );
220222

221223
const eT* A_mem = A.m.memptr();
@@ -225,10 +227,47 @@ op_dot::apply(const T1& X, const T2& Y)
225227
}
226228
}
227229

230+
if(is_subview<T1>::value || is_subview<T2>::value)
231+
{
232+
arma_debug_print("op_dot::apply(): subview optimisation");
233+
234+
const sv_keep_unwrap<T1>& UA(X);
235+
const sv_keep_unwrap<T2>& UB(Y);
236+
237+
typedef typename sv_keep_unwrap<T1>::stored_type UA_M_type;
238+
typedef typename sv_keep_unwrap<T2>::stored_type UB_M_type;
239+
240+
const UA_M_type& A = UA.M;
241+
const UB_M_type& B = UB.M;
242+
243+
const uword A_n_rows = A.n_rows;
244+
const uword A_n_cols = A.n_cols;
245+
246+
if( (A_n_rows == B.n_rows) && (A_n_cols == B.n_cols) )
247+
{
248+
eT acc = eT(0);
249+
250+
for(uword c=0; c < A_n_cols; ++c) { acc += op_dot::direct_dot(A_n_rows, A.colptr(c), B.colptr(c)); }
251+
252+
return acc;
253+
}
254+
else
255+
{
256+
const quasi_unwrap<UA_M_type> UUA(A);
257+
const quasi_unwrap<UB_M_type> UUB(B);
258+
259+
arma_conform_check( (UUA.M.n_elem != UUB.M.n_elem), "dot(): objects must have the same number of elements" );
260+
261+
return op_dot::direct_dot(UUA.M.n_elem, UUA.M.memptr(), UUB.M.memptr());
262+
}
263+
}
264+
228265
// if possible, bypass transposes of non-complex vectors
229266

230267
if( (is_cx<eT>::no) && (resolves_to_vector<T1>::value) && (resolves_to_vector<T2>::value) && (partial_unwrap<T1>::is_fast) && (partial_unwrap<T2>::is_fast) )
231268
{
269+
arma_debug_print("op_dot::apply(): vector optimisation");
270+
232271
const partial_unwrap<T1> UA(X);
233272
const partial_unwrap<T2> UB(Y);
234273

@@ -250,6 +289,8 @@ op_dot::apply(const T1& X, const T2& Y)
250289

251290
if(proxy_is_mat || use_at || have_direct_mem)
252291
{
292+
arma_debug_print("op_dot::apply(): direct_mem optimisation");
293+
253294
const quasi_unwrap<T1> A(X);
254295
const quasi_unwrap<T2> B(Y);
255296

@@ -263,15 +304,15 @@ op_dot::apply(const T1& X, const T2& Y)
263304

264305
arma_conform_check( (PA.get_n_elem() != PB.get_n_elem()), "dot(): objects must have the same number of elements" );
265306

266-
return op_dot::apply_proxy(PA,PB);
307+
return op_dot::apply_proxy_linear(PA,PB);
267308
}
268309

269310

270311

271312
template<typename T1, typename T2>
272313
inline
273314
typename arma_not_cx<typename T1::elem_type>::result
274-
op_dot::apply_proxy(const Proxy<T1>& PA, const Proxy<T2>& PB)
315+
op_dot::apply_proxy_linear(const Proxy<T1>& PA, const Proxy<T2>& PB)
275316
{
276317
arma_debug_sigprint();
277318

@@ -308,7 +349,7 @@ op_dot::apply_proxy(const Proxy<T1>& PA, const Proxy<T2>& PB)
308349
template<typename T1, typename T2>
309350
inline
310351
typename arma_cx_only<typename T1::elem_type>::result
311-
op_dot::apply_proxy(const Proxy<T1>& PA, const Proxy<T2>& PB)
352+
op_dot::apply_proxy_linear(const Proxy<T1>& PA, const Proxy<T2>& PB)
312353
{
313354
arma_debug_sigprint();
314355

0 commit comments

Comments
 (0)