GithubHelp home page GithubHelp logo

szaman19 / delta Goto Github PK

View Code? Open in Web Editor NEW
0.0 3.0 0.0 15 KB

A templated extendible modular automatic gradient and neural network library in C++

License: MIT License

Makefile 3.14% C++ 96.86%
autograd cpp deep-learning neural-network

delta's Introduction

Delta

A templated C++ autograd and neural network library interface.


Autograd example with reference CPU implementation

#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<float>;
using Tensor = Delta::Tensor<float, Tensor_Impl>;

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.