title: C++ template functions through Cython
body: <p>I generated a simple C++ header file lerp1d.h with a templated function and it's definition</p>
  
  <p>lerp1d.h:</p>
  
  <pre><code>template &lt;typename T&gt; std::vector&lt;T&gt; LinearInterp(std::vector&lt;T&gt; x_data, std::vector&lt;T&gt; x_target, std::vector&lt;T&gt; f_vals) {
  ...}
  </code></pre>
  
  <p>Then I wanted to compile this function with Cython and use it in a python program together with numpy, the basic idea is to test it together with plotting utilities etc.</p>
  
  <p>So I went ahead and created the following files:</p>
  
  <p>cy_lerp1d.pyx:</p>
  
  <pre><code># distutils: language = c++
  # distutils: sources = lerp1d.
  import Cython
  cimport numpy as np
  
  cdef extern from "&lt;vector&gt;" namespace "std":
      cdef cppclass vector [T]:
          cppclass iterator:
              T operator*()
              iterator operator++()
              bint operator==(iterator)
              bint operator!=(iterator)
              vector()
              void push_back(T&amp;)
              T&amp; operator[](int)
              T&amp; at(int)
              iterator begin()
              iterator end()
  
  cdef extern from "lerp1d.h":
      cdef vector[double] LinearInterp(vector[double]&amp;, vector[double]&amp;, vector[double]&amp;)
  </code></pre>
  
  <p>As I understand it the last statement creates a template instantiation for double, Next</p>
  
  <p>setup.py:</p>
  
  <pre><code>from distutils.core import setup
  from distutils.extension import Extension
  from Cython.Distutils import build_ext
  import numpy
  import os
  
  os.environ["CC"]  = "g++ -std=c++11 -Wall"
  os.environ["CXX"] = "g++ -std=c++11 -Wall"
  
  #To build call with $python setup build_ext -i
  setup(name = 'cy_lerp1d', ext_modules = 
      [Extension("cy_lerp1d", sources=["cy_lerp1d.pyx"],
       language = "c++" , include_dirs = [numpy.get_include()],
       cmdclass = {'build_ext' : build_ext})
  </code></pre>
  
  <p>And finally the test code:</p>
  
  <pre><code>import numpy as np
  import matplotlib.pyplot as plt
  from cy_lerp1d import * #LinearInterp
  
  if __name__ == '__main__':
      Some code...
  </code></pre>
  
  <p>I build the Cython extension with: <code>python setup.py build_ext -i</code> and it gives no errors
  However when I try to run the test I get</p>
  
  <pre><code> NameError: name 'LinearInterp' is not defined
  </code></pre>
  
  <p>If in the import statement I do from cy_lerp1d import LinearInterp I get:</p>
  
  <pre><code>ImportError: cannot import name LinearInterp
  </code></pre>
  
  <p>I am afraid I cannot find anything relevant to this situation so far, any help is welcome.</p>