MathGroup Archive 2010

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

Search the Archive

Re: Must tell Compile that Clip returns a number.

  • To: mathgroup at smc.vnet.net
  • Subject: [mg107727] Re: [mg107712] Must tell Compile that Clip returns a number.
  • From: DrMajorBob <btreat1 at austin.rr.com>
  • Date: Thu, 25 Feb 2010 01:50:05 -0500 (EST)
  • References: <201002241119.GAA22733@smc.vnet.net>
  • Reply-to: drmajorbob at yahoo.com

Your Clip example is NOT real valued, particularly when it's DOING  
anything.

For instance:

Clip[1.5, {0, 1}]

1

That's an Integer, not a Real.

Bobby

On Wed, 24 Feb 2010 05:19:36 -0600, asdf qwerty <bradc355113 at yahoo.com>  
wrote:

> (v7.0.1) I don't know whether this would be considered a bug or not,
> but it took me a bit to figure out what was going on, so someone else
> might find it useful.
>
> For some reason, Compile seems to expect Clip to return a list. (Maybe
> because it takes a list argument.) For example:
>
> In[1]:= Compile[{x}, Clip[x, {0, 1}]][0]
> CompiledFunction::cfte:
>    Compiled expression 0. should be a rank 1 tensor of
>     machine-size real numbers.
> CompiledFunction::cfex:
>    Could not complete external evaluation at instruction 3; proceeding
> with
>      uncompiled evaluation.
> Out[1]= 0
>
> A workaround is to use Compile's third argument to tell it that any
> expression with head Clip will evaluate to a single number:
>
> In[2]:= Compile[{x}, Clip[x, {0, 1}], {{_Clip, _Real}}][0]
> Out[2]= 0.
>


-- 
DrMajorBob at yahoo.com


  • Prev by Date: Re: NDSolve with Boundary Condition
  • Next by Date: Re: adding graphics and calibration to plot3d
  • Previous by thread: Custom ContourLabels in Contour Plots
  • Next by thread: Re: Must tell Compile that Clip returns a number.