title: Mixing int and float in Halide
body: <p>I'm using Halide with VS2013. I've successfully built and run the first tutorial.</p>
  
  <p>I'm trying to implement some of my code and do not understand why it won't compile. The code is as follows:</p>
  
  <pre><code>int main(int argc, char **argv) {
  
  ImageParam input(UInt(8), 3);
  
  Func input_clamped = BoundaryConditions::repeat_edge(input);
  Var x, y, c;
  
  Func float_input_clamped;
  float_input_clamped(x, y, c) = cast&lt;float&gt;(input_clamped(x, y, c)) / 255.0f;
  
  Func input_lum;
  input_lum(x, y) = cast&lt;float&gt;(0.299f * float_input_clamped(x, y, 0) + 0.587f * float_input_clamped(x, y, 1) + 0.114f * float_input_clamped(x, y, 2));
  
  Func m45;
  m45(x, y) = fabsf(input_lum(x - 1, y) - input_lum(x, y + 1)) + fabsf(input_lum(x, y + 1) - input_lum(x + 1, y + 2));
  
  return 0;
  }
  </code></pre>
  
  <p>The error occurs in the m45(x, y) = ... line. Apparently, input_lum isn't considered a float value. The error message is that "no suitable conversion from Halide::Expr to float exists."</p>
  
  <p>Apparently all of the casts and float math are just being ignored.</p>
  
  <p>(I know I don't initialize the input yet -- I'm trying to understand the way to think when I write Halide code, and the type inferencing is giving me fits.)</p>
  
  <p>What am I doing wrong here?</p>
  
  <p>(If it's not clear, I just want to take the luminance of a RGB image, and do some math on the luminance. I'd be delighted to stay in integer space if that works.)</p>
  
  <p>OK, I experimented and tried this:</p>
  
  <pre><code>ImageParam input(UInt(8), 3);
  
  Func input_clamped = BoundaryConditions::repeat_edge(input);
  Var x, y, c;
  
  Func input_lum;
  input_lum(x, y) = 0.299f * input_clamped(x, y, 0) + 0.587f * input_clamped(x, y, 1) + 0.114f * input_clamped(x, y, 2);
  
  Func m45;
  m45(x, y) = abs(input_lum(x - 1, y) - input_lum(x, y + 1)) + abs(input_lum(x, y + 1) - input_lum(x + 1, y + 2));
  </code></pre>
  
  <p>Now that compiles, but I have no idea what it is doing. Why wouldn't the type of input_lum() be float?</p>