Skip to content
Snippets Groups Projects
Commit ecf50aad authored by Carl Philipp Klemm's avatar Carl Philipp Klemm
Browse files

Inital fully operational version

Use exceptions to propagate backend failures
parent 206c9349
No related branches found
No related tags found
No related merge requests found
......@@ -17,9 +17,16 @@ public struct VersionFixed
public static extern VersionFixed GetVersion();
}
public class InferenceException : Exception
{
public InferenceException(){}
public InferenceException(string message): base(message){}
public InferenceException(string message, Exception inner): base(message, inner){}
}
public class Network
{
public delegate void ResultDlg(float[] result);
public delegate void ResultDlg(float[] result, Network network);
private struct Flight
{
......@@ -39,7 +46,7 @@ public class Network
Capi.free(result);
var flight = inflight[data];
inflight.Remove(data);
flight.Callback(managedResult);
flight.Callback(managedResult, this);
flight.Signal.Set();
}
......@@ -59,7 +66,10 @@ public class Network
flight.Callback = callback;
flight.Signal = new AutoResetEvent(false);
inflight.Add(flightcounter, flight);
Capi.kiss_async_run_inference_complex(ref net, spectra.Real, spectra.Imaginary, flightcounter);
byte ret = Capi.kiss_async_run_inference_complex(ref net, spectra.Real, spectra.Imaginary, flightcounter);
if(ret == 0)
throw new InferenceException(getError());
flightcounter += 1;
return flight.Signal;
}
......@@ -72,7 +82,9 @@ public class Network
flight.Callback = callback;
flight.Signal = new AutoResetEvent(false);
inflight.Add(flightcounter, flight);
Capi.kiss_async_run_inference(ref net, data, flightcounter);
byte ret = Capi.kiss_async_run_inference(ref net, data, flightcounter);
if(ret == 0)
throw new InferenceException(getError());
flightcounter += 1;
return flight.Signal;
}
......@@ -120,7 +132,6 @@ public class Network
return Capi.IntPtrToUtf8Array(net.outputLabels);
}
}
}
public class Spectra
......
......@@ -9,15 +9,21 @@ public class Program
Console.WriteLine("{0:F}+{1:F}i", spectra.Real[i], spectra.Imaginary[i]);
}
public static void Result(float[] result)
public static void Result(float[] result, Kiss.Network network)
{
Console.WriteLine("Thread id: {0:D}", System.Environment.CurrentManagedThreadId);
Console.WriteLine("Got result");
string[] outputLabels = network.OutputLabels;
for(int i = 0; i < result.Length; ++i)
Console.WriteLine("{0:S}: {1:F}", outputLabels[i], result[i]);
}
public static int Main(string[] args)
{
Kiss.VersionFixed version = Kiss.VersionFixed.GetVersion();
Console.WriteLine("libkissinference version: {0:D}.{1:D}.{2:D}", version.Major, version.Minor, version.Patch);
Console.WriteLine("Thread id: {0:D}", System.Environment.CurrentManagedThreadId);
var spectra = new Kiss.Spectra(Kiss.Utils.CreateRange(1, 10, 10, true), Kiss.Utils.CreateRange(1, 10, 10, true), Kiss.Utils.CreateRange(1, 10, 10, true));
......@@ -43,7 +49,7 @@ public class Program
try
{
var net = new Kiss.Network(filename, true);
var net = new Kiss.Network(filename, false);
Console.WriteLine("Input size: {0:D} OutputSize: {1:D} Purpose: {2:S} InputLabel: {3:S}", net.InputSize, net.OutputSize, net.Purpose, net.InputLabel);
spectra.Resample(net.InputSize/2);
Console.WriteLine("Expanded spectra:");
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment