0

Here's a simplified form of a function I would like to compile, but it produces errors

DataType = Compile[{{Inputdata, _Real, 1}}, Module[{CIEL, CIEa, CIEb},
    dim = Dimensions@Inputdata;
    If[dim[[1]] > 3,
     {CIEL, CIEa, CIEb} = Inputdata
        ]
    ],
   CompilationTarget -> "C"
   ];

The error Mathematica produces is:

Compile::extscalar: dim=Dimensions[Inputdata] cannot be compiled and will be evaluated externally. The result is assumed to be of type Void. >>

Is there a workaround to allow these types of functions to compile for conditionals that depend on the dimensions of a list?

M6299
  • 1,471
  • 1
  • 13
  • 20
Nothingtoseehere
  • 4,518
  • 2
  • 30
  • 58

1 Answers1

0

Conditionals are fine in compiled functions...

DataType = Compile[{{Inputdata, _Real, 1}},
   If[Length@Inputdata > 3, 1, 0], CompilationTarget -> "C"];

DataType[{5, 6, 7}]

(* 0 *)

DataType[{5, 6, 7, 8}]

(* 1 *)

The problem is your function returns nothing, you are trying to set global variables from inside the compiled function and also you never use a, b, and c.

s0rce
  • 9,632
  • 4
  • 45
  • 78