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.
03.1k
1import defineFunction, {ordargument} from "../defineFunction";2import {makeSpan} from "../buildCommon";3import {isCharacterBox} from "../utils";4import {MathNode} from "../mathMLTree";5import type {AnyParseNode} from "../parseNode";6 7import * as html from "../buildHTML";8import * as mml from "../buildMathML";9 10import type Options from "../Options";11import type {ParseNode} from "../parseNode";12 13function htmlBuilder(group: ParseNode<"mclass">, options: Options) {14 const elements = html.buildExpression(group.body, options, true);15 return makeSpan([group.mclass], elements, options);16}17 18function mathmlBuilder(group: ParseNode<"mclass">, options: Options) {19 let node: MathNode;20 const inner = mml.buildExpression(group.body, options);21 22 if (group.mclass === "minner") {23 node = new MathNode("mpadded", inner);24 } else if (group.mclass === "mord") {25 if (group.isCharacterBox) {26 node = inner[0];27 node.type = "mi";28 } else {29 node = new MathNode("mi", inner);30 }31 } else {32 if (group.isCharacterBox) {33 node = inner[0];34 node.type = "mo";35 } else {36 node = new MathNode("mo", inner);37 }38 39 // Set spacing based on what is the most likely adjacent atom type.40 // See TeXbook p170.41 if (group.mclass === "mbin") {42 node.attributes.lspace = "0.22em"; // medium space43 node.attributes.rspace = "0.22em";44 } else if (group.mclass === "mpunct") {45 node.attributes.lspace = "0em";46 node.attributes.rspace = "0.17em"; // thinspace47 } else if (group.mclass === "mopen" || group.mclass === "mclose") {48 node.attributes.lspace = "0em";49 node.attributes.rspace = "0em";50 } else if (group.mclass === "minner") {51 node.attributes.lspace = "0.0556em"; // 1 mu is the most likely option52 node.attributes.width = "+0.1111em";53 }54 // MathML <mo> default space is 5/18 em, so <mrel> needs no action.55 // Ref: https://developer.mozilla.org/en-US/docs/Web/MathML/Element/mo56 }57 return node;58}59 60// Math class commands except \mathop61defineFunction({62 type: "mclass",63 names: [64 "\\mathord", "\\mathbin", "\\mathrel", "\\mathopen",65 "\\mathclose", "\\mathpunct", "\\mathinner",66 ],67 props: {68 numArgs: 1,69 primitive: true,70 },71 handler({parser, funcName}, args) {72 const body = args[0];73 return {74 type: "mclass",75 mode: parser.mode,76 mclass: "m" + funcName.slice(5), // TODO(kevinb): don't prefix with 'm'77 body: ordargument(body),78 isCharacterBox: isCharacterBox(body),79 };80 },81 htmlBuilder,82 mathmlBuilder,83});84 85export const binrelClass = (arg: AnyParseNode): string => {86 // \binrel@ spacing varies with (bin|rel|ord) of the atom in the argument.87 // (by rendering separately and with {}s before and after, and measuring88 // the change in spacing). We'll do roughly the same by detecting the89 // atom type directly.90 const atom = (arg.type === "ordgroup" && arg.body.length ? arg.body[0] : arg);91 if (atom.type === "atom" && (atom.family === "bin" || atom.family === "rel")) {92 return "m" + atom.family;93 } else {94 return "mord";95 }96};97 98// \@binrel{x}{y} renders like y but as mbin/mrel/mord if x is mbin/mrel/mord.99// This is equivalent to \binrel@{x}\binrel@@{y} in AMSTeX.100defineFunction({101 type: "mclass",102 names: ["\\@binrel"],103 props: {104 numArgs: 2,105 },106 handler({parser}, args) {107 return {108 type: "mclass",109 mode: parser.mode,110 mclass: binrelClass(args[0]),111 body: ordargument(args[1]),112 isCharacterBox: isCharacterBox(args[1]),113 };114 },115});116 117// Build a relation or stacked op by placing one symbol on top of another118defineFunction({119 type: "mclass",120 names: ["\\stackrel", "\\overset", "\\underset"],121 props: {122 numArgs: 2,123 },124 handler({parser, funcName}, args) {125 const baseArg = args[1];126 const shiftedArg = args[0];127 128 let mclass;129 if (funcName !== "\\stackrel") {130 // LaTeX applies \binrel spacing to \overset and \underset.131 mclass = binrelClass(baseArg);132 } else {133 mclass = "mrel"; // for \stackrel134 }135 136 const baseOp: ParseNode<"op"> = {137 type: "op",138 mode: baseArg.mode,139 limits: true,140 alwaysHandleSupSub: true,141 parentIsSupSub: false,142 symbol: false,143 suppressBaseShift: funcName !== "\\stackrel",144 body: ordargument(baseArg),145 };146 147 const supsub: ParseNode<"supsub"> = {148 type: "supsub",149 mode: shiftedArg.mode,150 base: baseOp,151 sup: funcName === "\\underset" ? null : shiftedArg,152 sub: funcName === "\\underset" ? shiftedArg : null,153 };154 155 return {156 type: "mclass",157 mode: parser.mode,158 mclass,159 body: [supsub],160 isCharacterBox: isCharacterBox(supsub),161 };162 },163 htmlBuilder,164 mathmlBuilder,165});166 