MathGroup Archive 2008

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

Search the Archive

Re: Compiling SingularValueDecomposition

  • To: mathgroup at smc.vnet.net
  • Subject: [mg89839] Re: Compiling SingularValueDecomposition
  • From: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>
  • Date: Sun, 22 Jun 2008 03:23:55 -0400 (EDT)
  • Organization: The Open University, Milton Keynes, UK
  • References: <g3ihod$fc9$1@smc.vnet.net>

Frank Hu wrote:
> Hi, group,
> 
> I'm trying to speed up a piece of code that uses  
> SingularValueDecomposition by compiling it.  But I couldn't get it to  
> compile.  For a simple demonstration, try
> 
> fx=Compile[{{x, _Real, 2}},  SingularValueDecomposition[x],  
> {{SingularValueDecomposition, _Real, 3}}]
> 
> and fx[[4]] is
> {{1, 5}, {54, Function[{x}, SingularValueDecomposition[x]], 3, 2, 0,  
> 3, 2, 1}, {2}}
> 
> The "Function" there tells fx wasn't compiled successfully.  Calling  
> fx[{{1., 2.}, {3., 4.}}] will generate the following warnings
> 
> CompiledFunction::cfte: Compiled expression {<<1>>} should be a rank  
> 2 tensor of machine-size real numbers. >>
> CompiledFunction::cfex: Could not complete external evaluation at  
> instruction 2; proceeding with uncompiled evaluation. >>

Hi Frank,

You must write the intermediate functions as full expressions, that is 
SingularValueDecomposition[_] rather than just 
SingularValueDecomposition. The following works as expected:


In[1]:= fx = Compile[{{x, _Real, 2}}, SingularValueDecomposition[x],
      {{SingularValueDecomposition[_], _Real, 3}}]
fx[[4]]
fx[{{1., 2.}, {3., 4.}}]

Out[1]= CompiledFunction[]

Out[2]= {{1, 5}, {54, Function[{x}, SingularValueDecomposition[x]], 3, 
2, 0, 3,

    3, 1}, {2}}

Out[3]= {{{-0.404554, 0.914514}, {-0.914514, -0.404554}},

   {{5.46499, 0.}, {0., 0.365966}},

   {{-0.576048, -0.817416}, {-0.817416, 0.576048}}}


Regards,
-- Jean-Marc


  • Prev by Date: Mathematica performance improvements
  • Next by Date: Anyone with experience showing graphically, how data flows between
  • Previous by thread: Compiling SingularValueDecomposition
  • Next by thread: Re: Compiling SingularValueDecomposition