本文整理匯總了Python中numba.float64方法的典型用法代碼示例。如果您正苦於以下問題:Python numba.float64方法的具體用法?Python numba.float64怎麽用?Python numba.float64使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類numba
的用法示例。
在下文中一共展示了numba.float64方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: rotate_
# 需要導入模塊: import numba [as 別名]
# 或者: from numba import float64 [as 別名]
def rotate_(a, theta):
"""
rotate a theta from vector a
"""
d0 = np.cos(theta[2]) * (np.cos(theta[1]) * a[0]
+ np.sin(theta[1]) * (
np.sin(theta[0]) * a[1] + np.cos(
theta[0]) * a[2])) \
- np.sin(theta[2]) * (
np.cos(theta[0]) * a[1] - np.sin(theta[0]) * a[2])
d1 = np.sin(theta[2]) * (np.cos(theta[1]) * a[0]
+ np.sin(theta[1]) * (
np.sin(theta[0]) * a[1] + np.cos(
theta[0]) * a[2])) \
+ np.cos(theta[2]) * (
np.cos(theta[0]) * a[1] - np.sin(theta[0]) * a[2])
d2 = -np.sin(theta[1]) * a[0] + np.cos(theta[1]) * \
(np.sin(theta[0]) * a[1] + np.cos(theta[0]) * a[2])
vector = np.zeros(3, dtype=numba.float64)
vector[0] = d0
vector[1] = d1
vector[2] = d2
return vector
示例2: ij_bbox
# 需要導入模塊: import numba [as 別名]
# 或者: from numba import float64 [as 別名]
def ij_bbox(self,
xy_bbox: Tuple[float, float, float, float],
xy_border: float = 0.0,
ij_border: int = 0,
gu: bool = False) -> Tuple[int, int, int, int]:
"""
Compute bounding box in i,j pixel coordinates given a bounding box *xy_bbox* in x,y coordinates.
:param xy_bbox: Bounding box (x_min, y_min, x_max, y_max) given in the same CS as x and y.
:param xy_border: If non-zero, grows the bounding box *xy_bbox* before using it for comparisons. Defaults to 0.
:param ij_border: If non-zero, grows the returned i,j bounding box and clips it to size. Defaults to 0.
:param gu: Use generic ufunc for the computation (may be faster). Defaults to False.
:return: Bounding box in (i_min, j_min, i_max, j_max) in pixel coordinates.
Returns ``(-1, -1, -1, -1)`` if *xy_bbox* isn't intersecting any of the x,y coordinates.
"""
xy_bboxes = np.array([xy_bbox], dtype=np.float64)
ij_bboxes = np.full_like(xy_bboxes, -1, dtype=np.int64)
self.ij_bboxes(xy_bboxes, xy_border=xy_border, ij_border=ij_border, ij_bboxes=ij_bboxes, gu=gu)
# noinspection PyTypeChecker
return tuple(map(int, ij_bboxes[0]))
示例3: init_w
# 需要導入模塊: import numba [as 別名]
# 或者: from numba import float64 [as 別名]
def init_w(t, k, x, lx, w):
tb = t[k]
n = len(t)
m = len(x)
h = np.zeros(6, dtype=np.float64)#([0]*6 )
hh = np.zeros(5, dtype=np.float64)##np.array([0]*5)
te = t[n - k - 1]
l1 = k + 1
l2 = l1 + 1
for i in range(m):
arg = x[i]
if arg < tb:
arg = tb
if arg > te:
arg = te
while not (arg < t[l1] or l1 == (n - k - 1)):
l1 = l2
l2 = l1 + 1
h, hh = fpbspl(t, n, k, arg, l1, h, hh)
lx[i] = l1 - k - 1
for j in range(k + 1):
w[i][j] = h[j]
return w
示例4: csc_sprealloc_f
# 需要導入模塊: import numba [as 別名]
# 或者: from numba import float64 [as 別名]
def csc_sprealloc_f(An, Aindptr, Aindices, Adata, nzmax):
"""
Change the max # of entries a sparse matrix can hold.
:param An: number of columns
:param Aindptr: csc column pointers
:param Aindices: csc row indices
:param Adata: csc data
:param nzmax:new maximum number of entries
:return: indices, data, nzmax
"""
if nzmax <= 0:
nzmax = Aindptr[An]
length = min(nzmax, len(Aindices))
Ainew = np.empty(nzmax, dtype=nb.int32)
for i in range(length):
Ainew[i] = Aindices[i]
length = min(nzmax, len(Adata))
Axnew = np.empty(nzmax, dtype=nb.float64)
for i in range(length):
Axnew[i] = Adata[i]
return Ainew, Axnew, nzmax
示例5: csc_mat_vec_ff
# 需要導入模塊: import numba [as 別名]
# 或者: from numba import float64 [as 別名]
def csc_mat_vec_ff(m, n, Ap, Ai, Ax, x):
"""
Sparse matrix times dense column vector, y = A * x.
:param m: number of rows
:param n: number of columns
:param Ap: pointers
:param Ai: indices
:param Ax: data
:param x: vector x (n)
:return: vector y (m)
"""
assert n == x.shape[0]
y = np.zeros(m, dtype=nb.float64)
for j in range(n):
for p in range(Ap[j], Ap[j + 1]):
y[Ai[p]] += Ax[p] * x[j]
return y
示例6: csc_to_dense
# 需要導入模塊: import numba [as 別名]
# 或者: from numba import float64 [as 別名]
def csc_to_dense(m, n, indptr, indices, data):
"""
Convert csc matrix to dense
:param m:
:param n:
:param indptr:
:param indices:
:param data:
:return: 2d numpy array
"""
val = np.zeros((m, n), dtype=np.float64)
for j in range(n):
for p in range(indptr[j], indptr[j + 1]):
val[indices[p], j] = data[p]
return val
示例7: csc_diagonal
# 需要導入模塊: import numba [as 別名]
# 或者: from numba import float64 [as 別名]
def csc_diagonal(m, value=1.0):
"""
Build CSC diagonal matrix of the given value
:param m: size
:param value: value
:return: CSC matrix
"""
indptr = np.empty(m + 1, dtype=np.int32)
indices = np.empty(m, dtype=np.int32)
data = np.empty(m, dtype=np.float64)
for i in range(m):
indptr[i] = i
indices[i] = i
data[i] = value
indptr[m] = m
return indices, indptr, data
示例8: csc_diagonal_from_array
# 需要導入模塊: import numba [as 別名]
# 或者: from numba import float64 [as 別名]
def csc_diagonal_from_array(m, array):
"""
:param m:
:param array:
:return:
"""
indptr = np.empty(m + 1, dtype=np.int32)
indices = np.empty(m, dtype=np.int32)
data = np.empty(m, dtype=np.float64)
for i in range(m):
indptr[i] = i
indices[i] = i
data[i] = array[i]
indptr[m] = m
return indices, indptr, data
示例9: rot_axis
# 需要導入模塊: import numba [as 別名]
# 或者: from numba import float64 [as 別名]
def rot_axis(angle, axis):
# RX = np.array([ [1, 0, 0],
# [0, np.cos(gamma), -np.sin(gamma)],
# [0, np.sin(gamma), np.cos(gamma)]])
#
# RY = np.array([ [ np.cos(beta), 0, np.sin(beta)],
# [ 0, 1, 0],
# [-np.sin(beta), 0, np.cos(beta)]])
#
# RZ = np.array([ [np.cos(alpha), -np.sin(alpha), 0],
# [np.sin(alpha), np.cos(alpha), 0],
# [ 0, 0, 1]])
cg = np.cos(angle)
sg = np.sin(angle)
if axis == 0: # X
v = [0, 4, 5, 7, 8]
elif axis == 1: # Y
v = [4, 0, 6, 2, 8]
else: # Z
v = [8, 0, 1, 3, 4]
RX = np.zeros(9, dtype=numba.float64)
RX[v[0]] = 1.0
RX[v[1]] = cg
RX[v[2]] = -sg
RX[v[3]] = sg
RX[v[4]] = cg
return RX.reshape(3, 3)
示例10: _rotation_matrix
# 需要導入模塊: import numba [as 別名]
# 或者: from numba import float64 [as 別名]
def _rotation_matrix(axis, angle):
"""
This method produces a rotation matrix given an axis and an angle.
"""
axis_norm = _norm(axis)
for k in range(3):
axis[k] = axis[k] / axis_norm
axis_squared = axis**2
cos_angle = np.cos(angle)
sin_angle = np.sin(angle)
rotation_matrix = np.zeros((3,3), dtype=float64)
rotation_matrix[0, 0] = cos_angle + axis_squared[0]*(1.0-cos_angle)
rotation_matrix[0, 1] = axis[0]*axis[1]*(1.0-cos_angle) - axis[2]*sin_angle
rotation_matrix[0, 2] = axis[0]*axis[2]*(1.0-cos_angle) + axis[1]*sin_angle
rotation_matrix[1, 0] = axis[1]*axis[0]*(1.0-cos_angle) + axis[2]*sin_angle
rotation_matrix[1, 1] = cos_angle + axis_squared[1]*(1.0-cos_angle)
rotation_matrix[1, 2] = axis[1]*axis[2]*(1.0-cos_angle) - axis[0]*sin_angle
rotation_matrix[2, 0] = axis[2]*axis[0]*(1.0-cos_angle) - axis[1]*sin_angle
rotation_matrix[2, 1] = axis[2]*axis[1]*(1.0-cos_angle) + axis[0]*sin_angle
rotation_matrix[2, 2] = cos_angle + axis_squared[2]*(1.0-cos_angle)
return rotation_matrix
示例11: __init__
# 需要導入模塊: import numba [as 別名]
# 或者: from numba import float64 [as 別名]
def __init__(self, j2_max, j3_max):
self._size = j2_max + j3_max + 1
self.workspace = np.empty(4 * self._size, dtype=np.float64)
示例12: points_to_angles
# 需要導入模塊: import numba [as 別名]
# 或者: from numba import float64 [as 別名]
def points_to_angles(points):
angles = np.empty(len(points) - 1, dtype=np.float64)
for i, (p1, p2) in enumerate(zip(points[0:-1], points[1:])):
angles[i] = np.arctan2(p2[1] - p1[1], p2[0] - p1[0])
return angles
示例13: transform_lists_to_arrays
# 需要導入模塊: import numba [as 別名]
# 或者: from numba import float64 [as 別名]
def transform_lists_to_arrays(module, to_change, __funcs, vec=False, cache_blacklist=set([])):
if vec:
conv_fun = numba.vectorize
extra_args = extra_args_vec
else:
conv_fun = numba.njit
extra_args = extra_args_std
for s in to_change:
func = s.split('.')[-1]
mod = '.'.join(s.split('.')[:-1])
fake_mod = __funcs[mod]
try:
real_mod = getattr(module, mod)
except:
real_mod = module
for s in mod.split('.'):
real_mod = getattr(real_mod, s)
orig_func = getattr(real_mod, func)
source = inspect.getsource(orig_func)
source = remove_for_numba(source) # do before anything else
source = return_value_numpy(source)
source = re.sub(list_mult_expr, numpy_not_list_expr, source)
# if 'longitude_obliquity_nutation' in s:
# print(source)
numba_exec_cacheable(source, fake_mod.__dict__, fake_mod.__dict__)
new_func = fake_mod.__dict__[func]
do_cache = caching and func not in cache_blacklist
obj = conv_fun(cache=do_cache, **extra_args)(new_func)
__funcs[func] = obj
fake_mod.__dict__[func] = obj
obj.__doc__ = ''
#set_signatures = {'Clamond': [numba.float64(numba.float64, numba.float64, numba.boolean),
# numba.float64(numba.float64, numba.float64, numba.optional(numba.boolean))
# ]
# }
示例14: sequential_rotor_estimation_chunks
# 需要導入模塊: import numba [as 別名]
# 或者: from numba import float64 [as 別名]
def sequential_rotor_estimation_chunks(reference_model_array, query_model_array, n_samples, n_objects_per_sample, mutation_probability=None):
# Stack up a list of numbers
total_matches = n_samples*n_objects_per_sample
sample_indices = random.sample(range(total_matches), total_matches)
n_mvs = reference_model_array.shape[0]
sample_indices = [i % n_mvs for i in sample_indices]
if mutation_probability is not None:
reference_model_array_new = []
mutation_flag = np.random.binomial(1, mutation_probability, total_matches)
for mut, i in zip(mutation_flag, sample_indices):
if mut:
ref_ind = random.sample(range(len(reference_model_array)), 1)[0]
else:
ref_ind = i
reference_model_array_new.append(reference_model_array[ref_ind, :])
reference_model_array_new = np.array(reference_model_array_new)
else:
reference_model_array_new = np.array([reference_model_array[i, :] for i in sample_indices], dtype=np.float64)
query_model_array_new = np.array([query_model_array[i, :] for i in sample_indices], dtype=np.float64)
output = np.zeros((n_samples, 32), dtype=np.float64)
cost_array = np.zeros(n_samples, dtype=np.float64)
sequential_rotor_estimation_chunks_jit(reference_model_array_new, query_model_array_new, output, cost_array)
return output, cost_array
示例15: sequential_rotor_estimation_cuda
# 需要導入模塊: import numba [as 別名]
# 或者: from numba import float64 [as 別名]
def sequential_rotor_estimation_cuda(reference_model_array, query_model_array, n_samples=None, n_objects_per_sample=None, mutation_probability=None):
if n_samples is None:
n_samples = int(len(query_model_array)/2)
if n_objects_per_sample is None:
n_objects_per_sample = max(int(len(query_model_array)/10), 5)
# Stack up a list of numbers
total_matches = n_samples*n_objects_per_sample
sample_indices = random.sample(range(total_matches), total_matches)
n_mvs = reference_model_array.shape[0]
sample_indices = [i % n_mvs for i in sample_indices]
if mutation_probability is not None:
reference_model_array_new = []
mutation_flag = np.random.binomial(1, mutation_probability, total_matches)
for mut, i in zip(mutation_flag, sample_indices):
if mut:
ref_ind = random.sample(range(len(reference_model_array)), 1)[0]
else:
ref_ind = i
reference_model_array_new.append(reference_model_array[ref_ind, :])
reference_model_array_new = np.array(reference_model_array_new)
else:
reference_model_array_new = np.array([reference_model_array[i, :] for i in sample_indices], dtype=np.float64)
query_model_array_new = np.array([query_model_array[i, :] for i in sample_indices], dtype=np.float64)
output = np.zeros((n_samples, 32), dtype=np.float64)
cost_array = np.zeros(n_samples, dtype=np.float64)
blockdim = 64
griddim = int(math.ceil(reference_model_array_new.shape[0] / blockdim))
sequential_rotor_estimation_kernel[griddim, blockdim](reference_model_array_new, query_model_array_new, output, cost_array)
return output, cost_array