You can install the library via its NuGet package.

If you don't use NuGet, you can download the binaries of the latest release on GitHub.

For using DiffSharp, your project should target .NET Framework 4.6 or higher before installing the NuGet package.

Starting with version 0.7, DiffSharp only supports the 64 bit platform. In the build configuration of your project, you should set "x64" as the platform target (don't forget to do this for all build configurations).

If you are using F# interactive, you should run it in 64 bit mode. In Visual Studio, you can do this by selecting "Tools - Options - F# Tools - F# Interactive" and setting "64 bit F# Interactive" to "true" and restarting the IDE.

To install DiffSharp on NuGet, run the following in the Package Manager Console:
PM> Install-Package DiffSharp


Please make sure you have the latest libopenblas-dev package installed for OpenBLAS.

You should have a working .NET runtime on your system. Mono has been the standard choice for Linux, but the community is in the process of moving to .NET Core, a new cross-platform implementation of the framework. Please refer to fsharp.org for the latest instructions.

If you have a .NET setup where you can use NuGet, once you have the file libopenblas.so in the library search path (e.g. in /usr/lib), you can use the same NuGet package described above.

Alternatively, you can download the Linux-specific pack of binaries of the latest release, which also includes a compatible version of libopenblas.so, on GitHub.

You can check out Ionide, a lightweight editor for F# development on Linux.


"I get a System.EntryPointNotFoundException when running my code."

This is because you have an old version of OpenBLAS on your system. DiffSharp uses of ?omatcopy and ?imatcopy extensions for BLAS introduced by Intel MKL for fast matrix transposition, which were not present in earlier versions of OpenBLAS.

On Linux, you can compile the latest OpenBLAS using these instructions. We also distribute a compatible version of libopenblas.so in the Linux-specific pack of the latest release on GitHub.

Please make sure you have the latest version of libopenblas.so in the shared library search path. Also see the "Linux shared library search path" section on this page.

"When trying to use DiffSharp with an .fsx script in F# Interactive, I get 'Unable to load DLL libopenblas'. When I compile the code as a .fs code file, everything runs fine."

This is related with the general behavior of F# Interactive and how it works with native dlls. It is not specific to DiffSharp.

This post by Christoph Rüegg provides a detailed overview of how to load native libraries for scripts.

In short, you have to make sure that you have the OpenBLAS binaries (libopenblas.dll, libgccsseh-1.dll, libgfortran-3.dll, libquadmath-0.dll on Windows, and libopenblas.so on Linux) in a location reachable by the DiffSharp.dll assembly you are loading into your script (e.g., #r "../DiffSharp.dll").

On Linux, make sure that you have libopenblas.so in the shared library search path. Also see the "Linux shared library search path" section on this page.

On Windows, one way of accomplishing this is to put the DiffSharp.dll and OpenBLAS binaries into the same folder with your .fsx script and call

System.Environment.CurrentDirectory <- __SOURCE_DIRECTORY__

at the beginning of your script.

namespace System
type Environment =
  static member CommandLine : string
  static member CurrentDirectory : string with get, set
  static member Exit : exitCode:int -> unit
  static member ExitCode : int with get, set
  static member ExpandEnvironmentVariables : name:string -> string
  static member FailFast : message:string -> unit + 1 overload
  static member GetCommandLineArgs : unit -> string[]
  static member GetEnvironmentVariable : variable:string -> string + 1 overload
  static member GetEnvironmentVariables : unit -> IDictionary + 1 overload
  static member GetFolderPath : folder:SpecialFolder -> string + 1 overload
  nested type SpecialFolder
  nested type SpecialFolderOption

Full name: System.Environment
property System.Environment.CurrentDirectory: string