A minimal implementation of NumPy's core functionality for educational purposes and lightweight applications
Project description
MiniNumPy - Simplified Parallel Computing Library
A lightweight numpy-like library focusing on core array operations with threading and multiprocessing support.
Features
- Core Array Class: Basic numpy-like array with indexing, reshaping, and data manipulation
- Arithmetic Operations: Element-wise add, subtract, multiply, divide
- Statistical Functions: Sum, mean, max, min with parallel versions
- Parallel Computing: Threading and multiprocessing support for performance
- Easy to Use: Simple API similar to NumPy
Installation
# Clone or download the project
cd mininumpy/
python demo.py # Run the demo
Quick Start
import mininumpy as mnp
# Create arrays
a = mnp.zeros((1000, 1000))
b = mnp.ones((1000, 1000))
# Basic operations
c = mnp.add(a, b)
total = mnp.sum(c)
# Parallel operations
c_parallel = mnp.add_parallel(a, b, n_threads=4)
total_parallel = mnp.sum_parallel(c, n_threads=4)
Project Structure
mininumpy/
├── core/
│ ├── __init__.py
│ └── array.py # MiniArray class
├── operations/
│ ├── __init__.py
│ ├── arithmetic.py # Basic math operations
│ └── stats.py # Statistical functions
├── parallel/
│ ├── __init__.py
│ └── parallel.py # Threading/multiprocessing
├── tests/
│ └── test_basic.py # Unit tests
├── examples/
│ └── demo.py # Demonstration script
└── README.md
Running Tests
cd tests/
python test_basic.py
Performance
The library shows performance improvements with parallel operations on large arrays:
- Threading: Best for I/O bound and shared memory operations
- Multiprocessing: Best for CPU-intensive computations
See demo.py for detailed benchmarking results.
API Reference
Array Creation
MiniArray(data, shape=None, dtype='float64')- Create array from datazeros(shape)- Create array filled with zerosones(shape)- Create array filled with onesarange(start, stop, step=1)- Create array with range of values
Arithmetic Operations
add(a, b)- Element-wise additionsubtract(a, b)- Element-wise subtractionmultiply(a, b)- Element-wise multiplicationdivide(a, b)- Element-wise divisionadd_parallel(a, b, n_threads=4)- Parallel additionmultiply_parallel(a, b, n_processes=2)- Parallel multiplication
Statistical Operations
sum(array)- Sum all elementsmean(array)- Calculate meanmax(array)- Find maximum valuemin(array)- Find minimum valuesum_parallel(array, n_threads=4)- Parallel summean_parallel(array, n_threads=4)- Parallel mean
Example Usage
# Import the library
import mininumpy as mnp
# Create and manipulate arrays
arr = mnp.MiniArray([1, 2, 3, 4, 5, 6], shape=(2, 3))
print(f"Array shape: {arr.shape}")
print(f"Element at [1,1]: {arr[1, 1]}")
# Reshape operations
reshaped = arr.reshape((3, 2))
flattened = arr.flatten()
# Mathematical operations
a = mnp.ones((1000,))
b = mnp.arange(0, 1000)
result = mnp.add(a, b)
# Statistical analysis
total = mnp.sum(result)
average = mnp.mean(result)
# Parallel computing for large datasets
large_a = mnp.zeros((100000,))
large_b = mnp.ones((100000,))
# Compare performance
import time
# Sequential
start = time.time()
seq_result = mnp.add(large_a, large_b)
seq_time = time.time() - start
# Parallel
start = time.time()
par_result = mnp.add_parallel(large_a, large_b, n_threads=4)
par_time = time.time() - start
print(f"Sequential: {seq_time:.4f}s")
print(f"Parallel: {par_time:.4f}s")
print(f"Speedup: {seq_time/par_time:.2f}x")
Implementation Notes
- Arrays are stored as flat Python lists with shape metadata
- Parallel operations split work across threads/processes
- Thread-based parallelism for shared memory operations
- Process-based parallelism for CPU-intensive tasks
- Error handling for shape mismatches and invalid operations
Limitations
- No broadcasting (arrays must have same shape)
- Limited to basic operations (no advanced linear algebra)
- Python lists instead of optimized C arrays
- No GPU acceleration
Future Extensions
- Matrix multiplication
- Advanced slicing operations
- Broadcasting support
- GPU acceleration with numba
- More statistical functions
- Linear algebra operations
Contributing
This is an educational project. Feel free to extend with additional features:
- Add new mathematical operations
- Implement advanced indexing
- Add more statistical functions
- Optimize performance
- Add GPU support
License
Educational/demonstration purposes. Feel free to modify and extend.
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 Distribution
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 mininumpy-0.1.2.tar.gz.
File metadata
- Download URL: mininumpy-0.1.2.tar.gz
- Upload date:
- Size: 16.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bd887163c8c5d9c78f3de16ff3df97de636686331ff7c5a15af0c4b15e4d1fe3
|
|
| MD5 |
b437fcbb5edc2222e87cad7c22dec278
|
|
| BLAKE2b-256 |
c3ca292b9bd336730180c4de9e4aacbd9d69619cd76c04f1cfd238356eadcd91
|
File details
Details for the file mininumpy-0.1.2-py3-none-any.whl.
File metadata
- Download URL: mininumpy-0.1.2-py3-none-any.whl
- Upload date:
- Size: 18.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c11ce03f9b3b817f49cdd411f111aded5498459807fda88231be5938a2c89c1c
|
|
| MD5 |
fffd5da154bd1d9182b15896059aae7d
|
|
| BLAKE2b-256 |
00104fc4643ce61738fbce09eb465e29529b064007c1ddea59e2974fc8a710bc
|