Yet Different
Both SPL and MATLAB are free-form and the examples above show the
typical formatting styles of each language. The comment block
after the function declaration in a M file is displayed when the
user types
help detrend. SPL displays the free-form
text between the
#if @HELP_DETREND and
#endif
block. This block can be placed anywhere within the SPL
file.
detrend removes the least squares line from a series
or table. The function also has an optional argument to specify
that only the mean value should be removed. This optional argument
is detected in MATLAB by counting the number of input arguments
with
nargin. SPL uses the C/C++ like
argc to indicate the number of input
parameters.
Matrix vs Series Based Solution
Because MATLAB is matrix-based and series are stored in row form,
row vectors must be transposed into columns. In fact, operators
such as * and / actually perform matrix multiplication and
inversion. Because SPL is
series-based, row transpositions
are not required and mathematical operators work in the way you
would expect. SPL includes the explicit operators
*^ and
\^ to multiply and solve matrices.
If the optional argument is set to 1, the mean value of each column
is removed by forming a table of the mean values and subtracting it
from the data. MATLAB forms the table by creating a matrix of all
ones and performing a matrix multiply. SPL simply subtracts the
mean value of each column from the corresponding column.
The linear trend is removed by forming a least squares line.
Again, MATLAB resorts to matrix operations where SPL uses the
linreg function.
Although both routines accomplish the same goal, MATLAB approaches
the problem from a matrix point of view, where SPL offers a
series-based solution. Each approach has its advantages, but for
problems that involve single or multi-column data series, SPL can
result in clearer, more direct code.
M File Memory Limitations
All arrays in MATLAB are limited by the amount of physical memory.
Because MATLAB relies on the operating system's general purpose
implementation of virtual memory, if an array size exceeds the
available memory, calculations produce errors or grind to a halt if
a memory page is swapped to disk.
Virtual Series Management
SPL employs a optimized method called virtual series management.
Each series and each column of an array is limited only by
available disk space. If the series size exceeds available memory,
SPL automatically uses hard disk storage. Because virtual series
management is optimized for series processing, this method is much
faster and more robust than general purpose operating system page
swapping. The size of a series kept in memory is adjustible,
allowing users to optimize processing based on system memory. With
SPL, the memory footprint of large data series is small enough to
bypass slow operating system page swapping, but computation is fast
due to virtual data handling designed specifically for series
processing. Thus, SPL is ideally suited for manipulating any
number of very large data series.
More M File Issues
Because of the mixed heritage of the MATLAB language, several potentially
confusing ambiguities persist.
For example, the MATLAB * operator actually performs a matrix
multiply. A common expression like:
would perform matrix multiplication if a and b are arrays or
a standard multiply if either variable is a scalar. A careful
reading of the code is required to establish the specific
meaning of this simple expression.
SPL preserves the standard meaning of * and introduces the *^
operator for explicit matrix multiplication. Thus,
is always a standard multiplication whereas
is always a matrix multiplication. The intent of either expression
is immediately obvious.
Further, the MATLAB expression:
could refer to element
x of array
f or function
f called with argument
x. Again, a careful reading of the
code is required to disambiguate the two possible meanings.
In SPL as well as C/C++,
is always a function call and
is always an array reference. The intent is immediately clear and consistent
with the C/C++ family of modern programming languages.
C/C++ Style Syntax
In fact, SPL borrows so much of its syntax from C/C++ that many
C/C++ programs can be loaded directly as SPL routines! For example,
SPL supports C/C++ operators such as ++, --, +=, -=, /=, *= %=, ==,
!=, >>, <<, >>=, <<=, ||, && and scalar
pointers. Looping and iteration constructs such as
for,
while, do while, if, else, switch, goto work exactly as they
do in C/C++. Array construction also mimics the C/C++ syntax. SPL
also includes a full C/C++ like preprocessor:
#if, #ifdef,
#elif, #endif, #include, #define, #undef.
Useful Constructs
But SPL also borrows some good ideas from MATLAB. Matrix operators
such as matrix multiply
*^, divide
\^ and transpose ' are
supported. Powerful array addressing constructs such range
specifiers
1..10, array assignments
A[1..10] = 5, multiple return
values
(a, b) = f(x), automatic loading of SPL routines and
built-in help syntax are provided.
A simple table gives
a brief summary of the
operators and syntax supported by MATLAB, C/C++ and
SPL.
Convert M Files to SPL
Finally, if you need to convert your M files into SPL routines, the
MathWorks offers a MATLAB-to-C conversion utility. Because SPL
is so similar to C/C++, you can also use this utility as a great
shortcut for converting M files into SPL functions for use in
DADiSP.
(1) MATLAB is a registered trademark of The MathWorks, Inc.