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
supsub.ts269 linesDownload Raw Back to functions
1import {defineFunctionBuilders} from "../defineFunction";2import {makeSpan, makeVList} from "../buildCommon";3import {Span, SymbolNode, type HtmlDomNode} from "../domTree";4import {isCharacterBox} from "../utils";5import {MathNode} from "../mathMLTree";6import {makeEm} from "../units";7import Style from "../Style";8 9import * as html from "../buildHTML";10import * as mml from "../buildMathML";11import * as accent from "./accent";12import * as horizBrace from "./horizBrace";13import * as op from "./op";14import * as operatorname from "./operatorname";15 16import type Options from "../Options";17import type {ParseNode} from "../parseNode";18import type {HtmlBuilder} from "../defineFunction";19import type {MathNodeType} from "../mathMLTree";20 21/**22 * Sometimes, groups perform special rules when they have superscripts or23 * subscripts attached to them. This function lets the `supsub` group know that24 * Sometimes, groups perform special rules when they have superscripts or25 * its inner element should handle the superscripts and subscripts instead of26 * handling them itself.27 */28const htmlBuilderDelegate = function(29    group: ParseNode<"supsub">,30    options: Options,31// eslint-disable-next-line @typescript-eslint/no-explicit-any32): HtmlBuilder<any> | null | undefined {33    const base = group.base;34    if (!base) {35        return null;36    } else if (base.type === "op") {37        // Operators handle supsubs differently when they have limits38        // (e.g. `\displaystyle\sum_2^3`)39        const delegate = base.limits &&40            (options.style.size === Style.DISPLAY.size ||41            base.alwaysHandleSupSub);42        return delegate ? op.htmlBuilder : null;43    } else if (base.type === "operatorname") {44        const delegate = base.alwaysHandleSupSub &&45            (options.style.size === Style.DISPLAY.size || base.limits);46        return delegate ? operatorname.htmlBuilder : null;47    } else if (base.type === "accent") {48        return isCharacterBox(base.base) ? accent.htmlBuilder : null;49    } else if (base.type === "horizBrace") {50        const isSup = !group.sub;51        return isSup === base.isOver ? horizBrace.htmlBuilder : null;52    } else {53        return null;54    }55};56 57// Super scripts and subscripts, whose precise placement can depend on other58// functions that precede them.59defineFunctionBuilders({60    type: "supsub",61    htmlBuilder(group, options) {62        // Superscript and subscripts are handled in the TeXbook on page63        // 445-446, rules 18(a-f).64 65        // Here is where we defer to the inner group if it should handle66        // superscripts and subscripts itself.67        const builderDelegate = htmlBuilderDelegate(group, options);68        if (builderDelegate) {69            return builderDelegate(group, options);70        }71 72        const {base: valueBase, sup: valueSup, sub: valueSub} = group;73        const base = html.buildGroup(valueBase, options);74        let supm;75        let subm;76 77        const metrics = options.fontMetrics();78 79        // Rule 18a80        let supShift = 0;81        let subShift = 0;82 83        const isCharBox = valueBase && isCharacterBox(valueBase);84        if (valueSup) {85            const newOptions = options.havingStyle(options.style.sup());86            supm = html.buildGroup(valueSup, newOptions, options);87            if (!isCharBox) {88                supShift = base.height - newOptions.fontMetrics().supDrop89                    * newOptions.sizeMultiplier / options.sizeMultiplier;90            }91        }92 93        if (valueSub) {94            const newOptions = options.havingStyle(options.style.sub());95            subm = html.buildGroup(valueSub, newOptions, options);96            if (!isCharBox) {97                subShift = base.depth + newOptions.fontMetrics().subDrop98                    * newOptions.sizeMultiplier / options.sizeMultiplier;99            }100        }101 102        // Rule 18c103        let minSupShift;104        if (options.style === Style.DISPLAY) {105            minSupShift = metrics.sup1;106        } else if (options.style.cramped) {107            minSupShift = metrics.sup3;108        } else {109            minSupShift = metrics.sup2;110        }111 112        // scriptspace is a font-size-independent size, so scale it113        // appropriately for use as the marginRight.114        const multiplier = options.sizeMultiplier;115        const marginRight = makeEm((0.5 / metrics.ptPerEm) / multiplier);116 117        let marginLeft = null;118        if (subm) {119            // Subscripts shouldn't be shifted by the base's italic correction.120            // Account for that by shifting the subscript back the appropriate121            // amount. Note we only do this when the base is a single symbol.122            const isOiint =123                group.base && group.base.type === "op" && group.base.name &&124                (group.base.name === "\\oiint" || group.base.name === "\\oiiint");125            if (base instanceof SymbolNode || isOiint) {126                // SymbolNode has .italic natively; for \oiint/\oiiint the127                // op builder stores .italic on the wrapping Span.128                marginLeft = makeEm(129                    -((base as SymbolNode | Span<HtmlDomNode>).italic ?? 0));130            }131        }132 133        let supsub;134        if (supm && subm) {135            supShift = Math.max(136                supShift, minSupShift, supm.depth + 0.25 * metrics.xHeight);137            subShift = Math.max(subShift, metrics.sub2);138 139            const ruleWidth = metrics.defaultRuleThickness;140 141            // Rule 18e142            const maxWidth = 4 * ruleWidth;143            if ((supShift - supm.depth) - (subm.height - subShift) < maxWidth) {144                subShift = maxWidth - (supShift - supm.depth) + subm.height;145                const psi = 0.8 * metrics.xHeight - (supShift - supm.depth);146                if (psi > 0) {147                    supShift += psi;148                    subShift -= psi;149                }150            }151 152            const vlistElem = [153                {type: "elem" as const, elem: subm, shift: subShift, marginRight,154                    marginLeft},155                {type: "elem" as const, elem: supm, shift: -supShift, marginRight},156            ];157 158            supsub = makeVList({159                positionType: "individualShift",160                children: vlistElem,161            }, options);162        } else if (subm) {163            // Rule 18b164            subShift = Math.max(165                subShift, metrics.sub1,166                subm.height - 0.8 * metrics.xHeight);167 168            const vlistElem =169                [{type: "elem" as const, elem: subm, marginLeft, marginRight}];170 171            supsub = makeVList({172                positionType: "shift",173                positionData: subShift,174                children: vlistElem,175            }, options);176        } else if (supm) {177            // Rule 18c, d178            supShift = Math.max(supShift, minSupShift,179                supm.depth + 0.25 * metrics.xHeight);180 181            supsub = makeVList({182                positionType: "shift",183                positionData: -supShift,184                children: [{type: "elem" as const, elem: supm, marginRight}],185            }, options);186        } else {187            throw new Error("supsub must have either sup or sub.");188        }189 190        // Wrap the supsub vlist in a span.msupsub to reset text-align.191        const mclass = html.getTypeOfDomTree(base, "right") || "mord";192        return makeSpan([mclass],193            [base, makeSpan(["msupsub"], [supsub])],194            options);195    },196    mathmlBuilder(group, options) {197        // Is the inner group a relevant horizontal brace?198        let isBrace = false;199        let isOver;200        let isSup;201 202        if (group.base && group.base.type === "horizBrace") {203            isSup = !!group.sup;204            if (isSup === group.base.isOver) {205                isBrace = true;206                isOver = group.base.isOver;207            }208        }209 210        if (group.base &&211            (group.base.type === "op" || group.base.type === "operatorname")) {212            group.base.parentIsSupSub = true;213        }214 215        const children = [mml.buildGroup(group.base, options)];216 217        if (group.sub) {218            children.push(mml.buildGroup(group.sub, options));219        }220 221        if (group.sup) {222            children.push(mml.buildGroup(group.sup, options));223        }224 225        let nodeType: MathNodeType;226        if (isBrace) {227            nodeType = (isOver ? "mover" : "munder");228        } else if (!group.sub) {229            const base = group.base;230            if (base && base.type === "op" && base.limits &&231                (options.style === Style.DISPLAY || base.alwaysHandleSupSub)) {232                nodeType = "mover";233            } else if (base && base.type === "operatorname" &&234                base.alwaysHandleSupSub &&235                (base.limits || options.style === Style.DISPLAY)) {236                nodeType = "mover";237            } else {238                nodeType = "msup";239            }240        } else if (!group.sup) {241            const base = group.base;242            if (base && base.type === "op" && base.limits &&243                (options.style === Style.DISPLAY || base.alwaysHandleSupSub)) {244                nodeType = "munder";245            } else if (base && base.type === "operatorname" &&246                base.alwaysHandleSupSub &&247                (base.limits || options.style === Style.DISPLAY)) {248                nodeType = "munder";249            } else {250                nodeType = "msub";251            }252        } else {253            const base = group.base;254            if (base && base.type === "op" && base.limits &&255                options.style === Style.DISPLAY) {256                nodeType = "munderover";257            } else if (base && base.type === "operatorname" &&258                base.alwaysHandleSupSub &&259                (options.style === Style.DISPLAY || base.limits)) {260                nodeType = "munderover";261            } else {262                nodeType = "msubsup";263            }264        }265 266        return new MathNode(nodeType, children);267    },268});269 
Brunobkr/llama.cpp_AlgMor24_github · Team Ai