Skip to content

Commit a85f51f

Browse files
atkshclaude
andauthored
docs: Fix README and CONTRIBUTING inconsistencies with implementation (#56)
* docs: Fix README and CONTRIBUTING inconsistencies with implementation - Update README.md API Reference to match actual implementation - Add detailed parameter descriptions for all methods - Include missing getter methods for precision control - Fix insert() signature to show optional parameters - Add len() and n property documentation - Remove "(2D only)" from varargs query (works for 3D/4D too) - Add return type annotations for clarity - Update CONTRIBUTING.md project structure - Update file paths to reflect current project layout - Change cpp/ to include/prtree/core/ and src/cpp/bindings/ - Update Python wrapper path from __init__.py to core.py - Add pyproject.toml to project structure - Update test directory structure (unit/integration/e2e) All examples verified to work correctly with current implementation. * docs: Comprehensive documentation update with detailed docstrings Major improvements: 1. **README.md**: - Clarified Thread Safety section with detailed explanations - Distinguished between read and write operations - Added concrete examples of thread-safe usage patterns - Explained when external synchronization is needed 2. **src/python_prtree/core.py**: - Added comprehensive docstrings to all classes and methods - Included detailed Args, Returns, Raises, Examples sections - Added performance complexity analysis - Documented thread safety for each method - Added See Also cross-references - Explained precision selection behavior - Provided extensive usage examples for each method 3. **docs/README.md** (new): - Created documentation directory guide - Explained purpose of each subdirectory - Added navigation guide for users and developers Documentation now follows NumPy/Google docstring style with: - Complete parameter descriptions with types - Return value specifications - Exception documentation - Performance characteristics - Thread safety notes - Practical examples for all methods - Cross-references between related methods All README examples verified to work correctly with implementation. * docs: Fix documentation inconsistencies across all files Thoroughly verified all documentation against actual implementation and fixed the following inconsistencies: **README.md:** - Removed precision control methods (set/get_adaptive_epsilon, etc.) that are not exposed in the Python API. These methods exist in C++ bindings but are not accessible to users through the Python wrapper. **docs/DEVELOPMENT.md:** - Removed reference to non-existent benchmarks/python/ directory - Removed tests/legacy/ from test organization section (internal only) - Fixed cross-reference paths to use ../ prefix (CONTRIBUTING.md, README.md, CHANGES.md) since DEVELOPMENT.md is in docs/ subdirectory **docs/ARCHITECTURE.md:** - Removed benchmarks/python/README.md from directory structure - Added tests/legacy/ directory to test suite structure **Makefile:** - Fixed CPP_DIR variable from 'cpp' to 'src/cpp' to match actual directory structure All changes verified with tests - README examples still pass. --------- Co-authored-by: Claude <[email protected]>
1 parent 2c6288d commit a85f51f

File tree

7 files changed

+765
-121
lines changed

7 files changed

+765
-121
lines changed

CONTRIBUTING.md

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,10 @@ make quick # Quick test (clean + build + test)
103103
```
104104

105105
3. **Make changes**
106-
- C++ code: `cpp/prtree.h`, `cpp/main.cc`
107-
- Python wrapper: `src/python_prtree/__init__.py`
108-
- Tests: `tests/test_PRTree.py`
106+
- C++ core: `include/prtree/core/prtree.h`
107+
- Python bindings: `src/cpp/bindings/python_bindings.cc`
108+
- Python wrapper: `src/python_prtree/core.py`
109+
- Tests: `tests/unit/`, `tests/integration/`, `tests/e2e/`
109110

110111
4. **Build and test**
111112
```bash
@@ -144,7 +145,7 @@ make quick # Quick test (clean + build + test)
144145

145146
3. **Implement feature**
146147
```cpp
147-
// cpp/prtree.h
148+
// include/prtree/core/prtree.h
148149
// Add implementation
149150
```
150151

@@ -205,20 +206,30 @@ make test-coverage
205206

206207
```
207208
python_prtree/
208-
├── cpp/ # C++ implementation
209-
│ ├── prtree.h # PRTree core implementation
210-
│ ├── main.cc # Python bindings
211-
│ ├── parallel.h # Parallel processing utilities
212-
│ └── small_vector.h # Optimized vector
213-
├── src/python_prtree/ # Python wrapper
214-
│ └── __init__.py
209+
├── include/ # C++ public headers
210+
│ └── prtree/
211+
│ ├── core/ # Core algorithm headers
212+
│ │ └── prtree.h # PRTree core implementation
213+
│ └── utils/ # Utility headers
214+
│ ├── parallel.h # Parallel processing utilities
215+
│ └── small_vector.h # Optimized vector
216+
├── src/
217+
│ ├── cpp/ # C++ implementation
218+
│ │ └── bindings/ # Python bindings
219+
│ │ └── python_bindings.cc
220+
│ └── python_prtree/ # Python wrapper
221+
│ ├── __init__.py # Package entry point
222+
│ └── core.py # Main user-facing classes
215223
├── tests/ # Test suite
216-
│ └── test_PRTree.py
224+
│ ├── unit/ # Unit tests
225+
│ ├── integration/ # Integration tests
226+
│ └── e2e/ # End-to-end tests
217227
├── third/ # Third-party libraries (submodules)
218228
│ ├── pybind11/
219229
│ └── snappy/
220230
├── CMakeLists.txt # CMake configuration
221-
├── setup.py # Packaging configuration
231+
├── pyproject.toml # Project metadata and dependencies
232+
├── setup.py # Build configuration
222233
├── Makefile # Development workflow
223234
└── README.md # User documentation
224235
```

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ PIP := $(PYTHON) -m pip
1717

1818
# Project directories
1919
SRC_DIR := src/python_prtree
20-
CPP_DIR := cpp
20+
CPP_DIR := src/cpp
2121
TEST_DIR := tests
2222
BUILD_DIR := build
2323
DIST_DIR := dist

README.md

Lines changed: 87 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ tree4d = PRTree4D(indices, boxes_4d) # 4D boxes
6767
```python
6868
# Query with point coordinates
6969
result = tree.query([0.5, 0.5]) # Returns indices
70-
result = tree.query(0.5, 0.5) # Varargs also supported (2D only)
70+
result = tree.query(0.5, 0.5) # Varargs also supported
7171
```
7272

7373
### Dynamic Updates
@@ -178,24 +178,38 @@ The library supports native float32 and float64 precision with automatic selecti
178178
- **Auto-detection**: Precision automatically selected based on numpy array dtype
179179
- **Save/Load**: Precision automatically detected when loading from file
180180

181-
Advanced precision control available:
182-
```python
183-
# Configure precision parameters for challenging cases
184-
tree = PRTree2D(indices, boxes)
185-
tree.set_adaptive_epsilon(True) # Adaptive epsilon based on box sizes
186-
tree.set_relative_epsilon(1e-6) # Relative epsilon for intersection tests
187-
tree.set_absolute_epsilon(1e-12) # Absolute epsilon for near-zero cases
188-
tree.set_subnormal_detection(True) # Handle subnormal numbers correctly
189-
```
190-
191181
The new architecture eliminates the previous float32 tree + refinement approach,
192182
providing true native precision at each level for better performance and accuracy.
193183

194184
### Thread Safety
195185

196-
- Query operations are thread-safe
197-
- Insert/erase operations are NOT thread-safe
198-
- Use external synchronization for concurrent updates
186+
**Read Operations (Thread-Safe):**
187+
- `query()` and `batch_query()` are thread-safe when used concurrently from multiple threads
188+
- Multiple threads can safely perform read operations simultaneously
189+
- No external synchronization needed for concurrent queries
190+
191+
**Write Operations (Require Synchronization):**
192+
- `insert()`, `erase()`, and `rebuild()` modify the tree structure
193+
- These operations use internal mutex locks for atomicity
194+
- **Important**: Do NOT perform write operations concurrently with read operations
195+
- Use external synchronization (locks) to prevent concurrent reads and writes
196+
197+
**Recommended Pattern:**
198+
```python
199+
import threading
200+
201+
tree = PRTree2D([1, 2], [[0, 0, 1, 1], [2, 2, 3, 3]])
202+
lock = threading.Lock()
203+
204+
# Multiple threads can query safely without locks
205+
def query_worker():
206+
result = tree.query([0.5, 0.5, 1.5, 1.5]) # Safe without lock
207+
208+
# Write operations need external synchronization
209+
def insert_worker(idx, box):
210+
with lock: # Protect against concurrent reads/writes
211+
tree.insert(idx, box)
212+
```
199213

200214
## Installation from Source
201215

@@ -216,22 +230,68 @@ For detailed development setup, see [DEVELOPMENT.md](docs/DEVELOPMENT.md).
216230

217231
#### Constructor
218232
```python
219-
PRTree2D(indices=None, boxes=None)
220-
PRTree2D(filename) # Load from file
233+
PRTree2D() # Empty tree
234+
PRTree2D(indices, boxes) # With data
235+
PRTree2D(filename) # Load from file
221236
```
222237

238+
**Parameters:**
239+
- `indices` (optional): Array of integer indices for each bounding box
240+
- `boxes` (optional): Array of bounding boxes (shape: [n, 2*D] where D is dimension)
241+
- `filename` (optional): Path to saved tree file
242+
223243
#### Methods
224-
- `query(box, return_obj=False)` - Find overlapping boxes
225-
- `batch_query(boxes)` - Parallel batch queries
226-
- `query_intersections()` - Find all intersecting pairs
227-
- `insert(idx, bb, obj=None)` - Add box
228-
- `erase(idx)` - Remove box
229-
- `rebuild()` - Rebuild tree for optimal performance
230-
- `save(filename)` - Save to binary file
231-
- `load(filename)` - Load from binary file
232-
- `size()` - Get number of boxes
233-
- `get_obj(idx)` - Get stored object
234-
- `set_obj(idx, obj)` - Update stored object
244+
245+
**Query Methods:**
246+
- `query(*args, return_obj=False)``List[int]` or `List[Any]`
247+
- Find all bounding boxes that overlap with the query box or point
248+
- Accepts box coordinates as list/array or varargs (e.g., `query(x, y)` for 2D points)
249+
- Set `return_obj=True` to return associated objects instead of indices
250+
251+
- `batch_query(boxes)``List[List[int]]`
252+
- Parallel batch queries for multiple query boxes
253+
- Returns a list of result lists, one per query
254+
255+
- `query_intersections()``np.ndarray`
256+
- Find all pairs of intersecting bounding boxes
257+
- Returns array of shape (n_pairs, 2) containing index pairs
258+
259+
**Modification Methods:**
260+
- `insert(idx=None, bb=None, obj=None)``None`
261+
- Add a new bounding box to the tree
262+
- `idx`: Index for the box (auto-assigned if None)
263+
- `bb`: Bounding box coordinates (required)
264+
- `obj`: Optional Python object to associate with the box
265+
266+
- `erase(idx)``None`
267+
- Remove a bounding box by index
268+
269+
- `rebuild()``None`
270+
- Rebuild tree for optimal performance after many updates
271+
272+
**Persistence Methods:**
273+
- `save(filename)``None`
274+
- Save tree to binary file
275+
276+
- `load(filename)``None`
277+
- Load tree from binary file
278+
279+
**Object Storage Methods:**
280+
- `get_obj(idx)``Any`
281+
- Retrieve the Python object associated with a bounding box
282+
283+
- `set_obj(idx, obj)``None`
284+
- Update the Python object associated with a bounding box
285+
286+
**Size and Properties:**
287+
- `size()``int`
288+
- Get the number of bounding boxes in the tree
289+
290+
- `len(tree)``int`
291+
- Same as `size()`, allows using `len(tree)`
292+
293+
- `n``int` (property)
294+
- Get the number of bounding boxes (same as `size()`)
235295

236296
## Version History
237297

docs/ARCHITECTURE.md

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,15 @@ python_prtree/
4747
│ ├── e2e/ # End-to-end tests
4848
│ │ ├── test_readme_examples.py
4949
│ │ └── test_user_workflows.py
50+
│ ├── legacy/ # Legacy test suite
5051
│ └── conftest.py # Shared test fixtures
5152
5253
├── benchmarks/ # Performance Benchmarks
53-
│ ├── cpp/ # C++ benchmarks
54-
│ │ ├── benchmark_construction.cpp
55-
│ │ ├── benchmark_query.cpp
56-
│ │ ├── benchmark_parallel.cpp
57-
│ │ └── stress_test_concurrent.cpp
58-
│ └── python/ # Python benchmarks (future)
59-
│ └── README.md
54+
│ └── cpp/ # C++ benchmarks
55+
│ ├── benchmark_construction.cpp
56+
│ ├── benchmark_query.cpp
57+
│ ├── benchmark_parallel.cpp
58+
│ └── stress_test_concurrent.cpp
6059
6160
├── docs/ # Documentation
6261
│ ├── examples/ # Example notebooks and scripts

docs/DEVELOPMENT.md

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ python_prtree/
1919
│ ├── integration/ # Integration tests
2020
│ └── e2e/ # End-to-end tests
2121
├── benchmarks/ # Performance benchmarks
22-
│ ├── cpp/ # C++ benchmarks
23-
│ └── python/ # Python benchmarks
22+
│ └── cpp/ # C++ benchmarks
2423
├── docs/ # Documentation
2524
│ ├── examples/ # Example code
2625
│ ├── images/ # Images
@@ -198,7 +197,6 @@ All project metadata and dependencies are defined in `pyproject.toml`:
198197
- `tests/unit/`: Unit tests for individual components
199198
- `tests/integration/`: Tests for component interactions
200199
- `tests/e2e/`: End-to-end workflow tests
201-
- `tests/legacy/`: Legacy test suite
202200

203201
### Writing Tests
204202

@@ -343,9 +341,9 @@ pip install -e .
343341

344342
## Additional Resources
345343

346-
- [CONTRIBUTING.md](CONTRIBUTING.md) - Contribution guidelines
347-
- [README.md](README.md) - Project overview
348-
- [CHANGES.md](CHANGES.md) - Version history
344+
- [CONTRIBUTING.md](../CONTRIBUTING.md) - Contribution guidelines
345+
- [README.md](../README.md) - Project overview
346+
- [CHANGES.md](../CHANGES.md) - Version history
349347
- [GitHub Issues](https://github.com/atksh/python_prtree/issues) - Bug reports and feature requests
350348

351349
## Questions?
@@ -354,6 +352,6 @@ If you have questions or need help, please:
354352

355353
1. Check existing [GitHub Issues](https://github.com/atksh/python_prtree/issues)
356354
2. Open a new issue with your question
357-
3. See [CONTRIBUTING.md](CONTRIBUTING.md) for more details
355+
3. See [CONTRIBUTING.md](../CONTRIBUTING.md) for more details
358356

359357
Happy coding! 🎉

docs/README.md

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# Documentation Directory
2+
3+
This directory contains comprehensive documentation for python_prtree developers and contributors.
4+
5+
## Contents
6+
7+
### Core Documentation
8+
9+
- **[ARCHITECTURE.md](ARCHITECTURE.md)** - Project architecture and design decisions
10+
- Directory structure and separation of concerns
11+
- Data flow diagrams
12+
- Build system overview
13+
- Native precision support architecture
14+
15+
- **[DEVELOPMENT.md](DEVELOPMENT.md)** - Development environment setup
16+
- Prerequisites and installation
17+
- Build instructions
18+
- Testing and code quality tools
19+
- Troubleshooting guide
20+
21+
- **[MIGRATION.md](MIGRATION.md)** - Migration guides between versions
22+
- v0.7.0 project restructuring guide
23+
- Breaking changes and migration steps
24+
- Planned future migrations
25+
26+
### Supplementary Resources
27+
28+
- **baseline/** - Performance baseline measurements
29+
- System information
30+
- Benchmark results and analysis
31+
- Used for regression testing and performance comparison
32+
33+
- **examples/** - Example notebooks and scripts
34+
- Experimental notebooks for exploring the API
35+
- Usage demonstrations
36+
- Prototyping and development examples
37+
38+
- **images/** - Documentation images
39+
- Benchmark graphs used in README
40+
- Performance comparison charts
41+
- Referenced by main documentation
42+
43+
## For Users
44+
45+
If you're a user looking for usage documentation, see:
46+
- [README.md](../README.md) - Main user documentation with examples
47+
- [CONTRIBUTING.md](../CONTRIBUTING.md) - How to contribute to the project
48+
- [CHANGES.md](../CHANGES.md) - Version history and changelog
49+
50+
## For Developers
51+
52+
Start with these files in order:
53+
1. [README.md](../README.md) - Understand what the library does
54+
2. [DEVELOPMENT.md](DEVELOPMENT.md) - Set up your development environment
55+
3. [ARCHITECTURE.md](ARCHITECTURE.md) - Understand the codebase structure
56+
4. [CONTRIBUTING.md](../CONTRIBUTING.md) - Learn the contribution workflow
57+
58+
## Keeping Documentation Updated
59+
60+
When making changes:
61+
- Update ARCHITECTURE.md if you change the project structure
62+
- Update DEVELOPMENT.md if you change build/test processes
63+
- Update MIGRATION.md when introducing breaking changes
64+
- Regenerate benchmarks if performance characteristics change

0 commit comments

Comments
 (0)