allocate.

@param array $ratios

@return array
496651
public function allocate(array $ratios)
    {
        $remainder = $this->amount;
        $results = [];
        $total = array_sum($ratios);

        foreach ($ratios as $ratio) {
            $share = floor($this->amount * $ratio / $total);
            $results[] = new self($share, $this->currency);
            $remainder -= $share;
        }

        for ($i = 0; $remainder > 0; $i++) {
            $results[$i]->amount++;
            $remainder--;
        }

        return $results;
    }
430730
public function divide(array $attributes = [])
    {
        $attributes['class'] = self::formatGroupClass(array('class' => 'divider'), $attributes);

        $this->items->last()->divider = $attributes;
    }
788823
def allocate(self):
        """"""
        self.logger.debug("Allocating environment.")
        self._allocate()
        self.logger.debug("Environment successfully allocated.")
518423
private function shuffleAssoc(array $values)
    {
        $keys = array_keys($values);
        shuffle($keys);

        $output = [];
        foreach ($keys as $key) {
            $output[$key] = $values[$key];
        }

        return $output;
    }
348261
private static double assignShareIfUnderAllocated(
      double totalShare,
      final Collection<? extends Schedulable> schedulables) {

    double totalMinDemand = 0;
    for (Schedulable schedulable : schedulables) {
      schedulable.share = 0;
      totalMinDemand += Math.min(schedulable.getRequested(),
                                 schedulable.getMinimum());
    }

    if ((totalMinDemand > 0) && (totalMinDemand >= totalShare)) {
      distributeShareMin(schedulables);
    }

    return totalShare - totalMinDemand;
  }
750962
public function allocateByRatios(array $ratios)
    {
        /** @var Money[] $result */
        $result = array();
        $total = array_sum($ratios);
        $remainder = $this->amount;

        for ($i = 0; $i < count($ratios); $i++) {
            $amount = $this->castToFloat($this->amount * $ratios[$i] / $total);
            $result[] = $this->newMoney($amount);
            $remainder -= $amount;
        }

        for ($i = 0; $i < $remainder; $i++) {
            $result[$i] = $this->newMoney($result[$i]->getAmount() + 1);
        }

        return $result;
    }
611640
public function allocateToTargets($n)
    {
        if (is_int($n)) {
            $n = (float)$n;
        }

        if (!is_float($n)) {
            throw new InvalidArgumentException('$n ' . \Yii::t('skeeks/money', 'must be an integer'));
        }

        $low = $this->newMoney(floatval($this->amount / $n));
        $high = $this->newMoney($low->getAmount() + 1);
        $remainder = $this->amount % $n;
        $result = array();

        for ($i = 0; $i < $remainder; $i++) {
            $result[] = $high;
        }

        for ($i = $remainder; $i < $n; $i++) {
            $result[] = $low;
        }

        return $result;
    }
118776
public function scale($ratio)
    {
        $_width = (int)$this->do_getWidth();
        $_height = (int)$this->do_getHeight();

        if ($ratio === 1) {
            return $this;
        }

        $width = (int)($_width * $ratio);
        $height = (int)($_height * $ratio);

        $this->do_resize($width, $height);

        return $this;
    }
858403
public static function multiply(array ...$arrays): array
    {
        self::checkArrayLengths($arrays);

        $number_of_arrays = count($arrays);
        $length_of_arrays = count($arrays[0]);
        $products         = array_fill(0, $length_of_arrays, 1);

        for ($i = 0; $i < $length_of_arrays; $i++) {
            for ($j = 0; $j < $number_of_arrays; $j++) {
                $products[$i] *= $arrays[$j][$i];
            }
        }

        return $products;
    }
850795
private function chunkSplit(array $thrifts): array
    {
        $actualBufferSize = $this->zipkinBatchOverheadLength;
        $chunkId = 0;
        $chunks = [];

        foreach ($thrifts as $thrift) {
            $spanBufferLength = $this->getBufferLength($thrift);

            if (!empty($chunks[$chunkId]) && ($actualBufferSize + $spanBufferLength) > $this->maxBufferLength) {
                // point to next chunk
                ++$chunkId;

                // reset buffer size
                $actualBufferSize = $this->zipkinBatchOverheadLength;
            }

            if (!isset($chunks[$chunkId])) {
                $chunks[$chunkId] = [];
            }

            $chunks[$chunkId][] = $thrift;
            $actualBufferSize += $spanBufferLength;
        }

        return $chunks;
    }
824666
public function fill(array $attributes = [])
    {
        $this->raw = $attributes;

        $excludes = config("api.excludes");

        foreach ($attributes as $key => $attribute) {
            // Guarded attributes should be removed
            if (in_array($key, $excludes)) {
                unset($attributes[$key]);
            }
            else if (method_exists($this, $key) && ((is_array($attribute) || is_null($attribute)))) {
                // Its a relation
                $this->relationAttributes[$key] = $attribute;

                // For belongs to relation, while filling, we need to set relation key.
                $relation = call_user_func([$this, $key]);

                if ($relation instanceof BelongsTo) {
                    $primaryKey = $relation->getRelated()->getKeyName();

                    if ($attribute !== null) {
                        // If key value is not set in request, we create new object
                        if (!isset($attribute[$primaryKey])) {
                            throw new RelatedResourceNotFoundException('Resource for relation "' . $key . '" not found');
                        }
                        else {
                            $model = $relation->getRelated()->find($attribute[$primaryKey]);

                            if (!$model) {
                                // Resource not found
                                throw new ResourceNotFoundException();
                            }
                        }
                    }

                    $relationKey = $relation->getForeignKey();

                    $this->setAttribute($relationKey, ($attribute === null) ? null : $model->getKey());
                }

                unset($attributes[$key]);
            }
        }

        return parent::fill($attributes);
    }
293325
public function optimize(array $policiesAndSets): array
    {
        assert(empty($policiesAndSets) === false);

        $index              = 0;
        $rawTargets         = [];
        $serializedPolicies = [];
        foreach ($policiesAndSets as $policyOrSet) {
            /** @var PolicyInterface|PolicySetInterface $policyOrSet */
            $rawTargets[$index]         = $policyOrSet->getTarget();
            $serializedPolicies[$index] = $policyOrSet instanceof PolicyInterface ?
                Encoder::encodePolicy($policyOrSet) : Encoder::encodePolicySet($policyOrSet);
            $index++;
        }

        $callable         = static::METHOD;
        $optimizedTargets = $this->optimizeTargets($rawTargets);

        /** @var callable|array $callable */
        assert($callable !== null && is_array($callable) === true &&
            is_callable($callable) === true && count($callable) === 2 &&
            is_string($callable[0]) === true && is_string($callable[1]) === true);

        return [
            static::INDEX_TARGETS           => $optimizedTargets,
            static::INDEX_POLICIES_AND_SETS => $serializedPolicies,
            static::INDEX_CALLABLE          => $callable,
        ];
    }
758927
protected function aggregateValues(array $values)
    {
        $min = $values[0];

        foreach ($values as $value) {
            if ($value < $min) {
                $min = $value;
            }
        }

        return $min;
    }
701217
public function all($array = [])
    {
        if (!empty($array)) {
            foreach ($array as $key => $model) {
                $this->set($model, is_numeric($key) ? null : $key);
            }
        }

        return $this->byAlias;
    }
1178671
public function allocate($args)
    {
        $data = Ensure::Input($args);
        $url = URIResource::Make($this->path);
        $id = Locator::Find($this->client->post($url, $data->get()));

        $data->add("id", $id);
        return Constructor::Make($this, $data->get());
    }
227510
public function allocate($filesize)
    {
        $result = @ftp_alloc($this->connection, $filesize);
        
        if ($result === false) {
            throw new Exception('Unable to allocate');
        }

        return $this;
    }
819378
public function allocate(array $ratios)
    {
        if (count($ratios) === 0) {
            throw new \InvalidArgumentException('Cannot allocate to none, ratios cannot be an empty array');
        }

        $remainder = $this->amount;
        $results = [];
        $total = array_sum($ratios);

        if ($total <= 0) {
            throw new \InvalidArgumentException('Cannot allocate to none, sum of ratios must be greater than zero');
        }

        foreach ($ratios as $key => $ratio) {
            if ($ratio < 0) {
                throw new \InvalidArgumentException('Cannot allocate to none, ratio must be zero or positive');
            }
            $share = $this->getCalculator()->share($this->amount, $ratio, $total);
            $results[$key] = $this->newInstance($share);
            $remainder = $this->getCalculator()->subtract($remainder, $share);
        }

        if ($this->getCalculator()->compare($remainder, '0') === 0) {
            return $results;
        }

        $fractions = array_map(function ($ratio) use ($total) {
            $share = ($ratio / $total) * $this->amount;

            return $share - floor($share);
        }, $ratios);

        while ($this->getCalculator()->compare($remainder, '0') > 0) {
            $index = !empty($fractions) ? array_keys($fractions, max($fractions))[0] : 0;
            $results[$index]->amount = $this->getCalculator()->add($results[$index]->amount, '1');
            $remainder = $this->getCalculator()->subtract($remainder, '1');
            unset($fractions[$index]);
        }

        return $results;
    }