Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
1999
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 1999

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Change Rank in Compile

  • To: mathgroup at smc.vnet.net
  • Subject: [mg16057] Re: Change Rank in Compile
  • From: Paul Abbott <paul at physics.uwa.edu.au>
  • Date: Tue, 23 Feb 1999 03:45:16 -0500
  • Organization: University of Western Australia
  • References: <7ao4bi$s1u@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Peter Klamser wrote:
 
> Can I change Rank?
> 
> sum$compiled=
>   Compile[{{v,_Real,10}},
>     Block[{i=1,s=0.0,x=0.0},s=0.0;Do[x=Take[v,i];s=s+x 2,{i,10}]]]

I don't fully understand what you are tring to do with this code but I
think you should have a look at FoldList.  E.g., to compute cumulative
vector sums, you can use

	FoldList[Plus, {0, 0}, {{0, 1}, {1, 2}}]

and I think that, essentially, this is what you are after.

> gives the error message
> 
> Compile::"cset":
>     "Variable \!\(x\) of type \!\({\"_Real\", 0}\) encountered in
> assignment \
> of type \!\({\"_Real\", 10}\)."

The assignment x=0.0 implicitly makes the variable x of type _Real. 
However, the assignment x=Take[v,i] means that x is a List.

One point: before even trying to compile a Module it should work as a
Module -- and, if I make v a vector of Length 10, your code does not
work.

It might be a good idea to include sample input and output so that
others can follow exactly what you are trying to do.

Cheers,
	Paul

____________________________________________________________________ 
Paul Abbott                                   Phone: +61-8-9380-2734
Department of Physics                           Fax: +61-8-9380-1014
The University of Western Australia           
Nedlands WA  6907                     mailto:paul at physics.uwa.edu.au 
AUSTRALIA                        http://www.physics.uwa.edu.au/~paul

            God IS a weakly left-handed dice player
____________________________________________________________________


  • Prev by Date: Re: Mathlink and JAVA
  • Next by Date: Re: Simplify Log[ab] - Log[b] to Log[a] ?
  • Previous by thread: Change Rank in Compile
  • Next by thread: Re: Change Rank in Compile