@@ -182,21 +182,16 @@ site-packages directory.
182
182
$python setup.py install
183
183
will install the module in your site-packages file.
184
184
185
- See the distutils section of
186
- 'Extending and Embedding the Python Interpreter'
187
- at docs.python.org for more information.
185
+ See the setuptools section 'Building Extension Modules'
186
+ at setuptools.pypa.io for more information.
188
187
'''
189
188
189
+ from setuptools import setup, Extension
190
+ import numpy as np
190
191
191
- from distutils.core import setup, Extension
192
+ module1 = Extension( ' spam ' , sources = [ ' spammodule.c ' ])
192
193
193
- module1 = Extension(' spam' , sources = [' spammodule.c' ],
194
- include_dirs = [' /usr/local/lib' ])
195
-
196
- setup(name = ' spam' ,
197
- version = ' 1.0' ,
198
- description = ' This is my spam package' ,
199
- ext_modules = [module1])
194
+ setup(name = ' spam' , version = ' 1.0' , ext_modules = [module1])
200
195
201
196
202
197
Once the spam module is imported into python, you can call logit
@@ -355,8 +350,8 @@ using ``python setup.py build_ext --inplace``.
355
350
'''
356
351
setup.py file for single_type_logit.c
357
352
Note that since this is a numpy extension
358
- we use numpy.distutils instead of
359
- distutils from the python standard library .
353
+ we add an include_dirs=[get_include()] so that the
354
+ extension is built with numpy's C/C++ header files .
360
355
361
356
Calling
362
357
$python setup.py build_ext --inplace
@@ -373,33 +368,26 @@ using ``python setup.py build_ext --inplace``.
373
368
$python setup.py install
374
369
will install the module in your site-packages file.
375
370
376
- See the distutils section of
377
- 'Extending and Embedding the Python Interpreter'
378
- at docs.python.org and the documentation
379
- on numpy.distutils for more information.
371
+ See the setuptools section 'Building Extension Modules'
372
+ at setuptools.pypa.io for more information.
380
373
'''
381
374
375
+ from setuptools import setup, Extension
376
+ from numpy import get_include
382
377
383
- def configuration (parent_package = ' ' , top_path = None ):
384
- from numpy.distutils.misc_util import Configuration
385
-
386
- config = Configuration(' npufunc_directory' ,
387
- parent_package,
388
- top_path)
389
- config.add_extension(' npufunc' , [' single_type_logit.c' ])
378
+ npufunc = Extension(' npufunc' ,
379
+ sources = [' single_type_logit.c' ],
380
+ include_dirs = [get_include()])
390
381
391
- return config
382
+ setup( name = ' npufunc ' , version = ' 1.0 ' , ext_modules = [npufunc])
392
383
393
- if __name__ == " __main__" :
394
- from numpy.distutils.core import setup
395
- setup(configuration = configuration)
396
384
397
385
After the above has been installed, it can be imported and used as follows.
398
386
399
387
>>> import numpy as np
400
388
>>> import npufunc
401
389
>>> npufunc.logit(0.5 )
402
- 0.0
390
+ np.float64( 0.0)
403
391
>>> a = np.linspace(0 ,1 ,5 )
404
392
>>> npufunc.logit(a)
405
393
array([ -inf, -1.09861229, 0. , 1.09861229, inf])
@@ -607,8 +595,10 @@ or installed to site-packages via ``python setup.py install``.
607
595
'''
608
596
setup.py file for multi_type_logit.c
609
597
Note that since this is a numpy extension
610
- we use numpy.distutils instead of
611
- distutils from the python standard library.
598
+ we add an include_dirs=[get_include()] so that the
599
+ extension is built with numpy's C/C++ header files.
600
+ Furthermore, we also have to include the npymath
601
+ lib for half-float d-type.
612
602
613
603
Calling
614
604
$python setup.py build_ext --inplace
@@ -625,38 +615,31 @@ or installed to site-packages via ``python setup.py install``.
625
615
$python setup.py install
626
616
will install the module in your site-packages file.
627
617
628
- See the distutils section of
629
- 'Extending and Embedding the Python Interpreter'
630
- at docs.python.org and the documentation
631
- on numpy.distutils for more information.
618
+ See the setuptools section 'Building Extension Modules'
619
+ at setuptools.pypa.io for more information.
632
620
'''
633
621
622
+ from setuptools import setup, Extension
623
+ from numpy import get_include
624
+ from os import path
634
625
635
- def configuration (parent_package = ' ' , top_path = None ):
636
- from numpy.distutils.misc_util import Configuration, get_info
637
-
638
- # Necessary for the half-float d-type.
639
- info = get_info(' npymath' )
626
+ path_to_npymath = path.join(get_include(), ' ..' , ' lib' )
627
+ npufunc = Extension(' npufunc' ,
628
+ sources = [' multi_type_logit.c' ],
629
+ include_dirs = [get_include()],
630
+ # Necessary for the half-float d-type.
631
+ library_dirs = [path_to_npymath],
632
+ libraries = [" npymath" ])
640
633
641
- config = Configuration(' npufunc_directory' ,
642
- parent_package,
643
- top_path)
644
- config.add_extension(' npufunc' ,
645
- [' multi_type_logit.c' ],
646
- extra_info = info)
634
+ setup(name = ' npufunc' , version = ' 1.0' , ext_modules = [npufunc])
647
635
648
- return config
649
-
650
- if __name__ == " __main__" :
651
- from numpy.distutils.core import setup
652
- setup(configuration = configuration)
653
636
654
637
After the above has been installed, it can be imported and used as follows.
655
638
656
639
>>> import numpy as np
657
640
>>> import npufunc
658
641
>>> npufunc.logit(0.5 )
659
- 0.0
642
+ np.float64( 0.0)
660
643
>>> a = np.linspace(0 ,1 ,5 )
661
644
>>> npufunc.logit(a)
662
645
array([ -inf, -1.09861229, 0. , 1.09861229, inf])
@@ -678,13 +661,17 @@ the line
678
661
679
662
.. code-block :: python
680
663
681
- config.add_extension(' npufunc' , [' single_type_logit.c' ])
664
+ npufunc = Extension(' npufunc' ,
665
+ sources = [' single_type_logit.c' ],
666
+ include_dirs = [get_include()])
682
667
683
668
is replaced with
684
669
685
670
.. code-block :: python
686
671
687
- config.add_extension(' npufunc' , [' multi_arg_logit.c' ])
672
+ npufunc = Extension(' npufunc' ,
673
+ sources = [' multi_arg_logit.c' ],
674
+ include_dirs = [get_include()])
688
675
689
676
The C file is given below. The ufunc generated takes two arguments ``A ``
690
677
and ``B ``. It returns a tuple whose first element is ``A * B `` and whose second
@@ -809,13 +796,17 @@ the line
809
796
810
797
.. code-block :: python
811
798
812
- config.add_extension(' npufunc' , [' single_type_logit.c' ])
799
+ npufunc = Extension(' npufunc' ,
800
+ sources = [' single_type_logit.c' ],
801
+ include_dirs = [get_include()])
813
802
814
803
is replaced with
815
804
816
805
.. code-block :: python
817
806
818
- config.add_extension(' npufunc' , [' add_triplet.c' ])
807
+ npufunc = Extension(' npufunc' ,
808
+ sources = [' add_triplet.c' ],
809
+ include_dirs = [get_include()])
819
810
820
811
The C file is given below.
821
812
@@ -892,7 +883,7 @@ The C file is given below.
892
883
NULL
893
884
};
894
885
895
- PyMODINIT_FUNC PyInit_struct_ufunc_test (void)
886
+ PyMODINIT_FUNC PyInit_npufunc (void)
896
887
{
897
888
PyObject *m, *add_triplet, *d;
898
889
PyObject *dtype_dict;
0 commit comments