Skip to main content

High-performance numpy.loadtxt replacement using mmap + OpenMP + fast_float

Project description

fast_loadtxt

A high-performance drop-in replacement for numpy.loadtxt, built with mmap + OpenMP + fast_float.

Designed for scientific computing workflows where loading large text data files is a bottleneck — simulation outputs, observational datasets, parameter chains, etc.

Why?

numpy.loadtxt reads the entire file into memory, parses it single-threaded, and creates intermediate Python objects. For large files this is slow and memory-hungry.

fast_loadtxt takes a different approach:

numpy.loadtxt fast_loadtxt
File access read() into heap buffer mmap (zero-copy, OS-managed)
Parsing Single-threaded, strtod OpenMP parallel, fast_float
Intermediate allocs Many (Python objects, lists) One (the output array)
Memory overhead ~3× file size ~8 bytes per row (line offsets)

Architecture

Pass 1 (serial):   mmap file → scan bytes for '\n' → build line offset table
                    Detect column count from first data line
                    Allocate numpy array (nrows × ncols)

Pass 2 (parallel): OpenMP threads parse chunks of rows
                    Each thread reads mmap'd bytes → fast_float → writes into numpy buffer
                    Zero intermediate allocations

Cleanup:           munmap (OS reclaims pages), free offset table
                    Only the numpy array survives

Installation

Requirements: C++17 compiler with OpenMP support, Python ≥ 3.8, NumPy.

pip install .

Or for development:

pip install -e .

Usage

import fast_loadtxt as fl

# Basic — just like numpy.loadtxt
data = fl.loadtxt("simulation_output.dat")

# CSV with header
data = fl.loadtxt("results.csv", skip_rows=1)

# Tune for your hardware
data = fl.loadtxt("huge_file.dat", chunk_size=2000, num_threads=8)

Parameters

  • filepath — Path to the data file (space/tab/comma delimited)
  • comment — Comment character, default '#'
  • skip_rows — Header rows to skip (after comments), default 0
  • chunk_size — Rows per OpenMP chunk, default 500
  • num_threads — Thread count, default 0 (auto)

Benchmarks

Run the benchmark suite:

python benchmarks/bench.py

How It Works (for contributors)

The code is split into four small, focused files:

  1. file_mapper.h — POSIX mmap wrapper. Maps the file read-only, calls madvise for kernel readahead hints. RAII cleanup.

  2. line_scanner.h — Sequential byte scan. Counts data rows, detects columns, builds a vector<size_t> of byte offsets for each data line. This is the only heap allocation beyond the output array.

  3. chunk_parser.h — OpenMP parallel loop. Each thread gets a range of row indices, looks up their byte offsets, parses with fast_float, writes directly into the pre-allocated numpy buffer. Zero allocations in the hot loop.

  4. fast_loadtxt.cpp — pybind11 glue. Calls the above three in sequence, returns the numpy array.

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fast_loadtxt-0.1.0.tar.gz (57.3 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

fast_loadtxt-0.1.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (187.8 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

fast_loadtxt-0.1.0-cp313-cp313-macosx_11_0_arm64.whl (82.0 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

fast_loadtxt-0.1.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (187.9 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

fast_loadtxt-0.1.0-cp312-cp312-macosx_11_0_arm64.whl (82.0 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

fast_loadtxt-0.1.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (188.1 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

fast_loadtxt-0.1.0-cp311-cp311-macosx_11_0_arm64.whl (80.6 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

fast_loadtxt-0.1.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (186.4 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

fast_loadtxt-0.1.0-cp310-cp310-macosx_11_0_arm64.whl (79.2 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

fast_loadtxt-0.1.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (186.6 kB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

fast_loadtxt-0.1.0-cp39-cp39-macosx_11_0_arm64.whl (79.3 kB view details)

Uploaded CPython 3.9macOS 11.0+ ARM64

File details

Details for the file fast_loadtxt-0.1.0.tar.gz.

File metadata

  • Download URL: fast_loadtxt-0.1.0.tar.gz
  • Upload date:
  • Size: 57.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for fast_loadtxt-0.1.0.tar.gz
Algorithm Hash digest
SHA256 080ebd2600ef41e87397ea5c87c66a231de3af25a730558a2c59e0dbb3592d7a
MD5 89ce36a854bd8973710c3bb5cbdff5e0
BLAKE2b-256 b6cf18946bf8dcb655b4696ccc1e1c69e795974c69756165652ff00e78abc2b3

See more details on using hashes here.

File details

Details for the file fast_loadtxt-0.1.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for fast_loadtxt-0.1.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 0b23cac33821c4c938aa50844f9eeb1ac430dd69c6d420276abb2c92b67f8b4b
MD5 15488fec80fdc37e08178ee9a813b211
BLAKE2b-256 3dfcfbbf3ff6878856b959fd82276b0cb5bd0ebc2cdf6d8cd35fe48cbdbed25c

See more details on using hashes here.

File details

Details for the file fast_loadtxt-0.1.0-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for fast_loadtxt-0.1.0-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 66198eec0412d0c2e2b2cc5421949882e6539211aaa8e7a69aeb137e31fe4d43
MD5 0f45236d9e6072d56f6f7043377bd2b7
BLAKE2b-256 804db32fad291e89133789b533717332d3f33ae4da6c25b6ecafff93ddffe0e7

See more details on using hashes here.

File details

Details for the file fast_loadtxt-0.1.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for fast_loadtxt-0.1.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 1f06ba099687e929ed6d7b2eb08fc2a5d4f6078ee8d3ee581ecedd3c87dc61e4
MD5 ae8c6b9578949ce33bb24d5b80339595
BLAKE2b-256 71aed45d2ab3b7e7e83f9a715bab1d36711b9f2ea4a6f918757463f98c9789f5

See more details on using hashes here.

File details

Details for the file fast_loadtxt-0.1.0-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for fast_loadtxt-0.1.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 753a8a2d5daec43858acddb4cfb397497cb099f187984b8a224e3da1c705420d
MD5 c00b7d8638cc6024f1a3afcf70e9dd5d
BLAKE2b-256 91e53d9ba334e83135b21a82b7c72cce2763c5f90c218883bf2d45eaed96063e

See more details on using hashes here.

File details

Details for the file fast_loadtxt-0.1.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for fast_loadtxt-0.1.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 c5c8fbd17d9978cd45c3c30f1f252fbdb5d22e08daf2445545c3337f5fdcfa50
MD5 5e06236dff49fd235d99312be16fa6ec
BLAKE2b-256 b959cadb0d3bf8a424323c10d2d53f39ba592afa63392b6f7db62c74fbfeab86

See more details on using hashes here.

File details

Details for the file fast_loadtxt-0.1.0-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for fast_loadtxt-0.1.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 4936413eeece0531a63bf08ac1fcea159f79d5cb4e0dc9b6a795571a64b173df
MD5 ef923d86b27be9030324152cf9abd85d
BLAKE2b-256 1d055bf00d1b0789f8315f5cfa7b9ce22d1213035a2a9c115ba2045c77860ccf

See more details on using hashes here.

File details

Details for the file fast_loadtxt-0.1.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for fast_loadtxt-0.1.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a6810c7a85a9149d13c973213b794fc6a4e0ba92cfb6a1dbc6f27057c2eb861b
MD5 3d61de752f2184ed76dcd3e73778c596
BLAKE2b-256 c4df923d3fc6f810f33ada44c9c518dfc0f4b4a9ffe567f3d5bb53c7538bb930

See more details on using hashes here.

File details

Details for the file fast_loadtxt-0.1.0-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for fast_loadtxt-0.1.0-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 52fff61e2945e0b9dcba896123476128e223d52b577a2163df2188088787a879
MD5 828d7090e75bf1c93e9f7828b88ace51
BLAKE2b-256 7a01ed6e59b86066db06773797b806f1fcac9dee9267b6018ba1d1c1c15ff5a2

See more details on using hashes here.

File details

Details for the file fast_loadtxt-0.1.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for fast_loadtxt-0.1.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 ce9fdcf6dec4c45945636fecbd6c0ffd636399e2882b9ae0fbc0eb37fbda4dd9
MD5 e33299bb167dc553758ef60bd3a60bd5
BLAKE2b-256 d5664c1076ee745d5b7913b5a39fa0be508df173bd597733b75276a179333674

See more details on using hashes here.

File details

Details for the file fast_loadtxt-0.1.0-cp39-cp39-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for fast_loadtxt-0.1.0-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 9bf1906d11f51703225d869db3465794463bda089e0a0a941e91158777a694f4
MD5 6fb67d1400c179dc33f0ded977724709
BLAKE2b-256 3f02a1f7799a5e1c83e9b15f0cb97e9f23e877538934f60fd197fbd183bb4523

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page