Skip to content

Commit 2a86b80

Browse files
committed
first commit
0 parents  commit 2a86b80

1 file changed

Lines changed: 91 additions & 0 deletions

File tree

README.md

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
# DNLP Diff Engine
2+
3+
A minimalistic C-based expression tree system for nonlinear programming with automatic differentiation capabilities.
4+
5+
## Structure
6+
7+
```
8+
.
9+
├── include/ # Header files
10+
│ ├── expr.h # Base expression node definition
11+
│ ├── affine/ # Affine operations
12+
│ │ ├── variable.h
13+
│ │ ├── constant.h
14+
│ │ └── add.h
15+
│ └── elementwise/ # Elementwise operations
16+
│ ├── exp.h
17+
│ └── log.h
18+
├── src/
19+
│ ├── expr.c # Base node implementation
20+
│ ├── affine/ # Affine operations
21+
│ │ ├── variable.c
22+
│ │ ├── constant.c
23+
│ │ └── add.c
24+
│ └── elementwise/ # Elementwise operations
25+
│ ├── exp.c
26+
│ └── log.c
27+
├── tests/
28+
│ └── forward_pass/ # Forward pass tests
29+
│ └── test_forward_pass.c
30+
└── CMakeLists.txt # Build configuration
31+
```
32+
33+
## Features
34+
35+
- **Expression nodes**: Each node has dimension `m`, preallocated value memory, and up to two children
36+
- **Leaf nodes**: Variable (reads from input `u`) and Constant (fixed values)
37+
- **Affine operations**: Addition
38+
- **Elementwise operations**: Exponential (`exp`) and Logarithm (`log`)
39+
- **Forward pass**: Compute output values through the expression tree
40+
41+
## Building
42+
43+
```bash
44+
mkdir build && cd build
45+
cmake ..
46+
make
47+
```
48+
49+
## Running Tests
50+
51+
```bash
52+
# Run the test executable
53+
./test_forward_pass
54+
55+
# Or use CTest
56+
ctest --verbose
57+
```
58+
59+
## Example Usage
60+
61+
```c
62+
#include "expr.h"
63+
#include "affine/variable.h"
64+
#include "affine/constant.h"
65+
#include "affine/add.h"
66+
#include "elementwise/exp.h"
67+
#include "elementwise/log.h"
68+
69+
// Build expression tree: log(exp(x) + c)
70+
double u[2] = {1.0, 2.0};
71+
double c[2] = {1.0, 1.0};
72+
73+
expr* var = new_variable(2);
74+
expr* exp_node = new_exp(var);
75+
expr* const_node = new_constant(2, c);
76+
expr* sum = new_add(exp_node, const_node);
77+
expr* log_node = new_log(sum);
78+
79+
// Compute forward pass
80+
log_node->forward(log_node, u);
81+
82+
// Result is in log_node->value
83+
```
84+
85+
## Design
86+
87+
- Each node allocates its own output memory
88+
- Forward pass recursively evaluates children before computing node output
89+
- Clean separation: affine operations in `src/affine/`, elementwise in `src/elementwise/`
90+
- Memory management: nodes must be freed manually (children are not auto-freed)
91+
# DNLP-diff-engine

0 commit comments

Comments
 (0)