https://github.com/szaman19/delta
A templated extendible modular automatic gradient and neural network library in C++
https://github.com/szaman19/delta
autograd cpp deep-learning neural-network
Last synced: over 1 year ago
JSON representation
A templated extendible modular automatic gradient and neural network library in C++
- Host: GitHub
- URL: https://github.com/szaman19/delta
- Owner: szaman19
- License: mit
- Created: 2021-07-08T16:25:57.000Z (about 5 years ago)
- Default Branch: main
- Last Pushed: 2023-01-09T15:38:26.000Z (over 3 years ago)
- Last Synced: 2025-01-31T00:25:19.134Z (over 1 year ago)
- Topics: autograd, cpp, deep-learning, neural-network
- Language: C++
- Homepage:
- Size: 14.6 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Delta
A templated C++ autograd and neural network library interface.
---
Autograd example with reference CPU implementation
```C++
#include "Delta/Tensor.hpp"
#include "CPU/Tensor_CPU_impl.hpp"
#include "CPU/Operator_CPU_impl.hpp"
// The type of tensor included by the compiler decides the implementation
// Maybe think about having the ability to switch impl would be nice.
using Tensor_Impl = Delta::Tensor_CPU_Impl;
using Tensor = Delta::Tensor;
int main(int argc, char const *argv[]){
auto summand_1 = Tensor(1, {1}, true);
auto summand_2 = Tensor(2, {1}, true);
std::cout << summand_1;
std::cout << summand_2;
auto& res = Delta::Ops::Sum(summand_1, summand_2); // 2 + 1
std::cout << "Check: " << res.GetData()[0] <<" == " << 3 << std::endl;
auto multiplier = Tensor(5, {1}, true);
auto& out = Delta::Ops::Mul(res, multiplier);
std::cout << "Check: " << out.GetData()[0] << " == " << 15 << std::endl;
out.Backward();
std::cout << "Check: " << out.GetGrad()[0] << " == " << 1 << '\n';
std::cout << "Check: " << res.GetGrad()[0] << " == " << 5 << '\n';
std::cout << "Check: " << multiplier.GetGrad()[0] << " == " << 3 << '\n';
std::cout << "Check: " << summand_1.GetGrad()[0] << " == " << 5 << '\n';
std::cout << "Check: " << summand_2.GetGrad()[0] << " == " << 5 << std::endl;
return 0;
}
```
Outputs:
```
[1] Gradient enabled
[2] Gradient enabled
Check: 3 == 3
Check: 15 == 15
Check: 1 == 1
Check: 5 == 5
Check: 3 == 3
Check: 5 == 5
Check: 5 == 5
```