UnderscoreC
A C-based library focused on functional programming and mathematical computation, providing __ (underscore) placeholder syntax for Python. Currently integrated with lower-level NumPy/PyTorch C/C++ extensions for optimized performance.
Examples
Mathematical Computing
from underscorec import __
import numpy as np
import torch
arr = np.array([1, 2, 3, 4, 5])
# Create reusable mathematical expressions
normalize = (__ - __.mean()) / __.std()
result = normalize(arr) # Normalized array
# Simple transformations
mul_add = __ * 2 + 1
result = mul_add(arr)
# PyTorch integration
tensor = torch.tensor([1., 2., 3., 4., 5.])
tensor.apply_(__ * 2 + 1)
Method Calls and Attribute Access
# String processing
process_text = __.strip().lower()
clean = process_text(" Hello World ") # "hello world"
# Attribute access
numel_2d = __.shape >> __[0] * __[1]
numel_2d(matrix)
Composition
# Chain operations using >> operator
data = [1, 2, 3, 4, 5]
pipeline = (__ * 2) >> (__ - 5) >> abs
result = map(pipeline, data) # Apply transformations in sequence
# Compose with built-in functions
text_processor = __.strip() >> __.split(',') >> len
length = text_processor(" Hello, World! ") # 2
Why use it
Good for:
- Functional programming patterns
- Mathematical expressions in scientific computing
Performance:
- Lightweight wrapper that delivers similar performance to common operations
- May be fractionally slower for simple native Python operations
Contributing
Development Setup
UnderscoreC uses uv for dependency management and development workflows.
# Clone the repository
git clone https://github.com/yourusername/underscorec
cd underscorec
# Install dependencies
uv sync
# Build the C extension for development
uv run python setup.py build_ext --inplace
# Verify installation works
uv run python -c "from underscorec import __; print('Setup successful!')"
Running Tests
# Run all tests
uv run pytest
# Run specific test modules
uv run pytest tests/test_core_operations.py
# Run with coverage report
uv run pytest --cov-report=html
Running Performance Benchmark
# Run performance benchmarks
uv run python benchmarks/run_modular_benchmarks.py
Building and Publishing
# Build source distribution and wheel
uv build
# The built packages will be in dist/
# - underscorec-0.1.0.tar.gz (source distribution)
# - underscorec-0.1.0-cp310-cp310-macosx_15_0_arm64.whl (binary wheel)
# Publish to PyPI (requires PyPI credentials)
uv publish
# Or publish to Test PyPI first
uv publish --repository testpypi
Note: The MANIFEST.in file ensures that C++ header files are included in the source distribution for proper building on different platforms.
Future Improvements
This project is experimental and under development. More functionalities and performance improvements will be added as needed, including:
- Expression compilation for better performance
- Enhanced functional programming features
- Broader ecosystem integrations
Metadata
Release files for underscorec 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| underscorec-0.1.0.tar.gz | 34.3 kB | Details |
Built distributions (wheels)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| underscorec-0.1.0-cp310-cp310-macosx_15_0_arm64.whl | CPython 3.10 | CPython 3.10 | macOS 15.0+ ARM64 | Details |
| underscorec-0.1.0-cp310-cp310-macosx_11_0_arm64.whl | CPython 3.10 | CPython 3.10 | macOS 11.0+ ARM64 | Details |
Total release size: 182.9 kB
Release files / underscorec-0.1.0.tar.gz
| Download URL | underscorec-0.1.0.tar.gz |
|---|---|
| Size | 34.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d24924644f426669ac758be38adbd641f23f54727c5d56e83d03597918d46b22
|
|
BLAKE2b-256 checksum How to use checksums |
46d49f545384af67e5307b83372c13c4f552813dbb9649b82537101df2e78a95
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.7.19
|
Release files / underscorec-0.1.0-cp310-cp310-macosx_15_0_arm64.whl
| Download URL | underscorec-0.1.0-cp310-cp310-macosx_15_0_arm64.whl |
|---|---|
| Size | 73.5 kB |
| Tags | CPython 3.10 macOS 15.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
e7b0de798f61d6415ef1b973c9aa2fce1f22566e8d34869095d771085994d811
|
|
BLAKE2b-256 checksum How to use checksums |
00b5c05a9b9ee206df6112f7450d1d99a0fe2691491bfa936bb09bd5a17887ee
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.7.19
|
Release files / underscorec-0.1.0-cp310-cp310-macosx_11_0_arm64.whl
| Download URL | underscorec-0.1.0-cp310-cp310-macosx_11_0_arm64.whl |
|---|---|
| Size | 75.1 kB |
| Tags | CPython 3.10 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
8eb3f6f9aa846efbd86e9d5f99343149ad4341dd5a05789683f56079266caddf
|
|
BLAKE2b-256 checksum How to use checksums |
8f9db771fe77084910ae09bfd01042ecc34d069e56ca0987643fb1d4b191ee23
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.7.19
|