<commit_before>//
//  VectorArithmetic.swift
//  Surge
//
//  Created by <NAME> on 9/6/15.
//  Copyright © 2015 <NAME>. All rights reserved.
//

import Foundation

public protocol VectorArithmetic {
    
    // MARK: To Overload
    static func zero() -> Self
    static func one() -> Self
    static func negativeOne() -> Self
    static func add(x: [Self], _ y: [Self]) -> [Self]
    static func multiply(x: [Self], _ y: [Self]) -> [Self]
    
    //MARK: Optional Overload
    static func zeros(count: Int) -> [Self]
    static func ones(count: Int) -> [Self]
    static func negativeOnes(count: Int) -> [Self]
    static func subtract(x: [Self], _ y: [Self]) -> [Self]
    static func divide(x: [Self], _ y: [Self]) -> [Self]
    
}

public extension VectorArithmetic {
    
    static func zeros(count: Int) -> [Self] {
        return [Self](count: count, repeatedValue: Self.zero())
    }
    
    static func ones(count: Int) -> [Self] {
        return [Self](count: count, repeatedValue: Self.one())
    }
    
    static func negativeOnes(count: Int) -> [Self] {
        return [Self](count: count, repeatedValue: Self.negativeOne())
    }
    
    public static func subtract(x: [Self], _ y: [Self]) -> [Self] {
        return x + (y * self.negativeOne())
    }
    
    public static func divide(x: [Self], _ y: [Self]) -> [Self] {
        return x * (Self.one() / y)
    }
    
}

func +<T: VectorArithmetic>(lhs: [T], rhs: [T]) -> [T] {
    return T.add(lhs, rhs)
}

func +<T: VectorArithmetic>(lhs: [T], rhs: T) -> [T] {
    let rhsVect = Array<T>(count: lhs.count, repeatedValue: rhs)
    return T.add(lhs, rhsVect)
}

func +<T: VectorArithmetic>(lhs: T, rhs: [T]) -> [T] {
    let lhsVect = Array<T>(count: rhs.count, repeatedValue: lhs)
    return T.add(lhsVect, rhs)
}

func -<T: VectorArithmetic>(lhs: [T], rhs: [T]) -> [T] {
    return T.subtract(lhs, rhs)
}

func -<T: VectorArithmetic>(lhs: [T], rhs: T) -> [T] {
    let rhsVect = Array<T>(count: lhs.count, repeatedValue: rhs)
    return T.subtract(lhs, rhsVect)
}

func -<T: VectorArithmetic>(lhs: T, rhs: [T]) -> [T] {
    let lhsVect = Array<T>(count: rhs.count, repeatedValue: lhs)<commit_msg>Used new convenience methods for clarity.<commit_after>//
//  VectorArithmetic.swift
//  Surge
//
//  Created by <NAME> on 9/6/15.
//  Copyright © 2015 <NAME>. All rights reserved.
//

import Foundation

public protocol VectorArithmetic {
    
    // MARK: To Overload
    static func zero() -> Self
    static func one() -> Self
    static func negativeOne() -> Self
    static func add(x: [Self], _ y: [Self]) -> [Self]
    static func multiply(x: [Self], _ y: [Self]) -> [Self]
    
    //MARK: Optional Overload
    static func zeros(count: Int) -> [Self]
    static func ones(count: Int) -> [Self]
    static func negativeOnes(count: Int) -> [Self]
    static func subtract(x: [Self], _ y: [Self]) -> [Self]
    static func divide(x: [Self], _ y: [Self]) -> [Self]
    
}

public extension VectorArithmetic {
    
    static func zeros(count: Int) -> [Self] {
        return [Self](count: count, repeatedValue: Self.zero())
    }
    
    static func ones(count: Int) -> [Self] {
        return [Self](count: count, repeatedValue: Self.one())
    }
    
    static func negativeOnes(count: Int) -> [Self] {
        return [Self](count: count, repeatedValue: Self.negativeOne())
    }
    
    public static func subtract(x: [Self], _ y: [Self]) -> [Self] {
        return x + (y * Self.negativeOnes(y.count))
    }
    
    public static func divide(x: [Self], _ y: [Self]) -> [Self] {
        return x * (Self.ones(y.count) / y)
    }
    
}

func +<T: VectorArithmetic>(lhs: [T], rhs: [T]) -> [T] {
    return T.add(lhs, rhs)
}

func +<T: VectorArithmetic>(lhs: [T], rhs: T) -> [T] {
    let rhsVect = Array<T>(count: lhs.count, repeatedValue: rhs)
    return T.add(lhs, rhsVect)
}

func +<T: VectorArithmetic>(lhs: T, rhs: [T]) -> [T] {
    let lhsVect = Array<T>(count: rhs.count, repeatedValue: lhs)
    return T.add(lhsVect, rhs)
}

func -<T: VectorArithmetic>(lhs: [T], rhs: [T]) -> [T] {
    return T.subtract(lhs, rhs)
}

func -<T: VectorArithmetic>(lhs: [T], rhs: T) -> [T] {
    let rhsVect = Array<T>(count: lhs.count, repeatedValue: rhs)
    return T.subtract(lhs, rhsVect)
}

func -<T: VectorArithmetic>(lhs: T, rhs: [T]) -> [T] {
    let lhsVect = Array<T>(count: rhs.count, repeatedValue: lhs)
{'fraction_non_alphanumeric': 0.17632299270072993, 'fraction_numerical': 0.0036496350364963502, 'mean_word_length': 2.816362053959965, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 69, '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': '2462534', 'n_tokens_mistral': 1621, 'n_tokens_neox': 1575, 'n_words': 442}