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