Re: How do I DistributeDefinitions inside a function?
- To: mathgroup at smc.vnet.net
- Subject: [mg97832] Re: How do I DistributeDefinitions inside a function?
- From: Raffy <raffy at mac.com>
- Date: Mon, 23 Mar 2009 04:03:03 -0500 (EST)
- References: <gq2f1b$ef9$1@smc.vnet.net> <gq5503$813$1@smc.vnet.net>
On Mar 22, 3:47 am, Jens-Peer Kuska <ku... at informatik.uni-leipzig.de>
wrote:
> Hi,
>
> and
>
> LeaveOneOut[f_Symbol, items_] := (
> SetSharedFunction[f];
> Parallelize[
> MapIndexed[
> f[#1, items[[Complement[Table[i, {i, Length[items]}], #2]]]] &=
,
> items]])
> ?
>
> does not help.
>
> Regards
> Jens
>
>
>
> uk.org.micros... at googlemail.com wrote:
> > Hi
>
> > I have the following function:
>
> > LeaveOneOut[f_, items_] :=
> > Parallelize[
> > MapIndexed[
> > f[#1, items[[Complement[Table[i, {i, Length[items]}], #2]]]] &,
> > items]]
>
> > Which might be called as follows:
>
> > a = 10 Table[i, {i, 10}];
> > f[x_, items_] := Mean[items] + x;
> > DistributeDefinitions[a, f];
> > LeaveOneOut[f, a]
>
> > Notice that I need to explicitly call DistributeDefinitions. I would
> > like to modify LeaveOneOut such that it performs the
> > DistributeDefinitions call. I've tried a few things=97such as using
> > (Distribute....; Parallelize...) and Module[{}, Distribute....;
> > Parallelize...]=97but the arguments passed to LeaveOneOut don't seem =
to
> > be being distributed (old definitions are used instead). I'm a
> > relative Mathematica novice, so help=97and an explanation of why what=
I
> > have already tried doesn't work=97would very much be appreciated!
>
> > Cheers
>
> > Chris
I'm not sure I understand you correctly but:
distributeAndCall[h_,a___]:=(DistributeDefinitions[a];h[a]);
a = 10 Table[i, {i, 10}];
f[x_, items_] := Mean[items] + x;
distributeAndCall[LeaveOneOut, f, a]