Initial FP16 support
This commit is contained in:
committed by
conradsnicta
parent
252d43ae35
commit
f07af5a111
@@ -562,9 +562,10 @@ Conrad Sanderson and Ryan Curtin.
|
||||
<tr><td><a href="#output_streams">output streams</a></td><td> </td><td>streams for printing warnings and errors</td></tr>
|
||||
<tr><td><a href="#uword">uword / sword</a></td><td> </td><td>shorthand for unsigned and signed integers</td></tr>
|
||||
<tr><td><a href="#cx_double">cx_double / cx_float</a></td><td> </td><td>shorthand for std::complex<double> and std::complex<float></td></tr>
|
||||
<tr style="background-color: #F5F5F5;"><td><a href="#lowprec">fp16</a></td><td> </td><td>shorthand for low-precision types, if supported</td></tr>
|
||||
<tr style="background-color: #F5F5F5;"><td><a href="#syntax">Matlab/Armadillo syntax differences</a></td><td> </td><td>examples of Matlab syntax and conceptually corresponding Armadillo syntax</td></tr>
|
||||
<tr style="background-color: #F5F5F5;"><td><a href="#example_prog">example program</a></td><td> </td><td>short example program</td></tr>
|
||||
<tr style="background-color: #F5F5F5;"><td><a href="#config_hpp">config.hpp</a></td><td> </td><td>configuration options</td></tr>
|
||||
<tr><td><a href="#config_hpp">config.hpp</a></td><td> </td><td>configuration options</td></tr>
|
||||
<tr><td><a href="#changelog">API additions</a></td><td> </td><td>API stability and list of API additions</td></tr>
|
||||
<!--<tr><td><a href="#log_add">log_add</a></td><td> </td><td>TODO</td></tr>-->
|
||||
<!--<tr><td><a href="#catching_exceptions">catching exceptions</a></td><td> </td><td>TODO</td></tr>-->
|
||||
@@ -604,6 +605,10 @@ The root matrix class is <b>Mat<</b><i>type</i><b>></b>, where <i>type</i>
|
||||
</li>
|
||||
</ul>
|
||||
</li>
|
||||
<li>
|
||||
When compiling with C++23 support, <i>type</i> can also be the low-precision type <i>std::float16_t</i>, if hardware support is detected;
|
||||
see the <a href="#lowprec">low-precision support</a> section for more details
|
||||
</li>
|
||||
<br>
|
||||
<li>
|
||||
For convenience the following typedefs have been defined:
|
||||
@@ -698,6 +703,17 @@ For convenience the following typedefs have been defined:
|
||||
<code>Mat<<a href="#uword">sword</a>></code>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td style="vertical-align: top; text-align: right;">
|
||||
<code>fp16_mat</code>
|
||||
</td>
|
||||
<td style="vertical-align: top;">
|
||||
=
|
||||
</td>
|
||||
<td style="vertical-align: top;">
|
||||
<code>Mat<<a href="#lowprec">fp16</a>></code><font style="font-size: 75%"><i> (only if supported by compiler and hardware)</i></font></font>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</ul>
|
||||
@@ -1060,6 +1076,23 @@ For convenience the following typedefs have been defined:
|
||||
<code>Col<<a href="#uword">sword</a>></code>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td style="vertical-align: top; text-align: right;">
|
||||
<code>fp16_vec</code>
|
||||
</td>
|
||||
<td style="vertical-align: top;">
|
||||
=
|
||||
</td>
|
||||
<td style="vertical-align: top; text-align: right;">
|
||||
<code>fp16_colvec</code>
|
||||
</td>
|
||||
<td style="vertical-align: top;">
|
||||
=
|
||||
</td>
|
||||
<td style="vertical-align: top;">
|
||||
<code>Col<<a href="#lowprec">fp16</a>></code>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</ul>
|
||||
@@ -1311,6 +1344,17 @@ For convenience the following typedefs have been defined:
|
||||
<code>Row<<a href="#uword">sword</a>></code>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td style="vertical-align: top; text-align: right;">
|
||||
<code>fp16_rowvec</code>
|
||||
</td>
|
||||
<td style="vertical-align: top;">
|
||||
=
|
||||
</td>
|
||||
<td style="vertical-align: top;">
|
||||
<code>Row<<a href="#lowprec">fp16</a>></code><font style="font-size: 75%"><i> (only if supported by compiler and hardware)</i></font>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</ul>
|
||||
@@ -18394,6 +18438,86 @@ cx_double val = X(2,3);
|
||||
<br>
|
||||
</ul>
|
||||
|
||||
<div class="pagebreak"></div><div class="noprint"><hr class="greyline"><br></div>
|
||||
<a name="lowprec"></a>
|
||||
<b>fp16</b>
|
||||
<ul>
|
||||
<li>
|
||||
Convenience short form (typedef) for low-precision element types; <b>compiler and hardware support is required</b>
|
||||
</li>
|
||||
<br>
|
||||
<br>
|
||||
<li>
|
||||
The low-precision <i>fp16</i> type can be used with all Armadillo functions that do not require LAPACK (e.g., almost any operation that is not a decomposition like <code>svd()</code> or similar)
|
||||
</li>
|
||||
<br>
|
||||
<li>
|
||||
To enable automatic support for low-precision elements, <b>both</b> of the following are necessary:
|
||||
<br>
|
||||
<ul>
|
||||
<li>compiler C++23 support (e.g. compile with <code>-std=c++23</code> or similar)</li>
|
||||
<br>
|
||||
<li>hardware support for native FP16 operation (not emulated):
|
||||
<ul>
|
||||
<li>ARM devices require the <code>+fp16</code> extension (typically found on ARMv8.2-A+ devices)</li>
|
||||
<li>x86_64 devices require the AVX512-FP16 extension</li>
|
||||
</ul>
|
||||
</li>
|
||||
<br>
|
||||
<li>
|
||||
If no compiler or hardware support is detected, <i>fp16</i> will <b>not</b> be available
|
||||
</li>
|
||||
<br>
|
||||
<li>
|
||||
The C++ low-precision types <code>std::float16_t</code> is preferentially used to define the <i>fp16</i> type,
|
||||
but in certain situations other underlying intrinsic types such as <code>_Float16</code>, <code>__fp16</code>, or similar will be used
|
||||
</li>
|
||||
<br>
|
||||
<li>
|
||||
<b>NOTE:</b>
|
||||
Low-precision types can have numerical stability issues,
|
||||
and are not suitable for all applications:
|
||||
<i>fp16</i> only has a range from roughly -65536 to 65536!
|
||||
</li>
|
||||
<br>
|
||||
<li>
|
||||
The <code>ARMA_FORCE_USE_FP16</code> macro can be defined before including Armadillo
|
||||
to force emulated support even when native hardware support is not detected
|
||||
<ul>
|
||||
<li>Emulated FP16 support can be <b>very slow!</b></li>
|
||||
<li>Manually forcing support is only recommended when Armadillo's auto-detection is failing;</li>
|
||||
<li>in which case, please send an email to the developers to improve the auto-detection!</li>
|
||||
</ul>
|
||||
</li>
|
||||
<br>
|
||||
<li>
|
||||
Example:
|
||||
<ul>
|
||||
<pre>
|
||||
fp16_mat X(5, 5, fill::randu);
|
||||
|
||||
X(1,2) = fp16(1.5);
|
||||
|
||||
fp16 val = X(2,3);
|
||||
</pre>
|
||||
</ul>
|
||||
</li>
|
||||
<li>See also:
|
||||
<ul>
|
||||
<li><a href="https://en.wikipedia.org/wiki/Half-precision_floating-point_format">half-precision floating point format on Wikipedia</a></li>
|
||||
<li><a href="https://gcc.gnu.org/onlinedocs/gcc/Half-Precision.html">gcc half-precision documentation</a></li>
|
||||
<li><a href="https://clang.llvm.org/docs/LanguageExtensions.html#half-precision-floating-point">clang half-precision documentation</a></li>
|
||||
<li><a href="https://en.cppreference.com/w/cpp/header/stdfloat.html">std::float16_t reference</a></li>
|
||||
<li><a href="https://cplusplus.com/doc/tutorial/other_data_types/">explanation of <i>typedef</i></a></li>
|
||||
<li><a href="#Mat">fp16_mat</a> matrix type
|
||||
<li><a href="#Col">fp16_vec</a> vector type
|
||||
</ul>
|
||||
</li>
|
||||
<br>
|
||||
</ul>
|
||||
|
||||
|
||||
|
||||
<div class="pagebreak"></div><div class="noprint"><hr class="greyline"><br></div>
|
||||
<a name="syntax"></a>
|
||||
<b>Examples of Matlab/Octave syntax and conceptually corresponding Armadillo syntax</b>
|
||||
@@ -20287,6 +20411,7 @@ List of additions and changes for each version:
|
||||
<li>Version 15.0:
|
||||
<ul>
|
||||
<li>(under development)</li>
|
||||
<li>added support for <a href="#lowprec">low-precision fp16 type</a> when native hardware support is detected</li>
|
||||
<li>...</li>
|
||||
</ul>
|
||||
</li>
|
||||
|
||||
@@ -62,6 +62,10 @@
|
||||
// #include <system_error>
|
||||
// #endif
|
||||
|
||||
#if defined(ARMA_HAVE_CXX23)
|
||||
#include <stdfloat>
|
||||
#endif
|
||||
|
||||
#if ( defined(__unix__) || defined(__unix) || defined(_POSIX_C_SOURCE) || (defined(__APPLE__) && defined(__MACH__)) ) && !defined(_WIN32)
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
@@ -54,6 +54,9 @@ SpMat<eT>::~SpMat()
|
||||
if(values ) { memory::release(access::rw(values)); }
|
||||
if(row_indices) { memory::release(access::rw(row_indices)); }
|
||||
if(col_ptrs ) { memory::release(access::rw(col_ptrs)); }
|
||||
|
||||
// FP16 is not currently supported for sparse matrices
|
||||
arma_type_check(( is_fp16<eT>::value == true ));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -198,6 +198,21 @@ arma_isnan(const std::complex<T>& x)
|
||||
|
||||
|
||||
|
||||
//
|
||||
// wrappers for arma_pow()---see FP16 specialization below
|
||||
|
||||
|
||||
|
||||
template<typename eT, typename pow_eT>
|
||||
inline
|
||||
eT
|
||||
arma_pow(eT base, pow_eT pow)
|
||||
{
|
||||
return std::pow(base, pow);
|
||||
}
|
||||
|
||||
|
||||
|
||||
//
|
||||
// implementation of arma_sign()
|
||||
|
||||
@@ -417,4 +432,87 @@ struct arma_arg< std::complex<double> >
|
||||
|
||||
|
||||
|
||||
//
|
||||
// wrappers for low-precision fp16
|
||||
|
||||
#if defined(ARMA_HAVE_FP16)
|
||||
|
||||
template<>
|
||||
inline
|
||||
bool
|
||||
arma_isfinite(fp16 x)
|
||||
{
|
||||
// Technically not required until C++23 but basically every compiler supports it.
|
||||
// (this is true for almost every fp16 overload below)
|
||||
return std::isfinite(x);
|
||||
}
|
||||
|
||||
|
||||
|
||||
template<>
|
||||
inline
|
||||
bool
|
||||
arma_isinf(fp16 x)
|
||||
{
|
||||
return std::isinf(x);
|
||||
}
|
||||
|
||||
|
||||
|
||||
template<>
|
||||
inline
|
||||
bool
|
||||
arma_isnan(fp16 x)
|
||||
{
|
||||
return std::isnan(x);
|
||||
}
|
||||
|
||||
|
||||
|
||||
template<typename pow_eT>
|
||||
inline
|
||||
fp16
|
||||
arma_pow(fp16 base, pow_eT pow)
|
||||
{
|
||||
return std::pow(base, fp16(pow));
|
||||
}
|
||||
|
||||
|
||||
|
||||
template<>
|
||||
inline
|
||||
fp16
|
||||
arma_hypot(const fp16 x, const fp16 y)
|
||||
{
|
||||
return std::hypot(x, y);
|
||||
}
|
||||
|
||||
|
||||
|
||||
template<>
|
||||
inline
|
||||
fp16
|
||||
arma_sinc(const fp16 x)
|
||||
{
|
||||
return arma_sinc_generic(x);
|
||||
}
|
||||
|
||||
|
||||
|
||||
template<>
|
||||
struct arma_arg<fp16>
|
||||
{
|
||||
static
|
||||
inline
|
||||
fp16
|
||||
eval(const fp16 x)
|
||||
{
|
||||
return std::arg(x);
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
//! @}
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
|
||||
//! Generate the first line of the header used for saving matrices in text format.
|
||||
//! Format: "ARMA_MAT_TXT_ABXYZ".
|
||||
//! A is one of: I (for integral types) or F (for floating point types).
|
||||
//! A is one of: I (for integral types) or F (for floating point types)
|
||||
//! B is one of: U (for unsigned types), S (for signed types), N (for not applicable) or C (for complex types).
|
||||
//! XYZ specifies the width of each element in terms of bytes, eg. "008" indicates eight bytes.
|
||||
template<typename eT>
|
||||
@@ -40,6 +40,7 @@ diskio::gen_txt_header(const Mat<eT>&)
|
||||
const char* ARMA_MAT_TXT_IS004 = "ARMA_MAT_TXT_IS004";
|
||||
const char* ARMA_MAT_TXT_IU008 = "ARMA_MAT_TXT_IU008";
|
||||
const char* ARMA_MAT_TXT_IS008 = "ARMA_MAT_TXT_IS008";
|
||||
const char* ARMA_MAT_TXT_FN002 = "ARMA_MAT_TXT_FN002";
|
||||
const char* ARMA_MAT_TXT_FN004 = "ARMA_MAT_TXT_FN004";
|
||||
const char* ARMA_MAT_TXT_FN008 = "ARMA_MAT_TXT_FN008";
|
||||
const char* ARMA_MAT_TXT_FC008 = "ARMA_MAT_TXT_FC008";
|
||||
@@ -61,6 +62,7 @@ diskio::gen_txt_header(const Mat<eT>&)
|
||||
else if(is_slng_t_64<eT>::value) { header = const_cast<char*>(ARMA_MAT_TXT_IS008); }
|
||||
else if( is_float<eT>::value) { header = const_cast<char*>(ARMA_MAT_TXT_FN004); }
|
||||
else if( is_double<eT>::value) { header = const_cast<char*>(ARMA_MAT_TXT_FN008); }
|
||||
else if( is_fp16<eT>::value) { header = const_cast<char*>(ARMA_MAT_TXT_FN002); }
|
||||
else if( is_cx_float<eT>::value) { header = const_cast<char*>(ARMA_MAT_TXT_FC008); }
|
||||
else if(is_cx_double<eT>::value) { header = const_cast<char*>(ARMA_MAT_TXT_FC016); }
|
||||
|
||||
@@ -89,6 +91,7 @@ diskio::gen_bin_header(const Mat<eT>&)
|
||||
const char* ARMA_MAT_BIN_IS004 = "ARMA_MAT_BIN_IS004";
|
||||
const char* ARMA_MAT_BIN_IU008 = "ARMA_MAT_BIN_IU008";
|
||||
const char* ARMA_MAT_BIN_IS008 = "ARMA_MAT_BIN_IS008";
|
||||
const char* ARMA_MAT_BIN_FN002 = "ARMA_MAT_BIN_FN002";
|
||||
const char* ARMA_MAT_BIN_FN004 = "ARMA_MAT_BIN_FN004";
|
||||
const char* ARMA_MAT_BIN_FN008 = "ARMA_MAT_BIN_FN008";
|
||||
const char* ARMA_MAT_BIN_FC008 = "ARMA_MAT_BIN_FC008";
|
||||
@@ -110,6 +113,7 @@ diskio::gen_bin_header(const Mat<eT>&)
|
||||
else if(is_slng_t_64<eT>::value) { header = const_cast<char*>(ARMA_MAT_BIN_IS008); }
|
||||
else if( is_float<eT>::value) { header = const_cast<char*>(ARMA_MAT_BIN_FN004); }
|
||||
else if( is_double<eT>::value) { header = const_cast<char*>(ARMA_MAT_BIN_FN008); }
|
||||
else if( is_fp16<eT>::value) { header = const_cast<char*>(ARMA_MAT_BIN_FN002); }
|
||||
else if( is_cx_float<eT>::value) { header = const_cast<char*>(ARMA_MAT_BIN_FC008); }
|
||||
else if(is_cx_double<eT>::value) { header = const_cast<char*>(ARMA_MAT_BIN_FC016); }
|
||||
|
||||
@@ -138,10 +142,11 @@ diskio::gen_bin_header(const SpMat<eT>&)
|
||||
const char* ARMA_SPM_BIN_IS004 = "ARMA_SPM_BIN_IS004";
|
||||
const char* ARMA_SPM_BIN_IU008 = "ARMA_SPM_BIN_IU008";
|
||||
const char* ARMA_SPM_BIN_IS008 = "ARMA_SPM_BIN_IS008";
|
||||
//const char* ARMA_SPM_BIN_FN002 = "ARMA_SPM_BIN_FN002";
|
||||
const char* ARMA_SPM_BIN_FN004 = "ARMA_SPM_BIN_FN004";
|
||||
const char* ARMA_SPM_BIN_FN008 = "ARMA_SPM_BIN_FN008";
|
||||
const char* ARMA_SPM_BIN_FC008 = "ARMA_SPM_BIN_FC008";
|
||||
const char* ARMA_SPM_BIN_FC016 = "ARMA_SPM_BIN_FC016";
|
||||
const char* ARMA_SPM_BIN_FC016 = "ARMA_SPM_BIN_FC016";
|
||||
|
||||
char* header = nullptr;
|
||||
|
||||
@@ -159,6 +164,7 @@ diskio::gen_bin_header(const SpMat<eT>&)
|
||||
else if(is_slng_t_64<eT>::value) { header = const_cast<char*>(ARMA_SPM_BIN_IS008); }
|
||||
else if( is_float<eT>::value) { header = const_cast<char*>(ARMA_SPM_BIN_FN004); }
|
||||
else if( is_double<eT>::value) { header = const_cast<char*>(ARMA_SPM_BIN_FN008); }
|
||||
//else if( is_fp16<eT>::value) { header = const_cast<char*>(ARMA_SPM_BIN_FN002); }
|
||||
else if( is_cx_float<eT>::value) { header = const_cast<char*>(ARMA_SPM_BIN_FC008); }
|
||||
else if(is_cx_double<eT>::value) { header = const_cast<char*>(ARMA_SPM_BIN_FC016); }
|
||||
|
||||
@@ -186,6 +192,7 @@ diskio::gen_txt_header(const Cube<eT>&)
|
||||
const char* ARMA_CUB_TXT_IS004 = "ARMA_CUB_TXT_IS004";
|
||||
const char* ARMA_CUB_TXT_IU008 = "ARMA_CUB_TXT_IU008";
|
||||
const char* ARMA_CUB_TXT_IS008 = "ARMA_CUB_TXT_IS008";
|
||||
const char* ARMA_CUB_TXT_FN002 = "ARMA_CUB_TXT_FN002";
|
||||
const char* ARMA_CUB_TXT_FN004 = "ARMA_CUB_TXT_FN004";
|
||||
const char* ARMA_CUB_TXT_FN008 = "ARMA_CUB_TXT_FN008";
|
||||
const char* ARMA_CUB_TXT_FC008 = "ARMA_CUB_TXT_FC008";
|
||||
@@ -207,6 +214,7 @@ diskio::gen_txt_header(const Cube<eT>&)
|
||||
else if(is_slng_t_64<eT>::value) { header = const_cast<char*>(ARMA_CUB_TXT_IS008); }
|
||||
else if( is_float<eT>::value) { header = const_cast<char*>(ARMA_CUB_TXT_FN004); }
|
||||
else if( is_double<eT>::value) { header = const_cast<char*>(ARMA_CUB_TXT_FN008); }
|
||||
else if( is_fp16<eT>::value) { header = const_cast<char*>(ARMA_CUB_TXT_FN002); }
|
||||
else if( is_cx_float<eT>::value) { header = const_cast<char*>(ARMA_CUB_TXT_FC008); }
|
||||
else if(is_cx_double<eT>::value) { header = const_cast<char*>(ARMA_CUB_TXT_FC016); }
|
||||
|
||||
@@ -235,6 +243,7 @@ diskio::gen_bin_header(const Cube<eT>&)
|
||||
const char* ARMA_CUB_BIN_IS004 = "ARMA_CUB_BIN_IS004";
|
||||
const char* ARMA_CUB_BIN_IU008 = "ARMA_CUB_BIN_IU008";
|
||||
const char* ARMA_CUB_BIN_IS008 = "ARMA_CUB_BIN_IS008";
|
||||
const char* ARMA_CUB_BIN_FN002 = "ARMA_CUB_BIN_FN002";
|
||||
const char* ARMA_CUB_BIN_FN004 = "ARMA_CUB_BIN_FN004";
|
||||
const char* ARMA_CUB_BIN_FN008 = "ARMA_CUB_BIN_FN008";
|
||||
const char* ARMA_CUB_BIN_FC008 = "ARMA_CUB_BIN_FC008";
|
||||
@@ -256,6 +265,7 @@ diskio::gen_bin_header(const Cube<eT>&)
|
||||
else if(is_slng_t_64<eT>::value) { header = const_cast<char*>(ARMA_CUB_BIN_IS008); }
|
||||
else if( is_float<eT>::value) { header = const_cast<char*>(ARMA_CUB_BIN_FN004); }
|
||||
else if( is_double<eT>::value) { header = const_cast<char*>(ARMA_CUB_BIN_FN008); }
|
||||
else if( is_fp16<eT>::value) { header = const_cast<char*>(ARMA_CUB_BIN_FN002); }
|
||||
else if( is_cx_float<eT>::value) { header = const_cast<char*>(ARMA_CUB_BIN_FC008); }
|
||||
else if(is_cx_double<eT>::value) { header = const_cast<char*>(ARMA_CUB_BIN_FC016); }
|
||||
|
||||
@@ -655,7 +665,7 @@ diskio::prepare_stream(std::ostream& f)
|
||||
|
||||
// NOTE: for 'float' the optimum settings are f.precision(8) and cell_width = 15
|
||||
// NOTE: however, to avoid introducing errors in case single precision data is loaded as double precision,
|
||||
// NOTE: the same settings must be used for both 'float' and 'double'
|
||||
// NOTE: the same settings must be used for both 'float' and 'double' (and other floating-point types)
|
||||
}
|
||||
else
|
||||
if(is_cx<eT>::value)
|
||||
|
||||
@@ -49,6 +49,9 @@ namespace fill
|
||||
|
||||
template<> struct allow_conversion<std::complex<double>, double> { static constexpr bool value = false; };
|
||||
template<> struct allow_conversion<std::complex<double>, float > { static constexpr bool value = false; };
|
||||
#if defined(ARMA_HAVE_FP16)
|
||||
template<> struct allow_conversion<std::complex<double>, fp16 > { static constexpr bool value = false; };
|
||||
#endif
|
||||
template<> struct allow_conversion<std::complex<double>, u64 > { static constexpr bool value = false; };
|
||||
template<> struct allow_conversion<std::complex<double>, s64 > { static constexpr bool value = false; };
|
||||
template<> struct allow_conversion<std::complex<double>, u32 > { static constexpr bool value = false; };
|
||||
@@ -60,6 +63,9 @@ namespace fill
|
||||
|
||||
template<> struct allow_conversion<std::complex<float>, double> { static constexpr bool value = false; };
|
||||
template<> struct allow_conversion<std::complex<float>, float > { static constexpr bool value = false; };
|
||||
#if defined(ARMA_HAVE_FP16)
|
||||
template<> struct allow_conversion<std::complex<float>, fp16 > { static constexpr bool value = false; };
|
||||
#endif
|
||||
template<> struct allow_conversion<std::complex<float>, u64 > { static constexpr bool value = false; };
|
||||
template<> struct allow_conversion<std::complex<float>, s64 > { static constexpr bool value = false; };
|
||||
template<> struct allow_conversion<std::complex<float>, u32 > { static constexpr bool value = false; };
|
||||
@@ -74,6 +80,9 @@ namespace fill
|
||||
template<typename eT> inline bool isfinite_wrapper(eT ) { return true; }
|
||||
template<> inline bool isfinite_wrapper(float x) { return std::isfinite(x); }
|
||||
template<> inline bool isfinite_wrapper(double x) { return std::isfinite(x); }
|
||||
#if defined(ARMA_HAVE_FP16)
|
||||
template<> inline bool isfinite_wrapper(fp16 x) { return std::isfinite(x); }
|
||||
#endif
|
||||
template<typename T> inline bool isfinite_wrapper(std::complex<T>& x) { return std::isfinite(x.real()) && std::isfinite(x.imag()); }
|
||||
|
||||
//
|
||||
|
||||
@@ -42,10 +42,20 @@ typename arma_real_only<eT>::result
|
||||
chi2rnd(const eT df)
|
||||
{
|
||||
arma_debug_sigprint();
|
||||
|
||||
op_chi2rnd_varying_df<eT> generator;
|
||||
|
||||
return generator(df);
|
||||
|
||||
if(is_fp16<eT>::yes)
|
||||
{
|
||||
// std::chi_squared_distribution is undefined for types other than float, double, and long double
|
||||
op_chi2rnd_varying_df<float> generator;
|
||||
|
||||
return eT(generator(df));
|
||||
}
|
||||
else
|
||||
{
|
||||
op_chi2rnd_varying_df<eT> generator;
|
||||
|
||||
return generator(df);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ inline
|
||||
typename
|
||||
enable_if2
|
||||
<
|
||||
is_real<typename T1::pod_type>::value,
|
||||
is_blas_real<typename T1::pod_type>::value,
|
||||
const Op<T1,op_expmat>
|
||||
>::result
|
||||
expmat(const Base<typename T1::elem_type,T1>& A)
|
||||
@@ -43,7 +43,7 @@ inline
|
||||
typename
|
||||
enable_if2
|
||||
<
|
||||
is_real<typename T1::pod_type>::value,
|
||||
is_blas_real<typename T1::pod_type>::value,
|
||||
bool
|
||||
>::result
|
||||
expmat(Mat<typename T1::elem_type>& B, const Base<typename T1::elem_type,T1>& A)
|
||||
|
||||
@@ -25,14 +25,14 @@ inline
|
||||
bool
|
||||
svds_helper
|
||||
(
|
||||
Mat<typename T1::elem_type>& U,
|
||||
Col<typename T1::pod_type >& S,
|
||||
Mat<typename T1::elem_type>& V,
|
||||
const SpBase<typename T1::elem_type,T1>& X,
|
||||
const uword k,
|
||||
const typename T1::pod_type tol,
|
||||
const bool calc_UV,
|
||||
const typename arma_real_only<typename T1::elem_type>::result* junk = nullptr
|
||||
Mat<typename T1::elem_type>& U,
|
||||
Col<typename T1::pod_type >& S,
|
||||
Mat<typename T1::elem_type>& V,
|
||||
const SpBase<typename T1::elem_type,T1>& X,
|
||||
const uword k,
|
||||
const typename T1::pod_type tol,
|
||||
const bool calc_UV,
|
||||
const typename arma_blas_real_only<typename T1::elem_type>::result* junk = nullptr
|
||||
)
|
||||
{
|
||||
arma_debug_sigprint();
|
||||
@@ -270,13 +270,13 @@ inline
|
||||
bool
|
||||
svds
|
||||
(
|
||||
Mat<typename T1::elem_type>& U,
|
||||
Col<typename T1::pod_type >& S,
|
||||
Mat<typename T1::elem_type>& V,
|
||||
const SpBase<typename T1::elem_type,T1>& X,
|
||||
const uword k,
|
||||
const typename T1::pod_type tol = 0.0,
|
||||
const typename arma_real_or_cx_only<typename T1::elem_type>::result* junk = nullptr
|
||||
Mat<typename T1::elem_type>& U,
|
||||
Col<typename T1::pod_type >& S,
|
||||
Mat<typename T1::elem_type>& V,
|
||||
const SpBase<typename T1::elem_type,T1>& X,
|
||||
const uword k,
|
||||
const typename T1::pod_type tol = 0.0,
|
||||
const typename arma_blas_real_or_cx_only<typename T1::elem_type>::result* junk = nullptr
|
||||
)
|
||||
{
|
||||
arma_debug_sigprint();
|
||||
@@ -297,11 +297,11 @@ inline
|
||||
bool
|
||||
svds
|
||||
(
|
||||
Col<typename T1::pod_type >& S,
|
||||
const SpBase<typename T1::elem_type,T1>& X,
|
||||
const uword k,
|
||||
const typename T1::pod_type tol = 0.0,
|
||||
const typename arma_real_or_cx_only<typename T1::elem_type>::result* junk = nullptr
|
||||
Col<typename T1::pod_type >& S,
|
||||
const SpBase<typename T1::elem_type,T1>& X,
|
||||
const uword k,
|
||||
const typename T1::pod_type tol = 0.0,
|
||||
const typename arma_blas_real_or_cx_only<typename T1::elem_type>::result* junk = nullptr
|
||||
)
|
||||
{
|
||||
arma_debug_sigprint();
|
||||
@@ -326,10 +326,10 @@ inline
|
||||
Col<typename T1::pod_type>
|
||||
svds
|
||||
(
|
||||
const SpBase<typename T1::elem_type,T1>& X,
|
||||
const uword k,
|
||||
const typename T1::pod_type tol = 0.0,
|
||||
const typename arma_real_or_cx_only<typename T1::elem_type>::result* junk = nullptr
|
||||
const SpBase<typename T1::elem_type,T1>& X,
|
||||
const uword k,
|
||||
const typename T1::pod_type tol = 0.0,
|
||||
const typename arma_blas_real_or_cx_only<typename T1::elem_type>::result* junk = nullptr
|
||||
)
|
||||
{
|
||||
arma_debug_sigprint();
|
||||
|
||||
@@ -139,6 +139,24 @@ get_hdf5_type< double >()
|
||||
|
||||
|
||||
|
||||
#if defined(ARMA_HAVE_FP16) && defined(H5_HAVE__FLOAT16)
|
||||
template<>
|
||||
inline
|
||||
hid_t
|
||||
get_hdf5_type< fp16 >()
|
||||
{
|
||||
return H5Tcopy(H5T_NATIVE_FLOAT16);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
// NOTE: HDF5 has discussed adding bf16 support but it is not yet available.
|
||||
// https://github.com/HDFGroup/hdf5/issues/5317
|
||||
// https://forum.hdfgroup.org/t/hdf5-rfc-adding-support-for-16-bit-floating-point-and-complex-number-datatypes-to-hdf5/11975/29
|
||||
|
||||
|
||||
|
||||
//! Utility hid_t since HOFFSET() won't work with std::complex.
|
||||
template<typename eT>
|
||||
struct hdf5_complex_t
|
||||
@@ -264,6 +282,14 @@ is_supported_arma_hdf5_type(hid_t datatype)
|
||||
H5Tclose(search_type);
|
||||
if(is_equal) { return true; }
|
||||
|
||||
// check types that may or may not be supported
|
||||
#if defined(ARMA_HAVE_FP16) && defined(H5_HAVE__FLOAT16)
|
||||
search_type = get_hdf5_type<fp16>();
|
||||
is_equal = ( H5Tequal(datatype, search_type) > 0 );
|
||||
H5Tclose(search_type);
|
||||
if(is_equal) { return true; }
|
||||
#endif
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -484,7 +484,7 @@ class herk
|
||||
{
|
||||
herk<do_trans_A, use_alpha, use_beta>::apply_blas_type(C,A,alpha,beta);
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -56,8 +56,10 @@ op_chi2rnd::apply_noalias(Mat<typename T1::elem_type>& out, const Proxy<T1>& P)
|
||||
arma_debug_sigprint();
|
||||
|
||||
typedef typename T1::elem_type eT;
|
||||
// we can only make a generator for float/double/long double types
|
||||
typedef typename promote_type<eT, float>::result gT;
|
||||
|
||||
op_chi2rnd_varying_df<eT> generator;
|
||||
op_chi2rnd_varying_df<gT> generator;
|
||||
|
||||
const uword n_rows = P.get_n_rows();
|
||||
const uword n_cols = P.get_n_cols();
|
||||
@@ -74,7 +76,7 @@ op_chi2rnd::apply_noalias(Mat<typename T1::elem_type>& out, const Proxy<T1>& P)
|
||||
|
||||
for(uword i=0; i<N; ++i)
|
||||
{
|
||||
out_mem[i] = generator( Pea[i] );
|
||||
out_mem[i] = eT( generator( Pea[i] ) );
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -82,7 +84,7 @@ op_chi2rnd::apply_noalias(Mat<typename T1::elem_type>& out, const Proxy<T1>& P)
|
||||
for(uword col=0; col < n_cols; ++col)
|
||||
for(uword row=0; row < n_rows; ++row)
|
||||
{
|
||||
(*out_mem) = generator( P.at(row,col) ); ++out_mem;
|
||||
(*out_mem) = eT( generator( P.at(row,col) ) ); ++out_mem;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,9 +38,13 @@ class op_dot
|
||||
direct_dot_arma(const uword n_elem, const eT* const A, const eT* const B);
|
||||
|
||||
template<typename eT>
|
||||
arma_hot inline static typename arma_real_only<eT>::result
|
||||
arma_hot inline static typename arma_blas_real_only<eT>::result
|
||||
direct_dot(const uword n_elem, const eT* const A, const eT* const B);
|
||||
|
||||
|
||||
template<typename eT>
|
||||
arma_hot inline static typename arma_fp16_only<eT>::result
|
||||
direct_dot(const uword n_elem, const eT* const A, const eT* const B);
|
||||
|
||||
template<typename eT>
|
||||
arma_hot inline static typename arma_cx_only<eT>::result
|
||||
direct_dot(const uword n_elem, const eT* const A, const eT* const B);
|
||||
@@ -91,8 +95,11 @@ class op_cdot
|
||||
arma_hot inline static eT direct_cdot_arma(const uword n_elem, const eT* const A, const eT* const B);
|
||||
|
||||
template<typename eT>
|
||||
arma_hot inline static eT direct_cdot(const uword n_elem, const eT* const A, const eT* const B);
|
||||
|
||||
arma_hot inline static eT direct_cdot(const uword n_elem, const eT* const A, const eT* const B, const typename arma_blas_real_or_cx_only<eT>::result* junk = 0);
|
||||
|
||||
template<typename eT>
|
||||
arma_hot inline static eT direct_cdot(const uword n_elem, const eT* const A, const eT* const B, const typename arma_fp16_only<eT>::result* junk = 0);
|
||||
|
||||
template<typename T1, typename T2>
|
||||
arma_hot inline static typename T1::elem_type apply (const T1& X, const T2& Y);
|
||||
|
||||
|
||||
@@ -98,16 +98,16 @@ op_dot::direct_dot_arma(const uword n_elem, const eT* const A, const eT* const B
|
||||
|
||||
|
||||
|
||||
//! for two arrays, float and double version
|
||||
//! for two arrays, floating-point version
|
||||
template<typename eT>
|
||||
inline
|
||||
typename arma_real_only<eT>::result
|
||||
typename arma_blas_real_only<eT>::result
|
||||
op_dot::direct_dot(const uword n_elem, const eT* const A, const eT* const B)
|
||||
{
|
||||
arma_debug_sigprint();
|
||||
|
||||
if(n_elem <= 32u) { return op_dot::direct_dot_arma(n_elem, A, B); }
|
||||
|
||||
|
||||
#if defined(ARMA_USE_ATLAS)
|
||||
{
|
||||
arma_debug_print("atlas::cblas_dot()");
|
||||
@@ -129,6 +129,19 @@ op_dot::direct_dot(const uword n_elem, const eT* const A, const eT* const B)
|
||||
|
||||
|
||||
|
||||
//! for two arrays, fp16 version
|
||||
template<typename eT>
|
||||
inline
|
||||
typename arma_fp16_only<eT>::result
|
||||
op_dot::direct_dot(const uword n_elem, const eT* const A, const eT* const B)
|
||||
{
|
||||
arma_debug_sigprint();
|
||||
|
||||
return op_dot::direct_dot_arma(n_elem, A, B);
|
||||
}
|
||||
|
||||
|
||||
|
||||
//! for two arrays, complex version
|
||||
template<typename eT>
|
||||
inline
|
||||
@@ -447,9 +460,10 @@ op_cdot::direct_cdot_arma(const uword n_elem, const eT* const A, const eT* const
|
||||
template<typename eT>
|
||||
inline
|
||||
eT
|
||||
op_cdot::direct_cdot(const uword n_elem, const eT* const A, const eT* const B)
|
||||
op_cdot::direct_cdot(const uword n_elem, const eT* const A, const eT* const B, const typename arma_blas_real_or_cx_only<eT>::result* junk)
|
||||
{
|
||||
arma_debug_sigprint();
|
||||
arma_ignore(junk);
|
||||
|
||||
if(n_elem <= 32u) { return op_cdot::direct_cdot_arma(n_elem, A, B); }
|
||||
|
||||
@@ -485,6 +499,19 @@ op_cdot::direct_cdot(const uword n_elem, const eT* const A, const eT* const B)
|
||||
|
||||
|
||||
|
||||
template<typename eT>
|
||||
inline
|
||||
eT
|
||||
op_cdot::direct_cdot(const uword n_elem, const eT* const A, const eT* const B, const typename arma_fp16_only<eT>::result* junk)
|
||||
{
|
||||
arma_debug_sigprint();
|
||||
arma_ignore(junk);
|
||||
|
||||
return op_cdot::direct_cdot_arma(n_elem, A, B);
|
||||
}
|
||||
|
||||
|
||||
|
||||
template<typename T1, typename T2>
|
||||
inline
|
||||
typename T1::elem_type
|
||||
|
||||
@@ -120,12 +120,24 @@ op_norm2est::norm2est
|
||||
|
||||
if((A.n_rows == 1) || (A.n_cols == 1)) { return op_norm::vec_norm_2( Proxy< Mat<eT> >(A) ); }
|
||||
|
||||
norm2est_randu_filler<eT> randu_filler;
|
||||
// low-precision types cannot be used for norm2est_randu_filler
|
||||
// (std::uniform_real_distribution is undefined for types not float/double/long double)
|
||||
norm2est_randu_filler< typename promote_type<eT, float>::result > randu_filler;
|
||||
|
||||
Col<eT> x(A.n_rows, fill::none);
|
||||
Col<eT> y(A.n_cols, fill::none);
|
||||
|
||||
randu_filler.fill(y.memptr(), y.n_elem);
|
||||
if (is_fp16<eT>::yes)
|
||||
{
|
||||
// randu_filler can only fill floats, so do that and then convert
|
||||
Col<float> tmp(y.n_elem);
|
||||
randu_filler.fill(tmp.memptr(), tmp.n_elem);
|
||||
arrayops::convert(y.memptr(), tmp.memptr(), tmp.n_elem);
|
||||
}
|
||||
else
|
||||
{
|
||||
randu_filler.fill(y.memptr(), y.n_elem);
|
||||
}
|
||||
|
||||
T est_old = 0;
|
||||
T est_cur = 0;
|
||||
|
||||
@@ -27,12 +27,14 @@ class op_norm
|
||||
|
||||
template<typename T1> arma_hot inline static typename T1::pod_type vec_norm_1(const Proxy<T1>& P, const typename arma_not_cx<typename T1::elem_type>::result* junk = nullptr);
|
||||
template<typename T1> arma_hot inline static typename T1::pod_type vec_norm_1(const Proxy<T1>& P, const typename arma_cx_only<typename T1::elem_type>::result* junk = nullptr);
|
||||
template<typename eT> arma_hot inline static eT vec_norm_1_direct_std(const Mat<eT>& X);
|
||||
template<typename eT> arma_hot inline static eT vec_norm_1_direct_std(const Mat<eT>& X, const typename arma_blas_real_only<eT>::result* junk = nullptr);
|
||||
template<typename eT> arma_hot inline static eT vec_norm_1_direct_std(const Mat<eT>& X, const typename arma_fp16_only<eT>::result* junk = nullptr);
|
||||
template<typename eT> arma_hot inline static eT vec_norm_1_direct_mem(const uword N, const eT* A);
|
||||
|
||||
template<typename T1> arma_hot inline static typename T1::pod_type vec_norm_2(const Proxy<T1>& P, const typename arma_not_cx<typename T1::elem_type>::result* junk = nullptr);
|
||||
template<typename T1> arma_hot inline static typename T1::pod_type vec_norm_2(const Proxy<T1>& P, const typename arma_cx_only<typename T1::elem_type>::result* junk = nullptr);
|
||||
template<typename eT> arma_hot inline static eT vec_norm_2_direct_std(const Mat<eT>& X);
|
||||
template<typename eT> arma_hot inline static eT vec_norm_2_direct_std(const Mat<eT>& X, const typename arma_blas_real_only<eT>::result* junk = nullptr);
|
||||
template<typename eT> arma_hot inline static eT vec_norm_2_direct_std(const Mat<eT>& X, const typename arma_fp16_only<eT>::result* junk = nullptr);
|
||||
template<typename eT> arma_hot inline static eT vec_norm_2_direct_mem(const uword N, const eT* A);
|
||||
template<typename eT> arma_hot inline static eT vec_norm_2_direct_robust(const Mat<eT>& X);
|
||||
|
||||
@@ -42,7 +44,8 @@ class op_norm
|
||||
template<typename T1> arma_hot inline static typename T1::pod_type vec_norm_min(const Proxy<T1>& P);
|
||||
|
||||
template<typename eT> inline static typename get_pod_type<eT>::result mat_norm_1(const Mat<eT>& X);
|
||||
template<typename eT> inline static typename get_pod_type<eT>::result mat_norm_2(const Mat<eT>& X);
|
||||
template<typename eT> inline static typename get_pod_type<eT>::result mat_norm_2(const Mat<eT>& X, typename arma_blas_real_or_cx_only<eT>::result* junk = nullptr);
|
||||
template<typename eT> inline static typename get_pod_type<eT>::result mat_norm_2(const Mat<eT>& X, typename arma_fp16_only<eT>::result* junk = nullptr);
|
||||
|
||||
template<typename eT> inline static typename get_pod_type<eT>::result mat_norm_inf(const Mat<eT>& X);
|
||||
};
|
||||
|
||||
@@ -217,15 +217,16 @@ op_norm::vec_norm_1(const Proxy<T1>& P, const typename arma_cx_only<typename T1:
|
||||
template<typename eT>
|
||||
inline
|
||||
eT
|
||||
op_norm::vec_norm_1_direct_std(const Mat<eT>& X)
|
||||
op_norm::vec_norm_1_direct_std(const Mat<eT>& X, const typename arma_blas_real_only<eT>::result* junk)
|
||||
{
|
||||
arma_debug_sigprint();
|
||||
arma_ignore(junk);
|
||||
|
||||
const uword N = X.n_elem;
|
||||
const eT* A = X.memptr();
|
||||
|
||||
eT out_val = eT(0);
|
||||
|
||||
|
||||
#if defined(ARMA_USE_ATLAS)
|
||||
{
|
||||
arma_debug_print("atlas::cblas_asum()");
|
||||
@@ -254,6 +255,24 @@ op_norm::vec_norm_1_direct_std(const Mat<eT>& X)
|
||||
|
||||
|
||||
|
||||
template<typename eT>
|
||||
inline
|
||||
eT
|
||||
op_norm::vec_norm_1_direct_std(const Mat<eT>& X, const typename arma_fp16_only<eT>::result* junk)
|
||||
{
|
||||
arma_debug_sigprint();
|
||||
arma_ignore(junk);
|
||||
|
||||
const uword N = X.n_elem;
|
||||
const eT* A = X.memptr();
|
||||
|
||||
// fp16 support must be direct non-BLAS
|
||||
eT out_val = op_norm::vec_norm_1_direct_mem(N,A);
|
||||
return (out_val <= eT(0)) ? eT(0) : out_val;
|
||||
}
|
||||
|
||||
|
||||
|
||||
template<typename eT>
|
||||
inline
|
||||
eT
|
||||
@@ -518,9 +537,10 @@ op_norm::vec_norm_2(const Proxy<T1>& P, const typename arma_cx_only<typename T1:
|
||||
template<typename eT>
|
||||
inline
|
||||
eT
|
||||
op_norm::vec_norm_2_direct_std(const Mat<eT>& X)
|
||||
op_norm::vec_norm_2_direct_std(const Mat<eT>& X, const typename arma_blas_real_only<eT>::result* junk)
|
||||
{
|
||||
arma_debug_sigprint();
|
||||
arma_ignore(junk);
|
||||
|
||||
const uword N = X.n_elem;
|
||||
const eT* A = X.memptr();
|
||||
@@ -564,6 +584,34 @@ op_norm::vec_norm_2_direct_std(const Mat<eT>& X)
|
||||
|
||||
|
||||
|
||||
template<typename eT>
|
||||
inline
|
||||
eT
|
||||
op_norm::vec_norm_2_direct_std(const Mat<eT>& X, const typename arma_fp16_only<eT>::result* junk)
|
||||
{
|
||||
arma_debug_sigprint();
|
||||
arma_ignore(junk);
|
||||
|
||||
const uword N = X.n_elem;
|
||||
const eT* A = X.memptr();
|
||||
|
||||
// fp16 support must be non-BLAS
|
||||
eT out_val = op_norm::vec_norm_2_direct_mem(N,A);
|
||||
|
||||
if( (out_val != eT(0)) && arma_isfinite(out_val) )
|
||||
{
|
||||
return (out_val < eT(0)) ? eT(0) : out_val;
|
||||
}
|
||||
else
|
||||
{
|
||||
arma_debug_print("detected possible underflow or overflow");
|
||||
|
||||
return op_norm::vec_norm_2_direct_robust(X);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
template<typename eT>
|
||||
inline
|
||||
eT
|
||||
@@ -707,7 +755,7 @@ op_norm::vec_norm_k(const Proxy<T1>& P, const int k)
|
||||
|
||||
for(uword i=0; i<N; ++i)
|
||||
{
|
||||
acc += std::pow(std::abs(A[i]), k);
|
||||
acc += arma_pow(std::abs(A[i]), k);
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -720,14 +768,14 @@ op_norm::vec_norm_k(const Proxy<T1>& P, const int k)
|
||||
for(uword col=0; col < n_cols; ++col)
|
||||
for(uword row=0; row < n_rows; ++row)
|
||||
{
|
||||
acc += std::pow(std::abs(P.at(row,col)), k);
|
||||
acc += arma_pow(std::abs(P.at(row,col)), k);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for(uword col=0; col < n_cols; ++col)
|
||||
{
|
||||
acc += std::pow(std::abs(P.at(0,col)), k);
|
||||
acc += arma_pow(std::abs(P.at(0,col)), k);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -883,7 +931,7 @@ op_norm::mat_norm_1(const Mat<eT>& X)
|
||||
template<typename eT>
|
||||
inline
|
||||
typename get_pod_type<eT>::result
|
||||
op_norm::mat_norm_2(const Mat<eT>& X)
|
||||
op_norm::mat_norm_2(const Mat<eT>& X, typename arma_blas_real_or_cx_only<eT>::result* junk)
|
||||
{
|
||||
arma_debug_sigprint();
|
||||
|
||||
@@ -902,6 +950,20 @@ op_norm::mat_norm_2(const Mat<eT>& X)
|
||||
|
||||
|
||||
|
||||
template<typename eT>
|
||||
inline
|
||||
typename get_pod_type<eT>::result
|
||||
op_norm::mat_norm_2(const Mat<eT>& X, typename arma_fp16_only<eT>::result* junk)
|
||||
{
|
||||
arma_debug_sigprint();
|
||||
|
||||
arma_stop_logic_error("norm(): matrix 2-norm currently not supported for fp16 type");
|
||||
|
||||
return typename get_pod_type<eT>::result(0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
template<typename eT>
|
||||
inline
|
||||
typename get_pod_type<eT>::result
|
||||
|
||||
@@ -39,7 +39,14 @@ template<typename T> struct is_promotable<std::complex<T>, T> : public is_promot
|
||||
|
||||
template<> struct is_promotable<std::complex<double>, std::complex<float>> : public is_promotable_ok { typedef std::complex<double> result; };
|
||||
template<> struct is_promotable<std::complex<double>, float> : public is_promotable_ok { typedef std::complex<double> result; };
|
||||
#if defined(ARMA_HAVE_FP16)
|
||||
template<> struct is_promotable<std::complex<double>, fp16> : public is_promotable_ok { typedef std::complex<double> result; };
|
||||
#endif
|
||||
|
||||
template<> struct is_promotable<std::complex<float>, double> : public is_promotable_ok { typedef std::complex<double> result; };
|
||||
#if defined(ARMA_HAVE_FP16)
|
||||
template<> struct is_promotable<std::complex<float>, fp16> : public is_promotable_ok { typedef std::complex<float> result; };
|
||||
#endif
|
||||
|
||||
|
||||
template<typename t> struct is_promotable<std::complex<t>, u64> : public is_promotable_ok { typedef std::complex<t> result; };
|
||||
@@ -55,6 +62,9 @@ template<typename T> struct is_promotable<std::complex<T>, u8> : public is_p
|
||||
|
||||
|
||||
template<> struct is_promotable<double, float > : public is_promotable_ok { typedef double result; };
|
||||
#if defined(ARMA_HAVE_FP16)
|
||||
template<> struct is_promotable<double, fp16 > : public is_promotable_ok { typedef double result; };
|
||||
#endif
|
||||
template<> struct is_promotable<double, s64 > : public is_promotable_ok { typedef double result; };
|
||||
template<> struct is_promotable<double, u64 > : public is_promotable_ok { typedef double result; };
|
||||
template<> struct is_promotable<double, slng_t> : public is_promotable_ok { typedef double result; };
|
||||
@@ -66,6 +76,9 @@ template<> struct is_promotable<double, u16 > : public is_promotable_ok { type
|
||||
template<> struct is_promotable<double, s8 > : public is_promotable_ok { typedef double result; };
|
||||
template<> struct is_promotable<double, u8 > : public is_promotable_ok { typedef double result; };
|
||||
|
||||
#if defined(ARMA_HAVE_FP16)
|
||||
template<> struct is_promotable<float, fp16 > : public is_promotable_ok { typedef float result; };
|
||||
#endif
|
||||
template<> struct is_promotable<float, s64 > : public is_promotable_ok { typedef float result; };
|
||||
template<> struct is_promotable<float, u64 > : public is_promotable_ok { typedef float result; };
|
||||
template<> struct is_promotable<float, slng_t> : public is_promotable_ok { typedef float result; };
|
||||
@@ -77,6 +90,20 @@ template<> struct is_promotable<float, u16 > : public is_promotable_ok { typed
|
||||
template<> struct is_promotable<float, s8 > : public is_promotable_ok { typedef float result; };
|
||||
template<> struct is_promotable<float, u8 > : public is_promotable_ok { typedef float result; };
|
||||
|
||||
#if defined(ARMA_HAVE_FP16)
|
||||
// FP16 can only represent [-65504, 65504] so there are some cases where we have to go up!
|
||||
template<> struct is_promotable<fp16, s64 > : public is_promotable_ok { typedef float result; };
|
||||
template<> struct is_promotable<fp16, u64 > : public is_promotable_ok { typedef float result; };
|
||||
template<> struct is_promotable<fp16, slng_t> : public is_promotable_ok { typedef float result; };
|
||||
template<> struct is_promotable<fp16, ulng_t> : public is_promotable_ok { typedef float result; };
|
||||
template<> struct is_promotable<fp16, s32 > : public is_promotable_ok { typedef float result; };
|
||||
template<> struct is_promotable<fp16, u32 > : public is_promotable_ok { typedef float result; };
|
||||
template<> struct is_promotable<fp16, s16 > : public is_promotable_ok { typedef fp16 result; };
|
||||
template<> struct is_promotable<fp16, u16 > : public is_promotable_ok { typedef fp16 result; }; // very technically could not hold extreme u16s
|
||||
template<> struct is_promotable<fp16, s8 > : public is_promotable_ok { typedef fp16 result; };
|
||||
template<> struct is_promotable<fp16, u8 > : public is_promotable_ok { typedef fp16 result; };
|
||||
#endif
|
||||
|
||||
template<> struct is_promotable<u64, u32> : public is_promotable_ok { typedef u64 result; };
|
||||
template<> struct is_promotable<u64, u16> : public is_promotable_ok { typedef u64 result; };
|
||||
template<> struct is_promotable<u64, u8 > : public is_promotable_ok { typedef u64 result; };
|
||||
@@ -119,7 +146,14 @@ template<typename T> struct is_promotable<T, std::complex<T>> : public is_promot
|
||||
|
||||
template<> struct is_promotable<std::complex<float>, std::complex<double>> : public is_promotable_ok { typedef std::complex<double> result; };
|
||||
template<> struct is_promotable<float, std::complex<double>> : public is_promotable_ok { typedef std::complex<double> result; };
|
||||
#if defined(ARMA_HAVE_FP16)
|
||||
template<> struct is_promotable<fp16, std::complex<double>> : public is_promotable_ok { typedef std::complex<double> result; };
|
||||
#endif
|
||||
|
||||
template<> struct is_promotable<double, std::complex<float> > : public is_promotable_ok { typedef std::complex<double> result; };
|
||||
#if defined(ARMA_HAVE_FP16)
|
||||
template<> struct is_promotable<fp16, std::complex<float> > : public is_promotable_ok { typedef std::complex<float> result; };
|
||||
#endif
|
||||
|
||||
template<typename T> struct is_promotable<s64, std::complex<T>> : public is_promotable_ok { typedef std::complex<T> result; };
|
||||
template<typename T> struct is_promotable<u64, std::complex<T>> : public is_promotable_ok { typedef std::complex<T> result; };
|
||||
@@ -134,6 +168,9 @@ template<typename T> struct is_promotable<u8, std::complex<T>> : public is_p
|
||||
|
||||
|
||||
template<> struct is_promotable<float, double> : public is_promotable_ok { typedef double result; };
|
||||
#if defined(ARMA_HAVE_FP16)
|
||||
template<> struct is_promotable<fp16, double> : public is_promotable_ok { typedef double result; };
|
||||
#endif
|
||||
template<> struct is_promotable<s64, double> : public is_promotable_ok { typedef double result; };
|
||||
template<> struct is_promotable<u64, double> : public is_promotable_ok { typedef double result; };
|
||||
template<> struct is_promotable<slng_t, double> : public is_promotable_ok { typedef double result; };
|
||||
@@ -145,6 +182,9 @@ template<> struct is_promotable<u16, double> : public is_promotable_ok { type
|
||||
template<> struct is_promotable<s8, double> : public is_promotable_ok { typedef double result; };
|
||||
template<> struct is_promotable<u8, double> : public is_promotable_ok { typedef double result; };
|
||||
|
||||
#if defined(ARMA_HAVE_FP16)
|
||||
template<> struct is_promotable<fp16, float> : public is_promotable_ok { typedef float result; };
|
||||
#endif
|
||||
template<> struct is_promotable<s64, float> : public is_promotable_ok { typedef float result; };
|
||||
template<> struct is_promotable<u64, float> : public is_promotable_ok { typedef float result; };
|
||||
template<> struct is_promotable<slng_t, float> : public is_promotable_ok { typedef float result; };
|
||||
@@ -156,6 +196,19 @@ template<> struct is_promotable<u16, float> : public is_promotable_ok { typed
|
||||
template<> struct is_promotable<s8, float> : public is_promotable_ok { typedef float result; };
|
||||
template<> struct is_promotable<u8, float> : public is_promotable_ok { typedef float result; };
|
||||
|
||||
#if defined(ARMA_HAVE_FP16)
|
||||
template<> struct is_promotable<s64, fp16> : public is_promotable_ok { typedef float result; };
|
||||
template<> struct is_promotable<u64, fp16> : public is_promotable_ok { typedef float result; };
|
||||
template<> struct is_promotable<slng_t, fp16> : public is_promotable_ok { typedef float result; };
|
||||
template<> struct is_promotable<ulng_t, fp16> : public is_promotable_ok { typedef float result; };
|
||||
template<> struct is_promotable<s32, fp16> : public is_promotable_ok { typedef float result; };
|
||||
template<> struct is_promotable<u32, fp16> : public is_promotable_ok { typedef float result; };
|
||||
template<> struct is_promotable<s16, fp16> : public is_promotable_ok { typedef fp16 result; };
|
||||
template<> struct is_promotable<u16, fp16> : public is_promotable_ok { typedef fp16 result; };
|
||||
template<> struct is_promotable<s8, fp16> : public is_promotable_ok { typedef fp16 result; };
|
||||
template<> struct is_promotable<u8, fp16> : public is_promotable_ok { typedef fp16 result; };
|
||||
#endif
|
||||
|
||||
template<> struct is_promotable<u32, u64> : public is_promotable_ok { typedef u64 result; };
|
||||
template<> struct is_promotable<u16, u64> : public is_promotable_ok { typedef u64 result; };
|
||||
template<> struct is_promotable<u8, u64> : public is_promotable_ok { typedef u64 result; };
|
||||
|
||||
@@ -40,6 +40,9 @@ template<> struct arma_scalar_only< ulng_t > { typedef ulng_t result; };
|
||||
template<> struct arma_scalar_only< slng_t > { typedef slng_t result; };
|
||||
template<> struct arma_scalar_only< float > { typedef float result; };
|
||||
template<> struct arma_scalar_only< double > { typedef double result; };
|
||||
#if defined(ARMA_HAVE_FP16)
|
||||
template<> struct arma_scalar_only< fp16 > { typedef fp16 result; };
|
||||
#endif
|
||||
template<> struct arma_scalar_only< cx_float > { typedef cx_float result; };
|
||||
template<> struct arma_scalar_only< cx_double > { typedef cx_double result; };
|
||||
|
||||
@@ -89,6 +92,9 @@ template<> struct arma_signed_only< s64 > { typedef s64 result; };
|
||||
template<> struct arma_signed_only< slng_t > { typedef slng_t result; };
|
||||
template<> struct arma_signed_only< float > { typedef float result; };
|
||||
template<> struct arma_signed_only< double > { typedef double result; };
|
||||
#if defined(ARMA_HAVE_FP16)
|
||||
template<> struct arma_signed_only< fp16 > { typedef fp16 result; };
|
||||
#endif
|
||||
template<> struct arma_signed_only< cx_float > { typedef cx_float result; };
|
||||
template<> struct arma_signed_only< cx_double > { typedef cx_double result; };
|
||||
|
||||
@@ -98,16 +104,46 @@ template<typename T> struct arma_real_only { };
|
||||
|
||||
template<> struct arma_real_only< float > { typedef float result; };
|
||||
template<> struct arma_real_only< double > { typedef double result; };
|
||||
#if defined(ARMA_HAVE_FP16)
|
||||
template<> struct arma_real_only< fp16 > { typedef fp16 result; };
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
template<typename T> struct arma_blas_real_only { };
|
||||
|
||||
template<> struct arma_blas_real_only< float > { typedef float result; };
|
||||
template<> struct arma_blas_real_only< double > { typedef double result; };
|
||||
|
||||
|
||||
|
||||
template<typename T> struct arma_fp16_only { };
|
||||
|
||||
#if defined(ARMA_HAVE_FP16)
|
||||
template<> struct arma_fp16_only< fp16 > { typedef fp16 result; };
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
template<typename T> struct arma_real_or_cx_only { };
|
||||
|
||||
template<> struct arma_real_or_cx_only< float > { typedef float result; };
|
||||
template<> struct arma_real_or_cx_only< double > { typedef double result; };
|
||||
#if defined(ARMA_HAVE_FP16)
|
||||
template<> struct arma_real_or_cx_only< fp16 > { typedef fp16 result; };
|
||||
#endif
|
||||
template<> struct arma_real_or_cx_only< cx_float > { typedef cx_float result; };
|
||||
template<> struct arma_real_or_cx_only< cx_double > { typedef cx_double result; };
|
||||
|
||||
|
||||
template<typename T> struct arma_blas_real_or_cx_only { };
|
||||
|
||||
template<> struct arma_blas_real_or_cx_only< float > { typedef float result; };
|
||||
template<> struct arma_blas_real_or_cx_only< double > { typedef double result; };
|
||||
template<> struct arma_blas_real_or_cx_only< cx_float > { typedef cx_float result; };
|
||||
template<> struct arma_blas_real_or_cx_only< cx_double > { typedef cx_double result; };
|
||||
|
||||
|
||||
|
||||
template<typename T> struct arma_cx_only { };
|
||||
|
||||
|
||||
@@ -27,8 +27,8 @@ class spop_norm
|
||||
|
||||
template<typename eT> inline static typename get_pod_type<eT>::result mat_norm_1(const SpMat<eT>& X);
|
||||
|
||||
template<typename eT> inline static typename get_pod_type<eT>::result mat_norm_2(const SpMat<eT>& X, const typename arma_real_only<eT>::result* junk = nullptr);
|
||||
template<typename eT> inline static typename get_pod_type<eT>::result mat_norm_2(const SpMat<eT>& X, const typename arma_cx_only<eT>::result* junk = nullptr);
|
||||
template<typename eT> inline static typename get_pod_type<eT>::result mat_norm_2(const SpMat<eT>& X, const typename arma_blas_real_only<eT>::result* junk = nullptr);
|
||||
template<typename eT> inline static typename get_pod_type<eT>::result mat_norm_2(const SpMat<eT>& X, const typename arma_cx_only<eT>::result* junk = nullptr);
|
||||
|
||||
template<typename eT> inline static typename get_pod_type<eT>::result mat_norm_inf(const SpMat<eT>& X);
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ spop_norm::mat_norm_1(const SpMat<eT>& X)
|
||||
template<typename eT>
|
||||
inline
|
||||
typename get_pod_type<eT>::result
|
||||
spop_norm::mat_norm_2(const SpMat<eT>& X, const typename arma_real_only<eT>::result* junk)
|
||||
spop_norm::mat_norm_2(const SpMat<eT>& X, const typename arma_blas_real_only<eT>::result* junk)
|
||||
{
|
||||
arma_debug_sigprint();
|
||||
arma_ignore(junk);
|
||||
|
||||
@@ -955,6 +955,26 @@ struct is_double<double>
|
||||
|
||||
|
||||
|
||||
template<typename T1>
|
||||
struct is_fp16
|
||||
{
|
||||
static constexpr bool value = false;
|
||||
static constexpr bool yes = false;
|
||||
static constexpr bool no = true;
|
||||
};
|
||||
|
||||
#ifdef ARMA_HAVE_FP16
|
||||
template<>
|
||||
struct is_fp16<fp16>
|
||||
{
|
||||
static constexpr bool value = true;
|
||||
static constexpr bool yes = true;
|
||||
static constexpr bool no = false;
|
||||
};
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
template<typename T1>
|
||||
struct is_real
|
||||
{
|
||||
@@ -979,6 +999,42 @@ struct is_real<double>
|
||||
static constexpr bool no = false;
|
||||
};
|
||||
|
||||
#ifdef ARMA_HAVE_FP16
|
||||
template<>
|
||||
struct is_real<fp16>
|
||||
{
|
||||
static constexpr bool value = true;
|
||||
static constexpr bool yes = true;
|
||||
static constexpr bool no = false;
|
||||
};
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
template<typename T1>
|
||||
struct is_blas_real
|
||||
{
|
||||
static constexpr bool value = false;
|
||||
static constexpr bool yes = false;
|
||||
static constexpr bool no = true;
|
||||
};
|
||||
|
||||
template<>
|
||||
struct is_blas_real<float>
|
||||
{
|
||||
static constexpr bool value = true;
|
||||
static constexpr bool yes = true;
|
||||
static constexpr bool no = false;
|
||||
};
|
||||
|
||||
template<>
|
||||
struct is_blas_real<double>
|
||||
{
|
||||
static constexpr bool value = true;
|
||||
static constexpr bool yes = true;
|
||||
static constexpr bool no = false;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1053,6 +1109,7 @@ struct is_supported_elem_type
|
||||
is_slng_t<T1>::value ||
|
||||
is_float<T1>::value ||
|
||||
is_double<T1>::value ||
|
||||
is_fp16<T1>::value ||
|
||||
is_cx_float<T1>::value ||
|
||||
is_cx_double<T1>::value;
|
||||
};
|
||||
@@ -1109,6 +1166,10 @@ template<> struct is_non_integral< double > { static constexpr boo
|
||||
template<> struct is_non_integral< std::complex<float> > { static constexpr bool value = true; };
|
||||
template<> struct is_non_integral< std::complex<double> > { static constexpr bool value = true; };
|
||||
|
||||
#if defined(ARMA_HAVE_FP16)
|
||||
template<> struct is_non_integral< fp16 > { static constexpr bool value = true; };
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -130,6 +130,83 @@ typedef void* void_ptr;
|
||||
#endif
|
||||
|
||||
|
||||
//
|
||||
|
||||
|
||||
// Attempt to capture all supported float16 types.
|
||||
// If C++23 or newer is used, we have a native type;
|
||||
// otherwise, there are a few possibilities.
|
||||
#undef ARMA_HAVE_FP16
|
||||
#if defined(ARMA_HAVE_CXX23)
|
||||
#if defined(__STDCPP_FLOAT16_T__) && (__STDCPP_FLOAT16_T__ == 1)
|
||||
#define ARMA_HAVE_FP16
|
||||
typedef std::float16_t fp16;
|
||||
#endif
|
||||
|
||||
#elif defined(__GNUG__) && !defined(__clang__) && defined(ARMA_FORCE_USE_FP16)
|
||||
// All Armadillo-supported GCC versions support FP16.
|
||||
#if defined(__FLT16_MAX__) && defined(__ARM_FP16_FORMAT_IEEE)
|
||||
#define ARMA_HAVE_FP16
|
||||
typedef _Float16 fp16;
|
||||
#elif defined(__FLT16_MAX__) && defined(__SSE2__)
|
||||
// See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116122 for why __SSE2__ is needed.
|
||||
#define ARMA_HAVE_FP16
|
||||
typedef _Float16 fp16;
|
||||
#endif
|
||||
|
||||
#elif defined(__clang__) && defined(__is_identifier) && defined(ARMA_FORCE_USE_FP16)
|
||||
// NOTE: clang is_identifier behavior returns 0 if the symbol is an identifier.
|
||||
#if !(__is_identifier(_Float16))
|
||||
#define ARMA_HAVE_FP16
|
||||
typedef _Float16 fp16;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
//
|
||||
|
||||
|
||||
// If we can detect that the implementation of FP16 is going to be software emulated,
|
||||
// then it's going to be really slow. Disable it and tell the user---unless they
|
||||
// force the issue.
|
||||
#if defined(ARMA_HAVE_FP16)
|
||||
#undef ARMA_BAD_FP16
|
||||
#if defined(__aarch64__)
|
||||
#if !defined(__ARM_FEATURE_FP16_SCALAR_ARITHMETIC)
|
||||
// We have to have the scalar intrinsics for native FP16 support.
|
||||
#define ARMA_BAD_FP16
|
||||
#endif
|
||||
#elif defined(__x86_64__) || defined(__i386__)
|
||||
#if !defined(__AVX512FP16__)
|
||||
// Without the AVX512-FP16 extensions, FP16 support is non-native (emulated).
|
||||
#define ARMA_BAD_FP16
|
||||
#endif
|
||||
#else
|
||||
// We have an architecture that does not define any macros that we can use.
|
||||
#define ARMA_BAD_FP16
|
||||
#endif
|
||||
|
||||
#if defined(ARMA_BAD_FP16)
|
||||
#if defined(ARMA_FORCE_USE_FP16)
|
||||
#pragma message ("WARNING: 16-bit floating point support enabled (via ARMA_FORCE_USE_FP16), but native hardware support not detected---use of fp16 could be very slow!")
|
||||
|
||||
// An additional warning: if C++23 is not enabled, many function definitions might not exist.
|
||||
// Whether this is a problem depends on what the user is doing.
|
||||
#if !defined(ARMA_HAVE_CXX23)
|
||||
#pragma message("WARNING: C++23 mode not enabled but 16-bit floating point support is forced (via ARMA_FORCE_USE_FP16); compilation may fail as some std:: functions may not work on fp16s!");
|
||||
#endif
|
||||
#else
|
||||
#undef ARMA_HAVE_FP16
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#undef ARMA_BAD_FP16
|
||||
#elif defined(ARMA_FORCE_USE_FP16) && !defined(ARMA_HAVE_FP16)
|
||||
#pragma message("WARNING: 16-bit floating point support is forced (via ARMA_FORCE_USE_FP16), but no usable fp16 type could be detected! Disabled.");
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
//
|
||||
|
||||
|
||||
|
||||
@@ -98,6 +98,14 @@ typedef Col <cx_double> cx_colvec;
|
||||
typedef Row <cx_double> cx_rowvec;
|
||||
typedef Cube<cx_double> cx_cube;
|
||||
|
||||
#if defined(ARMA_HAVE_FP16)
|
||||
typedef Mat <fp16> fp16_mat;
|
||||
typedef Col <fp16> fp16_vec;
|
||||
typedef Col <fp16> fp16_colvec;
|
||||
typedef Row <fp16> fp16_rowvec;
|
||||
typedef Cube<fp16> fp16_cube;
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
typedef SpMat <uword> sp_umat;
|
||||
@@ -140,5 +148,13 @@ typedef SpCol <cx_double> sp_cx_vec;
|
||||
typedef SpCol <cx_double> sp_cx_colvec;
|
||||
typedef SpRow <cx_double> sp_cx_rowvec;
|
||||
|
||||
//#if defined(ARMA_HAVE_FP16)
|
||||
//typedef SpMat <fp16> sp_fp16_mat;
|
||||
//typedef SpCol <fp16> sp_fp16_vec;
|
||||
//typedef SpCol <fp16> sp_fp16_colvec;
|
||||
//typedef SpRow <fp16> sp_fp16_rowvec;
|
||||
//#endif
|
||||
|
||||
|
||||
|
||||
//! @}
|
||||
|
||||
+2
-2
@@ -1,7 +1,7 @@
|
||||
|
||||
LIB_FLAGS = -L../ -larmadillo
|
||||
#LIB_FLAGS = -lblas -llapack
|
||||
#LIB_FLAGS = -lopenblas -llapack
|
||||
#LIB_FLAGS = -lblas -llapack
|
||||
#LIB_FLAGS = -lopenblas -llapack
|
||||
|
||||
#CXX_FLAGS = -I../tmp/include/ -std=c++14 -Wshadow -Wall -pedantic -O0
|
||||
CXX_FLAGS = -I../tmp/include/ -std=c++14 -Wshadow -Wall -pedantic -Og
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
using namespace arma;
|
||||
|
||||
|
||||
TEST_CASE("attributes_1")
|
||||
TEST_CASE("attributes_1", "[attributes]")
|
||||
{
|
||||
mat A(5,6);
|
||||
REQUIRE(A.n_rows == 5);
|
||||
|
||||
+1
-1
@@ -22,7 +22,7 @@
|
||||
using namespace arma;
|
||||
|
||||
|
||||
TEST_CASE("bounds_1")
|
||||
TEST_CASE("bounds_1", "[bounds]")
|
||||
{
|
||||
const uword n_rows = 5;
|
||||
const uword n_cols = 6;
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
using namespace arma;
|
||||
|
||||
|
||||
TEST_CASE("decomp_eig_gen_1")
|
||||
TEST_CASE("decomp_eig_gen_1", "[eig_gen]")
|
||||
{
|
||||
mat A =
|
||||
"\
|
||||
@@ -73,7 +73,7 @@ TEST_CASE("decomp_eig_gen_1")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("decomp_eig_gen_2")
|
||||
TEST_CASE("decomp_eig_gen_2", "[eig_gen]")
|
||||
{
|
||||
cx_mat A =
|
||||
{
|
||||
@@ -122,7 +122,7 @@ TEST_CASE("decomp_eig_gen_2")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("decomp_eig_gen_3")
|
||||
TEST_CASE("decomp_eig_gen_3", "[eig_gen]")
|
||||
{
|
||||
mat A(5,5,fill::randu);
|
||||
|
||||
@@ -139,7 +139,7 @@ TEST_CASE("decomp_eig_gen_3")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("decomp_eig_gen_4")
|
||||
TEST_CASE("decomp_eig_gen_4", "[eig_gen]")
|
||||
{
|
||||
mat A(5,6,fill::randu);
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
using namespace arma;
|
||||
|
||||
|
||||
TEST_CASE("decomp_eig_pair_1")
|
||||
TEST_CASE("decomp_eig_pair_1", "[eig_pair]")
|
||||
{
|
||||
mat A1 =
|
||||
"\
|
||||
@@ -82,7 +82,7 @@ TEST_CASE("decomp_eig_pair_1")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("decomp_eig_pair_2")
|
||||
TEST_CASE("decomp_eig_pair_2", "[eig_pair]")
|
||||
{
|
||||
cx_mat A1 =
|
||||
{
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
using namespace arma;
|
||||
|
||||
|
||||
TEST_CASE("decomp_eig_sym_1")
|
||||
TEST_CASE("decomp_eig_sym_1", "[eig_sym]")
|
||||
{
|
||||
mat A =
|
||||
"\
|
||||
@@ -64,7 +64,7 @@ TEST_CASE("decomp_eig_sym_1")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("eig_sym_2")
|
||||
TEST_CASE("eig_sym_2", "[eig_sym]")
|
||||
{
|
||||
cx_mat A =
|
||||
{
|
||||
@@ -104,7 +104,7 @@ TEST_CASE("eig_sym_2")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("eig_sym_3")
|
||||
TEST_CASE("eig_sym_3", "[eig_sym]")
|
||||
{
|
||||
mat A(5,6,fill::randu);
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
using namespace arma;
|
||||
|
||||
|
||||
TEST_CASE("expr_elem_1")
|
||||
TEST_CASE("expr_elem_1", "[expr]")
|
||||
{
|
||||
mat A =
|
||||
"\
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
using namespace arma;
|
||||
|
||||
|
||||
TEST_CASE("expr_misc_1")
|
||||
TEST_CASE("expr_misc_1", "[expr]")
|
||||
{
|
||||
mat A =
|
||||
"\
|
||||
|
||||
+25
-8
@@ -18,11 +18,12 @@
|
||||
|
||||
#include <armadillo>
|
||||
#include "catch.hpp"
|
||||
#include "utils.hpp"
|
||||
|
||||
using namespace arma;
|
||||
|
||||
|
||||
TEST_CASE("fn_abs_1")
|
||||
TEST_CASE("fn_abs_1", "[fn_elem]")
|
||||
{
|
||||
mat A =
|
||||
"\
|
||||
@@ -93,7 +94,7 @@ TEST_CASE("fn_abs_1")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("fn_abs_2")
|
||||
TEST_CASE("fn_abs_2", "[fn_elem]")
|
||||
{
|
||||
mat A =
|
||||
"\
|
||||
@@ -142,7 +143,7 @@ TEST_CASE("fn_abs_2")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("fn_abs_3")
|
||||
TEST_CASE("fn_abs_3", "[fn_elem]")
|
||||
{
|
||||
vec re = 2*linspace<vec>(1,5,6);
|
||||
vec im = -4*linspace<vec>(1,5,6);
|
||||
@@ -167,7 +168,7 @@ TEST_CASE("fn_abs_3")
|
||||
}
|
||||
|
||||
|
||||
TEST_CASE("fn_abs_4")
|
||||
TEST_CASE("fn_abs_4", "[fn_elem]")
|
||||
{
|
||||
vec a = -2*linspace<vec>(1,5,6);
|
||||
vec b = +2*linspace<vec>(1,5,6);
|
||||
@@ -178,7 +179,7 @@ TEST_CASE("fn_abs_4")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("fn_abs_5")
|
||||
TEST_CASE("fn_abs_5", "[fn_elem]")
|
||||
{
|
||||
mat A = randu<mat>(5,6);
|
||||
|
||||
@@ -188,7 +189,7 @@ TEST_CASE("fn_abs_5")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("fn_abs_sp_mat")
|
||||
TEST_CASE("fn_abs_sp_mat", "[fn_elem]")
|
||||
{
|
||||
SpMat<double> a(3, 3);
|
||||
a(0, 2) = 4.3;
|
||||
@@ -216,7 +217,7 @@ TEST_CASE("fn_abs_sp_mat")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("fn_abs_sp_mat_2")
|
||||
TEST_CASE("fn_abs_sp_mat_2", "[fn_elem]")
|
||||
{
|
||||
mat x = randu<mat>(100, 100);
|
||||
x -= 0.5;
|
||||
@@ -234,7 +235,7 @@ TEST_CASE("fn_abs_sp_mat_2")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("fn_abs_sp_cx_mat")
|
||||
TEST_CASE("fn_abs_sp_cx_mat", "[fn_elem]")
|
||||
{
|
||||
cx_mat x = randu<cx_mat>(100, 100);
|
||||
x -= cx_double(0.5, 0.5);
|
||||
@@ -249,3 +250,19 @@ TEST_CASE("fn_abs_sp_cx_mat")
|
||||
REQUIRE( xr[i] == Approx((double) yr[i]) );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
TEMPLATE_TEST_CASE("fn_abs_randu", "[fn_elem]", TEST_FLOAT_TYPES)
|
||||
{
|
||||
typedef TestType eT;
|
||||
|
||||
Mat<eT> x = randu<Mat<eT>>(50, 50) - eT(0.5);
|
||||
|
||||
Mat<eT> y = abs(x);
|
||||
|
||||
for (uword i = 0; i < y.n_elem; ++i)
|
||||
{
|
||||
REQUIRE( y[i] == Approx(std::abs(x[i])) );
|
||||
}
|
||||
}
|
||||
|
||||
+23
-5
@@ -18,11 +18,12 @@
|
||||
|
||||
#include <armadillo>
|
||||
#include "catch.hpp"
|
||||
#include "utils.hpp"
|
||||
|
||||
using namespace arma;
|
||||
|
||||
|
||||
TEST_CASE("fn_accu_1")
|
||||
TEST_CASE("fn_accu_1", "[accu]")
|
||||
{
|
||||
mat A =
|
||||
"\
|
||||
@@ -61,7 +62,7 @@ TEST_CASE("fn_accu_1")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("fn_accu_2")
|
||||
TEST_CASE("fn_accu_2", "[accu]")
|
||||
{
|
||||
mat A =
|
||||
"\
|
||||
@@ -88,7 +89,7 @@ TEST_CASE("fn_accu_2")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("fn_accu_3")
|
||||
TEST_CASE("fn_accu_3", "[accu]")
|
||||
{
|
||||
vec a = linspace<vec>(1,5,5);
|
||||
vec b = linspace<vec>(1,5,6);
|
||||
@@ -101,7 +102,7 @@ TEST_CASE("fn_accu_3")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("fn_accu_4")
|
||||
TEST_CASE("fn_accu_4", "[accu]")
|
||||
{
|
||||
mat A(5,6); A.fill(2.0);
|
||||
mat B(5,6); B.fill(4.0);
|
||||
@@ -120,7 +121,7 @@ TEST_CASE("fn_accu_4")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("fn_accu_spmat")
|
||||
TEST_CASE("fn_accu_spmat", "[accu]")
|
||||
{
|
||||
SpMat<unsigned int> b(4, 4);
|
||||
b(0, 1) = 6;
|
||||
@@ -132,3 +133,20 @@ TEST_CASE("fn_accu_spmat")
|
||||
REQUIRE( accu(b) == 52 );
|
||||
REQUIRE( accu(b.submat(1, 1, 3, 3)) == 41 );
|
||||
}
|
||||
|
||||
|
||||
|
||||
TEMPLATE_TEST_CASE("fn_accu_randu", "[accu]", TEST_FLOAT_TYPES)
|
||||
{
|
||||
typedef TestType eT;
|
||||
|
||||
Mat<eT> x = randu<Mat<eT>>(50, 50) - eT(0.5);
|
||||
const eT y = accu(x);
|
||||
|
||||
// manually convert to double to check
|
||||
mat x_ref = conv_to<mat>::from(x);
|
||||
const double y_ref = accu(x_ref);
|
||||
|
||||
// large tolerance because fp16 can be really approximate!
|
||||
REQUIRE( double(y) == Approx(y_ref).epsilon(0.1) );
|
||||
}
|
||||
|
||||
+14
-3
@@ -18,11 +18,12 @@
|
||||
|
||||
#include <armadillo>
|
||||
#include "catch.hpp"
|
||||
#include "utils.hpp"
|
||||
|
||||
using namespace arma;
|
||||
|
||||
|
||||
TEST_CASE("fn_all_1")
|
||||
TEST_CASE("fn_all_1", "[all]")
|
||||
{
|
||||
vec a(5, fill::zeros);
|
||||
vec b(5, fill::zeros); b(0) = 1.0;
|
||||
@@ -45,7 +46,7 @@ TEST_CASE("fn_all_1")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("fn_all_2")
|
||||
TEST_CASE("fn_all_2", "[all]")
|
||||
{
|
||||
mat A(5, 6, fill::zeros);
|
||||
mat B(5, 6, fill::zeros); B(0,0) = 1.0;
|
||||
@@ -69,7 +70,7 @@ TEST_CASE("fn_all_2")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("fn_all_3")
|
||||
TEST_CASE("fn_all_3", "[all]")
|
||||
{
|
||||
mat A(5, 6, fill::zeros);
|
||||
mat B(5, 6, fill::zeros); B(0,0) = 1.0;
|
||||
@@ -94,3 +95,13 @@ TEST_CASE("fn_all_3")
|
||||
}
|
||||
|
||||
|
||||
|
||||
TEMPLATE_TEST_CASE("fn_all_fp", "[all]", TEST_FLOAT_TYPES)
|
||||
{
|
||||
typedef TestType eT;
|
||||
|
||||
Mat<eT> x = randu<Mat<eT>>(50, 50) - eT(0.5);
|
||||
mat x_ref = conv_to<mat>::from(x);
|
||||
|
||||
REQUIRE( all( vectorise( all( x > eT(0) ) ) == vectorise( all( x_ref > 0.0 ) ) ) );
|
||||
}
|
||||
|
||||
+15
-3
@@ -18,11 +18,12 @@
|
||||
|
||||
#include <armadillo>
|
||||
#include "catch.hpp"
|
||||
#include "utils.hpp"
|
||||
|
||||
using namespace arma;
|
||||
|
||||
|
||||
TEST_CASE("fn_any_1")
|
||||
TEST_CASE("fn_any_1", "[any]")
|
||||
{
|
||||
vec a(5, fill::zeros);
|
||||
vec b(5, fill::zeros); b(0) = 1.0;
|
||||
@@ -45,7 +46,7 @@ TEST_CASE("fn_any_1")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("fn_any_2")
|
||||
TEST_CASE("fn_any_2", "[any]")
|
||||
{
|
||||
mat A(5, 6, fill::zeros);
|
||||
mat B(5, 6, fill::zeros); B(0,0) = 1.0;
|
||||
@@ -69,7 +70,7 @@ TEST_CASE("fn_any_2")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("fn_any_3")
|
||||
TEST_CASE("fn_any_3", "[any]")
|
||||
{
|
||||
mat A(5, 6, fill::zeros);
|
||||
mat B(5, 6, fill::zeros); B(0,0) = 1.0;
|
||||
@@ -94,3 +95,14 @@ TEST_CASE("fn_any_3")
|
||||
}
|
||||
|
||||
|
||||
|
||||
TEMPLATE_TEST_CASE("fn_any_fp", "[any]", TEST_FLOAT_TYPES)
|
||||
{
|
||||
typedef TestType eT;
|
||||
|
||||
Mat<eT> x(1, 1);
|
||||
x(0, 0) = eT(1);
|
||||
|
||||
REQUIRE( any(vectorise(x > eT(0))) == true );
|
||||
REQUIRE( any(vectorise(x <= eT(0))) == false );
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
using namespace arma;
|
||||
|
||||
|
||||
TEST_CASE("fn_as_scalar_1")
|
||||
TEST_CASE("fn_as_scalar_1", "[as_scalar]")
|
||||
{
|
||||
mat A(1,1); A.fill(2.0);
|
||||
mat B(2,2); B.fill(2.0);
|
||||
@@ -38,7 +38,7 @@ TEST_CASE("fn_as_scalar_1")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("fn_as_scalar_2")
|
||||
TEST_CASE("fn_as_scalar_2", "[as_scalar]")
|
||||
{
|
||||
rowvec r = linspace<rowvec>(1,5,6);
|
||||
colvec q = linspace<colvec>(1,5,6);
|
||||
@@ -54,7 +54,7 @@ TEST_CASE("fn_as_scalar_2")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("fn_as_scalar_3")
|
||||
TEST_CASE("fn_as_scalar_3", "[as_scalar]")
|
||||
{
|
||||
cube A(1,1,1); A.fill(2.0);
|
||||
cube B(2,2,2); B.fill(2.0);
|
||||
|
||||
+1
-1
@@ -22,7 +22,7 @@
|
||||
using namespace arma;
|
||||
|
||||
|
||||
TEST_CASE("fn_clamp_1")
|
||||
TEST_CASE("fn_clamp_1", "[clamp]")
|
||||
{
|
||||
mat A = randu<mat>(100,123);
|
||||
|
||||
|
||||
+2
-2
@@ -22,7 +22,7 @@
|
||||
using namespace arma;
|
||||
|
||||
|
||||
TEST_CASE("fn_cond_1")
|
||||
TEST_CASE("fn_cond_1", "[cond]")
|
||||
{
|
||||
mat A =
|
||||
{
|
||||
@@ -37,7 +37,7 @@ TEST_CASE("fn_cond_1")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("fn_cond_2")
|
||||
TEST_CASE("fn_cond_2", "[cond]")
|
||||
{
|
||||
mat A = zeros<mat>(5,6);
|
||||
|
||||
|
||||
+16
-2
@@ -18,11 +18,12 @@
|
||||
|
||||
#include <armadillo>
|
||||
#include "catch.hpp"
|
||||
#include "utils.hpp"
|
||||
|
||||
using namespace arma;
|
||||
|
||||
|
||||
TEST_CASE("fn_conj_1")
|
||||
TEST_CASE("fn_conj_1", "[conj]")
|
||||
{
|
||||
vec re = linspace<vec>(1,5,6);
|
||||
vec im = 2*linspace<vec>(1,5,6);
|
||||
@@ -36,7 +37,7 @@ TEST_CASE("fn_conj_1")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("fn_conj2")
|
||||
TEST_CASE("fn_conj2", "[conj]")
|
||||
{
|
||||
cx_mat A = randu<cx_mat>(5,6);
|
||||
|
||||
@@ -45,3 +46,16 @@ TEST_CASE("fn_conj2")
|
||||
REQUIRE( all(vectorise(real(B) == real(A))) == true );
|
||||
REQUIRE( all(vectorise(imag(B) == -imag(A))) == true );
|
||||
}
|
||||
|
||||
|
||||
|
||||
TEMPLATE_TEST_CASE("fn_conj_fp_randu", "[conj]", TEST_CX_FLOAT_TYPES)
|
||||
{
|
||||
typedef TestType eT; // std::complex<something>
|
||||
|
||||
Mat<eT> A = randu<Mat<eT>>(50, 50);
|
||||
Mat<eT> B = conj(A);
|
||||
|
||||
REQUIRE( all(vectorise(real(B) == real(A))) == true );
|
||||
REQUIRE( all(vectorise(imag(B) == -imag(A))) == true );
|
||||
}
|
||||
|
||||
+35
-1
@@ -18,11 +18,12 @@
|
||||
|
||||
#include <armadillo>
|
||||
#include "catch.hpp"
|
||||
#include "utils.hpp"
|
||||
|
||||
using namespace arma;
|
||||
|
||||
|
||||
TEST_CASE("fn_conv_1")
|
||||
TEST_CASE("fn_conv_1", "[conv]")
|
||||
{
|
||||
vec a = linspace<vec>(1,5,6);
|
||||
vec b = 2*linspace<vec>(1,6,7);
|
||||
@@ -46,3 +47,36 @@ TEST_CASE("fn_conv_1")
|
||||
|
||||
REQUIRE( accu(abs(c - d)) == Approx(0.0).margin(0.001) );
|
||||
}
|
||||
|
||||
|
||||
|
||||
TEMPLATE_TEST_CASE("fn_conv_fp_randu", "[conv]", TEST_FLOAT_TYPES)
|
||||
{
|
||||
typedef TestType eT;
|
||||
|
||||
// generalized version of the test above with higher tolerances
|
||||
Col<eT> a = linspace<Col<eT>>(1,5,6);
|
||||
Col<eT> b = 2*linspace<Col<eT>>(1,6,7);
|
||||
|
||||
Col<eT> c = conv(a,b);
|
||||
Col<eT> d =
|
||||
{
|
||||
eT( 2.00),
|
||||
eT( 7.27),
|
||||
eT( 17.13),
|
||||
eT( 32.93),
|
||||
eT( 56.00),
|
||||
eT( 87.67),
|
||||
eT(117.67),
|
||||
eT(134.00),
|
||||
eT(137.73),
|
||||
eT(127.53),
|
||||
eT(102.07),
|
||||
eT( 60.00)
|
||||
};
|
||||
|
||||
for (uword i = 0; i < c.n_elem; ++i)
|
||||
{
|
||||
REQUIRE( eT(c[i]) == Approx(eT(d[i])).epsilon(eT(0.02)) );
|
||||
}
|
||||
}
|
||||
|
||||
+34
-9
@@ -22,7 +22,7 @@
|
||||
using namespace arma;
|
||||
|
||||
|
||||
TEST_CASE("fn_conv_to_1")
|
||||
TEST_CASE("fn_conv_to_1", "[conv_to]")
|
||||
{
|
||||
typedef std::vector<double> stdvec;
|
||||
|
||||
@@ -39,7 +39,7 @@ TEST_CASE("fn_conv_to_1")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("fn_conv_to2")
|
||||
TEST_CASE("fn_conv_to2", "[conv_to]")
|
||||
{
|
||||
mat A(5,6); A.fill(0.1);
|
||||
|
||||
@@ -57,7 +57,7 @@ TEST_CASE("fn_conv_to2")
|
||||
}
|
||||
|
||||
|
||||
TEST_CASE("fn_conv_to3")
|
||||
TEST_CASE("fn_conv_to3", "[conv_to]")
|
||||
{
|
||||
mat A(5,6); A.fill(1.0);
|
||||
|
||||
@@ -69,7 +69,7 @@ TEST_CASE("fn_conv_to3")
|
||||
}
|
||||
|
||||
|
||||
TEST_CASE("fn_conv_to4")
|
||||
TEST_CASE("fn_conv_to4", "[conv_to]")
|
||||
{
|
||||
mat A = linspace<rowvec>(1,5,6);
|
||||
mat B = 2*linspace<colvec>(1,5,6);
|
||||
@@ -83,7 +83,7 @@ TEST_CASE("fn_conv_to4")
|
||||
}
|
||||
|
||||
|
||||
TEST_CASE("fn_conv_to_spmat_mat_different_eT")
|
||||
TEST_CASE("fn_conv_to_spmat_mat_different_eT", "[conv_to]")
|
||||
{
|
||||
sp_fmat A;
|
||||
A.sprandu(10, 10, 0.3);
|
||||
@@ -117,7 +117,7 @@ TEST_CASE("fn_conv_to_spmat_mat_different_eT")
|
||||
}
|
||||
|
||||
|
||||
TEST_CASE("fn_conv_to_complex_sparse_to_real")
|
||||
TEST_CASE("fn_conv_to_complex_sparse_to_real", "[conv_to]")
|
||||
{
|
||||
sp_cx_mat A;
|
||||
A.sprandu(10, 10, 0.3);
|
||||
@@ -139,7 +139,7 @@ TEST_CASE("fn_conv_to_complex_sparse_to_real")
|
||||
}
|
||||
|
||||
|
||||
TEST_CASE("fn_conv_to_complex_real_to_sparse")
|
||||
TEST_CASE("fn_conv_to_complex_real_to_sparse", "[conv_to]")
|
||||
{
|
||||
cx_mat A;
|
||||
A.randu(10, 10);
|
||||
@@ -161,7 +161,7 @@ TEST_CASE("fn_conv_to_complex_real_to_sparse")
|
||||
}
|
||||
|
||||
|
||||
TEST_CASE("fn_conv_to_complex_sparse_to_different_eT_real")
|
||||
TEST_CASE("fn_conv_to_complex_sparse_to_different_eT_real", "[conv_to]")
|
||||
{
|
||||
sp_cx_fmat A;
|
||||
A.sprandu(10, 10, 0.3);
|
||||
@@ -183,7 +183,7 @@ TEST_CASE("fn_conv_to_complex_sparse_to_different_eT_real")
|
||||
}
|
||||
|
||||
|
||||
TEST_CASE("fn_conv_to_complex_real_to_different_eT_sparse")
|
||||
TEST_CASE("fn_conv_to_complex_real_to_different_eT_sparse", "[conv_to]")
|
||||
{
|
||||
cx_mat A;
|
||||
A.randu(10, 10);
|
||||
@@ -202,3 +202,28 @@ TEST_CASE("fn_conv_to_complex_real_to_different_eT_sparse")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
#if defined(ARMA_HAVE_FP16)
|
||||
TEST_CASE("fn_conv_to_fp16", "[conv_to]")
|
||||
{
|
||||
fp16_mat x1 = randu<fp16_mat>(50, 50);
|
||||
mat x2 = conv_to<mat>::from(x1);
|
||||
|
||||
REQUIRE( x1.n_rows == x2.n_rows );
|
||||
REQUIRE( x1.n_cols == x2.n_cols );
|
||||
for (uword i = 0; i < x1.n_elem; ++i)
|
||||
{
|
||||
REQUIRE( double(x1[i]) == Approx(x2[i]) );
|
||||
}
|
||||
|
||||
x2.randu();
|
||||
x1 = conv_to<fp16_mat>::from(x2);
|
||||
|
||||
for (uword i = 0; i < x1.n_elem; ++i)
|
||||
{
|
||||
REQUIRE( x1[i] == Approx(fp16(x2[i])) );
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
+19
-2
@@ -18,11 +18,12 @@
|
||||
|
||||
#include <armadillo>
|
||||
#include "catch.hpp"
|
||||
#include "utils.hpp"
|
||||
|
||||
using namespace arma;
|
||||
|
||||
|
||||
TEST_CASE("fn_cor_1")
|
||||
TEST_CASE("fn_cor_1", "[cor]")
|
||||
{
|
||||
vec a = linspace<vec>(1,5,6);
|
||||
vec b = 0.5*linspace<vec>(1,5,6);
|
||||
@@ -34,7 +35,7 @@ TEST_CASE("fn_cor_1")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("fn_cor_2")
|
||||
TEST_CASE("fn_cor_2", "[cor]")
|
||||
{
|
||||
mat A =
|
||||
{
|
||||
@@ -75,3 +76,19 @@ TEST_CASE("fn_cor_2")
|
||||
REQUIRE( accu(abs(cor(A,B) - AA)) == Approx(0.0).margin(0.0001) );
|
||||
REQUIRE( accu(abs(cor(A,C) - AC)) == Approx(0.0).margin(0.0001) );
|
||||
}
|
||||
|
||||
|
||||
|
||||
TEMPLATE_TEST_CASE("cor_fp_randu", "[cor]", TEST_FLOAT_TYPES)
|
||||
{
|
||||
typedef TestType eT;
|
||||
|
||||
// reimplementation of cor_1 for different types
|
||||
Col<eT> a = linspace<Col<eT>>(1,5,6);
|
||||
Col<eT> b = eT(0.5)*linspace<Col<eT>>(1,5,6);
|
||||
Col<eT> c = flipud(b);
|
||||
|
||||
// greater margin for low-precision types
|
||||
REQUIRE( as_scalar(cor(a,b) - eT(+1.0)) == Approx(eT(0)).margin(0.1) );
|
||||
REQUIRE( as_scalar(cor(a,c) - eT(-1.0)) == Approx(eT(0)).margin(0.1) );
|
||||
}
|
||||
|
||||
+18
-2
@@ -18,11 +18,12 @@
|
||||
|
||||
#include <armadillo>
|
||||
#include "catch.hpp"
|
||||
#include "utils.hpp"
|
||||
|
||||
using namespace arma;
|
||||
|
||||
|
||||
TEST_CASE("fn_cov_1")
|
||||
TEST_CASE("fn_cov_1", "[cov]")
|
||||
{
|
||||
vec a = linspace<vec>(1,5,6);
|
||||
vec b = 0.5*linspace<vec>(1,5,6);
|
||||
@@ -34,7 +35,7 @@ TEST_CASE("fn_cov_1")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("fn_cov_2")
|
||||
TEST_CASE("fn_cov_2", "[cov]")
|
||||
{
|
||||
mat A =
|
||||
{
|
||||
@@ -75,3 +76,18 @@ TEST_CASE("fn_cov_2")
|
||||
REQUIRE( accu(abs(cov(A,B) - AB)) == Approx(0.0).margin(0.001) );
|
||||
REQUIRE( accu(abs(cov(A,C) - AC)) == Approx(0.0).margin(0.001) );
|
||||
}
|
||||
|
||||
|
||||
|
||||
TEMPLATE_TEST_CASE("fn_cov_fp_randu", "[cov]", TEST_FLOAT_TYPES)
|
||||
{
|
||||
typedef TestType eT;
|
||||
|
||||
// the same as cov_1, but with different types and a larger margin for low-precision types
|
||||
Col<eT> a = linspace<Col<eT>>(1,5,6);
|
||||
Col<eT> b = eT(0.5)*linspace<Col<eT>>(1,5,6);
|
||||
Col<eT> c = flipud(b);
|
||||
|
||||
REQUIRE( as_scalar(cov(a,b) - eT(+1.12)) == Approx(eT(0)).margin(eT(0.1)) );
|
||||
REQUIRE( as_scalar(cov(a,c) - eT(-1.12)) == Approx(eT(0)).margin(eT(0.1)) );
|
||||
}
|
||||
|
||||
+18
-11
@@ -18,23 +18,30 @@
|
||||
|
||||
#include <armadillo>
|
||||
#include "catch.hpp"
|
||||
#include "utils.hpp"
|
||||
|
||||
using namespace arma;
|
||||
|
||||
|
||||
TEST_CASE("fn_cross_1")
|
||||
TEMPLATE_TEST_CASE("fn_cross_1", "[cross]", TEST_FLOAT_TYPES)
|
||||
{
|
||||
vec a = { 0.1, 2.3, 4.5 };
|
||||
vec b = { 6.7, 8.9, 10.0 };
|
||||
|
||||
vec c = {-17.050, 29.150, -14.520 };
|
||||
|
||||
REQUIRE( accu(abs(cross(a,b) - c)) == Approx(0.0).margin(0.001) );
|
||||
|
||||
vec x;
|
||||
|
||||
REQUIRE_THROWS( x = cross(randu<vec>(4), randu<vec>(4)) );
|
||||
typedef TestType eT;
|
||||
|
||||
Col<eT> a = { eT(0.1), eT(2.3), eT( 4.5) };
|
||||
Col<eT> b = { eT(6.7), eT(8.9), eT(10.0) };
|
||||
|
||||
Col<eT> c = { eT(-17.050), eT(29.150), eT(-14.520) };
|
||||
|
||||
constexpr eT margin = is_blas_real<eT>::value ? eT(0.001) : eT(0.1);
|
||||
|
||||
REQUIRE( accu(abs(cross(a,b) - c)) == Approx(eT(0)).margin(margin) );
|
||||
}
|
||||
|
||||
|
||||
|
||||
TEST_CASE("fn_cross_invalid", "[cross]")
|
||||
{
|
||||
vec x;
|
||||
|
||||
REQUIRE_THROWS( x = cross(randu<vec>(4), randu<vec>(4)) );
|
||||
}
|
||||
|
||||
+18
-3
@@ -18,17 +18,18 @@
|
||||
|
||||
#include <armadillo>
|
||||
#include "catch.hpp"
|
||||
#include "utils.hpp"
|
||||
|
||||
using namespace arma;
|
||||
|
||||
|
||||
TEST_CASE("fn_cumprod_1")
|
||||
TEST_CASE("fn_cumprod_1", "[cumprod]")
|
||||
{
|
||||
colvec a = linspace<colvec>(1,5,6);
|
||||
rowvec b = linspace<rowvec>(1,5,6);
|
||||
|
||||
colvec c = { 1.0000, 1.8000, 4.6800, 15.9120, 66.8304, 334.1520 };
|
||||
|
||||
|
||||
REQUIRE( accu(abs(cumprod(a) - c )) == Approx(0.0).margin(0.001) );
|
||||
REQUIRE( accu(abs(cumprod(b) - c.t())) == Approx(0.0).margin(0.001) );
|
||||
|
||||
@@ -37,7 +38,7 @@ TEST_CASE("fn_cumprod_1")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("fn_cumprod_2")
|
||||
TEST_CASE("fn_cumprod_2", "[cumprod]")
|
||||
{
|
||||
mat A =
|
||||
{
|
||||
@@ -68,3 +69,17 @@ TEST_CASE("fn_cumprod_2")
|
||||
|
||||
|
||||
|
||||
TEMPLATE_TEST_CASE("fn_cumprod_small_fp", "[cumprod]", TEST_FLOAT_TYPES)
|
||||
{
|
||||
typedef TestType eT;
|
||||
|
||||
Col<eT> a = linspace<Col<eT>>(1,4,5);
|
||||
Row<eT> b = linspace<Row<eT>>(1,4,5);
|
||||
|
||||
Col<eT> c = { eT(1.0000), eT(1.7500), eT(4.3750), eT(14.2188), eT(56.8750) };
|
||||
|
||||
constexpr eT margin = is_blas_real<eT>::value ? eT(0.001) : eT(0.1);
|
||||
|
||||
REQUIRE( accu(abs(cumprod(a) - c )) == Approx(eT(0)).margin(margin) );
|
||||
REQUIRE( accu(abs(cumprod(b) - c.t())) == Approx(eT(0)).margin(margin) );
|
||||
}
|
||||
|
||||
+15
-10
@@ -18,26 +18,31 @@
|
||||
|
||||
#include <armadillo>
|
||||
#include "catch.hpp"
|
||||
#include "utils.hpp"
|
||||
|
||||
using namespace arma;
|
||||
|
||||
|
||||
TEST_CASE("fn_cumsum_1")
|
||||
TEMPLATE_TEST_CASE("fn_cumsum_1", "[cumsum]", TEST_FLOAT_TYPES)
|
||||
{
|
||||
colvec a = linspace<colvec>(1,5,6);
|
||||
rowvec b = linspace<rowvec>(1,5,6);
|
||||
|
||||
colvec c = { 1.0000, 2.8000, 5.4000, 8.8000, 13.0000, 18.0000 };
|
||||
|
||||
REQUIRE( accu(abs(cumsum(a) - c )) == Approx(0.0).margin(0.001) );
|
||||
REQUIRE( accu(abs(cumsum(b) - c.t())) == Approx(0.0).margin(0.001) );
|
||||
|
||||
typedef TestType eT;
|
||||
|
||||
Col<eT> a = linspace<Col<eT>>(1,5,6);
|
||||
Row<eT> b = linspace<Row<eT>>(1,5,6);
|
||||
|
||||
Col<eT> c = { eT(1.0000), eT(2.8000), eT(5.4000), eT(8.8000), eT(13.0000), eT(18.0000) };
|
||||
|
||||
constexpr eT margin = is_blas_real<eT>::value ? eT(0.001) : eT(0.2);
|
||||
|
||||
REQUIRE( accu(abs(cumsum(a) - c )) == Approx(0.0).margin(margin) );
|
||||
REQUIRE( accu(abs(cumsum(b) - c.t())) == Approx(0.0).margin(margin) );
|
||||
|
||||
REQUIRE_THROWS( b = cumsum(a) );
|
||||
}
|
||||
|
||||
|
||||
|
||||
TEST_CASE("fn_cumsum_2")
|
||||
TEST_CASE("fn_cumsum_2", "[cumsum]")
|
||||
{
|
||||
mat A =
|
||||
{
|
||||
|
||||
+3
-3
@@ -22,7 +22,7 @@
|
||||
using namespace arma;
|
||||
|
||||
|
||||
TEST_CASE("fn_det_1")
|
||||
TEST_CASE("fn_det_1", "[det]")
|
||||
{
|
||||
mat A =
|
||||
"\
|
||||
@@ -45,7 +45,7 @@ TEST_CASE("fn_det_1")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("fn_det_2")
|
||||
TEST_CASE("fn_det_2", "[det]")
|
||||
{
|
||||
mat A = toeplitz(linspace(1,5,6));
|
||||
|
||||
@@ -67,7 +67,7 @@ TEST_CASE("fn_det_2")
|
||||
}
|
||||
|
||||
|
||||
TEST_CASE("fn_det_3")
|
||||
TEST_CASE("fn_det_3", "[det]")
|
||||
{
|
||||
mat A = toeplitz(linspace(1,5,6));
|
||||
|
||||
|
||||
+43
-3
@@ -18,11 +18,12 @@
|
||||
|
||||
#include <armadillo>
|
||||
#include "catch.hpp"
|
||||
#include "utils.hpp"
|
||||
|
||||
using namespace arma;
|
||||
|
||||
|
||||
TEST_CASE("fn_diagmat_1")
|
||||
TEST_CASE("fn_diagmat_1", "[diagmat]")
|
||||
{
|
||||
mat A =
|
||||
{
|
||||
@@ -62,7 +63,7 @@ TEST_CASE("fn_diagmat_1")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("fn_diagmat_2")
|
||||
TEST_CASE("fn_diagmat_2", "[diagmat]")
|
||||
{
|
||||
mat A =
|
||||
{
|
||||
@@ -88,7 +89,7 @@ TEST_CASE("fn_diagmat_2")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("fn_diagmat_3")
|
||||
TEST_CASE("fn_diagmat_3", "[diagmat]")
|
||||
{
|
||||
mat A =
|
||||
{
|
||||
@@ -141,3 +142,42 @@ TEST_CASE("fn_diagmat_3")
|
||||
|
||||
// TODO: Asub and At
|
||||
}
|
||||
|
||||
|
||||
|
||||
TEMPLATE_TEST_CASE("diagmat_fp_mul_randu", "[diagmat]", TEST_FLOAT_TYPES)
|
||||
{
|
||||
typedef TestType eT;
|
||||
|
||||
Mat<eT> d1 = diagmat(randu<Col<eT>>(10));
|
||||
Mat<eT> d2 = diagmat(randu<Row<eT>>(10));
|
||||
Mat<eT> x = randu<Mat<eT>>(10, 10);
|
||||
|
||||
Mat<eT> d3 = d1 * d2;
|
||||
Mat<eT> d4 = d2 * d1;
|
||||
Mat<eT> x2 = d1 * x;
|
||||
Mat<eT> x3 = x * d1;
|
||||
|
||||
REQUIRE( d3.n_rows == d1.n_rows );
|
||||
REQUIRE( d3.n_cols == d1.n_cols );
|
||||
REQUIRE( d4.n_rows == d1.n_rows );
|
||||
REQUIRE( d4.n_cols == d1.n_cols );
|
||||
for (uword i = 0; i < d1.n_rows; ++i)
|
||||
{
|
||||
REQUIRE( eT(d3(i, i)) == Approx(eT(d1(i, i)) * eT(d2(i, i))).epsilon(0.01) );
|
||||
REQUIRE( eT(d4(i, i)) == Approx(eT(d1(i, i)) * eT(d2(i, i))).epsilon(0.01) );
|
||||
}
|
||||
|
||||
REQUIRE( x2.n_rows == d1.n_rows );
|
||||
REQUIRE( x2.n_cols == d1.n_cols );
|
||||
REQUIRE( x3.n_rows == d1.n_rows );
|
||||
REQUIRE( x3.n_cols == d1.n_cols );
|
||||
for (uword c = 0; c < x2.n_cols; ++c)
|
||||
{
|
||||
for (uword r = 0; r < x2.n_rows; ++r)
|
||||
{
|
||||
REQUIRE( eT(x2(r, c)) == Approx(eT(d1(r, r)) * eT(x(r, c))).epsilon(0.01) );
|
||||
REQUIRE( eT(x3(r, c)) == Approx(eT(d1(c, c)) * eT(x(r, c))).epsilon(0.01) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+21
-1
@@ -18,11 +18,12 @@
|
||||
|
||||
#include <armadillo>
|
||||
#include "catch.hpp"
|
||||
#include "utils.hpp"
|
||||
|
||||
using namespace arma;
|
||||
|
||||
|
||||
TEST_CASE("fn_diagvec_1")
|
||||
TEST_CASE("fn_diagvec_1", "[diagvec]")
|
||||
{
|
||||
mat A =
|
||||
"\
|
||||
@@ -70,3 +71,22 @@ TEST_CASE("fn_diagvec_1")
|
||||
REQUIRE( accu(abs(A_p1 - b)) == Approx(0.0).margin(0.001) );
|
||||
REQUIRE( accu(abs(A_m1 - c)) == Approx(0.0).margin(0.001) );
|
||||
}
|
||||
|
||||
|
||||
|
||||
TEMPLATE_TEST_CASE("diagvec_fp_randu", "[diagvec]", TEST_FLOAT_TYPES)
|
||||
{
|
||||
typedef TestType eT;
|
||||
|
||||
Mat<eT> x = randu<Mat<eT>>(30, 30);
|
||||
|
||||
Col<eT> y1 = diagvec(x);
|
||||
Row<eT> y2 = diagvec(x).t();
|
||||
|
||||
REQUIRE( y1.n_elem == x.n_rows );
|
||||
REQUIRE( y2.n_elem == x.n_rows );
|
||||
for (uword i = 0; i < x.n_rows; ++i)
|
||||
{
|
||||
REQUIRE( eT(y1[i]) == Approx(eT(x(i, i))) );
|
||||
}
|
||||
}
|
||||
|
||||
+26
-20
@@ -18,39 +18,45 @@
|
||||
|
||||
#include <armadillo>
|
||||
#include "catch.hpp"
|
||||
#include "utils.hpp"
|
||||
|
||||
using namespace arma;
|
||||
|
||||
|
||||
TEST_CASE("fn_diff_1")
|
||||
TEMPLATE_TEST_CASE("fn_diff_1", "[diff]", TEST_FLOAT_TYPES)
|
||||
{
|
||||
colvec a = square( linspace<colvec>(1,5,6) );
|
||||
rowvec b = square( linspace<rowvec>(1,5,5) );
|
||||
typedef TestType eT;
|
||||
|
||||
colvec a_diff_1 = { 2.2400, 3.5200, 4.8000, 6.0800, 7.3600 };
|
||||
colvec a_diff_2 = { 1.2800, 1.2800, 1.2800, 1.2800 };
|
||||
colvec a_diff_9;
|
||||
Col<eT> a = square( linspace<Col<eT>>(1,5,6) );
|
||||
Row<eT> b = square( linspace<Row<eT>>(1,5,5) );
|
||||
|
||||
rowvec b_diff_1 = { 3, 5, 7, 9 };
|
||||
rowvec b_diff_2 = { 2, 2, 2 };
|
||||
rowvec b_diff_9;
|
||||
Col<eT> a_diff_1 = { eT(2.2400), eT(3.5200), eT(4.8000), eT(6.0800), eT(7.3600) };
|
||||
Col<eT> a_diff_2 = { eT(1.2800), eT(1.2800), eT(1.2800), eT(1.2800) };
|
||||
Col<eT> a_diff_9;
|
||||
|
||||
REQUIRE( accu(abs(diff(a,0) - a )) == Approx(0.0).margin(0.001) );
|
||||
REQUIRE( accu(abs(diff(a ) - a_diff_1)) == Approx(0.0).margin(0.001) );
|
||||
REQUIRE( accu(abs(diff(a,1) - a_diff_1)) == Approx(0.0).margin(0.001) );
|
||||
REQUIRE( accu(abs(diff(a,2) - a_diff_2)) == Approx(0.0).margin(0.001) );
|
||||
REQUIRE( accu(abs(diff(a,9) - a_diff_9)) == Approx(0.0).margin(0.001) );
|
||||
Row<eT> b_diff_1 = { eT(3), eT(5), eT(7), eT(9) };
|
||||
Row<eT> b_diff_2 = { eT(2), eT(2), eT(2) };
|
||||
Row<eT> b_diff_9;
|
||||
|
||||
// significantly larger margin for low-precision because the errors can really add up!
|
||||
constexpr eT margin = is_blas_real<eT>::value ? eT(0.001) : eT(1.0);
|
||||
|
||||
REQUIRE( accu(abs(diff(b,0) - b )) == Approx(0.0).margin(0.001) );
|
||||
REQUIRE( accu(abs(diff(b ) - b_diff_1)) == Approx(0.0).margin(0.001) );
|
||||
REQUIRE( accu(abs(diff(b,1) - b_diff_1)) == Approx(0.0).margin(0.001) );
|
||||
REQUIRE( accu(abs(diff(b,2) - b_diff_2)) == Approx(0.0).margin(0.001) );
|
||||
REQUIRE( accu(abs(diff(b,9) - b_diff_9)) == Approx(0.0).margin(0.001) );
|
||||
REQUIRE( eT(accu(abs(diff(a,0) - a ))) == Approx(eT(0)).margin(margin) );
|
||||
REQUIRE( eT(accu(abs(diff(a ) - a_diff_1))) == Approx(eT(0)).margin(margin) );
|
||||
REQUIRE( eT(accu(abs(diff(a,1) - a_diff_1))) == Approx(eT(0)).margin(margin) );
|
||||
REQUIRE( eT(accu(abs(diff(a,2) - a_diff_2))) == Approx(eT(0)).margin(margin) );
|
||||
REQUIRE( eT(accu(abs(diff(a,9) - a_diff_9))) == Approx(eT(0)).margin(margin) );
|
||||
|
||||
REQUIRE( eT(accu(abs(diff(b,0) - b ))) == Approx(eT(0)).margin(margin) );
|
||||
REQUIRE( eT(accu(abs(diff(b ) - b_diff_1))) == Approx(eT(0)).margin(margin) );
|
||||
REQUIRE( eT(accu(abs(diff(b,1) - b_diff_1))) == Approx(eT(0)).margin(margin) );
|
||||
REQUIRE( eT(accu(abs(diff(b,2) - b_diff_2))) == Approx(eT(0)).margin(margin) );
|
||||
REQUIRE( eT(accu(abs(diff(b,9) - b_diff_9))) == Approx(eT(0)).margin(margin) );
|
||||
}
|
||||
|
||||
|
||||
|
||||
TEST_CASE("fn_diff_2")
|
||||
TEST_CASE("fn_diff_2", "[diff]")
|
||||
{
|
||||
mat A =
|
||||
"\
|
||||
|
||||
+87
-7
@@ -18,11 +18,12 @@
|
||||
|
||||
#include <armadillo>
|
||||
#include "catch.hpp"
|
||||
#include "utils.hpp"
|
||||
|
||||
using namespace arma;
|
||||
|
||||
|
||||
TEST_CASE("fn_dot_1")
|
||||
TEST_CASE("fn_dot_1", "[dot]")
|
||||
{
|
||||
mat A =
|
||||
"\
|
||||
@@ -51,7 +52,7 @@ TEST_CASE("fn_dot_1")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("fn_dot_2")
|
||||
TEST_CASE("fn_dot_2", "[dot]")
|
||||
{
|
||||
mat A =
|
||||
"\
|
||||
@@ -77,7 +78,7 @@ TEST_CASE("fn_dot_2")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("fn_dot_sp_mat_mat")
|
||||
TEST_CASE("fn_dot_sp_mat_mat", "[dot]")
|
||||
{
|
||||
// Make matrices.
|
||||
SpMat<double> a("3.0 0.0 0.0; 1.0 2.0 2.0; 0.0 0.0 1.0");
|
||||
@@ -89,7 +90,7 @@ TEST_CASE("fn_dot_sp_mat_mat")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("fn_dot_sp_col_col")
|
||||
TEST_CASE("fn_dot_sp_col_col", "[dot]")
|
||||
{
|
||||
SpCol<unsigned int> a("3; 4; 0; 0; 0; 2; 0; 0");
|
||||
Col<unsigned int> b("1 6 1 2 3 7 1 2");
|
||||
@@ -100,7 +101,7 @@ TEST_CASE("fn_dot_sp_col_col")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("fn_dot_sp_mat_sp_mat")
|
||||
TEST_CASE("fn_dot_sp_mat_sp_mat", "[dot]")
|
||||
{
|
||||
SpMat<double> a("3.0 0.0 0.0; 1.0 2.0 2.0; 0.0 0.0 1.0");
|
||||
SpMat<double> b("3.0 0.0 0.0; 1.0 2.0 2.0; 0.0 0.0 1.0");
|
||||
@@ -111,7 +112,7 @@ TEST_CASE("fn_dot_sp_mat_sp_mat")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("fn_dot_sp_col_sp_col")
|
||||
TEST_CASE("fn_dot_sp_col_sp_col", "[dot]")
|
||||
{
|
||||
SpCol<unsigned int> a("3; 4; 0; 0; 0; 2; 0; 0");
|
||||
SpCol<unsigned int> b("0; 8; 0; 1; 1; 0; 0; 0");
|
||||
@@ -122,4 +123,83 @@ TEST_CASE("fn_dot_sp_col_sp_col")
|
||||
|
||||
|
||||
|
||||
// TODO: norm_dot
|
||||
TEMPLATE_TEST_CASE("fn_dot_fp_randu", "[dot]", TEST_FLOAT_TYPES)
|
||||
{
|
||||
typedef TestType eT;
|
||||
|
||||
Col<eT> x1 = randu<Col<eT>>(100);
|
||||
Col<eT> x2 = randu<Col<eT>>(100);
|
||||
|
||||
vec x1_ref = conv_to<vec>::from(x1);
|
||||
vec x2_ref = conv_to<vec>::from(x2);
|
||||
|
||||
eT d = dot(x1, x2);
|
||||
double d_ref = dot(x1_ref, x2_ref);
|
||||
|
||||
constexpr eT eps = is_blas_real<eT>::value ? eT(0.001) : eT(0.1);
|
||||
|
||||
REQUIRE( double(d) == Approx(d_ref).epsilon(eps) );
|
||||
}
|
||||
|
||||
|
||||
|
||||
//TEMPLATE_TEST_CASE("fn_sp_dot_fp_randu", "[dot]", TEST_FLOAT_TYPES)
|
||||
// {
|
||||
// typedef TestType eT;
|
||||
//
|
||||
// SpCol<eT> x1, x2;
|
||||
// x1.sprandu(1000, 1, 0.3);
|
||||
// x2.sprandu(1000, 1, 0.3);
|
||||
//
|
||||
// sp_mat x1_ref = conv_to<sp_mat>::from(x1);
|
||||
// sp_mat x2_ref = conv_to<sp_mat>::from(x2);
|
||||
//
|
||||
// eT d = dot(x1, x2);
|
||||
// double d_ref = dot(x1_ref, x2_ref);
|
||||
//
|
||||
// constexpr eT eps = is_blas_real<eT>::value ? eT(0.001) : eT(0.1);
|
||||
//
|
||||
// REQUIRE( double(d) == Approx(d_ref).epsilon(eps) );
|
||||
// }
|
||||
|
||||
|
||||
|
||||
TEMPLATE_TEST_CASE("fn_cdot_fp_randu", "[dot]", TEST_CX_FLOAT_TYPES)
|
||||
{
|
||||
typedef TestType eT;
|
||||
|
||||
Col<eT> x1 = randu<Col<eT>>(100);
|
||||
Col<eT> x2 = randu<Col<eT>>(100);
|
||||
|
||||
cx_vec x1_ref = conv_to<cx_vec>::from(x1);
|
||||
cx_vec x2_ref = conv_to<cx_vec>::from(x2);
|
||||
|
||||
eT d = cdot(x1, x2);
|
||||
std::complex<double> d_ref = cdot(x1_ref, x2_ref);
|
||||
|
||||
typedef typename get_pod_type<eT>::result epsT;
|
||||
constexpr epsT eps = is_blas_real<eT>::value ? epsT(0.001) : epsT(0.1);
|
||||
|
||||
REQUIRE( double(std::real(d)) == Approx(std::real(d_ref)).epsilon(eps) );
|
||||
REQUIRE( double(std::imag(d)) == Approx(std::imag(d_ref)).epsilon(eps) );
|
||||
}
|
||||
|
||||
|
||||
|
||||
TEMPLATE_TEST_CASE("fn_norm_dot_fp_randu", "[dot]", TEST_FLOAT_TYPES)
|
||||
{
|
||||
typedef TestType eT;
|
||||
|
||||
Col<eT> x1 = randu<Col<eT>>(10);
|
||||
Col<eT> x2 = randu<Col<eT>>(10);
|
||||
|
||||
const eT d_unnorm = dot(x1, x2);
|
||||
const eT norm1 = norm(x1);
|
||||
const eT norm2 = norm(x2);
|
||||
|
||||
const eT d_norm = norm_dot(x1, x2);
|
||||
|
||||
constexpr eT eps = is_blas_real<eT>::value ? eT(0.001) : eT(0.1);
|
||||
|
||||
REQUIRE( d_norm == Approx(d_unnorm / (norm1 * norm2)).epsilon(eps) );
|
||||
}
|
||||
|
||||
+36
-36
@@ -21,7 +21,7 @@
|
||||
|
||||
using namespace arma;
|
||||
|
||||
TEST_CASE("fn_eigs_gen_odd_test")
|
||||
TEST_CASE("fn_eigs_gen_odd_test", "[eigs_gen]")
|
||||
{
|
||||
const uword n_rows = 10;
|
||||
const uword n_eigval = 5;
|
||||
@@ -83,7 +83,7 @@ TEST_CASE("fn_eigs_gen_odd_test")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("fn_eigs_gen_even_test")
|
||||
TEST_CASE("fn_eigs_gen_even_test", "[eigs_gen]")
|
||||
{
|
||||
const uword n_rows = 10;
|
||||
const uword n_eigval = 4;
|
||||
@@ -148,7 +148,7 @@ TEST_CASE("fn_eigs_gen_even_test")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("fn_eigs_gen_even_opts_test")
|
||||
TEST_CASE("fn_eigs_gen_even_opts_test", "[eigs_gen]")
|
||||
{
|
||||
const uword n_rows = 10;
|
||||
const uword n_eigval = 4;
|
||||
@@ -214,7 +214,7 @@ TEST_CASE("fn_eigs_gen_even_opts_test")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("fn_eigs_gen_odd_sigma_test")
|
||||
TEST_CASE("fn_eigs_gen_odd_sigma_test", "[eigs_gen]")
|
||||
{
|
||||
const uword n_rows = 10;
|
||||
const uword n_eigval = 5;
|
||||
@@ -281,7 +281,7 @@ TEST_CASE("fn_eigs_gen_odd_sigma_test")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("fn_eigs_gen_even_sigma_test")
|
||||
TEST_CASE("fn_eigs_gen_even_sigma_test", "[eigs_gen]")
|
||||
{
|
||||
const uword n_rows = 10;
|
||||
const uword n_eigval = 4;
|
||||
@@ -348,7 +348,7 @@ TEST_CASE("fn_eigs_gen_even_sigma_test")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("fn_eigs_gen_even_sigma_opts_test")
|
||||
TEST_CASE("fn_eigs_gen_even_sigma_opts_test", "[eigs_gen]")
|
||||
{
|
||||
const uword n_rows = 10;
|
||||
const uword n_eigval = 4;
|
||||
@@ -416,7 +416,7 @@ TEST_CASE("fn_eigs_gen_even_sigma_opts_test")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("fn_eigs_gen_odd_sm_test")
|
||||
TEST_CASE("fn_eigs_gen_odd_sm_test", "[eigs_gen]")
|
||||
{
|
||||
const uword n_rows = 10;
|
||||
const uword n_eigval = 5;
|
||||
@@ -482,7 +482,7 @@ TEST_CASE("fn_eigs_gen_odd_sm_test")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("fn_eigs_gen_even_sm_test")
|
||||
TEST_CASE("fn_eigs_gen_even_sm_test", "[eigs_gen]")
|
||||
{
|
||||
const uword n_rows = 10;
|
||||
const uword n_eigval = 4;
|
||||
@@ -548,7 +548,7 @@ TEST_CASE("fn_eigs_gen_even_sm_test")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("fn_eigs_gen_even_sm_opts_test")
|
||||
TEST_CASE("fn_eigs_gen_even_sm_opts_test", "[eigs_gen]")
|
||||
{
|
||||
const uword n_rows = 10;
|
||||
const uword n_eigval = 4;
|
||||
@@ -615,7 +615,7 @@ TEST_CASE("fn_eigs_gen_even_sm_opts_test")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("fn_eigs_gen_odd_float_test")
|
||||
TEST_CASE("fn_eigs_gen_odd_float_test", "[eigs_gen]")
|
||||
{
|
||||
const uword n_rows = 10;
|
||||
const uword n_eigval = 5;
|
||||
@@ -681,7 +681,7 @@ TEST_CASE("fn_eigs_gen_odd_float_test")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("fn_eigs_gen_even_float_test")
|
||||
TEST_CASE("fn_eigs_gen_even_float_test", "[eigs_gen]")
|
||||
{
|
||||
const uword n_rows = 12;
|
||||
const uword n_eigval = 8;
|
||||
@@ -747,7 +747,7 @@ TEST_CASE("fn_eigs_gen_even_float_test")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("fn_eigs_gen_even_float_opts_test")
|
||||
TEST_CASE("fn_eigs_gen_even_float_opts_test", "[eigs_gen]")
|
||||
{
|
||||
const uword n_rows = 12;
|
||||
const uword n_eigval = 8;
|
||||
@@ -814,7 +814,7 @@ TEST_CASE("fn_eigs_gen_even_float_opts_test")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("fn_eigs_gen_odd_float_sigma_test")
|
||||
TEST_CASE("fn_eigs_gen_odd_float_sigma_test", "[eigs_gen]")
|
||||
{
|
||||
const uword n_rows = 10;
|
||||
const uword n_eigval = 5;
|
||||
@@ -882,7 +882,7 @@ TEST_CASE("fn_eigs_gen_odd_float_sigma_test")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("fn_eigs_gen_even_float_sigma_test")
|
||||
TEST_CASE("fn_eigs_gen_even_float_sigma_test", "[eigs_gen]")
|
||||
{
|
||||
const uword n_rows = 12;
|
||||
const uword n_eigval = 8;
|
||||
@@ -952,7 +952,7 @@ TEST_CASE("fn_eigs_gen_even_float_sigma_test")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("fn_eigs_gen_even_float_sigma_opts_test")
|
||||
TEST_CASE("fn_eigs_gen_even_float_sigma_opts_test", "[eigs_gen]")
|
||||
{
|
||||
const uword n_rows = 12;
|
||||
const uword n_eigval = 8;
|
||||
@@ -1021,7 +1021,7 @@ TEST_CASE("fn_eigs_gen_even_float_sigma_opts_test")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("fn_eigs_gen_odd_float_sm_test")
|
||||
TEST_CASE("fn_eigs_gen_odd_float_sm_test", "[eigs_gen]")
|
||||
{
|
||||
const uword n_rows = 10;
|
||||
const uword n_eigval = 5;
|
||||
@@ -1088,7 +1088,7 @@ TEST_CASE("fn_eigs_gen_odd_float_sm_test")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("fn_eigs_gen_even_float_sm_test")
|
||||
TEST_CASE("fn_eigs_gen_even_float_sm_test", "[eigs_gen]")
|
||||
{
|
||||
const uword n_rows = 12;
|
||||
const uword n_eigval = 8;
|
||||
@@ -1155,7 +1155,7 @@ TEST_CASE("fn_eigs_gen_even_float_sm_test")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("fn_eigs_gen_even_float_sm_opts_test")
|
||||
TEST_CASE("fn_eigs_gen_even_float_sm_opts_test", "[eigs_gen]")
|
||||
{
|
||||
const uword n_rows = 12;
|
||||
const uword n_eigval = 8;
|
||||
@@ -1223,7 +1223,7 @@ TEST_CASE("fn_eigs_gen_even_float_sm_opts_test")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("fn_eigs_gen_odd_complex_float_test")
|
||||
TEST_CASE("fn_eigs_gen_odd_complex_float_test", "[eigs_gen]")
|
||||
{
|
||||
const uword n_rows = 10;
|
||||
const uword n_eigval = 5;
|
||||
@@ -1285,7 +1285,7 @@ TEST_CASE("fn_eigs_gen_odd_complex_float_test")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("fn_eigs_gen_even_complex_float_test")
|
||||
TEST_CASE("fn_eigs_gen_even_complex_float_test", "[eigs_gen]")
|
||||
{
|
||||
const uword n_rows = 12;
|
||||
const uword n_eigval = 8;
|
||||
@@ -1347,7 +1347,7 @@ TEST_CASE("fn_eigs_gen_even_complex_float_test")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("fn_eigs_gen_even_complex_float_opts_test")
|
||||
TEST_CASE("fn_eigs_gen_even_complex_float_opts_test", "[eigs_gen]")
|
||||
{
|
||||
const uword n_rows = 12;
|
||||
const uword n_eigval = 8;
|
||||
@@ -1410,7 +1410,7 @@ TEST_CASE("fn_eigs_gen_even_complex_float_opts_test")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("fn_eigs_gen_odd_complex_float_sigma_test")
|
||||
TEST_CASE("fn_eigs_gen_odd_complex_float_sigma_test", "[eigs_gen]")
|
||||
{
|
||||
const uword n_rows = 10;
|
||||
const uword n_eigval = 5;
|
||||
@@ -1477,7 +1477,7 @@ TEST_CASE("fn_eigs_gen_odd_complex_float_sigma_test")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("fn_eigs_gen_even_complex_float_sigma_test")
|
||||
TEST_CASE("fn_eigs_gen_even_complex_float_sigma_test", "[eigs_gen]")
|
||||
{
|
||||
const uword n_rows = 12;
|
||||
const uword n_eigval = 8;
|
||||
@@ -1544,7 +1544,7 @@ TEST_CASE("fn_eigs_gen_even_complex_float_sigma_test")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("fn_eigs_gen_even_complex_float_sigma_opts_test")
|
||||
TEST_CASE("fn_eigs_gen_even_complex_float_sigma_opts_test", "[eigs_gen]")
|
||||
{
|
||||
const uword n_rows = 12;
|
||||
const uword n_eigval = 8;
|
||||
@@ -1612,7 +1612,7 @@ TEST_CASE("fn_eigs_gen_even_complex_float_sigma_opts_test")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("fn_eigs_gen_odd_complex_float_sm_test")
|
||||
TEST_CASE("fn_eigs_gen_odd_complex_float_sm_test", "[eigs_gen]")
|
||||
{
|
||||
const uword n_rows = 10;
|
||||
const uword n_eigval = 5;
|
||||
@@ -1678,7 +1678,7 @@ TEST_CASE("fn_eigs_gen_odd_complex_float_sm_test")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("fn_eigs_gen_even_complex_float_sm_test")
|
||||
TEST_CASE("fn_eigs_gen_even_complex_float_sm_test", "[eigs_gen]")
|
||||
{
|
||||
const uword n_rows = 12;
|
||||
const uword n_eigval = 8;
|
||||
@@ -1744,7 +1744,7 @@ TEST_CASE("fn_eigs_gen_even_complex_float_sm_test")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("fn_eigs_gen_even_complex_float_sm_opts_test")
|
||||
TEST_CASE("fn_eigs_gen_even_complex_float_sm_opts_test", "[eigs_gen]")
|
||||
{
|
||||
const uword n_rows = 12;
|
||||
const uword n_eigval = 8;
|
||||
@@ -1811,7 +1811,7 @@ TEST_CASE("fn_eigs_gen_even_complex_float_sm_opts_test")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("eigs_gen_odd_complex_test")
|
||||
TEST_CASE("eigs_gen_odd_complex_test", "[eigs_gen]")
|
||||
{
|
||||
const uword n_rows = 10;
|
||||
const uword n_eigval = 5;
|
||||
@@ -1873,7 +1873,7 @@ TEST_CASE("eigs_gen_odd_complex_test")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("fn_eigs_gen_even_complex_test")
|
||||
TEST_CASE("fn_eigs_gen_even_complex_test", "[eigs_gen]")
|
||||
{
|
||||
const uword n_rows = 15;
|
||||
const uword n_eigval = 6;
|
||||
@@ -1935,7 +1935,7 @@ TEST_CASE("fn_eigs_gen_even_complex_test")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("fn_eigs_gen_even_complex_opts_test")
|
||||
TEST_CASE("fn_eigs_gen_even_complex_opts_test", "[eigs_gen]")
|
||||
{
|
||||
const uword n_rows = 15;
|
||||
const uword n_eigval = 6;
|
||||
@@ -1998,7 +1998,7 @@ TEST_CASE("fn_eigs_gen_even_complex_opts_test")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("eigs_gen_odd_complex_sigma_test")
|
||||
TEST_CASE("eigs_gen_odd_complex_sigma_test", "[eigs_gen]")
|
||||
{
|
||||
const uword n_rows = 10;
|
||||
const uword n_eigval = 5;
|
||||
@@ -2065,7 +2065,7 @@ TEST_CASE("eigs_gen_odd_complex_sigma_test")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("fn_eigs_gen_even_complex_sigma_test")
|
||||
TEST_CASE("fn_eigs_gen_even_complex_sigma_test", "[eigs_gen]")
|
||||
{
|
||||
const uword n_rows = 15;
|
||||
const uword n_eigval = 6;
|
||||
@@ -2132,7 +2132,7 @@ TEST_CASE("fn_eigs_gen_even_complex_sigma_test")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("fn_eigs_gen_even_complex_sigma_opts_test")
|
||||
TEST_CASE("fn_eigs_gen_even_complex_sigma_opts_test", "[eigs_gen]")
|
||||
{
|
||||
const uword n_rows = 15;
|
||||
const uword n_eigval = 6;
|
||||
@@ -2200,7 +2200,7 @@ TEST_CASE("fn_eigs_gen_even_complex_sigma_opts_test")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("eigs_gen_odd_complex_sm_test")
|
||||
TEST_CASE("eigs_gen_odd_complex_sm_test", "[eigs_gen]")
|
||||
{
|
||||
const uword n_rows = 10;
|
||||
const uword n_eigval = 5;
|
||||
@@ -2263,7 +2263,7 @@ TEST_CASE("eigs_gen_odd_complex_sm_test")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("fn_eigs_gen_even_complex_sm_test")
|
||||
TEST_CASE("fn_eigs_gen_even_complex_sm_test", "[eigs_gen]")
|
||||
{
|
||||
const uword n_rows = 15;
|
||||
const uword n_eigval = 6;
|
||||
@@ -2326,7 +2326,7 @@ TEST_CASE("fn_eigs_gen_even_complex_sm_test")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("fn_eigs_gen_even_complex_sm_opts_test")
|
||||
TEST_CASE("fn_eigs_gen_even_complex_sm_opts_test", "[eigs_gen]")
|
||||
{
|
||||
const uword n_rows = 15;
|
||||
const uword n_eigval = 6;
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
|
||||
using namespace arma;
|
||||
|
||||
TEST_CASE("fn_eigs_test")
|
||||
TEST_CASE("fn_eigs_test", "[eigs_sym]")
|
||||
{
|
||||
for (size_t trial = 0; trial < 10; ++trial)
|
||||
{
|
||||
@@ -62,7 +62,7 @@ TEST_CASE("fn_eigs_test")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("fn_eigs_float_test")
|
||||
TEST_CASE("fn_eigs_float_test", "[eigs_sym]")
|
||||
{
|
||||
for (size_t trial = 0; trial < 10; ++trial)
|
||||
{
|
||||
@@ -103,7 +103,7 @@ TEST_CASE("fn_eigs_float_test")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("fn_eigs_sm_test")
|
||||
TEST_CASE("fn_eigs_sm_test", "[eigs_sym]")
|
||||
{
|
||||
for (size_t trial = 0; trial < 10; ++trial)
|
||||
{
|
||||
@@ -141,7 +141,7 @@ TEST_CASE("fn_eigs_sm_test")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("fn_eigs_sigma_test")
|
||||
TEST_CASE("fn_eigs_sigma_test", "[eigs_sym]")
|
||||
{
|
||||
const uword n_trials = 10;
|
||||
|
||||
|
||||
+17
-1
@@ -18,11 +18,12 @@
|
||||
|
||||
#include <armadillo>
|
||||
#include "catch.hpp"
|
||||
#include "utils.hpp"
|
||||
|
||||
using namespace arma;
|
||||
|
||||
|
||||
TEST_CASE("fn_eps_1")
|
||||
TEST_CASE("fn_eps_1", "[eps]")
|
||||
{
|
||||
mat A =
|
||||
"\
|
||||
@@ -47,3 +48,18 @@ TEST_CASE("fn_eps_1")
|
||||
|
||||
REQUIRE( accu(abs(eps(A) - B)) == Approx(0.0).margin(0.001) );
|
||||
}
|
||||
|
||||
|
||||
|
||||
// test compilation but not output for other types
|
||||
TEMPLATE_TEST_CASE("fn_eps_fp", "[eps]", TEST_FLOAT_TYPES)
|
||||
{
|
||||
typedef TestType eT;
|
||||
|
||||
Mat<eT> A(5, 5, fill::randu);
|
||||
|
||||
Mat<eT> B = eps(A);
|
||||
|
||||
REQUIRE( A.n_rows == B.n_rows );
|
||||
REQUIRE( A.n_cols == B.n_cols );
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
using namespace arma;
|
||||
|
||||
|
||||
TEST_CASE("fn_expmat_1")
|
||||
TEST_CASE("fn_expmat_1", "[expmat]")
|
||||
{
|
||||
mat A =
|
||||
"\
|
||||
@@ -48,6 +48,3 @@ TEST_CASE("fn_expmat_1")
|
||||
|
||||
REQUIRE_THROWS( X = expmat(A(span(0,3),span::all)) );
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
+20
-1
@@ -18,11 +18,12 @@
|
||||
|
||||
#include <armadillo>
|
||||
#include "catch.hpp"
|
||||
#include "utils.hpp"
|
||||
|
||||
using namespace arma;
|
||||
|
||||
|
||||
TEST_CASE("fn_find_1")
|
||||
TEST_CASE("fn_find_1", "[find]")
|
||||
{
|
||||
mat A =
|
||||
"\
|
||||
@@ -61,3 +62,21 @@ TEST_CASE("fn_find_1")
|
||||
|
||||
// REQUIRE_THROWS( );
|
||||
}
|
||||
|
||||
|
||||
|
||||
TEMPLATE_TEST_CASE("fn_find_fp", "[find]", TEST_FLOAT_TYPES)
|
||||
{
|
||||
typedef TestType eT;
|
||||
|
||||
Col<eT> x(10, fill::randu);
|
||||
x += eT(0.5);
|
||||
x[2] = 0;
|
||||
|
||||
uvec r1 = find(x == 0);
|
||||
uvec r2 = find(x == eT(0));
|
||||
uvec r3 = find(x);
|
||||
REQUIRE( all( r1 == uvec({ 2 }) ) );
|
||||
REQUIRE( all( r2 == uvec({ 2 }) ) );
|
||||
REQUIRE( all( r3 == uvec({ 0, 1, 3, 4, 5, 6, 7, 8, 9 }) ) );
|
||||
}
|
||||
|
||||
@@ -18,11 +18,12 @@
|
||||
|
||||
#include <armadillo>
|
||||
#include "catch.hpp"
|
||||
#include "utils.hpp"
|
||||
|
||||
using namespace arma;
|
||||
|
||||
|
||||
TEST_CASE("fn_find_finite_1")
|
||||
TEST_CASE("fn_find_finite_1", "[find]")
|
||||
{
|
||||
mat A =
|
||||
"\
|
||||
@@ -44,3 +45,20 @@ TEST_CASE("fn_find_finite_1")
|
||||
|
||||
// REQUIRE_THROWS( );
|
||||
}
|
||||
|
||||
|
||||
|
||||
TEMPLATE_TEST_CASE("fn_find_finite_fp", "[find]", TEST_FLOAT_TYPES)
|
||||
{
|
||||
typedef TestType eT;
|
||||
|
||||
Mat<eT> X(5, 1, fill::zeros);
|
||||
|
||||
X[1] = Datum<eT>::nan;
|
||||
X[2] = Datum<eT>::inf;
|
||||
X[3] = -Datum<eT>::inf;
|
||||
|
||||
uvec r = find_finite(X);
|
||||
|
||||
REQUIRE( all( r == uvec({ 0, 4 }) ) );
|
||||
}
|
||||
|
||||
@@ -18,11 +18,12 @@
|
||||
|
||||
#include <armadillo>
|
||||
#include "catch.hpp"
|
||||
#include "utils.hpp"
|
||||
|
||||
using namespace arma;
|
||||
|
||||
|
||||
TEST_CASE("fn_find_nonfinite_1")
|
||||
TEST_CASE("fn_find_nonfinite_1", "[find]")
|
||||
{
|
||||
mat A =
|
||||
"\
|
||||
@@ -49,3 +50,20 @@ TEST_CASE("fn_find_nonfinite_1")
|
||||
|
||||
// REQUIRE_THROWS( );
|
||||
}
|
||||
|
||||
|
||||
|
||||
TEMPLATE_TEST_CASE("fn_find_nonfinite_fp", "[find]", TEST_FLOAT_TYPES)
|
||||
{
|
||||
typedef TestType eT;
|
||||
|
||||
Mat<eT> X(5, 1, fill::zeros);
|
||||
|
||||
X[1] = Datum<eT>::nan;
|
||||
X[2] = Datum<eT>::inf;
|
||||
X[3] = -Datum<eT>::inf;
|
||||
|
||||
uvec r = find_nonfinite(X);
|
||||
|
||||
REQUIRE( all( r == uvec({ 1, 2, 3 }) ) );
|
||||
}
|
||||
|
||||
@@ -19,11 +19,12 @@
|
||||
|
||||
#include <armadillo>
|
||||
#include "catch.hpp"
|
||||
#include "utils.hpp"
|
||||
|
||||
using namespace arma;
|
||||
|
||||
|
||||
TEST_CASE("fn_find_nonnan_1")
|
||||
TEST_CASE("fn_find_nonnan_1", "[find]")
|
||||
{
|
||||
mat A =
|
||||
"\
|
||||
@@ -66,7 +67,7 @@ TEST_CASE("fn_find_nonnan_1")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("fn_find_nonnan_cube")
|
||||
TEST_CASE("fn_find_nonnan_cube", "[find]")
|
||||
{
|
||||
cube A(5, 4, 3, fill::randu);
|
||||
|
||||
@@ -97,7 +98,7 @@ TEST_CASE("fn_find_nonnan_cube")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("fn_find_nonnan_spmat")
|
||||
TEST_CASE("fn_find_nonnan_spmat", "[find]")
|
||||
{
|
||||
// sparse matrices will only return nonzero non-nan indices
|
||||
sp_mat A(10, 10);
|
||||
@@ -118,3 +119,20 @@ TEST_CASE("fn_find_nonnan_spmat")
|
||||
REQUIRE( indices[3] == 76 );
|
||||
REQUIRE( indices[4] == 98 );
|
||||
}
|
||||
|
||||
|
||||
|
||||
TEMPLATE_TEST_CASE("fn_find_nonnan_fp", "[find]", TEST_FLOAT_TYPES)
|
||||
{
|
||||
typedef TestType eT;
|
||||
|
||||
Mat<eT> X(5, 1, fill::zeros);
|
||||
|
||||
X[1] = Datum<eT>::nan;
|
||||
X[2] = Datum<eT>::inf;
|
||||
X[3] = -Datum<eT>::inf;
|
||||
|
||||
uvec r = find_nonnan(X);
|
||||
|
||||
REQUIRE( all( r == uvec({ 0, 2, 3, 4 }) ) );
|
||||
}
|
||||
|
||||
@@ -18,11 +18,12 @@
|
||||
|
||||
#include <armadillo>
|
||||
#include "catch.hpp"
|
||||
#include "utils.hpp"
|
||||
|
||||
using namespace arma;
|
||||
|
||||
|
||||
TEST_CASE("fn_find_unique_1")
|
||||
TEST_CASE("fn_find_unique_1", "[find]")
|
||||
{
|
||||
mat A =
|
||||
{
|
||||
@@ -55,7 +56,7 @@ TEST_CASE("fn_find_unique_1")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("fn_find_unique_2")
|
||||
TEST_CASE("fn_find_unique_2", "[find]")
|
||||
{
|
||||
cx_mat A =
|
||||
{
|
||||
@@ -98,3 +99,16 @@ TEST_CASE("fn_find_unique_2")
|
||||
|
||||
// REQUIRE_THROWS( );
|
||||
}
|
||||
|
||||
|
||||
|
||||
TEMPLATE_TEST_CASE("fn_find_unique_fp", "[find]", TEST_FLOAT_TYPES)
|
||||
{
|
||||
typedef TestType eT;
|
||||
|
||||
Col<eT> X({ eT(0), eT(1), eT(1), eT(2), eT(1), eT(2) });
|
||||
|
||||
uvec r = find_unique(X);
|
||||
|
||||
REQUIRE( all( r == uvec({ 0, 1, 3 }) ) );
|
||||
}
|
||||
|
||||
+22
-16
@@ -18,13 +18,16 @@
|
||||
|
||||
#include <armadillo>
|
||||
#include "catch.hpp"
|
||||
#include "utils.hpp"
|
||||
|
||||
using namespace arma;
|
||||
|
||||
|
||||
TEST_CASE("fn_flip_1")
|
||||
TEMPLATE_TEST_CASE("fn_flip_1", "[flip]", TEST_FLOAT_TYPES)
|
||||
{
|
||||
mat A =
|
||||
typedef TestType eT;
|
||||
|
||||
Mat<eT> A =
|
||||
"\
|
||||
0.061198 0.201990 0.019678 -0.493936 -0.126745 0.051408;\
|
||||
0.437242 0.058956 -0.149362 -0.045465 0.296153 0.035437;\
|
||||
@@ -33,7 +36,7 @@ TEST_CASE("fn_flip_1")
|
||||
0.239585 -0.428913 -0.406953 -0.291020 -0.353768 0.258704;\
|
||||
";
|
||||
|
||||
mat A_fliplr =
|
||||
Mat<eT> A_fliplr =
|
||||
"\
|
||||
0.051408 -0.126745 -0.493936 0.019678 0.201990 0.061198;\
|
||||
0.035437 0.296153 -0.045465 -0.149362 0.058956 0.437242;\
|
||||
@@ -42,7 +45,7 @@ TEST_CASE("fn_flip_1")
|
||||
0.258704 -0.353768 -0.291020 -0.406953 -0.428913 0.239585;\
|
||||
";
|
||||
|
||||
mat A_flipud =
|
||||
Mat<eT> A_flipud =
|
||||
"\
|
||||
0.239585 -0.428913 -0.406953 -0.291020 -0.353768 0.258704;\
|
||||
0.336352 0.411541 0.458476 -0.393139 -0.135040 0.373833;\
|
||||
@@ -52,7 +55,7 @@ TEST_CASE("fn_flip_1")
|
||||
";
|
||||
|
||||
|
||||
mat two_times_A_fliplr =
|
||||
Mat<eT> two_times_A_fliplr =
|
||||
"\
|
||||
0.102816 -0.253490 -0.987872 0.039356 0.403980 0.122396;\
|
||||
0.070874 0.592306 -0.090930 -0.298724 0.117912 0.874484;\
|
||||
@@ -61,7 +64,7 @@ TEST_CASE("fn_flip_1")
|
||||
0.517408 -0.707536 -0.582040 -0.813906 -0.857826 0.479170;\
|
||||
";
|
||||
|
||||
mat two_times_A_flipud =
|
||||
Mat<eT> two_times_A_flipud =
|
||||
"\
|
||||
0.479170 -0.857826 -0.813906 -0.582040 -0.707536 0.517408;\
|
||||
0.672704 0.823082 0.916952 -0.786278 -0.270080 0.747666;\
|
||||
@@ -69,21 +72,24 @@ TEST_CASE("fn_flip_1")
|
||||
0.874484 0.117912 -0.298724 -0.090930 0.592306 0.070874;\
|
||||
0.122396 0.403980 0.039356 -0.987872 -0.253490 0.102816;\
|
||||
";
|
||||
|
||||
// very large margins are needed for the low precision types
|
||||
constexpr const eT margin = is_blas_real<eT>::value ? eT(0.001) : eT(0.1);
|
||||
|
||||
REQUIRE( accu(abs( fliplr(A) - A_fliplr )) == Approx(0.0).margin(0.001) );
|
||||
REQUIRE( accu(abs( flipud(A) - A_flipud )) == Approx(0.0).margin(0.001) );
|
||||
REQUIRE( accu(abs( fliplr(A) - A_fliplr )) == Approx(eT(0)).margin(margin) );
|
||||
REQUIRE( accu(abs( flipud(A) - A_flipud )) == Approx(eT(0)).margin(margin) );
|
||||
|
||||
REQUIRE( accu(abs( (-fliplr(A)) + A_fliplr )) == Approx(0.0).margin(0.001) );
|
||||
REQUIRE( accu(abs( (-flipud(A)) + A_flipud )) == Approx(0.0).margin(0.001) );
|
||||
REQUIRE( accu(abs( (-fliplr(A)) + A_fliplr )) == Approx(eT(0)).margin(margin) );
|
||||
REQUIRE( accu(abs( (-flipud(A)) + A_flipud )) == Approx(eT(0)).margin(margin) );
|
||||
|
||||
REQUIRE( accu(abs( fliplr(-A) + A_fliplr )) == Approx(0.0).margin(0.001) );
|
||||
REQUIRE( accu(abs( flipud(-A) + A_flipud )) == Approx(0.0).margin(0.001) );
|
||||
REQUIRE( accu(abs( fliplr(-A) + A_fliplr )) == Approx(eT(0)).margin(margin) );
|
||||
REQUIRE( accu(abs( flipud(-A) + A_flipud )) == Approx(eT(0)).margin(margin) );
|
||||
|
||||
REQUIRE( accu(abs( 2*fliplr(A) - two_times_A_fliplr )) == Approx(0.0).margin(0.001) );
|
||||
REQUIRE( accu(abs( 2*flipud(A) - two_times_A_flipud )) == Approx(0.0).margin(0.001) );
|
||||
REQUIRE( accu(abs( 2*fliplr(A) - two_times_A_fliplr )) == Approx(eT(0)).margin(margin) );
|
||||
REQUIRE( accu(abs( 2*flipud(A) - two_times_A_flipud )) == Approx(eT(0)).margin(margin) );
|
||||
|
||||
REQUIRE( accu(abs( fliplr(2*A) - two_times_A_fliplr )) == Approx(0.0).margin(0.001) );
|
||||
REQUIRE( accu(abs( flipud(2*A) - two_times_A_flipud )) == Approx(0.0).margin(0.001) );
|
||||
REQUIRE( accu(abs( fliplr(2*A) - two_times_A_fliplr )) == Approx(eT(0)).margin(margin) );
|
||||
REQUIRE( accu(abs( flipud(2*A) - two_times_A_flipud )) == Approx(eT(0)).margin(margin) );
|
||||
|
||||
// REQUIRE_THROWS( );
|
||||
}
|
||||
|
||||
+11
-11
@@ -25,7 +25,7 @@ using namespace std;
|
||||
|
||||
|
||||
|
||||
TEST_CASE("fn_hess_non_square")
|
||||
TEST_CASE("fn_hess_non_square", "[hess]")
|
||||
{
|
||||
mat A(5, 6, fill::ones);
|
||||
mat U, H;
|
||||
@@ -35,7 +35,7 @@ TEST_CASE("fn_hess_non_square")
|
||||
|
||||
/***************** tests for real matrix ****************/
|
||||
|
||||
TEST_CASE("fn_hess_empty")
|
||||
TEST_CASE("fn_hess_empty", "[hess]")
|
||||
{
|
||||
mat A(1, 1);
|
||||
A.reset();
|
||||
@@ -53,7 +53,7 @@ TEST_CASE("fn_hess_empty")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("fn_hess_1")
|
||||
TEST_CASE("fn_hess_1", "[hess]")
|
||||
{
|
||||
mat A(1, 1);
|
||||
A(0, 0) = 0.061198;
|
||||
@@ -71,7 +71,7 @@ TEST_CASE("fn_hess_1")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("fn_hess_2")
|
||||
TEST_CASE("fn_hess_2", "[hess]")
|
||||
{
|
||||
mat A =
|
||||
"\
|
||||
@@ -107,7 +107,7 @@ TEST_CASE("fn_hess_2")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("fn_hess_3")
|
||||
TEST_CASE("fn_hess_3", "[hess]")
|
||||
{
|
||||
mat A =
|
||||
"\
|
||||
@@ -176,7 +176,7 @@ TEST_CASE("fn_hess_3")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("fn_hess_4")
|
||||
TEST_CASE("fn_hess_4", "[hess]")
|
||||
{
|
||||
mat A =
|
||||
"\
|
||||
@@ -279,7 +279,7 @@ TEST_CASE("fn_hess_4")
|
||||
|
||||
/***************** tests for complex matrix ****************/
|
||||
|
||||
TEST_CASE("fn_hess_cx_empty")
|
||||
TEST_CASE("fn_hess_cx_empty", "[hess]")
|
||||
{
|
||||
cx_mat A(1, 1);
|
||||
A.reset();
|
||||
@@ -297,7 +297,7 @@ TEST_CASE("fn_hess_cx_empty")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("fn_hess_cx_1")
|
||||
TEST_CASE("fn_hess_cx_1", "[hess]")
|
||||
{
|
||||
cx_mat A(1, 1);
|
||||
A(0, 0) = complex<double>(0.061198, 1.012234);
|
||||
@@ -322,7 +322,7 @@ TEST_CASE("fn_hess_cx_1")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("fn_hess_cx_2")
|
||||
TEST_CASE("fn_hess_cx_2", "[hess]")
|
||||
{
|
||||
mat B =
|
||||
"\
|
||||
@@ -375,7 +375,7 @@ TEST_CASE("fn_hess_cx_2")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("fn_hess_cx_3")
|
||||
TEST_CASE("fn_hess_cx_3", "[hess]")
|
||||
{
|
||||
mat B =
|
||||
"\
|
||||
@@ -481,7 +481,7 @@ TEST_CASE("fn_hess_cx_3")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("fn_hess_cx_4")
|
||||
TEST_CASE("fn_hess_cx_4", "[hess]")
|
||||
{
|
||||
mat B =
|
||||
"\
|
||||
|
||||
+44
-1
@@ -18,11 +18,12 @@
|
||||
|
||||
#include <armadillo>
|
||||
#include "catch.hpp"
|
||||
#include "utils.hpp"
|
||||
|
||||
using namespace arma;
|
||||
|
||||
|
||||
TEST_CASE("fn_interp1_1")
|
||||
TEST_CASE("fn_interp1_1", "[interp1]")
|
||||
{
|
||||
mat A =
|
||||
"\
|
||||
@@ -53,3 +54,45 @@ TEST_CASE("fn_interp1_1")
|
||||
|
||||
// REQUIRE_THROWS( );
|
||||
}
|
||||
|
||||
|
||||
|
||||
TEMPLATE_TEST_CASE("fn_interp1_fp_randu", "[interp1]", TEST_FLOAT_TYPES)
|
||||
{
|
||||
typedef TestType eT;
|
||||
|
||||
Col<eT> x = linspace<Col<eT>>(0, 1, 101);
|
||||
Col<eT> y = square(x);
|
||||
Col<eT> x2 = linspace<Col<eT>>(0, 2, 201);
|
||||
Col<eT> z1, z2, z3, z4;
|
||||
|
||||
vec x_ref = conv_to<vec>::from(x);
|
||||
vec y_ref = conv_to<vec>::from(y);
|
||||
vec x2_ref = conv_to<vec>::from(x2);
|
||||
vec z1_ref, z2_ref, z3_ref, z4_ref;
|
||||
|
||||
interp1(x, y, x2, z1, "nearest", eT(5));
|
||||
interp1(x, y, x2, z2, "linear", eT(5));
|
||||
interp1(x, y, x2, z3, "*nearest", eT(5));
|
||||
interp1(x, y, x2, z4, "*linear", eT(5));
|
||||
|
||||
interp1(x_ref, y_ref, x2_ref, z1_ref, "nearest", 5.0);
|
||||
interp1(x_ref, y_ref, x2_ref, z2_ref, "linear", 5.0);
|
||||
interp1(x_ref, y_ref, x2_ref, z3_ref, "*nearest", 5.0);
|
||||
interp1(x_ref, y_ref, x2_ref, z4_ref, "*linear", 5.0);
|
||||
|
||||
constexpr const eT margin = is_blas_real<eT>::value ? eT(0.001) : eT(0.1);
|
||||
|
||||
REQUIRE( z1.n_elem == z1_ref.n_elem );
|
||||
REQUIRE( z2.n_elem == z2_ref.n_elem );
|
||||
REQUIRE( z3.n_elem == z3_ref.n_elem );
|
||||
REQUIRE( z4.n_elem == z4_ref.n_elem );
|
||||
|
||||
for (uword i = 0; i < z1.n_elem; ++i)
|
||||
{
|
||||
REQUIRE( z1[i] == Approx(eT(z1_ref[i])).margin(margin) );
|
||||
REQUIRE( z2[i] == Approx(eT(z2_ref[i])).margin(margin) );
|
||||
REQUIRE( z3[i] == Approx(eT(z3_ref[i])).margin(margin) );
|
||||
REQUIRE( z4[i] == Approx(eT(z4_ref[i])).margin(margin) );
|
||||
}
|
||||
}
|
||||
|
||||
+22
-3
@@ -18,11 +18,12 @@
|
||||
|
||||
#include <armadillo>
|
||||
#include "catch.hpp"
|
||||
#include "utils.hpp"
|
||||
|
||||
using namespace arma;
|
||||
|
||||
|
||||
TEST_CASE("fn_intersect_1")
|
||||
TEST_CASE("fn_intersect_1", "[intersect]")
|
||||
{
|
||||
ivec A = regspace<ivec>(5, 1); // 5, 4, 3, 2, 1
|
||||
ivec B = regspace<ivec>(3, 7); // 3, 4, 5, 6, 7
|
||||
@@ -57,7 +58,7 @@ TEST_CASE("fn_intersect_1")
|
||||
}
|
||||
|
||||
|
||||
TEST_CASE("fn_intersect_2")
|
||||
TEST_CASE("fn_intersect_2", "[intersect]")
|
||||
{
|
||||
irowvec A = regspace<irowvec>(5, 1); // 5, 4, 3, 2, 1
|
||||
irowvec B = regspace<irowvec>(3, 7); // 3, 4, 5, 6, 7
|
||||
@@ -92,7 +93,7 @@ TEST_CASE("fn_intersect_2")
|
||||
}
|
||||
|
||||
|
||||
TEST_CASE("fn_intersect_3")
|
||||
TEST_CASE("fn_intersect_3", "[intersect]")
|
||||
{
|
||||
irowvec A = regspace<irowvec>(5, 1);
|
||||
irowvec B = regspace<irowvec>(3, 7);
|
||||
@@ -101,3 +102,21 @@ TEST_CASE("fn_intersect_3")
|
||||
|
||||
REQUIRE_THROWS( C = intersect(A,B) );
|
||||
}
|
||||
|
||||
|
||||
|
||||
TEMPLATE_TEST_CASE("fn_intersect_fp", "[intersect]", TEST_FLOAT_TYPES)
|
||||
{
|
||||
typedef TestType eT;
|
||||
|
||||
Mat<eT> X(10, 10, fill::randu);
|
||||
Mat<eT> Y(10, 10, fill::randu);
|
||||
Y -= eT(2); // so that no elements match
|
||||
|
||||
Y.submat(1, 1, 8, 8) = X.submat(1, 1, 8, 8);
|
||||
Mat<eT> Z_ref = sort(unique(vectorise(X.submat(1, 1, 8, 8))), "ascending");
|
||||
|
||||
Mat<eT> Z = intersect(X, Y);
|
||||
|
||||
REQUIRE( all( all( Z == Z_ref ) ) );
|
||||
}
|
||||
|
||||
+26
-1
@@ -18,11 +18,12 @@
|
||||
|
||||
#include <armadillo>
|
||||
#include "catch.hpp"
|
||||
#include "utils.hpp"
|
||||
|
||||
using namespace arma;
|
||||
|
||||
|
||||
TEST_CASE("fn_is_finite_1")
|
||||
TEST_CASE("fn_is_finite_1", "[is_finite]")
|
||||
{
|
||||
mat A =
|
||||
"\
|
||||
@@ -51,3 +52,27 @@ TEST_CASE("fn_is_finite_1")
|
||||
|
||||
// REQUIRE_THROWS( );
|
||||
}
|
||||
|
||||
|
||||
|
||||
TEMPLATE_TEST_CASE("fn_is_finite_fp", "[is_finite]", TEST_FLOAT_TYPES)
|
||||
{
|
||||
typedef TestType eT;
|
||||
|
||||
Col<eT> X1(5, fill::randu);
|
||||
Col<eT> X2(5, fill::randu);
|
||||
Col<eT> X3(5, fill::randu);
|
||||
Col<eT> X4(5, fill::randu);
|
||||
|
||||
X1(2) = Datum<eT>::nan;
|
||||
X1(3) = Datum<eT>::inf;
|
||||
X1(4) = -Datum<eT>::inf;
|
||||
X2(3) = Datum<eT>::inf;
|
||||
X2(4) = -Datum<eT>::inf;
|
||||
X3(4) = Datum<eT>::nan;
|
||||
|
||||
REQUIRE( X1.is_finite() == false );
|
||||
REQUIRE( X2.is_finite() == false );
|
||||
REQUIRE( X3.is_finite() == false );
|
||||
REQUIRE( X4.is_finite() == true );
|
||||
}
|
||||
|
||||
+102
-23
@@ -18,10 +18,11 @@
|
||||
#include <armadillo>
|
||||
|
||||
#include "catch.hpp"
|
||||
#include "utils.hpp"
|
||||
|
||||
using namespace arma;
|
||||
|
||||
TEST_CASE("fn_max_subview_test")
|
||||
TEST_CASE("fn_max_subview_test", "[max]")
|
||||
{
|
||||
// We will assume subview.at() works and returns points within the bounds of
|
||||
// the matrix, so we just have to ensure the results are the same as
|
||||
@@ -54,7 +55,7 @@ TEST_CASE("fn_max_subview_test")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("fn_max_subview_col_test")
|
||||
TEST_CASE("fn_max_subview_col_test", "[max]")
|
||||
{
|
||||
for (size_t r = 10; r < 50; ++r)
|
||||
{
|
||||
@@ -80,7 +81,7 @@ TEST_CASE("fn_max_subview_col_test")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("fn_max_subview_row_test")
|
||||
TEST_CASE("fn_max_subview_row_test", "[max]")
|
||||
{
|
||||
for (size_t r = 10; r < 50; ++r)
|
||||
{
|
||||
@@ -106,7 +107,7 @@ TEST_CASE("fn_max_subview_row_test")
|
||||
|
||||
|
||||
|
||||
// TEST_CASE("fn_max_incomplete_subview_test")
|
||||
// TEST_CASE("fn_max_incomplete_subview_test", "[max]")
|
||||
// {
|
||||
// for (size_t r = 50; r < 150; ++r)
|
||||
// {
|
||||
@@ -147,7 +148,7 @@ TEST_CASE("fn_max_subview_row_test")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("fn_max_incomplete_subview_col_test")
|
||||
TEST_CASE("fn_max_incomplete_subview_col_test", "[max]")
|
||||
{
|
||||
for (size_t r = 10; r < 50; ++r)
|
||||
{
|
||||
@@ -176,7 +177,7 @@ TEST_CASE("fn_max_incomplete_subview_col_test")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("fn_max_cx_subview_row_test")
|
||||
TEST_CASE("fn_max_cx_subview_row_test", "[max]")
|
||||
{
|
||||
for (size_t r = 10; r < 50; ++r)
|
||||
{
|
||||
@@ -205,7 +206,7 @@ TEST_CASE("fn_max_cx_subview_row_test")
|
||||
|
||||
|
||||
|
||||
// TEST_CASE("fn_max_cx_incomplete_subview_test")
|
||||
// TEST_CASE("fn_max_cx_incomplete_subview_test", "[max]")
|
||||
// {
|
||||
// for (size_t r = 50; r < 150; ++r)
|
||||
// {
|
||||
@@ -249,7 +250,7 @@ TEST_CASE("fn_max_cx_subview_row_test")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("fn_max_cx_incomplete_subview_col_test")
|
||||
TEST_CASE("fn_max_cx_incomplete_subview_col_test", "[max]")
|
||||
{
|
||||
for (size_t r = 10; r < 50; ++r)
|
||||
{
|
||||
@@ -281,7 +282,7 @@ TEST_CASE("fn_max_cx_incomplete_subview_col_test")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("fn_max_cx_incomplete_subview_row_test")
|
||||
TEST_CASE("fn_max_cx_incomplete_subview_row_test", "[max]")
|
||||
{
|
||||
for (size_t r = 10; r < 50; ++r)
|
||||
{
|
||||
@@ -313,7 +314,7 @@ TEST_CASE("fn_max_cx_incomplete_subview_row_test")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("fn_max_weird_operation")
|
||||
TEST_CASE("fn_max_weird_operation", "[max]")
|
||||
{
|
||||
mat a(10, 10, fill::randn);
|
||||
mat b(25, 10, fill::randn);
|
||||
@@ -333,7 +334,7 @@ TEST_CASE("fn_max_weird_operation")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("fn_max_weird_sparse_operation")
|
||||
TEST_CASE("fn_max_weird_sparse_operation", "[max]")
|
||||
{
|
||||
sp_mat a; a.sprandn(10, 10, 0.3);
|
||||
sp_mat b; b.sprandn(25, 10, 0.3);
|
||||
@@ -353,7 +354,7 @@ TEST_CASE("fn_max_weird_sparse_operation")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("fn_max_sp_subview_test")
|
||||
TEST_CASE("fn_max_sp_subview_test", "[max]")
|
||||
{
|
||||
// We will assume subview.at() works and returns points within the bounds of
|
||||
// the matrix, so we just have to ensure the results are the same as
|
||||
@@ -389,7 +390,7 @@ TEST_CASE("fn_max_sp_subview_test")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("fn_max_spsubview_col_test")
|
||||
TEST_CASE("fn_max_spsubview_col_test", "[max]")
|
||||
{
|
||||
for (size_t r = 10; r < 50; ++r)
|
||||
{
|
||||
@@ -418,7 +419,7 @@ TEST_CASE("fn_max_spsubview_col_test")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("fn_max_spsubview_row_max_test")
|
||||
TEST_CASE("fn_max_spsubview_row_max_test", "[max]")
|
||||
{
|
||||
for (size_t r = 10; r < 50; ++r)
|
||||
{
|
||||
@@ -447,7 +448,7 @@ TEST_CASE("fn_max_spsubview_row_max_test")
|
||||
|
||||
|
||||
|
||||
// TEST_CASE("fn_max_spincompletesubview_max_test")
|
||||
// TEST_CASE("fn_max_spincompletesubview_max_test", "[max]")
|
||||
// {
|
||||
// for (size_t r = 50; r < 150; ++r)
|
||||
// {
|
||||
@@ -489,7 +490,7 @@ TEST_CASE("fn_max_spsubview_row_max_test")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("fn_max_spincompletesubview_col_max_test")
|
||||
TEST_CASE("fn_max_spincompletesubview_col_max_test", "[max]")
|
||||
{
|
||||
for (size_t r = 10; r < 50; ++r)
|
||||
{
|
||||
@@ -518,7 +519,7 @@ TEST_CASE("fn_max_spincompletesubview_col_max_test")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("fn_max_spincompletesubview_row_max_test")
|
||||
TEST_CASE("fn_max_spincompletesubview_row_max_test", "[max]")
|
||||
{
|
||||
for (size_t r = 10; r < 50; ++r)
|
||||
{
|
||||
@@ -547,7 +548,7 @@ TEST_CASE("fn_max_spincompletesubview_row_max_test")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("fn_max_sp_cx_subview_max_test")
|
||||
TEST_CASE("fn_max_sp_cx_subview_max_test", "[max]")
|
||||
{
|
||||
// We will assume subview.at() works and returns points within the bounds of
|
||||
// the matrix, so we just have to ensure the results are the same as
|
||||
@@ -587,7 +588,7 @@ TEST_CASE("fn_max_sp_cx_subview_max_test")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("fn_max_sp_cx_subview_col_max_test")
|
||||
TEST_CASE("fn_max_sp_cx_subview_col_max_test", "[max]")
|
||||
{
|
||||
for (size_t r = 10; r < 50; ++r)
|
||||
{
|
||||
@@ -619,7 +620,7 @@ TEST_CASE("fn_max_sp_cx_subview_col_max_test")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("fn_max_sp_cx_subview_row_max_test")
|
||||
TEST_CASE("fn_max_sp_cx_subview_row_max_test", "[max]")
|
||||
{
|
||||
for (size_t r = 10; r < 50; ++r)
|
||||
{
|
||||
@@ -651,7 +652,7 @@ TEST_CASE("fn_max_sp_cx_subview_row_max_test")
|
||||
|
||||
|
||||
|
||||
// TEST_CASE("fn_max_sp_cx_incomplete_subview_max_test")
|
||||
// TEST_CASE("fn_max_sp_cx_incomplete_subview_max_test", "[max]")
|
||||
// {
|
||||
// for (size_t r = 50; r < 150; ++r)
|
||||
// {
|
||||
@@ -696,7 +697,7 @@ TEST_CASE("fn_max_sp_cx_subview_row_max_test")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("fn_max_sp_cx_incomplete_subview_col_max_test")
|
||||
TEST_CASE("fn_max_sp_cx_incomplete_subview_col_max_test", "[max]")
|
||||
{
|
||||
for (size_t r = 10; r < 50; ++r)
|
||||
{
|
||||
@@ -728,7 +729,7 @@ TEST_CASE("fn_max_sp_cx_incomplete_subview_col_max_test")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("fn_max_sp_cx_incomplete_subview_row_max_test")
|
||||
TEST_CASE("fn_max_sp_cx_incomplete_subview_row_max_test", "[max]")
|
||||
{
|
||||
for (size_t r = 10; r < 50; ++r)
|
||||
{
|
||||
@@ -757,3 +758,81 @@ TEST_CASE("fn_max_sp_cx_incomplete_subview_row_max_test")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
TEMPLATE_TEST_CASE("fn_max_unary_fp_reference", "[max]", TEST_FLOAT_TYPES)
|
||||
{
|
||||
typedef TestType eT;
|
||||
|
||||
constexpr eT margin = is_blas_real<eT>::value ? eT(0.001) : eT(0.1);
|
||||
|
||||
Mat<eT> X(10, 10, fill::randn);
|
||||
mat X_ref = conv_to<mat>::from(X);
|
||||
|
||||
eT max_val = X.max();
|
||||
uword max_val_index = X.index_max();
|
||||
|
||||
double max_val_ref = X_ref.max();
|
||||
uword max_val_index_ref = X_ref.index_max();
|
||||
|
||||
REQUIRE( max_val == Approx(eT(max_val_ref)).margin(margin) );
|
||||
REQUIRE( max_val_index == max_val_index_ref );
|
||||
|
||||
max_val = max(vectorise(X));
|
||||
max_val_index = index_max(vectorise(X));
|
||||
max_val_ref = max(vectorise(X_ref));
|
||||
max_val_index_ref = index_max(vectorise(X_ref));
|
||||
|
||||
REQUIRE( max_val == Approx(eT(max_val_ref)).margin(margin) );
|
||||
REQUIRE( max_val_index == max_val_index_ref );
|
||||
|
||||
max_val = X.submat(1, 1, 6, 6).max();
|
||||
max_val_index = X.submat(1, 1, 6, 6).index_max();
|
||||
max_val_ref = X_ref.submat(1, 1, 6, 6).max();
|
||||
max_val_index_ref = X_ref.submat(1, 1, 6, 6).index_max();
|
||||
|
||||
REQUIRE( max_val == Approx(eT(max_val_ref)).margin(margin) );
|
||||
REQUIRE( max_val_index == max_val_index_ref );
|
||||
|
||||
max_val = max(vectorise(X.submat(1, 1, 6, 6)));
|
||||
max_val_index = index_max(vectorise(X.submat(1, 1, 6, 6)));
|
||||
max_val_ref = max(vectorise(X_ref.submat(1, 1, 6, 6)));
|
||||
max_val_index_ref = index_max(vectorise(X_ref.submat(1, 1, 6, 6)));
|
||||
|
||||
REQUIRE( max_val == Approx(eT(max_val_ref)).margin(margin) );
|
||||
REQUIRE( max_val_index == max_val_index_ref );
|
||||
}
|
||||
|
||||
|
||||
|
||||
TEMPLATE_TEST_CASE("fn_max_binary_fp_reference", "[max]", TEST_FLOAT_TYPES)
|
||||
{
|
||||
typedef TestType eT;
|
||||
|
||||
Mat<eT> X(10, 10, fill::randn);
|
||||
Mat<eT> Y(10, 10, fill::randn);
|
||||
|
||||
Mat<eT> Z = max(X, Y);
|
||||
|
||||
REQUIRE( Z.n_rows == X.n_rows );
|
||||
REQUIRE( Z.n_cols == X.n_cols );
|
||||
|
||||
for (uword i = 0; i < Z.n_elem; ++i)
|
||||
{
|
||||
REQUIRE( Z[i] == Approx(std::max(X[i], Y[i])) );
|
||||
}
|
||||
|
||||
Z = max(X.submat(1, 1, 6, 6), Y.submat(1, 1, 6, 6));
|
||||
|
||||
REQUIRE( Z.n_rows == 6 );
|
||||
REQUIRE( Z.n_cols == 6 );
|
||||
|
||||
for (uword c = 0; c < Z.n_cols; ++c)
|
||||
{
|
||||
for (uword r = 0; r < Z.n_rows; ++r)
|
||||
{
|
||||
REQUIRE( Z(r, c) == Approx(std::max(X(r + 1, c + 1), Y(r + 1, c + 1))) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+49
-11
@@ -18,10 +18,11 @@
|
||||
#include <armadillo>
|
||||
|
||||
#include "catch.hpp"
|
||||
#include "utils.hpp"
|
||||
|
||||
using namespace arma;
|
||||
|
||||
TEST_CASE("fn_mean_spmat_empty_test")
|
||||
TEST_CASE("fn_mean_spmat_empty_test", "[mean]")
|
||||
{
|
||||
SpMat<double> m(20, 25);
|
||||
|
||||
@@ -69,7 +70,7 @@ TEST_CASE("fn_mean_spmat_empty_test")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("fn_mean_spcxmat_empty_test")
|
||||
TEST_CASE("fn_mean_spcxmat_empty_test", "[mean]")
|
||||
{
|
||||
// Now with complex numbers.
|
||||
SpMat<std::complex<double> > m(20, 25);
|
||||
@@ -123,7 +124,7 @@ TEST_CASE("fn_mean_spcxmat_empty_test")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("fn_mean_spmat_test")
|
||||
TEST_CASE("fn_mean_spmat_test", "[mean]")
|
||||
{
|
||||
// Create a random matrix and do mean testing on it, with varying levels of
|
||||
// nonzero (eventually this becomes a fully dense matrix).
|
||||
@@ -228,7 +229,7 @@ TEST_CASE("fn_mean_spmat_test")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("fn_mean_spcxmat_test")
|
||||
TEST_CASE("fn_mean_spcxmat_test", "[mean]")
|
||||
{
|
||||
// Create a random matrix and do mean testing on it, with varying levels of
|
||||
// nonzero (eventually this becomes a fully dense matrix).
|
||||
@@ -360,7 +361,7 @@ TEST_CASE("fn_mean_spcxmat_test")
|
||||
}
|
||||
|
||||
|
||||
TEST_CASE("fn_mean_sp_vector_test")
|
||||
TEST_CASE("fn_mean_sp_vector_test", "[mean]")
|
||||
{
|
||||
// Test mean() on vectors.
|
||||
SpCol<double> c(1000);
|
||||
@@ -435,7 +436,7 @@ TEST_CASE("fn_mean_sp_vector_test")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("fn_mean_sp_cx_vector_test")
|
||||
TEST_CASE("fn_mean_sp_cx_vector_test", "[mean]")
|
||||
{
|
||||
// Test mean() on vectors.
|
||||
SpCol<std::complex<double> > c(1000);
|
||||
@@ -519,7 +520,7 @@ TEST_CASE("fn_mean_sp_cx_vector_test")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("fn_mean_robust_sparse_test")
|
||||
TEST_CASE("fn_mean_robust_sparse_test", "[mean]")
|
||||
{
|
||||
// Create a sparse matrix with values that will overflow.
|
||||
SpMat<double> x;
|
||||
@@ -644,7 +645,7 @@ TEST_CASE("fn_mean_robust_sparse_test")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("fn_mean_robust_cx_sparse_test")
|
||||
TEST_CASE("fn_mean_robust_cx_sparse_test", "[mean]")
|
||||
{
|
||||
SpMat<std::complex<double> > x;
|
||||
x.sprandu(50, 75, 0.3);
|
||||
@@ -780,7 +781,7 @@ TEST_CASE("fn_mean_robust_cx_sparse_test")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("fn_mean_robust_sparse_vector_test")
|
||||
TEST_CASE("fn_mean_robust_sparse_vector_test", "[mean]")
|
||||
{
|
||||
// Test mean() on vectors.
|
||||
SpCol<double> c(1000);
|
||||
@@ -850,7 +851,7 @@ TEST_CASE("fn_mean_robust_sparse_vector_test")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("fn_mean_robust_cx_sparse_vector_test")
|
||||
TEST_CASE("fn_mean_robust_cx_sparse_vector_test", "[mean]")
|
||||
{
|
||||
// Test mean() on vectors.
|
||||
SpCol<std::complex<double> > c(1000);
|
||||
@@ -922,7 +923,7 @@ TEST_CASE("fn_mean_robust_cx_sparse_vector_test")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("fn_mean_sparse_alias_test")
|
||||
TEST_CASE("fn_mean_sparse_alias_test", "[mean]")
|
||||
{
|
||||
sp_mat s;
|
||||
s.sprandu(70, 70, 0.3);
|
||||
@@ -948,3 +949,40 @@ TEST_CASE("fn_mean_sparse_alias_test")
|
||||
REQUIRE( d[i] == Approx((double) s[i]) );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
TEMPLATE_TEST_CASE("fn_mean_fp_ref", "[mean]", TEST_FLOAT_TYPES)
|
||||
{
|
||||
typedef TestType eT;
|
||||
|
||||
// keep number of elements small so that floating-point error remains small
|
||||
Col<eT> X(10, fill::randu);
|
||||
vec X_ref = conv_to<vec>::from(X);
|
||||
|
||||
const eT mean_val = mean(X);
|
||||
const double mean_val_ref = mean(X_ref);
|
||||
|
||||
constexpr eT margin = is_blas_real<eT>::value ? eT(0.001) : eT(0.02);
|
||||
|
||||
REQUIRE( mean_val == Approx(eT(mean_val_ref)).margin(margin) );
|
||||
}
|
||||
|
||||
|
||||
|
||||
//TEMPLATE_TEST_CASE("fn_mean_sp_fp_ref", "[mean]", TEST_FLOAT_TYPES)
|
||||
// {
|
||||
// typedef TestType eT;
|
||||
//
|
||||
// // keep number of elements small so that floating-point error remains small
|
||||
// SpCol<eT> X;
|
||||
// X.sprandu(100, 1, 0.3);
|
||||
// sp_vec X_ref = conv_to<sp_mat>::from(X);
|
||||
//
|
||||
// const eT mean_val = mean(X);
|
||||
// const double mean_val_ref = mean(X_ref);
|
||||
//
|
||||
// constexpr eT margin = is_blas_real<eT>::value ? eT(0.001) : eT(0.02);
|
||||
//
|
||||
// REQUIRE( mean_val == Approx(eT(mean_val_ref)).margin(margin) );
|
||||
// }
|
||||
|
||||
+102
-23
@@ -18,10 +18,11 @@
|
||||
#include <armadillo>
|
||||
|
||||
#include "catch.hpp"
|
||||
#include "utils.hpp"
|
||||
|
||||
using namespace arma;
|
||||
|
||||
TEST_CASE("fn_min_subview_test")
|
||||
TEST_CASE("fn_min_subview_test", "[min]")
|
||||
{
|
||||
// We will assume subview.at() works and returns points within the bounds of
|
||||
// the matrix, so we just have to ensure the results are the same as
|
||||
@@ -54,7 +55,7 @@ TEST_CASE("fn_min_subview_test")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("fn_min_subview_col_test")
|
||||
TEST_CASE("fn_min_subview_col_test", "[min]")
|
||||
{
|
||||
for (size_t r = 10; r < 50; ++r)
|
||||
{
|
||||
@@ -80,7 +81,7 @@ TEST_CASE("fn_min_subview_col_test")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("fn_min_subview_row_test")
|
||||
TEST_CASE("fn_min_subview_row_test", "[min]")
|
||||
{
|
||||
for (size_t r = 10; r < 50; ++r)
|
||||
{
|
||||
@@ -106,7 +107,7 @@ TEST_CASE("fn_min_subview_row_test")
|
||||
|
||||
|
||||
|
||||
// TEST_CASE("fn_min_incomplete_subview_test")
|
||||
// TEST_CASE("fn_min_incomplete_subview_test", "[min]")
|
||||
// {
|
||||
// for (size_t r = 50; r < 150; ++r)
|
||||
// {
|
||||
@@ -147,7 +148,7 @@ TEST_CASE("fn_min_subview_row_test")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("fn_min_incomplete_subview_col_test")
|
||||
TEST_CASE("fn_min_incomplete_subview_col_test", "[min]")
|
||||
{
|
||||
for (size_t r = 10; r < 50; ++r)
|
||||
{
|
||||
@@ -176,7 +177,7 @@ TEST_CASE("fn_min_incomplete_subview_col_test")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("fn_min_cx_subview_row_test")
|
||||
TEST_CASE("fn_min_cx_subview_row_test", "[min]")
|
||||
{
|
||||
for (size_t r = 10; r < 50; ++r)
|
||||
{
|
||||
@@ -205,7 +206,7 @@ TEST_CASE("fn_min_cx_subview_row_test")
|
||||
|
||||
|
||||
|
||||
// TEST_CASE("fn_min_cx_incomplete_subview_test")
|
||||
// TEST_CASE("fn_min_cx_incomplete_subview_test", "[min]")
|
||||
// {
|
||||
// for (size_t r = 50; r < 150; ++r)
|
||||
// {
|
||||
@@ -249,7 +250,7 @@ TEST_CASE("fn_min_cx_subview_row_test")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("fn_min_cx_incomplete_subview_col_test")
|
||||
TEST_CASE("fn_min_cx_incomplete_subview_col_test", "[min]")
|
||||
{
|
||||
for (size_t r = 10; r < 50; ++r)
|
||||
{
|
||||
@@ -281,7 +282,7 @@ TEST_CASE("fn_min_cx_incomplete_subview_col_test")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("fn_min_cx_incomplete_subview_row_test")
|
||||
TEST_CASE("fn_min_cx_incomplete_subview_row_test", "[min]")
|
||||
{
|
||||
for (size_t r = 10; r < 50; ++r)
|
||||
{
|
||||
@@ -313,7 +314,7 @@ TEST_CASE("fn_min_cx_incomplete_subview_row_test")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("fn_min_weird_operation")
|
||||
TEST_CASE("fn_min_weird_operation", "[min]")
|
||||
{
|
||||
mat a(10, 10, fill::randn);
|
||||
mat b(25, 10, fill::randn);
|
||||
@@ -333,7 +334,7 @@ TEST_CASE("fn_min_weird_operation")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("fn_min_weird_sparse_operation")
|
||||
TEST_CASE("fn_min_weird_sparse_operation", "[min]")
|
||||
{
|
||||
sp_mat a; a.sprandn(10, 10, 0.3);
|
||||
sp_mat b; b.sprandn(25, 10, 0.3);
|
||||
@@ -353,7 +354,7 @@ TEST_CASE("fn_min_weird_sparse_operation")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("fn_min_sp_subview_test")
|
||||
TEST_CASE("fn_min_sp_subview_test", "[min]")
|
||||
{
|
||||
// We will assume subview.at() works and returns points within the bounds of
|
||||
// the matrix, so we just have to ensure the results are the same as
|
||||
@@ -389,7 +390,7 @@ TEST_CASE("fn_min_sp_subview_test")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("fn_min_spsubview_col_test")
|
||||
TEST_CASE("fn_min_spsubview_col_test", "[min]")
|
||||
{
|
||||
for (size_t r = 10; r < 50; ++r)
|
||||
{
|
||||
@@ -418,7 +419,7 @@ TEST_CASE("fn_min_spsubview_col_test")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("fn_min_spsubview_row_min_test")
|
||||
TEST_CASE("fn_min_spsubview_row_min_test", "[min]")
|
||||
{
|
||||
for (size_t r = 10; r < 50; ++r)
|
||||
{
|
||||
@@ -447,7 +448,7 @@ TEST_CASE("fn_min_spsubview_row_min_test")
|
||||
|
||||
|
||||
|
||||
// TEST_CASE("fn_min_spincompletesubview_min_test")
|
||||
// TEST_CASE("fn_min_spincompletesubview_min_test", "[min]")
|
||||
// {
|
||||
// for (size_t r = 50; r < 150; ++r)
|
||||
// {
|
||||
@@ -489,7 +490,7 @@ TEST_CASE("fn_min_spsubview_row_min_test")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("fn_min_spincompletesubview_col_min_test")
|
||||
TEST_CASE("fn_min_spincompletesubview_col_min_test", "[min]")
|
||||
{
|
||||
for (size_t r = 10; r < 50; ++r)
|
||||
{
|
||||
@@ -518,7 +519,7 @@ TEST_CASE("fn_min_spincompletesubview_col_min_test")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("fn_min_spincompletesubview_row_min_test")
|
||||
TEST_CASE("fn_min_spincompletesubview_row_min_test", "[min]")
|
||||
{
|
||||
for (size_t r = 10; r < 50; ++r)
|
||||
{
|
||||
@@ -547,7 +548,7 @@ TEST_CASE("fn_min_spincompletesubview_row_min_test")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("fn_min_sp_cx_subview_min_test")
|
||||
TEST_CASE("fn_min_sp_cx_subview_min_test", "[min]")
|
||||
{
|
||||
// We will assume subview.at() works and returns points within the bounds of
|
||||
// the matrix, so we just have to ensure the results are the same as
|
||||
@@ -587,7 +588,7 @@ TEST_CASE("fn_min_sp_cx_subview_min_test")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("fn_min_sp_cx_subview_col_min_test")
|
||||
TEST_CASE("fn_min_sp_cx_subview_col_min_test", "[min]")
|
||||
{
|
||||
for (size_t r = 10; r < 50; ++r)
|
||||
{
|
||||
@@ -619,7 +620,7 @@ TEST_CASE("fn_min_sp_cx_subview_col_min_test")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("fn_min_sp_cx_subview_row_min_test")
|
||||
TEST_CASE("fn_min_sp_cx_subview_row_min_test", "[min]")
|
||||
{
|
||||
for (size_t r = 10; r < 50; ++r)
|
||||
{
|
||||
@@ -651,7 +652,7 @@ TEST_CASE("fn_min_sp_cx_subview_row_min_test")
|
||||
|
||||
|
||||
|
||||
// TEST_CASE("fn_min_sp_cx_incomplete_subview_min_test")
|
||||
// TEST_CASE("fn_min_sp_cx_incomplete_subview_min_test", "[min]")
|
||||
// {
|
||||
// for (size_t r = 50; r < 150; ++r)
|
||||
// {
|
||||
@@ -696,7 +697,7 @@ TEST_CASE("fn_min_sp_cx_subview_row_min_test")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("fn_min_sp_cx_incomplete_subview_col_min_test")
|
||||
TEST_CASE("fn_min_sp_cx_incomplete_subview_col_min_test", "[min]")
|
||||
{
|
||||
for (size_t r = 10; r < 50; ++r)
|
||||
{
|
||||
@@ -728,7 +729,7 @@ TEST_CASE("fn_min_sp_cx_incomplete_subview_col_min_test")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("fn_min_sp_cx_incomplete_subview_row_min_test")
|
||||
TEST_CASE("fn_min_sp_cx_incomplete_subview_row_min_test", "[min]")
|
||||
{
|
||||
for (size_t r = 10; r < 50; ++r)
|
||||
{
|
||||
@@ -757,3 +758,81 @@ TEST_CASE("fn_min_sp_cx_incomplete_subview_row_min_test")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
TEMPLATE_TEST_CASE("fn_min_unary_fp_reference", "[min]", TEST_FLOAT_TYPES)
|
||||
{
|
||||
typedef TestType eT;
|
||||
|
||||
constexpr eT margin = is_blas_real<eT>::value ? eT(0.001) : eT(0.1);
|
||||
|
||||
Mat<eT> X(10, 10, fill::randn);
|
||||
mat X_ref = conv_to<mat>::from(X);
|
||||
|
||||
eT min_val = X.min();
|
||||
uword min_val_index = X.index_min();
|
||||
|
||||
double min_val_ref = X_ref.min();
|
||||
uword min_val_index_ref = X_ref.index_min();
|
||||
|
||||
REQUIRE( min_val == Approx(eT(min_val_ref)).margin(margin) );
|
||||
REQUIRE( min_val_index == min_val_index_ref );
|
||||
|
||||
min_val = min(vectorise(X));
|
||||
min_val_index = index_min(vectorise(X));
|
||||
min_val_ref = min(vectorise(X_ref));
|
||||
min_val_index_ref = index_min(vectorise(X_ref));
|
||||
|
||||
REQUIRE( min_val == Approx(eT(min_val_ref)).margin(margin) );
|
||||
REQUIRE( min_val_index == min_val_index_ref );
|
||||
|
||||
min_val = X.submat(1, 1, 6, 6).min();
|
||||
min_val_index = X.submat(1, 1, 6, 6).index_min();
|
||||
min_val_ref = X_ref.submat(1, 1, 6, 6).min();
|
||||
min_val_index_ref = X_ref.submat(1, 1, 6, 6).index_min();
|
||||
|
||||
REQUIRE( min_val == Approx(eT(min_val_ref)).margin(margin) );
|
||||
REQUIRE( min_val_index == min_val_index_ref );
|
||||
|
||||
min_val = min(vectorise(X.submat(1, 1, 6, 6)));
|
||||
min_val_index = index_min(vectorise(X.submat(1, 1, 6, 6)));
|
||||
min_val_ref = min(vectorise(X_ref.submat(1, 1, 6, 6)));
|
||||
min_val_index_ref = index_min(vectorise(X_ref.submat(1, 1, 6, 6)));
|
||||
|
||||
REQUIRE( min_val == Approx(eT(min_val_ref)).margin(margin) );
|
||||
REQUIRE( min_val_index == min_val_index_ref );
|
||||
}
|
||||
|
||||
|
||||
|
||||
TEMPLATE_TEST_CASE("fn_min_binary_fp_reference", "[min]", TEST_FLOAT_TYPES)
|
||||
{
|
||||
typedef TestType eT;
|
||||
|
||||
Mat<eT> X(10, 10, fill::randn);
|
||||
Mat<eT> Y(10, 10, fill::randn);
|
||||
|
||||
Mat<eT> Z = min(X, Y);
|
||||
|
||||
REQUIRE( Z.n_rows == X.n_rows );
|
||||
REQUIRE( Z.n_cols == X.n_cols );
|
||||
|
||||
for (uword i = 0; i < Z.n_elem; ++i)
|
||||
{
|
||||
REQUIRE( Z[i] == Approx(std::min(X[i], Y[i])) );
|
||||
}
|
||||
|
||||
Z = min(X.submat(1, 1, 6, 6), Y.submat(1, 1, 6, 6));
|
||||
|
||||
REQUIRE( Z.n_rows == 6 );
|
||||
REQUIRE( Z.n_cols == 6 );
|
||||
|
||||
for (uword c = 0; c < Z.n_cols; ++c)
|
||||
{
|
||||
for (uword r = 0; r < Z.n_rows; ++r)
|
||||
{
|
||||
REQUIRE( Z(r, c) == Approx(std::min(X(r + 1, c + 1), Y(r + 1, c + 1))) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -92,7 +92,7 @@ namespace
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("fn_princomp_1")
|
||||
TEST_CASE("fn_princomp_1", "[princomp]")
|
||||
{
|
||||
mat m(1000, 20);
|
||||
initMatrix(m);
|
||||
@@ -100,7 +100,7 @@ TEST_CASE("fn_princomp_1")
|
||||
checkEigenvectors(coeff);
|
||||
}
|
||||
|
||||
TEST_CASE("fn_princomp_2")
|
||||
TEST_CASE("fn_princomp_2", "[princomp]")
|
||||
{
|
||||
mat m(1000, 20);
|
||||
initMatrix(m);
|
||||
@@ -109,7 +109,7 @@ TEST_CASE("fn_princomp_2")
|
||||
checkEigenvectors(coeff);
|
||||
}
|
||||
|
||||
TEST_CASE("fn_princomp_3")
|
||||
TEST_CASE("fn_princomp_3", "[princomp]")
|
||||
{
|
||||
mat m(1000, 20);
|
||||
initMatrix(m);
|
||||
@@ -120,7 +120,7 @@ TEST_CASE("fn_princomp_3")
|
||||
checkEigenvectors(coeff);
|
||||
}
|
||||
|
||||
TEST_CASE("fn_princomp_4")
|
||||
TEST_CASE("fn_princomp_4", "[princomp]")
|
||||
{
|
||||
mat m(1000, 20);
|
||||
initMatrix(m);
|
||||
@@ -133,7 +133,7 @@ TEST_CASE("fn_princomp_4")
|
||||
checkEigenvalues(latent);
|
||||
}
|
||||
|
||||
TEST_CASE("fn_princomp_5")
|
||||
TEST_CASE("fn_princomp_5", "[princomp]")
|
||||
{
|
||||
mat m(1000, 20);
|
||||
initMatrix(m);
|
||||
@@ -148,7 +148,7 @@ TEST_CASE("fn_princomp_5")
|
||||
// checkHotteling(tsquared); // TODO
|
||||
}
|
||||
|
||||
TEST_CASE("fn_princomp_6")
|
||||
TEST_CASE("fn_princomp_6", "[princomp]")
|
||||
{
|
||||
mat m(5, 20);
|
||||
initMatrix(m);
|
||||
|
||||
+3
-3
@@ -21,7 +21,7 @@
|
||||
using namespace arma;
|
||||
|
||||
|
||||
TEST_CASE("fn_solve_1")
|
||||
TEST_CASE("fn_solve_1", "[solve]")
|
||||
{
|
||||
// square-sized A
|
||||
|
||||
@@ -63,7 +63,7 @@ TEST_CASE("fn_solve_1")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("fn_solve_2")
|
||||
TEST_CASE("fn_solve_2", "[solve]")
|
||||
{
|
||||
// square-sized A; rank-deficient
|
||||
|
||||
@@ -105,7 +105,7 @@ TEST_CASE("fn_solve_2")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("fn_solve_3")
|
||||
TEST_CASE("fn_solve_3", "[solve]")
|
||||
{
|
||||
// non-square-sized A
|
||||
|
||||
|
||||
+22
-22
@@ -23,7 +23,7 @@ using namespace arma;
|
||||
|
||||
#if defined(ARMA_USE_SUPERLU)
|
||||
|
||||
TEST_CASE("fn_spsolve_sparse_test")
|
||||
TEST_CASE("fn_spsolve_sparse_test", "[spsolve]")
|
||||
{
|
||||
// We want to spsolve a system of equations, AX = B, where we want to recover
|
||||
// X and we have A and B, and A is sparse.
|
||||
@@ -64,7 +64,7 @@ TEST_CASE("fn_spsolve_sparse_test")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("fn_spsolve_sparse_nonsymmetric_test")
|
||||
TEST_CASE("fn_spsolve_sparse_nonsymmetric_test", "[spsolve]")
|
||||
{
|
||||
for (size_t t = 0; t < 10; ++t)
|
||||
{
|
||||
@@ -104,7 +104,7 @@ TEST_CASE("fn_spsolve_sparse_nonsymmetric_test")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("fn_spsolve_sparse_float_test")
|
||||
TEST_CASE("fn_spsolve_sparse_float_test", "[spsolve]")
|
||||
{
|
||||
// We want to spsolve a system of equations, AX = B, where we want to recover
|
||||
// X and we have A and B, and A is sparse.
|
||||
@@ -156,7 +156,7 @@ TEST_CASE("fn_spsolve_sparse_float_test")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("fn_spsolve_sparse_nonsymmetric_float_test")
|
||||
TEST_CASE("fn_spsolve_sparse_nonsymmetric_float_test", "[spsolve]")
|
||||
{
|
||||
for (size_t t = 0; t < 10; ++t)
|
||||
{
|
||||
@@ -196,7 +196,7 @@ TEST_CASE("fn_spsolve_sparse_nonsymmetric_float_test")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("fn_spsolve_sparse_complex_float_test")
|
||||
TEST_CASE("fn_spsolve_sparse_complex_float_test", "[spsolve]")
|
||||
{
|
||||
// We want to spsolve a system of equations, AX = B, where we want to recover
|
||||
// X and we have A and B, and A is sparse.
|
||||
@@ -238,7 +238,7 @@ TEST_CASE("fn_spsolve_sparse_complex_float_test")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("fn_spsolve_sparse_nonsymmetric_complex_float_test")
|
||||
TEST_CASE("fn_spsolve_sparse_nonsymmetric_complex_float_test", "[spsolve]")
|
||||
{
|
||||
for (size_t t = 0; t < 10; ++t)
|
||||
{
|
||||
@@ -279,7 +279,7 @@ TEST_CASE("fn_spsolve_sparse_nonsymmetric_complex_float_test")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("fn_spsolve_sparse_complex_test")
|
||||
TEST_CASE("fn_spsolve_sparse_complex_test", "[spsolve]")
|
||||
{
|
||||
// We want to spsolve a system of equations, AX = B, where we want to recover
|
||||
// X and we have A and B, and A is sparse.
|
||||
@@ -321,7 +321,7 @@ TEST_CASE("fn_spsolve_sparse_complex_test")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("fn_spsolve_sparse_nonsymmetric_complex_test")
|
||||
TEST_CASE("fn_spsolve_sparse_nonsymmetric_complex_test", "[spsolve]")
|
||||
{
|
||||
for (size_t t = 0; t < 10; ++t)
|
||||
{
|
||||
@@ -362,7 +362,7 @@ TEST_CASE("fn_spsolve_sparse_nonsymmetric_complex_test")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("fn_spsolve_delayed_sparse_test")
|
||||
TEST_CASE("fn_spsolve_delayed_sparse_test", "[spsolve]")
|
||||
{
|
||||
const uword size = 10;
|
||||
|
||||
@@ -396,7 +396,7 @@ TEST_CASE("fn_spsolve_delayed_sparse_test")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("fn_spsolve_superlu_solve_test")
|
||||
TEST_CASE("fn_spsolve_superlu_solve_test", "[spsolve]")
|
||||
{
|
||||
// Solve this matrix, as in the examples:
|
||||
// [[19 0 21 21 0]
|
||||
@@ -440,7 +440,7 @@ TEST_CASE("fn_spsolve_superlu_solve_test")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("fn_spsolve_random_superlu_solve_test")
|
||||
TEST_CASE("fn_spsolve_random_superlu_solve_test", "[spsolve]")
|
||||
{
|
||||
// Try to solve some random systems.
|
||||
const size_t iterations = 10;
|
||||
@@ -472,7 +472,7 @@ TEST_CASE("fn_spsolve_random_superlu_solve_test")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("fn_spsolve_float_superlu_solve_test")
|
||||
TEST_CASE("fn_spsolve_float_superlu_solve_test", "[spsolve]")
|
||||
{
|
||||
// Solve this matrix, as in the examples:
|
||||
// [[19 0 21 21 0]
|
||||
@@ -516,7 +516,7 @@ TEST_CASE("fn_spsolve_float_superlu_solve_test")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("fn_spsolve_float_random_superlu_solve_test")
|
||||
TEST_CASE("fn_spsolve_float_random_superlu_solve_test", "[spsolve]")
|
||||
{
|
||||
// Try to solve some random systems.
|
||||
const size_t iterations = 10;
|
||||
@@ -562,7 +562,7 @@ TEST_CASE("fn_spsolve_float_random_superlu_solve_test")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("fn_spsolve_cx_float_superlu_solve_test")
|
||||
TEST_CASE("fn_spsolve_cx_float_superlu_solve_test", "[spsolve]")
|
||||
{
|
||||
// Solve this matrix, as in the examples:
|
||||
// [[19 0 21 21 0]
|
||||
@@ -616,7 +616,7 @@ TEST_CASE("fn_spsolve_cx_float_superlu_solve_test")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("fn_spsolve_cx_float_random_superlu_solve_test")
|
||||
TEST_CASE("fn_spsolve_cx_float_random_superlu_solve_test", "[spsolve]")
|
||||
{
|
||||
// Try to solve some random systems.
|
||||
const size_t iterations = 10;
|
||||
@@ -658,7 +658,7 @@ TEST_CASE("fn_spsolve_cx_float_random_superlu_solve_test")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("fn_spsolve_cx_superlu_solve_test")
|
||||
TEST_CASE("fn_spsolve_cx_superlu_solve_test", "[spsolve]")
|
||||
{
|
||||
// Solve this matrix, as in the examples:
|
||||
// [[19 0 21 21 0]
|
||||
@@ -712,7 +712,7 @@ TEST_CASE("fn_spsolve_cx_superlu_solve_test")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("fn_spsolve_cx_random_superlu_solve_test")
|
||||
TEST_CASE("fn_spsolve_cx_random_superlu_solve_test", "[spsolve]")
|
||||
{
|
||||
// Try to solve some random systems.
|
||||
const size_t iterations = 10;
|
||||
@@ -754,7 +754,7 @@ TEST_CASE("fn_spsolve_cx_random_superlu_solve_test")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("fn_spsolve_function_test")
|
||||
TEST_CASE("fn_spsolve_function_test", "[spsolve]")
|
||||
{
|
||||
sp_mat a;
|
||||
a.sprandu(50, 50, 0.3);
|
||||
@@ -785,7 +785,7 @@ TEST_CASE("fn_spsolve_function_test")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("fn_spsolve_float_function_test")
|
||||
TEST_CASE("fn_spsolve_float_function_test", "[spsolve]")
|
||||
{
|
||||
sp_fmat a;
|
||||
a.sprandu(50, 50, 0.3);
|
||||
@@ -823,7 +823,7 @@ TEST_CASE("fn_spsolve_float_function_test")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("fn_spsolve_cx_function_test")
|
||||
TEST_CASE("fn_spsolve_cx_function_test", "[spsolve]")
|
||||
{
|
||||
sp_cx_mat a;
|
||||
a.sprandu(50, 50, 0.3);
|
||||
@@ -864,7 +864,7 @@ TEST_CASE("fn_spsolve_cx_function_test")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("fn_spsolve_cx_float_function_test")
|
||||
TEST_CASE("fn_spsolve_cx_float_function_test", "[spsolve]")
|
||||
{
|
||||
sp_cx_fmat a;
|
||||
a.sprandu(50, 50, 0.3);
|
||||
@@ -905,7 +905,7 @@ TEST_CASE("fn_spsolve_cx_float_function_test")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("spsolve_factoriser_test")
|
||||
TEST_CASE("spsolve_factoriser_test", "[spsolve]")
|
||||
{
|
||||
sp_mat A;
|
||||
A.sprandu(100, 100, 0.2);
|
||||
|
||||
+41
-5
@@ -18,10 +18,11 @@
|
||||
#include <armadillo>
|
||||
|
||||
#include "catch.hpp"
|
||||
#include "utils.hpp"
|
||||
|
||||
using namespace arma;
|
||||
|
||||
TEST_CASE("fn_stddev_empty_sparse_test", "[fn_stddev]")
|
||||
TEST_CASE("fn_stddev_empty_sparse_test", "[stddev]")
|
||||
{
|
||||
SpMat<double> m(100, 100);
|
||||
|
||||
@@ -82,7 +83,7 @@ TEST_CASE("fn_stddev_empty_sparse_test", "[fn_stddev]")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("fn_stddev_empty_cx_sparse_test", "[fn_stddev]")
|
||||
TEST_CASE("fn_stddev_empty_cx_sparse_test", "[stddev]")
|
||||
{
|
||||
SpMat<std::complex<double> > m(100, 100);
|
||||
|
||||
@@ -143,7 +144,7 @@ TEST_CASE("fn_stddev_empty_cx_sparse_test", "[fn_stddev]")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("fn_stddev_sparse_test", "[fn_stddev]")
|
||||
TEST_CASE("fn_stddev_sparse_test", "[stddev]")
|
||||
{
|
||||
// Create a random matrix and do variance testing on it, with varying levels
|
||||
// of nonzero (eventually this becomes a fully dense matrix).
|
||||
@@ -333,7 +334,7 @@ TEST_CASE("fn_stddev_sparse_test", "[fn_stddev]")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("fn_stddev_sparse_cx_test", "[fn_stddev]")
|
||||
TEST_CASE("fn_stddev_sparse_cx_test", "[stddev]")
|
||||
{
|
||||
// Create a random matrix and do variance testing on it, with varying levels
|
||||
// of nonzero (eventually this becomes a fully dense matrix).
|
||||
@@ -523,7 +524,7 @@ TEST_CASE("fn_stddev_sparse_cx_test", "[fn_stddev]")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("fn_stddev_sparse_alias_test", "[fn_stddev]")
|
||||
TEST_CASE("fn_stddev_sparse_alias_test", "[stddev]")
|
||||
{
|
||||
sp_mat s;
|
||||
s.sprandu(70, 70, 0.3);
|
||||
@@ -549,3 +550,38 @@ TEST_CASE("fn_stddev_sparse_alias_test", "[fn_stddev]")
|
||||
REQUIRE( d[i] == Approx((double) s[i]) );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
TEMPLATE_TEST_CASE("fn_stddev_fp_reference", "[stddev]", TEST_FLOAT_TYPES)
|
||||
{
|
||||
typedef TestType eT;
|
||||
|
||||
Col<eT> X(10, fill::randn);
|
||||
vec X_ref = conv_to<vec>::from(X);
|
||||
|
||||
const eT stddev_val = stddev(X);
|
||||
const double stddev_ref = stddev(X_ref);
|
||||
|
||||
const eT margin = is_blas_real<eT>::value ? eT(0.001) : eT(0.02);
|
||||
|
||||
REQUIRE( stddev_val == Approx(eT(stddev_ref)).margin(margin) );
|
||||
}
|
||||
|
||||
|
||||
|
||||
//TEMPLATE_TEST_CASE("fn_stddev_sp_fp_reference", "[stddev]", TEST_FLOAT_TYPES)
|
||||
// {
|
||||
// typedef TestType eT;
|
||||
//
|
||||
// SpCol<eT> X;
|
||||
// X.sprandu(100, 1, 0.3);
|
||||
// sp_vec X_ref = conv_to<sp_mat>::from(X);
|
||||
//
|
||||
// const eT stddev_val = stddev(X);
|
||||
// const double stddev_ref = stddev(X_ref);
|
||||
//
|
||||
// const eT margin = is_blas_real<eT>::value ? eT(0.001) : eT(0.02);
|
||||
//
|
||||
// REQUIRE( stddev_val == Approx(eT(stddev_ref)).margin(margin) );
|
||||
// }
|
||||
|
||||
+70
-6
@@ -18,11 +18,12 @@
|
||||
|
||||
#include <armadillo>
|
||||
#include "catch.hpp"
|
||||
#include "utils.hpp"
|
||||
|
||||
using namespace arma;
|
||||
|
||||
|
||||
TEST_CASE("fn_sum_1")
|
||||
TEST_CASE("fn_sum_1", "[sum]")
|
||||
{
|
||||
vec a = linspace<vec>(1,5,5);
|
||||
vec b = linspace<vec>(1,5,6);
|
||||
@@ -33,7 +34,7 @@ TEST_CASE("fn_sum_1")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("sum2")
|
||||
TEST_CASE("fn_sum_2", "[sum]")
|
||||
{
|
||||
mat A =
|
||||
{
|
||||
@@ -57,7 +58,7 @@ TEST_CASE("sum2")
|
||||
}
|
||||
|
||||
|
||||
TEST_CASE("sum3")
|
||||
TEST_CASE("fn_sum_3", "[sum]")
|
||||
{
|
||||
mat AA =
|
||||
{
|
||||
@@ -87,9 +88,9 @@ TEST_CASE("sum3")
|
||||
}
|
||||
|
||||
|
||||
TEST_CASE("sum4")
|
||||
TEST_CASE("fn_sum_4", "[sum]")
|
||||
{
|
||||
mat X(100,101, fill::randu);
|
||||
mat X(100, 101, fill::randu);
|
||||
|
||||
REQUIRE( (sum(sum(X))/X.n_elem) == Approx(0.5).margin(0.02) );
|
||||
REQUIRE( (sum(sum(X(span::all,span::all)))/X.n_elem) == Approx(0.5).margin(0.02) );
|
||||
@@ -97,7 +98,7 @@ TEST_CASE("sum4")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("sum_spmat")
|
||||
TEST_CASE("fn_sum_spmat", "[sum]")
|
||||
{
|
||||
SpCol<double> a(5);
|
||||
a(0) = 3.0;
|
||||
@@ -156,3 +157,66 @@ TEST_CASE("sum_spmat")
|
||||
REQUIRE( (double) result(6, 0) == Approx(5.2) );
|
||||
REQUIRE( (double) result(7, 0) == Approx(4.6) );
|
||||
}
|
||||
|
||||
|
||||
|
||||
TEMPLATE_TEST_CASE("fn_sum_fp_ref", "[sum]", TEST_FLOAT_TYPES)
|
||||
{
|
||||
typedef TestType eT;
|
||||
|
||||
Mat<eT> X(5, 5, fill::randu);
|
||||
mat X_ref = conv_to<mat>::from(X);
|
||||
|
||||
Row<eT> res1 = sum(X, 0);
|
||||
Col<eT> res2 = sum(X, 1);
|
||||
eT res3 = sum(sum(X));
|
||||
|
||||
rowvec ref1 = sum(X_ref, 0);
|
||||
vec ref2 = sum(X_ref, 1);
|
||||
double ref3 = sum(sum(X_ref));
|
||||
|
||||
REQUIRE( res1.n_elem == ref1.n_elem );
|
||||
REQUIRE( res2.n_elem == ref2.n_elem );
|
||||
|
||||
constexpr eT margin = is_blas_real<eT>::value ? eT(0.001) : eT(0.1);
|
||||
|
||||
for (uword i = 0; i < res1.n_elem; ++i)
|
||||
{
|
||||
REQUIRE( res1[i] == Approx(eT(ref1[i])).margin(margin) );
|
||||
REQUIRE( res2[i] == Approx(eT(ref2[i])).margin(margin) );
|
||||
}
|
||||
|
||||
REQUIRE( res3 == Approx(eT(ref3)).margin(margin) );
|
||||
}
|
||||
|
||||
|
||||
|
||||
//TEMPLATE_TEST_CASE("fn_sum_sparse_fp_ref", "[sum]", TEST_FLOAT_TYPES)
|
||||
// {
|
||||
// typedef TestType eT;
|
||||
//
|
||||
// SpMat<eT> X;
|
||||
// X.sprandu(10, 10, 0.3);
|
||||
// sp_mat X_ref = conv_to<sp_mat>::from(X);
|
||||
//
|
||||
// SpRow<eT> res1 = sum(X, 0);
|
||||
// SpCol<eT> res2 = sum(X, 1);
|
||||
// eT res3 = sum(sum(X));
|
||||
//
|
||||
// sp_rowvec ref1 = sum(X_ref, 0);
|
||||
// sp_vec ref2 = sum(X_ref, 1);
|
||||
// double ref3 = sum(sum(X_ref));
|
||||
//
|
||||
// REQUIRE( res1.n_elem == ref1.n_elem );
|
||||
// REQUIRE( res2.n_elem == ref2.n_elem );
|
||||
//
|
||||
// constexpr eT margin = is_blas_real<eT>::value ? eT(0.001) : eT(0.1);
|
||||
//
|
||||
// for (uword i = 0; i < res1.n_elem; ++i)
|
||||
// {
|
||||
// REQUIRE( res1[i] == Approx(eT(double(ref1[i]))).margin(margin) );
|
||||
// REQUIRE( res2[i] == Approx(eT(double(ref2[i]))).margin(margin) );
|
||||
// }
|
||||
//
|
||||
// REQUIRE( res3 == Approx(eT(ref3)).margin(margin) );
|
||||
// }
|
||||
|
||||
+88
-2
@@ -18,11 +18,12 @@
|
||||
|
||||
#include <armadillo>
|
||||
#include "catch.hpp"
|
||||
#include "utils.hpp"
|
||||
|
||||
using namespace arma;
|
||||
|
||||
|
||||
TEST_CASE("fn_symmat_1")
|
||||
TEST_CASE("fn_symmat_1", "[symmat]")
|
||||
{
|
||||
mat A =
|
||||
"\
|
||||
@@ -63,7 +64,7 @@ TEST_CASE("fn_symmat_1")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("fn_symmat_2")
|
||||
TEST_CASE("fn_symmat_2", "[symmat]")
|
||||
{
|
||||
mat A =
|
||||
"\
|
||||
@@ -125,3 +126,88 @@ TEST_CASE("fn_symmat_2")
|
||||
}
|
||||
|
||||
|
||||
|
||||
TEMPLATE_TEST_CASE("fn_symmat_fp", "[symmat]", TEST_FLOAT_TYPES)
|
||||
{
|
||||
typedef TestType eT;
|
||||
|
||||
Mat<eT> X(10, 10, fill::randn);
|
||||
|
||||
Mat<eT> XU = symmatu(X);
|
||||
Mat<eT> XL = symmatl(X);
|
||||
|
||||
REQUIRE( XU.n_rows == X.n_rows );
|
||||
REQUIRE( XU.n_cols == X.n_cols );
|
||||
REQUIRE( XL.n_rows == X.n_rows );
|
||||
REQUIRE( XL.n_cols == X.n_cols );
|
||||
|
||||
constexpr const eT tol = is_blas_real<eT>::value ? eT(0.0001) : eT(0.01);
|
||||
|
||||
for (uword c = 0; c < X.n_cols; ++c)
|
||||
{
|
||||
for (uword r = 0; r < X.n_rows; ++r)
|
||||
{
|
||||
if (r > c)
|
||||
{
|
||||
REQUIRE( XU(r, c) == Approx(X(c, r)).epsilon(tol) );
|
||||
}
|
||||
else
|
||||
{
|
||||
REQUIRE( XU(r, c) == Approx(X(r, c)).epsilon(tol) );
|
||||
}
|
||||
|
||||
if (c > r)
|
||||
{
|
||||
REQUIRE( XL(r, c) == Approx(X(c, r)).epsilon(tol) );
|
||||
}
|
||||
else
|
||||
{
|
||||
REQUIRE( XL(r, c) == Approx(X(r, c)).epsilon(tol) );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//TEMPLATE_TEST_CASE("fn_symmat_sparse_fp", "[symmat]", TEST_FLOAT_TYPES)
|
||||
// {
|
||||
// typedef TestType eT;
|
||||
//
|
||||
// SpMat<eT> X;
|
||||
// X.sprandn(20, 20, 0.3);
|
||||
//
|
||||
// SpMat<eT> XU = symmatu(X);
|
||||
// SpMat<eT> XL = symmatl(X);
|
||||
//
|
||||
// REQUIRE( XU.n_rows == X.n_rows );
|
||||
// REQUIRE( XU.n_cols == X.n_cols );
|
||||
// REQUIRE( XL.n_rows == X.n_rows );
|
||||
// REQUIRE( XL.n_cols == X.n_cols );
|
||||
//
|
||||
// constexpr const eT tol = is_blas_real<eT>::value ? eT(0.0001) : eT(0.01);
|
||||
//
|
||||
// for (uword c = 0; c < X.n_cols; ++c)
|
||||
// {
|
||||
// for (uword r = 0; r < X.n_rows; ++r)
|
||||
// {
|
||||
// if (r > c)
|
||||
// {
|
||||
// REQUIRE( XU(r, c) == Approx(X(c, r)).epsilon(tol) );
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// REQUIRE( XU(r, c) == Approx(X(r, c)).epsilon(tol) );
|
||||
// }
|
||||
//
|
||||
// if (c > r)
|
||||
// {
|
||||
// REQUIRE( XL(r, c) == Approx(X(c, r)).epsilon(tol) );
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// REQUIRE( XL(r, c) == Approx(X(r, c)).epsilon(tol) );
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
+38
-4
@@ -18,11 +18,12 @@
|
||||
|
||||
#include <armadillo>
|
||||
#include "catch.hpp"
|
||||
#include "utils.hpp"
|
||||
|
||||
using namespace arma;
|
||||
|
||||
|
||||
TEST_CASE("fn_trace_1")
|
||||
TEST_CASE("fn_trace_1", "[trace]")
|
||||
{
|
||||
mat A =
|
||||
"\
|
||||
@@ -46,7 +47,7 @@ TEST_CASE("fn_trace_1")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("fn_trace_spmat")
|
||||
TEST_CASE("fn_trace_spmat", "[trace]")
|
||||
{
|
||||
SpMat<double> a(6, 6);
|
||||
a(0, 0) = 3.0;
|
||||
@@ -67,7 +68,7 @@ TEST_CASE("fn_trace_spmat")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("fn_trace_spmat_mul")
|
||||
TEST_CASE("fn_trace_spmat_mul", "[trace]")
|
||||
{
|
||||
// Test trace(SpMat * SpMat) and ensure the result is the same as if we
|
||||
// pre-multiplied the matrices.
|
||||
@@ -86,7 +87,7 @@ TEST_CASE("fn_trace_spmat_mul")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("fn_trace_spmat_t_mul")
|
||||
TEST_CASE("fn_trace_spmat_t_mul", "[trace]")
|
||||
{
|
||||
// Test trace(SpMat.t() * SpMat) and ensure the result is the same as if we
|
||||
// pre-multiplied the matrices.
|
||||
@@ -102,3 +103,36 @@ TEST_CASE("fn_trace_spmat_t_mul")
|
||||
|
||||
REQUIRE( trc == Approx(trab) );
|
||||
}
|
||||
|
||||
|
||||
|
||||
TEMPLATE_TEST_CASE("fn_trace_fp", "[trace]", TEST_FLOAT_TYPES)
|
||||
{
|
||||
typedef TestType eT;
|
||||
|
||||
Mat<eT> X(20, 20, fill::randu);
|
||||
|
||||
const eT tr = trace(X);
|
||||
const eT tr_ref = accu(X.diag());
|
||||
|
||||
constexpr const eT tol = is_blas_real<eT>::value ? eT(0.001) : eT(0.02);
|
||||
|
||||
REQUIRE( tr == Approx(tr_ref).epsilon(tol) );
|
||||
}
|
||||
|
||||
|
||||
|
||||
//TEMPLATE_TEST_CASE("fn_trace_sparse_fp", "[trace]", TEST_FLOAT_TYPES)
|
||||
// {
|
||||
// typedef TestType eT;
|
||||
//
|
||||
// SpMat<eT> X;
|
||||
// X.sprandu(50, 50, 0.3);
|
||||
//
|
||||
// const eT tr = trace(X);
|
||||
// const eT tr_ref = accu(X.diag());
|
||||
//
|
||||
// constexpr const eT tol = is_blas_real<eT>::value ? eT(0.001) : eT(0.02);
|
||||
//
|
||||
// REQUIRE( tr == Approx(tr_ref).epsilon(tol) );
|
||||
// }
|
||||
|
||||
+89
-6
@@ -18,11 +18,12 @@
|
||||
|
||||
#include <armadillo>
|
||||
#include "catch.hpp"
|
||||
#include "utils.hpp"
|
||||
|
||||
using namespace arma;
|
||||
|
||||
|
||||
TEST_CASE("fn_trans_1")
|
||||
TEST_CASE("fn_trans_1", "[trans]")
|
||||
{
|
||||
mat A =
|
||||
"\
|
||||
@@ -166,7 +167,7 @@ TEST_CASE("fn_trans_1")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("fn_trans_2")
|
||||
TEST_CASE("fn_trans_2", "[trans]")
|
||||
{
|
||||
mat A =
|
||||
"\
|
||||
@@ -297,7 +298,7 @@ TEST_CASE("fn_trans_2")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("fn_trans_3")
|
||||
TEST_CASE("fn_trans_3", "[trans]")
|
||||
{
|
||||
mat A =
|
||||
"\
|
||||
@@ -370,7 +371,7 @@ TEST_CASE("fn_trans_3")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("fn_trans_4")
|
||||
TEST_CASE("fn_trans_4", "[trans]")
|
||||
{
|
||||
mat A =
|
||||
"\
|
||||
@@ -491,7 +492,7 @@ TEST_CASE("fn_trans_4")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("op_trans_sp_mat")
|
||||
TEST_CASE("op_trans_sp_mat", "[trans]")
|
||||
{
|
||||
SpMat<unsigned int> a(4, 4);
|
||||
a(1, 0) = 5;
|
||||
@@ -578,7 +579,7 @@ TEST_CASE("op_trans_sp_mat")
|
||||
}
|
||||
|
||||
|
||||
TEST_CASE("op_trans_sp_cxmat")
|
||||
TEST_CASE("op_trans_sp_cxmat", "[trans]")
|
||||
{
|
||||
SpMat<cx_double> a(10, 10);
|
||||
for (uword c = 0; c < 7; ++c)
|
||||
@@ -624,3 +625,85 @@ TEST_CASE("op_trans_sp_cxmat")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
TEMPLATE_TEST_CASE("fn_trans_fp", "[trans]", TEST_FLOAT_TYPES)
|
||||
{
|
||||
typedef TestType eT;
|
||||
|
||||
Mat<eT> X(10, 10, fill::randu);
|
||||
Mat<eT> Y = trans(X);
|
||||
|
||||
constexpr eT tol = is_blas_real<eT>::value ? eT(0.0001) : eT(0.01);
|
||||
|
||||
REQUIRE( Y.n_rows == X.n_rows );
|
||||
REQUIRE( Y.n_cols == X.n_cols );
|
||||
|
||||
for (uword c = 0; c < Y.n_cols; ++c)
|
||||
{
|
||||
for (uword r = 0; r < Y.n_rows; ++r)
|
||||
{
|
||||
REQUIRE( Y(r, c) == Approx(X(c, r)).epsilon(tol) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//TEMPLATE_TEST_CASE("fn_trans_sparse_fp", "[trans]", TEST_FLOAT_TYPES)
|
||||
// {
|
||||
// typedef TestType eT;
|
||||
//
|
||||
// SpMat<eT> X;
|
||||
// X.sprandu(25, 25, 0.3);
|
||||
// SpMat<eT> Y = trans(X);
|
||||
//
|
||||
// constexpr eT tol = is_blas_real<eT>::value ? eT(0.0001) : eT(0.01);
|
||||
//
|
||||
// REQUIRE( Y.n_rows == X.n_rows );
|
||||
// REQUIRE( Y.n_cols == X.n_cols );
|
||||
//
|
||||
// for (uword c = 0; c < Y.n_cols; ++c)
|
||||
// {
|
||||
// for (uword r = 0; r < Y.n_rows; ++r)
|
||||
// {
|
||||
// REQUIRE( Y(r, c) == Approx(X(c, r)).epsilon(tol) );
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
|
||||
TEMPLATE_TEST_CASE("fn_trans_cx_fp", "[trans]", TEST_CX_FLOAT_TYPES)
|
||||
{
|
||||
typedef TestType eT;
|
||||
|
||||
Mat<eT> X(10, 10, fill::randu);
|
||||
Mat<eT> Y1 = trans(X);
|
||||
Mat<eT> Y2 = htrans(X);
|
||||
Mat<eT> Y3 = strans(X);
|
||||
|
||||
typedef typename get_pod_type<eT>::result gT;
|
||||
constexpr gT tol = is_blas_real<gT>::value ? gT(0.0001) : gT(0.01);
|
||||
|
||||
REQUIRE( Y1.n_rows == X.n_rows );
|
||||
REQUIRE( Y1.n_cols == X.n_cols );
|
||||
REQUIRE( Y2.n_rows == X.n_rows );
|
||||
REQUIRE( Y2.n_cols == X.n_cols );
|
||||
REQUIRE( Y3.n_rows == X.n_rows );
|
||||
REQUIRE( Y3.n_cols == X.n_cols );
|
||||
|
||||
for (uword c = 0; c < Y1.n_cols; ++c)
|
||||
{
|
||||
for (uword r = 0; r < Y1.n_rows; ++r)
|
||||
{
|
||||
REQUIRE( std::real(Y1(r, c)) == Approx( std::real(X(c, r))).epsilon(tol) );
|
||||
REQUIRE( std::imag(Y1(r, c)) == Approx(-std::imag(X(c, r))).epsilon(tol) );
|
||||
REQUIRE( std::real(Y2(r, c)) == Approx( std::real(X(c, r))).epsilon(tol) );
|
||||
REQUIRE( std::imag(Y2(r, c)) == Approx(-std::imag(X(c, r))).epsilon(tol) );
|
||||
REQUIRE( std::real(Y3(r, c)) == Approx( std::real(X(c, r))).epsilon(tol) );
|
||||
REQUIRE( std::imag(Y3(r, c)) == Approx( std::imag(X(c, r))).epsilon(tol) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+41
-5
@@ -18,10 +18,11 @@
|
||||
#include <armadillo>
|
||||
|
||||
#include "catch.hpp"
|
||||
#include "utils.hpp"
|
||||
|
||||
using namespace arma;
|
||||
|
||||
TEST_CASE("fn_var_empty_sparse_test")
|
||||
TEST_CASE("fn_var_empty_sparse_test", "[var]")
|
||||
{
|
||||
SpMat<double> m(100, 100);
|
||||
|
||||
@@ -82,7 +83,7 @@ TEST_CASE("fn_var_empty_sparse_test")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("fn_var_empty_cx_sparse_test")
|
||||
TEST_CASE("fn_var_empty_cx_sparse_test", "[var]")
|
||||
{
|
||||
SpMat<std::complex<double> > m(100, 100);
|
||||
|
||||
@@ -143,7 +144,7 @@ TEST_CASE("fn_var_empty_cx_sparse_test")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("fn_var_sparse_test")
|
||||
TEST_CASE("fn_var_sparse_test", "[var]")
|
||||
{
|
||||
// Create a random matrix and do variance testing on it, with varying levels
|
||||
// of nonzero (eventually this becomes a fully dense matrix).
|
||||
@@ -333,7 +334,7 @@ TEST_CASE("fn_var_sparse_test")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("fn_var_sparse_cx_test")
|
||||
TEST_CASE("fn_var_sparse_cx_test", "[var]")
|
||||
{
|
||||
// Create a random matrix and do variance testing on it, with varying levels
|
||||
// of nonzero (eventually this becomes a fully dense matrix).
|
||||
@@ -523,7 +524,7 @@ TEST_CASE("fn_var_sparse_cx_test")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("fn_var_sparse_alias_test")
|
||||
TEST_CASE("fn_var_sparse_alias_test", "[var]")
|
||||
{
|
||||
sp_mat s;
|
||||
s.sprandu(70, 70, 0.3);
|
||||
@@ -549,3 +550,38 @@ TEST_CASE("fn_var_sparse_alias_test")
|
||||
REQUIRE( d[i] == Approx((double) s[i]) );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
TEMPLATE_TEST_CASE("fn_var_fp_reference", "[var]", TEST_FLOAT_TYPES)
|
||||
{
|
||||
typedef TestType eT;
|
||||
|
||||
Col<eT> X(10, fill::randn);
|
||||
vec X_ref = conv_to<vec>::from(X);
|
||||
|
||||
const eT var_val = var(X);
|
||||
const double var_ref = var(X_ref);
|
||||
|
||||
const eT margin = is_blas_real<eT>::value ? eT(0.001) : eT(0.02);
|
||||
|
||||
REQUIRE( var_val == Approx(eT(var_ref)).margin(margin) );
|
||||
}
|
||||
|
||||
|
||||
|
||||
//TEMPLATE_TEST_CASE("fn_var_sp_fp_reference", "[var]", TEST_FLOAT_TYPES)
|
||||
// {
|
||||
// typedef TestType eT;
|
||||
//
|
||||
// SpCol<eT> X;
|
||||
// X.sprandu(100, 1, 0.3);
|
||||
// sp_vec X_ref = conv_to<sp_mat>::from(X);
|
||||
//
|
||||
// const eT var_val = var(X);
|
||||
// const double var_ref = var(X_ref);
|
||||
//
|
||||
// const eT margin = is_blas_real<eT>::value ? eT(0.001) : eT(0.02);
|
||||
//
|
||||
// REQUIRE( var_val == Approx(eT(var_ref)).margin(margin) );
|
||||
// }
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
using namespace arma;
|
||||
|
||||
|
||||
TEST_CASE("fn_vectorise_1")
|
||||
TEST_CASE("fn_vectorise_1", "[vectorise]")
|
||||
{
|
||||
mat A =
|
||||
"\
|
||||
|
||||
+27
-25
@@ -18,43 +18,45 @@
|
||||
|
||||
#include <armadillo>
|
||||
#include "catch.hpp"
|
||||
#include "utils.hpp"
|
||||
|
||||
using namespace arma;
|
||||
|
||||
|
||||
TEST_CASE("gen_linspace_1")
|
||||
TEMPLATE_TEST_CASE("gen_linspace_1", "[linspace]", TEST_FLOAT_TYPES)
|
||||
{
|
||||
vec a = linspace(1,5,5);
|
||||
typedef TestType eT;
|
||||
|
||||
Col<eT> a = linspace<Col<eT>>(1,5,5);
|
||||
|
||||
constexpr eT margin = is_blas_real<eT>::value ? eT(0.0001) : eT(0.05);
|
||||
|
||||
REQUIRE(a(0) == Approx(1.0));
|
||||
REQUIRE(a(1) == Approx(2.0));
|
||||
REQUIRE(a(2) == Approx(3.0));
|
||||
REQUIRE(a(3) == Approx(4.0));
|
||||
REQUIRE(a(4) == Approx(5.0));
|
||||
REQUIRE(a(0) == Approx(1.0).margin(margin));
|
||||
REQUIRE(a(1) == Approx(2.0).margin(margin));
|
||||
REQUIRE(a(2) == Approx(3.0).margin(margin));
|
||||
REQUIRE(a(3) == Approx(4.0).margin(margin));
|
||||
REQUIRE(a(4) == Approx(5.0).margin(margin));
|
||||
|
||||
vec b = linspace<vec>(1,5,6);
|
||||
Col<eT> b = linspace<Col<eT>>(1,5,6);
|
||||
|
||||
REQUIRE(b(0) == Approx(1.0));
|
||||
REQUIRE(b(1) == Approx(1.8));
|
||||
REQUIRE(b(2) == Approx(2.6));
|
||||
REQUIRE(b(3) == Approx(3.4));
|
||||
REQUIRE(b(4) == Approx(4.2));
|
||||
REQUIRE(b(5) == Approx(5.0));
|
||||
REQUIRE(b(0) == Approx(1.0).margin(margin));
|
||||
REQUIRE(b(1) == Approx(1.8).margin(margin));
|
||||
REQUIRE(b(2) == Approx(2.6).margin(margin));
|
||||
REQUIRE(b(3) == Approx(3.4).margin(margin));
|
||||
REQUIRE(b(4) == Approx(4.2).margin(margin));
|
||||
REQUIRE(b(5) == Approx(5.0).margin(margin));
|
||||
|
||||
rowvec c = linspace<rowvec>(1,5,6);
|
||||
Row<eT> c = linspace<Row<eT>>(1,5,6);
|
||||
|
||||
REQUIRE(c(0) == Approx(1.0));
|
||||
REQUIRE(c(1) == Approx(1.8));
|
||||
REQUIRE(c(2) == Approx(2.6));
|
||||
REQUIRE(c(3) == Approx(3.4));
|
||||
REQUIRE(c(4) == Approx(4.2));
|
||||
REQUIRE(c(5) == Approx(5.0));
|
||||
REQUIRE(c(0) == Approx(1.0).margin(margin));
|
||||
REQUIRE(c(1) == Approx(1.8).margin(margin));
|
||||
REQUIRE(c(2) == Approx(2.6).margin(margin));
|
||||
REQUIRE(c(3) == Approx(3.4).margin(margin));
|
||||
REQUIRE(c(4) == Approx(4.2).margin(margin));
|
||||
REQUIRE(c(5) == Approx(5.0).margin(margin));
|
||||
|
||||
mat X = linspace<mat>(1,5,6);
|
||||
Mat<eT> X = linspace<Mat<eT>>(1,5,6);
|
||||
|
||||
REQUIRE(X.n_rows == 6);
|
||||
REQUIRE(X.n_cols == 1);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
+43
-36
@@ -18,100 +18,107 @@
|
||||
|
||||
#include <armadillo>
|
||||
#include "catch.hpp"
|
||||
#include "utils.hpp"
|
||||
|
||||
using namespace arma;
|
||||
|
||||
|
||||
TEST_CASE("gen_ones_1")
|
||||
TEMPLATE_TEST_CASE("gen_ones_1", "[ones]", TEST_FLOAT_TYPES)
|
||||
{
|
||||
mat A(5,6,fill::ones);
|
||||
typedef TestType eT;
|
||||
|
||||
Mat<eT> A(5,6,fill::ones);
|
||||
|
||||
REQUIRE( accu(A) == Approx(double(5*6)) );
|
||||
REQUIRE( double(accu(A)) == Approx(double(5*6)) );
|
||||
REQUIRE( A.n_rows == 5 );
|
||||
REQUIRE( A.n_cols == 6 );
|
||||
|
||||
mat B(5,6,fill::randu);
|
||||
Mat<eT> B(5,6,fill::randu);
|
||||
|
||||
B.ones();
|
||||
|
||||
REQUIRE( accu(B) == Approx(double(5*6)) );
|
||||
REQUIRE( double(accu(B)) == Approx(double(5*6)) );
|
||||
REQUIRE( B.n_rows == 5 );
|
||||
REQUIRE( B.n_cols == 6 );
|
||||
|
||||
mat C = ones<mat>(5,6);
|
||||
Mat<eT> C = ones<Mat<eT>>(5,6);
|
||||
|
||||
REQUIRE( accu(C) == Approx(double(5*6)) );
|
||||
REQUIRE( double(accu(C)) == Approx(double(5*6)) );
|
||||
REQUIRE( C.n_rows == 5 );
|
||||
REQUIRE( C.n_cols == 6 );
|
||||
|
||||
mat D; D = ones<mat>(5,6);
|
||||
Mat<eT> D; D = ones<Mat<eT>>(5,6);
|
||||
|
||||
REQUIRE( accu(D) == Approx(double(5*6)) );
|
||||
REQUIRE( double(accu(D)) == Approx(double(5*6)) );
|
||||
REQUIRE( D.n_rows == 5 );
|
||||
REQUIRE( D.n_cols == 6 );
|
||||
|
||||
mat E; E = 2*ones<mat>(5,6);
|
||||
Mat<eT> E; E = 2*ones<Mat<eT>>(5,6);
|
||||
|
||||
REQUIRE( accu(E) == Approx(double(2*5*6)) );
|
||||
REQUIRE( double(accu(E)) == Approx(double(2*5*6)) );
|
||||
REQUIRE( E.n_rows == 5 );
|
||||
REQUIRE( E.n_cols == 6 );
|
||||
}
|
||||
|
||||
|
||||
|
||||
TEST_CASE("gen_ones_2")
|
||||
TEMPLATE_TEST_CASE("gen_ones_2", "[ones]", TEST_FLOAT_TYPES)
|
||||
{
|
||||
mat A(5,6,fill::zeros);
|
||||
typedef TestType eT;
|
||||
|
||||
Mat<eT> A(5,6,fill::zeros);
|
||||
|
||||
A.col(1).ones();
|
||||
|
||||
REQUIRE( accu(A.col(0)) == Approx(0.0).margin(0.001) );
|
||||
REQUIRE( accu(A.col(1)) == Approx(double(A.n_rows)) );
|
||||
REQUIRE( accu(A.col(2)) == Approx(0.0).margin(0.001) );
|
||||
REQUIRE( double(accu(A.col(0))) == Approx(0.0).margin(0.001) );
|
||||
REQUIRE( double(accu(A.col(1))) == Approx(double(A.n_rows)) );
|
||||
REQUIRE( double(accu(A.col(2))) == Approx(0.0).margin(0.001) );
|
||||
|
||||
mat B(5,6,fill::zeros);
|
||||
Mat<eT> B(5,6,fill::zeros);
|
||||
|
||||
B.row(1).ones();
|
||||
|
||||
REQUIRE( accu(B.row(0)) == Approx(0.0).margin(0.001) );
|
||||
REQUIRE( accu(B.row(1)) == Approx(double(B.n_cols)) );
|
||||
REQUIRE( accu(B.row(2)) == Approx(0.0).margin(0.001) );
|
||||
REQUIRE( double(accu(B.row(0))) == Approx(0.0).margin(0.001) );
|
||||
REQUIRE( double(accu(B.row(1))) == Approx(double(B.n_cols)) );
|
||||
REQUIRE( double(accu(B.row(2))) == Approx(0.0).margin(0.001) );
|
||||
|
||||
mat C(5,6,fill::zeros);
|
||||
Mat<eT> C(5,6,fill::zeros);
|
||||
|
||||
C(span(1,3),span(1,4)).ones();
|
||||
|
||||
REQUIRE( accu(C.head_cols(1)) == Approx(0.0).margin(0.001) );
|
||||
REQUIRE( accu(C.head_rows(1)) == Approx(0.0).margin(0.001) );
|
||||
REQUIRE( double(accu(C.head_cols(1))) == Approx(0.0).margin(0.001) );
|
||||
REQUIRE( double(accu(C.head_rows(1))) == Approx(0.0).margin(0.001) );
|
||||
|
||||
REQUIRE( accu(C.tail_cols(1)) == Approx(0.0).margin(0.001) );
|
||||
REQUIRE( accu(C.tail_rows(1)) == Approx(0.0).margin(0.001) );
|
||||
REQUIRE( double(accu(C.tail_cols(1))) == Approx(0.0).margin(0.001) );
|
||||
REQUIRE( double(accu(C.tail_rows(1))) == Approx(0.0).margin(0.001) );
|
||||
|
||||
REQUIRE( accu(C(span(1,3),span(1,4))) == Approx(double(3*4)) );
|
||||
REQUIRE( double(accu(C(span(1,3),span(1,4)))) == Approx(double(3*4)) );
|
||||
|
||||
mat D(5,6,fill::zeros);
|
||||
Mat<eT> D(5,6,fill::zeros);
|
||||
|
||||
D.diag().ones();
|
||||
|
||||
REQUIRE( accu(D.diag()) == Approx(double(5)) );
|
||||
REQUIRE( double(accu(D.diag())) == Approx(double(5)) );
|
||||
}
|
||||
|
||||
|
||||
|
||||
TEST_CASE("gen_ones_3")
|
||||
TEMPLATE_TEST_CASE("gen_ones_3", "[ones]", TEST_FLOAT_TYPES)
|
||||
{
|
||||
mat A(5,6,fill::zeros);
|
||||
typedef TestType eT;
|
||||
|
||||
Mat<eT> A(5,6,fill::zeros);
|
||||
|
||||
uvec indices = { 2, 4, 6 };
|
||||
|
||||
A(indices).ones();
|
||||
|
||||
REQUIRE( accu(A) == Approx(double(3)) );
|
||||
REQUIRE( double(accu(A)) == Approx(double(3)) );
|
||||
|
||||
REQUIRE( A(0) == Approx(0.0).margin(0.001) );
|
||||
REQUIRE( A(A.n_elem-1) == Approx(0.0).margin(0.001) );
|
||||
REQUIRE( A(0) == Approx(eT(0)).margin(0.001) );
|
||||
REQUIRE( A(A.n_elem-1) == Approx(eT(0)).margin(0.001) );
|
||||
|
||||
REQUIRE( A(indices(0)) == Approx(1.0) );
|
||||
REQUIRE( A(indices(1)) == Approx(1.0) );
|
||||
REQUIRE( A(indices(2)) == Approx(1.0) );
|
||||
REQUIRE( A(indices(0)) == Approx(eT(1)) );
|
||||
REQUIRE( A(indices(1)) == Approx(eT(1)) );
|
||||
REQUIRE( A(indices(2)) == Approx(eT(1)) );
|
||||
}
|
||||
|
||||
+30
-16
@@ -18,42 +18,56 @@
|
||||
|
||||
#include <armadillo>
|
||||
#include "catch.hpp"
|
||||
#include "utils.hpp"
|
||||
|
||||
using namespace arma;
|
||||
|
||||
|
||||
TEST_CASE("gen_randu_1")
|
||||
TEMPLATE_TEST_CASE("gen_randu_1", "[randu]", TEST_FLOAT_TYPES)
|
||||
{
|
||||
typedef TestType eT;
|
||||
|
||||
const uword n_rows = 100;
|
||||
const uword n_cols = 101;
|
||||
|
||||
mat A(n_rows,n_cols, fill::randu);
|
||||
Mat<eT> A(n_rows,n_cols, fill::randu);
|
||||
|
||||
mat B(n_rows,n_cols); B.randu();
|
||||
Mat<eT> B(n_rows,n_cols); B.randu();
|
||||
|
||||
mat C; C.randu(n_rows,n_cols);
|
||||
Mat<eT> C; C.randu(n_rows,n_cols);
|
||||
|
||||
REQUIRE( (accu(A)/A.n_elem) == Approx(0.5).margin(0.02) );
|
||||
REQUIRE( (accu(B)/A.n_elem) == Approx(0.5).margin(0.02) );
|
||||
REQUIRE( (accu(C)/A.n_elem) == Approx(0.5).margin(0.02) );
|
||||
constexpr const double margin1 = is_blas_real<eT>::value ? 0.02 : 0.2;
|
||||
constexpr const double margin2 = is_blas_real<eT>::value ? 0.025 : 0.3;
|
||||
|
||||
REQUIRE( (mean(vectorise(A))) == Approx(0.5).margin(0.025) );
|
||||
// low-precision types could underflow, so convert to doubles before computing the mean
|
||||
|
||||
REQUIRE( (accu(conv_to<mat>::from(A))/A.n_elem) == Approx(0.5).margin(margin1) );
|
||||
REQUIRE( (accu(conv_to<mat>::from(B))/A.n_elem) == Approx(0.5).margin(margin1) );
|
||||
REQUIRE( (accu(conv_to<mat>::from(C))/A.n_elem) == Approx(0.5).margin(margin1) );
|
||||
|
||||
REQUIRE( (mean(vectorise(conv_to<mat>::from(A)))) == Approx(eT(0.5)).margin(margin2) );
|
||||
}
|
||||
|
||||
|
||||
|
||||
TEST_CASE("gen_randu_2")
|
||||
TEMPLATE_TEST_CASE("gen_randu_2", "[randu]", TEST_FLOAT_TYPES)
|
||||
{
|
||||
mat A(50,60,fill::zeros);
|
||||
typedef TestType eT;
|
||||
|
||||
Mat<eT> A(50,60,fill::zeros);
|
||||
|
||||
A(span(1,48),span(1,58)).randu();
|
||||
|
||||
REQUIRE( accu(A.head_cols(1)) == Approx(0.0).margin(0.001) );
|
||||
REQUIRE( accu(A.head_rows(1)) == Approx(0.0).margin(0.001) );
|
||||
constexpr const eT margin1 = is_blas_real<eT>::value ? eT(0.001) : eT(0.01 );
|
||||
constexpr const double margin2 = is_blas_real<eT>::value ? eT(0.025) : eT(0.025);
|
||||
|
||||
REQUIRE( accu(A.tail_cols(1)) == Approx(0.0).margin(0.001) );
|
||||
REQUIRE( accu(A.tail_rows(1)) == Approx(0.0).margin(0.001) );
|
||||
REQUIRE( accu(A.head_cols(1)) == Approx(eT(0)).margin(margin1) );
|
||||
REQUIRE( accu(A.head_rows(1)) == Approx(eT(0)).margin(margin1) );
|
||||
|
||||
REQUIRE( mean(vectorise(A(span(1,48),span(1,58)))) == Approx(double(0.5)).margin(0.025) );
|
||||
REQUIRE( accu(A.tail_cols(1)) == Approx(eT(0)).margin(margin1) );
|
||||
REQUIRE( accu(A.tail_rows(1)) == Approx(eT(0)).margin(margin1) );
|
||||
|
||||
// low-precision types could overflow
|
||||
|
||||
REQUIRE( mean(vectorise(conv_to<mat>::from(A)(span(1,48),span(1,58)))) == Approx(0.5).margin(margin2) );
|
||||
}
|
||||
|
||||
|
||||
+50
-37
@@ -18,107 +18,120 @@
|
||||
|
||||
#include <armadillo>
|
||||
#include "catch.hpp"
|
||||
#include "utils.hpp"
|
||||
|
||||
using namespace arma;
|
||||
|
||||
|
||||
TEST_CASE("gen_zeros_1")
|
||||
TEMPLATE_TEST_CASE("gen_zeros_1", "[zeros]", TEST_FLOAT_TYPES)
|
||||
{
|
||||
mat A(5,6,fill::zeros);
|
||||
typedef TestType eT;
|
||||
|
||||
REQUIRE( accu(A) == Approx(0.0).margin(0.001) );
|
||||
constexpr const eT margin = is_blas_real<eT>::value ? eT(0.001) : eT(0.01);
|
||||
|
||||
Mat<eT> A(5,6,fill::zeros);
|
||||
|
||||
REQUIRE( accu(A) == Approx(eT(0)).margin(margin) );
|
||||
REQUIRE( A.n_rows == 5 );
|
||||
REQUIRE( A.n_cols == 6 );
|
||||
|
||||
mat B(5,6,fill::randu);
|
||||
Mat<eT> B(5,6,fill::randu);
|
||||
|
||||
B.zeros();
|
||||
|
||||
REQUIRE( accu(B) == Approx(0.0).margin(0.001) );
|
||||
REQUIRE( accu(B) == Approx(eT(0)).margin(margin) );
|
||||
REQUIRE( B.n_rows == 5 );
|
||||
REQUIRE( B.n_cols == 6 );
|
||||
|
||||
mat C = zeros<mat>(5,6);
|
||||
Mat<eT> C = zeros<Mat<eT>>(5,6);
|
||||
|
||||
REQUIRE( accu(C) == Approx(0.0).margin(0.001) );
|
||||
REQUIRE( accu(C) == Approx(eT(0)).margin(margin) );
|
||||
REQUIRE( C.n_rows == 5 );
|
||||
REQUIRE( C.n_cols == 6 );
|
||||
|
||||
mat D; D = zeros<mat>(5,6);
|
||||
Mat<eT> D; D = zeros<Mat<eT>>(5,6);
|
||||
|
||||
REQUIRE( accu(D) == Approx(0.0).margin(0.001) );
|
||||
REQUIRE( accu(D) == Approx(eT(0)).margin(margin) );
|
||||
REQUIRE( D.n_rows == 5 );
|
||||
REQUIRE( D.n_cols == 6 );
|
||||
|
||||
mat E; E = 2*zeros<mat>(5,6);
|
||||
Mat<eT> E; E = 2*zeros<Mat<eT>>(5,6);
|
||||
|
||||
REQUIRE( accu(E) == Approx(0.0).margin(0.001) );
|
||||
REQUIRE( accu(E) == Approx(eT(0)).margin(margin) );
|
||||
REQUIRE( E.n_rows == 5 );
|
||||
REQUIRE( E.n_cols == 6 );
|
||||
}
|
||||
|
||||
|
||||
|
||||
TEST_CASE("gen_zeros_2")
|
||||
TEMPLATE_TEST_CASE("gen_zeros_2", "[zeros]", TEST_FLOAT_TYPES)
|
||||
{
|
||||
mat A(5,6,fill::ones);
|
||||
typedef TestType eT;
|
||||
|
||||
Mat<eT> A(5,6,fill::ones);
|
||||
|
||||
A.col(1).zeros();
|
||||
|
||||
REQUIRE( accu(A.col(0)) == Approx(double(A.n_rows)) );
|
||||
REQUIRE( accu(A.col(1)) == Approx(0.0).margin(0.001) );
|
||||
REQUIRE( accu(A.col(2)) == Approx(double(A.n_rows)) );
|
||||
constexpr const eT margin = is_blas_real<eT>::value ? eT(0.001) : eT(0.01);
|
||||
|
||||
mat B(5,6,fill::ones);
|
||||
REQUIRE( accu(A.col(0)) == Approx(eT(A.n_rows)) );
|
||||
REQUIRE( accu(A.col(1)) == Approx(eT(0)).margin(margin) );
|
||||
REQUIRE( accu(A.col(2)) == Approx(eT(A.n_rows)) );
|
||||
|
||||
Mat<eT> B(5,6,fill::ones);
|
||||
|
||||
B.row(1).zeros();
|
||||
|
||||
REQUIRE( accu(B.row(0)) == Approx(double(B.n_cols)) );
|
||||
REQUIRE( accu(B.row(1)) == Approx(0.0).margin(0.001) );
|
||||
REQUIRE( accu(B.row(2)) == Approx(double(B.n_cols)) );
|
||||
REQUIRE( accu(B.row(0)) == Approx(eT(B.n_cols)) );
|
||||
REQUIRE( accu(B.row(1)) == Approx(eT(0)).margin(margin) );
|
||||
REQUIRE( accu(B.row(2)) == Approx(eT(B.n_cols)) );
|
||||
|
||||
mat C(5,6,fill::ones);
|
||||
Mat<eT> C(5,6,fill::ones);
|
||||
|
||||
C(span(1,3),span(1,4)).zeros();
|
||||
|
||||
REQUIRE( accu(C.head_cols(1)) == Approx(double(5)) );
|
||||
REQUIRE( accu(C.head_rows(1)) == Approx(double(6)) );
|
||||
REQUIRE( accu(C.head_cols(1)) == Approx(eT(5)) );
|
||||
REQUIRE( accu(C.head_rows(1)) == Approx(eT(6)) );
|
||||
|
||||
REQUIRE( accu(C.tail_cols(1)) == Approx(double(5)) );
|
||||
REQUIRE( accu(C.tail_rows(1)) == Approx(double(6)) );
|
||||
REQUIRE( accu(C.tail_cols(1)) == Approx(eT(5)) );
|
||||
REQUIRE( accu(C.tail_rows(1)) == Approx(eT(6)) );
|
||||
|
||||
REQUIRE( accu(C(span(1,3),span(1,4))) == Approx(0.0).margin(0.001) );
|
||||
REQUIRE( accu(C(span(1,3),span(1,4))) == Approx(eT(0)).margin(margin) );
|
||||
|
||||
mat D(5,6,fill::ones);
|
||||
Mat<eT> D(5,6,fill::ones);
|
||||
|
||||
D.diag().zeros();
|
||||
|
||||
REQUIRE( accu(D.diag()) == Approx(0.0).margin(0.001) );
|
||||
REQUIRE( accu(D.diag()) == Approx(eT(0)).margin(margin) );
|
||||
}
|
||||
|
||||
|
||||
|
||||
TEST_CASE("gen_zeros_3")
|
||||
TEMPLATE_TEST_CASE("gen_zeros_3", "[zeros]", TEST_FLOAT_TYPES)
|
||||
{
|
||||
mat A(5,6,fill::ones);
|
||||
typedef TestType eT;
|
||||
|
||||
Mat<eT> A(5,6,fill::ones);
|
||||
|
||||
constexpr const eT margin = is_blas_real<eT>::value ? eT(0.001) : eT(0.01);
|
||||
|
||||
uvec indices = { 2, 4, 6 };
|
||||
|
||||
A(indices).zeros();
|
||||
|
||||
REQUIRE( accu(A) == Approx(double(5*6-3)) );
|
||||
REQUIRE( accu(A) == Approx(eT(5*6-3)) );
|
||||
|
||||
REQUIRE( A(0) == Approx(1.0) );
|
||||
REQUIRE( A(A.n_elem-1) == Approx(1.0) );
|
||||
REQUIRE( A(0) == Approx(eT(1)) );
|
||||
REQUIRE( A(A.n_elem-1) == Approx(eT(1)) );
|
||||
|
||||
REQUIRE( A(indices(0)) == Approx(0.0).margin(0.001) );
|
||||
REQUIRE( A(indices(1)) == Approx(0.0).margin(0.001) );
|
||||
REQUIRE( A(indices(2)) == Approx(0.0).margin(0.001) );
|
||||
REQUIRE( A(indices(0)) == Approx(eT(0)).margin(margin) );
|
||||
REQUIRE( A(indices(1)) == Approx(eT(0)).margin(margin) );
|
||||
REQUIRE( A(indices(2)) == Approx(eT(0)).margin(margin) );
|
||||
}
|
||||
|
||||
|
||||
|
||||
TEST_CASE("gen_zeros_sp_mat")
|
||||
TEST_CASE("gen_zeros_sp_mat", "[zeros]")
|
||||
{
|
||||
SpMat<unsigned int> e(2, 2);
|
||||
|
||||
|
||||
+2
-2
@@ -25,7 +25,7 @@ using namespace arma;
|
||||
/**
|
||||
* Make sure that gmm_full can fit manually constructed Gaussians.
|
||||
*/
|
||||
TEST_CASE("gmm_full_1")
|
||||
TEST_CASE("gmm_full_1", "[gmm]")
|
||||
{
|
||||
// Higher dimensionality gives us a greater chance of having separated Gaussians.
|
||||
const uword dims = 8;
|
||||
@@ -127,7 +127,7 @@ TEST_CASE("gmm_full_1")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("gmm_diag_1")
|
||||
TEST_CASE("gmm_diag_1", "[gmm]")
|
||||
{
|
||||
// Higher dimensionality gives us a greater chance of having separated Gaussians.
|
||||
const uword dims = 4;
|
||||
|
||||
+59
-25
@@ -24,7 +24,7 @@ using namespace arma;
|
||||
|
||||
#if defined(ARMA_USE_HDF5)
|
||||
|
||||
TEST_CASE("hdf5_u8_test")
|
||||
TEST_CASE("hdf5_u8_test", "[hdf5]")
|
||||
{
|
||||
arma::Mat<u8> a;
|
||||
a.randu(20, 20);
|
||||
@@ -57,7 +57,7 @@ TEST_CASE("hdf5_u8_test")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("hdf5_u16_test")
|
||||
TEST_CASE("hdf5_u16_test", "[hdf5]")
|
||||
{
|
||||
arma::Mat<u16> a;
|
||||
a.randu(20, 20);
|
||||
@@ -90,7 +90,7 @@ TEST_CASE("hdf5_u16_test")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("hdf5_u32_test")
|
||||
TEST_CASE("hdf5_u32_test", "[hdf5]")
|
||||
{
|
||||
arma::Mat<u32> a;
|
||||
a.randu(20, 20);
|
||||
@@ -124,7 +124,7 @@ TEST_CASE("hdf5_u32_test")
|
||||
|
||||
|
||||
#ifdef ARMA_USE_U64S64
|
||||
TEST_CASE("hdf5_u64_test")
|
||||
TEST_CASE("hdf5_u64_test", "[hdf5]")
|
||||
{
|
||||
arma::Mat<u64> a;
|
||||
a.randu(20, 20);
|
||||
@@ -158,7 +158,7 @@ TEST_CASE("hdf5_u64_test")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("hdf5_s8_test")
|
||||
TEST_CASE("hdf5_s8_test", "[hdf5]")
|
||||
{
|
||||
arma::Mat<s8> a;
|
||||
a.randu(20, 20);
|
||||
@@ -191,7 +191,7 @@ TEST_CASE("hdf5_s8_test")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("hdf5_s16_test")
|
||||
TEST_CASE("hdf5_s16_test", "[hdf5]")
|
||||
{
|
||||
arma::Mat<s16> a;
|
||||
a.randu(20, 20);
|
||||
@@ -224,7 +224,7 @@ TEST_CASE("hdf5_s16_test")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("hdf5_s32_test")
|
||||
TEST_CASE("hdf5_s32_test", "[hdf5]")
|
||||
{
|
||||
arma::Mat<s32> a;
|
||||
a.randu(20, 20);
|
||||
@@ -258,7 +258,7 @@ TEST_CASE("hdf5_s32_test")
|
||||
|
||||
|
||||
#ifdef ARMA_USE_U64S64
|
||||
TEST_CASE("hdf5_s64_test")
|
||||
TEST_CASE("hdf5_s64_test", "[hdf5]")
|
||||
{
|
||||
arma::Mat<s64> a;
|
||||
a.randu(20, 20);
|
||||
@@ -292,7 +292,7 @@ TEST_CASE("hdf5_s64_test")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("hdf5_char_test")
|
||||
TEST_CASE("hdf5_char_test", "[hdf5]")
|
||||
{
|
||||
arma::Mat<char> a;
|
||||
a.randu(20, 20);
|
||||
@@ -325,7 +325,7 @@ TEST_CASE("hdf5_char_test")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("hdf5_int_test")
|
||||
TEST_CASE("hdf5_int_test", "[hdf5]")
|
||||
{
|
||||
arma::Mat<signed int> a;
|
||||
a.randu(20, 20);
|
||||
@@ -358,7 +358,7 @@ TEST_CASE("hdf5_int_test")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("hdf5_uint_test")
|
||||
TEST_CASE("hdf5_uint_test", "[hdf5]")
|
||||
{
|
||||
arma::Mat<unsigned int> a;
|
||||
a.randu(20, 20);
|
||||
@@ -391,7 +391,7 @@ TEST_CASE("hdf5_uint_test")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("hdf5_short_test")
|
||||
TEST_CASE("hdf5_short_test", "[hdf5]")
|
||||
{
|
||||
arma::Mat<signed short> a;
|
||||
a.randu(20, 20);
|
||||
@@ -424,7 +424,7 @@ TEST_CASE("hdf5_short_test")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("hdf5_ushort_test")
|
||||
TEST_CASE("hdf5_ushort_test", "[hdf5]")
|
||||
{
|
||||
arma::Mat<unsigned short> a;
|
||||
a.randu(20, 20);
|
||||
@@ -457,7 +457,7 @@ TEST_CASE("hdf5_ushort_test")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("hdf5_long_test")
|
||||
TEST_CASE("hdf5_long_test", "[hdf5]")
|
||||
{
|
||||
arma::Mat<signed long> a;
|
||||
a.randu(20, 20);
|
||||
@@ -490,7 +490,7 @@ TEST_CASE("hdf5_long_test")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("hdf5_ulong_test")
|
||||
TEST_CASE("hdf5_ulong_test", "[hdf5]")
|
||||
{
|
||||
arma::Mat<unsigned long> a;
|
||||
a.randu(20, 20);
|
||||
@@ -524,7 +524,7 @@ TEST_CASE("hdf5_ulong_test")
|
||||
|
||||
|
||||
#ifdef ARMA_USE_U64S64
|
||||
TEST_CASE("hdf5_llong_test")
|
||||
TEST_CASE("hdf5_llong_test", "[hdf5]")
|
||||
{
|
||||
arma::Mat<signed long long> a;
|
||||
a.randu(20, 20);
|
||||
@@ -557,7 +557,7 @@ TEST_CASE("hdf5_llong_test")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("hdf5_ullong_test")
|
||||
TEST_CASE("hdf5_ullong_test", "[hdf5]")
|
||||
{
|
||||
arma::Mat<unsigned long long> a;
|
||||
a.randu(20, 20);
|
||||
@@ -591,7 +591,7 @@ TEST_CASE("hdf5_ullong_test")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("hdf5_float_test")
|
||||
TEST_CASE("hdf5_float_test", "[hdf5]")
|
||||
{
|
||||
arma::Mat<float> a;
|
||||
a.randu(20, 20);
|
||||
@@ -624,7 +624,7 @@ TEST_CASE("hdf5_float_test")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("hdf5_double_test")
|
||||
TEST_CASE("hdf5_double_test", "[hdf5]")
|
||||
{
|
||||
arma::Mat<double> a;
|
||||
a.randu(20, 20);
|
||||
@@ -657,7 +657,7 @@ TEST_CASE("hdf5_double_test")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("hdf5_complex_float_test")
|
||||
TEST_CASE("hdf5_complex_float_test", "[hdf5]")
|
||||
{
|
||||
arma::Mat<std::complex<float> > a;
|
||||
a.randu(20, 20);
|
||||
@@ -690,7 +690,7 @@ TEST_CASE("hdf5_complex_float_test")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("hdf5_complex_double_test")
|
||||
TEST_CASE("hdf5_complex_double_test", "[hdf5]")
|
||||
{
|
||||
arma::Mat<std::complex<double> > a;
|
||||
a.randu(20, 20);
|
||||
@@ -721,7 +721,7 @@ TEST_CASE("hdf5_complex_double_test")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("hdf5_dataset_append_test")
|
||||
TEST_CASE("hdf5_dataset_append_test", "[hdf5]")
|
||||
{
|
||||
arma::Mat<double> a;
|
||||
a.randu(20, 20);
|
||||
@@ -758,7 +758,7 @@ TEST_CASE("hdf5_dataset_append_test")
|
||||
std::remove("file.h5");
|
||||
}
|
||||
|
||||
TEST_CASE("hdf5_cube_dataset_append_test")
|
||||
TEST_CASE("hdf5_cube_dataset_append_test", "[hdf5]")
|
||||
{
|
||||
arma::Mat<double> a;
|
||||
a.randu(20, 20);
|
||||
@@ -796,7 +796,7 @@ TEST_CASE("hdf5_cube_dataset_append_test")
|
||||
}
|
||||
|
||||
|
||||
TEST_CASE("hdf5_dataset_append-overwrite-test")
|
||||
TEST_CASE("hdf5_dataset_append-overwrite-test", "[hdf5]")
|
||||
{
|
||||
arma::Mat<double> a;
|
||||
a.randu(20, 20);
|
||||
@@ -829,7 +829,7 @@ TEST_CASE("hdf5_dataset_append-overwrite-test")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("hdf5_dataset_same_dataset_twice_test")
|
||||
TEST_CASE("hdf5_dataset_same_dataset_twice_test", "[hdf5]")
|
||||
{
|
||||
arma::Mat<double> a;
|
||||
a.randu(20, 20);
|
||||
@@ -846,4 +846,38 @@ TEST_CASE("hdf5_dataset_same_dataset_twice_test")
|
||||
std::remove("file.h5");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
#if defined(ARMA_HAVE_FP16)
|
||||
#if defined(H5_HAVE__FLOAT16)
|
||||
TEST_CASE("hdf5_load_fp16", "[hdf5]")
|
||||
{
|
||||
arma::Mat<fp16> a;
|
||||
a.randu(20, 20);
|
||||
|
||||
a.save(hdf5_name("file.h5", "dataset1"), hdf5_binary);
|
||||
|
||||
arma::Mat<fp16> b;
|
||||
b.randu(10, 10);
|
||||
|
||||
b.load(hdf5_name("file.h5", "dataset1"), hdf5_binary);
|
||||
|
||||
REQUIRE( approx_equal(a, b, "absdiff", fp16(1e-5), fp16(1e-5)) );
|
||||
|
||||
std::remove("file.h5");
|
||||
}
|
||||
#else
|
||||
TEST_CASE("hdf5_fail_to_load_fp16", "[hdf5]")
|
||||
{
|
||||
arma::Mat<fp16> a;
|
||||
a.randu(20, 20);
|
||||
|
||||
REQUIRE_FALSE( a.save(hdf5_name("file.h5", "dataset1"), hdf5_binary) );
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
+16
-13
@@ -18,30 +18,33 @@
|
||||
|
||||
#include <armadillo>
|
||||
#include "catch.hpp"
|
||||
#include "utils.hpp"
|
||||
|
||||
using namespace arma;
|
||||
|
||||
|
||||
TEST_CASE("init_auxmem_1")
|
||||
TEMPLATE_TEST_CASE("init_auxmem_1", "[init]", TEST_FLOAT_TYPES)
|
||||
{
|
||||
double data[] = { 1, 2, 3, 4, 5, 6 };
|
||||
typedef TestType eT;
|
||||
|
||||
eT data[] = { 1, 2, 3, 4, 5, 6 };
|
||||
|
||||
mat A(data, 2, 3);
|
||||
mat B(data, 2, 3, false);
|
||||
mat C(data, 2, 3, false, true);
|
||||
Mat<eT> A(data, 2, 3);
|
||||
Mat<eT> B(data, 2, 3, false);
|
||||
Mat<eT> C(data, 2, 3, false, true);
|
||||
|
||||
REQUIRE( A(0,0) == double(1) );
|
||||
REQUIRE( A(1,0) == double(2) );
|
||||
REQUIRE( A(0,0) == eT(1) );
|
||||
REQUIRE( A(1,0) == eT(2) );
|
||||
|
||||
REQUIRE( A(0,1) == double(3) );
|
||||
REQUIRE( A(1,1) == double(4) );
|
||||
REQUIRE( A(0,1) == eT(3) );
|
||||
REQUIRE( A(1,1) == eT(4) );
|
||||
|
||||
REQUIRE( A(0,2) == double(5) );
|
||||
REQUIRE( A(1,2) == double(6) );
|
||||
REQUIRE( A(0,2) == eT(5) );
|
||||
REQUIRE( A(1,2) == eT(6) );
|
||||
|
||||
A(0,0) = 123.0; REQUIRE( data[0] == 1 );
|
||||
A(0,0) = eT(123.0); REQUIRE( data[0] == eT(1) );
|
||||
|
||||
B(0,0) = 123.0; REQUIRE( data[0] == 123.0 );
|
||||
B(0,0) = eT(123.0); REQUIRE( data[0] == eT(123.0) );
|
||||
|
||||
REQUIRE_THROWS( C.set_size(5,6) );
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
using namespace arma;
|
||||
|
||||
|
||||
TEST_CASE("init_fill_1")
|
||||
TEST_CASE("init_fill_1", "[init]")
|
||||
{
|
||||
mat Z( 5, 6, fill::zeros);
|
||||
mat O( 5, 6, fill::ones);
|
||||
@@ -46,7 +46,7 @@ TEST_CASE("init_fill_1")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("init_fill_2")
|
||||
TEST_CASE("init_fill_2", "[init]")
|
||||
{
|
||||
cube Z( 5, 6, 2, fill::zeros);
|
||||
cube O( 5, 6, 2, fill::ones);
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
using namespace arma;
|
||||
|
||||
|
||||
TEST_CASE("init_misc_1")
|
||||
TEST_CASE("init_misc_1", "[init]")
|
||||
{
|
||||
const uword n_rows = 5;
|
||||
const uword n_cols = 6;
|
||||
@@ -91,7 +91,7 @@ TEST_CASE("init_misc_1")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("init_misc_2")
|
||||
TEST_CASE("init_misc_2", "[init]")
|
||||
{
|
||||
mat A =
|
||||
{
|
||||
@@ -143,7 +143,7 @@ TEST_CASE("init_misc_2")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("init_misc_3")
|
||||
TEST_CASE("init_misc_3", "[init]")
|
||||
{
|
||||
const uword n_rows = 5;
|
||||
const uword n_cols = 6;
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
using namespace arma;
|
||||
|
||||
|
||||
TEST_CASE("instantiation_mat_1")
|
||||
TEST_CASE("instantiation_mat_1", "[instantiation]")
|
||||
{
|
||||
const uword n_rows = 5;
|
||||
const uword n_cols = 6;
|
||||
@@ -43,7 +43,7 @@ TEST_CASE("instantiation_mat_1")
|
||||
// TODO: rowvec_instantiation
|
||||
|
||||
|
||||
TEST_CASE("instantiation_cube_1")
|
||||
TEST_CASE("instantiation_cube_1", "[instantiation]")
|
||||
{
|
||||
const uword n_rows = 5;
|
||||
const uword n_cols = 6;
|
||||
|
||||
+27
-1
@@ -18,11 +18,12 @@
|
||||
|
||||
#include <armadillo>
|
||||
#include "catch.hpp"
|
||||
#include "utils.hpp"
|
||||
|
||||
using namespace arma;
|
||||
|
||||
|
||||
TEST_CASE("mat_minus_1")
|
||||
TEST_CASE("mat_minus_1", "[minus]")
|
||||
{
|
||||
mat A =
|
||||
"\
|
||||
@@ -102,3 +103,28 @@ TEST_CASE("mat_minus_1")
|
||||
|
||||
// REQUIRE_THROWS( );
|
||||
}
|
||||
|
||||
|
||||
|
||||
TEMPLATE_TEST_CASE("mat_minus_fp", "[minus]", TEST_FLOAT_TYPES)
|
||||
{
|
||||
typedef TestType eT;
|
||||
|
||||
Mat<eT> A(10, 10, fill::randu);
|
||||
Mat<eT> B = -A;
|
||||
Mat<eT> C = A;
|
||||
|
||||
for (uword i = 0; i < A.n_elem; ++i)
|
||||
{
|
||||
REQUIRE( B[i] == Approx(-A[i]) );
|
||||
}
|
||||
|
||||
Mat<eT> D = A - C;
|
||||
|
||||
constexpr const eT margin = is_blas_real<eT>::value ? eT(0.0001) : eT(0.01);
|
||||
|
||||
for (uword i = 0; i < A.n_elem; ++i)
|
||||
{
|
||||
REQUIRE( D[i] == Approx(eT(0)).margin(margin) );
|
||||
}
|
||||
}
|
||||
|
||||
+44
-1
@@ -18,11 +18,12 @@
|
||||
|
||||
#include <armadillo>
|
||||
#include "catch.hpp"
|
||||
#include "utils.hpp"
|
||||
|
||||
using namespace arma;
|
||||
|
||||
|
||||
TEST_CASE("mat_mul_cx_1")
|
||||
TEST_CASE("mat_mul_cx_1", "[mat_mul]")
|
||||
{
|
||||
mat A =
|
||||
"\
|
||||
@@ -291,3 +292,45 @@ TEST_CASE("mat_mul_cx_1")
|
||||
|
||||
|
||||
|
||||
TEMPLATE_TEST_CASE("mat_mul_cx_fp_compare", "[mat_mul]", TEST_CX_FLOAT_TYPES)
|
||||
{
|
||||
typedef TestType eT;
|
||||
typedef typename get_pod_type<eT>::result T;
|
||||
|
||||
Mat<eT> X(10, 10, fill::randu);
|
||||
Mat<eT> Y(10, 10, fill::randu);
|
||||
|
||||
cx_mat X_ref = conv_to<cx_mat>::from(X);
|
||||
cx_mat Y_ref = conv_to<cx_mat>::from(Y);
|
||||
|
||||
Mat<eT> Z1 = X * Y;
|
||||
Mat<eT> Z2 = X.t() * Y;
|
||||
Mat<eT> Z3 = X * Y.t();
|
||||
Mat<eT> Z4 = X.t() * Y.t();
|
||||
|
||||
cx_mat Z1_ref = X_ref * Y_ref;
|
||||
cx_mat Z2_ref = X_ref.t() * Y_ref;
|
||||
cx_mat Z3_ref = X_ref * Y_ref.t();
|
||||
cx_mat Z4_ref = X_ref.t() * Y_ref.t();
|
||||
|
||||
REQUIRE( Z1.n_rows == Z1_ref.n_rows );
|
||||
REQUIRE( Z1.n_cols == Z1_ref.n_cols );
|
||||
REQUIRE( Z2.n_rows == Z2_ref.n_rows );
|
||||
REQUIRE( Z2.n_cols == Z2_ref.n_cols );
|
||||
REQUIRE( Z3.n_rows == Z3_ref.n_rows );
|
||||
REQUIRE( Z3.n_cols == Z3_ref.n_cols );
|
||||
REQUIRE( Z4.n_rows == Z4_ref.n_rows );
|
||||
REQUIRE( Z4.n_cols == Z4_ref.n_cols );
|
||||
|
||||
cx_mat diff1 = conv_to<cx_mat>::from(Z1) - Z1_ref;
|
||||
cx_mat diff2 = conv_to<cx_mat>::from(Z2) - Z2_ref;
|
||||
cx_mat diff3 = conv_to<cx_mat>::from(Z3) - Z3_ref;
|
||||
cx_mat diff4 = conv_to<cx_mat>::from(Z4) - Z4_ref;
|
||||
|
||||
constexpr const T margin = is_blas_real<T>::value ? T(0.0001) : T(0.05);
|
||||
|
||||
REQUIRE( accu(abs(diff1)) == Approx(T(0)).margin(margin * diff1.n_elem) );
|
||||
REQUIRE( accu(abs(diff2)) == Approx(T(0)).margin(margin * diff2.n_elem) );
|
||||
REQUIRE( accu(abs(diff3)) == Approx(T(0)).margin(margin * diff3.n_elem) );
|
||||
REQUIRE( accu(abs(diff4)) == Approx(T(0)).margin(margin * diff4.n_elem) );
|
||||
}
|
||||
|
||||
+48
-6
@@ -18,11 +18,12 @@
|
||||
|
||||
#include <armadillo>
|
||||
#include "catch.hpp"
|
||||
#include "utils.hpp"
|
||||
|
||||
using namespace arma;
|
||||
|
||||
|
||||
TEST_CASE("mat_mul_real_1")
|
||||
TEST_CASE("mat_mul_real_1", "[mat_mul]")
|
||||
{
|
||||
mat A =
|
||||
"\
|
||||
@@ -99,7 +100,7 @@ TEST_CASE("mat_mul_real_1")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("mat_mul_real_2")
|
||||
TEST_CASE("mat_mul_real_2", "[mat_mul]")
|
||||
{
|
||||
mat A =
|
||||
"\
|
||||
@@ -224,7 +225,7 @@ TEST_CASE("mat_mul_real_2")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("mat_mul_real_3")
|
||||
TEST_CASE("mat_mul_real_3", "[mat_mul]")
|
||||
{
|
||||
mat A =
|
||||
"\
|
||||
@@ -363,7 +364,7 @@ TEST_CASE("mat_mul_real_3")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("mat_mul_real_4")
|
||||
TEST_CASE("mat_mul_real_4", "[mat_mul]")
|
||||
{
|
||||
mat A =
|
||||
"\
|
||||
@@ -563,7 +564,7 @@ TEST_CASE("mat_mul_real_4")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("mat_mul_real_5")
|
||||
TEST_CASE("mat_mul_real_5", "[mat_mul]")
|
||||
{
|
||||
mat A =
|
||||
"\
|
||||
@@ -777,7 +778,7 @@ TEST_CASE("mat_mul_real_5")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("mat_mul_real_6")
|
||||
TEST_CASE("mat_mul_real_6", "[mat_mul]")
|
||||
{
|
||||
mat A =
|
||||
"\
|
||||
@@ -927,3 +928,44 @@ TEST_CASE("mat_mul_real_6")
|
||||
|
||||
|
||||
|
||||
TEMPLATE_TEST_CASE("mat_mul_fp_compare", "[mat_mul]", TEST_FLOAT_TYPES)
|
||||
{
|
||||
typedef TestType eT;
|
||||
|
||||
Mat<eT> X(10, 10, fill::randu);
|
||||
Mat<eT> Y(10, 10, fill::randu);
|
||||
|
||||
mat X_ref = conv_to<mat>::from(X);
|
||||
mat Y_ref = conv_to<mat>::from(Y);
|
||||
|
||||
Mat<eT> Z1 = X * Y;
|
||||
Mat<eT> Z2 = X.t() * Y;
|
||||
Mat<eT> Z3 = X * Y.t();
|
||||
Mat<eT> Z4 = X.t() * Y.t();
|
||||
|
||||
mat Z1_ref = X_ref * Y_ref;
|
||||
mat Z2_ref = X_ref.t() * Y_ref;
|
||||
mat Z3_ref = X_ref * Y_ref.t();
|
||||
mat Z4_ref = X_ref.t() * Y_ref.t();
|
||||
|
||||
REQUIRE( Z1.n_rows == Z1_ref.n_rows );
|
||||
REQUIRE( Z1.n_cols == Z1_ref.n_cols );
|
||||
REQUIRE( Z2.n_rows == Z2_ref.n_rows );
|
||||
REQUIRE( Z2.n_cols == Z2_ref.n_cols );
|
||||
REQUIRE( Z3.n_rows == Z3_ref.n_rows );
|
||||
REQUIRE( Z3.n_cols == Z3_ref.n_cols );
|
||||
REQUIRE( Z4.n_rows == Z4_ref.n_rows );
|
||||
REQUIRE( Z4.n_cols == Z4_ref.n_cols );
|
||||
|
||||
mat diff1 = conv_to<mat>::from(Z1) - Z1_ref;
|
||||
mat diff2 = conv_to<mat>::from(Z2) - Z2_ref;
|
||||
mat diff3 = conv_to<mat>::from(Z3) - Z3_ref;
|
||||
mat diff4 = conv_to<mat>::from(Z4) - Z4_ref;
|
||||
|
||||
constexpr const eT margin = is_blas_real<eT>::value ? eT(0.0001) : eT(0.05);
|
||||
|
||||
REQUIRE( accu(abs(diff1)) == Approx(eT(0)).margin(margin * diff1.n_elem) );
|
||||
REQUIRE( accu(abs(diff2)) == Approx(eT(0)).margin(margin * diff2.n_elem) );
|
||||
REQUIRE( accu(abs(diff3)) == Approx(eT(0)).margin(margin * diff3.n_elem) );
|
||||
REQUIRE( accu(abs(diff4)) == Approx(eT(0)).margin(margin * diff4.n_elem) );
|
||||
}
|
||||
|
||||
+1
-1
@@ -22,7 +22,7 @@
|
||||
using namespace arma;
|
||||
|
||||
|
||||
TEST_CASE("mat_neg_1")
|
||||
TEST_CASE("mat_neg_1", "[neg]")
|
||||
{
|
||||
mat A =
|
||||
"\
|
||||
|
||||
+29
-3
@@ -18,11 +18,11 @@
|
||||
|
||||
#include <armadillo>
|
||||
#include "catch.hpp"
|
||||
#include "utils.hpp"
|
||||
|
||||
using namespace arma;
|
||||
|
||||
|
||||
TEST_CASE("mat_plus_1")
|
||||
TEST_CASE("mat_plus_1", "[plus]")
|
||||
{
|
||||
mat A =
|
||||
"\
|
||||
@@ -96,7 +96,7 @@ TEST_CASE("mat_plus_1")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("mat_plus_2")
|
||||
TEST_CASE("mat_plus_2", "[plus]")
|
||||
{
|
||||
mat A(5,6); A.fill(1.0);
|
||||
mat B(5,6); B.fill(2.0);
|
||||
@@ -115,3 +115,29 @@ TEST_CASE("mat_plus_2")
|
||||
|
||||
|
||||
|
||||
TEMPLATE_TEST_CASE("mat_plus_fp_compare", "[plus]", TEST_FLOAT_TYPES)
|
||||
{
|
||||
typedef TestType eT;
|
||||
|
||||
Mat<eT> A(5, 6, fill::randu);
|
||||
Mat<eT> B(5, 6, fill::randu);
|
||||
|
||||
mat A_ref = conv_to<mat>::from(A);
|
||||
mat B_ref = conv_to<mat>::from(B);
|
||||
|
||||
Mat<eT> C = A + B;
|
||||
Mat<eT> D = A + eT(1);
|
||||
|
||||
mat C_ref = A_ref + B_ref;
|
||||
mat D_ref = A_ref + 1.0;
|
||||
|
||||
REQUIRE( C.n_rows == A.n_rows );
|
||||
REQUIRE( C.n_cols == A.n_cols );
|
||||
REQUIRE( D.n_rows == A.n_rows );
|
||||
REQUIRE( D.n_cols == A.n_cols );
|
||||
|
||||
constexpr const eT margin = is_blas_real<eT>::value ? eT(0.0001) : eT(0.01);
|
||||
|
||||
REQUIRE( all( all( abs(conv_to<mat>::from(C) - C_ref) < margin ) ) );
|
||||
REQUIRE( all( all( abs(conv_to<mat>::from(D) - D_ref) < margin ) ) );
|
||||
}
|
||||
|
||||
+5
-5
@@ -21,7 +21,7 @@
|
||||
|
||||
using namespace arma;
|
||||
|
||||
TEST_CASE("spcol_insert_test")
|
||||
TEST_CASE("spcol_insert_test", "[spcol]")
|
||||
{
|
||||
SpCol<double> sp;
|
||||
sp.set_size(10, 1);
|
||||
@@ -39,7 +39,7 @@ TEST_CASE("spcol_insert_test")
|
||||
REQUIRE( sp.n_nonzero == 0 );
|
||||
}
|
||||
|
||||
TEST_CASE("col_iterator_test")
|
||||
TEST_CASE("col_iterator_test", "[spcol]")
|
||||
{
|
||||
SpCol<double> x(5, 1);
|
||||
x(3) = 3.1;
|
||||
@@ -112,7 +112,7 @@ TEST_CASE("col_iterator_test")
|
||||
REQUIRE( x.n_nonzero == 4 );
|
||||
}
|
||||
|
||||
TEST_CASE("basic_sp_col_operator_test")
|
||||
TEST_CASE("basic_sp_col_operator_test", "[spcol]")
|
||||
{
|
||||
// +=, -=, *=, /=, %=
|
||||
SpCol<double> a(6, 1);
|
||||
@@ -170,7 +170,7 @@ BOOST_AUTO_TEST_CASE(SparseSparseColMultiplicationTest) {
|
||||
}
|
||||
*/
|
||||
|
||||
TEST_CASE("spcol_shed_row_test")
|
||||
TEST_CASE("spcol_shed_row_test", "[spcol]")
|
||||
{
|
||||
// On an SpCol
|
||||
SpCol<int> e(10);
|
||||
@@ -195,7 +195,7 @@ TEST_CASE("spcol_shed_row_test")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("spcol_col_constructor")
|
||||
TEST_CASE("spcol_col_constructor", "[spcol]")
|
||||
{
|
||||
SpMat<double> m(100, 100);
|
||||
m.sprandu(100, 100, 0.3);
|
||||
|
||||
+66
-66
@@ -22,7 +22,7 @@
|
||||
using namespace arma;
|
||||
|
||||
// Does the matrix correctly report when it is empty?
|
||||
TEST_CASE("empty_test")
|
||||
TEST_CASE("empty_test", "[spmat]")
|
||||
{
|
||||
// bool testPassed = true;
|
||||
|
||||
@@ -34,7 +34,7 @@ TEST_CASE("empty_test")
|
||||
}
|
||||
|
||||
// Can we insert items into the matrix correctly?
|
||||
TEST_CASE("insertion_test")
|
||||
TEST_CASE("insertion_test", "[spmat]")
|
||||
{
|
||||
int correctResult[3][4] =
|
||||
{{1, 0, 0, 0},
|
||||
@@ -63,7 +63,7 @@ TEST_CASE("insertion_test")
|
||||
}
|
||||
|
||||
// Does sparse-sparse matrix multiplication work?
|
||||
TEST_CASE("full_sparse_sparse_matrix_multiplication_test")
|
||||
TEST_CASE("full_sparse_sparse_matrix_multiplication_test", "[spmat]")
|
||||
{
|
||||
// Now perform the test again for SpMat.
|
||||
SpMat<int> spa(3, 3);
|
||||
@@ -104,7 +104,7 @@ TEST_CASE("full_sparse_sparse_matrix_multiplication_test")
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("sparse_sparse_matrix_multiplication_test")
|
||||
TEST_CASE("sparse_sparse_matrix_multiplication_test", "[spmat]")
|
||||
{
|
||||
SpMat<double> spaa(10, 10);
|
||||
spaa(1, 5) = 0.4;
|
||||
@@ -144,7 +144,7 @@ TEST_CASE("sparse_sparse_matrix_multiplication_test")
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("hadamard_product_test")
|
||||
TEST_CASE("hadamard_product_test", "[spmat]")
|
||||
{
|
||||
SpMat<int> a(4, 4), b(4, 4);
|
||||
|
||||
@@ -198,7 +198,7 @@ TEST_CASE("hadamard_product_test")
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("division_test")
|
||||
TEST_CASE("division_test", "[spmat]")
|
||||
{
|
||||
SpMat<double> a(2, 2), b(2, 2);
|
||||
|
||||
@@ -215,7 +215,7 @@ TEST_CASE("division_test")
|
||||
REQUIRE( std::isnan((double) a(1, 1)) );
|
||||
}
|
||||
|
||||
TEST_CASE("insert_delete_test")
|
||||
TEST_CASE("insert_delete_test", "[spmat]")
|
||||
{
|
||||
SpMat<double> sp;
|
||||
sp.set_size(10, 10);
|
||||
@@ -236,7 +236,7 @@ TEST_CASE("insert_delete_test")
|
||||
REQUIRE( sp.n_nonzero == 0 );
|
||||
}
|
||||
|
||||
TEST_CASE("value_operator_test")
|
||||
TEST_CASE("value_operator_test", "[spmat]")
|
||||
{
|
||||
// Test operators that work with a single value.
|
||||
// =(double), /=(double), *=(double)
|
||||
@@ -284,7 +284,7 @@ TEST_CASE("value_operator_test")
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("iterator_test")
|
||||
TEST_CASE("iterator_test", "[spmat]")
|
||||
{
|
||||
SpMat<double> x(5, 5);
|
||||
x(4, 1) = 3.1;
|
||||
@@ -357,7 +357,7 @@ TEST_CASE("iterator_test")
|
||||
REQUIRE( x.n_nonzero == 4 );
|
||||
}
|
||||
|
||||
TEST_CASE("row_iterator_test")
|
||||
TEST_CASE("row_iterator_test", "[spmat]")
|
||||
{
|
||||
SpMat<double> x(5, 5);
|
||||
x(4, 1) = 3.1;
|
||||
@@ -430,7 +430,7 @@ TEST_CASE("row_iterator_test")
|
||||
REQUIRE( x.n_nonzero == 4 );
|
||||
}
|
||||
|
||||
TEST_CASE("basic_sp_mat_operator_test")
|
||||
TEST_CASE("basic_sp_mat_operator_test", "[spmat]")
|
||||
{
|
||||
// +=, -=, *=, /=, %=
|
||||
SpMat<double> a(6, 5);
|
||||
@@ -495,7 +495,7 @@ TEST_CASE("basic_sp_mat_operator_test")
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("min_max_test")
|
||||
TEST_CASE("min_max_test", "[spmat]")
|
||||
{
|
||||
SpMat<double> a(6, 5);
|
||||
a(0, 0) = 3.4;
|
||||
@@ -520,7 +520,7 @@ TEST_CASE("min_max_test")
|
||||
REQUIRE( index2 == 19 );
|
||||
}
|
||||
|
||||
TEST_CASE("swap_row_test")
|
||||
TEST_CASE("swap_row_test", "[spmat]")
|
||||
{
|
||||
SpMat<double> a(6, 5);
|
||||
a(0, 0) = 3.4;
|
||||
@@ -580,7 +580,7 @@ TEST_CASE("swap_row_test")
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("swap_col_test")
|
||||
TEST_CASE("swap_col_test", "[spmat]")
|
||||
{
|
||||
SpMat<double> a(6, 5);
|
||||
a(0, 0) = 3.4;
|
||||
@@ -652,7 +652,7 @@ TEST_CASE("swap_col_test")
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("shed_col_test")
|
||||
TEST_CASE("shed_col_test", "[spmat]")
|
||||
{
|
||||
SpMat<int> a(2, 2);
|
||||
a(0, 0) = 1;
|
||||
@@ -677,7 +677,7 @@ TEST_CASE("shed_col_test")
|
||||
REQUIRE( a(1, 0) == 1 );
|
||||
}
|
||||
|
||||
TEST_CASE("shed_cols_test")
|
||||
TEST_CASE("shed_cols_test", "[spmat]")
|
||||
{
|
||||
SpMat<int> a(3, 3);
|
||||
a(0, 0) = 1;
|
||||
@@ -737,7 +737,7 @@ TEST_CASE("shed_cols_test")
|
||||
REQUIRE( c.row_indices[c.n_nonzero] == 0 );
|
||||
}
|
||||
|
||||
TEST_CASE("shed_row_test")
|
||||
TEST_CASE("shed_row_test", "[spmat]")
|
||||
{
|
||||
SpMat<int> a(3, 3);
|
||||
a(0, 0) = 1;
|
||||
@@ -774,7 +774,7 @@ TEST_CASE("shed_row_test")
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("shed_rows_test")
|
||||
TEST_CASE("shed_rows_test", "[spmat]")
|
||||
{
|
||||
SpMat<int> a(5, 5);
|
||||
a(0, 0) = 1;
|
||||
@@ -834,7 +834,7 @@ TEST_CASE("shed_rows_test")
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("sp_mat_reshape_test")
|
||||
TEST_CASE("sp_mat_reshape_test", "[spmat]")
|
||||
{
|
||||
// Input matrix:
|
||||
// [[0 2 0]
|
||||
@@ -875,7 +875,7 @@ TEST_CASE("sp_mat_reshape_test")
|
||||
REQUIRE( (unsigned int) ref(2, 3) == 6 );
|
||||
}
|
||||
|
||||
TEST_CASE("sp_mat_zeros_tests")
|
||||
TEST_CASE("sp_mat_zeros_tests", "[spmat]")
|
||||
{
|
||||
SpMat<double> m(4, 3);
|
||||
m(1, 0) = 1;
|
||||
@@ -937,7 +937,7 @@ TEST_CASE("sp_mat_zeros_tests")
|
||||
/**
|
||||
* Check that eye() works.
|
||||
*/
|
||||
TEST_CASE("sp_mat_eye_test")
|
||||
TEST_CASE("sp_mat_eye_test", "[spmat]")
|
||||
{
|
||||
SpMat<double> e = eye<SpMat<double> >(5, 5);
|
||||
|
||||
@@ -967,7 +967,7 @@ TEST_CASE("sp_mat_eye_test")
|
||||
/**
|
||||
* Check that pow works.
|
||||
*
|
||||
TEST_CASE("sp_mat_pow_test")
|
||||
TEST_CASE("sp_mat_pow_test", "[spmat]")
|
||||
{
|
||||
SpMat<double> a(3, 3);
|
||||
a(0, 2) = 4.3;
|
||||
@@ -997,7 +997,7 @@ TEST_CASE("sp_mat_pow_test")
|
||||
// I hate myself.
|
||||
#undef TEST_OPERATOR
|
||||
#define TEST_OPERATOR(EOP_TEST, EOP) \
|
||||
TEST_CASE(EOP_TEST) \
|
||||
TEST_CASE(EOP_TEST, "[spmat]") \
|
||||
{\
|
||||
SpMat<double> a(3, 3);\
|
||||
a(0, 2) = 4.3;\
|
||||
@@ -1151,7 +1151,7 @@ TEST_OPERATOR("sp_mat_ceil_test", ceil)
|
||||
//TEST_OPERATOR(atanhTest, atanh);
|
||||
|
||||
/*
|
||||
TEST_CASE("spmat_diskio_tests")
|
||||
TEST_CASE("spmat_diskio_tests", "[spmat]")
|
||||
{
|
||||
std::string file_names[] = {"raw_ascii.txt",
|
||||
"raw_binary.bin",
|
||||
@@ -1209,7 +1209,7 @@ TEST_CASE("spmat_diskio_tests")
|
||||
*/
|
||||
|
||||
|
||||
TEST_CASE("min_test")
|
||||
TEST_CASE("min_test", "[spmat]")
|
||||
{
|
||||
SpCol<double> a(5);
|
||||
|
||||
@@ -1292,7 +1292,7 @@ TEST_CASE("min_test")
|
||||
}
|
||||
|
||||
|
||||
TEST_CASE("max_test")
|
||||
TEST_CASE("max_test", "[spmat]")
|
||||
{
|
||||
SpCol<double> a(5);
|
||||
|
||||
@@ -1375,7 +1375,7 @@ TEST_CASE("max_test")
|
||||
}
|
||||
|
||||
|
||||
TEST_CASE("spmat_min_cx_test")
|
||||
TEST_CASE("spmat_min_cx_test", "[spmat]")
|
||||
{
|
||||
SpCol<cx_double> a(5);
|
||||
|
||||
@@ -1463,7 +1463,7 @@ TEST_CASE("spmat_min_cx_test")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("spmat_max_cx_test")
|
||||
TEST_CASE("spmat_max_cx_test", "[spmat]")
|
||||
{
|
||||
SpCol<cx_double> a(5);
|
||||
|
||||
@@ -1550,7 +1550,7 @@ TEST_CASE("spmat_max_cx_test")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("spmat_complex_constructor_test")
|
||||
TEST_CASE("spmat_complex_constructor_test", "[spmat]")
|
||||
{
|
||||
// First make two sparse matrices.
|
||||
SpMat<double> a(8, 10);
|
||||
@@ -1602,7 +1602,7 @@ TEST_CASE("spmat_complex_constructor_test")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("spmat_unary_operators_test")
|
||||
TEST_CASE("spmat_unary_operators_test", "[spmat]")
|
||||
{
|
||||
SpMat<int> a(3, 3);
|
||||
SpMat<int> b(3, 3);
|
||||
@@ -1679,7 +1679,7 @@ TEST_CASE("spmat_unary_operators_test")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("spmat_unary_val_operators_test")
|
||||
TEST_CASE("spmat_unary_val_operators_test", "[spmat]")
|
||||
{
|
||||
SpMat<double> a(2, 2);
|
||||
|
||||
@@ -1704,7 +1704,7 @@ TEST_CASE("spmat_unary_val_operators_test")
|
||||
}
|
||||
|
||||
|
||||
TEST_CASE("spmat_sparse_unary_multiplication_test")
|
||||
TEST_CASE("spmat_sparse_unary_multiplication_test", "[spmat]")
|
||||
{
|
||||
SpMat<double> spaa(10, 10);
|
||||
spaa(1, 5) = 0.4;
|
||||
@@ -1771,7 +1771,7 @@ TEST_CASE("spmat_sparse_unary_multiplication_test")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("spmat_unary_operator_test_2")
|
||||
TEST_CASE("spmat_unary_operator_test_2", "[spmat]")
|
||||
{
|
||||
SpMat<double> a(3, 3);
|
||||
a(0, 0) = 1;
|
||||
@@ -1859,7 +1859,7 @@ TEST_CASE("spmat_unary_operator_test_2")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("spmat_mat_operator_tests")
|
||||
TEST_CASE("spmat_mat_operator_tests", "[spmat]")
|
||||
{
|
||||
SpMat<double> a(3, 3);
|
||||
a(0, 0) = 2.0;
|
||||
@@ -1982,7 +1982,7 @@ TEST_CASE("spmat_mat_operator_tests")
|
||||
}
|
||||
|
||||
|
||||
TEST_CASE("spmat_empty_hadamard")
|
||||
TEST_CASE("spmat_empty_hadamard", "[spmat]")
|
||||
{
|
||||
SpMat<double> x(5, 5), y(5, 5), z;
|
||||
|
||||
@@ -1995,7 +1995,7 @@ TEST_CASE("spmat_empty_hadamard")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("spmat_sparse_dense_in_place")
|
||||
TEST_CASE("spmat_sparse_dense_in_place", "[spmat]")
|
||||
{
|
||||
SpMat<double> a;
|
||||
a.sprandu(50, 50, 0.1);
|
||||
@@ -2071,7 +2071,7 @@ TEST_CASE("spmat_sparse_dense_in_place")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("spmat_sparse_dense_not_in_place")
|
||||
TEST_CASE("spmat_sparse_dense_not_in_place", "[spmat]")
|
||||
{
|
||||
SpMat<double> a;
|
||||
a.sprandu(50, 50, 0.1);
|
||||
@@ -2212,7 +2212,7 @@ TEST_CASE("spmat_sparse_dense_not_in_place")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("spmat_batch_insert_test")
|
||||
TEST_CASE("spmat_batch_insert_test", "[spmat]")
|
||||
{
|
||||
Mat<uword> locations(2, 5);
|
||||
locations(1, 0) = 1;
|
||||
@@ -2261,7 +2261,7 @@ TEST_CASE("spmat_batch_insert_test")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("spmat_batch_insert_unsorted_test")
|
||||
TEST_CASE("spmat_batch_insert_unsorted_test", "[spmat]")
|
||||
{
|
||||
Mat<uword> locations(2, 5);
|
||||
locations(1, 0) = 4;
|
||||
@@ -2308,7 +2308,7 @@ TEST_CASE("spmat_batch_insert_unsorted_test")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("spmat_batch_insert_empty_test")
|
||||
TEST_CASE("spmat_batch_insert_empty_test", "[spmat]")
|
||||
{
|
||||
Mat<uword> locations(2, 0);
|
||||
Col<double> values;
|
||||
@@ -2354,7 +2354,7 @@ void CheckMatrices(const T1& a, const T2& b)
|
||||
}
|
||||
|
||||
// Test the constructor written by Dirk.
|
||||
TEST_CASE("spmat_dirk_constructor_test")
|
||||
TEST_CASE("spmat_dirk_constructor_test", "[spmat]")
|
||||
{
|
||||
// Come up with some values and stuff.
|
||||
vec values = "4.0 2.0 1.0 3.2 1.2 3.5";
|
||||
@@ -2401,7 +2401,7 @@ TEST_CASE("spmat_dirk_constructor_test")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("spmat_dirk_constructor_test2")
|
||||
TEST_CASE("spmat_dirk_constructor_test2", "[spmat]")
|
||||
{
|
||||
// note the zero at (1,1)
|
||||
vec values = "4.0 2.0 0.0 1.0 3.2 1.2 3.5";
|
||||
@@ -2449,7 +2449,7 @@ TEST_CASE("spmat_dirk_constructor_test2")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("spmat_clear_test")
|
||||
TEST_CASE("spmat_clear_test", "[spmat]")
|
||||
{
|
||||
sp_mat x;
|
||||
x.sprandu(10, 10, 0.6);
|
||||
@@ -2463,7 +2463,7 @@ TEST_CASE("spmat_clear_test")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("spmat_batch_insert_zeroes_test")
|
||||
TEST_CASE("spmat_batch_insert_zeroes_test", "[spmat]")
|
||||
{
|
||||
Mat<uword> locations(2, 5);
|
||||
locations(1, 0) = 1;
|
||||
@@ -2510,7 +2510,7 @@ TEST_CASE("spmat_batch_insert_zeroes_test")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("spmat_batch_insert_unsorted_case_zeroes")
|
||||
TEST_CASE("spmat_batch_insert_unsorted_case_zeroes", "[spmat]")
|
||||
{
|
||||
Mat<uword> locations(2, 5);
|
||||
locations(1, 0) = 4;
|
||||
@@ -2559,7 +2559,7 @@ TEST_CASE("spmat_batch_insert_unsorted_case_zeroes")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("spmat_const_row_col_iterator_test")
|
||||
TEST_CASE("spmat_const_row_col_iterator_test", "[spmat]")
|
||||
{
|
||||
mat X;
|
||||
X.zeros(5, 5);
|
||||
@@ -2608,7 +2608,7 @@ TEST_CASE("spmat_const_row_col_iterator_test")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("spmat_row_col_iterator_test")
|
||||
TEST_CASE("spmat_row_col_iterator_test", "[spmat]")
|
||||
{
|
||||
mat X;
|
||||
X.zeros(5, 5);
|
||||
@@ -2657,7 +2657,7 @@ TEST_CASE("spmat_row_col_iterator_test")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("spmat_const_sprow_col_iterator_test")
|
||||
TEST_CASE("spmat_const_sprow_col_iterator_test", "[spmat]")
|
||||
{
|
||||
sp_mat X(5, 5);
|
||||
for (uword i = 0; i < 5; ++i)
|
||||
@@ -2705,7 +2705,7 @@ TEST_CASE("spmat_const_sprow_col_iterator_test")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("spmat_sprow_col_iterator_test")
|
||||
TEST_CASE("spmat_sprow_col_iterator_test", "[spmat]")
|
||||
{
|
||||
sp_mat X(5, 5);
|
||||
for (uword i = 0; i < 5; ++i)
|
||||
@@ -2752,7 +2752,7 @@ TEST_CASE("spmat_sprow_col_iterator_test")
|
||||
}
|
||||
|
||||
|
||||
TEST_CASE("spmat_row_iterator_constructor")
|
||||
TEST_CASE("spmat_row_iterator_constructor", "[spmat]")
|
||||
{
|
||||
// Create a row iterator with an exact position.
|
||||
Mat<double> tmp =
|
||||
@@ -2786,7 +2786,7 @@ TEST_CASE("spmat_row_iterator_constructor")
|
||||
|
||||
|
||||
// Check that sparse + scalar works.
|
||||
TEST_CASE("spmat_scalar_add")
|
||||
TEST_CASE("spmat_scalar_add", "[spmat]")
|
||||
{
|
||||
sp_mat m;
|
||||
m.sprandu(100, 200, 0.1);
|
||||
@@ -2806,7 +2806,7 @@ TEST_CASE("spmat_scalar_add")
|
||||
|
||||
|
||||
// Check that sparse - scalar works.
|
||||
TEST_CASE("spmat_scalar_minus")
|
||||
TEST_CASE("spmat_scalar_minus", "[spmat]")
|
||||
{
|
||||
sp_mat m;
|
||||
m.sprandu(100, 200, 0.1);
|
||||
@@ -2826,7 +2826,7 @@ TEST_CASE("spmat_scalar_minus")
|
||||
|
||||
|
||||
// Check that sparse / (sparse + eps) works. (and also for (sparse - eps) and (eps - sparse).
|
||||
TEST_CASE("spmat_div_test")
|
||||
TEST_CASE("spmat_div_test", "[spmat]")
|
||||
{
|
||||
sp_mat m;
|
||||
m.sprandu(100, 200, 0.1);
|
||||
@@ -2865,7 +2865,7 @@ TEST_CASE("spmat_div_test")
|
||||
|
||||
|
||||
// Check that sparse % (sparse + eps) works. (and also for (sparse - eps) and (eps - sparse).
|
||||
TEST_CASE("spmat_schur_test")
|
||||
TEST_CASE("spmat_schur_test", "[spmat]")
|
||||
{
|
||||
sp_mat m;
|
||||
m.sprandu(100, 200, 0.1);
|
||||
@@ -2904,7 +2904,7 @@ TEST_CASE("spmat_schur_test")
|
||||
|
||||
|
||||
// Make sure this compiles and works.
|
||||
TEST_CASE("spmat_repeated_add_subtract")
|
||||
TEST_CASE("spmat_repeated_add_subtract", "[spmat]")
|
||||
{
|
||||
sp_mat m;
|
||||
m.sprandu(100, 200, 0.1);
|
||||
@@ -2941,7 +2941,7 @@ TEST_CASE("spmat_repeated_add_subtract")
|
||||
|
||||
// If we wrap an sp_mat() constructor around a (sparse + plus) it should force
|
||||
// evaluate into a sparse matrix.
|
||||
TEST_CASE("spmat_force_plus_minus_sparse")
|
||||
TEST_CASE("spmat_force_plus_minus_sparse", "[spmat]")
|
||||
{
|
||||
// We can't test that our desired optimization is used but we can test that it
|
||||
// compiles.
|
||||
@@ -2966,7 +2966,7 @@ TEST_CASE("spmat_force_plus_minus_sparse")
|
||||
|
||||
|
||||
// Test elementwise max().
|
||||
TEST_CASE("spmat_elementwise_max")
|
||||
TEST_CASE("spmat_elementwise_max", "[spmat]")
|
||||
{
|
||||
sp_mat m, n;
|
||||
m.sprandu(100, 200, 0.1);
|
||||
@@ -2986,7 +2986,7 @@ TEST_CASE("spmat_elementwise_max")
|
||||
|
||||
|
||||
// Test elementwise max() with a dense object.
|
||||
TEST_CASE("spmat_mat_elementwise_max")
|
||||
TEST_CASE("spmat_mat_elementwise_max", "[spmat]")
|
||||
{
|
||||
sp_mat m;
|
||||
mat n;
|
||||
@@ -3010,7 +3010,7 @@ TEST_CASE("spmat_mat_elementwise_max")
|
||||
|
||||
|
||||
// Test elementwise complex max().
|
||||
TEST_CASE("spmat_elementwise_max_cx")
|
||||
TEST_CASE("spmat_elementwise_max_cx", "[spmat]")
|
||||
{
|
||||
sp_cx_mat m, n;
|
||||
m.sprandu(100, 200, 0.1);
|
||||
@@ -3033,7 +3033,7 @@ TEST_CASE("spmat_elementwise_max_cx")
|
||||
|
||||
|
||||
// Test elementwise min().
|
||||
TEST_CASE("spmat_elementwise_min")
|
||||
TEST_CASE("spmat_elementwise_min", "[spmat]")
|
||||
{
|
||||
sp_mat m, n;
|
||||
m.sprandu(100, 200, 0.1);
|
||||
@@ -3053,7 +3053,7 @@ TEST_CASE("spmat_elementwise_min")
|
||||
|
||||
|
||||
// Test elementwise min() with a dense object.
|
||||
TEST_CASE("spmat_mat_elementwise_min")
|
||||
TEST_CASE("spmat_mat_elementwise_min", "[spmat]")
|
||||
{
|
||||
sp_mat m;
|
||||
mat n;
|
||||
@@ -3077,7 +3077,7 @@ TEST_CASE("spmat_mat_elementwise_min")
|
||||
|
||||
|
||||
// Test elementwise complex min().
|
||||
TEST_CASE("spmat_elementwise_min_cx")
|
||||
TEST_CASE("spmat_elementwise_min_cx", "[spmat]")
|
||||
{
|
||||
sp_cx_mat m, n;
|
||||
m.sprandu(100, 200, 0.1);
|
||||
@@ -3099,7 +3099,7 @@ TEST_CASE("spmat_elementwise_min_cx")
|
||||
|
||||
|
||||
// Test vectorise() on a matrix.
|
||||
TEST_CASE("spmat_vectorise_matrix")
|
||||
TEST_CASE("spmat_vectorise_matrix", "[spmat]")
|
||||
{
|
||||
sp_mat m;
|
||||
m.sprandu(10, 10, 0.1);
|
||||
@@ -3119,7 +3119,7 @@ TEST_CASE("spmat_vectorise_matrix")
|
||||
|
||||
|
||||
// Test vectorise() as an alias.
|
||||
TEST_CASE("spmat_vectorise_alias")
|
||||
TEST_CASE("spmat_vectorise_alias", "[spmat]")
|
||||
{
|
||||
sp_mat m;
|
||||
m.sprandu(10, 10, 0.1);
|
||||
@@ -3138,7 +3138,7 @@ TEST_CASE("spmat_vectorise_alias")
|
||||
|
||||
|
||||
// Test vectorise() with the dimension argument.
|
||||
TEST_CASE("spmat_vectorise_dimension")
|
||||
TEST_CASE("spmat_vectorise_dimension", "[spmat]")
|
||||
{
|
||||
sp_mat m;
|
||||
m.sprandu(10, 10, 0.1);
|
||||
@@ -3161,7 +3161,7 @@ TEST_CASE("spmat_vectorise_dimension")
|
||||
|
||||
|
||||
// Test vectorise() with an alias and a dimension argument.
|
||||
TEST_CASE("spmat_vectorise_dimension_alias")
|
||||
TEST_CASE("spmat_vectorise_dimension_alias", "[spmat]")
|
||||
{
|
||||
sp_mat m;
|
||||
m.sprandu(10, 10, 0.1);
|
||||
|
||||
+2
-2
@@ -21,7 +21,7 @@
|
||||
|
||||
using namespace arma;
|
||||
|
||||
TEST_CASE("sprow_shed_col_test")
|
||||
TEST_CASE("sprow_shed_col_test", "[sprow]")
|
||||
{
|
||||
|
||||
SpRow<int> d(10);
|
||||
@@ -47,7 +47,7 @@ TEST_CASE("sprow_shed_col_test")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("sprow_row_constructor_test")
|
||||
TEST_CASE("sprow_row_constructor_test", "[sprow]")
|
||||
{
|
||||
SpMat<double> m(100, 100);
|
||||
m.sprandu(100, 100, 0.3);
|
||||
|
||||
+23
-23
@@ -21,7 +21,7 @@
|
||||
|
||||
using namespace arma;
|
||||
|
||||
TEST_CASE("sp_subview_tests")
|
||||
TEST_CASE("sp_subview_tests", "[spsubview]")
|
||||
{
|
||||
Mat<double> ref(4,4);
|
||||
ref.eye(4,4);
|
||||
@@ -78,7 +78,7 @@ TEST_CASE("sp_subview_tests")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("sp_subview_const_test")
|
||||
TEST_CASE("sp_subview_const_test", "[spsubview]")
|
||||
{
|
||||
Mat<double> ref(4, 4);
|
||||
ref.eye(4, 4);
|
||||
@@ -102,7 +102,7 @@ TEST_CASE("sp_subview_const_test")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("sp_subview_multiplication_test")
|
||||
TEST_CASE("sp_subview_multiplication_test", "[spsubview]")
|
||||
{
|
||||
// Ensure matrix multiplication with subviews works correctly.
|
||||
SpMat<double> a(2, 5);
|
||||
@@ -153,7 +153,7 @@ TEST_CASE("sp_subview_multiplication_test")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("sp_subview_multiplication_test_2")
|
||||
TEST_CASE("sp_subview_multiplication_test_2", "[spsubview]")
|
||||
{
|
||||
// Ensure matrix multiplication with subviews works correctly.
|
||||
SpMat<double> a(4, 5);
|
||||
@@ -206,7 +206,7 @@ TEST_CASE("sp_subview_multiplication_test_2")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("sp_subview_unary_operators_test")
|
||||
TEST_CASE("sp_subview_unary_operators_test", "[spsubview]")
|
||||
{
|
||||
SpMat<int> a(3, 3);
|
||||
SpMat<int> b(5, 5);
|
||||
@@ -282,7 +282,7 @@ TEST_CASE("sp_subview_unary_operators_test")
|
||||
}
|
||||
|
||||
|
||||
TEST_CASE("sp_subview_mat_operator_tests")
|
||||
TEST_CASE("sp_subview_mat_operator_tests", "[spsubview]")
|
||||
{
|
||||
SpMat<double> a(6, 10);
|
||||
a(2, 2) = 2.0;
|
||||
@@ -410,7 +410,7 @@ TEST_CASE("sp_subview_mat_operator_tests")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("sp_subview_base_test")
|
||||
TEST_CASE("sp_subview_base_test", "[spsubview]")
|
||||
{
|
||||
SpMat<double> a(6, 10);
|
||||
a(2, 2) = 2.0;
|
||||
@@ -558,7 +558,7 @@ TEST_CASE("sp_subview_base_test")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("sp_subview_sp_mat_test")
|
||||
TEST_CASE("sp_subview_sp_mat_test", "[spsubview]")
|
||||
{
|
||||
SpMat<double> a(6, 10);
|
||||
a(2, 2) = 2.0;
|
||||
@@ -682,7 +682,7 @@ TEST_CASE("sp_subview_sp_mat_test")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("sp_subview_sp_subview_tests")
|
||||
TEST_CASE("sp_subview_sp_subview_tests", "[spsubview]")
|
||||
{
|
||||
SpMat<double> a(6, 10);
|
||||
a(2, 2) = 2.0;
|
||||
@@ -822,7 +822,7 @@ TEST_CASE("sp_subview_sp_subview_tests")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("sp_subview_iterators_test")
|
||||
TEST_CASE("sp_subview_iterators_test", "[spsubview]")
|
||||
{
|
||||
SpMat<double> b(5, 5);
|
||||
b(0, 0) = 1.0;
|
||||
@@ -973,7 +973,7 @@ TEST_CASE("sp_subview_iterators_test")
|
||||
}
|
||||
|
||||
|
||||
TEST_CASE("sp_subview_row_iterators_test")
|
||||
TEST_CASE("sp_subview_row_iterators_test", "[spsubview]")
|
||||
{
|
||||
SpMat<double> b(5, 5);
|
||||
b(0, 0) = 1.0;
|
||||
@@ -1119,7 +1119,7 @@ TEST_CASE("sp_subview_row_iterators_test")
|
||||
}
|
||||
|
||||
|
||||
TEST_CASE("sp_subview_sp_base_add_subtract_modulo")
|
||||
TEST_CASE("sp_subview_sp_base_add_subtract_modulo", "[spsubview]")
|
||||
{
|
||||
SpMat<double> m;
|
||||
m.sprandu(100, 100, 0.1);
|
||||
@@ -1176,7 +1176,7 @@ TEST_CASE("sp_subview_sp_base_add_subtract_modulo")
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("sp_subview_hadamard")
|
||||
TEST_CASE("sp_subview_hadamard", "[spsubview]")
|
||||
{
|
||||
SpMat<double> x;
|
||||
x.sprandu(100, 100, 0.1);
|
||||
@@ -1199,7 +1199,7 @@ TEST_CASE("sp_subview_hadamard")
|
||||
}
|
||||
|
||||
|
||||
TEST_CASE("sp_subview_subviews_test")
|
||||
TEST_CASE("sp_subview_subviews_test", "[spsubview]")
|
||||
{
|
||||
SpMat<double> m(20, 20);
|
||||
m.sprandu(20, 20, 0.3);
|
||||
@@ -1345,7 +1345,7 @@ TEST_CASE("sp_subview_subviews_test")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("sp_subview_assignment_sp_base")
|
||||
TEST_CASE("sp_subview_assignment_sp_base", "[spsubview]")
|
||||
{
|
||||
mat d(51, 51);
|
||||
d.fill(7.0); // Why not?
|
||||
@@ -1366,7 +1366,7 @@ TEST_CASE("sp_subview_assignment_sp_base")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("sp_subview_addition_sp_base")
|
||||
TEST_CASE("sp_subview_addition_sp_base", "[spsubview]")
|
||||
{
|
||||
mat d(51, 51);
|
||||
d.fill(7.0); // Why not?
|
||||
@@ -1386,7 +1386,7 @@ TEST_CASE("sp_subview_addition_sp_base")
|
||||
}
|
||||
|
||||
|
||||
TEST_CASE("sp_subview_subtraction_sp_base")
|
||||
TEST_CASE("sp_subview_subtraction_sp_base", "[spsubview]")
|
||||
{
|
||||
mat d(51, 51);
|
||||
d.fill(7.0); // Why not?
|
||||
@@ -1407,7 +1407,7 @@ TEST_CASE("sp_subview_subtraction_sp_base")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("sp_subview_schur_sp_base")
|
||||
TEST_CASE("sp_subview_schur_sp_base", "[spsubview]")
|
||||
{
|
||||
mat d(51, 51);
|
||||
d.fill(7.0); // Why not?
|
||||
@@ -1428,7 +1428,7 @@ TEST_CASE("sp_subview_schur_sp_base")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("sp_subview_division_sp_base")
|
||||
TEST_CASE("sp_subview_division_sp_base", "[spsubview]")
|
||||
{
|
||||
mat d(51, 51);
|
||||
d.fill(7.0); // Why not?
|
||||
@@ -1452,7 +1452,7 @@ TEST_CASE("sp_subview_division_sp_base")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("sp_subview_row_iterator_constructor")
|
||||
TEST_CASE("sp_subview_row_iterator_constructor", "[spsubview]")
|
||||
{
|
||||
// Create a row iterator with an exact position.
|
||||
Mat<double> tmp =
|
||||
@@ -1490,7 +1490,7 @@ TEST_CASE("sp_subview_row_iterator_constructor")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("sp_subview_row_iterator_test_1")
|
||||
TEST_CASE("sp_subview_row_iterator_test_1", "[spsubview]")
|
||||
{
|
||||
Mat<double> tmp =
|
||||
{ { 1.1, 1.2, 1.3, 1.4, 1.5 },
|
||||
@@ -1516,7 +1516,7 @@ TEST_CASE("sp_subview_row_iterator_test_1")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("sp_subview_row_iterator_test_2")
|
||||
TEST_CASE("sp_subview_row_iterator_test_2", "[spsubview]")
|
||||
{
|
||||
// Make sure the loop terminates.
|
||||
Mat<double> tmp =
|
||||
@@ -1541,7 +1541,7 @@ TEST_CASE("sp_subview_row_iterator_test_2")
|
||||
|
||||
|
||||
|
||||
TEST_CASE("sp_subview_n_nonzero_test")
|
||||
TEST_CASE("sp_subview_n_nonzero_test", "[spsubview]")
|
||||
{
|
||||
sp_mat x;
|
||||
x.sprandu(100, 100, 0.3);
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
// Copyright 2025 Ryan Curtin (http://www.ratml.org/)
|
||||
//
|
||||
// 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.
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
#include <armadillo>
|
||||
|
||||
#if defined(ARMA_HAVE_FP16)
|
||||
#define TEST_FLOAT_TYPES double, float, fp16
|
||||
#else
|
||||
#define TEST_FLOAT_TYPES double, float
|
||||
#endif
|
||||
|
||||
#define TEST_CX_FLOAT_TYPES cx_double, cx_float
|
||||
Reference in New Issue
Block a user