Team Ai
Datasetpublic

Brunobkr/llama.cpp_AlgMor24_github

ΩFFFΣLLIa • llama.cpp • AlgMor24 ██████╗ ███████╗███████╗███████╗██╗ ██╗ ██╗ █████╗ ██╔═══██╗██╔════╝██╔════╝██╔════╝██║ ██║ ██║██╔══██╗ ██║ ██║█████╗ █████╗ █████╗ ██║ ██║ ██║███████║ ██║ ██║██╔══╝ ██╔══╝ ██╔══╝ ██║ ██║ ██║██╔══██║ ╚██████╔╝██║ ██║ ███████╗███████╗███████╗██║██║ ██║ ╚═════╝ ╚═╝ ╚═╝ ╚══════╝╚══════╝╚══════╝╚═╝╚═╝ ╚═╝ High-Performance LLM / VLM Inference & Autonomous Agentic Ecosystem… See the full description on the dataset page: https://huggingface.co/datasets/Brunobkr/llama.cpp_AlgMor24_github.

sourceHugging Faceupdated 2mo agoView on Hugging Face
0likes3.1kdownloads
cd.ts319 linesDownload Raw Back to environments
1import {wrapFragment} from "../buildCommon";2import defineFunction from "../defineFunction";3import {MathNode} from "../mathMLTree";4import * as html from "../buildHTML";5import * as mml from "../buildMathML";6import {assertSymbolNodeType} from "../parseNode";7import ParseError from "../ParseError";8import {makeEm} from "../units";9 10import type Parser from "../Parser";11import type {ParseNode, AnyParseNode} from "../parseNode";12 13const cdArrowFunctionName: Record<string, string> = {14    ">": "\\\\cdrightarrow",15    "<": "\\\\cdleftarrow",16    "=": "\\\\cdlongequal",17    "A": "\\uparrow",18    "V": "\\downarrow",19    "|": "\\Vert",20    ".": "no arrow",21};22 23const newCell = (): ParseNode<"styling"> => {24    // Create an empty cell, to be filled below with parse nodes.25    // The parseTree from this module must be constructed like the26    // one created by parseArray(), so an empty CD cell must27    // be a ParseNode<"styling">. And CD is always displaystyle.28    return {29        type: "styling",30        body: [],31        mode: "math",32        style: "display",33        resetFont: true,34    };35};36 37const isStartOfArrow = (node: AnyParseNode) => {38    return (node.type === "textord" && node.text === "@");39};40 41const isLabelEnd = (node: AnyParseNode, endChar: string): boolean => {42    return ((node.type === "mathord" || node.type === "atom") &&43        node.text === endChar);44};45 46function cdArrow(47    arrowChar: string,48    labels: ParseNode<"ordgroup">[],49    parser: Parser50): AnyParseNode {51    // Return a parse tree of an arrow and its labels.52    // This acts in a way similar to a macro expansion.53    const funcName = cdArrowFunctionName[arrowChar];54    switch (funcName) {55        case "\\\\cdrightarrow":56        case "\\\\cdleftarrow":57            return parser.callFunction(58                funcName, [labels[0]], [labels[1]]59            );60        case "\\uparrow":61        case "\\downarrow": {62            const leftLabel = parser.callFunction(63                "\\\\cdleft", [labels[0]], []64            );65            const bareArrow: ParseNode<"atom"> = {66                type: "atom",67                text: funcName,68                mode: "math",69                family: "rel",70            };71            const sizedArrow = parser.callFunction("\\Big", [bareArrow], []);72            const rightLabel = parser.callFunction(73                "\\\\cdright", [labels[1]], []74            );75            const arrowGroup: ParseNode<"ordgroup"> = {76                type: "ordgroup",77                mode: "math",78                body: [leftLabel, sizedArrow, rightLabel],79            };80            return parser.callFunction("\\\\cdparent", [arrowGroup], []);81        }82        case "\\\\cdlongequal":83            return parser.callFunction("\\\\cdlongequal", [], []);84        case "\\Vert": {85            const arrow: ParseNode<"textord"> = {type: "textord", text: "\\Vert", mode: "math"};86            return parser.callFunction("\\Big", [arrow], []);87        }88        default:89            return {type: "textord", text: " ", mode: "math"};90    }91}92 93export function parseCD(parser: Parser): ParseNode<"array"> {94    // Get the array's parse nodes with \\ temporarily mapped to \cr.95    const parsedRows: AnyParseNode[][] = [];96    parser.gullet.beginGroup();97    parser.gullet.macros.set("\\cr", "\\\\\\relax");98    parser.gullet.beginGroup();99    while (true) {100        // Get the parse nodes for the next row.101        parsedRows.push(parser.parseExpression(false, "\\\\"));102        parser.gullet.endGroup();103        parser.gullet.beginGroup();104        const next = parser.fetch().text;105        if (next === "&" || next === "\\\\") {106            parser.consume();107        } else if (next === "\\end") {108            if (parsedRows[parsedRows.length - 1].length === 0) {109                parsedRows.pop(); // final row ended in \\110            }111            break;112        } else {113            throw new ParseError("Expected \\\\ or \\cr or \\end",114                                 parser.nextToken);115        }116    }117 118    let row: ParseNode<"styling">[] = [];119    const body: ParseNode<"styling">[][] = [row];120 121    // Loop thru the parse nodes. Collect them into cells and arrows.122    for (let i = 0; i < parsedRows.length; i++) {123        // Start a new row.124        const rowNodes = parsedRows[i];125        // Create the first cell.126        let cell = newCell();127 128        for (let j = 0; j < rowNodes.length; j++) {129            if (!isStartOfArrow(rowNodes[j])) {130                // If a parseNode is not an arrow, it goes into a cell.131                cell.body.push(rowNodes[j]);132            } else {133                // Parse node j is an "@", the start of an arrow.134                // Before starting on the arrow, push the cell into `row`.135                row.push(cell);136 137                // Now collect parseNodes into an arrow.138                // The character after "@" defines the arrow type.139                j += 1;140                const arrowChar = assertSymbolNodeType(rowNodes[j]).text;141 142                // Create two empty label nodes. We may or may not use them.143                const labels: ParseNode<"ordgroup">[] = new Array(2);144                labels[0] = {type: "ordgroup", mode: "math", body: []};145                labels[1] = {type: "ordgroup", mode: "math", body: []};146 147                // Process the arrow.148                if ("=|.".includes(arrowChar)) {149                    // Three "arrows", ``@=`, `@|`, and `@.`, do not take labels.150                    // Do nothing here.151                } else if ("<>AV".includes(arrowChar)) {152                    // Four arrows, `@>>>`, `@<<<`, `@AAA`, and `@VVV`, each take153                    // two optional labels. E.g. the right-point arrow syntax is154                    // really:  @>{optional label}>{optional label}>155                    // Collect parseNodes into labels.156                    for (let labelNum = 0; labelNum < 2; labelNum++) {157                        let inLabel = true;158                        for (let k = j + 1; k < rowNodes.length; k++) {159                            if (isLabelEnd(rowNodes[k], arrowChar)) {160                                inLabel = false;161                                j = k;162                                break;163                            }164                            if (isStartOfArrow(rowNodes[k])) {165                                throw new ParseError("Missing a " + arrowChar +166                                " character to complete a CD arrow.", rowNodes[k]);167                            }168 169                            labels[labelNum].body.push(rowNodes[k]);170                        }171                        if (inLabel) {172                            // isLabelEnd never returned a true.173                            throw new ParseError("Missing a " + arrowChar +174                                " character to complete a CD arrow.", rowNodes[j]);175                        }176                    }177                } else {178                    throw new ParseError(`Expected one of "<>AV=|." after @`,179                        rowNodes[j]);180                }181 182                // Now join the arrow to its labels.183                const arrow: AnyParseNode = cdArrow(arrowChar, labels, parser);184 185                // Wrap the arrow in  ParseNode<"styling">.186                // This is done to match parseArray() behavior.187                const wrappedArrow: ParseNode<"styling"> = {188                    type: "styling",189                    body: [arrow],190                    mode: "math",191                    style: "display", // CD is always displaystyle.192                    resetFont: true,193                };194                row.push(wrappedArrow);195                // In CD's syntax, cells are implicit. That is, everything that196                // is not an arrow gets collected into a cell. So create an empty197                // cell now. It will collect upcoming parseNodes.198                cell = newCell();199            }200        }201        if (i % 2 === 0) {202            // Even-numbered rows consist of: cell, arrow, cell, arrow, ... cell203            // The last cell is not yet pushed into `row`, so:204            row.push(cell);205        } else {206            // Odd-numbered rows consist of: vert arrow, empty cell, ... vert arrow207            // Remove the empty cell that was placed at the beginning of `row`.208            row.shift();209        }210        row = [];211        body.push(row);212    }213 214    // End row group215    parser.gullet.endGroup();216    // End array group defining \\217    parser.gullet.endGroup();218 219    // define column separation.220    const cols = new Array(body[0].length).fill({221        type: "align",222        align: "c",223        pregap: 0.25,  // CD package sets \enskip between columns.224        postgap: 0.25, // So pre and post each get half an \enskip, i.e. 0.25em.225    });226 227    return {228        type: "array",229        mode: "math",230        body,231        arraystretch: 1,232        addJot: true,233        rowGaps: [null],234        cols,235        colSeparationType: "CD",236        hLinesBeforeRow: new Array(body.length + 1).fill([]),237    };238}239 240// The functions below are not available for general use.241// They are here only for internal use by the {CD} environment in placing labels242// next to vertical arrows.243 244// We don't need any such functions for horizontal arrows because we can reuse245// the functionality that already exists for extensible arrows.246 247defineFunction({248    type: "cdlabel",249    names: ["\\\\cdleft", "\\\\cdright"],250    props: {251        numArgs: 1,252    },253    handler({parser, funcName}, args) {254        return {255            type: "cdlabel",256            mode: parser.mode,257            side: funcName.slice(4),258            label: args[0],259        };260    },261    htmlBuilder(group, options) {262        const newOptions = options.havingStyle(options.style.sup());263        const label = wrapFragment(264            html.buildGroup(group.label, newOptions, options), options);265        label.classes.push("cd-label-" + group.side);266        label.style.bottom = makeEm(0.8 - label.depth);267        // Zero out label height & depth, so vertical align of arrow is set268        // by the arrow height, not by the label.269        label.height = 0;270        label.depth = 0;271        return label;272    },273    mathmlBuilder(group, options) {274        let label = new MathNode("mrow",275            [mml.buildGroup(group.label, options)]);276        label = new MathNode("mpadded", [label]);277        label.setAttribute("width", "0");278        if (group.side === "left") {279            label.setAttribute("lspace", "-1width");280        }281        // We have to guess at vertical alignment. We know the arrow is 1.8em tall,282        // But we don't know the height or depth of the label.283        label.setAttribute("voffset", "0.7em");284        label = new MathNode("mstyle", [label]);285        label.setAttribute("displaystyle", "false");286        label.setAttribute("scriptlevel", "1");287        return label;288    },289});290 291defineFunction({292    type: "cdlabelparent",293    names: ["\\\\cdparent"],294    props: {295        numArgs: 1,296    },297    handler({parser}, args) {298        return {299            type: "cdlabelparent",300            mode: parser.mode,301            fragment: args[0],302        };303    },304    htmlBuilder(group, options) {305        // Wrap the vertical arrow and its labels.306        // The parent gets position: relative. The child gets position: absolute.307        // So CSS can locate the label correctly.308        const parent = wrapFragment(309            html.buildGroup(group.fragment, options), options310        );311        parent.classes.push("cd-vert-arrow");312        return parent;313    },314    mathmlBuilder(group, options) {315        return new MathNode("mrow",316            [mml.buildGroup(group.fragment, options)]);317    },318});319 
Brunobkr/llama.cpp_AlgMor24_github · Team Ai