def _rvs(self, low, high):
     """An array of *size* random integers >= ``low`` and < ``high``."""
     if self._size is not None:
         # Numpy's RandomState.randint() doesn't broadcast its arguments.
         # Use `broadcast_to()` to extend the shapes of low and high
         # up to self._size.  Then we can use the numpy.vectorize'd
         # randint without needing to pass it a `size` argument.
         low = broadcast_to(low, self._size)
         high = broadcast_to(high, self._size)
     randint = np.vectorize(self._random_state.randint, otypes=[np.int_])
     return randint(low, high)
Esempio n. 2
0
 def _rvs(self, low, high):
     """An array of *size* random integers >= ``low`` and < ``high``."""
     if self._size is not None:
         # Numpy's RandomState.randint() doesn't broadcast its arguments.
         # Use `broadcast_to()` to extend the shapes of low and high
         # up to self._size.  Then we can use the numpy.vectorize'd
         # randint without needing to pass it a `size` argument.
         low = broadcast_to(low, self._size)
         high = broadcast_to(high, self._size)
     randint = np.vectorize(self._random_state.randint, otypes=[np.int_])
     return randint(low, high)
Esempio n. 3
0
 def __rsub__(self, other):  # other - self
     if isscalarlike(other):
         if other == 0:
             return -self.copy()
         raise NotImplementedError('subtracting a sparse matrix from a '
                                   'nonzero scalar is not supported')
     elif isdense(other):
         other = broadcast_to(other, self.shape)
         return self._rsub_dense(other)
     else:
         return NotImplemented
Esempio n. 4
0
 def __rsub__(self,other):  # other - self
     if isscalarlike(other):
         if other == 0:
             return -self.copy()
         raise NotImplementedError('subtracting a sparse matrix from a '
                                   'nonzero scalar is not supported')
     elif isdense(other):
         other = broadcast_to(other, self.shape)
         return self._rsub_dense(other)
     else:
         return NotImplemented
Esempio n. 5
0
 def __sub__(self, other):  # self - other
     if isscalarlike(other):
         if other == 0:
             return self.copy()
         raise NotImplementedError('subtracting a nonzero scalar from a '
                                   'sparse matrix is not supported')
     elif isspmatrix(other):
         if other.shape != self.shape:
             raise ValueError("inconsistent shapes")
         return self._sub_sparse(other)
     elif isdense(other):
         other = broadcast_to(other, self.shape)
         return self._sub_dense(other)
     else:
         return NotImplemented
Esempio n. 6
0
 def __sub__(self, other):  # self - other
     if isscalarlike(other):
         if other == 0:
             return self.copy()
         raise NotImplementedError('subtracting a nonzero scalar from a '
                                   'sparse matrix is not supported')
     elif isspmatrix(other):
         if other.shape != self.shape:
             raise ValueError("inconsistent shapes")
         return self._sub_sparse(other)
     elif isdense(other):
         other = broadcast_to(other, self.shape)
         return self._sub_dense(other)
     else:
         return NotImplemented
Esempio n. 7
0
 def __add__(self, other):  # self + other
     if isscalarlike(other):
         if other == 0:
             return self.copy()
         # Now we would add this scalar to every element.
         raise NotImplementedError('adding a nonzero scalar to a '
                                   'sparse matrix is not supported')
     elif isspmatrix(other):
         if other.shape != self.shape:
             raise ValueError("inconsistent shapes")
         return self._add_sparse(other)
     elif isdense(other):
         other = broadcast_to(other, self.shape)
         return self._add_dense(other)
     else:
         return NotImplemented
Esempio n. 8
0
 def __add__(self, other):  # self + other
     if isscalarlike(other):
         if other == 0:
             return self.copy()
         # Now we would add this scalar to every element.
         raise NotImplementedError('adding a nonzero scalar to a '
                                   'sparse matrix is not supported')
     elif isspmatrix(other):
         if other.shape != self.shape:
             raise ValueError("inconsistent shapes")
         return self._add_sparse(other)
     elif isdense(other):
         other = broadcast_to(other, self.shape)
         return self._add_dense(other)
     else:
         return NotImplemented