Sample Entropy

View: New views
2 Messages — Rating Filter:   Alert me  

Sample Entropy

by Paul Koufalas-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Fixed a bug that caused Octave to crash when epoch length M != 2.






Paul.
_______________________________________________
Octave-sources mailing list
Octave-sources@...
https://www.cae.wisc.edu/mailman/listinfo/octave-sources

sampen.cc (15K) Download Attachment

Re: Sample Entropy

by David Bateman :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Paul Koufalas wrote:
> Fixed a bug that caused Octave to crash when epoch length M != 2.
>

Paul,

Code like this

    if ((run = (int *) calloc(n, sizeof(int))) == NULL)
        exit(1);
    if ((run1 = (int *) calloc(n, sizeof(int))) == NULL)
        exit(1);

is not a good idea in Octave for many reasons.. Firstly, a user function
should never force an exit from Octave. Secondly, if the exits are
removed you leave memory allocated and probably don't remove it. Thirdly
the use of malloc and family are discouraged in C++ as they bypass the
C++ garbage collector. The Octave way of writing the above would be

OCTAVE_LOCAL_BUFFER (int, run, n);
OCTAVE_LOCAL_BUFFER (int, run1, n);

and the C++ garbage collector will clean up the allocated memory, so no
need to free it at the end of your program. I can see a reason of
writing the code with calloc if this code is shared with a C library
elsewhere. However in that case it might be better to have a macro like

#ifdef OCTAVE_SOURCE
#define mycalloc(typ, var, sz) OCTAVE_LOCAL_BUFFER (typ, var, sz)
#define myfree(var)
#else
#define mycalloc(typ, var, sz) var = (typ *) calloc (sz, sizeof(typ))
#define myfree(var) free(var)
#endif

and then use them.

Cheers
David

--
David Bateman                                David.Bateman@...
Motorola Labs - Paris                        +33 1 69 35 48 04 (Ph)
Parc Les Algorithmes, Commune de St Aubin    +33 6 72 01 06 33 (Mob)
91193 Gif-Sur-Yvette FRANCE                  +33 1 69 35 77 01 (Fax)

The information contained in this communication has been classified as:

[x] General Business Information
[ ] Motorola Internal Use Only
[ ] Motorola Confidential Proprietary

_______________________________________________
Octave-sources mailing list
Octave-sources@...
https://www.cae.wisc.edu/mailman/listinfo/octave-sources
LightInTheBox - Buy quality products at wholesale price