MathGroup Archive 2013

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

Search the Archive

ConstantArray dimensions in Compiled functions


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