View Raw SPL
/*****************************************************************************
* *
* NUMEL.SPL Copyright (C) 2002-2020 DSP Development Corporation *
* All Rights Reserved *
* *
* Author: Randy Race *
* *
* Synopsis: Total number of elements *
* *
* Revisions: 13 Aug 2002 RRR Creation *
* 26 Nov 2020 RRR collength optimization *
* *
*****************************************************************************/
#include
#if @HELP_NUMEL
NUMEL
Purpose: Returns the total number of array elements
Syntax: NUMEL(a)
a - Optional, an array. Defaults to the current
Window.
Returns: An integer, the total number of array elements.
Example:
a = rand(20, 3)
numel(a) == 60
b = {{1..10, 2, 1..2}}
numel(b) == 13
Remarks:
For a series, NUMEL(a) is equivalent to LENGTH(a).
See Also:
Collength
Length
Size
#endif
/* total number of elements */
numel(a)
{
local n;
/* use current series if no input */
if (argc < 1)
{
if (numrows(w0) == 0)
{
return(0);
}
a = refseries();
}
if (not(isarray(a))) a = castseries(a);
n = isempty(a) ? 0 : castint(max(collength(a, 3)));
return(n);
}