setup.py 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  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. transform = glob.glob(os.path.join(ROOT,"Source","TransformFunctions","*.c"))
  20. # Files are present when creating the source distribution
  21. # but they are not copied to the source distribution
  22. # When doing pip install those files are not prevent
  23. # and it should not fail
  24. try:
  25. transform.remove(os.path.join(ROOT,"Source","TransformFunctions","TransformFunctions.c"))
  26. transform.remove(os.path.join(ROOT,"Source","TransformFunctions","TransformFunctionsF16.c"))
  27. except:
  28. pass
  29. support = glob.glob(os.path.join(ROOT,"Source","SupportFunctions","*.c"))
  30. try:
  31. support.remove(os.path.join(ROOT,"Source","SupportFunctions","SupportFunctions.c"))
  32. support.remove(os.path.join(ROOT,"Source","SupportFunctions","SupportFunctionsF16.c"))
  33. except:
  34. pass
  35. fastmath = glob.glob(os.path.join(ROOT,"Source","FastMathFunctions","*.c"))
  36. try:
  37. fastmath.remove(os.path.join(ROOT,"Source","FastMathFunctions","FastMathFunctions.c"))
  38. except:
  39. pass
  40. filtering = glob.glob(os.path.join(ROOT,"Source","FilteringFunctions","*.c"))
  41. try:
  42. filtering.remove(os.path.join(ROOT,"Source","FilteringFunctions","FilteringFunctions.c"))
  43. filtering.remove(os.path.join(ROOT,"Source","FilteringFunctions","FilteringFunctionsF16.c"))
  44. except:
  45. pass
  46. matrix = glob.glob(os.path.join(ROOT,"Source","MatrixFunctions","*.c"))
  47. try:
  48. matrix.remove(os.path.join(ROOT,"Source","MatrixFunctions","MatrixFunctions.c"))
  49. matrix.remove(os.path.join(ROOT,"Source","MatrixFunctions","MatrixFunctionsF16.c"))
  50. except:
  51. pass
  52. statistics = glob.glob(os.path.join(ROOT,"Source","StatisticsFunctions","*.c"))
  53. try:
  54. statistics.remove(os.path.join(ROOT,"Source","StatisticsFunctions","StatisticsFunctions.c"))
  55. statistics.remove(os.path.join(ROOT,"Source","StatisticsFunctions","StatisticsFunctionsF16.c"))
  56. except:
  57. pass
  58. complexf = glob.glob(os.path.join(ROOT,"Source","ComplexMathFunctions","*.c"))
  59. try:
  60. complexf.remove(os.path.join(ROOT,"Source","ComplexMathFunctions","ComplexMathFunctions.c"))
  61. complexf.remove(os.path.join(ROOT,"Source","ComplexMathFunctions","ComplexMathFunctionsF16.c"))
  62. except:
  63. pass
  64. basic = glob.glob(os.path.join(ROOT,"Source","BasicMathFunctions","*.c"))
  65. try:
  66. basic.remove(os.path.join(ROOT,"Source","BasicMathFunctions","BasicMathFunctions.c"))
  67. basic.remove(os.path.join(ROOT,"Source","BasicMathFunctions","BasicMathFunctionsF16.c"))
  68. except:
  69. pass
  70. controller = glob.glob(os.path.join(ROOT,"Source","ControllerFunctions","*.c"))
  71. try:
  72. controller.remove(os.path.join(ROOT,"Source","ControllerFunctions","ControllerFunctions.c"))
  73. except:
  74. pass
  75. common = glob.glob(os.path.join(ROOT,"Source","CommonTables","*.c"))
  76. try:
  77. common.remove(os.path.join(ROOT,"Source","CommonTables","CommonTables.c"))
  78. common.remove(os.path.join(ROOT,"Source","CommonTables","CommonTablesF16.c"))
  79. except:
  80. pass
  81. interpolation = glob.glob(os.path.join(ROOT,"Source","InterpolationFunctions","*.c"))
  82. try:
  83. interpolation.remove(os.path.join(ROOT,"Source","InterpolationFunctions","InterpolationFunctions.c"))
  84. interpolation.remove(os.path.join(ROOT,"Source","InterpolationFunctions","InterpolationFunctionsF16.c"))
  85. except:
  86. pass
  87. quaternion = glob.glob(os.path.join(ROOT,"Source","QuaternionMathFunctions","*.c"))
  88. try:
  89. quaternion.remove(os.path.join(ROOT,"Source","QuaternionMathFunctions","QuaternionMathFunctions.c"))
  90. except:
  91. pass
  92. distance = glob.glob(os.path.join(ROOT,"Source","DistanceFunctions","*.c"))
  93. try:
  94. distance.remove(os.path.join(ROOT,"Source","DistanceFunctions","DistanceFunctions.c"))
  95. except:
  96. pass
  97. bayes = glob.glob(os.path.join(ROOT,"Source","BayesFunctions","*.c"))
  98. try:
  99. bayes.remove(os.path.join(ROOT,"Source","BayesFunctions","BayesFunctions.c"))
  100. except:
  101. pass
  102. svm = glob.glob(os.path.join(ROOT,"Source","SVMFunctions","*.c"))
  103. try:
  104. svm.remove(os.path.join(ROOT,"Source","SVMFunctions","SVMFunctions.c"))
  105. except:
  106. pass
  107. # Add dependencies
  108. transformMod = transform + common + basic + complexf + fastmath + matrix + statistics
  109. statisticsMod = statistics + common + fastmath + basic
  110. interpolationMod = interpolation + common
  111. filteringMod = filtering + common + support + fastmath + basic
  112. controllerMod = controller + common
  113. matrixMod = matrix
  114. supportMod = support
  115. complexfMod = complexf + fastmath + common + basic
  116. basicMod = basic
  117. quaternionMod = quaternion
  118. fastmathMod = basic + fastmath + common
  119. distanceMod = distance + common + basic + statistics + fastmath
  120. bayesMod = bayes + fastmath + common + statistics + basic
  121. svmMod = svm + fastmath + common + basic
  122. filteringMod.append(os.path.join("PythonWrapper","cmsisdsp_pkg","src","cmsisdsp_filtering.c"))
  123. matrixMod.append(os.path.join("PythonWrapper","cmsisdsp_pkg","src","cmsisdsp_matrix.c"))
  124. supportMod.append(os.path.join("PythonWrapper","cmsisdsp_pkg","src","cmsisdsp_support.c"))
  125. statisticsMod.append(os.path.join("PythonWrapper","cmsisdsp_pkg","src","cmsisdsp_statistics.c"))
  126. complexfMod.append(os.path.join("PythonWrapper","cmsisdsp_pkg","src","cmsisdsp_complexf.c"))
  127. basicMod.append(os.path.join("PythonWrapper","cmsisdsp_pkg","src","cmsisdsp_basic.c"))
  128. controllerMod.append(os.path.join("PythonWrapper","cmsisdsp_pkg","src","cmsisdsp_controller.c"))
  129. transformMod.append(os.path.join("PythonWrapper","cmsisdsp_pkg","src","cmsisdsp_transform.c"))
  130. interpolationMod.append(os.path.join("PythonWrapper","cmsisdsp_pkg","src","cmsisdsp_interpolation.c"))
  131. quaternionMod.append(os.path.join("PythonWrapper","cmsisdsp_pkg","src","cmsisdsp_quaternion.c"))
  132. fastmathMod.append(os.path.join("PythonWrapper","cmsisdsp_pkg","src","cmsisdsp_fastmath.c"))
  133. distanceMod.append(os.path.join("PythonWrapper","cmsisdsp_pkg","src","cmsisdsp_distance.c"))
  134. bayesMod.append(os.path.join("PythonWrapper","cmsisdsp_pkg","src","cmsisdsp_bayes.c"))
  135. svmMod.append(os.path.join("PythonWrapper","cmsisdsp_pkg","src","cmsisdsp_svm.c"))
  136. missing=set([
  137. ])
  138. def notf16(number):
  139. if re.search(r'f16',number):
  140. return(False)
  141. if re.search(r'F16',number):
  142. return(False)
  143. return(True)
  144. def isnotmissing(src):
  145. name=os.path.splitext(os.path.basename(src))[0]
  146. return(not (name in missing))
  147. # If there are too many files, the linker command is failing on Windows.
  148. # So f16 functions are removed since they are not currently available in the wrapper.
  149. # A next version will have to structure this wrapper more cleanly so that the
  150. # build can work even with more functions
  151. filtering = list(filter(isnotmissing,list(filter(notf16, filteringMod))))
  152. matrix = list(filter(isnotmissing,list(filter(notf16, matrixMod))))
  153. support = list(filter(isnotmissing,list(filter(notf16, supportMod))))
  154. statistics = list(filter(isnotmissing,list(filter(notf16, statisticsMod))))
  155. complexf = list(filter(isnotmissing,list(filter(notf16, complexfMod))))
  156. basic = list(filter(isnotmissing,list(filter(notf16, basicMod))))
  157. controller = list(filter(isnotmissing,list(filter(notf16, controllerMod))))
  158. transform = list(filter(isnotmissing,list(filter(notf16, transformMod))))
  159. interpolation = list(filter(isnotmissing,list(filter(notf16, interpolationMod))))
  160. quaternion = list(filter(isnotmissing,list(filter(notf16, quaternionMod))))
  161. fastmath = list(filter(isnotmissing,list(filter(notf16, fastmathMod))))
  162. distance = list(filter(isnotmissing,list(filter(notf16, distanceMod))))
  163. bayes = list(filter(isnotmissing,list(filter(notf16, bayesMod))))
  164. svm = list(filter(isnotmissing,list(filter(notf16, svmMod))))
  165. #for l in filtering:
  166. # print(os.path.basename(l))
  167. #quit()
  168. def mkModule(name,srcs,funcDir,newCflags=[]):
  169. localinc = os.path.join(ROOT,"Source",funcDir)
  170. return(Extension(name,
  171. sources = (srcs
  172. )
  173. ,
  174. include_dirs = [localinc] + includes + [numpy.get_include()],
  175. extra_compile_args = cflags + newCflags
  176. ))
  177. flagsForCommonWithoutFFT=["-DARM_DSP_CONFIG_TABLES",
  178. "-DARM_FAST_ALLOW_TABLES",
  179. "-DARM_ALL_FAST_TABLES"]
  180. moduleFiltering = mkModule('cmsisdsp_filtering',filtering,"FilteringFunctions",flagsForCommonWithoutFFT)
  181. moduleMatrix = mkModule('cmsisdsp_matrix',matrix,"MatrixFunctions")
  182. moduleSupport = mkModule('cmsisdsp_support',support,"SupportFunctions")
  183. moduleStatistics = mkModule('cmsisdsp_statistics',statistics,"StatisticsFunctions",flagsForCommonWithoutFFT)
  184. moduleComplexf= mkModule('cmsisdsp_complexf',complexf,"ComplexMathFunctions")
  185. moduleBasic = mkModule('cmsisdsp_basic',basic,"BasicMathFunctions")
  186. moduleController = mkModule('cmsisdsp_controller',controller,"ControllerFunctions",flagsForCommonWithoutFFT)
  187. moduleTransform = mkModule('cmsisdsp_transform',transform,"TransformFunctions")
  188. moduleInterpolation = mkModule('cmsisdsp_interpolation',interpolation,"InterpolationFunctions",flagsForCommonWithoutFFT)
  189. moduleQuaternion = mkModule('cmsisdsp_quaternion',quaternion,"QuaternionMathFunctions")
  190. moduleFastmath = mkModule('cmsisdsp_fastmath',fastmath,"FastMathFunctions",flagsForCommonWithoutFFT)
  191. moduleDistance = mkModule('cmsisdsp_distance',distance,"DistanceFunctions",flagsForCommonWithoutFFT)
  192. moduleBayes = mkModule('cmsisdsp_bayes',bayes,"BayesFunctions",flagsForCommonWithoutFFT)
  193. moduleSVM = mkModule('cmsisdsp_svm',svm,"SVMFunctions",flagsForCommonWithoutFFT)
  194. def build():
  195. if sys.version_info.major < 3:
  196. print('setup.py: Error: This package only supports Python 3.', file=sys.stderr)
  197. sys.exit(1)
  198. main_ns = {}
  199. ver_path = convert_path(os.path.join("cmsisdsp","version.py"))
  200. with open(ver_path) as ver_file:
  201. exec(ver_file.read(), main_ns)
  202. setup (name = 'cmsisdsp',
  203. version = main_ns['__version__'],
  204. packages=["cmsisdsp","cmsisdsp.sdf","cmsisdsp.sdf.nodes","cmsisdsp.sdf.nodes.host","cmsisdsp.sdf.scheduler"],
  205. description = 'CMSIS-DSP Python API',
  206. long_description=open("PythonWrapper_README.md").read(),
  207. long_description_content_type='text/markdown',
  208. ext_modules = [moduleFiltering ,
  209. moduleMatrix,
  210. moduleSupport,
  211. moduleStatistics,
  212. moduleComplexf,
  213. moduleBasic,
  214. moduleController,
  215. moduleTransform,
  216. moduleInterpolation,
  217. moduleQuaternion,
  218. moduleFastmath,
  219. moduleDistance,
  220. moduleBayes,
  221. moduleSVM
  222. ],
  223. include_package_data=True,
  224. author = 'Copyright (C) 2010-2022 ARM Limited or its affiliates. All rights reserved.',
  225. author_email = 'christophe.favergeon@arm.com',
  226. url="https://arm-software.github.io/CMSIS_5/DSP/html/index.html",
  227. python_requires='>=3.6',
  228. license="License :: OSI Approved :: Apache Software License",
  229. platforms=['any'],
  230. classifiers=[
  231. "Programming Language :: Python :: 3",
  232. "Programming Language :: Python :: Implementation :: CPython",
  233. "Programming Language :: C",
  234. "License :: OSI Approved :: Apache Software License",
  235. "Operating System :: OS Independent",
  236. "Development Status :: 4 - Beta",
  237. "Topic :: Software Development :: Embedded Systems",
  238. "Topic :: Scientific/Engineering :: Mathematics",
  239. "Environment :: Console",
  240. "Intended Audience :: Developers",
  241. ],
  242. keywords=['development','dsp','cmsis','cmsis-dsp','Arm','signal processing','maths'],
  243. install_requires=['numpy>=1.19',
  244. 'networkx>=2.5',
  245. 'jinja2>= 2.0, <3.0',
  246. 'sympy>=1.6',
  247. 'markupsafe<2.1'
  248. ],
  249. project_urls={ # Optional
  250. 'Bug Reports': 'https://github.com/ARM-software/CMSIS_5/issues',
  251. 'Source': 'https://github.com/ARM-software/CMSIS_5/tree/develop/CMSIS/DSP',
  252. }
  253. )
  254. build()