feat(includes): 软关键字 fn/fun/func/function 与 match 语句判定; 解析 fail-fast 错误记录(get_parse_err_*) + 相邻字符串字面量隐式拼接; ord/chr 内置函数; llvmlite build_alloca_aligned; memhub 超块请求返回 NULL; numpy 显式 string./stdio. 前缀; this 数组迭代修复
This commit is contained in:
1 parent
dd5a639437
commit
a6444a4e1f
9 files changed
+320
-38
No files matched your search
+21
-21
@@ -44,7 +44,7 @@ class ndarray[T]:
|
||||
self.pool = pool
|
||||
self.data = pool.alloc(n * T.__sizeof__())
|
||||
if self.data:
|
||||
memset(self.data, 0, n * T.__sizeof__())
|
||||
string.memset(self.data, 0, n * T.__sizeof__())
|
||||
self.ndim = 1
|
||||
self.size = n
|
||||
self.shape[0] = n
|
||||
@@ -148,7 +148,7 @@ class ndarray[T]:
|
||||
def copy(self) -> ndarray[T] | t.CPtr:
|
||||
result: ndarray[T] | t.CPtr = _empty_like(self)
|
||||
if not result: return None
|
||||
memcpy(result.data, self.data, self.size * T.__sizeof__())
|
||||
string.memcpy(result.data, self.data, self.size * T.__sizeof__())
|
||||
return result
|
||||
|
||||
def reshape(self, new_shape: INTPTR, new_ndim: t.CInt) -> ndarray[T] | t.CPtr:
|
||||
@@ -253,30 +253,30 @@ class ndarray[T]:
|
||||
|
||||
def print_arr(self):
|
||||
if self.ndim == 1:
|
||||
printf("[")
|
||||
stdio.printf("[")
|
||||
i: t.CSizeT = 0
|
||||
while i < self.size:
|
||||
if i > 0: printf(", ")
|
||||
printf("%.4f", self.data[i])
|
||||
if i > 0: stdio.printf(", ")
|
||||
stdio.printf("%.4f", self.data[i])
|
||||
i += 1
|
||||
printf("]\n")
|
||||
stdio.printf("]\n")
|
||||
elif self.ndim == 2:
|
||||
rows: t.CSizeT = self.shape[0]
|
||||
cols: t.CSizeT = self.shape[1]
|
||||
printf("[")
|
||||
stdio.printf("[")
|
||||
i: t.CSizeT = 0
|
||||
while i < rows:
|
||||
if i > 0: printf(" ")
|
||||
printf("[")
|
||||
if i > 0: stdio.printf(" ")
|
||||
stdio.printf("[")
|
||||
j: t.CSizeT = 0
|
||||
while j < cols:
|
||||
if j > 0: printf(", ")
|
||||
printf("%.4f", self.data[i * cols + j])
|
||||
if j > 0: stdio.printf(", ")
|
||||
stdio.printf("%.4f", self.data[i * cols + j])
|
||||
j += 1
|
||||
if i < rows - 1:
|
||||
printf("]\n")
|
||||
stdio.printf("]\n")
|
||||
else:
|
||||
printf("]]\n")
|
||||
stdio.printf("]]\n")
|
||||
i += 1
|
||||
|
||||
|
||||
@@ -298,7 +298,7 @@ Uint8Array: t.CTypedef = ndarray[t.CUnsignedChar]
|
||||
def _alloc_ndarray(pool: memhub.MemManager | t.CPtr) -> ndarray[t.CDouble] | t.CPtr:
|
||||
a: ndarray[t.CDouble] | t.CPtr = pool.alloc(ndarray[t.CDouble].__sizeof__())
|
||||
if a:
|
||||
memset(a, 0, ndarray[t.CDouble].__sizeof__())
|
||||
string.memset(a, 0, ndarray[t.CDouble].__sizeof__())
|
||||
return a
|
||||
|
||||
def _compute_strides(a: ndarray[t.CDouble] | t.CPtr):
|
||||
@@ -337,7 +337,7 @@ def array(pool: memhub.MemManager | t.CPtr, data: t.CDouble | t.CPtr, n: t.CSize
|
||||
if not a.data:
|
||||
pool.free(a)
|
||||
return None
|
||||
memcpy(a.data, data, n * t.CDouble.__sizeof__())
|
||||
string.memcpy(a.data, data, n * t.CDouble.__sizeof__())
|
||||
a.pool = pool
|
||||
a.ndim = 1
|
||||
a.size = n
|
||||
@@ -353,7 +353,7 @@ def zeros(pool: memhub.MemManager | t.CPtr, n: t.CSizeT) -> ndarray[t.CDouble] |
|
||||
if not a.data:
|
||||
pool.free(a)
|
||||
return None
|
||||
memset(a.data, 0, n * t.CDouble.__sizeof__())
|
||||
string.memset(a.data, 0, n * t.CDouble.__sizeof__())
|
||||
a.pool = pool
|
||||
a.ndim = 1
|
||||
a.size = n
|
||||
@@ -420,7 +420,7 @@ def empty2d(pool: memhub.MemManager | t.CPtr, rows: t.CSizeT, cols: t.CSizeT) ->
|
||||
if not a.data:
|
||||
pool.free(a)
|
||||
return None
|
||||
memset(a.data, 0, total * t.CDouble.__sizeof__())
|
||||
string.memset(a.data, 0, total * t.CDouble.__sizeof__())
|
||||
a.pool = pool
|
||||
a.ndim = 2
|
||||
a.size = total
|
||||
@@ -669,8 +669,8 @@ def concatenate(a: ndarray[t.CDouble] | t.CPtr, b: ndarray[t.CDouble] | t.CPtr)
|
||||
total: t.CSizeT = a.size + b.size
|
||||
result: ndarray[t.CDouble] | t.CPtr = zeros(a.pool, total)
|
||||
if not result: return None
|
||||
memcpy(result.data, a.data, a.size * t.CDouble.__sizeof__())
|
||||
memcpy(result.data + a.size, b.data, b.size * t.CDouble.__sizeof__())
|
||||
string.memcpy(result.data, a.data, a.size * t.CDouble.__sizeof__())
|
||||
string.memcpy(result.data + a.size, b.data, b.size * t.CDouble.__sizeof__())
|
||||
return result
|
||||
|
||||
def sort_arr(a: ndarray[t.CDouble] | t.CPtr) -> ndarray[t.CDouble] | t.CPtr:
|
||||
@@ -913,7 +913,7 @@ def flatten(a: ndarray[t.CDouble] | t.CPtr) -> ndarray[t.CDouble] | t.CPtr:
|
||||
result.ndim = 1
|
||||
result.shape[0] = a.size
|
||||
result.strides[0] = 1
|
||||
memcpy(result.data, a.data, a.size * t.CDouble.__sizeof__())
|
||||
string.memcpy(result.data, a.data, a.size * t.CDouble.__sizeof__())
|
||||
return result
|
||||
|
||||
def trace(a: ndarray[t.CDouble] | t.CPtr) -> t.CDouble:
|
||||
@@ -1049,7 +1049,7 @@ def zeros_like(a: ndarray[t.CDouble] | t.CPtr) -> ndarray[t.CDouble] | t.CPtr:
|
||||
if not result.data:
|
||||
a.pool.free(result)
|
||||
return None
|
||||
memset(result.data, 0, a.size * t.CDouble.__sizeof__())
|
||||
string.memset(result.data, 0, a.size * t.CDouble.__sizeof__())
|
||||
result.pool = a.pool
|
||||
result.ndim = a.ndim
|
||||
result.size = a.size
|
||||
|
||||
Reference in new issue
Block a user