C-based functional programming library with __ syntax for Python
Project description
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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file underscorec-0.1.0.tar.gz.
File metadata
- Download URL: underscorec-0.1.0.tar.gz
- Upload date:
- Size: 34.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.19
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d24924644f426669ac758be38adbd641f23f54727c5d56e83d03597918d46b22
|
|
| MD5 |
00a0cd270ae87d6592b776edfbc91a90
|
|
| BLAKE2b-256 |
46d49f545384af67e5307b83372c13c4f552813dbb9649b82537101df2e78a95
|
File details
Details for the file underscorec-0.1.0-cp310-cp310-macosx_15_0_arm64.whl.
File metadata
- Download URL: underscorec-0.1.0-cp310-cp310-macosx_15_0_arm64.whl
- Upload date:
- Size: 73.5 kB
- Tags: CPython 3.10, macOS 15.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.19
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e7b0de798f61d6415ef1b973c9aa2fce1f22566e8d34869095d771085994d811
|
|
| MD5 |
8ec0e82557dad3e13c1ac7efa7db9be6
|
|
| BLAKE2b-256 |
00b5c05a9b9ee206df6112f7450d1d99a0fe2691491bfa936bb09bd5a17887ee
|
File details
Details for the file underscorec-0.1.0-cp310-cp310-macosx_11_0_arm64.whl.
File metadata
- Download URL: underscorec-0.1.0-cp310-cp310-macosx_11_0_arm64.whl
- Upload date:
- Size: 75.1 kB
- Tags: CPython 3.10, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.19
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8eb3f6f9aa846efbd86e9d5f99343149ad4341dd5a05789683f56079266caddf
|
|
| MD5 |
1c7625262cdc842d852c9e266249f460
|
|
| BLAKE2b-256 |
8f9db771fe77084910ae09bfd01042ecc34d069e56ca0987643fb1d4b191ee23
|