octave-maintainers
[Top][All Lists]
Advanced

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

Re: problem with sum (...)


From: Ben Abbott
Subject: Re: problem with sum (...)
Date: Mon, 5 Nov 2007 21:28:48 -0500


On Nov 5, 2007, at 10:16 AM, David Bateman wrote:

Ben Abbott wrote:
I've encountered a problem with the internal function sum(), using 2.9.16

The test below produces the correct result

    sum ([true, false])
    ans = 1

The result is *not* logical (which is consistent with Matlab).

    islogical (sum ([true, false]))
    ans = 0

However, when asked to return the result in the native format of the
inputs  (as Matlab does) ...

    islogical (sum ([true, false], 'native'))
    error: invalid conversion from string to real scalar
    error: octave_base_value::int_value (): wrong type argument
`sq_string'
    error: evaluating argument list element number 1

The "native" argument is not implemented and so what is happening above
is that the argument 'native' is taken as defining the dimension along
which to add the values..


While Matlab produces this result ans=1, which is consistent with
Octave when the test is modified as ...

    islogical (logical (sum ([true, false])))
    ans = 1

When the arguments to sum are characters and accompanied by 'native',
Matlab  produces an error.

I'm not up to c++ programing. So I will not be any help in modifying
the internal function, sum ().

I don't see why matlab should produce an error here.. Adding character
values should be legal, though perhaps a dumb thing to do.. Equally I
don't see why matlab  chose to limit this argument only to the "sum"
function and not also include the "cumsum", "prod", etc functions as
well. In any case consider the attached patch that adds this
functionality to "sum".. Perhaps the other data reduction operators
should also include this functionality?

I'm also bewildered why Mathworks didn't include the 'native' option for other functions ... even more confusing to me is why 'native' isn't the default.

I have no opinion on providing this functionality to the other functions in Octave.

I'm attempting to apply the patch and compile (I'm new to this) ... I'll not have a chance to check on its success until morning. However, your examples produced identical results under Matlab 7.3.0.





reply via email to

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