@@ -224,7 +224,7 @@ cdef class Generator:
224
224
capsule = bit_generator .capsule
225
225
cdef const char * name = "BitGenerator"
226
226
if not PyCapsule_IsValid (capsule , name ):
227
- raise ValueError ("Invalid bit generator' . The bit generator must "
227
+ raise ValueError ("Invalid bit generator. The bit generator must "
228
228
"be instantiated." )
229
229
self ._bitgen = (< bitgen_t * > PyCapsule_GetPointer (capsule , name ))[0 ]
230
230
self .lock = bit_generator .lock
@@ -635,26 +635,26 @@ cdef class Generator:
635
635
636
636
Parameters
637
637
----------
638
- a : 1-D array-like or int
638
+ a : {array_like, int}
639
639
If an ndarray, a random sample is generated from its elements.
640
- If an int, the random sample is generated as if a were np.arange(a)
641
- size : int or tuple of ints , optional
640
+ If an int, the random sample is generated from np.arange(a).
641
+ size : { int, tuple[int]} , optional
642
642
Output shape. If the given shape is, e.g., ``(m, n, k)``, then
643
643
``m * n * k`` samples are drawn from the 1-d `a`. If `a` has more
644
644
than one dimension, the `size` shape will be inserted into the
645
645
`axis` dimension, so the output ``ndim`` will be ``a.ndim - 1 +
646
646
len(size)``. Default is None, in which case a single value is
647
647
returned.
648
- replace : boolean , optional
648
+ replace : bool , optional
649
649
Whether the sample is with or without replacement
650
- p : 1-D array-like , optional
650
+ p : 1-D array_like , optional
651
651
The probabilities associated with each entry in a.
652
652
If not given the sample assumes a uniform distribution over all
653
653
entries in a.
654
654
axis : int, optional
655
655
The axis along which the selection is performed. The default, 0,
656
656
selects by row.
657
- shuffle : boolean , optional
657
+ shuffle : bool , optional
658
658
Whether the sample is shuffled when sampling without replacement.
659
659
Default is True, False provides a speedup.
660
660
@@ -725,13 +725,15 @@ cdef class Generator:
725
725
# __index__ must return an integer by python rules.
726
726
pop_size = operator .index (a .item ())
727
727
except TypeError :
728
- raise ValueError ("a must be 1-dimensional or an integer" )
728
+ raise ValueError ("a must an array or an integer" )
729
729
if pop_size <= 0 and np .prod (size ) != 0 :
730
- raise ValueError ("a must be greater than 0 unless no samples are taken" )
730
+ raise ValueError ("a must be a positive integer unless no"
731
+ "samples are taken" )
731
732
else :
732
733
pop_size = a .shape [axis ]
733
734
if pop_size == 0 and np .prod (size ) != 0 :
734
- raise ValueError ("'a' cannot be empty unless no samples are taken" )
735
+ raise ValueError ("a cannot be empty unless no samples are"
736
+ "taken" )
735
737
736
738
if p is not None :
737
739
d = len (p )
@@ -746,9 +748,9 @@ cdef class Generator:
746
748
pix = < double * > np .PyArray_DATA (p )
747
749
748
750
if p .ndim != 1 :
749
- raise ValueError ("'p' must be 1-dimensional" )
751
+ raise ValueError ("p must be 1-dimensional" )
750
752
if p .size != pop_size :
751
- raise ValueError ("'a' and 'p' must have same size" )
753
+ raise ValueError ("a and p must have same size" )
752
754
p_sum = kahan_sum (pix , d )
753
755
if np .isnan (p_sum ):
754
756
raise ValueError ("probabilities contain NaN" )
@@ -770,13 +772,14 @@ cdef class Generator:
770
772
cdf /= cdf [- 1 ]
771
773
uniform_samples = self .random (shape )
772
774
idx = cdf .searchsorted (uniform_samples , side = 'right' )
773
- idx = np .array (idx , copy = False , dtype = np .int64 ) # searchsorted returns a scalar
775
+ # searchsorted returns a scalar
776
+ idx = np .array (idx , copy = False , dtype = np .int64 )
774
777
else :
775
778
idx = self .integers (0 , pop_size , size = shape , dtype = np .int64 )
776
779
else :
777
780
if size > pop_size :
778
781
raise ValueError ("Cannot take a larger sample than "
779
- "population when ' replace= False' " )
782
+ "population when replace is False" )
780
783
elif size < 0 :
781
784
raise ValueError ("negative dimensions are not allowed" )
782
785
0 commit comments