def __div__(self, other):
"""
Division
self / other
Parameters
----------
other: scalar or Pitcharray
Returns
-------
out : PitchArray
A new PitchArray
"""
if isinstance(other, PitchArray):
if self.shape != other.shape:
raise ValueError("array dimension misaligned")
result = self._new_like_me(_get_common_dtype(self, other))
if self.size:
if self.M == 1:
func = pu.get_divarray_function(
self.dtype, other.dtype, result.dtype, pitch = False)
func.prepared_call(
self._grid, self._block, result.gpudata,
self.gpudata, other.gpudata, self.size)
else:
func = pu.get_divarray_function(
self.dtype, other.dtype, result.dtype, pitch = True)
func.prepared_call(
self._grid, self._block, self.M, self.N,
result.gpudata, result.ld, self.gpudata,
self.ld, other.gpudata, other.ld)
return result
elif issubclass(type(other), (float, int, complex, np.integer,
np.floating, np.complexfloating)):
dtype = _get_common_dtype_with_scalar(other, self)
if other == 1.0:
return self.astype(dtype)
else:
result = self._new_like_me(dtype)
if self.size:
if self.M == 1:
func = pu.get_divscalar_function(
self.dtype, dtype, pitch = False)
func.prepared_call(
self._grid, self._block, result.gpudata,
self.gpudata, other, self.size)
else:
func = pu.get_divscalar_function(
self.dtype, dtype, pitch = True)
func.prepared_call(
self._grid, self._block, self.M, self.N,
result.gpudata, result.ld, self.gpudata,
self.ld, other)
return result
else:
raise TypeError("type of object to be divided "
"is not supported")
评论列表
文章目录