octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

How to realize 'all (isfinite (x)(:))' in C++


From: Lukas Reichlin
Subject: How to realize 'all (isfinite (x)(:))' in C++
Date: Fri, 13 Nov 2015 16:18:53 +0100

Dear Octave community,

In the control package, there are a couple of helper functions written in C++, 
one of these functions is 'is_real_matrix' [1]. In an attempt to improve 
argument checks (see bug #46330 [2] for the motivation), I would like to extend 
'is_real_matrix' in a way such that the revised function works like

        is_real_matrix (x) && all (isfinite (x)(:))

To do so, I need to realize the expression 'all (isfinite (x)(:))' in C++ and 
add it to the if-statement below (this if-statement is part of 
is_real_matrix.cc [1])

            if (args(i).ndims () != 2 || ! args(i).is_numeric_type ()
                || ! args(i).is_real_type ())

I know that Octave's 'isfinite' function is defined in 
'libinterp/corefcn/mappers.cc' and boils down to

    retval = args(0).finite ();

Now my problem is that 'args(i).finite ()' works element-wise but I need the 
answer matrix-wise. So I had a look at function 'all' in 
'libinterp/corefcn/data.cc', which is a one-liner:

  ANY_ALL (all);

ANY_ALL is a macro defined just the lines before 'all'. I have to admit that 
I'm not proficient in C macros.

OK then, I could try to realize 'all (isfinite (x)(:))' as

        ANY_ALL (ANY_ALL (args(i).finite ()))

but it would look like bad style to me and I'm convinced that there is a more 
elegant solution to this problem. So what would be the/a proper way to realize 
'all (isfinite (x)(:))' in C++?

Thanks in advance and best regards,
Lukas


[1]
http://sourceforge.net/p/octave/control/ci/default/tree/src/is_real_matrix.cc

[2]
http://savannah.gnu.org/bugs/?46330






reply via email to

[Prev in Thread] Current Thread [Next in Thread]