Share on Facebook Tweet on Twitter Share on LinkedIn Share by email
Sho External API Guide

If you'd like to use the Sho libraries directly from .NET (C#, Managed C++, F#, etc.), you'll need to add references to specific libraries depending on what functionality you wish to use; in some cases you'll also need to do a bit of setup so that the references will resolve properly. This guide explains how to do this.

Installing the Libraries

To get the libraries, we recommend installing Sho so that you can use the Sho Console as well; however, to build against the libraries, all you need are the contents of the "bin" directory from the Sho install; you can get these by copying them from your Sho install (evaluate "shobindir" in the Sho console to find the location). Thus, if you're putting code into source control, distributing the code, etc., you'll only need to distribute the bin directory. Note that if you plan to use EmbeddedSho, you'll likely want to copy the entire Sho directory, as you'll need to point to it when creating an EmbeddedSho engine.

Code Setup

Because the ShoArray classes contain both managed and unmanaged code to achieve maximal computation speed, the array libraries depend on some satellite DLLs. In order for the managed libraries to resolve these references, you'll have to do one of the following:

  • [preferred method] Set the environment variable SHODIR to the parent of Sho's bin directory. Alternatively, you can set the variable SHOBINDIR to the bin directory directly. For instance, if you copied the bin directory from the Sho install to C:\libraries\Sho\bin, you should point SHODIR to C:\libraries\Sho. Note that you can set the variable programatically (ideally as soon as the app starts) via

    System.Environment.SetEnvironmentVariable("SHODIR",...)
  • Another option is to put your .exe into the Sho\bin directory, or equivalently copy the Sho\bin directory to the directory that contains your .exe.

What References Do I Need to Add?

The table below lists the DLL's and namespaces required for various aspects of Sho functionality.

 

Functionality

Namespaces

Referenced DLLs

Basic matrix math

ShoNS.Array

ShoArray.dll
MatrixInterf.dll

Basic matrix + complex numbers

ShoNS.Array
Microsoft.Scripting.Math

ShoArray.dll
MatrixInterf.dll
Microsoft.Dynamic.dll

Extensions for Python matrix code

ShoNS.Array
ShoNS.PythonExtensions

ShoArray.dll
MatrixInterf.dll
PythonExt.dll

Random number generation

ShoNS.MathFunc

Rand.dll

Auto-mapping functions

ShoNS.Array
ShoNS.MathFunc

ShoArray.dll
MatrixInterf.dll
MathFunc.dll

Reading/writing delimited files

ShoNS.Array

ShoNS.IO

ShoArray.dll
MatrixInterf.dll
dlmIO.dll

Plotting/charting and other visualization

ShoNS.Visualization

ShoViz.dll
System.Windows.Forms

Serialization of objects (including Python objects)

ShoNS.Pickling
System.IO

ShoPickleHelper.dll

Embedding a Sho interpreter in your C# code

ShoNS.Hosting

EmbeddedSho.dll
IronPython.dll
IronPython.Modules.dll

 

Sample Projects

The following projects show examples of how to use the Sho libraries from C#. Each zip file contains a Visual Studio solution file; you should unzip this to {SHODIR}\playpen so that the relative references will work properly.

  • CSharpExample - shows how to create an array, do some linear algebra operations, and create a plot window from C#.
    [Project Zip file]
  • EmbeddedShoTest - shows how to create an EmbeddedSho engine, pass variable values back and from C# to Sho, and execute Sho statements (including a plot).]
    [Project Zip file]