setup.py 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. #from distutils.core import setup, Extension
  2. from setuptools import setup, Extension,find_packages
  3. from distutils.util import convert_path
  4. import glob
  5. import numpy
  6. import sys
  7. import os
  8. import os.path
  9. import re
  10. import pathlib
  11. here = pathlib.Path(__file__).parent.resolve()
  12. ROOT = here
  13. ROOT=""
  14. includes = [os.path.join(ROOT,"Include"),os.path.join(ROOT,"PrivateInclude"),os.path.join("PythonWrapper","cmsisdsp_pkg","src")]
  15. if sys.platform == 'win32':
  16. cflags = ["-DWIN","-DCMSISDSP","-DUNALIGNED_SUPPORT_DISABLE"]
  17. else:
  18. cflags = ["-Wno-attributes","-Wno-unused-function","-Wno-unused-variable","-Wno-implicit-function-declaration","-DCMSISDSP","-D__GNUC_PYTHON__"]
  19. # Add dependencies
  20. transformMod = [] # transform + common + basic + complexf + fastmath + matrix + statistics
  21. statisticsMod = [] # statistics + common + fastmath + basic
  22. interpolationMod = [] # interpolation + common
  23. filteringMod = [] # filtering + common + support + fastmath + basic
  24. controllerMod = [] # controller + common
  25. matrixMod = [] # matrix + basic
  26. supportMod = [] # support
  27. complexfMod = [] # complexf + fastmath + common + basic
  28. basicMod = [] # basic
  29. quaternionMod = [] # quaternion
  30. fastmathMod = [] # basic + fastmath + common
  31. distanceMod = [] # distance + common + basic + statistics + fastmath
  32. bayesMod = [] # bayes + fastmath + common + statistics + basic
  33. svmMod = [] # svm + fastmath + common + basic
  34. windowMod = [] # window
  35. filteringMod.append(os.path.join("PythonWrapper","cmsisdsp_pkg","src","cmsisdsp_filtering.c"))
  36. matrixMod.append(os.path.join("PythonWrapper","cmsisdsp_pkg","src","cmsisdsp_matrix.c"))
  37. supportMod.append(os.path.join("PythonWrapper","cmsisdsp_pkg","src","cmsisdsp_support.c"))
  38. statisticsMod.append(os.path.join("PythonWrapper","cmsisdsp_pkg","src","cmsisdsp_statistics.c"))
  39. complexfMod.append(os.path.join("PythonWrapper","cmsisdsp_pkg","src","cmsisdsp_complexf.c"))
  40. basicMod.append(os.path.join("PythonWrapper","cmsisdsp_pkg","src","cmsisdsp_basic.c"))
  41. controllerMod.append(os.path.join("PythonWrapper","cmsisdsp_pkg","src","cmsisdsp_controller.c"))
  42. transformMod.append(os.path.join("PythonWrapper","cmsisdsp_pkg","src","cmsisdsp_transform.c"))
  43. interpolationMod.append(os.path.join("PythonWrapper","cmsisdsp_pkg","src","cmsisdsp_interpolation.c"))
  44. quaternionMod.append(os.path.join("PythonWrapper","cmsisdsp_pkg","src","cmsisdsp_quaternion.c"))
  45. fastmathMod.append(os.path.join("PythonWrapper","cmsisdsp_pkg","src","cmsisdsp_fastmath.c"))
  46. distanceMod.append(os.path.join("PythonWrapper","cmsisdsp_pkg","src","cmsisdsp_distance.c"))
  47. bayesMod.append(os.path.join("PythonWrapper","cmsisdsp_pkg","src","cmsisdsp_bayes.c"))
  48. svmMod.append(os.path.join("PythonWrapper","cmsisdsp_pkg","src","cmsisdsp_svm.c"))
  49. windowMod.append(os.path.join("PythonWrapper","cmsisdsp_pkg","src","cmsisdsp_window.c"))
  50. missing=set([
  51. ])
  52. def notf16(number):
  53. if re.search(r'f16',number):
  54. return(False)
  55. if re.search(r'F16',number):
  56. return(False)
  57. return(True)
  58. def isnotmissing(src):
  59. name=os.path.splitext(os.path.basename(src))[0]
  60. return(not (name in missing))
  61. # If there are too many files, the linker command is failing on Windows.
  62. # So f16 functions are removed since they are not currently available in the wrapper.
  63. # A next version will have to structure this wrapper more cleanly so that the
  64. # build can work even with more functions
  65. filtering = list(filter(isnotmissing,list(filter(notf16, filteringMod))))
  66. matrix = list(filter(isnotmissing,list(filter(notf16, matrixMod))))
  67. support = list(filter(isnotmissing,list(filter(notf16, supportMod))))
  68. statistics = list(filter(isnotmissing,list(filter(notf16, statisticsMod))))
  69. complexf = list(filter(isnotmissing,list(filter(notf16, complexfMod))))
  70. basic = list(filter(isnotmissing,list(filter(notf16, basicMod))))
  71. controller = list(filter(isnotmissing,list(filter(notf16, controllerMod))))
  72. transform = list(filter(isnotmissing,list(filter(notf16, transformMod))))
  73. interpolation = list(filter(isnotmissing,list(filter(notf16, interpolationMod))))
  74. quaternion = list(filter(isnotmissing,list(filter(notf16, quaternionMod))))
  75. fastmath = list(filter(isnotmissing,list(filter(notf16, fastmathMod))))
  76. distance = list(filter(isnotmissing,list(filter(notf16, distanceMod))))
  77. bayes = list(filter(isnotmissing,list(filter(notf16, bayesMod))))
  78. svm = list(filter(isnotmissing,list(filter(notf16, svmMod))))
  79. window = list(filter(isnotmissing,list(filter(notf16, windowMod))))
  80. #for l in filtering:
  81. # print(os.path.basename(l))
  82. #quit()
  83. def mkModule(name,srcs,funcDir):
  84. localinc = os.path.join(ROOT,"Source",funcDir)
  85. libdir = [os.path.join(ROOT,"PythonWrapper","build","bin_dsp")]
  86. lib = ["CMSISDSP"]
  87. extraobjs=[]
  88. if sys.platform.startswith('linux'):
  89. lib = []
  90. extraobjs = [os.path.join(ROOT,"PythonWrapper","build_linux","bin_dsp","libCMSISDSP.a")]
  91. libdir = []
  92. if sys.platform.startswith('darwin'):
  93. lib = []
  94. extraobjs = [os.path.join(ROOT,"PythonWrapper","build_darwin","bin_dsp","libCMSISDSP.a")]
  95. libdir = []
  96. return(Extension(name,
  97. sources = (srcs
  98. )
  99. ,
  100. include_dirs = [localinc] + includes + [numpy.get_include()],
  101. extra_compile_args = cflags,
  102. library_dirs = libdir,
  103. libraries=lib,
  104. extra_objects=extraobjs
  105. ))
  106. flagsForCommonWithoutFFT=["-DARM_DSP_CONFIG_TABLES",
  107. "-DARM_FAST_ALLOW_TABLES",
  108. "-DARM_ALL_FAST_TABLES"]
  109. moduleFiltering = mkModule('cmsisdsp_filtering',filtering,"FilteringFunctions")
  110. moduleMatrix = mkModule('cmsisdsp_matrix',matrix,"MatrixFunctions")
  111. moduleSupport = mkModule('cmsisdsp_support',support,"SupportFunctions")
  112. moduleStatistics = mkModule('cmsisdsp_statistics',statistics,"StatisticsFunctions")
  113. moduleComplexf= mkModule('cmsisdsp_complexf',complexf,"ComplexMathFunctions")
  114. moduleBasic = mkModule('cmsisdsp_basic',basic,"BasicMathFunctions")
  115. moduleController = mkModule('cmsisdsp_controller',controller,"ControllerFunctions")
  116. moduleTransform = mkModule('cmsisdsp_transform',transform,"TransformFunctions")
  117. moduleInterpolation = mkModule('cmsisdsp_interpolation',interpolation,"InterpolationFunctions")
  118. moduleQuaternion = mkModule('cmsisdsp_quaternion',quaternion,"QuaternionMathFunctions")
  119. moduleFastmath = mkModule('cmsisdsp_fastmath',fastmath,"FastMathFunctions")
  120. moduleDistance = mkModule('cmsisdsp_distance',distance,"DistanceFunctions")
  121. moduleBayes = mkModule('cmsisdsp_bayes',bayes,"BayesFunctions")
  122. moduleSVM = mkModule('cmsisdsp_svm',svm,"SVMFunctions")
  123. moduleWindow = mkModule('cmsisdsp_window',window,"WindowFunctions")
  124. def build():
  125. if sys.version_info.major < 3:
  126. print('setup.py: Error: This package only supports Python 3.', file=sys.stderr)
  127. sys.exit(1)
  128. main_ns = {}
  129. ver_path = convert_path(os.path.join("cmsisdsp","version.py"))
  130. with open(ver_path) as ver_file:
  131. exec(ver_file.read(), main_ns)
  132. setup (name = 'cmsisdsp',
  133. version = main_ns['__version__'],
  134. packages=["cmsisdsp",
  135. "cmsisdsp.cg",
  136. "cmsisdsp.cg.nodes",
  137. "cmsisdsp.cg.nodes.host",
  138. "cmsisdsp.cg.scheduler",
  139. "cmsisdsp.cg.scheduler.templates"],
  140. description = 'CMSIS-DSP Python API',
  141. long_description=open("PythonWrapper_README.md").read(),
  142. long_description_content_type='text/markdown',
  143. ext_modules = [moduleFiltering ,
  144. moduleMatrix,
  145. moduleSupport,
  146. moduleStatistics,
  147. moduleComplexf,
  148. moduleBasic,
  149. moduleController,
  150. moduleTransform,
  151. moduleInterpolation,
  152. moduleQuaternion,
  153. moduleFastmath,
  154. moduleDistance,
  155. moduleBayes,
  156. moduleSVM,
  157. moduleWindow
  158. ],
  159. include_package_data=True,
  160. author = 'Copyright (C) 2010-2023 ARM Limited or its affiliates. All rights reserved.',
  161. author_email = 'christophe.favergeon@arm.com',
  162. url="https://github.com/ARM-software/CMSIS-DSP",
  163. python_requires='>=3.7',
  164. license="License :: OSI Approved :: Apache Software License",
  165. platforms=['any'],
  166. classifiers=[
  167. "Programming Language :: Python :: 3",
  168. "Programming Language :: Python :: Implementation :: CPython",
  169. "Programming Language :: C",
  170. "License :: OSI Approved :: Apache Software License",
  171. "Operating System :: OS Independent",
  172. "Development Status :: 4 - Beta",
  173. "Topic :: Software Development :: Embedded Systems",
  174. "Topic :: Scientific/Engineering :: Mathematics",
  175. "Environment :: Console",
  176. "Intended Audience :: Developers",
  177. ],
  178. keywords=['development','dsp','cmsis','cmsis-dsp','Arm','signal processing','maths','ml','cortex-m','cortex-a'],
  179. install_requires=['numpy>=1.22, < 1.23 ',
  180. 'networkx>=3.0',
  181. 'jinja2>= 3.1.2, <4.0',
  182. 'sympy>=1.7.1',
  183. 'MarkupSafe>=2.1.2, <3.0'
  184. ],
  185. project_urls={ # Optional
  186. 'Bug Reports': 'https://github.com/ARM-software/CMSIS-DSP/issues',
  187. 'Source': 'https://github.com/ARM-software/CMSIS-DSP',
  188. }
  189. )
  190. build()