Spin multidimensional arrays
bjdav5
Posts: 1
Hi
I am trying to compile spin containing a multidimensional array like this:
var
long weightsIH[noparse][[/noparse]numInputs][noparse][[/noparse]numHiddens]····
numInputs and numHiddens are declared as constants, such as
con
numInputs···· =·············· 3·····
numHiddens······ = 4····
and the compiler returns with the error:· expected "," or end of line.
Any help would be appreciated!
Thanks
I am trying to compile spin containing a multidimensional array like this:
var
long weightsIH[noparse][[/noparse]numInputs][noparse][[/noparse]numHiddens]····
numInputs and numHiddens are declared as constants, such as
con
numInputs···· =·············· 3·····
numHiddens······ = 4····
and the compiler returns with the error:· expected "," or end of line.
Any help would be appreciated!
Thanks
Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
JMH
-Phil
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Airspace V - international hangar flying!
www.airspace-v.com/ggadgets for tools & toys
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Cardinal Fang! Fetch the comfy chair.
For example, if you want a 16 x 16 array, you can generate indexes like this:
shifting ( multiplying by powers of 2) is much faster because the Propeller makes use of a barrel shifter that can shift any number of places with one instruction.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·"I have always wished that my computer would be as easy to use as my telephone.· My wish has come true.· I no longer know how to use my telephone."
- Bjarne Stroustrup
Post Edited (Ken Peterson) : 2/27/2009 12:33:28 PM GMT
TJ
Parallax does not have the resources to make significant changes to the Spin compiler like what would be required to add support for multiple dimensional arrays. They will be busy enough finishing the development of the Propeller II chip and making the basic changes to the Propeller Tool to support the changes to the instruction set, built-in register names, etc. Try the 3rd party (free) Spin compilers.
mpark's homespun compiler takes a format like ...
foo[noparse][[/noparse]a][noparse][[/noparse]c]
..and converts it into the equivalent spin bytecode, and while its a more convenient terminology to use it's no more efficient than doing it longhand.
In addition, homespun is the only compiler that supports this extension, so code written this way is not compatible with the Parallax compiler.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Cardinal Fang! Fetch the comfy chair.
http://obex.parallax.com/objects/317/
to study a comprehensive working solution for vector and matrix operations in SPIN. This driver uses the simple coding form for matrices as shown by virtuPIC.·In the demo·you can find examples such as the triad algorithm for your robot to figure out its least squares attitude solution from acceleration and magnetometer data, or even singular value decomposition of any arbitrary (real) [noparse][[/noparse]n x m] matrices. This later operation can be found only in advanced math packages.
When you setup your ANN application in matrix form, then the propagation from the input layer to the hidden neurons can be coded as simply as
Matrix_Multiply(@HiddenInput, @WeightsI_2_H, @InputValues, 4, 3, 3, 1)
Starting from a [noparse][[/noparse]3 by 1] column vector of the inputs for the neural network, you will get a [noparse][[/noparse]4 by 1] matrix, a column
vector 'HiddenInput' that represents the weighted input values for the hidden nonlinear, e.g. tanh, processing neurons.
After these processing elements did their job, i.e. create 'HiddenOutput' vector, the outcome values for the network can be obtained simply as
Matrix_Multiply(@OutputValues, @WeigthsH_2_O, @HiddenOutput, 2, 4, 4, 1)
where I supposed 2 output values. You can make simple Put and Get SPIN procedures to access individual i,j matrix elements, like
Put(@Mat, i, j) and Get(@Mat, i, j)
Similarly, the whole ANN backpropagation learning algorithm· can be programmed just·IN FEW LINES IN SPIN·ONLY using the FPU_Matrix_Driver.SPIN.