<commit_before>//
//  SimplicialMap.swift
//  SwiftyAlgebra
//
//  Created by <NAME> on 2017/11/05.
//  Copyright © 2017年 <NAME>. All rights reserved.
//

import Foundation

public struct SimplicialMap: GeometricComplexMap {
    public typealias ComplexType = SimplicialComplex
    public typealias Domain      = Simplex
    public typealias Codomain    = Simplex
    
    public var domain:   SimplicialComplex
    public var codomain: SimplicialComplex?
    private let map: (Vertex) -> Vertex
    
    public init(from: SimplicialComplex, to: SimplicialComplex? = nil, _ map: @escaping (Vertex) -> Vertex) {
        self.domain = from
        self.codomain = to
        self.map = map
    }
    
    public init(from: SimplicialComplex, to: SimplicialComplex? = nil, _ map: [Vertex: Vertex]) {
        self.init(from: from, to: to, { v in map[v]! })
    }
    
    public var image: SimplicialComplex {
        let cells = domain.cellTable.map{ cells in
            cells.flatMap{ s -> Simplex? in
                let t = self.appliedTo(s)
                return (s.dim == t.dim) ? t : nil
            }
        }
        return SimplicialComplex(cells)
    }
    
    public func appliedTo(_ x: Vertex) -> Vertex {
        return map(x)
    }
    
    public func appliedTo(_ s: Simplex) -> Simplex {
        return Simplex(s.vertices.map{ self.appliedTo($0) }.unique())
    }
    
    public static func identity(from: SimplicialComplex) -> SimplicialMap {
        return SimplicialMap(from: from) { v in v }
    }
    
    public static func diagonal(from: SimplicialComplex) -> SimplicialMap {
        return SimplicialMap(from: from) { v in v × v }
    }
    
    public static func projection(from: SimplicialComplex, _ i: Int) -> SimplicialMap {
        return SimplicialMap(from: from) { v in v.components[i] }
    }
}<commit_msg>SimplicialMap bug fix.<commit_after>//
//  SimplicialMap.swift
//  SwiftyAlgebra
//
//  Created by <NAME> on 2017/11/05.
//  Copyright © 2017年 <NAME>. All rights reserved.
//

import Foundation

public struct SimplicialMap: GeometricComplexMap {
    public typealias ComplexType = SimplicialComplex
    public typealias Domain      = Simplex
    public typealias Codomain    = Simplex
    
    public var domain:   SimplicialComplex
    public var codomain: SimplicialComplex?
    private let map: (Vertex) -> Vertex
    
    public init(from: SimplicialComplex, to: SimplicialComplex? = nil, _ map: @escaping (Vertex) -> Vertex) {
        self.domain = from
        self.codomain = to
        self.map = map
    }
    
    public init(from: SimplicialComplex, to: SimplicialComplex? = nil, _ map: [Vertex: Vertex]) {
        self.init(from: from, to: to, { v in map[v]! })
    }
    
    public var image: SimplicialComplex {
        let cells = domain.cellTable.map{ cells in
            cells.flatMap{ s -> Simplex? in
                let t = self.appliedTo(s)
                return (s.dim == t.dim) ? t : nil
            }.unique()
        }
        return SimplicialComplex(cells)
    }
    
    public func appliedTo(_ x: Vertex) -> Vertex {
        return map(x)
    }
    
    public func appliedTo(_ s: Simplex) -> Simplex {
        return Simplex(s.vertices.map{ self.appliedTo($0) }.unique())
    }
    
    public static func identity(from: SimplicialComplex) -> SimplicialMap {
        return SimplicialMap(from: from) { v in v }
    }
    
    public static func diagonal(from: SimplicialComplex) -> SimplicialMap {
        return SimplicialMap(from: from) { v in v × v }
    }
    
    public static func projection(from: SimplicialComplex, _ i: Int) -> SimplicialMap {
        return SimplicialMap(from: from) { v in v.components[i] }
    }
}
{'fraction_non_alphanumeric': 0.10324324324324324, 'fraction_numerical': 0.007027027027027027, 'mean_word_length': 2.2897777777777777, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 23, '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': '1991906', 'n_tokens_mistral': 1193, 'n_tokens_neox': 1111, 'n_words': 321}