// generate fixed size array
766815
func ArrayOfFunction(env *Zlisp, name string,
	args []Sexp) (Sexp, error) {

	if len(args) != 2 {
		return SexpNull, fmt.Errorf("insufficient arguments to ([size] regtype) array constructor. use: " +
			"([size...] a-regtype)\n")
	}
	sz := 0
	Q("args = %#v in ArrayOfFunction", args)
	switch ar := args[1].(type) {
	case *SexpArray:
		if len(ar.Val) == 0 {
			return SexpNull, fmt.Errorf("at least one size must be specified in array constructor; e.g. ([size ...] regtype)")
		}
		asInt, isInt := ar.Val[0].(*SexpInt)
		if !isInt {
			return SexpNull, fmt.Errorf("size must be an int (not %T) in array constructor; e.g. ([size ...] regtype)", ar.Val[0])
		}
		sz = int(asInt.Val)
		// TODO: implement multiple dimensional arrays (matrixes etc).
	default:
		return SexpNull, fmt.Errorf("at least one size must be specified in array constructor; e.g. ([size ...] regtype)")
	}

	var rt *RegisteredType
	switch arg := args[0].(type) {
	case *RegisteredType:
		rt = arg
	case *SexpHash:
		rt = arg.GoStructFactory
	default:
		return SexpNull, fmt.Errorf("argument tx in (%s x) was not regtype, "+
			"instead type %T displaying as '%v' ",
			name, arg, arg.SexpString(nil))
	}

	//Q("arrayOf arg = '%s' with type %T", args[0].SexpString(nil), args[0])

	derivedType := reflect.ArrayOf(sz, rt.TypeCache)
	arrayRt := NewRegisteredType(func(env *Zlisp, h *SexpHash) (interface{}, error) {
		return reflect.New(derivedType), nil
	})
	arrayRt.DisplayAs = fmt.Sprintf("(%s %s)", name, rt.DisplayAs)
	arrayName := "arrayOf" + rt.RegisteredName
	GoStructRegistry.RegisterUserdef(arrayRt, false, arrayName)
	return arrayRt, nil
}
993638
func generateSalt() ([keySize]byte, error) {
	var data32 [keySize]byte
	data := make([]byte, keySize)
	_, err := rand.Read(data)
	if err != nil {
		return data32, err
	}
	total := copy(data32[:], data)
	if total != keySize {
		return data32, SaltGenerationError
	}
	return data32, nil
}
993393
func GenerateFileDeps(target, filesGenerator string, files []string) string {
	return replacePlaceholders(fileDepMkTemplate,
		"DEPS_GEN_APP_NAME", appName(),
		"DEPS_GEN_FILES_GENERATOR", filesGenerator,
		"DEPS_GEN_ALL_FILES_STORED", strings.Join(files, " "),
		"DEPS_GEN_TARGET", target,
	)
}
687305
func Generate(width, height int, o *Options) *image.RGBA {
	dst := image.NewRGBA(image.Rect(0, 0, width, height))

	// Get options or defaults
	noiseFn := Uniform
	monochrome := false
	if o != nil {
		if o.NoiseFn != nil {
			noiseFn = o.NoiseFn
		}
		monochrome = o.Monochrome
	}

	rand.Seed(time.Now().UTC().UnixNano())

	if monochrome {
		fillMonochrome(dst, noiseFn)
	} else {
		fillColored(dst, noiseFn)
	}

	return dst
}
1033661
func ToHexArray(b [][]byte) []string {
	r := make([]string, len(b))
	for i := range b {
		r[i] = ToHex(b[i])
	}
	return r
}
27391
func generatePatterns(url string) ([]string, error) {
	hosts, err := generateLookupHosts(url)
	if err != nil {
		return nil, err
	}
	paths, err := generateLookupPaths(url)
	if err != nil {
		return nil, err
	}
	var patterns []string
	for _, h := range hosts {
		for _, p := range paths {
			patterns = append(patterns, h+p)
		}
	}
	return patterns, nil
}
638990
func calculateEvenSplits(size int64, src SourceInfo) (startIndex, endIndex []int64) {
	if size == 0 {
		return
	}

	reqParts := partsRequired(size)
	startIndex = make([]int64, reqParts)
	endIndex = make([]int64, reqParts)
	// Compute number of required parts `k`, as:
	//
	// k = ceiling(size / copyPartSize)
	//
	// Now, distribute the `size` bytes in the source into
	// k parts as evenly as possible:
	//
	// r parts sized (q+1) bytes, and
	// (k - r) parts sized q bytes, where
	//
	// size = q * k + r (by simple division of size by k,
	// so that 0 <= r < k)
	//
	start := src.start
	if start == -1 {
		start = 0
	}
	quot, rem := size/reqParts, size%reqParts
	nextStart := start
	for j := int64(0); j < reqParts; j++ {
		curPartSize := quot
		if j < rem {
			curPartSize++
		}

		cStart := nextStart
		cEnd := cStart + curPartSize - 1
		nextStart = cEnd + 1

		startIndex[j], endIndex[j] = cStart, cEnd
	}
	return
}
50571
func arrayBindingJava(inner string, arraySizes []string) string {
	// Java array type declarations do not include the length.
	return inner + strings.Repeat("[]", len(arraySizes))
}
624033
func (s Seq) Array() (output []float64) {
	if s.Len() == 0 {
		return
	}

	output = make([]float64, s.Len())
	for i := 0; i < s.Len(); i++ {
		output[i] = s.GetValue(i)
	}
	return
}
1109438
func (b *BaggedModel) generateTrainingAttrs(model int, from base.FixedDataGrid) []base.Attribute {
	ret := make([]base.Attribute, 0)
	attrs := base.NonClassAttributes(from)
	if b.RandomFeatures == 0 {
		ret = attrs
	} else {
		for {
			if len(ret) >= b.RandomFeatures {
				break
			}
			attrIndex := rand.Intn(len(attrs))
			attr := attrs[attrIndex]
			matched := false
			for _, a := range ret {
				if a.Equals(attr) {
					matched = true
					break
				}
			}
			if !matched {
				ret = append(ret, attr)
			}
		}
	}
	for _, a := range from.AllClassAttributes() {
		ret = append(ret, a)
	}
	b.lock.Lock()
	b.selectedAttributes[model] = ret
	b.lock.Unlock()
	return ret
}
517505
func AppendArray(b []byte, n int) []byte {
	return appendPrefix(b, '*', int64(n))
}
673297
func GenerateDocs(apiDef *raml.APIDefinition, format, output string) error {
	switch format {
	case formatMarkdown:
		md := &markdownDocs{
			api:    apiDef,
			output: output,
		}
		return md.generate()
	default:
		return fmt.Errorf("unknown format '%s'", format)
	}
}
139274
func (r *randomGraph) Generate(n int) ([]*triple.Triple, error) {
	maxEdges := r.nodes * r.nodes
	if n > maxEdges {
		return nil, fmt.Errorf("current configuration only allow a max of %d triples (%d requested)", maxEdges, n)
	}
	var trpls []*triple.Triple
	for _, idx := range rand.Perm(maxEdges)[:n] {
		i, j := idx/r.nodes, idx%r.nodes
		t, err := r.newTriple(i, j)
		if err != nil {
			return nil, err
		}
		trpls = append(trpls, t)
	}
	return trpls, nil
}
490568
func generateLookupPaths(urlStr string) ([]string, error) {
	const maxPathComponents = 4

	parsedURL, err := parseURL(urlStr)
	if err != nil {
		return nil, err
	}
	path := parsedURL.Path

	paths := []string{"/"}
	var pathComponents []string
	for _, p := range strings.Split(path, "/") {
		if p != "" {
			pathComponents = append(pathComponents, p)
		}
	}

	numComponents := len(pathComponents)
	if numComponents > maxPathComponents {
		numComponents = maxPathComponents
	}

	for i := 1; i < numComponents; i++ {
		paths = append(paths, "/"+strings.Join(pathComponents[:i], "/")+"/")
	}
	if path != "/" {
		paths = append(paths, path)
	}
	if len(parsedURL.RawQuery) > 0 {
		paths = append(paths, path+"?"+parsedURL.RawQuery)
	}
	return paths, nil
}
43664
func (m *MT19937) SeedArray(initKey [NN]uint64) {
	var i, j uint64

	m.Seed(19650218)
	i = 1
	j = 0

	k := NN
	if NN <= len(initKey) {
		k = len(initKey)
	}

	for ; k != 0; k-- {
		m.mt[i] = (m.mt[i] ^ ((m.mt[i-1] ^ (m.mt[i-1] >> 62)) * 3935559000370003845)) + initKey[j] + j /* non linear */

		i++
		j++
		if i >= NN {
			m.mt[0] = m.mt[NN-1]
			i = 1
		}
		if j >= uint64(len(initKey)) {
			j = 0
		}
	}

	for k = NN - 1; k != 0; k-- {
		m.mt[i] = (m.mt[i] ^ ((m.mt[i-1] ^ (m.mt[i-1] >> 62)) * 2862933555777941757)) - i /* non linear */
		i++
		if i >= NN {
			m.mt[0] = m.mt[NN-1]
			i = 1
		}
	}

	m.mt[0] = 1 << 63 /* MSB is 1; assuring non-zero initial array */
}
1126284
func padStringArray(arr []string, l int) []string {
	if l <= len(arr) {
		return arr
	}
	return append(arr, make([]string, l-len(arr))...)
}
135288
func generateScripts(d *schema.ResourceData) ([]string, error) {
	var lines []string
	for _, l := range d.Get("inline").([]interface{}) {
		line, ok := l.(string)
		if !ok {
			return nil, fmt.Errorf("Error parsing %v as a string", l)
		}
		lines = append(lines, line)
	}
	lines = append(lines, "")

	return []string{strings.Join(lines, "\n")}, nil
}