MathGroup Archive 2009

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

Search the Archive

Re: Calling functions with huge arguments

  • To: mathgroup at smc.vnet.net
  • Subject: [mg97652] Re: [mg97621] Calling functions with huge arguments
  • From: "David Park" <djmpark at comcast.net>
  • Date: Wed, 18 Mar 2009 04:51:44 -0500 (EST)
  • References: <29371288.1237286742339.JavaMail.root@m02>

In your function definitions use the Attributes HoldFirst or HoldAll. Look
up Attributes and HoldFirst and Hold All.

Attributes[f] = {HoldFirst};

f[tensor_]:= ...

or 

Attributes[f] = {HoldAll};
f[tensor1_, tensor2_, ...] := ...

This passes the reference and not the object.


David Park
djmpark at comcast.net
http://home.comcast.net/~djmpark/  




From: Fernando Cucchietti [mailto:fernando.cucchietti at icfo.es] 


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




  • Prev by Date: Filling Between Surfaces
  • Next by Date: Re: Calling functions with huge arguments
  • Previous by thread: Re: Calling functions with huge arguments
  • Next by thread: Re: Calling functions with huge arguments