MathGroup Archive 2000

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

Search the Archive

Matrices & Compile

  • To: mathgroup at smc.vnet.net
  • Subject: [mg22525] Matrices & Compile
  • From: Kurt Taretto <Kurt.Taretto at ipe.uni-stuttgart.de>
  • Date: Thu, 9 Mar 2000 03:24:16 -0500 (EST)
  • Organization: Comp.Center (RUS), U of Stuttgart, FRG
  • Sender: owner-wri-mathgroup at wolfram.com

Hi,

I'm making some functions using Compile, but I found some features of
Compile which I don't fully
understand yet.  The following trivial function should take an nxn
matrix and asign the value 1.0
to the element (2,2) of that matrix:

In[1]:=
f = Compile[{{n, _Integer}, {a, _Real, 2}}, a[[2, 2]] = 1.0]

Out[1]=
CompiledFunction[{n, a}, a[[2, 2]] = 1., "-CompiledCode-"]


The compilation was succesfull, but the function does not work:

In[2]:=
a = {{3, 2}, {1, 4}};

In[3]:=
f[2, a]

Set::"setps": {{3, 2}, {1, 4}}; in assignment of part is not a symbol."

Out[3]=
1.

In[4]:=
a

Out[4]=
{{3, 2}, {1, 4}}

If I assign matrix a to an object b, everything goes well

In[5]:=
f = Compile[{{n, _Integer}, {a, _Real, 2}},
    Module[{b}, b = a; b[[2, 2]] = 1; b]]

Out[5]=
CompiledFunction[{n, a},
  Module[{b}, b = a; b[[2, 2]]= 1;b], "-CompiledCode-"]

In[6]:=
a = f[2, a]

Out[6]=
{{3., 2.}, {1., 1.}}

The problem with this alternative is the unecessary memory requirement
for b, and also the
need for extra notation.  I'm dealing with functions that take several
large matrices as arguments,
and do operations on their elements.  Making statements like the above
"b=a" makes the resulting code
unnecesary complicated and more difficult to read.  Is there any way out
of this or did I make some
simple mistake?

Any help will be appreciated!  Thanks!

Kurt Taretto



  • Prev by Date: Re: Problem with Integration
  • Next by Date: Re: Re: export graphic to ps---trouble with fonts
  • Previous by thread: Re: Rookie question ..
  • Next by thread: Re: Matrices & Compile