[Date Index]
[Thread Index]
[Author Index]
Re: Compile for different parameter types
*To*: mathgroup at smc.vnet.net
*Subject*: [mg97450] Re: Compile for different parameter types
*From*: Szabolcs Horvát <szhorvat at gmail.com>
*Date*: Fri, 13 Mar 2009 04:52:46 -0500 (EST)
*References*: <gpacur$mu6$1@smc.vnet.net>
Sebastian Meznaric wrote:
> Say I want to have a compiled function that works for tensors of rank
> 2 or 3. Let's call this function f. Then
>
> f = Compile[{{A,_Real,2},{B,_Real,2}}, expr]
>
> would make function f for tensor of rank 2. Is it possible to expand
> this function to work for both tensors of rank 2 and 3? Eventually I
> would like to obtain a compiled function that works for a wide (but
> limited) range of combinations of tensor ranks. All tensor ranks are
> less than 15 so we are talking about at most 15^2=225 combinations.
>
You could use a proxy function that checks the type of the argument, and
dispatches the task to the appropriate compiled function.
f[x_Integer] := fInteger[x]
(* fInteger is optimized for working with Integers *)
f[x_Real] := fReal[x]
Something like that.
Use Depth to obtain the tensor rank.
f[t_?TensorQ] /; Depth[t] == 4 := ...
etc.
Prev by Date:
**Re: opening notebooks in mathematica player instead of mathematica**
Next by Date:
**Re: opening notebooks in mathematica player instead of mathematica**
Previous by thread:
**Re: Compile for different parameter types**
Next by thread:
**Re: Compile for different parameter types**
| |