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
spring.js370 linesDownload Raw Back to motion
1/** @import { Task } from '#client' */2/** @import { TickContext } from './private.js' */3/** @import { Spring as SpringStore, SpringOptions, SpringUpdateOptions } from './public.js' */4import { writable } from '../store/shared/index.js';5import { loop } from '../internal/client/loop.js';6import { raf } from '../internal/client/timing.js';7import { is_date } from './utils.js';8import { set, state } from '../internal/client/reactivity/sources.js';9import { render_effect } from '../internal/client/reactivity/effects.js';10import { tag } from '../internal/client/dev/tracing.js';11import { get } from '../internal/client/runtime.js';12import { deferred, noop } from '../internal/shared/utils.js';13import { DEV } from 'esm-env';14 15/**16 * @template T17 * @param {TickContext} ctx18 * @param {T} last_value19 * @param {T} current_value20 * @param {T} target_value21 * @returns {T}22 */23function tick_spring(ctx, last_value, current_value, target_value) {24	if (typeof current_value === 'number' || is_date(current_value)) {25		// @ts-ignore26		const delta = target_value - current_value;27		// @ts-ignore28		const velocity = (current_value - last_value) / (ctx.dt || 1 / 60); // guard div by 029		const spring = ctx.opts.stiffness * delta;30		const damper = ctx.opts.damping * velocity;31		const acceleration = (spring - damper) * ctx.inv_mass;32		const d = (velocity + acceleration) * ctx.dt;33		if (Math.abs(d) < ctx.opts.precision && Math.abs(delta) < ctx.opts.precision) {34			return target_value; // settled35		} else {36			ctx.settled = false; // signal loop to keep ticking37			// @ts-ignore38			return is_date(current_value) ? new Date(current_value.getTime() + d) : current_value + d;39		}40	} else if (Array.isArray(current_value)) {41		// @ts-ignore42		return current_value.map((_, i) =>43			// @ts-ignore44			tick_spring(ctx, last_value[i], current_value[i], target_value[i])45		);46	} else if (typeof current_value === 'object') {47		const next_value = {};48		for (const k in current_value) {49			// @ts-ignore50			next_value[k] = tick_spring(ctx, last_value[k], current_value[k], target_value[k]);51		}52		// @ts-ignore53		return next_value;54	} else {55		throw new Error(`Cannot spring ${typeof current_value} values`);56	}57}58 59/**60 * The spring function in Svelte creates a store whose value is animated, with a motion that simulates the behavior of a spring. This means when the value changes, instead of transitioning at a steady rate, it "bounces" like a spring would, depending on the physics parameters provided. This adds a level of realism to the transitions and can enhance the user experience.61 *62 * @deprecated Use [`Spring`](https://svelte.dev/docs/svelte/svelte-motion#Spring) instead63 * @template [T=any]64 * @param {T} [value]65 * @param {SpringOptions} [opts]66 * @returns {SpringStore<T>}67 */68export function spring(value, opts = {}) {69	const store = writable(value);70	const { stiffness = 0.15, damping = 0.8, precision = 0.01 } = opts;71	/** @type {number} */72	let last_time;73	/** @type {Task | null} */74	let task;75	/** @type {object} */76	let current_token;77 78	let last_value = /** @type {T} */ (value);79	let target_value = /** @type {T | undefined} */ (value);80 81	let inv_mass = 1;82	let inv_mass_recovery_rate = 0;83	let cancel_task = false;84	/**85	 * @param {T} new_value86	 * @param {SpringUpdateOptions} opts87	 * @returns {Promise<void>}88	 */89	function set(new_value, opts = {}) {90		target_value = new_value;91		const token = (current_token = {});92		if (value == null || opts.hard || (spring.stiffness >= 1 && spring.damping >= 1)) {93			cancel_task = true; // cancel any running animation94			last_time = raf.now();95			last_value = new_value;96			store.set((value = target_value));97			return Promise.resolve();98		} else if (opts.soft) {99			const rate = opts.soft === true ? 0.5 : +opts.soft;100			inv_mass_recovery_rate = 1 / (rate * 60);101			inv_mass = 0; // infinite mass, unaffected by spring forces102		}103		if (!task) {104			last_time = raf.now();105			cancel_task = false;106			task = loop((now) => {107				if (cancel_task) {108					cancel_task = false;109					task = null;110					return false;111				}112				inv_mass = Math.min(inv_mass + inv_mass_recovery_rate, 1);113 114				// clamp elapsed time to 1/30th of a second, so that longer pauses115				// (blocked thread or inactive tab) don't cause the spring to go haywire116				const elapsed = Math.min(now - last_time, 1000 / 30);117 118				/** @type {TickContext} */119				const ctx = {120					inv_mass,121					opts: spring,122					settled: true,123					dt: (elapsed * 60) / 1000124				};125				// @ts-ignore126				const next_value = tick_spring(ctx, last_value, value, target_value);127				last_time = now;128				last_value = /** @type {T} */ (value);129				store.set((value = /** @type {T} */ (next_value)));130				if (ctx.settled) {131					task = null;132				}133				return !ctx.settled;134			});135		}136		return new Promise((fulfil) => {137			/** @type {Task} */ (task).promise.then(() => {138				if (token === current_token) fulfil();139			});140		});141	}142	/** @type {SpringStore<T>} */143	// @ts-expect-error - class-only properties are missing144	const spring = {145		set,146		update: (fn, opts) => set(fn(/** @type {T} */ (target_value), /** @type {T} */ (value)), opts),147		subscribe: store.subscribe,148		stiffness,149		damping,150		precision151	};152	return spring;153}154 155/**156 * A wrapper for a value that behaves in a spring-like fashion. Changes to `spring.target` will cause `spring.current` to157 * move towards it over time, taking account of the `spring.stiffness` and `spring.damping` parameters.158 *159 * ```svelte160 * <script>161 * 	import { Spring } from 'svelte/motion';162 *163 * 	const spring = new Spring(0);164 * </script>165 *166 * <input type="range" bind:value={spring.target} />167 * <input type="range" bind:value={spring.current} disabled />168 * ```169 * @template T170 * @since 5.8.0171 */172export class Spring {173	#stiffness = state(0.15);174	#damping = state(0.8);175	#precision = state(0.01);176 177	#current;178	#target;179 180	#last_value = /** @type {T} */ (undefined);181	#last_time = 0;182 183	#inverse_mass = 1;184	#momentum = 0;185 186	/** @type {import('../internal/client/types').Task | null} */187	#task = null;188 189	/** @type {ReturnType<typeof deferred> | null} */190	#deferred = null;191 192	/**193	 * @param {T} value194	 * @param {SpringOptions} [options]195	 */196	constructor(value, options = {}) {197		this.#current = DEV ? tag(state(value), 'Spring.current') : state(value);198		this.#target = DEV ? tag(state(value), 'Spring.target') : state(value);199 200		if (typeof options.stiffness === 'number') this.#stiffness.v = clamp(options.stiffness, 0, 1);201		if (typeof options.damping === 'number') this.#damping.v = clamp(options.damping, 0, 1);202		if (typeof options.precision === 'number') this.#precision.v = options.precision;203 204		if (DEV) {205			tag(this.#stiffness, 'Spring.stiffness');206			tag(this.#damping, 'Spring.damping');207			tag(this.#precision, 'Spring.precision');208			tag(this.#current, 'Spring.current');209			tag(this.#target, 'Spring.target');210		}211	}212 213	/**214	 * Create a spring whose value is bound to the return value of `fn`. This must be called215	 * inside an effect root (for example, during component initialisation).216	 *217	 * ```svelte218	 * <script>219	 * 	import { Spring } from 'svelte/motion';220	 *221	 * 	let { number } = $props();222	 *223	 * 	const spring = Spring.of(() => number);224	 * </script>225	 * ```226	 * @template U227	 * @param {() => U} fn228	 * @param {SpringOptions} [options]229	 */230	static of(fn, options) {231		const spring = new Spring(fn(), options);232 233		render_effect(() => {234			spring.set(fn());235		});236 237		return spring;238	}239 240	/** @param {T} value */241	#update(value) {242		set(this.#target, value);243 244		this.#current.v ??= value;245		this.#last_value ??= this.#current.v;246 247		if (!this.#task) {248			this.#last_time = raf.now();249 250			var inv_mass_recovery_rate = 1000 / (this.#momentum * 60);251 252			this.#task ??= loop((now) => {253				this.#inverse_mass = Math.min(this.#inverse_mass + inv_mass_recovery_rate, 1);254 255				// clamp elapsed time to 1/30th of a second, so that longer pauses256				// (blocked thread or inactive tab) don't cause the spring to go haywire257				const elapsed = Math.min(now - this.#last_time, 1000 / 30);258 259				/** @type {import('./private').TickContext} */260				const ctx = {261					inv_mass: this.#inverse_mass,262					opts: {263						stiffness: this.#stiffness.v,264						damping: this.#damping.v,265						precision: this.#precision.v266					},267					settled: true,268					dt: (elapsed * 60) / 1000269				};270 271				var next = tick_spring(ctx, this.#last_value, this.#current.v, this.#target.v);272				this.#last_value = this.#current.v;273				this.#last_time = now;274				set(this.#current, next);275 276				if (ctx.settled) {277					this.#task = null;278				}279 280				return !ctx.settled;281			});282		}283 284		return this.#task.promise;285	}286 287	/**288	 * Sets `spring.target` to `value` and returns a `Promise` that resolves if and when `spring.current` catches up to it.289	 *290	 * If `options.instant` is `true`, `spring.current` immediately matches `spring.target`.291	 *292	 * If `options.preserveMomentum` is provided, the spring will continue on its current trajectory for293	 * the specified number of milliseconds. This is useful for things like 'fling' gestures.294	 *295	 * @param {T} value296	 * @param {SpringUpdateOptions} [options]297	 */298	set(value, options) {299		this.#deferred?.reject(new Error('Aborted'));300 301		if (options?.instant || this.#current.v === undefined) {302			this.#task?.abort();303			this.#task = null;304			set(this.#current, set(this.#target, value));305			this.#last_value = value;306			return Promise.resolve();307		}308 309		if (options?.preserveMomentum) {310			this.#inverse_mass = 0;311			this.#momentum = options.preserveMomentum;312		}313 314		var d = (this.#deferred = deferred());315		d.promise.catch(noop);316 317		this.#update(value).then(() => {318			if (d !== this.#deferred) return;319			d.resolve(undefined);320		});321 322		return d.promise;323	}324 325	get current() {326		return get(this.#current);327	}328 329	get damping() {330		return get(this.#damping);331	}332 333	set damping(v) {334		set(this.#damping, clamp(v, 0, 1));335	}336 337	get precision() {338		return get(this.#precision);339	}340 341	set precision(v) {342		set(this.#precision, v);343	}344 345	get stiffness() {346		return get(this.#stiffness);347	}348 349	set stiffness(v) {350		set(this.#stiffness, clamp(v, 0, 1));351	}352 353	get target() {354		return get(this.#target);355	}356 357	set target(v) {358		this.set(v);359	}360}361 362/**363 * @param {number} n364 * @param {number} min365 * @param {number} max366 */367function clamp(n, min, max) {368	return Math.max(min, Math.min(max, n));369}370 
Brunobkr/llama.cpp_AlgMor24_github · Team Ai