move classes

This commit is contained in:
conrad
2022-03-16 14:24:37 +10:00
parent cfdf1a84d7
commit 1795d9405d
8 changed files with 237 additions and 273 deletions
-2
View File
@@ -214,7 +214,6 @@ namespace arma
#include "armadillo_bits/op_log_det_bones.hpp"
#include "armadillo_bits/op_inv_gen_bones.hpp"
#include "armadillo_bits/op_inv_spd_bones.hpp"
#include "armadillo_bits/op_inv_rcond_bones.hpp"
#include "armadillo_bits/op_htrans_bones.hpp"
#include "armadillo_bits/op_max_bones.hpp"
#include "armadillo_bits/op_min_bones.hpp"
@@ -646,7 +645,6 @@ namespace arma
#include "armadillo_bits/op_log_det_meat.hpp"
#include "armadillo_bits/op_inv_gen_meat.hpp"
#include "armadillo_bits/op_inv_spd_meat.hpp"
#include "armadillo_bits/op_inv_rcond_meat.hpp"
#include "armadillo_bits/op_htrans_meat.hpp"
#include "armadillo_bits/op_max_meat.hpp"
#include "armadillo_bits/op_index_max_meat.hpp"
+26 -26
View File
@@ -61,31 +61,6 @@ inv
template<typename T1>
inline
typename enable_if2< is_supported_blas_type<typename T1::elem_type>::value, bool >::result
inv
(
Mat<typename T1::elem_type>& out_inv,
typename T1::pod_type& out_rcond,
const Base<typename T1::elem_type,T1>& X
)
{
arma_extra_debug_sigprint();
const bool status = op_inv_rcond::apply_direct_gen(out_inv, out_rcond, X.get_ref());
if(status == false)
{
out_inv.soft_reset();
arma_debug_warn_level(3, "inv(): matrix is singular");
}
return status;
}
template<typename T1>
arma_warn_unused
arma_inline
@@ -128,6 +103,31 @@ inv
template<typename T1>
inline
typename enable_if2< is_supported_blas_type<typename T1::elem_type>::value, bool >::result
inv
(
Mat<typename T1::elem_type>& out_inv,
typename T1::pod_type& out_rcond,
const Base<typename T1::elem_type,T1>& X
)
{
arma_extra_debug_sigprint();
const bool status = op_inv_gen_rcond::apply_direct(out_inv, out_rcond, X.get_ref());
if(status == false)
{
out_inv.soft_reset();
arma_debug_warn_level(3, "inv(): matrix is singular");
}
return status;
}
//
@@ -226,7 +226,7 @@ inv_sympd
{
arma_extra_debug_sigprint();
const bool status = op_inv_rcond::apply_direct_spd(out_inv, out_rcond, X.get_ref());
const bool status = op_inv_spd_rcond::apply_direct(out_inv, out_rcond, X.get_ref());
if(status == false)
{
@@ -60,6 +60,17 @@ class op_inv_gen_full
class op_inv_gen_rcond
: public traits_op_default
{
public:
template<typename T1>
inline static bool apply_direct(Mat<typename T1::elem_type>& out_inv, typename T1::pod_type& out_rcond, const Base<typename T1::elem_type,T1>& expr);
};
namespace inv_opts
{
struct opts
@@ -295,4 +295,98 @@ op_inv_gen_full::apply_tiny(Mat<eT>& X)
template<typename T1>
inline
bool
op_inv_gen_rcond::apply_direct(Mat<typename T1::elem_type>& out, typename T1::pod_type& out_rcond, const Base<typename T1::elem_type,T1>& expr)
{
arma_extra_debug_sigprint();
typedef typename T1::elem_type eT;
typedef typename T1::pod_type T;
out = expr.get_ref();
out_rcond = T(0);
arma_debug_check( (out.is_square() == false), "inv(): given matrix must be square sized" );
const uword N = out.n_rows;
if(is_op_diagmat<T1>::value || out.is_diagmat())
{
arma_extra_debug_print("op_inv_gen_rcond: detected diagonal matrix");
eT* colmem = out.memptr();
T max_abs_src_val = T(0);
T max_abs_inv_val = T(0);
for(uword i=0; i<N; ++i)
{
eT& out_ii = colmem[i];
const eT src_val = out_ii;
const eT inv_val = eT(1) / src_val;
if(src_val == eT(0)) { return false; }
out_ii = inv_val;
const T abs_src_val = std::abs(src_val);
const T abs_inv_val = std::abs(inv_val);
max_abs_src_val = (abs_src_val > max_abs_src_val) ? abs_src_val : max_abs_src_val;
max_abs_inv_val = (abs_inv_val > max_abs_inv_val) ? abs_inv_val : max_abs_inv_val;
colmem += N;
}
out_rcond = T(1) / (max_abs_src_val * max_abs_inv_val);
return true;
}
const strip_trimat<T1> strip(expr.get_ref());
const bool is_triu_expr = strip.do_triu;
const bool is_tril_expr = strip.do_tril;
const bool is_triu_mat = (is_triu_expr || is_tril_expr) ? false : ( trimat_helper::is_triu(out));
const bool is_tril_mat = (is_triu_expr || is_tril_expr) ? false : ((is_triu_mat) ? false : trimat_helper::is_tril(out));
if(is_triu_expr || is_tril_expr || is_triu_mat || is_tril_mat)
{
return auxlib::inv_tr_rcond(out, out_rcond, ((is_triu_expr || is_triu_mat) ? uword(0) : uword(1)));
}
#if defined(ARMA_OPTIMISE_SYMPD)
const bool try_sympd = (auxlib::crippled_lapack(out)) ? false : sympd_helper::guess_sympd(out);
#else
const bool try_sympd = false;
#endif
if(try_sympd)
{
arma_extra_debug_print("op_inv_gen_rcond: attempting sympd optimisation");
Mat<eT> tmp = out;
bool sympd_state = false;
const bool status = auxlib::inv_sympd_rcond(tmp, sympd_state, out_rcond, T(-1));
if(status) { out.steal_mem(tmp); return true; }
if((status == false) && (sympd_state == true)) { return false; }
arma_extra_debug_print("op_inv_gen_rcond: sympd optimisation failed");
// fallthrough if optimisation failed
}
return auxlib::inv_rcond(out, out_rcond);
}
//! @}
@@ -1,38 +0,0 @@
// SPDX-License-Identifier: Apache-2.0
//
// Copyright 2008-2016 Conrad Sanderson (http://conradsanderson.id.au)
// Copyright 2008-2016 National ICT Australia (NICTA)
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ------------------------------------------------------------------------
//! \addtogroup op_inv_rcond
//! @{
class op_inv_rcond
: public traits_op_default
{
public:
template<typename T1>
inline static bool apply_direct_gen(Mat<typename T1::elem_type>& out_inv, typename T1::pod_type& out_rcond, const Base<typename T1::elem_type,T1>& expr);
template<typename T1>
inline static bool apply_direct_spd(Mat<typename T1::elem_type>& out_inv, typename T1::pod_type& out_rcond, const Base<typename T1::elem_type,T1>& expr);
};
//! @}
@@ -1,207 +0,0 @@
// SPDX-License-Identifier: Apache-2.0
//
// Copyright 2008-2016 Conrad Sanderson (http://conradsanderson.id.au)
// Copyright 2008-2016 National ICT Australia (NICTA)
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ------------------------------------------------------------------------
//! \addtogroup op_inv_rcond
//! @{
template<typename T1>
inline
bool
op_inv_rcond::apply_direct_gen(Mat<typename T1::elem_type>& out, typename T1::pod_type& out_rcond, const Base<typename T1::elem_type,T1>& expr)
{
arma_extra_debug_sigprint();
typedef typename T1::elem_type eT;
typedef typename T1::pod_type T;
out = expr.get_ref();
out_rcond = T(0);
arma_debug_check( (out.is_square() == false), "inv(): given matrix must be square sized" );
const uword N = out.n_rows;
if(is_op_diagmat<T1>::value || out.is_diagmat())
{
arma_extra_debug_print("op_inv_rcond: detected diagonal matrix");
eT* colmem = out.memptr();
T max_abs_src_val = T(0);
T max_abs_inv_val = T(0);
for(uword i=0; i<N; ++i)
{
eT& out_ii = colmem[i];
const eT src_val = out_ii;
const eT inv_val = eT(1) / src_val;
if(src_val == eT(0)) { return false; }
out_ii = inv_val;
const T abs_src_val = std::abs(src_val);
const T abs_inv_val = std::abs(inv_val);
max_abs_src_val = (abs_src_val > max_abs_src_val) ? abs_src_val : max_abs_src_val;
max_abs_inv_val = (abs_inv_val > max_abs_inv_val) ? abs_inv_val : max_abs_inv_val;
colmem += N;
}
out_rcond = T(1) / (max_abs_src_val * max_abs_inv_val);
return true;
}
const strip_trimat<T1> strip(expr.get_ref());
const bool is_triu_expr = strip.do_triu;
const bool is_tril_expr = strip.do_tril;
const bool is_triu_mat = (is_triu_expr || is_tril_expr) ? false : ( trimat_helper::is_triu(out));
const bool is_tril_mat = (is_triu_expr || is_tril_expr) ? false : ((is_triu_mat) ? false : trimat_helper::is_tril(out));
if(is_triu_expr || is_tril_expr || is_triu_mat || is_tril_mat)
{
return auxlib::inv_tr_rcond(out, out_rcond, ((is_triu_expr || is_triu_mat) ? uword(0) : uword(1)));
}
#if defined(ARMA_OPTIMISE_SYMPD)
const bool try_sympd = (auxlib::crippled_lapack(out)) ? false : sympd_helper::guess_sympd(out);
#else
const bool try_sympd = false;
#endif
if(try_sympd)
{
arma_extra_debug_print("op_inv_rcond: attempting sympd optimisation");
Mat<eT> tmp = out;
bool sympd_state = false;
const bool status = auxlib::inv_sympd_rcond(tmp, sympd_state, out_rcond, T(-1));
if(status) { out.steal_mem(tmp); return true; }
if((status == false) && (sympd_state == true)) { return false; }
arma_extra_debug_print("op_inv_rcond: sympd optimisation failed");
// fallthrough if optimisation failed
}
return auxlib::inv_rcond(out, out_rcond);
}
template<typename T1>
inline
bool
op_inv_rcond::apply_direct_spd(Mat<typename T1::elem_type>& out, typename T1::pod_type& out_rcond, const Base<typename T1::elem_type,T1>& expr)
{
arma_extra_debug_sigprint();
typedef typename T1::elem_type eT;
typedef typename T1::pod_type T;
if(auxlib::crippled_lapack(out))
{
out.soft_reset();
out_rcond = T(0);
arma_stop_runtime_error("inv_sympd(): not available for complex matrices due to presence of incomplete LAPACK");
return false;
}
out = expr.get_ref();
out_rcond = T(0);
arma_debug_check( (out.is_square() == false), "inv_sympd(): given matrix must be square sized" );
if((arma_config::debug) && (auxlib::rudimentary_sym_check(out) == false))
{
if(is_cx<eT>::no ) { arma_debug_warn_level(1, "inv_sympd(): given matrix is not symmetric"); }
if(is_cx<eT>::yes) { arma_debug_warn_level(1, "inv_sympd(): given matrix is not hermitian"); }
}
const uword N = out.n_rows;
if(is_cx<eT>::yes)
{
arma_extra_debug_print("op_inv_rcond: checking imaginary components of diagonal elements");
const T tol = T(100) * std::numeric_limits<T>::epsilon(); // allow some leeway
const eT* colmem = out.memptr();
for(uword i=0; i<N; ++i)
{
const eT& out_ii = colmem[i];
const T out_ii_imag = access::tmp_imag(out_ii);
if(std::abs(out_ii_imag) > tol) { return false; }
colmem += N;
}
}
if(is_op_diagmat<T1>::value || out.is_diagmat())
{
arma_extra_debug_print("op_inv_rcond: detected diagonal matrix");
eT* colmem = out.memptr();
T max_abs_src_val = T(0);
T max_abs_inv_val = T(0);
for(uword i=0; i<N; ++i)
{
eT& out_ii = colmem[i];
const eT src_val = out_ii;
const eT inv_val = eT(1) / src_val;
if( (src_val == eT(0)) || (access::tmp_real(src_val) <= T(0)) ) { return false; }
out_ii = inv_val;
const T abs_src_val = std::abs(src_val);
const T abs_inv_val = std::abs(inv_val);
max_abs_src_val = (abs_src_val > max_abs_src_val) ? abs_src_val : max_abs_src_val;
max_abs_inv_val = (abs_inv_val > max_abs_inv_val) ? abs_inv_val : max_abs_inv_val;
colmem += N;
}
out_rcond = T(1) / (max_abs_src_val * max_abs_inv_val);
return true;
}
return auxlib::inv_sympd_rcond(out, out_rcond, T(-1));
}
//! @}
@@ -52,4 +52,15 @@ class op_inv_spd_full
class op_inv_spd_rcond
: public traits_op_default
{
public:
template<typename T1>
inline static bool apply_direct(Mat<typename T1::elem_type>& out_inv, typename T1::pod_type& out_rcond, const Base<typename T1::elem_type,T1>& expr);
};
//! @}
@@ -228,4 +228,99 @@ op_inv_spd_full::apply_tiny(Mat<eT>& out)
//
template<typename T1>
inline
bool
op_inv_spd_rcond::apply_direct(Mat<typename T1::elem_type>& out, typename T1::pod_type& out_rcond, const Base<typename T1::elem_type,T1>& expr)
{
arma_extra_debug_sigprint();
typedef typename T1::elem_type eT;
typedef typename T1::pod_type T;
if(auxlib::crippled_lapack(out))
{
out.soft_reset();
out_rcond = T(0);
arma_stop_runtime_error("inv_sympd(): not available for complex matrices due to presence of incomplete LAPACK");
return false;
}
out = expr.get_ref();
out_rcond = T(0);
arma_debug_check( (out.is_square() == false), "inv_sympd(): given matrix must be square sized" );
if((arma_config::debug) && (auxlib::rudimentary_sym_check(out) == false))
{
if(is_cx<eT>::no ) { arma_debug_warn_level(1, "inv_sympd(): given matrix is not symmetric"); }
if(is_cx<eT>::yes) { arma_debug_warn_level(1, "inv_sympd(): given matrix is not hermitian"); }
}
const uword N = out.n_rows;
if(is_cx<eT>::yes)
{
arma_extra_debug_print("op_inv_spd_rcond: checking imaginary components of diagonal elements");
const T tol = T(100) * std::numeric_limits<T>::epsilon(); // allow some leeway
const eT* colmem = out.memptr();
for(uword i=0; i<N; ++i)
{
const eT& out_ii = colmem[i];
const T out_ii_imag = access::tmp_imag(out_ii);
if(std::abs(out_ii_imag) > tol) { return false; }
colmem += N;
}
}
if(is_op_diagmat<T1>::value || out.is_diagmat())
{
arma_extra_debug_print("op_inv_spd_rcond: detected diagonal matrix");
eT* colmem = out.memptr();
T max_abs_src_val = T(0);
T max_abs_inv_val = T(0);
for(uword i=0; i<N; ++i)
{
eT& out_ii = colmem[i];
const eT src_val = out_ii;
const eT inv_val = eT(1) / src_val;
if( (src_val == eT(0)) || (access::tmp_real(src_val) <= T(0)) ) { return false; }
out_ii = inv_val;
const T abs_src_val = std::abs(src_val);
const T abs_inv_val = std::abs(inv_val);
max_abs_src_val = (abs_src_val > max_abs_src_val) ? abs_src_val : max_abs_src_val;
max_abs_inv_val = (abs_inv_val > max_abs_inv_val) ? abs_inv_val : max_abs_inv_val;
colmem += N;
}
out_rcond = T(1) / (max_abs_src_val * max_abs_inv_val);
return true;
}
bool is_sympd_junk = false;
return auxlib::inv_sympd_rcond(out, is_sympd_junk, out_rcond, T(-1));
}
//! @}