// ScaleSimple is responsible for updating job's parallelism.
541910
func (scaler *JobScaler) ScaleSimple(namespace, name string, preconditions *ScalePrecondition, newSize uint) error {
	job, err := scaler.c.Jobs(namespace).Get(name)
	if err != nil {
		return ScaleError{ScaleGetFailure, "Unknown", err}
	}
	if preconditions != nil {
		if err := preconditions.ValidateJob(job); err != nil {
			return err
		}
	}
	parallelism := int(newSize)
	job.Spec.Parallelism = &parallelism
	if _, err := scaler.c.Jobs(namespace).Update(job); err != nil {
		if errors.IsInvalid(err) {
			return ScaleError{ScaleUpdateInvalidFailure, job.ResourceVersion, err}
		}
		return ScaleError{ScaleUpdateFailure, job.ResourceVersion, err}
	}
	return nil
}
123782
func runScale(args *docopt.Args, client controller.Client) error {
	app := mustApp()

	typeSpecs := args.All["<type>=<spec>"].([]string)

	showAll := args.Bool["--all"]

	if len(typeSpecs) > 0 && showAll {
		return fmt.Errorf("ERROR: Can't use --all when scaling")
	}

	releaseID := args.String["--release"]
	if releaseID != "" && showAll {
		return fmt.Errorf("ERROR: Can't use --all in combination with --release")
	}

	if len(typeSpecs) == 0 {
		return showFormations(client, releaseID, showAll, app)
	}

	release, err := determineRelease(client, releaseID, app)
	if err != nil {
		return err
	}

	processes := make(map[string]int, len(typeSpecs))
	tags := make(map[string]map[string]string, len(typeSpecs))
	invalid := make([]string, 0, len(release.Processes))
	for _, arg := range typeSpecs {
		i := strings.IndexRune(arg, '=')
		if i < 0 {
			return fmt.Errorf("ERROR: scale args must be of the form <typ>=<spec>")
		}

		countTags := strings.Split(arg[i+1:], ",")

		count, err := strconv.Atoi(countTags[0])
		if err != nil {
			return fmt.Errorf("ERROR: could not parse quantity in %q", arg)
		} else if count < 0 {
			return fmt.Errorf("ERROR: process quantities cannot be negative in %q", arg)
		}

		processType := arg[:i]
		if _, ok := release.Processes[processType]; ok {
			processes[processType] = count
		} else {
			invalid = append(invalid, fmt.Sprintf("%q", processType))
			continue
		}

		if len(countTags) > 1 {
			processTags := make(map[string]string, len(countTags)-1)
			for i := 1; i < len(countTags); i++ {
				keyVal := strings.SplitN(countTags[i], "=", 2)
				if len(keyVal) == 1 && keyVal[0] != "" {
					processTags[keyVal[0]] = "true"
				} else if len(keyVal) == 2 {
					processTags[keyVal[0]] = keyVal[1]
				}
			}
			tags[processType] = processTags
		}
	}
	if len(invalid) > 0 {
		return fmt.Errorf("ERROR: unknown process types: %s", strings.Join(invalid, ", "))
	}

	opts := ct.ScaleOptions{
		Processes: processes,
		Tags:      tags,
		NoWait:    args.Bool["--no-wait"],
	}

	status, err := client.Status()
	if err != nil {
		return err
	}
	v := version.Parse(status.Version)
	if !v.Dev && v.Before(version.Parse(minScaleRequestVersion)) {
		return runScaleWithJobEvents(client, app, release, opts)
	}
	return runScaleWithScaleRequest(client, app, release, opts)
}
191732
func scaleFromCustomResource(cr *unstructured.Unstructured, specReplicasPath, statusReplicasPath, labelSelectorPath string) (*autoscalingv1.Scale, bool, error) {
	specReplicasPath = strings.TrimPrefix(specReplicasPath, ".") // ignore leading period
	specReplicas, foundSpecReplicas, err := unstructured.NestedInt64(cr.UnstructuredContent(), strings.Split(specReplicasPath, ".")...)
	if err != nil {
		return nil, false, err
	} else if !foundSpecReplicas {
		specReplicas = 0
	}

	statusReplicasPath = strings.TrimPrefix(statusReplicasPath, ".") // ignore leading period
	statusReplicas, found, err := unstructured.NestedInt64(cr.UnstructuredContent(), strings.Split(statusReplicasPath, ".")...)
	if err != nil {
		return nil, false, err
	} else if !found {
		statusReplicas = 0
	}

	var labelSelector string
	if len(labelSelectorPath) > 0 {
		labelSelectorPath = strings.TrimPrefix(labelSelectorPath, ".") // ignore leading period
		labelSelector, found, err = unstructured.NestedString(cr.UnstructuredContent(), strings.Split(labelSelectorPath, ".")...)
		if err != nil {
			return nil, false, err
		}
	}

	scale := &autoscalingv1.Scale{
		// Populate apiVersion and kind so conversion recognizes we are already in the desired GVK and doesn't try to convert
		TypeMeta: metav1.TypeMeta{
			APIVersion: "autoscaling/v1",
			Kind:       "Scale",
		},
		ObjectMeta: metav1.ObjectMeta{
			Name:              cr.GetName(),
			Namespace:         cr.GetNamespace(),
			UID:               cr.GetUID(),
			ResourceVersion:   cr.GetResourceVersion(),
			CreationTimestamp: cr.GetCreationTimestamp(),
		},
		Spec: autoscalingv1.ScaleSpec{
			Replicas: int32(specReplicas),
		},
		Status: autoscalingv1.ScaleStatus{
			Replicas: int32(statusReplicas),
			Selector: labelSelector,
		},
	}

	return scale, foundSpecReplicas, nil
}
1241407
func Convert_autoscaling_Scale_To_v1_Scale(in *autoscaling.Scale, out *v1.Scale, s conversion.Scope) error {
	return autoConvert_autoscaling_Scale_To_v1_Scale(in, out, s)
}
331849
func (h Histogram) Scale(s ScaleFunc, idx int) float64 {
	bkt := h.Buckets[idx]
	scale := s(h.Min, h.Max, bkt.Count)
	return scale
}
1344486
func (s *VirtualMachineService) ScaleVirtualMachine(p *ScaleVirtualMachineParams) (*ScaleVirtualMachineResponse, error) {
	resp, err := s.cs.newRequest("scaleVirtualMachine", p.toURLValues())
	if err != nil {
		return nil, err
	}

	var r ScaleVirtualMachineResponse
	if err := json.Unmarshal(resp, &r); err != nil {
		return nil, err
	}

	// If we have a async client, we need to wait for the async result
	if s.cs.async {
		b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
		if err != nil {
			if err == AsyncTimeoutErr {
				return &r, err
			}
			return nil, err
		}

		if err := json.Unmarshal(b, &r); err != nil {
			return nil, err
		}
	}

	return &r, nil
}
399702
func scaleCondition(r *JobPsuedoScaler, precondition *ScalePrecondition, namespace, name string, count uint, updatedResourceVersion *string) wait.ConditionFunc {
	return func() (bool, error) {
		rv, err := r.ScaleSimple(namespace, name, precondition, count)
		if updatedResourceVersion != nil {
			*updatedResourceVersion = rv
		}
		// Retry only on update conflicts.
		if errors.IsConflict(err) {
			return false, nil
		}
		if err != nil {
			return false, err
		}
		return true, nil
	}
}
610386
func (c *FakeReplicaSets) UpdateScale(replicaSetName string, scale *autoscalingv1.Scale) (result *autoscalingv1.Scale, err error) {
	obj, err := c.Fake.
		Invokes(testing.NewUpdateSubresourceAction(replicasetsResource, "scale", c.ns, scale), &autoscalingv1.Scale{})

	if obj == nil {
		return nil, err
	}
	return obj.(*autoscalingv1.Scale), err
}
729558
func Scale(a []float32, s float32) {
	for i, v := range a {
		a[i] = v * s
	}
}
33435
func (c *statefulSets) GetScale(statefulSetName string, options metav1.GetOptions) (result *autoscalingv1.Scale, err error) {
	result = &autoscalingv1.Scale{}
	err = c.client.Get().
		Namespace(c.ns).
		Resource("statefulsets").
		Name(statefulSetName).
		SubResource("scale").
		VersionedParams(&options, scheme.ParameterCodec).
		Do().
		Into(result)
	return
}
1054681
func (a int64Amount) AsScale(scale Scale) (int64Amount, bool) {
	if a.scale >= scale {
		return a, true
	}
	result, exact := negativeScaleInt64(a.value, scale-a.scale)
	return int64Amount{value: result, scale: scale}, exact
}
702674
func (c *FleetClient) Scale(
	component string, requested int, wg *sync.WaitGroup, out, ew io.Writer) {

	if requested < 0 {
		fmt.Fprintln(ew, "cannot scale below 0")
		return
	}
	// check how many currently exist
	components, err := c.Units(component)
	if err != nil {
		// skip checking the first time; we just want a tally
		if !strings.Contains(err.Error(), "could not find unit") {
			fmt.Fprintln(ew, err.Error())
			return
		}
	}

	timesToScale := int(math.Abs(float64(requested - len(components))))
	switch {
	case timesToScale == 0:
		return
	case requested-len(components) > 0:
		c.scaleUp(component, len(components), timesToScale, wg, out, ew)
	default:
		c.scaleDown(component, len(components), timesToScale, wg, out, ew)
	}
}
300897
func (m Matrix) Scaled(around Vec, scale float64) Matrix {
	return m.ScaledXY(around, V(scale, scale))
}
973624
func (a infDecAmount) AsScale(scale Scale) (infDecAmount, bool) {
	tmp := &inf.Dec{}
	tmp.Round(a.Dec, scale.infScale(), inf.RoundUp)
	return infDecAmount{tmp}, tmp.Cmp(a.Dec) == 0
}
1215901
func (m *Matrix) ScaleComponent() (x, y float32) {
	return m.Val[m00], m.Val[m11]
}
1038041
func (c RGBA) Scaled(scale float64) RGBA {
	return RGBA{
		R: c.R * scale,
		G: c.G * scale,
		B: c.B * scale,
		A: c.A * scale,
	}
}
44368
func (co *Context) ScaleTensor(yDesc *TensorDescriptor, y Memory, alpha float64) error {
	var alphaC unsafe.Pointer
	switch yDesc.dataType {
	case Float, Half:
		var alphaF C.float
		alphaF = C.float(float32(alpha))
		alphaC = unsafe.Pointer(&alphaF)
	case Double:
		var alphaF C.double
		alphaF = C.double(alpha)
		alphaC = unsafe.Pointer(&alphaF)
	default:
		return errors.Errorf("Unsupported data type: %v", yDesc.dataType)
	}
	// call cudnnScaleTensor
	return result(C.cudnnScaleTensor(co.internal, yDesc.internal, y.Pointer(), alphaC))
}