MathGroup Archive 2013

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

Search the Archive

ConstantArray dimensions in Compiled functions

  • To: mathgroup at smc.vnet.net
  • Subject: [mg131553] ConstantArray dimensions in Compiled functions
  • From: jliu.blueta at gmail.com
  • Date: Sat, 24 Aug 2013 04:21:14 -0400 (EDT)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com
  • Delivered-to: l-mathgroup@wolfram.com
  • Delivered-to: mathgroup-outx@smc.vnet.net
  • Delivered-to: mathgroup-newsendx@smc.vnet.net

Hi, 

Mathematica seems to always assume ConstantArray returns {_Real,2}

f = Compile[{{x, _Real}}, Module[{m (*= {{{0.0}}}*)},
   m = ConstantArray[0.0, {2, 2, 2}];
   m[[1, 1, 1]] = x;
   m
   ]
  ]

Compile::part: Part specification m[[1,1,1]] cannot be compiled since the argument is not a tensor of sufficient rank. Evaluation will use the uncompiled function. >>




If I initialize m to {_Real, 3},

f = Compile[{{x, _Real}}, Module[{m = {{{0.0}}}},
   m = ConstantArray[0.0, {2, 2, 2}];
   m[[1, 1, 1]] = x;
   m
   ]
  ]

f[1.0]

Compile::cset: Variable m of type {_Real,3} encountered in assignment of type {_Real,2}. >>



Same error even if I specifically say ConstantArray[] returns a 3-d array.

f = Compile[{{x, _Real}}, Module[{m = {{{0.0}}}},
   m = ConstantArray[0.0, {2, 2, 2}];
   m[[1, 1, 1]] = x;
   m
   ], {{ConstantArray[___], _Real, 3}}
  ]

f[1.0]

Compile::cset: Variable m of type {_Real,3} encountered in assignment of type {_Real,2}. >>


I'd appreciate any help!




  • Prev by Date: Re: Color Saturation in plots
  • Next by Date: Classification of handwritten digits
  • Previous by thread: Re: Color Saturation in plots
  • Next by thread: Classification of handwritten digits