修复了一些错误
This commit is contained in:
1 parent
61acfc2759
commit
0d77b68cc4
26 files changed
+116
-116
No files matched your search
+18
-18
@@ -38,9 +38,9 @@ class ndarray[T]:
|
||||
ndim: t.CInt
|
||||
size: t.CSizeT
|
||||
owns_data: t.CInt
|
||||
pool: memhub.MemManager | t.CPtr
|
||||
pool: rawptr[memhub.MemManager]
|
||||
|
||||
def __new__(self, pool: memhub.MemManager | t.CPtr, n: t.CSizeT):
|
||||
def __new__(self, pool: rawptr[memhub.MemManager], n: t.CSizeT):
|
||||
self.pool = pool
|
||||
self.data = pool.alloc(n * T.__sizeof__())
|
||||
if self.data:
|
||||
@@ -295,7 +295,7 @@ Uint8Array: t.CTypedef = ndarray[t.CUnsignedChar]
|
||||
# Internal helpers (specialized for float64 by default)
|
||||
# Use _alloc_ndarray_t[T] / _empty_like_t[T] for other types
|
||||
# ============================================================
|
||||
def _alloc_ndarray(pool: memhub.MemManager | t.CPtr) -> ndarray[t.CDouble] | t.CPtr:
|
||||
def _alloc_ndarray(pool: rawptr[memhub.MemManager]) -> ndarray[t.CDouble] | t.CPtr:
|
||||
a: ndarray[t.CDouble] | t.CPtr = pool.alloc(ndarray[t.CDouble].__sizeof__())
|
||||
if a:
|
||||
string.memset(a, 0, ndarray[t.CDouble].__sizeof__())
|
||||
@@ -330,7 +330,7 @@ def _empty_like(a: ndarray[t.CDouble] | t.CPtr) -> ndarray[t.CDouble] | t.CPtr:
|
||||
# ============================================================
|
||||
# Array creation functions (float64 default)
|
||||
# ============================================================
|
||||
def array(pool: memhub.MemManager | t.CPtr, data: t.CDouble | t.CPtr, n: t.CSizeT) -> ndarray[t.CDouble] | t.CPtr:
|
||||
def array(pool: rawptr[memhub.MemManager], data: t.CDouble | t.CPtr, n: t.CSizeT) -> ndarray[t.CDouble] | t.CPtr:
|
||||
a: ndarray[t.CDouble] | t.CPtr = _alloc_ndarray(pool)
|
||||
if not a: return None
|
||||
a.data = pool.alloc(n * t.CDouble.__sizeof__())
|
||||
@@ -346,7 +346,7 @@ def array(pool: memhub.MemManager | t.CPtr, data: t.CDouble | t.CPtr, n: t.CSize
|
||||
a.owns_data = 1
|
||||
return a
|
||||
|
||||
def zeros(pool: memhub.MemManager | t.CPtr, n: t.CSizeT) -> ndarray[t.CDouble] | t.CPtr:
|
||||
def zeros(pool: rawptr[memhub.MemManager], n: t.CSizeT) -> ndarray[t.CDouble] | t.CPtr:
|
||||
a: ndarray[t.CDouble] | t.CPtr = _alloc_ndarray(pool)
|
||||
if not a: return None
|
||||
a.data = pool.alloc(n * t.CDouble.__sizeof__())
|
||||
@@ -362,19 +362,19 @@ def zeros(pool: memhub.MemManager | t.CPtr, n: t.CSizeT) -> ndarray[t.CDouble] |
|
||||
a.owns_data = 1
|
||||
return a
|
||||
|
||||
def ones(pool: memhub.MemManager | t.CPtr, n: t.CSizeT) -> ndarray[t.CDouble] | t.CPtr:
|
||||
def ones(pool: rawptr[memhub.MemManager], n: t.CSizeT) -> ndarray[t.CDouble] | t.CPtr:
|
||||
a: ndarray[t.CDouble] | t.CPtr = zeros(pool, n)
|
||||
if not a: return None
|
||||
a.fill(t.CDouble(1.0))
|
||||
return a
|
||||
|
||||
def full(pool: memhub.MemManager | t.CPtr, n: t.CSizeT, val: t.CDouble) -> ndarray[t.CDouble] | t.CPtr:
|
||||
def full(pool: rawptr[memhub.MemManager], n: t.CSizeT, val: t.CDouble) -> ndarray[t.CDouble] | t.CPtr:
|
||||
a: ndarray[t.CDouble] | t.CPtr = zeros(pool, n)
|
||||
if not a: return None
|
||||
a.fill(val)
|
||||
return a
|
||||
|
||||
def arange(pool: memhub.MemManager | t.CPtr, start: t.CDouble, stop: t.CDouble, step: t.CDouble) -> ndarray[t.CDouble] | t.CPtr:
|
||||
def arange(pool: rawptr[memhub.MemManager], start: t.CDouble, stop: t.CDouble, step: t.CDouble) -> ndarray[t.CDouble] | t.CPtr:
|
||||
if step == t.CDouble(0.0): return None
|
||||
n: t.CSizeT = 0
|
||||
if step > t.CDouble(0.0):
|
||||
@@ -398,7 +398,7 @@ def arange(pool: memhub.MemManager | t.CPtr, start: t.CDouble, stop: t.CDouble,
|
||||
i += 1
|
||||
return a
|
||||
|
||||
def linspace(pool: memhub.MemManager | t.CPtr, start: t.CDouble, stop: t.CDouble, num: t.CSizeT) -> ndarray[t.CDouble] | t.CPtr:
|
||||
def linspace(pool: rawptr[memhub.MemManager], start: t.CDouble, stop: t.CDouble, num: t.CSizeT) -> ndarray[t.CDouble] | t.CPtr:
|
||||
if num == 0: return None
|
||||
a: ndarray[t.CDouble] | t.CPtr = zeros(pool, num)
|
||||
if not a: return None
|
||||
@@ -412,7 +412,7 @@ def linspace(pool: memhub.MemManager | t.CPtr, start: t.CDouble, stop: t.CDouble
|
||||
i += 1
|
||||
return a
|
||||
|
||||
def empty2d(pool: memhub.MemManager | t.CPtr, rows: t.CSizeT, cols: t.CSizeT) -> ndarray[t.CDouble] | t.CPtr:
|
||||
def empty2d(pool: rawptr[memhub.MemManager], rows: t.CSizeT, cols: t.CSizeT) -> ndarray[t.CDouble] | t.CPtr:
|
||||
a: ndarray[t.CDouble] | t.CPtr = _alloc_ndarray(pool)
|
||||
if not a: return None
|
||||
total: t.CSizeT = rows * cols
|
||||
@@ -430,16 +430,16 @@ def empty2d(pool: memhub.MemManager | t.CPtr, rows: t.CSizeT, cols: t.CSizeT) ->
|
||||
_compute_strides(a)
|
||||
return a
|
||||
|
||||
def zeros2d(pool: memhub.MemManager | t.CPtr, rows: t.CSizeT, cols: t.CSizeT) -> ndarray[t.CDouble] | t.CPtr:
|
||||
def zeros2d(pool: rawptr[memhub.MemManager], rows: t.CSizeT, cols: t.CSizeT) -> ndarray[t.CDouble] | t.CPtr:
|
||||
return empty2d(pool, rows, cols)
|
||||
|
||||
def ones2d(pool: memhub.MemManager | t.CPtr, rows: t.CSizeT, cols: t.CSizeT) -> ndarray[t.CDouble] | t.CPtr:
|
||||
def ones2d(pool: rawptr[memhub.MemManager], rows: t.CSizeT, cols: t.CSizeT) -> ndarray[t.CDouble] | t.CPtr:
|
||||
a: ndarray[t.CDouble] | t.CPtr = empty2d(pool, rows, cols)
|
||||
if not a: return None
|
||||
a.fill(t.CDouble(1.0))
|
||||
return a
|
||||
|
||||
def eye(pool: memhub.MemManager | t.CPtr, n: t.CSizeT) -> ndarray[t.CDouble] | t.CPtr:
|
||||
def eye(pool: rawptr[memhub.MemManager], n: t.CSizeT) -> ndarray[t.CDouble] | t.CPtr:
|
||||
a: ndarray[t.CDouble] | t.CPtr = empty2d(pool, n, n)
|
||||
if not a: return None
|
||||
i: t.CSizeT = 0
|
||||
@@ -448,7 +448,7 @@ def eye(pool: memhub.MemManager | t.CPtr, n: t.CSizeT) -> ndarray[t.CDouble] | t
|
||||
i += 1
|
||||
return a
|
||||
|
||||
def diag(pool: memhub.MemManager | t.CPtr, vals: ndarray[t.CDouble] | t.CPtr) -> ndarray[t.CDouble] | t.CPtr:
|
||||
def diag(pool: rawptr[memhub.MemManager], vals: ndarray[t.CDouble] | t.CPtr) -> ndarray[t.CDouble] | t.CPtr:
|
||||
n: t.CSizeT = vals.size
|
||||
a: ndarray[t.CDouble] | t.CPtr = empty2d(pool, n, n)
|
||||
if not a: return None
|
||||
@@ -1033,10 +1033,10 @@ def np_greater_equal(a: ndarray[t.CDouble] | t.CPtr, b: ndarray[t.CDouble] | t.C
|
||||
# ============================================================
|
||||
# Additional creation functions (float64 default)
|
||||
# ============================================================
|
||||
def empty(pool: memhub.MemManager | t.CPtr, n: t.CSizeT) -> ndarray[t.CDouble] | t.CPtr:
|
||||
def empty(pool: rawptr[memhub.MemManager], n: t.CSizeT) -> ndarray[t.CDouble] | t.CPtr:
|
||||
return zeros(pool, n)
|
||||
|
||||
def full2d(pool: memhub.MemManager | t.CPtr, rows: t.CSizeT, cols: t.CSizeT, val: t.CDouble) -> ndarray[t.CDouble] | t.CPtr:
|
||||
def full2d(pool: rawptr[memhub.MemManager], rows: t.CSizeT, cols: t.CSizeT, val: t.CDouble) -> ndarray[t.CDouble] | t.CPtr:
|
||||
a: ndarray[t.CDouble] | t.CPtr = empty2d(pool, rows, cols)
|
||||
if not a: return None
|
||||
a.fill(val)
|
||||
@@ -1066,10 +1066,10 @@ def ones_like(a: ndarray[t.CDouble] | t.CPtr) -> ndarray[t.CDouble] | t.CPtr:
|
||||
result.fill(t.CDouble(1.0))
|
||||
return result
|
||||
|
||||
def arange1(pool: memhub.MemManager | t.CPtr, stop: t.CDouble) -> ndarray[t.CDouble] | t.CPtr:
|
||||
def arange1(pool: rawptr[memhub.MemManager], stop: t.CDouble) -> ndarray[t.CDouble] | t.CPtr:
|
||||
return arange(pool, t.CDouble(0.0), stop, t.CDouble(1.0))
|
||||
|
||||
def linspace2(pool: memhub.MemManager | t.CPtr, start: t.CDouble, stop: t.CDouble) -> ndarray[t.CDouble] | t.CPtr:
|
||||
def linspace2(pool: rawptr[memhub.MemManager], start: t.CDouble, stop: t.CDouble) -> ndarray[t.CDouble] | t.CPtr:
|
||||
return linspace(pool, start, stop, 50)
|
||||
|
||||
def meshgrid(x: ndarray[t.CDouble] | t.CPtr, y: ndarray[t.CDouble] | t.CPtr) -> ndarray[t.CDouble] | t.CPtr:
|
||||
|
||||
Reference in new issue
Block a user