View Raw SPL
/*****************************************************************************
* *
* ONES.SPL Copyright (C) 1997-2006 DSP Development Corporation *
* All Rights Reserved *
* *
* Author: Randy Race *
* *
* Synopsis: Returns an array of all ones *
* *
* Revisions: 9 Jun 1997 RRR Creation *
* 14 Feb 2006 RRR use builtin gvalarray for speed *
* *
*****************************************************************************/
#include
#if @HELP_ONES
ONES
Purpose: Creates an array of all ones
Syntax: ONES(numrows, numcols, dx, dy)
numrows - an integer specifying the number of rows
numcols - an optional integer for the number columns (default 1)
dx - an optional real, the delta X value. Defaults to 1.0.
dy - an optional real, the delta Y value. Defaults to 1.0.
Returns: A series or array
Example:
Ones(3)
returns the series {1, 1, 1}
Ones(3, 2)
returns the 3x2 array {{1, 1},
{1, 1},
{1, 1}}
Remarks:
Ones(size(A)) returns a array of all ones with same dimension
as A
See Also
Gline
Ravel
Size
Zeros
#endif
/* generate a series or array of all ones */
ones(a, b, dx, dy)
{
local nr, nc, out;
if (argc < 4)
{
if (argc < 3) dx = 1.0;
dy = 1.0;
}
if (argc > 1)
{
/* e.g. ones(10, 3) */
if (isscalar(a) && isscalar(b))
{
/* convert to ints */
a = castint(a);
b = castint(b);
if (a <= 0 || b <= 0)
{
/* empty series */
return({});
}
else
{
out = gvalarray(1.0, a, b);
setdeltax(out, dx);
}
setdeltay(out, dy);
return(out);
}
else
{
error("ones - series or number required");
}
}
else
{
if (argc < 1) return(1);
if (isarray(a))
{
/* series argument - get size */
(nr, nc) = size(a);
if (nr == 2 && nc == 1)
{
/*
* assume series came from size function,
* e.g. ones(size(a))
*/
b = int(a[2]);
a = int(a[1]);
}
else
{
/* e.g. ones(x) - obsolete */
dx = deltax(a);
dy = deltay(a);
a = nr;
b = nc;
}
}
else if (isscalar(a))
{
/* convert to ints */
a = castint(a);
b = a;
}
else
{
error("ones - series or number required");
}
if (a * b == 0)
{
/* empty series */
out = {};
}
else
{
out = gvalarray(1.0, a, b);
setdeltax(out, dx);
}
setdeltay(out, dy);
return(out);
}
}