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
operatorname.ts162 linesDownload Raw Back to functions
1import defineFunction, {ordargument} from "../defineFunction";2import defineMacro from "../defineMacro";3import {makeSpan} from "../buildCommon";4import {MathNode, newDocumentFragment, SpaceNode, TextNode} from "../mathMLTree";5import {SymbolNode} from "../domTree";6import {assembleSupSub} from "./utils/assembleSupSub";7import {assertNodeType} from "../parseNode";8 9import * as html from "../buildHTML";10import * as mml from "../buildMathML";11 12import type {HtmlBuilderSupSub, MathMLBuilder} from "../defineFunction";13import type {AnyParseNode, ParseNode} from "../parseNode";14 15// NOTE: Unlike most `htmlBuilder`s, this one handles not only16// "operatorname", but also  "supsub" since \operatorname* can17// affect super/subscripting.18export const htmlBuilder: HtmlBuilderSupSub<"operatorname"> = (grp, options) => {19    // Operators are handled in the TeXbook pg. 443-444, rule 13(a).20    let supGroup;21    let subGroup;22    let hasLimits = false;23    let group: ParseNode<"operatorname">;24    if (grp.type === "supsub") {25        // If we have limits, supsub will pass us its group to handle. Pull26        // out the superscript and subscript and set the group to the op in27        // its base.28        supGroup = grp.sup;29        subGroup = grp.sub;30        group = assertNodeType(grp.base, "operatorname");31        hasLimits = true;32    } else {33        group = assertNodeType(grp, "operatorname");34    }35 36    let base;37    if (group.body.length > 0) {38        const body = group.body.map((child): AnyParseNode => {39            const childText = "text" in child ? child.text : undefined;40            if (typeof childText === "string") {41                return {42                    type: "textord",43                    mode: child.mode,44                    text: childText,45                };46            } else {47                return child;48            }49        });50 51        // Consolidate function names into symbol characters.52        const expression = html.buildExpression(53            body, options.withFont("mathrm"), true);54 55        for (let i = 0; i < expression.length; i++) {56            const child = expression[i];57            if (child instanceof SymbolNode) {58                // Per amsopn package,59                // change minus to hyphen and \ast to asterisk60                child.text = child.text.replace(/\u2212/, "-")61                    .replace(/\u2217/, "*");62            }63        }64        base = makeSpan(["mop"], expression, options);65    } else {66        base = makeSpan(["mop"], [], options);67    }68 69    if (hasLimits) {70        return assembleSupSub(base, supGroup, subGroup, options,71            options.style, 0, 0);72 73    } else {74        return base;75    }76};77 78const mathmlBuilder: MathMLBuilder<"operatorname"> = (group, options) => {79    // The steps taken here are similar to the html version.80    let expression: Array<MathNode | TextNode> = mml.buildExpression(81        group.body, options.withFont("mathrm"));82 83    // Is expression a string or has it something like a fraction?84    let isAllString = true;  // default85    for (let i = 0; i < expression.length; i++) {86        const node = expression[i];87        if (node instanceof SpaceNode) {88            // Do nothing89        } else if (node instanceof MathNode) {90            switch (node.type) {91                case "mi":92                case "mn":93                case "mspace":94                case "mtext":95                    break;  // Do nothing yet.96                case "mo": {97                    const child = node.children[0];98                    if (node.children.length === 1 &&99                        child instanceof TextNode) {100                        child.text =101                            child.text.replace(/\u2212/, "-")102                                .replace(/\u2217/, "*");103                    } else {104                        isAllString = false;105                    }106                    break;107                }108                default:109                    isAllString = false;110            }111        } else {112            isAllString = false;113        }114    }115 116    if (isAllString) {117        // Write a single TextNode instead of multiple nested tags.118        const word = expression.map(node => node.toText()).join("");119        expression = [new TextNode(word)];120    }121 122    const identifier = new MathNode("mi", expression);123    identifier.setAttribute("mathvariant", "normal");124 125    // \u2061 is the same as &ApplyFunction;126    // ref: https://www.w3schools.com/charsets/ref_html_entities_a.asp127    const operator = new MathNode("mo",128        [mml.makeText("\u2061", "text")]);129 130    if (group.parentIsSupSub) {131        return new MathNode("mrow", [identifier, operator]);132    } else {133        return newDocumentFragment([identifier, operator]);134    }135};136 137// \operatorname138// amsopn.dtx: \mathop{#1\kern\z@\operator@font#3}\newmcodes@139defineFunction({140    type: "operatorname",141    names: ["\\operatorname@", "\\operatornamewithlimits"],142    props: {143        numArgs: 1,144    },145    handler: ({parser, funcName}, args) => {146        const body = args[0];147        return {148            type: "operatorname",149            mode: parser.mode,150            body: ordargument(body),151            alwaysHandleSupSub: (funcName === "\\operatornamewithlimits"),152            limits: false,153            parentIsSupSub: false,154        };155    },156    htmlBuilder,157    mathmlBuilder,158});159 160defineMacro("\\operatorname",161  "\\@ifstar\\operatornamewithlimits\\operatorname@");162 
Brunobkr/llama.cpp_AlgMor24_github · Team Ai