Commit 8c1cf39a authored by Pierre Augier's avatar Pierre Augier
Browse files

Use memview in tests and doc

parent d1fe3a691037
import numpy as np
from transonic import boost
from transonic import boost, Array
MV2d = Array[np.int64, "2d", "memview"]
MV1d = Array[np.int64, "1d", "memview"]
T0 = "int[:, :]"
T1 = "int[:]"
@boost(boundscheck=False, wraparound=False)
def row_sum_loops(arr: T0, columns: T1):
def row_sum_loops(arr: MV2d, columns: MV1d):
# locals type annotations are used only for Cython
i: int
j: int
sum_: int
res: "int[]" = np.empty(arr.shape[0], dtype=arr.dtype)
res: MV1d = np.empty(arr.shape[0], dtype=np.int64)
for i in range(arr.shape[0]):
sum_ = 0
for j in range(columns.shape[0]):
......
......@@ -4,12 +4,12 @@ import numpy as np
cimport numpy as np
ctypedef fused __row_sum_loops_arr:
np.ndarray[np.int_t, ndim=2]
np.int64_t[:, :]
ctypedef fused __row_sum_loops_columns:
np.ndarray[np.int_t, ndim=1]
np.int64_t[:]
@cython.locals(i=cython.int, j=cython.int, sum_=cython.int, res=np.int_t[:])
@cython.locals(i=cython.int, j=cython.int, sum_=cython.int, res=np.int64_t[:])
cpdef row_sum_loops(__row_sum_loops_arr arr, __row_sum_loops_columns columns)
ctypedef fused __row_sum_transpose_arr:
......
......@@ -10,7 +10,7 @@ import numpy as np
@cython.wraparound(False)
def row_sum_loops(arr, columns):
# locals type annotations are used only for Cython
res = np.empty(arr.shape[0], dtype=arr.dtype)
res = np.empty(arr.shape[0], dtype=np.int64)
for i in range(arr.shape[0]):
sum_ = 0
for j in range(columns.shape[0]):
......
......@@ -6,7 +6,7 @@ import numpy as np
def row_sum_loops(arr, columns):
# locals type annotations are used only for Cython
res = np.empty(arr.shape[0], dtype=arr.dtype)
res = np.empty(arr.shape[0], dtype=np.int64)
for i in range(arr.shape[0]):
sum_ = 0
for j in range(columns.shape[0]):
......
......@@ -3,7 +3,7 @@ import numpy as np
def row_sum_loops(arr, columns):
# locals type annotations are used only for Cython
res = np.empty(arr.shape[0], dtype=arr.dtype)
res = np.empty(arr.shape[0], dtype=np.int64)
for i in range(arr.shape[0]):
sum_ = 0
for j in range(columns.shape[0]):
......
......@@ -3,7 +3,7 @@ import numpy as np
def row_sum_loops(arr, columns):
# locals type annotations are used only for Cython
res = np.empty(arr.shape[0], dtype=arr.dtype)
res = np.empty(arr.shape[0], dtype=np.int64)
for i in range(arr.shape[0]):
sum_ = 0
for j in range(columns.shape[0]):
......
export row_sum_loops(int[:, :], int[:])
export row_sum_loops(int64[:, :], int64[:])
export row_sum_transpose(int[:, :], int[:])
......
import numpy as np
from transonic import boost
from transonic import boost, Array
T0 = "int[:, :]"
T1 = "int[:]"
MV1d = Array[np.int64, "1d", "memview"]
MV2d = Array[np.int64, "2d", "memview"]
A1d = "int[:]"
A2d = "int[:, :]"
@boost
def row_sum(arr: T0, columns: T1):
def row_sum(arr: A2d, columns: A1d):
return arr.T[columns].sum(0)
@boost(boundscheck=False, wraparound=False)
def row_sum_loops(arr: T0, columns: T1):
def row_sum_loops(arr: MV2d, columns: MV1d):
# locals type annotations are used only for Cython
i: int
j: int
sum_: int
res: "int[]" = np.empty(arr.shape[0], dtype=arr.dtype)
res: MV1d = np.empty(arr.shape[0], dtype=np.int64)
for i in range(arr.shape[0]):
sum_ = 0
for j in range(columns.shape[0]):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment