anchor.diff:  
   # DiffSharp: Differentiable Tensor Programming Made Simple
   
  -DiffSharp is a tensor library with support for [differentiable programming](https://en.wikipedia.org/wiki/Automatic_differentiation).
  +DiffSharp is a tensor library with support for [differentiable programming](https://en.wikipedia.org/wiki/Differentiable_programming).
   It is designed for use in machine learning, probabilistic programming, optimization and other domains.
   
   <button class="button" style="vertical-align:middle" onclick="window.location.href='{{root}}install.html'"><span>Install »</span></button>
  
positive.code: 
  ## Practical, Familiar and Efficient
  
  DiffSharp comes with a [LibTorch](https://pytorch.org/cppdocs/) backend, using the same C++ and CUDA implementations for tensor computations that power [PyTorch](https://pytorch.org/). On top of these raw tensors (LibTorch's ATen, excluding autograd), DiffSharp implements its own computation graph and differentiation capabilities. It is tested on Linux and Windows and includes support for CUDA.
  
  The DiffSharp API is designed to be similar to [the PyTorch Python API](https://pytorch.org/docs/stable/index.html) through very similar naming and idioms, and where elements have similar names the PyTorch documentation can generally be used as a guide.
  
  DiffSharp uses [the incredible F# programming language](https://fsharp.org) for tensor programming. F# code is generally faster and more robust than equivalent Python code, while still being succinct and compact like Python, making it an ideal modern AI and machine learning implementation language. This allows fluent and productive code while focusing on the tensor programming domain.
  
  </br>
  <iframe width="85%" src="https://www.youtube.com/embed/_QnbV6CAWXc" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
  
  ## Examples
  
  Using the buttons [![Binder](img/badge-binder.svg)](https://mybinder.org/v2/gh/diffsharp/diffsharp.github.io/master?filepath={{fsdocs-source-basename}}.ipynb) 
  [![Script](img/badge-script.svg)]({{fsdocs-source-basename}}.fsx) 
  [![Script](img/badge-notebook.svg)]({{fsdocs-source-basename}}.ipynb) on the top of the page, you can execute this page and all other documentation pages as an interactive notebook running in your browser, or download it as a script or a .NET Interactive Jupyter notebook. If using Visual Studio Code, you can download, edit, and execute these notebooks using [the .NET Interactive Notebooks for VS Code](https://marketplace.visualstudio.com/items?itemName=ms-dotnettools.dotnet-interactive-vscode).
  
  First reference the package, by using one of the following three lines. For LibTorch support use [`DiffSharp-cpu`](https://www.nuget.org/packages/DiffSharp-cpu) instead of [`DiffSharp-lite`](https://www.nuget.org/packages/DiffSharp-lite).
  
      #r "nuget: DiffSharp-lite" // Use the latest version
      #r "nuget: DiffSharp-lite,*-*" // Use the latest pre-release version
      #r "nuget: DiffSharp-lite,1.0.0-local-210421" // Use a specific version
  
  *)
  
  open DiffSharp
  
  (** 
  Configure:
  *)
  dsharp.config(dtype=Dtype.Float32, device=Device.CPU, backend=Backend.Reference)
  
  (** 
  Defining and adding two tensors:
  *)
  let t1 = dsharp.tensor [ 0.0 .. 0.2 .. 1.0 ]
  let t2 = dsharp.tensor [ 0, 1, 2, 7, 8, 9 ]
  
  t1 + t2
  
  (** 
  Computing a convolution:
  *)
  let t3 = dsharp.tensor [[[[0.0 .. 10.0]]]]
  let t4 = dsharp.tensor [[[[0.0 ..0.1 .. 1.0]]]]
  
  t3.conv2d(t4)
  
  (** 
  Take the gradient of a vector-to-scalar function:
  *)
  
  let f (x: Tensor) = x.exp().sum()
  
  dsharp.grad f (dsharp.tensor([1.8, 2.5]))
  
  (**
  Define a model and optimize it:
  
negative.code: 
  print $"Validation loss: {validLoss/validSet.length}"
  
  (**
  
  Numerous other model definition, differentiation, and training patterns are supported. See the tutorials in the left-hand menu and [examples](https://github.com/DiffSharp/DiffSharp/tree/dev/examples) on GitHub.
  
  ## More Information
  
  