<commit_before>//
//  Arithmetic.swift
//
//  The MIT License
//  Copyright (c) 2015 - 2019 <NAME>. All rights reserved.
//
//  Permission is hereby granted, free of charge, to any person obtaining a copy
//  of this software and associated documentation files (the "Software"), to deal
//  in the Software without restriction, including without limitation the rights
//  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
//  copies of the Software, and to permit persons to whom the Software is
//  furnished to do so, subject to the following conditions:
//
//  The above copyright notice and this permission notice shall be included in
//  all copies or substantial portions of the Software.
//
//  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
//  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
//  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
//  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
//  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
//  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
//  THE SOFTWARE.
//

public protocol ScalarProtocol: ScalarMultiplicative, Multiplicative, SignedNumeric, Strideable, ExpressibleByFloatLiteral where Scalar == Self {
    
    static func * (lhs: Self, rhs: Self) -> Self
    
    static func *= (lhs: inout Self, rhs: Self)
}

public protocol ScalarMultiplicative : AdditiveArithmetic {
    
    associatedtype Scalar : ScalarMultiplicative where Scalar == Scalar.Scalar
    
    static prefix func - (x: Self) -> Self
    
    static func * (lhs: Scalar, rhs: Self) -> Self
    
    static func * (lhs: Self, rhs: Scalar) -> Self
    
    static func *= (lhs: inout Self, rhs: Scalar)
    
    static func / (lhs: Self, rhs: Scalar) -> Self
    
    static func /= (lhs: inout Self, rhs: Scalar)
}

public protocol Multiplicative : Equatable {
    
    static func * (lhs: Self, rhs: Self) -> Self
    
    static func *= (lhs: inout Self, rhs: Self)
}

public protocol MapReduceArithmetic : ScalarMultiplicative, Collection where Element : ScalarMultiplicative, Element.Scalar == Scalar {
    
    func map(_ transform: (Element) -> Element) -> Self
    
    func reduce(_ nextPartialResult: (Element, Element) -> Element) -> Element?
    
    func reduce<Result>(_ initialResult: Result, _ nextPartialResult: (Result, Element) -> Result) -> Result
    
    func reduce<Result>(into initialResult: Result, _ updateAccumulatingResult: (inout Result, Element) -> ()) -> Result
    
    func combined(_ other: Self, _ transform: (Element, Element) -> Element) -> Self
}

extension Collection where Self : MapReduceArithmetic {
    
    @inlinable
    @inline(__always)
    public func reduce(_ nextPartialResult: (Element, Element) -> Element) -> Element? {
        return self.reduce(nil) { partial, current in partial.map { nextPartialResult($0, current) } ?? current }
    }
    
    @inlinable
    @inline(__always)
    public func reduce<Result>(_ initialResult: Result, _ nextPartialResult: (Result, Element) -> Result) -> Result {
        return self.reduce(into: initialResult) { $0 = nextPartialResult($0, $1) }
    }
}

extension MapReduceArithmetic {
    
    @inlinable
    @inline(__always)
    public static prefix func + (val: Self) -> Self {
        return val
    }
    
    @inlinable
    @inline(__always)
    public static prefix func - (val: Self) -> Self {
        return val.map { -$0 }
    }
    
    @inlinable
    @inline(__always)
    public static func + (lhs: Self, rhs: Self) -> Self {
        return lhs.combined(rhs) { $0 + $1 }
    }
    @inlinable
    @inline(__always)
    public static func - (lhs: Self, rhs: Self) -> Self {
        return lhs.combined(rhs) { $0 - $1 }
    }
    
    @inlinable
    @inline(__always)
    public static func += (lhs: inout Self, rhs: Self) {
        lhs = lhs + rhs
    }
    
    @inlinable
    @inline(__always)
    public static func -= (lhs: inout Self, rhs: Self) {
        lhs = lhs - rhs
    }
    
    @inlinable
    @inline(__always)
    public static func * (lhs: Scalar, rhs: Self) -> Self {
        return rhs.map { lhs * $0 }
    }
    @inlinable
    @inline(__always)
    public static func * (lhs: Self, rhs: Scalar) -> Self {
        return lhs.map { $0 * rhs }
    }
    @inlinable
    @inline(__always)
    public static func / (lhs: Self, rhs: Scalar) -> Self {
        return lhs.map { $0 / rhs }
    }
    @inlinable
    @inline(__always)
    public static func *= (lhs: inout Self, rhs: Scalar) {
        lhs = lhs * rhs
    }
    @inlinable
    @inline(__always)
    public static func /= (lhs: inout Self, rhs: Scalar) {
        lhs = lhs / rhs
    }
}

extension MapReduceArithmetic where Element == Point {
    
    @inlinable
    @inline(__always)
    public static func * (lhs: Self, rhs: SDTransform) -> Self {
        return lhs.map { $0 * rhs }
    }
    
    @inlinable
    @inline(__always)
    public static func *= (lhs: inout Self, rhs: SDTransform) {
        lhs = lhs * rhs
    }
}

extension MapReduceArithmetic where Element == Vector {
    
    @inlinable
    @inline(__always)<commit_msg>clean<commit_after>//
//  Arithmetic.swift
//
//  The MIT License
//  Copyright (c) 2015 - 2019 <NAME>. All rights reserved.
//
//  Permission is hereby granted, free of charge, to any person obtaining a copy
//  of this software and associated documentation files (the "Software"), to deal
//  in the Software without restriction, including without limitation the rights
//  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
//  copies of the Software, and to permit persons to whom the Software is
//  furnished to do so, subject to the following conditions:
//
//  The above copyright notice and this permission notice shall be included in
//  all copies or substantial portions of the Software.
//
//  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
//  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
//  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
//  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
//  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
//  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
//  THE SOFTWARE.
//

public protocol ScalarProtocol: SignedNumeric, Strideable, ExpressibleByFloatLiteral, Multiplicative, ScalarMultiplicative where Self == Scalar {
    
    static func * (lhs: Self, rhs: Self) -> Self
    
    static func *= (lhs: inout Self, rhs: Self)
}

public protocol ScalarMultiplicative : AdditiveArithmetic {
    
    associatedtype Scalar : ScalarProtocol
    
    static prefix func - (x: Self) -> Self
    
    static func * (lhs: Scalar, rhs: Self) -> Self
    
    static func * (lhs: Self, rhs: Scalar) -> Self
    
    static func *= (lhs: inout Self, rhs: Scalar)
    
    static func / (lhs: Self, rhs: Scalar) -> Self
    
    static func /= (lhs: inout Self, rhs: Scalar)
}

public protocol Multiplicative : Equatable {
    
    static func * (lhs: Self, rhs: Self) -> Self
    
    static func *= (lhs: inout Self, rhs: Self)
}

public protocol MapReduceArithmetic : ScalarMultiplicative {
    
    associatedtype Element : ScalarMultiplicative
    
    func map(_ transform: (Element) -> Element) -> Self
    
    func reduce(_ nextPartialResult: (Element, Element) -> Element) -> Element?
    
    func reduce<Result>(_ initialResult: Result, _ nextPartialResult: (Result, Element) -> Result) -> Result
    
    func reduce<Result>(into initialResult: Result, _ updateAccumulatingResult: (inout Result, Element) -> ()) -> Result
    
    func combined(_ other: Self, _ transform: (Element, Element) -> Element) -> Self
}

extension Collection where Self : MapReduceArithmetic {
    
    @inlinable
    @inline(__always)
    public func reduce(_ nextPartialResult: (Element, Element) -> Element) -> Element? {
        return self.reduce(nil) { partial, current in partial.map { nextPartialResult($0, current) } ?? current }
    }
    
    @inlinable
    @inline(__always)
    public func reduce<Result>(_ initialResult: Result, _ nextPartialResult: (Result, Element) -> Result) -> Result {
        return self.reduce(into: initialResult) { $0 = nextPartialResult($0, $1) }
    }
}

extension MapReduceArithmetic {
    
    @inlinable
    @inline(__always)
    public static prefix func + (val: Self) -> Self {
        return val
    }
    
    @inlinable
    @inline(__always)
    public static prefix func - (val: Self) -> Self {
        return val.map { -$0 }
    }
    
    @inlinable
    @inline(__always)
    public static func + (lhs: Self, rhs: Self) -> Self {
        return lhs.combined(rhs) { $0 + $1 }
    }
    @inlinable
    @inline(__always)
    public static func - (lhs: Self, rhs: Self) -> Self {
        return lhs.combined(rhs) { $0 - $1 }
    }
    
    @inlinable
    @inline(__always)
    public static func += (lhs: inout Self, rhs: Self) {
        lhs = lhs + rhs
    }
    
    @inlinable
    @inline(__always)
    public static func -= (lhs: inout Self, rhs: Self) {
        lhs = lhs - rhs
    }
    
    @inlinable
    @inline(__always)
    public static func * (lhs: Element.Scalar, rhs: Self) -> Self {
        return rhs.map { lhs * $0 }
    }
    @inlinable
    @inline(__always)
    public static func * (lhs: Self, rhs: Element.Scalar) -> Self {
        return lhs.map { $0 * rhs }
    }
    @inlinable
    @inline(__always)
    public static func / (lhs: Self, rhs: Element.Scalar) -> Self {
        return lhs.map { $0 / rhs }
    }
    @inlinable
    @inline(__always)
    public static func *= (lhs: inout Self, rhs: Element.Scalar) {
        lhs = lhs * rhs
    }
    @inlinable
    @inline(__always)
    public static func /= (lhs: inout Self, rhs: Element.Scalar) {
        lhs = lhs / rhs
    }
}

extension MapReduceArithmetic where Element == Point {
    
    @inlinable
    @inline(__always)
    public static func * (lhs: Self, rhs: SDTransform) -> Self {
        return lhs.map { $0 * rhs }
    }
    
    @inlinable
    @inline(__always)
    public static func *= (lhs: inout Self, rhs: SDTransform) {
        lhs = lhs * rhs
    }
}

extension MapReduceArithmetic where Element == Vector {
    
    @inlinable
    @inline(__always)
{'fraction_non_alphanumeric': 0.10693807339449542, 'fraction_numerical': 0.0040137614678899085, 'mean_word_length': 2.6706418800420906, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 67, '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': '2632367', 'n_tokens_mistral': 3204, 'n_tokens_neox': 3156, 'n_words': 1087}