// Normalize returns an error iff the request is invalid.
430644
func (r *EnsureGraphDataReq) Normalize() error {
	if r.ForExecution != nil {
		if err := r.ForExecution.Normalize(); err != nil {
			return err
		}
	}

	if err := r.RawAttempts.Normalize(); err != nil {
		return err
	}

	hasAttempts := false
	if r.RawAttempts != nil {
		for _, nums := range r.RawAttempts.To {
			if len(nums.Nums) == 0 {
				return errors.New("EnsureGraphDataReq.attempts must only include valid (non-0, non-empty) attempt numbers")
			}
			hasAttempts = true
		}
	}

	if len(r.Quest) != len(r.QuestAttempt) {
		return errors.New("mismatched quest_attempt v. quest lengths")
	}

	if len(r.TemplateQuest) != len(r.TemplateAttempt) {
		return errors.New("mismatched template_attempt v. template_quest lengths")
	}

	if err := checkAttemptNums("template_attempts", r.TemplateAttempt); err != nil {
		return err
	}

	for i, q := range r.TemplateQuest {
		if err := q.Normalize(); err != nil {
			return fmt.Errorf("template_quests[%d]: %s", i, err)
		}
	}

	if err := checkAttemptNums("quest_attempt", r.QuestAttempt); err != nil {
		return err
	}

	for i, desc := range r.Quest {
		if err := desc.Normalize(); err != nil {
			return fmt.Errorf("quest[%d]: %s", i, err)
		}
	}

	if len(r.Quest) == 0 && len(r.TemplateQuest) == 0 && !hasAttempts {
		return errors.New("EnsureGraphDataReq must have at least one of quests, template_quests and raw_attempts")
	}

	if r.Limit == nil {
		r.Limit = &EnsureGraphDataReq_Limit{}
	}
	if r.Limit.MaxDataSize == 0 {
		r.Limit.MaxDataSize = DefaultLimitMaxDataSize
	}
	if r.Limit.MaxDataSize > MaxLimitMaxDataSize {
		r.Limit.MaxDataSize = MaxLimitMaxDataSize
	}

	if r.Include == nil {
		r.Include = &EnsureGraphDataReq_Include{Attempt: &EnsureGraphDataReq_Include_Options{}}
	} else if r.Include.Attempt == nil {
		r.Include.Attempt = &EnsureGraphDataReq_Include_Options{}
	}
	return nil
}
1225876
func (env *EnvironmentItemModel) Normalize() error {
	opts, err := env.GetOptions()
	if err != nil {
		return err
	}
	(*env)[OptionsKey] = opts
	return nil
}
773846
func (m mathUtil) Normalize(values ...float64) []float64 {
	var total float64
	for _, v := range values {
		total += v
	}
	output := make([]float64, len(values))
	for x, v := range values {
		output[x] = m.RoundDown(v/total, 0.0001)
	}
	return output
}
834500
func (s *Etcd) normalize(key string) string {
	key = store.Normalize(key)
	return strings.TrimPrefix(key, "/")
}
81335
func (q1 Quat) Normalize() Quat {
	length := q1.Len()

	if FloatEqual(1, length) {
		return q1
	}
	if length == 0 {
		return QuatIdent()
	}
	if length == InfPos {
		length = MaxValue
	}

	return Quat{q1.W * 1 / length, q1.V.Mul(1 / length)}
}
288377
func Normalize(name string) string {
	fargs := func(c rune) bool {
		return !unicode.IsLetter(c) && !unicode.IsNumber(c)
	}
	// get function
	return strings.Join(strings.FieldsFunc(name, fargs), "-")
}
225615
func Normalize(version string) string {

	// ignore aliases and just assume the alias is required instead of the source
	result := RegFind(`^([^,\s]+) +as +([^,\s]+)$`, version)
	if result != nil {
		version = result[1]
	}

	// match master-like branches
	if regexpMasterLikeBranches.MatchString(strings.ToLower(version)) {
		return "9999999-dev"
	}

	if strings.HasPrefix(strings.ToLower(version), "dev-") {
		return "dev-" + version[4:len(version)]
	}

	index := 0

	// match classical versioning
	result = RegFind(`(?i)^v?(\d{1,3})(\.\d+)?(\.\d+)?(\.\d+)?`+modifierRegex+`$`, version)
	if result != nil {
		version = ""
		for _, val := range result[1:5] {
			if val != "" {
				version = version + val
			} else {
				version = version + ".0"
			}
		}

		index = 5
	} else {
		// match date-based versioning
		result = RegFind(`(?i)^v?(\d{4}(?:[.:-]?\d{2}){1,6}(?:[.:-]?\d{1,3})?)`+modifierRegex+`$`, version)
		if result != nil {
			version = regexp.MustCompile(`\D`).ReplaceAllString(result[1], "-")
			index = 2
		}
	}

	if index != 0 {
		if result[index] != "" {
			if result[index] == "stable" {
				return version
			}

			version = version + "-" + expandStability(result[index])
			if result[index+1] != "" {
				version = version + result[index+1]
			}
		}

		if result[index+2] != "" {
			version = version + "-dev"
		}

		return version
	}

	result = RegFind(`(?i)(.*?)[.-]?dev$`, version)
	if result != nil {
		return normalizeBranch(result[1])
	}

	return version
}
870658
func (s Seq) Normalize() Seq {
	min, max := s.MinMax()

	delta := max - min
	output := make([]float64, s.Len())
	for i := 0; i < s.Len(); i++ {
		output[i] = (s.GetValue(i) - min) / delta
	}

	return Seq{Provider: Array(output)}
}
927225
func (lrs *LinearRegressionSeries) normalize(xvalue float64) float64 {
	return (xvalue - lrs.avgx) / lrs.stddevx
}
1255817
func (c *CipdSpec) Normalize() error {
	if err := schemaHostURLValidate(c.Server); err != nil {
		return fmt.Errorf("job.inputs.cipd.server: %s", err)
	}
	if c.Client != nil {
		if err := c.Client.Normalize(); err != nil {
			return fmt.Errorf("job.inputs.cipd.client: %s", err)
		}
	}
	for path, pkgs := range c.ByPath {
		for i, p := range pkgs.Pkg {
			if err := p.Normalize(); err != nil {
				return fmt.Errorf("job.inputs.cipd.by_path[%s].pkg[%d]: %s", path, i, err)
			}
		}
	}
	return nil
}
1108432
func (quat *T) Normalized() T {
	norm := quat.Norm()
	if norm != 1 && norm != 0 {
		ool := 1 / math.Sqrt(norm)
		return T{
			quat[0] * ool,
			quat[1] * ool,
			quat[2] * ool,
			quat[3] * ool,
		}
	} else {
		return *quat
	}
}
798591
func (n *normalizedEndpoints) normalize(name string) string {
	n.mux.RLock()
	norm, ok := n.names[name]
	l := len(n.names)
	n.mux.RUnlock()
	if ok {
		return norm
	}
	if l >= n.maxSize {
		return ""
	}
	return n.normalizeWithLock(name)
}
36343
func Normalize(cmd *cobra.Command) *cobra.Command {
	if len(cmd.Long) > 0 {
		cmd.Long = LongDesc(cmd.Long)
	}
	if len(cmd.Example) > 0 {
		cmd.Example = Examples(cmd.Example)
	}
	return cmd
}
1333938
func normalize(i interface{}) (int, error) {
	switch v := i.(type) {
	case int:
		return v, nil
	case int32:
		return int(v), nil
	case int64:
		return int(v), nil
	case float32:
		return int(v + 0.5), nil
	case float64:
		// We need this check here because NaN can be a float. Casting NaN to
		// int results in a large negative number. Even after you add 0.5.
		if math.IsNaN(v) {
			return -1, fmt.Errorf("Could not normalize NaN %v", v)
		}
		return int(v + 0.5), nil
	case string:
		f, err := strconv.ParseFloat(v, 64)
		if err != nil {
			return -1, err
		}
		return normalize(f)
	default:
		return -1, fmt.Errorf("Could not normalize %q", v)
	}
}
544543
func (e *WalkGraphReq_Exclude) Normalize() error {
	if len(e.Quests) > 0 {
		e.Quests = e.Quests[:set.Uniq(sort.StringSlice(e.Quests))]
	}
	return e.Attempts.Normalize()
}
344616
func (f *FailureStage) Normalize() error {
	if f.Chance < 0 {
		return fmt.Errorf("too small FailureStage chance")
	}
	if f.Chance > 1 {
		return fmt.Errorf("too large FailureStage chance")
	}
	return nil
}
740296
func (s *SparseRange) Normalize() error {
	if len(s.Items) == 0 {
		s.Items = []*RangeItem{{RangeItem: &RangeItem_Single{1}}}
		return nil
	}
	current := uint32(0)
	for _, itm := range s.Items {
		switch i := itm.RangeItem.(type) {
		case *RangeItem_Single:
			if i.Single <= current {
				return fmt.Errorf("malformed SparseRange")
			}
			current = i.Single
		case *RangeItem_Range:
			if err := i.Range.Normalize(); err != nil {
				return err
			}
			if i.Range.Low <= current {
				return fmt.Errorf("malformed SparseRange")
			}
			current = i.Range.High
		default:
			return fmt.Errorf("unknown SparseRange entry")
		}
	}
	return nil
}