Re: Calling functions with huge arguments
- To: mathgroup at smc.vnet.net
- Subject: [mg97681] Re: Calling functions with huge arguments
- From: Jens-Peer Kuska <kuska at informatik.uni-leipzig.de>
- Date: Wed, 18 Mar 2009 04:57:17 -0500 (EST)
- Organization: Uni Leipzig
- References: <gpns8b$gkh$1@smc.vnet.net>
- Reply-to: kuska at informatik.uni-leipzig.de
Hi,
the best way is to make a block in your top-level function
as in thr example below
ToplevelFunction[huge_]:=Block[{hugeLocalCopy=huge},
nextlevel[];
]
nextlevel[]:=Module[{any=2},hugeLocalCopy=any*hugeLocalCopy]
Block[] mak a dynamic scoping, i.e., all functions called from
a Block[] can access its local data.
Regards
Jens
Fernando Cucchietti wrote:
> Hi all,
>
> I am working with a VERY large tensor, so much that I would like to
> keep at most two copies of it in memory at any given time. The
> algorithm I want to run is convoluted and repetitive, but it looks
> very compact when written in terms of subroutines and functions that
> call themselves many times. However, from what I gather, Mathematica
> effectively creates a copy of the arguments when a function is called.
> Is this correct?
> If so, I need to find a way to mimic pass-by-reference style as in C
> or Fortran, or just pass the arguments that are not big and keep my
> tensors defined globally (which I think makes the code look less
> nice). Unwrapping the code so that it does not call functions is not
> an option, because it would be very complex and never-again-usable.
> My main question is then: what are the best ways to do pass-by-
> reference (if it is better than global naming), or what approaches
> have you taken to overcome similar problems?
>
> Thanks in advance,
>
> Fernando
>