MathGroup Archive 2001

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

Search the Archive

errors with Compile?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg27940] errors with Compile?
  • From: Otto Linsuain <linsuain+ at andrew.cmu.edu>
  • Date: Sat, 24 Mar 2001 15:15:45 -0500 (EST)
  • Sender: owner-wri-mathgroup at wolfram.com

Dear group:

I find that when using a compiled function to define another, I often
get error messages related to the rank of the tensors involved.
Mathematica automatically switches to the uncompiled definitions and
carries out the calculations correctly, but precious time is wasted.

Here is an idea of what I am talking about:

f1=Compile[ {{x,_Real,1}},  Take[x,1] ];

f2=Compile[{{x,_Real,1}}, f1[x]^2 ];

In this case  f2[ Table[Random[], {5} ]  goes through smoothly. And it
should because a list of 5 numbers is a rank 1 tensor.

Now consider the slightly different situation:

f1=Compile[ {{x,_Real,1}},  Part[x,1] ];  (Notice Part instead of Take)

f2=Compile[{{x,_Real,1}}, f1[x]^2 ];

In this case, however,  f2[ Table[Random[], {5} ] complains about the
rank of the argument. One can see that after the list of five numbers is
proccessed through f1 (in the second case) what comes out is a simple
number (as opposed to a simple number WITH THE HEAD List, as it was in
the first case). Now, I agree that a simple number is not a rank 1
tensor, unless it has the head List, but what was fed to f2 was a list
of five numbers, which IS a rank 1 tensor. Why should f2 go by what
comes out of f1, and not by what is fed to it? Is this a feature or a
bug?

Thanks, Otto Linsuain.

P.S. I have further found other cases where one would get an error
message either way. I mean if you feed f2 what its variable description
specifies, it complains because what returns from f1 is not
satisfactory. It you feed it a different rank tensor, so that what
returns from f1 becomes acceptable, then it complains because that is
not the rank of tensor specified in its variable description. Quite a
mess at the end of the day.


  • Prev by Date: Re: Q: Print in different colors
  • Next by Date: RE: Q: Print in different colors
  • Previous by thread: Failure to simplify logical expressions
  • Next by thread: Re: DSolve bug in Mathematica version 4.1?,