<commit_before>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Signum.Utilities
{
    public static class ArrayExtensions
    {
        public static T[,] Initialize<T>(this T[,] array, Func<int, int, T> valueXY)
        {
            for (int j = 0; j < array.GetLength(1); j++)
                for (int i = 0; i < array.GetLength(0); i++)
                    array[i, j] = valueXY(i, j);

            return array;
        }

        public static T[, ,] Initialize<T>(this T[, ,] array, Func<int, int, int, T> valueXYZ)
        {
            for (int k = 0; k < array.GetLength(2); k++)
                for (int j = 0; j < array.GetLength(1); j++)
                    for (int i = 0; i < array.GetLength(0); i++)
                        array[i, j, k] = valueXYZ(i, j, k);

            return array;
        }

        public static S[] ToArray<T, S>(this IEnumerable<T> collection, Func<T, S> value, Func<T, int> xPos)
        {
            if (collection.IsEmpty())
                return new S[0];

            return ToArray(collection, value, xPos, collection.Max(xPos) + 1);
        }

        public static S[] ToArray<T, S>(this IEnumerable<T> collection, Func<T, S> value, Func<T, int> xPos, int xLength)
        {
            S[] result = new S[xLength];
            foreach (var item in collection)
                result[xPos(item)] = value(item);
            return result;
        }

        public static S[,] ToArray<T, S>(this IEnumerable<T> collection, Func<T, S> value, Func<T, int> xPos, Func<T, int> yPos)
        {
            if (collection.IsEmpty())
                return new S[0, 0];

            return ToArray(collection, value, xPos, yPos, collection.Max(xPos) + 1, collection.Max(yPos) + 1);
        }

        public static S[,] ToArray<T, S>(this IEnumerable<T> collection, Func<T, S> value, Func<T, int> xPos, Func<T, int> yPos, int xLength, int yLength)
        {
            S[,] result = new S[xLength, yLength];
            foreach (var item in collection)
                result[xPos(item), yPos(item)] = value(item);
            return result;
        }

        public static S[, ,] ToArray<T, S>(this IEnumerable<T> collection, Func<T, S> value, Func<T, int> xPos, Func<T, int> yPos, Func<T, int> zPos)
        {
            if (collection.IsEmpty())
                return new S[0, 0, 0];

            return ToArray(collection, value, xPos, yPos, zPos, collection.Max(xPos) + 1, collection.Max(yPos) + 1, collection.Max(zPos) + 1);
        }

        public static S[, ,] ToArray<T, S>(this IEnumerable<T> collection, Func<T, S> value, Func<T, int> xPos, Func<T, int> yPos, Func<T, int> zPos, int xLength, int yLength, int zLength)
        {
            S[, ,] result = new S[xLength, yLength, zLength];
            foreach (var item in collection)
                result[xPos(item), yPos(item), zPos(item)] = value(item);
            return result;
        }

        public static IEnumerable<T> Row<T>(this T[,] data, int row)
        {
            for (int i = 0; i < data.GetLength(0); i++)
                yield return data[i, row];
        }

        public static IEnumerable<T> Column<T>(this T[,] data, int column)
        {
            for (int j = 0; j < data.GetLength(1); j++)
                yield return data[column, j];
        }

        public static T[,] AddRow<T>(this T[,] values, int pos, T[] newValues)
        {
            return AddRow(values, pos, i => newValues[i]);
        }

        public static T[,] AddRow<T>(this T[,] values, int pos, Func<int, T> newValue)
        {
            int width = values.GetLength(0);
            int height = values.GetLength(1);
            T[,] result = new T[width, height + 1];
            for (int j = 0; j < pos; j++)
                for (int i = 0; i < width; i++)
                    result[i, j] = values[i, j];
<commit_msg>remove ToArray<commit_after>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Signum.Utilities
{
    public static class ArrayExtensions
    {
        public static T[,] Initialize<T>(this T[,] array, Func<int, int, T> valueXY)
        {
            for (int j = 0; j < array.GetLength(1); j++)
                for (int i = 0; i < array.GetLength(0); i++)
                    array[i, j] = valueXY(i, j);

            return array;
        }

        public static T[, ,] Initialize<T>(this T[, ,] array, Func<int, int, int, T> valueXYZ)
        {
            for (int k = 0; k < array.GetLength(2); k++)
                for (int j = 0; j < array.GetLength(1); j++)
                    for (int i = 0; i < array.GetLength(0); i++)
                        array[i, j, k] = valueXYZ(i, j, k);

            return array;
        }
        public static IEnumerable<T> Row<T>(this T[,] data, int row)
        {
            for (int i = 0; i < data.GetLength(0); i++)
                yield return data[i, row];
        }

        public static IEnumerable<T> Column<T>(this T[,] data, int column)
        {
            for (int j = 0; j < data.GetLength(1); j++)
                yield return data[column, j];
        }

        public static T[,] AddRow<T>(this T[,] values, int pos, T[] newValues)
        {
            return AddRow(values, pos, i => newValues[i]);
        }

        public static T[,] AddRow<T>(this T[,] values, int pos, Func<int, T> newValue)
        {
            int width = values.GetLength(0);
            int height = values.GetLength(1);
            T[,] result = new T[width, height + 1];
            for (int j = 0; j < pos; j++)
                for (int i = 0; i < width; i++)
                    result[i, j] = values[i, j];

{'fraction_non_alphanumeric': 0.14413623595505617, 'fraction_numerical': 0.00877808988764045, 'mean_word_length': 1.811944718657453, 'pattern_counts': {'":': 0, '<': 73, '<?xml version=': 0, '>': 57, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '244839', 'n_tokens_mistral': 1900, 'n_tokens_neox': 1800, 'n_words': 555}