arrayCantBeEmpty() public static method

public static arrayCantBeEmpty ( ) : InvalidArgumentException
return InvalidArgumentException
Esempio n. 1
0
 /**
  * @param array|float[] $a
  * @param bool          $sample
  *
  * @return float
  *
  * @throws InvalidArgumentException
  */
 public static function population(array $a, $sample = true)
 {
     if (empty($a)) {
         throw InvalidArgumentException::arrayCantBeEmpty();
     }
     $n = count($a);
     if ($sample && $n === 1) {
         throw InvalidArgumentException::arraySizeToSmall(2);
     }
     $mean = Mean::arithmetic($a);
     $carry = 0.0;
     foreach ($a as $val) {
         $d = $val - $mean;
         $carry += $d * $d;
     }
     if ($sample) {
         --$n;
     }
     return sqrt((double) ($carry / $n));
 }
Esempio n. 2
0
 /**
  * @param array $array
  *
  * @throws InvalidArgumentException
  */
 private static function checkArrayLength(array $array)
 {
     if (0 == count($array)) {
         throw InvalidArgumentException::arrayCantBeEmpty();
     }
 }