Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/moses-smt/vowpal_wabbit.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'cs_test')
-rw-r--r--cs_test/Program.cs25
-rw-r--r--cs_test/VowpalWabbitInterface.cs8
2 files changed, 30 insertions, 3 deletions
diff --git a/cs_test/Program.cs b/cs_test/Program.cs
index 2af31061..ababf145 100644
--- a/cs_test/Program.cs
+++ b/cs_test/Program.cs
@@ -74,7 +74,6 @@ namespace cs_test
VowpalWabbitInterface.Finish(vw);
// clean up the memory we allocated
-
pinnedsFeatures.Free();
pinnedtFeatures.Free();
pinnedFeatureSpace.Free();
@@ -82,7 +81,7 @@ namespace cs_test
private static void RunParserTest()
{
- IntPtr vw = VowpalWabbitInterface.Initialize("-q st -d 0002.dat -f out");
+ IntPtr vw = VowpalWabbitInterface.Initialize("-q st -d 0002.dat -f out2");
VowpalWabbitInterface.StartParser(vw, false);
@@ -91,6 +90,28 @@ namespace cs_test
while (IntPtr.Zero != (example = VowpalWabbitInterface.GetExample(vw)))
{
count++;
+ int featureSpaceLen = 0;
+ IntPtr featureSpacePtr = VowpalWabbitInterface.ExportExample(example, ref featureSpaceLen);
+
+ VowpalWabbitInterface.FEATURE_SPACE[] featureSpace = new VowpalWabbitInterface.FEATURE_SPACE[featureSpaceLen];
+ int featureSpace_size = Marshal.SizeOf(typeof(VowpalWabbitInterface.FEATURE_SPACE));
+
+ for (int i = 0; i < featureSpaceLen; i++)
+ {
+ IntPtr curfeatureSpacePos = new IntPtr(featureSpacePtr.ToInt32() + i * featureSpace_size);
+ featureSpace[i] = (VowpalWabbitInterface.FEATURE_SPACE)Marshal.PtrToStructure(curfeatureSpacePos, typeof(VowpalWabbitInterface.FEATURE_SPACE));
+
+ VowpalWabbitInterface.FEATURE[] feature = new VowpalWabbitInterface.FEATURE[featureSpace[i].len];
+ int feature_size = Marshal.SizeOf(typeof(VowpalWabbitInterface.FEATURE));
+ for (int j = 0; j < featureSpace[i].len; j++)
+ {
+ IntPtr curfeaturePos = new IntPtr((featureSpace[i].features.ToInt32() + j * feature_size));
+ feature[j] = (VowpalWabbitInterface.FEATURE)Marshal.PtrToStructure(curfeaturePos, typeof(VowpalWabbitInterface.FEATURE));
+ }
+ }
+ VowpalWabbitInterface.ReleaseFeatureSpace(featureSpacePtr, featureSpaceLen);
+
+
float score = VowpalWabbitInterface.Learn(vw, example);
VowpalWabbitInterface.FinishExample(vw, example);
}
diff --git a/cs_test/VowpalWabbitInterface.cs b/cs_test/VowpalWabbitInterface.cs
index a93a206f..014e39b2 100644
--- a/cs_test/VowpalWabbitInterface.cs
+++ b/cs_test/VowpalWabbitInterface.cs
@@ -32,7 +32,13 @@ namespace Microsoft.Research.MachineLearning
[DllImport("libvw.dll", EntryPoint = "VW_ImportExample", CallingConvention = CallingConvention.StdCall)]
// features points to a FEATURE_SPACE[]
public static extern IntPtr ImportExample(IntPtr vw, IntPtr features, int length);
-
+
+ [DllImport("libvw.dll", EntryPoint = "VW_ExportExample", CallingConvention = CallingConvention.StdCall)]
+ public static extern IntPtr ExportExample(IntPtr example, ref int length);
+
+ [DllImport("libvw.dll", EntryPoint = "VW_ReleaseFeatureSpace", CallingConvention = CallingConvention.StdCall)]
+ public static extern IntPtr ReleaseFeatureSpace(IntPtr fs, int length);
+
[DllImport("libvw.dll", EntryPoint = "VW_ReadExample", CallingConvention = CallingConvention.StdCall)]
public static extern IntPtr ReadExample(IntPtr vw, [MarshalAs(UnmanagedType.LPWStr)]string exampleString);