Logo vun Numpy Performance

Numpy Performance

Communautéit
0xBakeer
numpy-performance

Making numeric Python fast with NumPy - vectorizing loops, broadcasting, dtypes and memory, avoiding copies, and measuring with timeit before and after.

Iwwersiicht

Editeur0xBakeer
RepositoryTandemLLM
Skill-Nummnumpy-performance
Stären
75
Forks
14
Matgeliwwert Fichieren
Nëmmen Instruktiounen
LizenzAGPL-3.0
Linken
  • Instruktiounen am Markdown-Format

    Eng SKILL.md-Datei, déi de Modell bei Bedarf luet, soudatt nëmmen Token ufalen, wann eng Ufro tatsächlech dozou passt.

  • Funktionéiert mat all LLM

    KI-Skills si reng Markdown, keen ubidderspezifesche Code. Dofir funktionéiert dëse Skill mat GPT, Claude, Gemini, Grok oder engem lokale Modell.

  • Alles an den Instruktiounen

    Alles, wat de Modell brauch, steet an den Instruktiounen — keng zousätzlech Dateien ze synchroniséieren.

  • Open Source

    Vum 0xBakeer op GitHub verëffentlecht. Liest de Quelltext, ier Dir de Skill installéiert.

Installatioun

Installéiert de KI-Skill Numpy Performance an TypingMind, fir e mat all LLM ze benotzen, oder füügt en an en anere KI-Agent an, deen SKILL.md liest.

1

An TypingMind installéieren

TypingMind installéiert e Skill direkt aus sengem GitHub-Dossier — dobäi gëtt SKILL.md gelies, d'Ressourcedateie gi gebëndelt an d'Resultat gëtt lokal gespäichert.

  1. Maacht d'App op a gitt op Plugins → Skills.
  2. Wielt „Vun GitHub installéieren“.
  3. Pecht d'URL vum Skill-Dossier hei drënner an a bestätegt.
    https://github.com/0xBakeer/TandemLLM/tree/main/packages/library/numpy-performance
  4. Aktivéiert de Skill an all Chat, an deem Dir e benotze wëllt.
Plugins → Skills → Skill afügen → Vu GitHub-URL, pecht dann d'URL vum Dossier an a klickt op Weider.
2

An engem anere KI-Agent installéieren

All KI-Agent, deen d'Format Agent Skills liest, kann dëse Skill benotzen — kopéiert den Dossier an de Skill-Verzeechnes vun deem KI-Agent.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/0xBakeer/TandemLLM.git /tmp/TandemLLM
mkdir -p .claude/skills
cp -r /tmp/TandemLLM/packages/library/numpy-performance .claude/skills/numpy-performance
Start Claude Code nom Kopéieren nei, fir datt den neie Skill erkannt gëtt.

An TypingMind benotzen

Aktivéiert Numpy Performance an engem Chat vun TypingMind, an de Modell iwwerhëlt de Rescht. Den Numm an d'Beschreiwung stinn am System-Prompt. Soubal eng Ufro dozou passt, luet de Modell déi komplett Instruktioune selwer — Dir musst de Skill ni manuell opruffen, an et fale keng Token un, bis en tatsächlech benotzt gëtt.

De Modell luet Numpy Performance automatesch, soubal eng Ufro dozou passt.

Funktionéiert mat all KI-Modell

KI-Skills si reng Markdown-Instruktiounen amplaz vun ubidderspezifeschem Code. Dofir ass Numpy Performance net un de Modell gebonnen, fir deen de Skill geschriwwe gouf. Installéiert en eemol an TypingMind a benotzt e mat GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama oder engem lokale Modell, deen Dir selwer bedreift — alles mat Ären eegenen API-Keys.

  • Gëtt nëmme gelueden, wann et néideg ass

    De System-Prompt enthält nëmmen den Numm an d'Beschreiwung. D'Instruktioune gi bei der éischter passender Ufro gelueden, soudatt en onbenotzte Skill näischt kascht.

  • De Modell am lafende Chat wiesselen

    Well de Skill aus Instruktiounen amplaz vu Code besteet, funktionéiert en och no engem Modellwiessel — den nächste Modell liest déi selwecht SKILL.md-Datei.

Skill-Instruktiounen

Dëst ass den Inhalt vu SKILL.md, deen de Modell luet. Liest e virun der Installatioun — e Skill besteet aus Instruktiounen, déi Äre Modell befollegt.

NumPy performance

Rules:

  • Measure first: timeit the slow function on a realistic size (the real N, not 10). Write the number down before changing anything.
  • Replace Python loops over arrays with array expressions: slicing, broadcasting, np.where, np.cumsum, np.einsum, boolean masks.
  • Choose the dtype: float32 halves memory and often doubles speed when 7 digits are enough; int64 for indices and counts. Say which and why.
  • Allocate once outside loops; use out= and in-place operators (a += b) on hot paths.

What goes wrong:

  • np.append in a loop: quadratic. Collect in a list, convert once, or preallocate.
  • Broadcasting an (N,1) against (N,) creates (N,N) by accident; memory explodes. Print shapes.
  • float64 to float32 conversion inside the loop every iteration.

Check: time the old and the new version on the same input, show both numbers and the speedup, and np.allclose(old, new) with the tolerance stated.

Done when:

  • Before and after timings on the real size in the result (ms, and the ratio).
  • np.allclose(old, new, rtol=1e-6) is True (or the differences explained).
  • Peak memory or the array shapes and dtypes printed for the hot arrays.

Reference

Timing:

python
import timeit, numpy as np
x = np.random.default_rng(0).random(1_000_000)
t_old = timeit.timeit(lambda: f_old(x), number=5) / 5
t_new = timeit.timeit(lambda: f_new(x), number=5) / 5
print(f"old {t_old*1e3:.1f} ms  new {t_new*1e3:.1f} ms  x{t_old/t_new:.1f}  close={np.allclose(f_old(x), f_new(x))}")

Loop to vector:

python
# before
out = np.empty(len(x))
for i in range(1, len(x)): out[i] = out[i-1] * 0.9 + x[i]
# after (moving sum, distances, conditionals)
m = np.convolve(x, np.ones(5) / 5, mode="valid")
d = np.sqrt(((p[:, None, :] - q[None, :, :]) ** 2).sum(-1))   # (N, M) distances; watch memory N*M*8 bytes
y = np.where(x > 0.5, x, 0.0)

Preallocate and in-place: acc = np.zeros(n, dtype=np.float32); np.add(acc, x, out=acc). Memory: a.nbytes / 1e6 MB; np.shares_memory(a, b) to check views; np.ascontiguousarray(a) before passing to C code. numba for an unavoidable recurrence:

python
from numba import njit
@njit(cache=True)
def ewma(x, a):
    out = np.empty_like(x); out[0] = x[0]
    for i in range(1, len(x)): out[i] = a * x[i] + (1 - a) * out[i-1]
    return out

Peak memory: /usr/bin/time -l python script.py (macOS) or -v (Linux), read "maximum resident set size".

More rules:

  • Know what copies: fancy indexing and np.concatenate copy; slices and reshape of contiguous arrays do not. Check a.flags["C_CONTIGUOUS"] before a hot loop.
  • Beyond NumPy, in this order: numba for an unavoidable loop, then scipy routines, then a GPU library, each justified by a measured number.

More pitfalls:

  • A "vectorized" version that gives different results from the loop; compare with np.allclose before trusting the speedup.

Heefeg gestallte Froen

Wat mécht de KI-Skill Numpy Performance?

Making numeric Python fast with NumPy - vectorizing loops, broadcasting, dtypes and memory, avoiding copies, and measuring with timeit before and after.

Firwat Numpy Performance op TypingMind benotzen?

Well Dir en eemol installéiert a mat all Modell benotze kënnt. Numpy Performance besteet aus einfachem Markdown amplaz vun ubidderspezifeschem Code. Dee selwechte Skill funktionéiert also mat GPT-5, Claude, Gemini, Grok oder engem lokale Modell – an Dir kënnt de Modell matzen am Chat wiesselen, ouni datt de Skill ophält ze funktionéieren. TypingMind benotzt Är eegen API-Schlësselen, sou datt Dir d'Ubidder direkt bezuelt amplaz vun engem Abonnement pro Benotzerplaz. Är Skills a Chats bleiwen an Ärem eegene Späicher.

Wéi installéieren ech Numpy Performance an TypingMind?

Maacht an TypingMind Plugins → Skills → Vu GitHub installéieren op a setzt https://github.com/0xBakeer/TandemLLM/tree/main/packages/library/numpy-performance an. TypingMind liest d'Datei SKILL.md an installéiert de Skill, deen Dir pro Chat aktivéiere kënnt.

Wéi eng KI-Modeller kënnen Numpy Performance benotzen?

All Modell, deen Dir an TypingMind verbënnt. KI-Skills sinn einfach Markdown-Instruktiounen an net ubidderspezifesche Code. Dofir kënne GPT, Claude, Gemini, Grok a lokal Modeller dëse Skill lueden, wann eng Ufro dozou passt.

Wéi vill KI-Modeller kann ech mat Numpy Performance benotzen?

Esou vill Dir wëllt. Soulaang e Modell Skills ënnerstëtzt, kënnt Dir Numpy Performance domat benotzen – GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama a méi – alles op TypingMind mat Ären eegenen API-Schlësselen.

Ass de KI-Skill Numpy Performance gratis?

Jo. De Skill gëtt vum 0xBakeer ënner der Lizenz AGPL-3.0 op GitHub publizéiert. Dir bezuelt nëmmen Ären eegene KI-Ubidder fir d'Token, déi Dir benotzt.

Wat si KI-Skills?

E KI-Skill ass e weiderverwendbaart Pak vun Instruktiounen, dat engem KI-Modell bäibréngt, wéi en eng bestëmmt Aufgab erfëllt. E follegt dem oppenen Agent Skills-Format: eng Datei SKILL.md mat engem Numm an enger Beschreiwung, plus all Scripten, Virlagen oder Referenzdateien, déi de Modell eventuell brauch. De Modell liest d'Instruktiounen eréischt, wann Är Ufro zum Skill passt. En installéierte Skill kascht also näischt, bis e benotzt gëtt.

Wéi ënnerscheede sech KI-Skills vu Plugins oder MCP-Serveren?

E Plugin oder MCP-Server gëtt engem Modell nei Tools, déi en opruffe kann – Code, deen iergendwou leeft an e Resultat zeréckgëtt. E KI-Skill gëtt dem Modell dogéint Wëssen an eng Virgoensweis: wéi en eng Aufgab ugeet, wéi eng Schrëtt en nokënnt a wéi eng gutt Ausgab ausgesäit. Skills bestinn aus einfachem Markdown, brauche kee Server, keen API-Schlëssel a keng Lafzäitëmfeld a funktionéiere mat all Modell.

All weisen

Elo Ären eegene KI-Workspace ariichten

Abonnéiert Iech op eisen Newsletter, fir iwwer nei Funktiounen an zukünfteg Gewënnspiller informéiert ze ginn 👇