Accessing intermediate armadillo object member without naming it [C++]

  armadillo, c++

Using the armadillo library, one may write

// Log if this is non-finite
if ( ! averages.is_finite() )
{
    arma::uvec nonfinites = arma::find_nonfinite( averages );
    PI_LOG_WARN( "There are ",  nonfinites.n_elem, " of ", averages.n_elem,
            " non-finite elements in the band border averages of the input signal." );
}

I’d like to simplify this without using the nonfinites intermediate vector, like so:

    PI_LOG_WARN( "There are ",  (arma::find_nonfinite( averages )).n_elem, " of ", averages.n_elem,
            " non-finite elements in the band border averages of the input signal." );

But I get a g++ error message

/path/to/file.cpp:901:71: error: ‘arma::enable_if2<true, const arma::mtOp<long long un
signed int, arma::Mat<double>, arma::op_find_nonfinite> >::result’ has no member named ‘n_elem’
         PI_LOG_WARN( "There are ", (arma::find_nonfinite( averages )).n_elem, " of ", averages.n_elem,

I’m unsure if I’m dealing with a general C++ issue or if the arma library function return type is not an arma::uvec (as indicated by the g++ error). which actually has the member n_elem. Is it required to convert the returned object into an uvec first?

Many thanks in advance for any explanation!

Source: Windows Questions C++

LEAVE A COMMENT