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
composeVisitors.js443 linesDownload Raw Back to node
1// @ts-check2/** @typedef {import('./index').Visitor} Visitor */3 4/**5 * Composes multiple visitor objects into a single one.6 * @param {Visitor[]} visitors 7 * @return {Visitor}8 */9function composeVisitors(visitors) {10  if (visitors.length === 1) {11    return visitors[0];12  }13 14  /** @type Visitor */15  let res = {};16  composeSimpleVisitors(res, visitors, 'StyleSheet');17  composeSimpleVisitors(res, visitors, 'StyleSheetExit');18  composeObjectVisitors(res, visitors, 'Rule', ruleVisitor, wrapCustomAndUnknownAtRule);19  composeObjectVisitors(res, visitors, 'RuleExit', ruleVisitor, wrapCustomAndUnknownAtRule);20  composeObjectVisitors(res, visitors, 'Declaration', declarationVisitor, wrapCustomProperty);21  composeObjectVisitors(res, visitors, 'DeclarationExit', declarationVisitor, wrapCustomProperty);22  composeSimpleVisitors(res, visitors, 'Url');23  composeSimpleVisitors(res, visitors, 'Color');24  composeSimpleVisitors(res, visitors, 'Image');25  composeSimpleVisitors(res, visitors, 'ImageExit');26  composeSimpleVisitors(res, visitors, 'Length');27  composeSimpleVisitors(res, visitors, 'Angle');28  composeSimpleVisitors(res, visitors, 'Ratio');29  composeSimpleVisitors(res, visitors, 'Resolution');30  composeSimpleVisitors(res, visitors, 'Time');31  composeSimpleVisitors(res, visitors, 'CustomIdent');32  composeSimpleVisitors(res, visitors, 'DashedIdent');33  composeArrayFunctions(res, visitors, 'MediaQuery');34  composeArrayFunctions(res, visitors, 'MediaQueryExit');35  composeSimpleVisitors(res, visitors, 'SupportsCondition');36  composeSimpleVisitors(res, visitors, 'SupportsConditionExit');37  composeArrayFunctions(res, visitors, 'Selector');38  composeTokenVisitors(res, visitors, 'Token', 'token', false);39  composeTokenVisitors(res, visitors, 'Function', 'function', false);40  composeTokenVisitors(res, visitors, 'FunctionExit', 'function', true);41  composeTokenVisitors(res, visitors, 'Variable', 'var', false);42  composeTokenVisitors(res, visitors, 'VariableExit', 'var', true);43  composeTokenVisitors(res, visitors, 'EnvironmentVariable', 'env', false);44  composeTokenVisitors(res, visitors, 'EnvironmentVariableExit', 'env', true);45  return res;46}47 48module.exports = composeVisitors;49 50function wrapCustomAndUnknownAtRule(k, f) {51  if (k === 'unknown') {52    return (value => f({ type: 'unknown', value }));53  }54  if (k === 'custom') {55    return (value => f({ type: 'custom', value }));56  }57  return f;58}59 60function wrapCustomProperty(k, f) {61  return k === 'custom' ? (value => f({ property: 'custom', value })) : f;62}63 64/**65 * @param {import('./index').Visitor['Rule']} f 66 * @param {import('./ast').Rule} item 67 */68function ruleVisitor(f, item) {69  if (typeof f === 'object') {70    if (item.type === 'unknown') {71      let v = f.unknown;72      if (typeof v === 'object') {73        v = v[item.value.name];74      }75      return v?.(item.value);76    }77    if (item.type === 'custom') {78      let v = f.custom;79      if (typeof v === 'object') {80        v = v[item.value.name];81      }82      return v?.(item.value);83    }84    return f[item.type]?.(item);85  }86  return f?.(item);87}88 89/**90 * @param {import('./index').Visitor['Declaration']} f 91 * @param {import('./ast').Declaration} item 92 */93function declarationVisitor(f, item) {94  if (typeof f === 'object') {95    /** @type {string} */96    let name = item.property;97    if (item.property === 'unparsed') {98      name = item.value.propertyId.property;99    } else if (item.property === 'custom') {100      let v = f.custom;101      if (typeof v === 'object') {102        v = v[item.value.name];103      }104      return v?.(item.value);105    }106    return f[name]?.(item);107  }108  return f?.(item);109}110 111/**112 * 113 * @param {Visitor[]} visitors 114 * @param {string} key 115 * @returns {[any[], boolean, Set<string>]}116 */117function extractObjectsOrFunctions(visitors, key) {118  let values = [];119  let hasFunction = false;120  let allKeys = new Set();121  for (let visitor of visitors) {122    let v = visitor[key];123    if (v) {124      if (typeof v === 'function') {125        hasFunction = true;126      } else {127        for (let key in v) {128          allKeys.add(key);129        }130      }131      values.push(v);132    }133  }134  return [values, hasFunction, allKeys];135}136 137/**138 * @template {keyof Visitor} K139 * @param {Visitor} res140 * @param {Visitor[]} visitors141 * @param {K} key142 * @param {(visitor: Visitor[K], item: any) => any | any[] | void} apply 143 * @param {(k: string, f: any) => any} wrapKey 144 */145function composeObjectVisitors(res, visitors, key, apply, wrapKey) {146  let [values, hasFunction, allKeys] = extractObjectsOrFunctions(visitors, key);147  if (values.length === 0) {148    return;149  }150 151  if (values.length === 1) {152    res[key] = values[0];153    return;154  }155 156  let f = createArrayVisitor(visitors, (visitor, item) => apply(visitor[key], item));157  if (hasFunction) {158    res[key] = f;159  } else {160    /** @type {any} */161    let v = {};162    for (let k of allKeys) {163      v[k] = wrapKey(k, f);164    }165    res[key] = v;166  }167}168 169/**170 * @param {Visitor} res 171 * @param {Visitor[]} visitors 172 * @param {string} key 173 * @param {import('./ast').TokenOrValue['type']} type 174 * @param {boolean} isExit 175 */176function composeTokenVisitors(res, visitors, key, type, isExit) {177  let [values, hasFunction, allKeys] = extractObjectsOrFunctions(visitors, key);178  if (values.length === 0) {179    return;180  }181 182  if (values.length === 1) {183    res[key] = values[0];184    return;185  }186 187  let f = createTokenVisitor(visitors, type, isExit);188  if (hasFunction) {189    res[key] = f;190  } else {191    let v = {};192    for (let key of allKeys) {193      v[key] = f;194    }195    res[key] = v;196  }197}198 199/**200 * @param {Visitor[]} visitors 201 * @param {import('./ast').TokenOrValue['type']} type 202 */203function createTokenVisitor(visitors, type, isExit) {204  let v = createArrayVisitor(visitors, (visitor, /** @type {import('./ast').TokenOrValue} */ item) => {205    let f;206    switch (item.type) {207      case 'token':208        f = visitor.Token;209        if (typeof f === 'object') {210          f = f[item.value.type];211        }212        break;213      case 'function':214        f = isExit ? visitor.FunctionExit : visitor.Function;215        if (typeof f === 'object') {216          f = f[item.value.name];217        }218        break;219      case 'var':220        f = isExit ? visitor.VariableExit : visitor.Variable;221        break;222      case 'env':223        f = isExit ? visitor.EnvironmentVariableExit : visitor.EnvironmentVariable;224        if (typeof f === 'object') {225          let name;226          switch (item.value.name.type) {227            case 'ua':228            case 'unknown':229              name = item.value.name.value;230              break;231            case 'custom':232              name = item.value.name.ident;233              break;234          }235          f = f[name];236        }237        break;238      case 'color':239        f = visitor.Color;240        break;241      case 'url':242        f = visitor.Url;243        break;244      case 'length':245        f = visitor.Length;246        break;247      case 'angle':248        f = visitor.Angle;249        break;250      case 'time':251        f = visitor.Time;252        break;253      case 'resolution':254        f = visitor.Resolution;255        break;256      case 'dashed-ident':257        f = visitor.DashedIdent;258        break;259    }260 261    if (!f) {262      return;263    }264 265    let res = f(item.value);266    switch (item.type) {267      case 'color':268      case 'url':269      case 'length':270      case 'angle':271      case 'time':272      case 'resolution':273      case 'dashed-ident':274        if (Array.isArray(res)) {275          res = res.map(value => ({ type: item.type, value }))276        } else if (res) {277          res = { type: item.type, value: res };278        }279        break;280    }281 282    return res;283  });284 285  return value => v({ type, value });286}287 288/**289 * @param {Visitor[]} visitors 290 * @param {string} key 291 */292function extractFunctions(visitors, key) {293  let functions = [];294  for (let visitor of visitors) {295    let f = visitor[key];296    if (f) {297      functions.push(f);298    }299  }300  return functions;301}302 303/**304 * @param {Visitor} res 305 * @param {Visitor[]} visitors 306 * @param {string} key 307 */308function composeSimpleVisitors(res, visitors, key) {309  let functions = extractFunctions(visitors, key);310  if (functions.length === 0) {311    return;312  }313 314  if (functions.length === 1) {315    res[key] = functions[0];316    return;317  }318 319  res[key] = arg => {320    let mutated = false;321    for (let f of functions) {322      let res = f(arg);323      if (res) {324        arg = res;325        mutated = true;326      }327    }328 329    return mutated ? arg : undefined;330  };331}332 333/**334 * @param {Visitor} res 335 * @param {Visitor[]} visitors 336 * @param {string} key 337 */338function composeArrayFunctions(res, visitors, key) {339  let functions = extractFunctions(visitors, key);340  if (functions.length === 0) {341    return;342  }343 344  if (functions.length === 1) {345    res[key] = functions[0];346    return;347  }348 349  res[key] = createArrayVisitor(functions, (f, item) => f(item));350}351 352/**353 * @template T354 * @template V355 * @param {T[]} visitors 356 * @param {(visitor: T, item: V) => V | V[] | void} apply 357 * @returns {(item: V) => V | V[] | void}358 */359function createArrayVisitor(visitors, apply) {360  let seen = new Bitset(visitors.length);361  return arg => {362    let arr = [arg];363    let mutated = false;364    seen.clear();365    for (let i = 0; i < arr.length; i++) {366      // For each value, call all visitors. If a visitor returns a new value,367      // we start over, but skip the visitor that generated the value or saw368      // it before (to avoid cycles). This way, visitors can be composed in any order. 369      for (let v = 0; v < visitors.length;) {370        if (seen.get(v)) {371          v++;372          continue;373        }374 375        let item = arr[i];376        let visitor = visitors[v];377        let res = apply(visitor, item);378        if (Array.isArray(res)) {379          if (res.length === 0) {380            arr.splice(i, 1);381          } else if (res.length === 1) {382            arr[i] = res[0];383          } else {384            arr.splice(i, 1, ...res);385          }386          mutated = true;387          seen.set(v);388          v = 0;389        } else if (res) {390          arr[i] = res;391          mutated = true;392          seen.set(v);393          v = 0;394        } else {395          v++;396        }397      }398    }399 400    if (!mutated) {401      return;402    }403 404    return arr.length === 1 ? arr[0] : arr;405  };406}407 408class Bitset {409  constructor(maxBits = 32) {410    this.bits = 0;411    this.more = maxBits > 32 ? new Uint32Array(Math.ceil((maxBits - 32) / 32)) : null;412  }413 414  /** @param {number} bit */415  get(bit) {416    if (bit >= 32 && this.more) {417      let i = Math.floor((bit - 32) / 32);418      let b = bit % 32;419      return Boolean(this.more[i] & (1 << b));420    } else {421      return Boolean(this.bits & (1 << bit));422    }423  }424 425  /** @param {number} bit */426  set(bit) {427    if (bit >= 32 && this.more) {428      let i = Math.floor((bit - 32) / 32);429      let b = bit % 32;430      this.more[i] |= 1 << b;431    } else {432      this.bits |= 1 << bit;433    }434  }435 436  clear() {437    this.bits = 0;438    if (this.more) {439      this.more.fill(0);440    }441  }442}443 
Brunobkr/llama.cpp_AlgMor24_github · Team Ai