l0n0lc 0.5.0__py3-none-any.whl → 0.6.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,5 @@
1
1
  from typing import Union, List, get_origin, get_args
2
2
  from .通用 import 生成变量Id, toCString
3
- import numpy as np
4
3
  import ctypes
5
4
 
6
5
 
@@ -61,10 +60,6 @@ def py类型转ctypes类型(类型):
61
60
  if 类型 is 指针:
62
61
  return ctypes.c_void_p
63
62
 
64
- # numpy dtype 转换
65
- return numpy类型转ctypes类型(类型)
66
-
67
-
68
63
  额外py转c函数 = []
69
64
 
70
65
 
@@ -104,98 +99,12 @@ def py类型转c类型(类型):
104
99
  val_type = py类型转c类型(args[1])
105
100
  return f"std::unordered_map<{key_type}, {val_type}>&"
106
101
 
107
- # numpy dtype 转换
108
- ret = numpy类型转c类型(类型)
109
- if ret is not None:
110
- return ret
111
-
112
102
  # 直接传字符串类型名
113
103
  if isinstance(类型, str):
114
104
  return 类型
115
105
 
116
106
  return cpp类型.ANY
117
107
 
118
-
119
- 额外numpy转ctypes函数 = []
120
-
121
-
122
- def numpy类型转ctypes类型(npdtype):
123
- ret = 执行额外函数(额外numpy转ctypes函数, npdtype)
124
- if ret is not None:
125
- return ret
126
-
127
- if npdtype == np.int8:
128
- return ctypes.c_int8
129
- if npdtype == np.int16:
130
- return ctypes.c_int16
131
- if npdtype == np.int32:
132
- return ctypes.c_int32
133
- if npdtype == np.int64:
134
- return ctypes.c_int64
135
- if npdtype == np.uint8:
136
- return ctypes.c_uint8
137
- if npdtype == np.uint16:
138
- return ctypes.c_uint16
139
- if npdtype == np.uint32:
140
- return ctypes.c_uint32
141
- if npdtype == np.uint64:
142
- return ctypes.c_uint64
143
- try:
144
- if npdtype == np.bool_:
145
- return ctypes.c_bool
146
- except:
147
- pass
148
- try:
149
- if npdtype == np.bool: # type: ignore
150
- return ctypes.c_bool
151
- except:
152
- pass
153
- if npdtype == np.float32:
154
- return ctypes.c_float
155
- if npdtype == np.float64:
156
- return ctypes.c_double
157
-
158
-
159
- 额外numpy转c函数 = []
160
-
161
-
162
- def numpy类型转c类型(npdtype):
163
- ret = 执行额外函数(额外numpy转c函数, npdtype)
164
- if ret is not None:
165
- return ret
166
-
167
- if npdtype == np.int8:
168
- return cpp类型.INT8_T
169
- if npdtype == np.int16:
170
- return cpp类型.INT16_T
171
- if npdtype == np.int32:
172
- return cpp类型.INT32_T
173
- if npdtype == np.int64:
174
- return cpp类型.INT64_T
175
- if npdtype == np.uint8:
176
- return cpp类型.UINT8_T
177
- if npdtype == np.uint16:
178
- return cpp类型.UINT16_T
179
- if npdtype == np.uint32:
180
- return cpp类型.UINT32_T
181
- if npdtype == np.uint64:
182
- return cpp类型.UINT64_T
183
- try:
184
- if npdtype == np.bool_:
185
- return cpp类型.BOOL
186
- except:
187
- pass
188
- try:
189
- if npdtype == np.bool: # type: ignore
190
- return cpp类型.BOOL
191
- except:
192
- pass
193
- if npdtype == np.float16:
194
- return cpp类型.HALF
195
- if npdtype == np.float32:
196
- return cpp类型.FLOAT
197
-
198
-
199
108
  def cpp类型检查(类型, 支持提示: str):
200
109
  if 类型 not in [int, float, str, bool]:
201
110
  raise Exception(f'{支持提示} 仅支持 [int, float, str, bool]')
@@ -235,15 +144,6 @@ def 从list构建初始化列表(value: List):
235
144
  return list初始化列表(初始化列表, 数据类型列表, len(value))
236
145
 
237
146
 
238
- def 从ndarray构建初始化列表(value: np.ndarray):
239
- value = value.reshape(value.size)
240
- 类型 = numpy类型转c类型(value.dtype)
241
- if 类型 is None:
242
- raise Exception(f'暂不支持{value.dtype}')
243
- 初始化列表 = '{' + ','.join(value) + '}'
244
- return list初始化列表(初始化列表, 类型, value.size)
245
-
246
-
247
147
  class dict初始化列表:
248
148
  def __init__(
249
149
  self,
l0n0lc/jit.py CHANGED
@@ -290,10 +290,6 @@ class py2cpp编译器(ast.NodeVisitor):
290
290
  参数字符串 = ','.join(参数列表)
291
291
  return f'{fn.__name__}({参数字符串});'
292
292
 
293
- def 获取numpy属性(self, 对象, 属性):
294
- if 属性 == 'size':
295
- pass
296
-
297
293
  def 获取Subscript(self, node: ast.Subscript):
298
294
  对象 = self.获取值(node.value)
299
295
  切片 = node.slice
@@ -546,17 +542,17 @@ class py2cpp编译器(ast.NodeVisitor):
546
542
  return self.cpp函数(*args)
547
543
 
548
544
 
549
- def jit(jit编译器=py2cpp编译器, cpp编译器=cpp编译器, 每次运行都重新编译: bool = False):
545
+ def jit(jit编译器=None, c编译器=None, 每次运行都重新编译: bool = False):
550
546
  def 编译函数(fn: Callable):
551
547
 
552
548
  # print(ast.dump(语法树, indent=' '))
553
- c语言函数编译器 = jit编译器(fn)
549
+ c语言函数编译器 = jit编译器 or py2cpp编译器(fn)
554
550
  库文件名 = c语言函数编译器.获取库文件名()
555
551
  # 检测是否已存在
556
552
  if 每次运行都重新编译 or not os.path.exists(f'{通用信息.工作文件夹地址}/{库文件名}'):
557
553
  c语言函数编译器.编译()
558
554
  c语言函数编译器.将代码保存到文件()
559
- 编译器 = cpp编译器()
555
+ 编译器 = c编译器 or cpp编译器()
560
556
  编译器.include目录列表 = list(c语言函数编译器.include目录)
561
557
  编译器.库目录列表 = list(c语言函数编译器.库目录)
562
558
  编译器.链接库 = list(c语言函数编译器.链接库列表)
@@ -1,12 +1,11 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: l0n0lc
3
- Version: 0.5.0
3
+ Version: 0.6.0
4
4
  Summary: 用python写c
5
5
  Classifier: Programming Language :: Python :: 3
6
6
  Requires-Python: >=3.10
7
7
  Description-Content-Type: text/markdown
8
8
  License-File: LICENSE
9
- Requires-Dist: numpy>=1.26.0
10
9
  Dynamic: license-file
11
10
 
12
11
  # 将python函数翻译为c++函数并运行
@@ -0,0 +1,12 @@
1
+ l0n0lc/StdList.py,sha256=fA6sWAfW2JgDUhQDK2Hlx_PPuSdLwTcCTk5aha4zA-Q,863
2
+ l0n0lc/StdMap.py,sha256=TIVKqhT078cjLIM0Zlq-TwGFSy-KwOyJe00BLFPVxr8,735
3
+ l0n0lc/__init__.py,sha256=fUC6TMeN_fEL7HDazrBEdoWOQkXi5uSGZb7LZj6juog,137
4
+ l0n0lc/c基础处理.py,sha256=FMauoVx4-33JXl4OLpUl1D6NCkLjk6yBH7do9WnT0Wg,5671
5
+ l0n0lc/jit.py,sha256=WEVbF6__oULyekz2hizkp7T30NHkDjgyuq1P_fpkSIM,22634
6
+ l0n0lc/编译.py,sha256=f1ugdTpnKcDOprcGu2Q5zMm_sYdxWMphBeo4ZL-cW3o,2016
7
+ l0n0lc/通用.py,sha256=O_Y4bbW1WzHCJkibxAy9WGACv-aEZJLG-fEeVBcAbBQ,3649
8
+ l0n0lc-0.6.0.dist-info/licenses/LICENSE,sha256=1L-MAjulZ3kpbYwsJtlXpDVITRxykna2Ecg_521YfkA,1093
9
+ l0n0lc-0.6.0.dist-info/METADATA,sha256=emcsYp78PoDOzeVWMnTXMgSiExmDDssEsvupVhbb4ec,2400
10
+ l0n0lc-0.6.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
11
+ l0n0lc-0.6.0.dist-info/top_level.txt,sha256=Q21D_eEY_-xgRUPwATGp9YDKSBO4w_7MI2MYxQI1aT4,7
12
+ l0n0lc-0.6.0.dist-info/RECORD,,
@@ -1,12 +0,0 @@
1
- l0n0lc/StdList.py,sha256=fA6sWAfW2JgDUhQDK2Hlx_PPuSdLwTcCTk5aha4zA-Q,863
2
- l0n0lc/StdMap.py,sha256=TIVKqhT078cjLIM0Zlq-TwGFSy-KwOyJe00BLFPVxr8,735
3
- l0n0lc/__init__.py,sha256=fUC6TMeN_fEL7HDazrBEdoWOQkXi5uSGZb7LZj6juog,137
4
- l0n0lc/c基础处理.py,sha256=ZJEMxK1MyRAgbUnpfUUZC0ZHj61RCD6UMlhVssCyiCE,8201
5
- l0n0lc/jit.py,sha256=zI6erRTE90chukkpovOCwAHXxFUI-SSaDvsmFKHwLYs,22718
6
- l0n0lc/编译.py,sha256=f1ugdTpnKcDOprcGu2Q5zMm_sYdxWMphBeo4ZL-cW3o,2016
7
- l0n0lc/通用.py,sha256=O_Y4bbW1WzHCJkibxAy9WGACv-aEZJLG-fEeVBcAbBQ,3649
8
- l0n0lc-0.5.0.dist-info/licenses/LICENSE,sha256=1L-MAjulZ3kpbYwsJtlXpDVITRxykna2Ecg_521YfkA,1093
9
- l0n0lc-0.5.0.dist-info/METADATA,sha256=bpEXrXY0TGG96jvvcscid62YkzZWcQcLMNH6KfruUDc,2429
10
- l0n0lc-0.5.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
11
- l0n0lc-0.5.0.dist-info/top_level.txt,sha256=Q21D_eEY_-xgRUPwATGp9YDKSBO4w_7MI2MYxQI1aT4,7
12
- l0n0lc-0.5.0.dist-info/RECORD,,
File without changes