Repository: explosion/spaCy

Issue:
docs: Added missing cosine declaration
- Added missing cosine declaration to code listing that already included
  imports for `dot` and `norm` function it uses.

Signed-off-by: mr.Shu mr@shu.io

---

@honnibal Thanks a ton for a great library! 

While reading the index document I kind of skipped the previous declarations of `cosine`. It seemed strange not to find them here since the imports were already in place.



Discussion:
Thanks!

@honnibal may I ask why did you just close this and the other pull request? Especially with this one I thought you'd be inclined to merge it in. Is there something wrong with it?

Argh. I was supposed to merge. I thought I'd merged it, and then I also
needed to close it.

On Mon, Jan 26, 2015 at 4:25 AM, Marek Šuppa notifications@github.com
wrote:

> @honnibal https://github.com/honnibal may I ask why did you just close
> this and the other pull request? Especially with this one I thought you'd
> be inclined to merge it in. Is there something wrong with it?
> 
> —
> Reply to this email directly or view it on GitHub
> https://github.com/honnibal/spaCy/pull/3#issuecomment-71382133.


Resolving patch:
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -8,8 +8,44 @@
 
 from setuptools import Extension
 from distutils import sysconfig
+from distutils.core import setup, Extension
+from distutils.command.build_ext import build_ext
+
 import platform
 
+# By subclassing build_extensions we have the actual compiler that will be used which is really known only after finalize_options
+# http://stackoverflow.com/questions/724664/python-distutils-how-to-get-a-compiler-that-is-going-to-be-used
+compile_options =  {'msvc'  : ['/Ox', '/EHsc']  ,
+                    'other' : ['-O3', '-Wno-strict-prototypes', '-Wno-unused-function']       }
+link_options    =  {'msvc'  : [] ,
+                    'other' : [] }
+class build_ext_options:
+    def build_options(self):
+        c_type = None
+        if self.compiler.compiler_type in compile_options:
+            c_type = self.compiler.compiler_type
+        elif 'other' in compile_options:
+            c_type = 'other'
+        if c_type is not None:
+           for e in self.extensions:
+               e.extra_compile_args = compile_options[c_type]
+
+        l_type = None 
+        if self.compiler.compiler_type in link_options:
+            l_type = self.compiler.compiler_type
+        elif 'other' in link_options:
+            l_type = 'other'
+        if l_type is not None:
+           for e in self.extensions:
+               e.extra_link_args = link_options[l_type]
+
+class build_ext_subclass( build_ext, build_ext_options ):
+    def build_extensions(self):
+        build_ext_options.build_options(self)
+        build_ext.build_extensions(self)
+        
+    
+
 # PyPy --- NB! PyPy doesn't really work, it segfaults all over the place. But,
 # this is necessary to get it compile.
 # We have to resort to monkey-patching to set the compiler, because pypy broke
@@ -61,24 +97,27 @@ def name_to_path(mod_name, ext):
     return '%s.%s' % (mod_name.replace('.', '/'), ext)
 
 
-def c_ext(mod_name, language, includes, compile_args, link_args):
+def c_ext(mod_name, language, includes):
     mod_path = name_to_path(mod_name, language)
-    return Extension(mod_name, [mod_path], include_dirs=includes,
-                     extra_compile_args=compile_args, extra_link_args=link_args)
+    return Extension(mod_name, [mod_path], include_dirs=includes)
 
 
-def cython_setup(mod_names, language, includes, compile_args, link_args):
+def cython_setup(mod_names, language, includes):
     import Cython.Distutils
     import Cython.Build
     import distutils.core
 
+    class build_ext_cython_subclass( Cython.Distutils.build_ext, build_ext_options ):
+        def build_extensions(self):
+            build_ext_options.build_options(self)
+            Cython.Distutils.build_ext.build_extensions(self)
+
     if language == 'cpp':
         language = 'c++'
     exts = []
     for mod_name in mod_names:
         mod_path = mod_name.replace('.', '/') + '.pyx'
-        e = Extension(mod_name, [mod_path], language=language, include_dirs=includes,
-                      extra_compile_args=compile_args, extra_link_args=link_args)
+        e = Extension(mod_name, [mod_path], language=language, include_dirs=includes)
         exts.append(e)
     distutils.core.setup(
         name='spacy',
@@ -97,7 +136,7 @@ def cython_setup(mod_names, language, includes, compile_args, link_args):
                                    "data/vocab/strings.txt"],
                       "spacy.syntax": ["*.pxd"]},
         ext_modules=exts,
-        cmdclass={'build_ext': Cython.Distutils.build_ext},
+        cmdclass={'build_ext': build_ext_cython_subclass},
         license="Dual: Commercial or AGPL",
     )
 
@@ -122,10 +161,11 @@ def run_setup(exts):
                       "spacy.syntax": ["*.pxd"]},
         ext_modules=exts,
         license="MIT",
-        install_requires=['numpy', 'murmurhash', 'cymem >= 1.11', 'preshed >= 0.41',
+        install_requires=['numpy', 'murmurhash', 'cymem >= 1.11', 'preshed >= 0.42',
                           'thinc == 3.3', "text_unidecode", 'wget', 'plac', 'six',
                           'ujson', 'cloudpickle'],
         setup_requires=["headers_workaround"],
+        cmdclass = {'build_ext': build_ext_subclass },
     )
 
     import headers_workaround
@@ -139,19 +179,16 @@ def run_setup(exts):
 def main(modules, is_pypy):
     language = "cpp"
     includes = ['.', path.join(sys.prefix, 'include')]
-    compile_args = ['-O3', '-Wno-strict-prototypes', '-Wno-unused-function']
-    link_args = []
     if sys.prefix == 'darwin':
-        compile_args.append(['-mmacosx-version-min=10.8', '-stdlib=libc++'])
-        link_args.append('-lc++')
+        compile_options['other'].append(['-mmacosx-version-min=10.8', '-stdlib=libc++'])
+        link_opions['other'].append('-lc++')
     if use_cython:
-        cython_setup(modules, language, includes, compile_args, link_args)
+        cython_setup(modules, language, includes)
     else:
-        exts = [c_ext(mn, language, includes, compile_args, link_args)
+        exts = [c_ext(mn, language, includes)
                       for mn in modules]
         run_setup(exts)
 
-
 MOD_NAMES = ['spacy.parts_of_speech', 'spacy.strings',
              'spacy.lexeme', 'spacy.vocab', 'spacy.attrs',
              'spacy.morphology', 'spacy.tagger',


Test patch: