<commit_before>function Get-Gradient {
    <#
    .Synopsis
        Get a range of colors from one or more colors
    #>
    [CmdletBinding()]
    param(
        # One or more colors to generate a gradient from
        [Parameter(Mandatory)]
        [PoshCode.Pansies.RgbColor[]]$Color,

        [int]$Height = $Host.UI.RawUI.WindowSize.Height,

        [int]$Width = $Host.UI.RawUI.WindowSize.Width,

        [ValidateSet("CMY","CMYK","LAB","LCH","LUV","HunterLAB","HSL","HSV","HSB","RGB","XYZ","YXY")]
        $ColorSpace = "HunterLab",

        # For color spaces with Hue (HSL, HSV), setting this generates the gradient the long way
        [switch]$Reverse,

        [switch]$Flatten
    )
    $Height = [Math]::Max(1, $Height)
    $Width = [Math]::Max(1, $Width)
    $Colors = new-object Rgb[][] $Height, $Width
    $C = [PSCustomObject]@{R = 0; G = 0; B = 0}
    # If we're not doing a color scale, we can return immediately:
    if ($Color.Count -eq 1) {
        for ($r = 0; $r -lt $Height; $r++) {
            for ($c = 0; $c -lt $Width; $c++) {
                $Colors[$r][$c] = $Color[0]
            }
        }
    }
    else {
        # Simple pythagorean distance
        $Size = [Math]::Sqrt($Height * $Height + $Width * $Width)

        $Left = $Color[0]."To$ColorSpace"()
        $Right = $Color[-1]."To$ColorSpace"()
        $StepSize = New-Object "${ColorSpace}Color" -Property @{
            Ordinals = $(
                foreach ($i in 0..($Left.Ordinals.Count-1)) {
                    ($Left.Ordinals[$i] - $Right.Ordinals[$i]) / $Size
                }
            )
        }
        Write-Verbose "Size: $('{0:N2}' -f $Size)"
        Write-Verbose "Diff: {$StepSize}"
        Write-Verbose "From: {$Left}"
        Write-Verbose "To:   {$Right}"
        # For colors based on hue rotation, the math is slightly more complex:
        [bool]$RotatingColor = $StepSize | Get-Member H

        if($RotatingColor) {
            [Bool]$Change = [Math]::Abs($StepSize.H) -ge 180 / $Size
            if ($Reverse) { $Change = !$Change }
            if ($Change) {
                $StepSize.H = if ($StepSize.H -gt 0) {
                    $StepSize.H - 360 / $Size
                } else {
                    $StepSize.H + 360 / $Size
                }
            }
            $Ceiling = 360
        }

        for ($Line = 1; $Line -le $Height; $Line++) {
            for ($Column = 1; $Column -le $Width; $Column++) {
                $D = [Math]::Sqrt($Line * $Line + $Column * $Column)

                $StepColor = New-Object "${ColorSpace}Color" -Property @{
                    Ordinals = $(
                        foreach ($i in 0..$Left.Ordinals.Count) {
                            $Left.Ordinals[$i] - $StepSize.Ordinals[$i] * $D
                        }
                    )
                }

                # For colors based on hue rotation, the math is slightly more complex:
                if($RotatingColor) { $StepColor.H %= $Ceiling }
                Write-Debug "Step ${Line},${Column}: $StepColor"

                $Colors[$Line - 1][$Column - 1] = $StepColor.ToRgb()
                Write-Debug "Step: $($Colors[$Line - 1][$Column - 1])"
            }
        }
    }

    if ($Flatten) {
        $Colors.GetEnumerator().GetEnumerator()
    } else {
        ,$Colors
    }

}<commit_msg>Fix Get-Gradient<commit_after>function Get-Gradient {
    <#
    .Synopsis
        Get a range of colors from one or more colors
    #>
    [CmdletBinding()]
    param(
        # One or more colors to generate a gradient from
        [Parameter(Mandatory, Position=0)]
        [PoshCode.Pansies.RgbColor]$StartColor,

        [Parameter(Mandatory, Position=1)]
        [PoshCode.Pansies.RgbColor]$EndColor,

        [Parameter(Position=2)]
        [Alias("Length","Count","Steps")]
        [int]$Width = $Host.UI.RawUI.WindowSize.Width,
        
        [Parameter(Position=3)]
        [int]$Height = 1,
        [ValidateSet("CMY","CMYK","LAB","LCH","LUV","HunterLAB","HSL","HSV","HSB","RGB","XYZ","YXY")]
        $ColorSpace = "HunterLab",

        # For color spaces with Hue (HSL, HSV), setting this generates the gradient the long way
        [switch]$Reverse,

        [switch]$Flatten
    )

    $Height = [Math]::Max(1, $Height)
    $Width = [Math]::Max(1, $Width)
    $Colors = new-object Rgb[][] $Height, $Width
    $C = [PSCustomObject]@{R = 0; G = 0; B = 0}

    # Simple pythagorean distance
    $Size = [Math]::Sqrt(($Height - 1) * ($Height - 1) + ($Width - 1) * ($Width - 1))

    $Left = $StartColor."To$ColorSpace"()
    $Right = $EndColor."To$ColorSpace"()
    $StepSize = New-Object "${ColorSpace}Color" -Property @{
        Ordinals = $(
            foreach ($i in 0..($Left.Ordinals.Count-1)) {
                ($Right.Ordinals[$i] - $Left.Ordinals[$i]) / $Size
            }
        )
    }
    Write-Verbose "Size: $('{0:N2}' -f $Size) ($Width x $Height) ($($Colors.Length) x $($Colors[0].Length))"
    Write-Verbose "Diff: {$StepSize}"
    Write-Verbose "From: {$Left} $($StartColor.Ordinals)"
    Write-Verbose "To:   {$Right} $($EndColor.Ordinals)"
    # For colors based on hue rotation, the math is slightly more complex:
    [bool]$RotatingColor = $StepSize | Get-Member H

    if($RotatingColor) {
        [Bool]$Change = [Math]::Abs($StepSize.H) -ge 180 / $Size
        if ($Reverse) { $Change = !$Change }
        if ($Change) {
            $StepSize.H = if ($StepSize.H -gt 0) {
                $StepSize.H - 360 / $Size
            } else {
                $StepSize.H + 360 / $Size
            }
        }
        $Ceiling = 360
    }

    for ($Line = 1; $Line -le $Height; $Line++) {
        for ($Column = 1; $Column -le $Width; $Column++) {
            $D = [Math]::Sqrt(($Line - 1) * ($Line - 1) + ($Column - 1) * ($Column - 1))

            $StepColor = New-Object "${ColorSpace}Color" -Property @{
                Ordinals = $(
                    foreach ($i in 0..$Left.Ordinals.Count) {
                        $Left.Ordinals[$i] + $StepSize.Ordinals[$i] * $D
                    }
                )
            }

            # For colors based on hue rotation, the math is slightly more complex:
            if($RotatingColor) {
                if($StepColor.H -lt 0) {
                    $StepColor.H += 360
                }
                $StepColor.H %= $Ceiling
            }
            $Ordinals1 = $StepColor.Ordinals

            $Colors[$Line - 1][$Column - 1] = $StepColor.ToRgb()
            $Ordinals2 = $Colors[$Line - 1][$Column - 1].Ordinals
            Write-Debug ("Step ${Line},${Column}: {0:N2}, {1:N2}, {2:N2}  =>  {3:N2}, {4:N2}, {5:N2}" -f $Ordinals1[0], $Ordinals1[1], $Ordinals1[2], $Ordinals2[0], $Ordinals2[1], $Ordinals2[2] )
        }
    }
    
    if ($Flatten) {
        $Colors.GetEnumerator().GetEnumerator()
    } else {
        ,$Colors
    }

}
{'fraction_non_alphanumeric': 0.16943473193473194, 'fraction_numerical': 0.015734265734265736, 'mean_word_length': 1.7771035598705502, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 6, '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': '6486585', 'n_tokens_mistral': 2350, 'n_tokens_neox': 2212, 'n_words': 498}