|
| 1 | +# Contributing to node-accelerate |
| 2 | + |
| 3 | +Thank you for your interest in contributing! This document provides guidelines for contributing to node-accelerate. |
| 4 | + |
| 5 | +## Development Setup |
| 6 | + |
| 7 | +### Prerequisites |
| 8 | + |
| 9 | +- macOS (Apple Silicon or Intel) |
| 10 | +- Node.js >= 18.0.0 |
| 11 | +- Xcode Command Line Tools |
| 12 | +- Git |
| 13 | + |
| 14 | +### Getting Started |
| 15 | + |
| 16 | +1. Fork the repository |
| 17 | +2. Clone your fork: |
| 18 | + ```bash |
| 19 | + git clone https://github.com/Digital-Defiance/node-accelerate.git |
| 20 | + cd node-accelerate |
| 21 | + ``` |
| 22 | + |
| 23 | +3. Install dependencies: |
| 24 | + ```bash |
| 25 | + npm install |
| 26 | + ``` |
| 27 | + |
| 28 | +4. Build the addon: |
| 29 | + ```bash |
| 30 | + npm run build |
| 31 | + ``` |
| 32 | + |
| 33 | +5. Run tests: |
| 34 | + ```bash |
| 35 | + npm test |
| 36 | + ``` |
| 37 | + |
| 38 | +## Project Structure |
| 39 | + |
| 40 | +``` |
| 41 | +node-accelerate/ |
| 42 | +├── accelerate.cc # C++ implementation |
| 43 | +├── binding.gyp # Build configuration |
| 44 | +├── index.js # JavaScript wrapper |
| 45 | +├── index.d.ts # TypeScript definitions |
| 46 | +├── test.js # Test suite |
| 47 | +├── benchmark.js # Performance benchmarks |
| 48 | +└── README.md # Documentation |
| 49 | +``` |
| 50 | + |
| 51 | +## Making Changes |
| 52 | + |
| 53 | +### Code Style |
| 54 | + |
| 55 | +**C++ Code:** |
| 56 | +- Follow Google C++ Style Guide |
| 57 | +- Use 2-space indentation |
| 58 | +- Add comments for complex operations |
| 59 | +- Include error handling |
| 60 | + |
| 61 | +**JavaScript Code:** |
| 62 | +- Use 2-space indentation |
| 63 | +- Use `const` and `let`, not `var` |
| 64 | +- Add JSDoc comments for functions |
| 65 | +- Follow Node.js best practices |
| 66 | + |
| 67 | +### Adding New Functions |
| 68 | + |
| 69 | +1. **Add C++ implementation** in `accelerate.cc`: |
| 70 | + ```cpp |
| 71 | + Napi::Value YourFunction(const Napi::CallbackInfo& info) { |
| 72 | + Napi::Env env = info.Env(); |
| 73 | + |
| 74 | + // Validate arguments |
| 75 | + if (info.Length() < 1) { |
| 76 | + Napi::TypeError::New(env, "Expected 1 argument").ThrowAsJavaScriptException(); |
| 77 | + return env.Null(); |
| 78 | + } |
| 79 | + |
| 80 | + // Your implementation using Accelerate framework |
| 81 | + |
| 82 | + return result; |
| 83 | + } |
| 84 | + ``` |
| 85 | +
|
| 86 | +2. **Export the function** in `Init()`: |
| 87 | + ```cpp |
| 88 | + exports.Set("yourFunction", Napi::Function::New(env, YourFunction)); |
| 89 | + ``` |
| 90 | + |
| 91 | +3. **Add TypeScript definition** in `index.d.ts`: |
| 92 | + ```typescript |
| 93 | + export function yourFunction(arg: Float64Array): number; |
| 94 | + ``` |
| 95 | + |
| 96 | +4. **Add tests** in `test.js`: |
| 97 | + ```javascript |
| 98 | + console.log('Testing your function...'); |
| 99 | + const result = accelerate.yourFunction(testData); |
| 100 | + assertClose(result, expectedValue, 1e-10, 'Your function test'); |
| 101 | + ``` |
| 102 | + |
| 103 | +5. **Update documentation** in `README.md` |
| 104 | + |
| 105 | +### Testing |
| 106 | + |
| 107 | +Run the test suite: |
| 108 | +```bash |
| 109 | +npm test |
| 110 | +``` |
| 111 | + |
| 112 | +Add tests for: |
| 113 | +- Correct results with known inputs |
| 114 | +- Edge cases (empty arrays, single elements) |
| 115 | +- Large inputs (performance validation) |
| 116 | +- Error handling (invalid arguments) |
| 117 | + |
| 118 | +### Benchmarking |
| 119 | + |
| 120 | +Run benchmarks: |
| 121 | +```bash |
| 122 | +npm run benchmark |
| 123 | +``` |
| 124 | + |
| 125 | +When adding new functions, include benchmarks comparing: |
| 126 | +- Pure JavaScript implementation |
| 127 | +- Accelerate-based implementation |
| 128 | +- Speedup factor |
| 129 | + |
| 130 | +## Pull Request Process |
| 131 | + |
| 132 | +1. **Create a branch** for your feature: |
| 133 | + ```bash |
| 134 | + git checkout -b feature/your-feature-name |
| 135 | + ``` |
| 136 | + |
| 137 | +2. **Make your changes** following the code style guidelines |
| 138 | + |
| 139 | +3. **Add tests** for new functionality |
| 140 | + |
| 141 | +4. **Run tests** to ensure everything works: |
| 142 | + ```bash |
| 143 | + npm test |
| 144 | + npm run benchmark |
| 145 | + ``` |
| 146 | + |
| 147 | +5. **Commit your changes** with clear messages: |
| 148 | + ```bash |
| 149 | + git commit -m "Add feature: description" |
| 150 | + ``` |
| 151 | + |
| 152 | +6. **Push to your fork**: |
| 153 | + ```bash |
| 154 | + git push origin feature/your-feature-name |
| 155 | + ``` |
| 156 | + |
| 157 | +7. **Create a Pull Request** with: |
| 158 | + - Clear description of changes |
| 159 | + - Test results |
| 160 | + - Benchmark results (if applicable) |
| 161 | + - Documentation updates |
| 162 | + |
| 163 | +## What to Contribute |
| 164 | + |
| 165 | +### High Priority |
| 166 | + |
| 167 | +- **More BLAS operations**: Matrix-vector multiply, triangular solve, etc. |
| 168 | +- **More vDSP operations**: Convolution, correlation, windowing |
| 169 | +- **Float32 support**: Add single-precision variants |
| 170 | +- **Error handling**: Improve validation and error messages |
| 171 | +- **Documentation**: More examples and use cases |
| 172 | + |
| 173 | +### Medium Priority |
| 174 | + |
| 175 | +- **Performance optimizations**: Reduce overhead, optimize memory usage |
| 176 | +- **Additional tests**: Edge cases, stress tests |
| 177 | +- **CI/CD**: GitHub Actions for automated testing |
| 178 | +- **Benchmarks**: More comprehensive performance tests |
| 179 | + |
| 180 | +### Low Priority |
| 181 | + |
| 182 | +- **Additional platforms**: Explore other ARM64 platforms |
| 183 | +- **Advanced features**: Sparse matrices, complex numbers |
| 184 | +- **Utilities**: Helper functions for common patterns |
| 185 | + |
| 186 | +## Code Review |
| 187 | + |
| 188 | +All submissions require review. We'll look for: |
| 189 | + |
| 190 | +- **Correctness**: Does it work as intended? |
| 191 | +- **Performance**: Does it maintain or improve performance? |
| 192 | +- **Tests**: Are there adequate tests? |
| 193 | +- **Documentation**: Is it well-documented? |
| 194 | +- **Style**: Does it follow the style guide? |
| 195 | + |
| 196 | +## Reporting Issues |
| 197 | + |
| 198 | +When reporting issues, include: |
| 199 | + |
| 200 | +1. **Environment**: |
| 201 | + - macOS version |
| 202 | + - Node.js version |
| 203 | + - Chip (M1/M2/M3/M4/Intel) |
| 204 | + |
| 205 | +2. **Description**: Clear description of the issue |
| 206 | + |
| 207 | +3. **Reproduction**: Minimal code to reproduce |
| 208 | + |
| 209 | +4. **Expected vs Actual**: What you expected vs what happened |
| 210 | + |
| 211 | +5. **Logs**: Any error messages or logs |
| 212 | + |
| 213 | +## Questions? |
| 214 | + |
| 215 | +- Open an issue for questions |
| 216 | +- Check existing issues first |
| 217 | +- Be respectful and constructive |
| 218 | + |
| 219 | +## License |
| 220 | + |
| 221 | +By contributing, you agree that your contributions will be licensed under the MIT License. |
| 222 | + |
| 223 | +## Acknowledgments |
| 224 | + |
| 225 | +Thank you for contributing to node-accelerate! Your efforts help make high-performance numerical computing accessible to the Node.js community. |
0 commit comments