Agent skill

numpy-memory

Stars 0
Forks 0

Install this agent skill to your Project

npx add-skill https://github.com/cuba6112/skillfactory/tree/main/skills/numpy-memory

SKILL.md

Overview

NumPy memory management revolves around the concept of "strides." Strides define the number of bytes to skip in a flat 1D buffer to move to the next element in an N-dimensional space. Understanding this allows for zero-copy operations like transposition and complex sliding windows.

When to Use

  • Optimizing high-performance code for CPU cache locality.
  • Creating overlapping sliding windows for signal processing without duplicating data.
  • Interfacing with libraries that require specific memory orders (e.g., BLAS/Fortran).
  • Manipulating array logic without incurring the cost of data copying.

Decision Tree

  1. Need to optimize for row-wise processing?
    • Use C-order (row-major). Smallest stride is on the last axis.
  2. Interfacing with legacy Fortran or BLAS?
    • Use Fortran-order (column-major). Smallest stride is on the first axis.
  3. Want to create a sliding window view?
    • Use np.lib.stride_tricks.as_strided. (Use with caution).

Workflows

  1. Analyzing Memory Locality

    • Check arr.strides and arr.itemsize.
    • Identify the axis with the smallest stride (fastest changing in memory).
    • Reorder loops or axes to ensure data access follows the smallest stride for cache efficiency.
  2. Zero-Copy Transposition

    • Call arr.T or arr.transpose().
    • Inspect the strides of the result.
    • Note that the underlying data buffer remains identical; only the stride metadata was swapped.
  3. Creating Sliding Windows without Copies

    • Identify an array segment.
    • Use np.lib.stride_tricks.as_strided with a custom stride tuple to create overlapping windows.
    • Perform vectorized operations on the windowed view (warning: values may overlap).

Non-Obvious Insights

  • Metadata Logic: Changing an array's shape or transposing it often changes only the strides and shape metadata, leaving the data buffer untouched.
  • Cache Performance: Iterating over an axis with a large stride is slow because elements are spaced far apart in memory, causing CPU cache misses.
  • Strides Modification: Directly setting arr.strides is unsafe and discouraged; as_strided is the preferred, safer interface for advanced memory manipulation.

Evidence

  • "The strides of an array tell us how many bytes we have to skip in memory to move to the next position along a certain axis." Source
  • "The shape of the array can be changed very easily without changing anything in the data buffer or any data copying at all." Source

Scripts

  • scripts/numpy-memory_tool.py: Tools for stride analysis and zero-copy window creation.
  • scripts/numpy-memory_tool.js: Simulated byte-offset calculator.

Dependencies

  • numpy (Python)

References

  • references/README.md

Expand your agent's capabilities with these related and highly-rated skills.

cuba6112/skillfactory

prompt-engineering

Comprehensive prompt engineering techniques for Claude models. Use this skill when crafting, optimizing, or debugging prompts for Claude API, Claude Code, or any Claude-powered application. Covers system prompts, role prompting, multishot examples, chain of thought, XML structuring, long context handling, extended thinking, prompt chaining, Claude 4.x-specific best practices, and agentic orchestration including subagents, agent loops, skills, MCP integration, and multi-agent workflows.

0 0
Explore
cuba6112/skillfactory

adk-rag-agent

Build RAG (Retrieval-Augmented Generation) agents with Google ADK and Vertex AI RAG Engine. Use when implementing document Q&A, knowledge base search, or citation-backed responses. Covers VertexAiRagRetrieval tool, corpus setup, and citation formatting.

0 0
Explore
cuba6112/skillfactory

headless-cli-agents

Build agentic systems using Claude CLI in headless mode or the Claude Agent SDK. Use when building automation pipelines, CI/CD integrations, multi-agent orchestration, or programmatic Claude interactions. Covers CLI flags (-p, --output-format), session management (--resume, --continue), Python SDK (claude-agent-sdk), custom tools, and agent loop patterns.

0 0
Explore
cuba6112/skillfactory

notion-knowledge-capture

Capture conversations and decisions into structured Notion pages; use when turning chats/notes into wiki entries, how-tos, decisions, or FAQs with proper linking.

0 0
Explore
cuba6112/skillfactory

mcp-builder

Guide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when building MCP servers to integrate external APIs or services, whether in Python (FastMCP) or Node/TypeScript (MCP SDK).

0 0
Explore
cuba6112/skillfactory

gh-fix-ci

Inspect GitHub PR checks with gh, pull failing GitHub Actions logs, summarize failure context, then create a fix plan and implement after user approval. Use when a user asks to debug or fix failing PR CI/CD checks on GitHub Actions and wants a plan + code changes; for external checks (e.g., Buildkite), only report the details URL and mark them out of scope.

0 0
Explore

Didn't find tool you were looking for?

Be as detailed as possible for better results