public void Test_Empty() { int errorCode = 0; try { ILBaseArray[] data = new ILBaseArray[60]; for (int i = 0; i < data.Length; i++) { data[i] = new ILArray <Int16>(new Int16[1] { (Int16)i }); } ILCell A = new ILCell(data, 20, 3); ILArray <double> ind = new double[0] { }; ILBaseArray elem = A[null, ind]; if (!(elem is ILCell)) { throw new Exception("empty return from ILCell should be ILCell"); } Success(); } catch (Exception e) { Error(errorCode, e.Message); } }
public static ILCell PermuteTestArrays(params ILCell[] inputParameter) { if (inputParameter == null || inputParameter.Length == 0) throw new Exception("no input parameter specified!"); for (int i = 0; i < inputParameter.Length; i++) { if (inputParameter[i] == null || inputParameter[i].IsEmpty || !inputParameter[i].IsColumnVector) throw new Exception("input parameter #" + i + " has wrong format. All parameters must be column vectors!"); } ILCell ret = new ILCell(inputParameter[0].Length,inputParameter.Length); int[] curPos = new int[inputParameter.Length]; int p = 0, d = 0; while (d < curPos.Length) { for (int i = 0; i < curPos.Length; i++) { ret[p,i] = inputParameter[i][curPos[i],0]; } p++; d = 0; while (d < curPos.Length) { if (curPos[d] < inputParameter[d].Length - 1) { curPos[d]++; break; } curPos[d++] = 0; } } return ret; }
// update the shapes with new data. Data are made by the helper class // "Computation" and are provided as ILCell, holding the coords for the // pendula weigth (one circle only) and the corresponding indices (mapping). private void UpdateShapes(ILCell data) { // get the data out of the cell ILArray <double> circ = (ILArray <double>)data[0]; ILArray <double> mapping = (ILArray <double>)data[1]; // update the pendula weight edges (lit quads) // Data contains only one circle, since we need two, we concatenate // the array: x and y are simply doubled, z is added with 0.4 to // create a volume. m_quads.Update(circ[0.0, null].Concat(circ[0.0, null], 1), circ[1.0, null].Concat(circ[1.0, null], 1), circ[2.0, null].Concat(circ[2.0, null] + 0.4, 1), // mapping contains the indices referencing the vertices in circ mapping); // the polygon updates are even easier: since ILPolygon is a simple (bordered) // shape, no mappings are needed, we just pass the vertex data: m_poly1.Update(circ[0.0, null], circ[1.0, null], circ[2.0, null]); m_poly2.Update(circ[0.0, null], circ[1.0, null], circ[2.0, null] + 0.4); // note, calling Update on any ILShape will at the same time invalidate the shape. // this is important to signal the scene (panel) for the size of the scene and the // position(s) of shape(s) may have changed. Latter is important for the order in which // shapes are drawn in case of transparent shapes. Since Update() already does this for us, // we do not have to call [shape].Invalidate() manually. // However, if we would use the low-level interface for scene updates and manipulate the // shapes vertices directly, we would need to call Invalidate() afterwards. }
public override ILCell GenerateTestArrays() { ILCell ret = new ILCell(); int count = 0; // empty ILArray <double> tmp; ret[count++] = ILArray <double> .empty(0, 0); ret[count++] = ILArray <double> .empty(1, 0); ret[count++] = ILArray <double> .empty(0, 1, 0); // scalar ret[count++] = (ILArray <double>) 1.0; ret[count++] = (ILArray <double>) double.NaN; ret[count++] = (ILArray <double>) double.PositiveInfinity; ret[count++] = (ILArray <double>) double.NegativeInfinity; ret[count++] = (ILArray <double>) 0.0; ret[count++] = (ILArray <double>)(-30.0); // vector ret[count++] = ILMath.zeros(1, 10); ret[count++] = ILMath.ones(1, 10); ret[count++] = ILMath.zeros(10, 1); ret[count++] = ILMath.ones(10, 1); ret[count++] = ILMath.vector(0.0, 10.0); ret[count++] = ILMath.vector(-5.0, 4.0); tmp = ILMath.vector(-5.0, 4.0); tmp[0] = double.NegativeInfinity; tmp["end"] = double.PositiveInfinity; tmp[3] = double.NaN; ret[count++] = tmp; // matrix ret[count++] = ILMath.zeros(3, 2); ret[count++] = ILMath.rand(2, 4); ret[count++] = ILMath.ones(2, 3) * double.NaN; ret[count++] = ILMath.ones(3, 2) / 0.0; // inf tmp = ILMath.ones(3, 2); tmp[0] = double.NaN; ret[count++] = tmp; tmp[1] = double.PositiveInfinity; ret[count++] = tmp; tmp[3] = double.NegativeInfinity; ret[count++] = tmp; // 3d array ret[count++] = ILMath.zeros(4, 3, 2); ret[count++] = ILMath.ones(4, 3, 2); ret[count++] = 0.0 / ILMath.zeros(4, 3, 2); ret[count++] = ILMath.ones(4, 3, 2) * double.NaN; ret[count++] = ILMath.ones(4, 3, 2) * double.NegativeInfinity; ret[count++] = ILMath.rand(4, 3, 2); // 4d array ret[count++] = ILMath.rand(30, 2, 3, 20); return(ret); }
public ILTest() { m_failed = 0; m_success = 0; m_failedTestNames = new List<string>(); m_failedTestCases = new Dictionary<string,int>(); m_manualOverrides = new ILCell(); // 6930812 220803 m_manualIgnoreIds = new List<int>(); m_ignoreAllErrors = false; }
public ILTest() { m_failed = 0; m_success = 0; m_failedTestNames = new List <string>(); m_failedTestCases = new Dictionary <string, int>(); m_manualOverrides = new ILCell(); // 6930812 220803 m_manualIgnoreIds = new List <int>(); m_ignoreAllErrors = false; }
public override ILCell GenerateTestArrays() { ILCell byteCell = new ILTestProviderUInt16().GenerateTestArrays(); ILCell ret = new ILCell(byteCell.Dimensions[0],byteCell.Dimensions[1]); int counter = 0; foreach (ILBaseArray arr in byteCell.Values) { if (arr is ILArray<UInt16>) { ILArray<UInt16> arrB = arr as ILArray<UInt16>; ret[counter++,0] = ILMath.touint32(arrB); } } return ret; }
public override ILCell GenerateTestArrays() { ILCell ret = new ILCell(); int count = 0; // empty ILArray<double> tmp; ret[count++] = ILArray<double>.empty(0, 0); ret[count++] = ILArray<double>.empty(1, 0); ret[count++] = ILArray<double>.empty(0, 1, 0); // scalar ret[count++] = (ILArray<double>)1.0; ret[count++] = (ILArray<double>)double.NaN; ret[count++] = (ILArray<double>)double.PositiveInfinity; ret[count++] = (ILArray<double>)double.NegativeInfinity; ret[count++] = (ILArray<double>)0.0; ret[count++] = (ILArray<double>) (-30.0); // vector ret[count++] = ILMath.zeros(1,10); ret[count++] = ILMath.ones(1,10); ret[count++] = ILMath.zeros(10,1); ret[count++] = ILMath.ones(10,1); ret[count++] = ILMath.vector(0.0,10.0); ret[count++] = ILMath.vector(-5.0,4.0); tmp = ILMath.vector(-5.0,4.0); tmp[0] = double.NegativeInfinity; tmp["end"] = double.PositiveInfinity; tmp[3] = double.NaN; ret[count++] = tmp; // matrix ret[count++] = ILMath.zeros(3,2); ret[count++] = ILMath.rand(2,4); ret[count++] = ILMath.ones(2,3) * double.NaN; ret[count++] = ILMath.ones(3,2) / 0.0; // inf tmp = ILMath.ones(3,2); tmp[0] = double.NaN; ret[count++] = tmp; tmp[1] = double.PositiveInfinity; ret[count++] = tmp; tmp[3] = double.NegativeInfinity; ret[count++] = tmp; // 3d array ret[count++] = ILMath.zeros(4, 3, 2); ret[count++] = ILMath.ones(4, 3, 2); ret[count++] = 0.0 / ILMath.zeros(4, 3, 2); ret[count++] = ILMath.ones(4, 3, 2) * double.NaN; ret[count++] = ILMath.ones(4, 3, 2) * double.NegativeInfinity; ret[count++] = ILMath.rand(4, 3, 2); // 4d array ret[count++] = ILMath.rand(30, 2, 3, 20); return ret; }
public static ILRetCell DBQuery() { using (ILScope.Enter()) { // prepare return cell ILCell ret = cell(size(2, 2)); // todo: fetch data from db and replace below example data ret[0, 0] = "header_1"; ret[1, 0] = "header_2"; ret[0, 1] = rand(100, 200); ret[1, 1] = ones <float>(2, 3000); return(ret); } }
private void Test_Test() { int errorCode = 0; try { ILCell C = new ILCell(2,3); // than create another cell holding an ILArray<double>, ILCell Ci = new ILCell(2,4); Ci[0] = ILMath.rand(4,5); // store this as inner cell of C C[0] = Ci; Success(); } catch (Exception e) { Error(errorCode ,e.Message); } }
/// <summary> /// create vertices by triangularization, starting from icosahedron and subseq. creating finer grained details /// </summary> /// <param name="detail">number of iterations for triangularization</param> /// <param name="indices">out param: return triangles</param> /// <returns>vertex data</returns> public static ILArray <float> CreateVerticesTri(int detail, out ILArray <int> indices) { if (s_vertexCache.ContainsKey(detail) && s_vertexCache[detail] != null) { ILCell data = s_vertexCache[detail]; indices = (ILArray <int>)data[1]; return((ILArray <float>)data[0]); } else { // regular octahedron //float[,] pos = new float[,] { // {1, 0, 0}, {-1, 0, 0}, // {0, 1, 0}, {0, -1, 0}, // {0, 0, 1}, {0, 0, -1} //}; //int[,] ind = new int[,] { // {4, 0, 3}, {4, 3, 1}, {4 ,1 ,2}, {4, 2 ,0}, // {0, 2, 5}, {3, 0, 5}, {1, 3, 5}, {1, 5, 2} //}; //// regular icosahedron float X = 0.525731112119133606f; float Z = 0.850650808352039932f; float[,] pos = new float[, ] { { -X, 0, Z }, { X, 0, Z }, { -X, 0, -Z }, { X, 0, -Z }, { 0, Z, X }, { 0, Z, -X }, { 0, -Z, X }, { 0, -Z, -X }, { Z, X, 0 }, { -Z, X, 0 }, { Z, -X, 0 }, { -Z, -X, 0 } }; int[,] ind = new int[, ] { { 0, 4, 1 }, { 0, 9, 4 }, { 9, 5, 4 }, { 4, 5, 8 }, { 4, 8, 1 }, { 8, 10, 1 }, { 8, 3, 10 }, { 5, 3, 8 }, { 5, 2, 3 }, { 2, 7, 3 }, { 7, 10, 3 }, { 7, 6, 10 }, { 7, 11, 6 }, { 11, 0, 6 }, { 0, 1, 6 }, { 6, 1, 10 }, { 9, 0, 11 }, { 9, 11, 2 }, { 9, 2, 5 }, { 7, 2, 11 } }; ILArray <float> vertices = pos; indices = ((ILArray <int>)ind); //vertices = vertices[":;0:2"]; //indices = new int[] { 0, 1, 2 }; //indices = indices.T; ILArray <float> outVertices; Triangularize(vertices, indices, detail, out outVertices, out indices); // normalize vertices outVertices = Normalize(outVertices); // store in cache s_vertexCache.Add(detail, new ILCell(new ILBaseArray[] { outVertices.C, indices.C }, 2, 1)); return(outVertices); } }
public void Test_Empty() { int errorCode = 0; try { ILBaseArray[] data = new ILBaseArray[60]; for (int i = 0; i < data.Length; i++) data[i] = new ILArray<Int16>(new Int16[1]{(Int16)i}); ILCell A = new ILCell(data,20,3); ILArray<double> ind = new double[0]{}; ILBaseArray elem = A[null,ind]; if (!(elem is ILCell)) throw new Exception("empty return from ILCell should be ILCell"); Success(); } catch (Exception e) { Error(errorCode ,e.Message); } }
private void Test_Test() { int errorCode = 0; try { ILCell C = new ILCell(2, 3); // than create another cell holding an ILArray<double>, ILCell Ci = new ILCell(2, 4); Ci[0] = ILMath.rand(4, 5); // store this as inner cell of C C[0] = Ci; Success(); } catch (Exception e) { Error(errorCode, e.Message); } }
public override ILCell GenerateTestArrays() { ILCell byteCell = new ILTestProviderUInt16().GenerateTestArrays(); ILCell ret = new ILCell(byteCell.Dimensions[0], byteCell.Dimensions[1]); int counter = 0; foreach (ILBaseArray arr in byteCell.Values) { if (arr is ILArray <UInt16> ) { ILArray <UInt16> arrB = arr as ILArray <UInt16>; ret[counter++, 0] = ILMath.touint32(arrB); } } return(ret); }
public override ILCell GenerateTestArrays() { ILCell ret = new ILCell(); int count = 0; // empty ILArray <short> tmp; ret[count++] = ILArray <short> .empty(0, 0); ret[count++] = ILArray <short> .empty(1, 0); ret[count++] = ILArray <short> .empty(0, 1, 0); // scalar ret[count++] = (ILArray <short>)(short) 1; ret[count++] = (ILArray <short>) short.MaxValue; ret[count++] = (ILArray <short>) short.MinValue; ret[count++] = (ILArray <short>)(short) 0; ret[count++] = (ILArray <short>)(short)(-30); // vector ret[count++] = ILMath.toint16(ILMath.zeros(1, 10)); ret[count++] = ILMath.toint16(ILMath.ones(1, 10)); ret[count++] = ILMath.toint16(ILMath.zeros(10, 1)); ret[count++] = ILMath.toint16(ILMath.ones(10, 1)); ret[count++] = ILMath.toint16(ILMath.vector(0.0, 10.0)); ret[count++] = ILMath.toint16(ILMath.vector(-5.0, 4.0)); tmp = ILMath.toint16(ILMath.vector(-5.0, 4.0)); tmp[0] = short.MinValue; tmp["end"] = short.MaxValue; tmp[3] = 0; ret[count++] = tmp; // matrix ret[count++] = ILMath.toint16(ILMath.zeros(3, 2)); ret[count++] = ILMath.toint16(ILMath.rand(2, 4)); ret[count++] = ILMath.toint16(ILMath.ones(2, 3) * double.NaN); ret[count++] = ILMath.toint16(ILMath.ones(3, 2) / 0.0); // inf // 3d array ret[count++] = ILMath.toint16(ILMath.zeros(4, 3, 2)); ret[count++] = ILMath.toint16(ILMath.ones(4, 3, 2)); ret[count++] = ILMath.toint16(0.0 / ILMath.zeros(4, 3, 2)); ret[count++] = ILMath.toint16(ILMath.ones(4, 3, 2) * short.MinValue); ret[count++] = ILMath.toint16(ILMath.rand(4, 3, 2) * short.MaxValue - (short.MaxValue / 2.0)); // 4d array ret[count++] = ILMath.toint16(ILMath.rand(30, 2, 3, 20) * short.MaxValue - (short.MaxValue / 2.0)); return(ret); }
public override ILCell GenerateTestArrays() { ILCell ret = new ILCell(); int count = 0; // empty ILArray <long> tmp; ret[count++] = ILArray <long> .empty(0, 0); ret[count++] = ILArray <long> .empty(1, 0); ret[count++] = ILArray <long> .empty(0, 1, 0); // scalar ret[count++] = (ILArray <long>)(long) 1; ret[count++] = (ILArray <long>)(long) int.MaxValue; ret[count++] = (ILArray <long>)(long) int.MinValue; ret[count++] = (ILArray <long>)(long) 0; ret[count++] = (ILArray <long>)(long)(-30); // vector ret[count++] = ILMath.toint64(ILMath.zeros(1, 10)); ret[count++] = ILMath.toint64(ILMath.ones(1, 10)); ret[count++] = ILMath.toint64(ILMath.zeros(10, 1)); ret[count++] = ILMath.toint64(ILMath.ones(10, 1)); ret[count++] = ILMath.toint64(ILMath.vector(0.0, 10.0)); ret[count++] = ILMath.toint64(ILMath.vector(-5.0, 4.0)); tmp = ILMath.toint64(ILMath.vector(-5.0, 4.0)); tmp[0] = int.MinValue; tmp["end"] = int.MaxValue; tmp[3] = 0; ret[count++] = tmp; // matrix ret[count++] = ILMath.toint64(ILMath.zeros(3, 2)); ret[count++] = ILMath.toint64(ILMath.rand(2, 4)); ret[count++] = ILMath.toint64(ILMath.ones(2, 3)); ret[count++] = ILMath.toint64(ILMath.ones(3, 2)); // 3d array ret[count++] = ILMath.toint64(ILMath.zeros(4, 3, 2)); ret[count++] = ILMath.toint64(ILMath.ones(4, 3, 2)); ret[count++] = ILMath.toint64(ILMath.toint32(0.0 / (ILMath.randn(4, 3, 2)))); ret[count++] = ILMath.toint64(ILMath.ones(4, 3, 2) * int.MinValue); ret[count++] = ILMath.toint64(ILMath.rand(4, 3, 2) * int.MaxValue); // 4d array ret[count++] = ILMath.toint64(ILMath.rand(30, 2, 3, 20) * int.MaxValue); return(ret); }
public override ILCell GenerateTestArrays() { ILCell ret = new ILCell(); int count = 0; // empty ILArray <ulong> tmp; ret[count++] = ILArray <ulong> .empty(0, 0); ret[count++] = ILArray <ulong> .empty(1, 0); ret[count++] = ILArray <ulong> .empty(0, 1, 0); // scalar ret[count++] = (ILArray <ulong>)(ulong) 1; ret[count++] = (ILArray <ulong>)(ulong) uint.MaxValue; ret[count++] = (ILArray <ulong>)(ulong) uint.MinValue; ret[count++] = (ILArray <ulong>)(ulong) 0; ret[count++] = (ILArray <ulong>)(ulong)(30); // vector ret[count++] = ILMath.touint64(ILMath.zeros(1, 10)); ret[count++] = ILMath.touint64(ILMath.ones(1, 10)); ret[count++] = ILMath.touint64(ILMath.zeros(10, 1)); ret[count++] = ILMath.touint64(ILMath.ones(10, 1)); ret[count++] = ILMath.touint64(ILMath.vector(0.0, 10.0)); ret[count++] = ILMath.touint64(ILMath.vector(0.0, 14.0)); tmp = ILMath.touint64(ILMath.vector(0, 14.0)); tmp[0] = uint.MinValue; tmp["end"] = uint.MaxValue; tmp[3] = 0; ret[count++] = tmp; // matrix ret[count++] = ILMath.touint64(ILMath.zeros(3, 2)); ret[count++] = ILMath.touint64(ILMath.rand(2, 4)); ret[count++] = ILMath.touint64(ILMath.ones(2, 3) * double.NaN); ret[count++] = ILMath.touint64(ILMath.ones(3, 2) / 0.0); // inf // 3d array ret[count++] = ILMath.touint64(ILMath.zeros(4, 3, 2)); ret[count++] = ILMath.touint64(ILMath.ones(4, 3, 2)); ret[count++] = ILMath.touint64(0.0 / ILMath.zeros(4, 3, 2)); ret[count++] = ILMath.touint64(ILMath.ones(4, 3, 2) * uint.MinValue); ret[count++] = ILMath.touint64(ILMath.rand(4, 3, 2) * uint.MaxValue); // 4d array ret[count++] = ILMath.touint64(ILMath.rand(30, 2, 3, 20) * uint.MaxValue); return(ret); }
static void Main(string[] args) { using (ILScope.Enter()) { ILCell data = Helper.DBQuery(); // data is: //Cell [2,2] //[0]: <String> header 1 <Double> [100,200] //[1]: <String> header 2 <Single> [2,3000] // store into mat file ILMatFile mat = new ILMatFile(); var key1 = (string)data.GetArray <string>(0, 0); mat.AddArray(data.GetArray <double>(0, 1), key1); // stores rand(100,200) as key: "header1" // proceed with other columns... // write mat file mat.Write("filename"); } }
public static ILCell LoadImage(string path) { BitmapSource bitmapSource = new BitmapImage(new Uri(System.IO.Path.GetFullPath(path))); if (bitmapSource.Format != PixelFormats.Bgra32) { bitmapSource = new FormatConvertedBitmap(bitmapSource, PixelFormats.Bgra32, null, 0); } int width = bitmapSource.PixelWidth; int height = bitmapSource.PixelHeight; int bytes = (PixelFormats.Bgra32.BitsPerPixel + 7) / 8; int stride = (width * bytes); //Stream stream = (bitmapSource as BitmapImage).StreamSource; //BinaryReader br = new BinaryReader(stream); byte[] ba = new byte[width * height * bytes]; bitmapSource.CopyPixels(ba, stride, 0); ILArray <double> blue = new ILArray <double>(width, height); ILArray <double> green = new ILArray <double>(width, height); ILArray <double> red = new ILArray <double>(width, height); ILArray <double> alpha = new ILArray <double>(width, height); double[] b = blue.InternalArray4Experts; double[] g = green.InternalArray4Experts; double[] r = red.InternalArray4Experts; double[] a = alpha.InternalArray4Experts; for (int i = 0, j = 0; i < width * height * bytes; i += bytes) { b[j] = ba[i]; g[j] = ba[i + 1]; r[j] = ba[i + 2]; a[j] = ba[i + 3]; ++j; //b[i] = br.ReadByte(); //g[i] = br.ReadByte(); //r[i] = br.ReadByte(); //a[i] = br.ReadByte(); } ILCell cell = new ILCell(4); cell[0] = blue; cell[1] = green; cell[2] = red; cell[3] = alpha; return(cell); }
public override ILCell GenerateTestArrays() { ILCell ret = new ILCell(); int count = 0; // empty ILArray<long> tmp; ret[count++] = ILArray<long>.empty(0, 0); ret[count++] = ILArray<long>.empty(1, 0); ret[count++] = ILArray<long>.empty(0, 1, 0); // scalar ret[count++] = (ILArray<long>)(long)1; ret[count++] = (ILArray<long>)(long)int.MaxValue; ret[count++] = (ILArray<long>)(long)int.MinValue; ret[count++] = (ILArray<long>)(long)0; ret[count++] = (ILArray<long>) (long)(-30); // vector ret[count++] = ILMath.toint64(ILMath.zeros(1,10)); ret[count++] = ILMath.toint64(ILMath.ones(1,10)); ret[count++] = ILMath.toint64(ILMath.zeros(10,1)); ret[count++] = ILMath.toint64(ILMath.ones(10,1)); ret[count++] = ILMath.toint64(ILMath.vector(0.0,10.0)); ret[count++] = ILMath.toint64(ILMath.vector(-5.0,4.0)); tmp = ILMath.toint64(ILMath.vector(-5.0,4.0)); tmp[0] = int.MinValue; tmp["end"] = int.MaxValue; tmp[3] = 0; ret[count++] = tmp; // matrix ret[count++] = ILMath.toint64(ILMath.zeros(3,2)); ret[count++] = ILMath.toint64(ILMath.rand(2,4)); ret[count++] = ILMath.toint64(ILMath.ones(2,3)); ret[count++] = ILMath.toint64(ILMath.ones(3,2)); // 3d array ret[count++] = ILMath.toint64(ILMath.zeros(4, 3, 2)); ret[count++] = ILMath.toint64(ILMath.ones(4, 3, 2)); ret[count++] = ILMath.toint64(ILMath.toint32(0.0 / (ILMath.randn(4, 3, 2)))); ret[count++] = ILMath.toint64(ILMath.ones(4, 3, 2) * int.MinValue); ret[count++] = ILMath.toint64(ILMath.rand(4, 3, 2) * int.MaxValue); // 4d array ret[count++] = ILMath.toint64(ILMath.rand(30, 2, 3, 20) * int.MaxValue); return ret; }
public override ILCell GenerateTestArrays() { ILCell ret = new ILCell(); int count = 0; // empty ILArray<ulong> tmp; ret[count++] = ILArray<ulong>.empty(0, 0); ret[count++] = ILArray<ulong>.empty(1, 0); ret[count++] = ILArray<ulong>.empty(0, 1, 0); // scalar ret[count++] = (ILArray<ulong>)(ulong)1; ret[count++] = (ILArray<ulong>)(ulong)uint.MaxValue; ret[count++] = (ILArray<ulong>)(ulong)uint.MinValue; ret[count++] = (ILArray<ulong>)(ulong)0; ret[count++] = (ILArray<ulong>) (ulong)(30); // vector ret[count++] = ILMath.touint64(ILMath.zeros(1,10)); ret[count++] = ILMath.touint64(ILMath.ones(1,10)); ret[count++] = ILMath.touint64(ILMath.zeros(10,1)); ret[count++] = ILMath.touint64(ILMath.ones(10,1)); ret[count++] = ILMath.touint64(ILMath.vector(0.0,10.0)); ret[count++] = ILMath.touint64(ILMath.vector(0.0,14.0)); tmp = ILMath.touint64(ILMath.vector(0,14.0)); tmp[0] = uint.MinValue; tmp["end"] = uint.MaxValue; tmp[3] = 0; ret[count++] = tmp; // matrix ret[count++] = ILMath.touint64(ILMath.zeros(3,2)); ret[count++] = ILMath.touint64(ILMath.rand(2,4)); ret[count++] = ILMath.touint64(ILMath.ones(2,3) * double.NaN); ret[count++] = ILMath.touint64(ILMath.ones(3,2) / 0.0); // inf // 3d array ret[count++] = ILMath.touint64(ILMath.zeros(4, 3, 2)); ret[count++] = ILMath.touint64(ILMath.ones(4, 3, 2)); ret[count++] = ILMath.touint64(0.0 / ILMath.zeros(4, 3, 2)); ret[count++] = ILMath.touint64(ILMath.ones(4, 3, 2) * uint.MinValue); ret[count++] = ILMath.touint64(ILMath.rand(4, 3, 2) * uint.MaxValue); // 4d array ret[count++] = ILMath.touint64(ILMath.rand(30, 2, 3, 20) * uint.MaxValue ); return ret; }
public override ILCell GenerateTestArrays() { ILCell ret = new ILCell(); int count = 0; // empty ILArray<byte> tmp; ret[count++] = ILArray<byte>.empty(0, 0); ret[count++] = ILArray<byte>.empty(1, 0); ret[count++] = ILArray<byte>.empty(0, 1, 0); // scalar ret[count++] = (ILArray<byte>)(byte)1; ret[count++] = (ILArray<byte>)byte.MaxValue; ret[count++] = (ILArray<byte>)byte.MinValue; ret[count++] = (ILArray<byte>)(byte)0; ret[count++] = (ILArray<byte>) (byte)(30); // vector ret[count++] = ILMath.tobyte(ILMath.zeros(1,10)); ret[count++] = ILMath.tobyte(ILMath.ones(1,10)); ret[count++] = ILMath.tobyte(ILMath.zeros(10,1)); ret[count++] = ILMath.tobyte(ILMath.ones(10,1)); ret[count++] = ILMath.tobyte(ILMath.vector(0.0,10.0)); ret[count++] = ILMath.tobyte(ILMath.vector(-5.0,4.0)); tmp = ILMath.tobyte(ILMath.vector(-5.0,4.0)); tmp[0] = byte.MinValue; tmp["end"] = byte.MaxValue; tmp[3] = 0; ret[count++] = tmp; // matrix ret[count++] = ILMath.tobyte(ILMath.zeros(3,2)); ret[count++] = ILMath.tobyte(ILMath.rand(2,4)); ret[count++] = ILMath.tobyte(ILMath.ones(2,3) * double.NaN); ret[count++] = ILMath.tobyte(ILMath.ones(3,2) / 0.0); // inf // 3d array ret[count++] = ILMath.tobyte(ILMath.zeros(4, 3, 2)); ret[count++] = ILMath.tobyte(ILMath.ones(4, 3, 2)); ret[count++] = ILMath.tobyte(0.0 / ILMath.zeros(4, 3, 2)); ret[count++] = ILMath.tobyte(ILMath.ones(4, 3, 2) * byte.MinValue); ret[count++] = ILMath.tobyte(ILMath.rand(4, 3, 2) * byte.MaxValue - (byte.MaxValue / 2.0)); // 4d array ret[count++] = ILMath.tobyte(ILMath.rand(30, 2, 3, 20) * byte.MaxValue - (byte.MaxValue / 2.0)); return ret; }
public static ILCell LoadImage(string path) { BitmapSource bitmapSource = new BitmapImage(new Uri(System.IO.Path.GetFullPath(path))); if (bitmapSource.Format != PixelFormats.Bgra32) { bitmapSource = new FormatConvertedBitmap(bitmapSource, PixelFormats.Bgra32, null, 0); } int width = bitmapSource.PixelWidth; int height = bitmapSource.PixelHeight; int bytes = (PixelFormats.Bgra32.BitsPerPixel + 7) / 8; int stride = (width * bytes); //Stream stream = (bitmapSource as BitmapImage).StreamSource; //BinaryReader br = new BinaryReader(stream); byte[] ba = new byte[width * height * bytes]; bitmapSource.CopyPixels(ba, stride, 0); ILArray<double> blue = new ILArray<double>(width, height); ILArray<double> green = new ILArray<double>(width, height); ILArray<double> red = new ILArray<double>(width, height); ILArray<double> alpha = new ILArray<double>(width, height); double[] b = blue.InternalArray4Experts; double[] g = green.InternalArray4Experts; double[] r = red.InternalArray4Experts; double[] a = alpha.InternalArray4Experts; for (int i = 0, j = 0; i < width * height * bytes; i += bytes) { b[j] = ba[i]; g[j] = ba[i + 1]; r[j] = ba[i + 2]; a[j] = ba[i + 3]; ++j; //b[i] = br.ReadByte(); //g[i] = br.ReadByte(); //r[i] = br.ReadByte(); //a[i] = br.ReadByte(); } ILCell cell = new ILCell(4); cell[0] = blue; cell[1] = green; cell[2] = red; cell[3] = alpha; return cell; }
public divide(ILTestAutoGenerator generator) : base(generator) { #region binary parameterized version generator.RelativeTestCasePath = "divide"; int testCount = 0; ArrayProviders = ILTestPermutingArrayProvider.GetDefaultArrayTypes(2); #region overrides - ML does not recognize complex with imaginary part being zero List <ILResultOverride> overrides = new List <ILResultOverride>(); ILCell inputOverride = new ILCell(1, 2); inputOverride[0] = (ILArray <complex>) new complex(double.PositiveInfinity, double.PositiveInfinity); ILCell outputOverride = new ILCell(1, 2); outputOverride[0] = (ILArray <complex>) new complex(0.0, 0.0); ILResultOverride overr = new ILResultOverride(ArrayProviders["complex"], inputOverride, outputOverride); overrides.Add(overr); #endregion ILTestCaseDefinition divide1 = new ILTestCaseDefinition("TEST_ILMath_divide" + (testCount++).ToString(), "[{2}] = {0} ./ {1};", "{2}=ILMath.divide({0},{1});", 2, 1, overrides); CaseDefinitions.Add(divide1); #endregion }
public static ILCell PermuteTestArrays(params ILCell[] inputParameter) { if (inputParameter == null || inputParameter.Length == 0) { throw new Exception("no input parameter specified!"); } for (int i = 0; i < inputParameter.Length; i++) { if (inputParameter[i] == null || inputParameter[i].IsEmpty || !inputParameter[i].IsColumnVector) { throw new Exception("input parameter #" + i + " has wrong format. All parameters must be column vectors!"); } } ILCell ret = new ILCell(inputParameter[0].Length, inputParameter.Length); int[] curPos = new int[inputParameter.Length]; int p = 0, d = 0; while (d < curPos.Length) { for (int i = 0; i < curPos.Length; i++) { ret[p, i] = inputParameter[i][curPos[i], 0]; } p++; d = 0; while (d < curPos.Length) { if (curPos[d] < inputParameter[d].Length - 1) { curPos[d]++; break; } curPos[d++] = 0; } } return(ret); }
public override ILCell GenerateTestArrays() { ILCell ret = new ILCell(); int count = 0; complex[] elements = new complex[] { new complex(0.0,0.0), new complex(1.0,0.0), new complex(1.0,1.0), new complex(0.0,1.0), new complex(-1.0,0.0), new complex(-1.0,-1.0), new complex(0.0,-1.0), new complex(double.NaN,0.0), new complex(double.NaN,1.0), new complex(0.0,double.NaN), new complex(1.0,double.NaN), new complex(double.NaN,double.NaN), // 11 new complex(double.PositiveInfinity,0.0), new complex(double.PositiveInfinity,1.0), new complex(0.0,double.PositiveInfinity), new complex(1.0,double.PositiveInfinity), new complex(double.PositiveInfinity,double.PositiveInfinity), new complex(double.NegativeInfinity,0.0), new complex(double.NegativeInfinity,1.0), new complex(0.0,double.NegativeInfinity), new complex(1.0,double.NegativeInfinity), new complex(double.NegativeInfinity,double.NegativeInfinity), // mixed new complex(double.NaN,double.NegativeInfinity), new complex(double.NaN,double.PositiveInfinity), new complex(double.PositiveInfinity,double.NegativeInfinity), new complex(double.NegativeInfinity,double.PositiveInfinity), new complex(double.NaN,double.PositiveInfinity), new complex(double.NegativeInfinity,double.NaN), new complex(double.PositiveInfinity,double.NaN), new complex(double.MaxValue,double.NaN), new complex(double.MinValue,double.NaN), new complex(double.MaxValue,double.MinValue), new complex(double.NaN,double.MaxValue), new complex(double.NaN,double.MinValue), new complex(double.MaxValue,double.MinValue) }; // empty ILArray<complex> tmp; ret[count++] = ILArray<complex>.empty(0,0); ret[count++] = ILArray<complex>.empty(1, 0); ret[count++] = ILArray<complex>.empty(0, 1, 0); // scalar foreach (complex elem in elements) ret[count++] = (ILArray<complex>)elem; // vector ret[count++] = ILArray<complex>.zeros(1,10); ret[count++] = ILArray<complex>.zeros(1,10) + elements[2]; ret[count++] = ILArray<complex>.zeros(10,1); ret[count++] = ILArray<complex>.zeros(10,1) + elements[2]; ret[count++] = ILMath.ccomplex(ILMath.vector(0.0,10.0),ILMath.vector(0.0,10.0)); ret[count++] = ILMath.ccomplex(ILMath.vector(-5.0,4.0),-ILMath.vector(-5.0,4.0)); tmp = ILMath.ccomplex(ILMath.vector(-5.0,4.0),-ILMath.vector(-5.0,4.0)); tmp[0] = elements[22]; tmp["end"] = elements[25]; tmp[3] = elements[26]; ret[count++] = tmp; // matrix ret[count++] = ILArray<complex>.zeros(3,2); ret[count++] = ILMath.ccomplex(ILMath.rand(3,4),ILMath.rand(3,4)); ret[count++] = ILMath.ccomplex(ILMath.ones(2,3) * double.NaN,ILMath.ones(2,3) * double.NaN); ret[count++] = ILMath.ccomplex(ILMath.ones(3,2) / 0.0,ILMath.ones(3,2) / 0.0); // inf tmp = ILArray<complex>.zeros(3,2) + elements[2]; tmp[0] = elements[11]; // nans ret[count++] = tmp; tmp[1] = elements[15]; ret[count++] = tmp; tmp[3] = elements[20]; // neg inf ret[count++] = tmp; // 3d array ret[count++] = ILMath.ccomplex(ILMath.zeros(4, 3, 2),ILMath.zeros(4, 3, 2)); ret[count++] = ILMath.ccomplex(ILMath.ones(4, 3, 2),ILMath.ones(4, 3, 2)); ret[count++] = ILMath.ccomplex(0.0 / ILMath.zeros(4, 3, 2),0.0 / ILMath.zeros(4, 3, 2)); ret[count++] = ILMath.ccomplex(ILMath.ones(4, 3, 2) * float.NaN,ILMath.ones(4, 3, 2) * float.NaN); ret[count++] = ILMath.ccomplex(ILMath.ones(4, 3, 2) * float.NegativeInfinity,ILMath.ones(4, 3, 2) * float.NegativeInfinity); ret[count++] = ILMath.ccomplex(ILMath.rand(4, 3, 2),ILMath.rand(4, 3, 2)); // 4d array ret[count++] = ILMath.ccomplex(ILMath.rand(15, 12, 3, 10),ILMath.rand(15, 12, 3, 10)); return ret; }
/// <summary> /// linear discriminant analysis /// </summary> /// <param name="X">data matrix. Must be of size d x n, having samples arranged in columns </param> /// <param name="Labels">class labels for <paramref name="X"/>. </param> /// <param name="gamma">RLDA regularization parameter, with values between 0 and 1. /// GAMMA=0 gives normal LDA, GAMMA=1 uses a multiple of the identity matrix instead /// of the pooled covariance matrix.</param> /// <returns>cell array with discriminant hyperplane description</returns> /// <remarks><para><c>Labels</c> can be a vector of length n, having positive/negative values at indices /// corresponding to data X. Alternatively it is a 2 row matrix of length n with 1's in the first row at positions /// of data in the dirst class and 1's in the second row labeling the data in the second class.</para> /// <para>References: <list><item>J.H. Friedman, Regularized Discriminant Analysis, Journal /// of the Americal Statistical Association, vol.84(405), 1989. The method implemented here /// is Friedman's method with LAMDBA==1. </item> /// <item>The algorithm is base on implementation of Fraunhofer FIRST.IDA (2004)</item></list></para></remarks> public Hyperplane TrainLDA(ILArray<double> X, ILLogicalArray Labels, double gamma) { base.Run(); // <- will set state to 'Running' if (gamma > 1.0 || gamma < 0) throw new ILArgumentException("Regularization parameter gamma must be in range 0...1!"); // if size(yTr,1) == 1 yTr = [yTr<0; yTr>0]; end if (Labels.IsVector) Labels = new ILLogicalArray( vertcat(Labels < 0.0, Labels > 0.0)); //ind = find(sum(abs(xTr),1)==inf); //ILArray<double> ind = Find(sum(abs(X),1) == double.PositiveInfinity); // <- he? what if negative infinity ? Hm. //// xTr(:,ind) = []; //X[null,ind] = null; //// yTr(:,ind) = []; //Labels[null,ind] = null; // nClasses= size(yTr,1); int nClasses = Labels.Dimensions[0]; // clInd= cell(nClasses,1); ILCell clInd = new ILCell(nClasses,1); //N= zeros(nClasses, 1); int[] N = new int [nClasses]; int sumN = 0; //for ci= 1:nClasses, for (int ci = 0; ci < nClasses; ci++) { // clInd{ci} = find(yTr(ci,:)); clInd[ci] = find(Labels[ci,null]); // N(ci)= length(clInd{ci}); N[ci] = clInd[ci].Dimensions.Longest; sumN += N[ci]; } //priorP = ones(nClasses,1)/nClasses; ILArray<double> priorP = ones(nClasses,1) / nClasses; //d= size(xTr,1); int d = X.Dimensions[0]; //m= zeros(d, nClasses); ILArray<double> m = zeros(d,nClasses); //Sq= zeros(d, d); ILArray<double> Sq = zeros(d,d); //for ci= 1:nClasses, for (int ci = 0; ci < nClasses; ci++) { // cli= clInd{ci}; ILArray<double> cli = (ILArray<double>)clInd[ci]; // m(:,ci)= mean(xTr(:,cli),2); m[null,ci] = mean(X[null,cli],1); // % gleichanteil löschen: // yc= xTr(:,cli) - m(:,ci) * ones(1,N(ci)); ILArray<double> yc = X[null,cli] - repmat(m[null,ci],1,N[ci]); // % yc sind xTr Daten des ersten merkmals mit mean = 0 // Sq = Sq + yc*yc'; Sq = Sq + multiply(yc,yc.T); } //Sq= Sq/(sum(N)-1); Sq = Sq / (sumN-1); //Sq = (1-gamma)*Sq + gamma/d*trace(Sq)*eye(d); Sq = (1-gamma) * Sq + gamma/(double)d * sum(diag(Sq))*eye(d,d); //Sq = pinv(Sq); Sq = pinv(Sq); //C.w = Sq*m; ILArray<double> Cw = multiply(Sq,m); ILArray<double> Cb = -0.5 * sum(m*Cw,0).T + log(priorP); //if nClasses==2 if (nClasses == 2) { // C.w = C.w(:,2) - C.w(:,1); Cw = Cw[null,1] - Cw[null,0]; // C.b = C.b(2)-C.b(1); Cb = Cb[1] - Cb[0]; } Hyperplane C; C.w = Cw; //C.b = -0.5*sum(m.*C.w,1)' + log(priorP); C.b = Cb; SetState(ILAlgorithmState.Finished); return C; }
// in Form_Load the panel and all shapes should be created // and initialized. private void Form1_Load(object sender, EventArgs e) { // the ILPanel is created ... m_panel = ILPanel.Create(); // and added to the Controls collection of the form Controls.Add(m_panel); // a scene graph will hold our shapes ILSceneGraph scene = m_panel.Graphs.AddSceneGraph(); // data for the shapes are best created in the Computation // helper - keeping the GUI code clean ILCell data = Computation.CreatePendulaWeight(); // setup the first polygon. For creation we do // not specify vertex data yet. This will be done // later in the UpdateShapes function m_poly1 = new ILLitPolygon(m_panel, data[0].Dimensions[1]); m_poly1.Border.Width = 2; m_poly1.Border.Color = Color.Gray; m_poly1.Opacity = 180; m_poly1.CustomCenter = new ILPoint3Df(0, 0, 1); m_poly1.Label.Text = ""; // and add it to the scene. We create an individual node // for the weight' shapes. ILSceneGraphInnerNode weightNode = new ILSceneGraphInnerNode(m_panel); scene.AddNode(weightNode); weightNode.Add(m_poly1); // setup the 2nd polygon. The same size is here used as // for the first polygon. m_poly2 = new ILLitPolygon(m_panel, data[0].Dimensions[1]); m_poly2.Border.Width = 2; m_poly2.Border.Color = Color.Gray; m_poly2.Opacity = 180; m_poly2.Label.Text = ""; m_poly2.CustomCenter = new ILPoint3Df(0, 0, 1); weightNode.Add(m_poly2); // the same for the quads: only give the number // of vertices needed. Data are updated later m_quads = new ILLitQuads(m_panel, data[0].Dimensions[1] * 2); m_quads.FillColor = Color.Red; m_quads.Opacity = 180; m_quads.Label.Text = ""; m_quads.CustomCenter = new ILPoint3Df(0, 0, 1); // add the quads to the scene weightNode.Add(m_quads); // create the scale below the pendula weight ILCell lData = Computation.CreateScale(); ILArray <double> vert = lData[0] as ILArray <double>; ILArray <double> maps = lData[1] as ILArray <double>; m_lines = new ILLines(m_panel, vert[0.0, null], vert[1.0, null], vert[2.0, null], maps); m_lines.Label.Text = ""; m_lines.Properties.Color = Color.Black; m_lines.Shading = ShadingStyles.Flat; // the scale lines we put directly in the root node // (no need to create an extra inner node for them) scene.AddNode(m_lines); // initialize the shapes UpdateShapes(data); // Experiment with these panel settings! They get clear than! //m_panel.PlotBoxScreenSizeMode = PlotBoxScreenSizeMode.StrictOptimal; // default: Optimal //m_panel.AutoZoomContent = false; // (default: true) m_panel.AspectRatio = AspectRatioMode.MaintainRatios; //m_panel.Projection = Projection.Perspective; m_panel.InteractiveMode = InteractiveModes.Rotating; // setup the timer control m_timer = new Timer(); m_timer.Interval = 40; m_timer.Tick += new EventHandler(m_timer_Tick); m_timer.Start(); }
public void Test_Addressing() { int errorCode = 0; try { ILBaseArray[] data = new ILBaseArray[60]; for (int i = 0; i < data.Length; i++) { data[i] = new ILArray <Int16>(new Int16[1] { (Int16)i }); } ILCell A = new ILCell(data, 20, 3); A.Name = "A"; errorCode = 1; A[1, 1] = ILMath.vector(10, 100); A[2, 1] = ILMath.vector(-10, -1, -100); errorCode = 2; // test subarray access: single ILBaseArray ret = A[23]; ret.Name = "ret"; errorCode = 3; // single element returned should be inner ILBaseArray if (!(ret is ILArray <Int16>)) { throw new Exception("ILCell: single element returned should be of ILArray<double> type"); } ILArray <Int16> a23 = (ILArray <Int16>)ret; a23.Name = "a23"; if (!a23.IsScalar || a23 != 23.0) { throw new Exception("ILCell: returned element value mismatch! Expected: 23, found:" + a23.GetValue(0)); } errorCode = 4; // test subarray access: multiple via vector (sequential) // - put Cell into cell ILArray <double> element1 = ILMath.vector(10, 2, 20); element1.Name = "element1"; ILArray <double> element2 = ILMath.vector(20, 2, 30); element2.Name = "element2"; ILCell innerCell = new ILCell(new ILBaseArray[] { element1, element2 }, 2, 1); A[3, 1] = innerCell; ILArray <double> ind = new ILArray <double>(new double[] { 20.0, 21.0, 22.0, 23.0, 24.0 }); ind.Name = "ind"; ILCell cellresult_vect = (ILCell)A[ind]; cellresult_vect.Name = "cellresult_vect"; if (!cellresult_vect.IsRowVector || cellresult_vect.Dimensions[0] != 1 || cellresult_vect.Dimensions[1] != 5) { throw new Exception("ILCell: index access dimension mismatch: should be ILCell 1x5! "); } if (!(cellresult_vect[0, 0] is ILArray <short>) || !(cellresult_vect[0, 1] is ILArray <double>) || !(cellresult_vect[0, 2] is ILArray <double>) || !(cellresult_vect[0, 3] is ILCell) || !(cellresult_vect[0, 4] is ILArray <short>)) { throw new Exception("ILCell: index access failed. Inner element mismatch for vector indices."); } errorCode = 5; // test if elements returned are properly referenced (detached from original) ILArray <short> tmps = (ILArray <short>)cellresult_vect[0, 0]; tmps.Name = "tmps"; if (!tmps.IsScalar || (tmps != 20.0)) { throw new Exception("ILCell: invalid value returned: expected:20, found:" + tmps.GetValue(0)); } ILArray <double> tmp = (ILArray <double>)cellresult_vect[1]; tmp.Name = "tmp"; if (!tmp.IsVector || (bool)(tmp.Length != 91) || (bool)(tmp[0] != 10) || (bool)(tmp["end"] != 100)) { throw new Exception("ILCell: invalid value returned: expected double vector 10:2:20"); } tmp = (ILArray <double>)cellresult_vect[2]; if (!tmp.IsVector || (bool)(tmp.Length != 91) || (bool)(tmp[0] != -10) || (bool)(tmp["end"] != -100)) { throw new Exception("ILCell: invalid value returned: expected vector 20:2:30"); } tmps = (ILArray <short>)cellresult_vect[4]; if (!tmps.IsScalar || (bool)(tmps["end"] != 24.0)) { throw new Exception("ILCell: invalid value returned: expected short 24, found: " + tmps.GetValue(0)); } cellresult_vect[0, 3, 1, 0, 1] = -111.0; if ((ILArray <double>)cellresult_vect[0, 3, 1, 0, 1] != -111.0) { throw new Exception("ILCell: invalid result of inner element index access: expected: -111.0, found: " + ((ILArray <double>)cellresult_vect[0, 3, 1, 0, 1]).GetValue(0)); } errorCode = 6; // test if original still intact if (!A[3, 1, 1, 0, 1].IsScalar || (ILArray <double>)A[3, 1, 1, 0, 1] != 22.0) { throw new Exception("ILCell: original should not be altered if reference was altered! A[3,1,1,0,1] = " + ((ILArray <double>)A[3, 1, 1, 0, 1]).GetValue(0)); } // test subarray access: matrix (sequential) ********************************************** errorCode = 7; ind = new ILArray <double>(new double[6] { 20.0, 21.0, 22.0, 23.0, 24.0, 25.0 }, 3, 2); ind.Name = "ind"; cellresult_vect = (ILCell)A[ind]; cellresult_vect.Name = "cellresult_vect"; if (!cellresult_vect.IsMatrix || cellresult_vect.Dimensions[0] != 3 || cellresult_vect.Dimensions[1] != 2) { throw new Exception("ILCell: index access dimension mismatch: should be ILCell 3x2! "); } if (!(cellresult_vect[0, 0] is ILArray <short>) || !(cellresult_vect[1, 0] is ILArray <double>) || !(cellresult_vect[2, 0] is ILArray <double>) || !(cellresult_vect[0, 1] is ILCell) || !(cellresult_vect[1, 1] is ILArray <short>) || !(cellresult_vect[2, 1] is ILArray <short>)) { throw new Exception("ILCell: index access failed. Inner element mismatch for vector indices."); } if (!(cellresult_vect[0] is ILArray <short>) || !(cellresult_vect[1] is ILArray <double>) || !(cellresult_vect[2] is ILArray <double>) || !(cellresult_vect[3] is ILCell) || !(cellresult_vect[4] is ILArray <short>) || !(cellresult_vect[5] is ILArray <short>)) { throw new Exception("ILCell: index access failed. Inner element mismatch for vector indices."); } errorCode = 8; // test if elements returned are properly referenced (detached from original) tmps = (ILArray <short>)cellresult_vect[0, 0]; tmps.Name = "tmps"; if (!tmps.IsScalar || (byte)tmps != 20.0) { throw new Exception("ILCell: invalid value returned: expected:20, found:" + tmps.GetValue(0)); } tmp = (ILArray <double>)cellresult_vect[1]; tmp.Name = "tmp"; if (!tmp.IsVector || tmp.Length != 91 || tmp[0] != 10.0 || tmp["end"] != 100.0) { throw new Exception("ILCell: invalid value returned: expected double vector 10:2:20"); } tmp = (ILArray <double>)cellresult_vect[2]; if (!tmp.IsVector || tmp.Length != 91 || tmp[0] != -10.0 || tmp["end"] != -100.0) { throw new Exception("ILCell: invalid value returned: expected vector 20:2:30"); } tmps = (ILArray <short>)cellresult_vect[4]; if (!tmps.IsScalar || (byte)tmps["end"] != 24.0) { throw new Exception("ILCell: invalid value returned: expected short 24, found: " + tmps.GetValue(0)); } cellresult_vect[0, 1, 1, 0, 1] = -111.0; if ((double)(ILArray <double>)cellresult_vect[0, 1, 1, 0, 1] != -111.0) { throw new Exception("ILCell: invalid result of inner element index access: expected: -111.0, found: " + ((ILArray <double>)cellresult_vect[0, 3, 1, 0, 1]).GetValue(0)); } errorCode = 9; // test if original still untouched if ((ILArray <double>)A[3, 1, 1, 0, 1] != 22.0) { throw new Exception("ILCell: original should not be altered if reference was altered! A[3,1,1,0,1] = " + ((ILArray <double>)A[3, 1, 1, 0, 1]).GetValue(0)); } // test sequential index array set acces innerCell = new ILCell(4, 3, 2); innerCell[0] = ILMath.vector(20, -3, -100); innerCell[1] = ((ILArray <double>)innerCell[0] < 0.0); ILCell rangedsource = new ILCell(new ILBaseArray [] { new ILArray <int>(3333), new ILLogicalArray(1), ILMath.vector(1000, 2000), innerCell }, 2, 2); ILArray <double> range = new ILArray <double>(new double[] { 0, 51, 52, 59 }); A[range] = rangedsource; if (!(A[0] is ILArray <int>)) { throw new Exception("ILCell: seq.ranged set mismatch. index 0"); } if (!(A[51] is ILLogicalArray)) { throw new Exception("ILCell: seq.ranged set mismatch. index 1"); } if (!(A[52] is ILArray <double>)) { throw new Exception("ILCell: seq.ranged set mismatch. index 2"); } if (!(A[59] is ILCell)) { throw new Exception("ILCell: seq.ranged set mismatch. index 3"); } errorCode = 10; // test detached referencing (alter elements of query result) // test index access for ranges via ILBaseArray[] data = new ILBaseArray[60]; for (int i = 0; i < data.Length; i++) { data[i] = new ILArray <Int16>(new Int16[] { (Int16)i }); } A = new ILCell(data, 20, 3); A.Name = "A"; ILArray <double> r = ILMath.vector(0, 2); ILArray <short> c = (ILArray <short>)ILMath.ones(NumericType.Int16, 1); ILCell rangeGet = (ILCell)A[r, c]; if (rangeGet.Dimensions[0] != 3 || rangeGet.Dimensions[1] != 1) { throw new Exception("ILCell: ranged index get access via ILBaseArray failed. Wrong dimension returned."); } if ((ILArray <short>)rangeGet[0, 0] != 20.0) { throw new Exception("ILCell: invalid index returned: exp.20, found:" + ((ILArray <int>)rangeGet[0, 0]).GetValue(0)); } A[0, 1] = new ILArray <double>(17, 18, 1000); if ((ILArray <short>)rangeGet[0, 0] != 20.0) { throw new Exception("ILCell: invalid index returned: exp.20, found:" + ((ILArray <double>)rangeGet[0, 0]).GetValue(0) + ". The reference returned was not detached properly!"); } errorCode = 11; // test ranged setter A[c, r] = A[c + 10, r]; if ((ILArray <short>)A[1, 1] != 31.0) { throw new Exception("Wrong value found after copying part of cell to other position."); } A[1, 1] = -1122.0; if ((ILArray <short>)A[11, 1] != 31.0 || (ILArray <double>)A[1, 1] != -1122.0) { throw new Exception("wrong value stored or reference not properly un-linked in ILCell."); } // test removal of elements errorCode = 12; A[new ILArray <double>(new double[] { 4.0, 5.0, 11.0 }), null] = null; if (A.Dimensions[0] != 17 || A.Dimensions[1] != 3) { throw new Exception("ILCell removal via ILBaseArray[] failed."); } A[new ILArray <double>(new double[] { 4.0, 5.0, 11.0 })] = null; if (A.Dimensions[0] != 1 || A.Dimensions[1] != 48) { throw new Exception("ILCell removal via sequential indexes failed!"); } errorCode = 13; // test if error on removal will restore old dimensions A = new ILCell(2, 3, 2); ind = new double[] { 15, 16, 22, 223 }; try { A[ind] = null; throw new Exception("ILCell remove: index out of range not signaled!"); } catch (Exception) {} if (A.Dimensions[0] != 2 || A.Dimensions[1] != 3 || A.Dimensions[2] != 2) { throw new Exception("ILCell: error on remove should restore old dimensions!"); } Success(); } catch (Exception e) { Error(errorCode, e.Message); } }
public override ILCell GenerateTestArrays() { ILCell ret = new ILCell(); int count = 0; complex[] elements = new complex[] { new complex(0.0, 0.0), new complex(1.0, 0.0), new complex(1.0, 1.0), new complex(0.0, 1.0), new complex(-1.0, 0.0), new complex(-1.0, -1.0), new complex(0.0, -1.0), new complex(double.NaN, 0.0), new complex(double.NaN, 1.0), new complex(0.0, double.NaN), new complex(1.0, double.NaN), new complex(double.NaN, double.NaN), // 11 new complex(double.PositiveInfinity, 0.0), new complex(double.PositiveInfinity, 1.0), new complex(0.0, double.PositiveInfinity), new complex(1.0, double.PositiveInfinity), new complex(double.PositiveInfinity, double.PositiveInfinity), new complex(double.NegativeInfinity, 0.0), new complex(double.NegativeInfinity, 1.0), new complex(0.0, double.NegativeInfinity), new complex(1.0, double.NegativeInfinity), new complex(double.NegativeInfinity, double.NegativeInfinity), // mixed new complex(double.NaN, double.NegativeInfinity), new complex(double.NaN, double.PositiveInfinity), new complex(double.PositiveInfinity, double.NegativeInfinity), new complex(double.NegativeInfinity, double.PositiveInfinity), new complex(double.NaN, double.PositiveInfinity), new complex(double.NegativeInfinity, double.NaN), new complex(double.PositiveInfinity, double.NaN), new complex(double.MaxValue, double.NaN), new complex(double.MinValue, double.NaN), new complex(double.MaxValue, double.MinValue), new complex(double.NaN, double.MaxValue), new complex(double.NaN, double.MinValue), new complex(double.MaxValue, double.MinValue) }; // empty ILArray <complex> tmp; ret[count++] = ILArray <complex> .empty(0, 0); ret[count++] = ILArray <complex> .empty(1, 0); ret[count++] = ILArray <complex> .empty(0, 1, 0); // scalar foreach (complex elem in elements) { ret[count++] = (ILArray <complex>)elem; } // vector ret[count++] = ILArray <complex> .zeros(1, 10); ret[count++] = ILArray <complex> .zeros(1, 10) + elements[2]; ret[count++] = ILArray <complex> .zeros(10, 1); ret[count++] = ILArray <complex> .zeros(10, 1) + elements[2]; ret[count++] = ILMath.ccomplex(ILMath.vector(0.0, 10.0), ILMath.vector(0.0, 10.0)); ret[count++] = ILMath.ccomplex(ILMath.vector(-5.0, 4.0), -ILMath.vector(-5.0, 4.0)); tmp = ILMath.ccomplex(ILMath.vector(-5.0, 4.0), -ILMath.vector(-5.0, 4.0)); tmp[0] = elements[22]; tmp["end"] = elements[25]; tmp[3] = elements[26]; ret[count++] = tmp; // matrix ret[count++] = ILArray <complex> .zeros(3, 2); ret[count++] = ILMath.ccomplex(ILMath.rand(3, 4), ILMath.rand(3, 4)); ret[count++] = ILMath.ccomplex(ILMath.ones(2, 3) * double.NaN, ILMath.ones(2, 3) * double.NaN); ret[count++] = ILMath.ccomplex(ILMath.ones(3, 2) / 0.0, ILMath.ones(3, 2) / 0.0); // inf tmp = ILArray <complex> .zeros(3, 2) + elements[2]; tmp[0] = elements[11]; // nans ret[count++] = tmp; tmp[1] = elements[15]; ret[count++] = tmp; tmp[3] = elements[20]; // neg inf ret[count++] = tmp; // 3d array ret[count++] = ILMath.ccomplex(ILMath.zeros(4, 3, 2), ILMath.zeros(4, 3, 2)); ret[count++] = ILMath.ccomplex(ILMath.ones(4, 3, 2), ILMath.ones(4, 3, 2)); ret[count++] = ILMath.ccomplex(0.0 / ILMath.zeros(4, 3, 2), 0.0 / ILMath.zeros(4, 3, 2)); ret[count++] = ILMath.ccomplex(ILMath.ones(4, 3, 2) * float.NaN, ILMath.ones(4, 3, 2) * float.NaN); ret[count++] = ILMath.ccomplex(ILMath.ones(4, 3, 2) * float.NegativeInfinity, ILMath.ones(4, 3, 2) * float.NegativeInfinity); ret[count++] = ILMath.ccomplex(ILMath.rand(4, 3, 2), ILMath.rand(4, 3, 2)); // 4d array ret[count++] = ILMath.ccomplex(ILMath.rand(15, 12, 3, 10), ILMath.rand(15, 12, 3, 10)); return(ret); }
/// <summary> /// linear discriminant analysis /// </summary> /// <param name="X">data matrix. Must be of size d x n, having samples arranged in columns </param> /// <param name="Labels">class labels for <paramref name="X"/>. </param> /// <param name="gamma">RLDA regularization parameter, with values between 0 and 1. /// GAMMA=0 gives normal LDA, GAMMA=1 uses a multiple of the identity matrix instead /// of the pooled covariance matrix.</param> /// <returns>cell array with discriminant hyperplane description</returns> /// <remarks><para><c>Labels</c> can be a vector of length n, having positive/negative values at indices /// corresponding to data X. Alternatively it is a 2 row matrix of length n with 1's in the first row at positions /// of data in the dirst class and 1's in the second row labeling the data in the second class.</para> /// <para>References: <list><item>J.H. Friedman, Regularized Discriminant Analysis, Journal /// of the Americal Statistical Association, vol.84(405), 1989. The method implemented here /// is Friedman's method with LAMDBA==1. </item> /// <item>The algorithm is base on implementation of Fraunhofer FIRST.IDA (2004)</item></list></para></remarks> public Hyperplane TrainLDA(ILArray <double> X, ILLogicalArray Labels, double gamma) { base.Run(); // <- will set state to 'Running' if (gamma > 1.0 || gamma < 0) { throw new ILArgumentException("Regularization parameter gamma must be in range 0...1!"); } // if size(yTr,1) == 1 yTr = [yTr<0; yTr>0]; end if (Labels.IsVector) { Labels = new ILLogicalArray(vertcat(Labels <0.0, Labels> 0.0)); } //ind = find(sum(abs(xTr),1)==inf); //ILArray<double> ind = Find(sum(abs(X),1) == double.PositiveInfinity); // <- he? what if negative infinity ? Hm. //// xTr(:,ind) = []; //X[null,ind] = null; //// yTr(:,ind) = []; //Labels[null,ind] = null; // nClasses= size(yTr,1); int nClasses = Labels.Dimensions[0]; // clInd= cell(nClasses,1); ILCell clInd = new ILCell(nClasses, 1); //N= zeros(nClasses, 1); int[] N = new int [nClasses]; int sumN = 0; //for ci= 1:nClasses, for (int ci = 0; ci < nClasses; ci++) { // clInd{ci} = find(yTr(ci,:)); clInd[ci] = find(Labels[ci, null]); // N(ci)= length(clInd{ci}); N[ci] = clInd[ci].Dimensions.Longest; sumN += N[ci]; } //priorP = ones(nClasses,1)/nClasses; ILArray <double> priorP = ones(nClasses, 1) / nClasses; //d= size(xTr,1); int d = X.Dimensions[0]; //m= zeros(d, nClasses); ILArray <double> m = zeros(d, nClasses); //Sq= zeros(d, d); ILArray <double> Sq = zeros(d, d); //for ci= 1:nClasses, for (int ci = 0; ci < nClasses; ci++) { // cli= clInd{ci}; ILArray <double> cli = (ILArray <double>)clInd[ci]; // m(:,ci)= mean(xTr(:,cli),2); m[null, ci] = mean(X[null, cli], 1); // % gleichanteil löschen: // yc= xTr(:,cli) - m(:,ci) * ones(1,N(ci)); ILArray <double> yc = X[null, cli] - repmat(m[null, ci], 1, N[ci]); // % yc sind xTr Daten des ersten merkmals mit mean = 0 // Sq = Sq + yc*yc'; Sq = Sq + multiply(yc, yc.T); } //Sq= Sq/(sum(N)-1); Sq = Sq / (sumN - 1); //Sq = (1-gamma)*Sq + gamma/d*trace(Sq)*eye(d); Sq = (1 - gamma) * Sq + gamma / (double)d * sum(diag(Sq)) * eye(d, d); //Sq = pinv(Sq); Sq = pinv(Sq); //C.w = Sq*m; ILArray <double> Cw = multiply(Sq, m); ILArray <double> Cb = -0.5 * sum(m * Cw, 0).T + log(priorP); //if nClasses==2 if (nClasses == 2) { // C.w = C.w(:,2) - C.w(:,1); Cw = Cw[null, 1] - Cw[null, 0]; // C.b = C.b(2)-C.b(1); Cb = Cb[1] - Cb[0]; } Hyperplane C; C.w = Cw; //C.b = -0.5*sum(m.*C.w,1)' + log(priorP); C.b = Cb; SetState(ILAlgorithmState.Finished); return(C); }
public ILResultOverride(ILTestArrayProvider testArrayProvider, ILCell inputs, ILCell outputs) { m_outputs = outputs; m_inputs = inputs; m_testArrayProvider = testArrayProvider; }
/// <summary> /// generate single test case /// </summary> /// <param name="arrProv">test data provider (ILCell, specific type)</param> /// <param name="definition">case definition</param> /// <returns>localPostfixedTestCaseName</returns> public string AutoCreateTestCase(ILTestArrayProvider arrProv, ILTestCaseDefinition definition) { StringBuilder ocs = new StringBuilder("clear output*;"); string matInputFileName = INPUT_PARAMETER_PREFIX + ".mat"; string matOutputFileName = OUTPUT_PARAMETER_PREFIX + ".mat"; string resultOverridesFileName = OVERRIDES_PARAMETER_PREFIX + ".mat"; ILCell inputVars = arrProv.GenerateTestArrays(); ILMatFile matFile = new ILMatFile(); List <string> inTag = new List <string>(); List <string> outTag = new List <string>(); string outTagJoined; string inTagJoined; ocs.Append("\n" + String.Format("parameter = load('{0}');", matInputFileName)); for (int i = 0; i < inputVars.Dimensions[0]; i++) { inTag.Clear(); outTag.Clear(); // handle input parameters for (int c = 0; c < definition.InputParameterCount; c++) { string ident = "_" + i.ToString() + "_" + c.ToString(); matFile[INPUT_PARAMETER_PREFIX + ident] = inputVars.GetValue(i, c); inTag.Add("parameter." + INPUT_PARAMETER_PREFIX + ident); } // handle output parameters for (int c = 0; c < definition.OutputParameterCount; c++) { string ident = "_" + i.ToString() + "_" + c.ToString(); outTag.Add(OUTPUT_PARAMETER_PREFIX + ident); } //outTagJoined = String.Join(",", outTag.ToArray()); //inTagJoined = String.Join(",", inTag.ToArray()); List <object> allTags = new List <object>(); foreach (string s in inTag) { allTags.Add(s); } foreach (string s in outTag) { allTags.Add(s); } string octaveFuncCall = String.Format(definition.OctaveFunctionDef, allTags.ToArray()); ocs.Append(String.Format("\ntry {0} catch {1} = 'Exception'; end", octaveFuncCall, outTag[0])); } // the name for the case directory will be postfixed with the arrayprovider types ('double',...) string localPostfixedTestCaseName = definition.TestCaseName + "_" + arrProv.GetIdentifierPostfix(); string TestCaseOutputPath = Path.Combine(m_baseDirectory, RelativeTestCasePath); TestCaseOutputPath = Path.Combine(TestCaseOutputPath, localPostfixedTestCaseName) + Path.DirectorySeparatorChar; if (Directory.Exists(TestCaseOutputPath)) { Directory.Delete(TestCaseOutputPath, true); } Directory.CreateDirectory(TestCaseOutputPath); // save matfile using (Stream outStream = new FileStream(TestCaseOutputPath + matInputFileName, FileMode.Create)) { matFile.Write(outStream); } // finish + save creation script ocs.Append(String.Format("\n\nsave ('{0}','{1}*','-v6');", matOutputFileName, OUTPUT_PARAMETER_PREFIX)); File.WriteAllText(TestCaseOutputPath + OCTAVE_CREATION_SCRIPT_NAME, ocs.ToString()); #region create test class file inTag.Clear(); outTag.Clear(); List <string> inTagR = new List <string>(); StringBuilder testRunFunc = new StringBuilder(); // handles input parameter for (int i = 0; i < definition.InputParameterCount; i++) { testRunFunc.Append(String.Format(@"{1} {2}{0} = ({1})m_inputMatfile[""{2}_""+id.ToString()+""_{0}""]; {2}{0}.Detach();" , i.ToString(), arrProv.GetCSharpTypeDefinition(), INPUT_PARAMETER_PREFIX)); inTag.Add(INPUT_PARAMETER_PREFIX + i.ToString()); inTagR.Add(INPUT_PARAMETER_PREFIX + i.ToString() + ".R"); } // handles output parameter StringBuilder errorCheckString = new StringBuilder(); for (int i = 0; i < definition.OutputParameterCount; i++) { testRunFunc.Append(Environment.NewLine + "\t\t\t\t" + String.Format(@"ILBaseArray parameter{0} = null;", i)); outTag.Add("parameter" + i.ToString()); // error checking errorCheckString.Append(String.Format(@" if (!(parameter{0}.IsEmpty & m_outputMatfile[""output_""+id.ToString()+""_{0}""].IsEmpty) && (!TestHelper.TestEqualSloppy(parameter{0},m_outputMatfile[""{1}_""+id.ToString()+""_{0}""]))) {{ Error(""result{0} does not match expected value! parameterset: #""+id.ToString()+"",input #0: "" + input0.Dimensions.ToString()); return ProcessParameterErrorInfo(id, parameter{0}, {2}, {3}, {0}, m_inputMatfile, m_outputMatfile,{4}); }}", i.ToString(), OUTPUT_PARAMETER_PREFIX, definition.InputParameterCount, definition.OutputParameterCount, escape(definition.TargetFunctionDef))); } outTagJoined = String.Join(",", outTag.ToArray()); inTagJoined = String.Join(",", inTag.ToArray()); string inTagRJoined = String.Join(",", inTagR.ToArray()); inTag.AddRange(outTag); inTagR.AddRange(outTag); string targetFunction = String.Format(definition.TargetFunctionDef, inTag.ToArray()); // create dense test testRunFunc.Append(Environment.NewLine + "\t\t\t\t" + targetFunction); testRunFunc.Append(errorCheckString.ToString()); // create reference test targetFunction = String.Format(definition.TargetFunctionDef, inTagR.ToArray()); testRunFunc.Append(Environment.NewLine + "\t\t\t\t" + targetFunction); testRunFunc.Append(errorCheckString.ToString()); // finish string runtimeRelPath2matFiles = Path.Combine(m_baseDirectoryRelative2EXE, RelativeTestCasePath) + Path.DirectorySeparatorChar + localPostfixedTestCaseName + Path.DirectorySeparatorChar; string testClass = String.Format(HEADER, localPostfixedTestCaseName, // 0 runtimeRelPath2matFiles + matInputFileName, runtimeRelPath2matFiles + matOutputFileName, // 1,2 inputVars.Dimensions[0].ToString(), testRunFunc.ToString(), arrProv.GetCSharpTypeDefinition(), runtimeRelPath2matFiles + resultOverridesFileName); File.WriteAllText(TestCaseOutputPath + localPostfixedTestCaseName + ".cs", testClass); #endregion if (DeleteResultsOnRecreate) { if (File.Exists(TestCaseOutputPath + matOutputFileName)) { File.Delete(TestCaseOutputPath + matOutputFileName); } } #region write ResultOverrides if (definition.ResultOverrides != null) { ILMatFile overridesMatFile = new ILMatFile(); bool mustWriteOverrides = false; foreach (ILResultOverride overr in definition.ResultOverrides) { if (overr.TestArrayProvider == arrProv) { // foreach override find matching parameters in current provider for (int o = 0; o < overr.Inputs.Dimensions[0]; o++) { for (int i = 0; i < inputVars.Dimensions[0]; i++) { if (ILMath.isequalwithequalnans( overr.Inputs[o, null], inputVars[i, null])) { // matching override found System.Diagnostics.Debug.Assert(overr.Outputs.Dimensions[1] == inputVars.Dimensions[1]); for (int c = 0; c < inputVars.Dimensions[1]; c++) { string ident = "_" + i.ToString() + "_" + c.ToString(); overridesMatFile[OUTPUT_PARAMETER_PREFIX + ident] = overr.Outputs[o, c]; } mustWriteOverrides = true; } } } } } if (mustWriteOverrides) { using (FileStream overridesStream = new FileStream(TestCaseOutputPath + OVERRIDES_PARAMETER_PREFIX + ".mat", FileMode.Create)) { overridesMatFile.Write(overridesStream); } } else if (File.Exists(TestCaseOutputPath + OVERRIDES_PARAMETER_PREFIX + ".mat")) { File.Delete(TestCaseOutputPath + OVERRIDES_PARAMETER_PREFIX + ".mat"); } } #endregion return(localPostfixedTestCaseName); }
public max_min(ILTestAutoGenerator generator) : base(generator) { ArrayProviders.Add("double", new ILTestProviderDouble()); ArrayProviders.Add("float", new ILTestProviderSingle()); ArrayProviders.Add("complex", new ILTestProviderComplex()); ArrayProviders.Add("fcomplex", new ILTestProviderFComplex()); ArrayProviders.Add("int16", new ILTestProviderInt16()); ArrayProviders.Add("int32", new ILTestProviderInt32()); ArrayProviders.Add("uint16", new ILTestProviderUInt16()); ArrayProviders.Add("uint32", new ILTestProviderUInt32()); //Matlab produces results of type double on max(char) //arrayProviders.Add("char",new ILTestProviderChar()); ArrayProviders.Add("byte", new ILTestProviderByte()); int count = 0; #region TEST R = max(A) #region create overrides (since even ML is not perfect! ;) ) // here: max should really ignore NaNs in complex array! (Matlab [Rel. 13] does not) List <ILResultOverride> overrides = new List <ILResultOverride>(); ILCell correctResultComplex = new ILCell(1, 1); correctResultComplex[0, 0] = new ILArray <complex>(new complex[] { new complex(double.NegativeInfinity, double.PositiveInfinity) }); ILCell input2override = new ILCell(1, 1); input2override[0, 0] = ArrayProviders["complex"].GenerateTestArrays()[44, null]; overrides.Add(new ILResultOverride(ArrayProviders["complex"], input2override, correctResultComplex)); ILCell correctResultFcomplex = new ILCell(1, 1); correctResultFcomplex[0, 0] = new ILArray <fcomplex>(new fcomplex[] { new fcomplex(float.NegativeInfinity, float.PositiveInfinity) }); input2override = new ILCell(1, 1); input2override[0, 0] = ArrayProviders["fcomplex"].GenerateTestArrays()[44, null]; overrides.Add(new ILResultOverride(ArrayProviders["fcomplex"], input2override, correctResultFcomplex)); #endregion ILTestCaseDefinition testCaseDef = new ILTestCaseDefinition("TEST_ILMath_max", "[{1}] = max({0});", "{1}=ILMath.max({0});", 1, 1, overrides); generator.RelativeTestCasePath = "max" + (count++).ToString("d4"); CaseDefinitions.Add(testCaseDef); #endregion CaseDefinitions.Add(new ILTestCaseDefinition("TEST_ILMath_maxdim", "[{1}] = max({0},[],1);", "{1}=ILMath.max({0},ref NULL_INPUT_DOUBLE, 0);", 1, 1, overrides)); CaseDefinitions.Add(new ILTestCaseDefinition("TEST_ILMath_maxdim2", "[{1}] = max({0},[],2);", "{1}=ILMath.max({0},ref NULL_INPUT_DOUBLE, 1);", 1, 1)); Run(false, true); #region TEST min generator.RelativeTestCasePath = "min" + (count++).ToString("d4"); overrides = new List <ILResultOverride>(); correctResultComplex = new ILCell(1, 1); correctResultComplex[0] = new ILArray <complex>(new complex[] { new complex(0, 0) }); input2override = new ILCell(1, 1); input2override[0] = ArrayProviders["complex"].GenerateTestArrays()[44, null]; ILResultOverride overrideMinComplexNan = new ILResultOverride( ArrayProviders["complex"], input2override, correctResultComplex); overrides.Add(overrideMinComplexNan); correctResultFcomplex = new ILCell(1, 1); correctResultFcomplex[0] = new ILArray <fcomplex>(new fcomplex[] { new fcomplex(0, 0) }); input2override = new ILCell(1, 1); input2override[0] = ArrayProviders["fcomplex"].GenerateTestArrays()[44, null]; ILResultOverride overrideMinFComplexNan = new ILResultOverride( ArrayProviders["fcomplex"], input2override, correctResultFcomplex); overrides.Add(overrideMinFComplexNan); CaseDefinitions.Add(new ILTestCaseDefinition("TEST_ILMath_min", "[{1}] = min({0});", "{1}=ILMath.min({0});", 1, 1, overrides)); CaseDefinitions.Add(new ILTestCaseDefinition("TEST_ILMath_mindim", "[{1}] = min({0},[],1);", "{1}=ILMath.min({0},ref NULL_INPUT_DOUBLE, 0);", 1, 1, overrides)); CaseDefinitions.Add(new ILTestCaseDefinition("TEST_ILMath_mindim2", "[{1}] = min({0},[],2);", "{1}=ILMath.min({0},ref NULL_INPUT_DOUBLE, 1);", 1, 1)); Run(true, true); #endregion /////////////////////////// char //////////////////////////////////// /* the problem: matlab R13 max() function returns double class on char input, also -v6 is buggy by * not storing char as uint16 but as uint8 */ generator.RelativeTestCasePath = "maxmin32_char" + (count++).ToString("d4"); ArrayProviders.Add("int", new ILTestProviderUInt32MaxChar()); CaseDefinitions.Add(new ILTestCaseDefinition("TEST_ILMath_max", "[{1}] = max({0});", "{1}=ILMath.touint32(ILMath.max(ILMath.tochar({0})));", 1, 1)); CaseDefinitions.Add(new ILTestCaseDefinition("TEST_ILMath_maxdim", "[{1}] = max({0},[],1);", "{1}=ILMath.touint32(ILMath.max(ILMath.tochar({0}),ref NULL_INPUT_DOUBLE, 0));", 1, 1)); CaseDefinitions.Add(new ILTestCaseDefinition("TEST_ILMath_maxdim2", "[{1}] = max({0},[],2);", "{1}=ILMath.touint32(ILMath.max(ILMath.tochar({0}),ref NULL_INPUT_DOUBLE, 1));", 1, 1)); CaseDefinitions.Add(new ILTestCaseDefinition("TEST_ILMath_min", "[{1}] = min({0});", "{1}=ILMath.touint32(ILMath.min(ILMath.tochar({0})));", 1, 1)); CaseDefinitions.Add(new ILTestCaseDefinition("TEST_ILMath_mindim", "[{1}] = min({0},[],1);", "{1}=ILMath.touint32(ILMath.min(ILMath.tochar({0}),ref NULL_INPUT_DOUBLE, 0));", 1, 1)); CaseDefinitions.Add(new ILTestCaseDefinition("TEST_ILMath_mindim2", "[{1}] = min({0},[],2);", "{1}=ILMath.touint32(ILMath.min(ILMath.tochar({0}),ref NULL_INPUT_DOUBLE, 1));", 1, 1)); Run(true, true); /////////////////////////// char //////////////////////////////////// /* problem: matlab max() function does not support 64bit integer data types. * so we first (in Matlab) convert to int32, do max than and convert back for storage. */ generator.RelativeTestCasePath = "maxmin64_64" + (count++).ToString("d4"); ArrayProviders.Add("int64", new ILTestProviderInt64MaxInt64()); CaseDefinitions.Add(new ILTestCaseDefinition("TEST_ILMath_max", "[{1}] = int64(max(int32({0})));", "{1}=ILMath.max({0});", 1, 1)); CaseDefinitions.Add(new ILTestCaseDefinition("TEST_ILMath_maxdim", "[{1}] = int64(max(int32({0}),[],1));", "{1}=ILMath.max({0},ref NULL_INPUT_DOUBLE, 0);", 1, 1)); CaseDefinitions.Add(new ILTestCaseDefinition("TEST_ILMath_maxdim2", "[{1}] = int64(max(int32({0}),[],2));", "{1}=ILMath.max({0},ref NULL_INPUT_DOUBLE, 1);", 1, 1)); CaseDefinitions.Add(new ILTestCaseDefinition("TEST_ILMath_min", "[{1}] = int64(min(int32({0})));", "{1}=ILMath.min({0});", 1, 1)); CaseDefinitions.Add(new ILTestCaseDefinition("TEST_ILMath_mindim", "[{1}] = int64(min(int32({0}),[],1));", "{1}=ILMath.min({0},ref NULL_INPUT_DOUBLE, 0);", 1, 1)); CaseDefinitions.Add(new ILTestCaseDefinition("TEST_ILMath_mindim2", "[{1}] = int64(min(int32({0}),[],2));", "{1}=ILMath.min({0},ref NULL_INPUT_DOUBLE, 1);", 1, 1)); Run(true, true); generator.RelativeTestCasePath = "maxmin64_32" + (count++).ToString("d4"); ArrayProviders.Add("uint64", new ILTestProviderUInt64MaxUInt32()); CaseDefinitions.Add(new ILTestCaseDefinition("TEST_ILMath_max", "[{1}] = uint64(max(uint32({0})));", "{1}=ILMath.max({0});", 1, 1)); CaseDefinitions.Add(new ILTestCaseDefinition("TEST_ILMath_maxdim", "[{1}] = uint64(max(uint32({0}),[],1));", "{1}=ILMath.max({0},ref NULL_INPUT_DOUBLE, 0);", 1, 1)); CaseDefinitions.Add(new ILTestCaseDefinition("TEST_ILMath_maxdim2", "[{1}] = uint64(max(uint32({0}),[],2));", "{1}=ILMath.max({0},ref NULL_INPUT_DOUBLE, 1);", 1, 1)); CaseDefinitions.Add(new ILTestCaseDefinition("TEST_ILMath_min", "[{1}] = uint64(min(uint32({0})));", "{1}=ILMath.min({0});", 1, 1)); CaseDefinitions.Add(new ILTestCaseDefinition("TEST_ILMath_mindim", "[{1}] = uint64(min(uint32({0}),[],1));", "{1}=ILMath.min({0},ref NULL_INPUT_DOUBLE, 0);", 1, 1)); CaseDefinitions.Add(new ILTestCaseDefinition("TEST_ILMath_mindim2", "[{1}] = uint64(min(uint32({0}),[],2));", "{1}=ILMath.min({0},ref NULL_INPUT_DOUBLE, 1);", 1, 1)); Run(true, true); }
public max_min(ILTestAutoGenerator generator) : base (generator) { ArrayProviders.Add("double",new ILTestProviderDouble()); ArrayProviders.Add("float",new ILTestProviderSingle()); ArrayProviders.Add("complex",new ILTestProviderComplex()); ArrayProviders.Add("fcomplex",new ILTestProviderFComplex()); ArrayProviders.Add("int16",new ILTestProviderInt16()); ArrayProviders.Add("int32",new ILTestProviderInt32()); ArrayProviders.Add("uint16",new ILTestProviderUInt16()); ArrayProviders.Add("uint32",new ILTestProviderUInt32()); //Matlab produces results of type double on max(char) //arrayProviders.Add("char",new ILTestProviderChar()); ArrayProviders.Add("byte",new ILTestProviderByte()); int count = 0; #region TEST R = max(A) #region create overrides (since even ML is not perfect! ;) ) // here: max should really ignore NaNs in complex array! (Matlab [Rel. 13] does not) List<ILResultOverride> overrides = new List<ILResultOverride>(); ILCell correctResultComplex = new ILCell(1,1); correctResultComplex[0,0] = new ILArray<complex>(new complex[]{new complex(double.NegativeInfinity,double.PositiveInfinity)}); ILCell input2override = new ILCell(1,1); input2override[0,0] = ArrayProviders["complex"].GenerateTestArrays()[44,null]; overrides.Add(new ILResultOverride(ArrayProviders["complex"],input2override,correctResultComplex)); ILCell correctResultFcomplex = new ILCell(1,1); correctResultFcomplex[0,0] = new ILArray<fcomplex>(new fcomplex[]{new fcomplex(float.NegativeInfinity,float.PositiveInfinity)}); input2override = new ILCell(1,1); input2override[0,0] = ArrayProviders["fcomplex"].GenerateTestArrays()[44,null]; overrides.Add(new ILResultOverride(ArrayProviders["fcomplex"],input2override,correctResultFcomplex)); #endregion ILTestCaseDefinition testCaseDef = new ILTestCaseDefinition("TEST_ILMath_max","[{1}] = max({0});", "{1}=ILMath.max({0});", 1, 1,overrides); generator.RelativeTestCasePath = "max" + (count++).ToString("d4"); CaseDefinitions.Add(testCaseDef); #endregion CaseDefinitions.Add(new ILTestCaseDefinition("TEST_ILMath_maxdim","[{1}] = max({0},[],1);", "{1}=ILMath.max({0},ref NULL_INPUT_DOUBLE, 0);", 1, 1,overrides)); CaseDefinitions.Add(new ILTestCaseDefinition("TEST_ILMath_maxdim2","[{1}] = max({0},[],2);", "{1}=ILMath.max({0},ref NULL_INPUT_DOUBLE, 1);", 1, 1)); Run(false,true); #region TEST min generator.RelativeTestCasePath = "min" + (count++).ToString("d4"); overrides = new List<ILResultOverride>(); correctResultComplex = new ILCell(1,1); correctResultComplex[0] = new ILArray<complex>(new complex[] {new complex(0,0)}); input2override = new ILCell(1,1); input2override[0] = ArrayProviders["complex"].GenerateTestArrays()[44,null]; ILResultOverride overrideMinComplexNan = new ILResultOverride( ArrayProviders["complex"], input2override, correctResultComplex); overrides.Add(overrideMinComplexNan); correctResultFcomplex = new ILCell(1,1); correctResultFcomplex[0] = new ILArray<fcomplex>(new fcomplex[]{new fcomplex(0,0)}); input2override = new ILCell(1,1); input2override[0] = ArrayProviders["fcomplex"].GenerateTestArrays()[44,null]; ILResultOverride overrideMinFComplexNan = new ILResultOverride( ArrayProviders["fcomplex"], input2override, correctResultFcomplex); overrides.Add(overrideMinFComplexNan); CaseDefinitions.Add(new ILTestCaseDefinition("TEST_ILMath_min","[{1}] = min({0});", "{1}=ILMath.min({0});", 1, 1,overrides)); CaseDefinitions.Add(new ILTestCaseDefinition("TEST_ILMath_mindim","[{1}] = min({0},[],1);", "{1}=ILMath.min({0},ref NULL_INPUT_DOUBLE, 0);", 1, 1,overrides)); CaseDefinitions.Add(new ILTestCaseDefinition("TEST_ILMath_mindim2","[{1}] = min({0},[],2);", "{1}=ILMath.min({0},ref NULL_INPUT_DOUBLE, 1);", 1, 1)); Run(true,true); #endregion /////////////////////////// char //////////////////////////////////// /* the problem: matlab R13 max() function returns double class on char input, also -v6 is buggy by * not storing char as uint16 but as uint8 */ generator.RelativeTestCasePath = "maxmin32_char" + (count++).ToString("d4"); ArrayProviders.Add("int",new ILTestProviderUInt32MaxChar()); CaseDefinitions.Add(new ILTestCaseDefinition("TEST_ILMath_max","[{1}] = max({0});", "{1}=ILMath.touint32(ILMath.max(ILMath.tochar({0})));", 1, 1)); CaseDefinitions.Add(new ILTestCaseDefinition("TEST_ILMath_maxdim","[{1}] = max({0},[],1);", "{1}=ILMath.touint32(ILMath.max(ILMath.tochar({0}),ref NULL_INPUT_DOUBLE, 0));", 1, 1)); CaseDefinitions.Add(new ILTestCaseDefinition("TEST_ILMath_maxdim2","[{1}] = max({0},[],2);", "{1}=ILMath.touint32(ILMath.max(ILMath.tochar({0}),ref NULL_INPUT_DOUBLE, 1));", 1, 1)); CaseDefinitions.Add(new ILTestCaseDefinition("TEST_ILMath_min","[{1}] = min({0});", "{1}=ILMath.touint32(ILMath.min(ILMath.tochar({0})));", 1, 1)); CaseDefinitions.Add(new ILTestCaseDefinition("TEST_ILMath_mindim","[{1}] = min({0},[],1);", "{1}=ILMath.touint32(ILMath.min(ILMath.tochar({0}),ref NULL_INPUT_DOUBLE, 0));", 1, 1)); CaseDefinitions.Add(new ILTestCaseDefinition("TEST_ILMath_mindim2","[{1}] = min({0},[],2);", "{1}=ILMath.touint32(ILMath.min(ILMath.tochar({0}),ref NULL_INPUT_DOUBLE, 1));", 1, 1)); Run(true,true); /////////////////////////// char //////////////////////////////////// /* problem: matlab max() function does not support 64bit integer data types. * so we first (in Matlab) convert to int32, do max than and convert back for storage. */ generator.RelativeTestCasePath = "maxmin64_64" + (count++).ToString("d4"); ArrayProviders.Add("int64",new ILTestProviderInt64MaxInt64()); CaseDefinitions.Add(new ILTestCaseDefinition("TEST_ILMath_max","[{1}] = int64(max(int32({0})));", "{1}=ILMath.max({0});", 1, 1)); CaseDefinitions.Add(new ILTestCaseDefinition("TEST_ILMath_maxdim","[{1}] = int64(max(int32({0}),[],1));", "{1}=ILMath.max({0},ref NULL_INPUT_DOUBLE, 0);", 1, 1)); CaseDefinitions.Add(new ILTestCaseDefinition("TEST_ILMath_maxdim2","[{1}] = int64(max(int32({0}),[],2));", "{1}=ILMath.max({0},ref NULL_INPUT_DOUBLE, 1);", 1, 1)); CaseDefinitions.Add(new ILTestCaseDefinition("TEST_ILMath_min","[{1}] = int64(min(int32({0})));", "{1}=ILMath.min({0});", 1, 1)); CaseDefinitions.Add(new ILTestCaseDefinition("TEST_ILMath_mindim","[{1}] = int64(min(int32({0}),[],1));", "{1}=ILMath.min({0},ref NULL_INPUT_DOUBLE, 0);", 1, 1)); CaseDefinitions.Add(new ILTestCaseDefinition("TEST_ILMath_mindim2","[{1}] = int64(min(int32({0}),[],2));", "{1}=ILMath.min({0},ref NULL_INPUT_DOUBLE, 1);", 1, 1)); Run(true,true); generator.RelativeTestCasePath = "maxmin64_32" + (count++).ToString("d4"); ArrayProviders.Add("uint64",new ILTestProviderUInt64MaxUInt32()); CaseDefinitions.Add(new ILTestCaseDefinition("TEST_ILMath_max","[{1}] = uint64(max(uint32({0})));", "{1}=ILMath.max({0});", 1, 1)); CaseDefinitions.Add(new ILTestCaseDefinition("TEST_ILMath_maxdim","[{1}] = uint64(max(uint32({0}),[],1));", "{1}=ILMath.max({0},ref NULL_INPUT_DOUBLE, 0);", 1, 1)); CaseDefinitions.Add(new ILTestCaseDefinition("TEST_ILMath_maxdim2","[{1}] = uint64(max(uint32({0}),[],2));", "{1}=ILMath.max({0},ref NULL_INPUT_DOUBLE, 1);", 1, 1)); CaseDefinitions.Add(new ILTestCaseDefinition("TEST_ILMath_min","[{1}] = uint64(min(uint32({0})));", "{1}=ILMath.min({0});", 1, 1)); CaseDefinitions.Add(new ILTestCaseDefinition("TEST_ILMath_mindim","[{1}] = uint64(min(uint32({0}),[],1));", "{1}=ILMath.min({0},ref NULL_INPUT_DOUBLE, 0);", 1, 1)); CaseDefinitions.Add(new ILTestCaseDefinition("TEST_ILMath_mindim2","[{1}] = uint64(min(uint32({0}),[],2));", "{1}=ILMath.min({0},ref NULL_INPUT_DOUBLE, 1);", 1, 1)); Run(true,true); }
public void Test_Addressing() { int errorCode = 0; try { ILBaseArray[] data = new ILBaseArray[60]; for (int i = 0; i < data.Length; i++) data[i] = new ILArray<Int16>(new Int16[1]{(Int16)i}); ILCell A = new ILCell(data,20,3); A.Name = "A"; errorCode = 1; A[1,1] = ILMath.vector(10,100); A[2,1] = ILMath.vector(-10,-1,-100); errorCode = 2; // test subarray access: single ILBaseArray ret = A[23]; ret.Name = "ret"; errorCode = 3; // single element returned should be inner ILBaseArray if (!(ret is ILArray<Int16>)) throw new Exception("ILCell: single element returned should be of ILArray<double> type"); ILArray<Int16> a23 = (ILArray<Int16>)ret; a23.Name = "a23"; if (!a23.IsScalar || a23 != 23.0) throw new Exception("ILCell: returned element value mismatch! Expected: 23, found:" + a23.GetValue(0)); errorCode = 4; // test subarray access: multiple via vector (sequential) // - put Cell into cell ILArray<double> element1 = ILMath.vector(10,2,20); element1.Name = "element1"; ILArray<double> element2 = ILMath.vector(20,2,30); element2.Name = "element2"; ILCell innerCell = new ILCell(new ILBaseArray[]{element1,element2},2,1); A[3,1] = innerCell; ILArray<double> ind = new ILArray<double>(new double[]{20.0,21.0,22.0,23.0,24.0}); ind.Name = "ind"; ILCell cellresult_vect = (ILCell)A[ind]; cellresult_vect.Name = "cellresult_vect"; if (!cellresult_vect.IsRowVector || cellresult_vect.Dimensions[0] != 1 ||cellresult_vect.Dimensions[1] != 5) throw new Exception("ILCell: index access dimension mismatch: should be ILCell 1x5! "); if (!(cellresult_vect[0,0] is ILArray<short>) || !(cellresult_vect[0,1] is ILArray<double>) || !(cellresult_vect[0,2] is ILArray<double>) || !(cellresult_vect[0,3] is ILCell) || !(cellresult_vect[0,4] is ILArray<short>)) throw new Exception("ILCell: index access failed. Inner element mismatch for vector indices."); errorCode = 5; // test if elements returned are properly referenced (detached from original) ILArray<short> tmps = (ILArray<short>) cellresult_vect[0,0]; tmps.Name = "tmps"; if (!tmps.IsScalar || (tmps != 20.0)) throw new Exception("ILCell: invalid value returned: expected:20, found:" + tmps.GetValue(0)); ILArray<double> tmp = (ILArray<double>) cellresult_vect[1]; tmp.Name = "tmp"; if (!tmp.IsVector || (bool)(tmp.Length != 91) || (bool)(tmp[0] != 10) || (bool)(tmp["end"] != 100)) throw new Exception("ILCell: invalid value returned: expected double vector 10:2:20"); tmp = (ILArray<double>) cellresult_vect[2]; if (!tmp.IsVector || (bool)(tmp.Length != 91) || (bool)(tmp[0] != -10) || (bool)(tmp["end"] != -100)) throw new Exception("ILCell: invalid value returned: expected vector 20:2:30"); tmps = (ILArray<short>) cellresult_vect[4]; if (!tmps.IsScalar || (bool)(tmps["end"] != 24.0)) throw new Exception("ILCell: invalid value returned: expected short 24, found: " + tmps.GetValue(0)); cellresult_vect[0,3,1,0,1] = -111.0; if ((ILArray<double>)cellresult_vect[0,3,1,0,1] != -111.0) throw new Exception("ILCell: invalid result of inner element index access: expected: -111.0, found: "+ ((ILArray<double>)cellresult_vect[0,3,1,0,1]).GetValue(0)); errorCode = 6; // test if original still intact if (!A[3,1,1,0,1].IsScalar || (ILArray<double>)A[3,1,1,0,1] != 22.0) throw new Exception("ILCell: original should not be altered if reference was altered! A[3,1,1,0,1] = " + ((ILArray<double>)A[3,1,1,0,1]).GetValue(0)); // test subarray access: matrix (sequential) ********************************************** errorCode = 7; ind = new ILArray<double>(new double[6]{20.0,21.0,22.0,23.0,24.0,25.0},3,2); ind.Name = "ind"; cellresult_vect = (ILCell)A[ind]; cellresult_vect.Name = "cellresult_vect"; if (!cellresult_vect.IsMatrix || cellresult_vect.Dimensions[0] != 3 ||cellresult_vect.Dimensions[1] != 2) throw new Exception("ILCell: index access dimension mismatch: should be ILCell 3x2! "); if ( !(cellresult_vect[0,0] is ILArray<short>) || !(cellresult_vect[1,0] is ILArray<double>) || !(cellresult_vect[2,0] is ILArray<double>) || !(cellresult_vect[0,1] is ILCell) || !(cellresult_vect[1,1] is ILArray<short>) || !(cellresult_vect[2,1] is ILArray<short>)) throw new Exception("ILCell: index access failed. Inner element mismatch for vector indices."); if ( !(cellresult_vect[0] is ILArray<short>) || !(cellresult_vect[1] is ILArray<double>) || !(cellresult_vect[2] is ILArray<double>) || !(cellresult_vect[3] is ILCell) || !(cellresult_vect[4] is ILArray<short>) || !(cellresult_vect[5] is ILArray<short>)) throw new Exception("ILCell: index access failed. Inner element mismatch for vector indices."); errorCode = 8; // test if elements returned are properly referenced (detached from original) tmps = (ILArray<short>) cellresult_vect[0,0]; tmps.Name = "tmps"; if (!tmps.IsScalar || (byte)tmps != 20.0) throw new Exception("ILCell: invalid value returned: expected:20, found:" + tmps.GetValue(0)); tmp = (ILArray<double>) cellresult_vect[1]; tmp.Name = "tmp"; if (!tmp.IsVector || tmp.Length != 91 || tmp[0]!=10.0 || tmp["end"]!=100.0) throw new Exception("ILCell: invalid value returned: expected double vector 10:2:20"); tmp = (ILArray<double>) cellresult_vect[2]; if (!tmp.IsVector || tmp.Length != 91 || tmp[0]!=-10.0 || tmp["end"]!=-100.0) throw new Exception("ILCell: invalid value returned: expected vector 20:2:30"); tmps = (ILArray<short>) cellresult_vect[4]; if (!tmps.IsScalar || (byte)tmps["end"] != 24.0) throw new Exception("ILCell: invalid value returned: expected short 24, found: " + tmps.GetValue(0)); cellresult_vect[0,1,1,0,1] = -111.0; if ((double)(ILArray<double>)cellresult_vect[0,1,1,0,1] != -111.0) throw new Exception("ILCell: invalid result of inner element index access: expected: -111.0, found: "+ ((ILArray<double>)cellresult_vect[0,3,1,0,1]).GetValue(0)); errorCode = 9; // test if original still untouched if ((ILArray<double>)A[3,1,1,0,1] != 22.0) throw new Exception("ILCell: original should not be altered if reference was altered! A[3,1,1,0,1] = " + ((ILArray<double>)A[3,1,1,0,1]).GetValue(0)); // test sequential index array set acces innerCell = new ILCell(4,3,2); innerCell[0] = ILMath.vector(20,-3,-100); innerCell[1] = ((ILArray<double>)innerCell[0] < 0.0); ILCell rangedsource = new ILCell(new ILBaseArray [] { new ILArray<int>(3333), new ILLogicalArray(1), ILMath.vector(1000,2000), innerCell},2,2); ILArray<double> range = new ILArray<double>(new double[]{0,51,52,59}); A[range] = rangedsource; if (!(A[0] is ILArray<int>)) throw new Exception ("ILCell: seq.ranged set mismatch. index 0"); if (!(A[51] is ILLogicalArray)) throw new Exception ("ILCell: seq.ranged set mismatch. index 1"); if (!(A[52] is ILArray<double>)) throw new Exception ("ILCell: seq.ranged set mismatch. index 2"); if (!(A[59] is ILCell)) throw new Exception ("ILCell: seq.ranged set mismatch. index 3"); errorCode = 10; // test detached referencing (alter elements of query result) // test index access for ranges via ILBaseArray[] data = new ILBaseArray[60]; for (int i = 0; i < data.Length; i++) data[i] = new ILArray<Int16>(new Int16[]{(Int16)i}); A = new ILCell(data,20,3); A.Name = "A"; ILArray<double> r = ILMath.vector(0,2); ILArray<short> c = (ILArray<short>)ILMath.ones(NumericType.Int16,1); ILCell rangeGet = (ILCell) A[r,c]; if (rangeGet.Dimensions[0] != 3 || rangeGet.Dimensions[1] != 1) throw new Exception("ILCell: ranged index get access via ILBaseArray failed. Wrong dimension returned."); if ((ILArray<short>)rangeGet[0,0] != 20.0) throw new Exception("ILCell: invalid index returned: exp.20, found:" + ((ILArray<int>)rangeGet[0,0]).GetValue(0)); A[0,1] = new ILArray<double>(17,18,1000); if ((ILArray<short>)rangeGet[0,0] != 20.0) throw new Exception("ILCell: invalid index returned: exp.20, found:" + ((ILArray<double>)rangeGet[0,0]).GetValue(0) + ". The reference returned was not detached properly!"); errorCode = 11; // test ranged setter A[c,r] = A[c+10,r]; if ((ILArray<short>)A[1,1] != 31.0) throw new Exception("Wrong value found after copying part of cell to other position."); A[1,1] = -1122.0; if ((ILArray<short>)A[11,1] != 31.0 || (ILArray<double>)A[1,1] != -1122.0) throw new Exception ("wrong value stored or reference not properly un-linked in ILCell."); // test removal of elements errorCode = 12; A[new ILArray<double>(new double[]{4.0,5.0,11.0}),null] = null; if (A.Dimensions[0] != 17 || A.Dimensions[1] != 3) throw new Exception("ILCell removal via ILBaseArray[] failed."); A[new ILArray<double>(new double[]{4.0,5.0,11.0})] = null; if (A.Dimensions[0] != 1 || A.Dimensions[1] != 48) throw new Exception("ILCell removal via sequential indexes failed!"); errorCode = 13; // test if error on removal will restore old dimensions A = new ILCell(2,3,2); ind = new double[]{15,16,22,223}; try { A[ind] = null; throw new Exception("ILCell remove: index out of range not signaled!"); } catch(Exception) {} if (A.Dimensions[0] != 2 || A.Dimensions[1] != 3 || A.Dimensions[2]!= 2) throw new Exception("ILCell: error on remove should restore old dimensions!"); Success(); } catch (Exception e) { Error(errorCode ,e.Message); } }
public static ILBaseArray ILCellFromDataTable(DataTable dataTable) { int nColumns = dataTable.Columns.Count; ILBaseArray baseArray; // Check if last row is all null int nRows = dataTable.Rows.Count; int rowsToExclude; bool oneNonNull = true; for (int i = nRows - 1; i > 0; --i) { oneNonNull = false; for (int j = 0; j < nColumns; ++j) { if (!(dataTable.Rows[i].IsNull(j))) { oneNonNull = true; } } if (oneNonNull == false) { dataTable.Rows[i].Delete(); } } dataTable.AcceptChanges(); nRows = dataTable.Rows.Count; // Check if all columns have the same type Type firstColumnType = dataTable.Columns[0].DataType; bool columnTypesDifferent = false; for (int i = 0; i < nColumns; ++i) { if (dataTable.Columns[i].DataType != firstColumnType) { columnTypesDifferent = true; } } if (columnTypesDifferent) { baseArray = new ILCell(nColumns); for (int i = 0; i < nColumns; ++i) { Type type = dataTable.Columns[i].DataType; // need CreateInstance(Type t, int size) really! if (type == System.Type.GetType("System.Double")) { ((ILCell)baseArray)[i] = LoadILArrayFromDataColumn <double>(dataTable, i); } else if (type == System.Type.GetType("System.Single")) { ((ILCell)baseArray)[i] = LoadILArrayFromDataColumn <float>(dataTable, i); } else if (type == System.Type.GetType("System.Byte")) { ((ILCell)baseArray)[i] = LoadILArrayFromDataColumn <byte>(dataTable, i); } else if (type == System.Type.GetType("System.Int32")) { ((ILCell)baseArray)[i] = LoadILArrayFromDataColumn <int>(dataTable, i); } else if (type == System.Type.GetType("System.String")) { ((ILCell)baseArray)[i] = LoadILArrayFromDataColumn <string>(dataTable, i); } } } else { if (firstColumnType == System.Type.GetType("System.Double")) { baseArray = LoadILArrayFromDataTable <double>(dataTable); } else if (firstColumnType == System.Type.GetType("System.Single")) { baseArray = LoadILArrayFromDataTable <float>(dataTable); } else if (firstColumnType == System.Type.GetType("System.Byte")) { baseArray = LoadILArrayFromDataTable <byte>(dataTable); } else if (firstColumnType == System.Type.GetType("System.Int32")) { baseArray = LoadILArrayFromDataTable <int>(dataTable); } else if (firstColumnType == System.Type.GetType("System.String")) { baseArray = LoadILArrayFromDataTable <string>(dataTable); } else { baseArray = new ILCell(1); } } return(baseArray); }
// update the shapes with new data. Data are made by the helper class // "Computation" and are provided as ILCell, holding the coords for the // pendula weigth (one circle only) and the corresponding indices (mapping). private void UpdateShapes(ILCell data) { // get the data out of the cell ILArray<double> circ = (ILArray<double>)data[0]; ILArray<double> mapping = (ILArray<double>)data[1]; // update the pendula weight edges (lit quads) // Data contains only one circle, since we need two, we concatenate // the array: x and y are simply doubled, z is added with 0.4 to // create a volume. m_quads.Update(circ[0.0, null].Concat(circ[0.0, null], 1), circ[1.0, null].Concat(circ[1.0, null], 1), circ[2.0, null].Concat(circ[2.0, null] + 0.4, 1), // mapping contains the indices referencing the vertices in circ mapping); // the polygon updates are even easier: since ILPolygon is a simple (bordered) // shape, no mappings are needed, we just pass the vertex data: m_poly1.Update(circ[0.0, null], circ[1.0, null], circ[2.0, null]); m_poly2.Update(circ[0.0, null], circ[1.0, null], circ[2.0, null] + 0.4); // note, calling Update on any ILShape will at the same time invalidate the shape. // this is important to signal the scene (panel) for the size of the scene and the // position(s) of shape(s) may have changed. Latter is important for the order in which // shapes are drawn in case of transparent shapes. Since Update() already does this for us, // we do not have to call [shape].Invalidate() manually. // However, if we would use the low-level interface for scene updates and manipulate the // shapes vertices directly, we would need to call Invalidate() afterwards. }