Contributing
We welcome contributions! This guide will help you get started.
Development Setup
Clone the repository:
git clone <repository-url> cd kmeans
Install in development mode:
pip install -e ".[dev]"
Run tests:
pytest tests/
Code Style
Python
Follow PEP 8 guidelines. Use type hints where appropriate.
C Code
The C code uses a custom clang-format style. Format code with:
clang-format -i src/kmeans/_kmeans.c
Key style points:
2-space indentation
Braces on new lines for functions
100 character line limit
Pointer alignment to the right:
double *ptr
Testing
Write tests for new features:
# tests/test_new_feature.py
import pytest
from kmeans import KMeans
def test_new_feature():
model = KMeans(n_clusters=3)
# ... test code ...
assert model.centroids_ is not None
Run tests with coverage:
pytest --cov=kmeans tests/
Documentation
Update documentation for new features:
Add docstrings to Python code (NumPy style)
Add usage examples to
docs/examples.rstUpdate API reference if needed
Build documentation locally:
cd docs
make html
# Open _build/html/index.html
Pull Request Process
Create a feature branch
Make your changes
Add tests
Update documentation
Ensure all tests pass
Submit pull request
Commit Messages
Use clear, descriptive commit messages:
Add support for weighted k-means
- Implement sample weights in C core
- Add weight parameter to Python API
- Add tests for weighted clustering
Reporting Issues
When reporting bugs, include:
Python version
NumPy version
Operating system
Minimal code to reproduce
Error messages and stack traces
Feature Requests
For feature requests, describe:
Use case and motivation
Proposed API
Example usage
Any related work or references