public ILFormatter(ILArray <T> array) { m_array = array; //GetClientSize(); }
public ILArrayDebuggerProxy(ILArray <T> array) { m_array = array; }
/// <summary>Calculates interpolated values using 'natural' Cubic Spline Interpolation</summary> /// <param name="xi">X values at which interpolated values are required</param> /// <returns>Interpolated values </returns> /// <remarks><para></para> /// </remarks> public ILArray <double> GetValuesCubicSpline(ILArray <double> xi) { return(GetValuesCubicSpline(xi, BoundaryType.SecondDerivativeSpecified, 0.0, BoundaryType.SecondDerivativeSpecified, 0.0)); }
/// <summary> /// Constructor for ILCurve /// </summary> /// <param name="x">Vector of X values for the Curve</param> /// <param name="y">Vector of Y values for the Curve</param> /// <remarks></remarks> public ILCurve(ILArray <BaseT> x, ILArray <BaseT> y) { this.x = x; this.y = y; Validate(); n = x.Length; }
/// <summary>Calculates interpolated values using default cubic interpolation which is Monotone Piecewise Cubic Hermite Interpolation</summary> /// <param name="xi">X values at which interpolated values are required</param> /// <returns>Interpolated Y values </returns> /// <remarks><para></para> /// </remarks> public ILArray <double> GetValuesCubic(ILArray <double> xi) { return(GetValuesMonotoneCubicSpline(xi)); }
/// <summary>Calculates interpolated values using Cubic Spline Interpolation</summary> /// <param name="xi">X values at which interpolated values are required</param> /// <returns>Interpolated Y values </returns> /// <remarks><para></para> /// </remarks> public ILArray <double> GetValuesSpline(ILArray <double> xi) { return(GetValuesCubicSpline(xi)); }
/// <summary> /// Concatenate this array /// </summary> /// <param name="inArray">N-dimensional storage. Except for dimensions leadDim /// the dimensions must match the dimensions of this storage.</param> /// <param name="leadDim">index of dimension to concatenate arrays along. /// If leadDim is larger than the number of dimensions of any of the arrays /// its value will be used in modulus</param> /// <returns>logical array having the size /// of both input arrays layed behind each other along the leadDim's-dimension</returns> /// <remarks>The array returned will be a /// <list type="bullet"> /// <item> reference storage, if inArray is the same as this array (object references /// are the same) and ILArray.MinimumRefDimensions is less or equal /// the number of dimensions of the resulting storage, or a /// </item> /// <item>physical storage else. /// </item></list> /// There are only very few cases where it is possible to reference two arrays in the /// same reference storage. Not only the storages must point to the same underlying /// physical System.Array, but the ILIndexOffset must be suited in a special way. /// Therefore the restriction was made always to create a reference storage, if /// both storages are not the same.</remarks> public new ILLogicalArray Concat(ILArray <byte> inArray, int leadDim) { return(new ILLogicalArray(base.Concat(inArray, leadDim))); }
/// <summary> /// Constructor creating ILLogicalArray from <![CDATA[ILArray<byte>]]> /// </summary> /// <param name="A">input array, the storage of this ILArray will directly be used for /// storage of the new ILLogicalArray</param> public ILLogicalArray(ILArray <byte> A) : base(A) { m_numberNonZero = sumElements(); }
/// <summary> /// get/set/remove single element /// </summary> /// The type of access depends on the length of indices. /// <paramref name="indices" value="index to element"/> /// <value>inner element, new inner element or null</value> /// <remarks>If indices contains only one element, the array will be accessed via sequential index access. /// This is sometimes called "linear" index access also. Sequential index access reflects the index of internal storage /// the way the data are actually organized in memory. This access method is mainly convinient for vectors where you are not interested of orientation. /// The following example demonstrates sequential index access for ILArray's (which also holds for ILCells): /// <example><code> /// ILArray<double> A = new ILArray<double>(1.0,12.0); /// A[2] gives: 3.0 /// </code>But the transpose /// <code> /// A.T[2] gives also: 3.0 /// </code> /// For matrices and N-dimensional arrays this holds as well: /// <code> /// ILArray<double> A = new ILArray<double>(1.0,12.0); /// A = /// [1.0 4.0 /// 2.0 5.0 /// 3.0 6.0 /// /// 7.0 10.0 /// 8.0 11.0 /// 9.0 12.0] /// /// A = ILMath.Reshape(A,3,2,2); /// A[10] gives 11.0 /// A[10,1] gives ILArgumentException -> out of range /// A[2,1,1] gives 12.0 /// A[2,1] gives 6.0 (set trailing dimension to '0')</code></example> /// <para>For get access the array returned will be a reference to the element addressed.</para> /// <para>If the element addressed is a ILCell itself, a deep reference to this element will be returned instead. /// I.e. all elements of the ILCell will be recursively replaced with references to itself.</para> /// <para> /// <list type="bullet"> /// <listheader>The type of the element returned depends on the type of the element addressed:</listheader> /// <item>For ILArray<BaseT> the array returned will be a reference to the original array (same type and size).</item> /// <item>For ILCell the ILBaseArray returned is a deep reference of the original element stored.</item> /// <item>for other types the behavior is undefined. (since other types are not implemented yet ;)</item> /// </list> </para> /// <para>This indexer may also be used for direct access to elements of elements of this cell: /// <example> /// <code> /// ILCell innerCell = new ILCell(2,1); /// innerCell[0] = ILMath.vector(10,200); /// innerCell[1] = ILArray<int>(-10,-20,-30); /// ILCell cell = new ILCell(2,1); /// cell[0] = innerCell; /// cell[1] = new ILArray<string>("foobla"); /// // cell is now: /// // [ILCell,(1x2)] /// // [innerCell[0], ILArray<double>(1x181)] /// // [innerCell[0], ILArray<double>(1x3)] /// // [ILArray<string>,(1x1)] /// /// cell[0,0] -> will give innerCell eq. ILCell (1x2) /// cell[0,1] -> will give ILArray<string> /// cell[0,0,0,1] -> will give innerCell[1] eq. ILArray<int>(1x3) /// </code> /// </example> /// In the last example above the trailing indices specified make the indexer walk down into the ILCell element and retrieve /// the content of this element. This kind of index access may be done as deep as you want. Just /// append the inner indices into inner elements to the right side of index specification. Addressing inner elements /// this way is the only way to alter elements <b>directly</b> inside the ILCell. </para> /// <para>For set access the element <code>value</code> will directly be stored in the ILCell. No copy/reference will be done for it!</para></remarks> public new ILBaseArray this[params int[] indices] { get{ int mydimlen = m_dimensions.NumberOfDimensions; if (indices.Length <= mydimlen) { // address this ILCell ILBaseArray ret = base[indices].GetValue(0, 0); if (object.Equals(ret, null)) { return(null); } else if (ret is ILArray <ILBaseArray> ) { ILArray <ILBaseArray> tmp = (ILArray <ILBaseArray>)ret; ILCell retC = new ILCell(tmp).DeepReferenceElements(); return(retC); } else if (ret is ILLogicalArray) { return(((ILLogicalArray)ret).C); } else { return((ILBaseArray)ret.Clone()); } } else { // address element of an element of this ILCell int[] innerIndices = new int[indices.Length - mydimlen]; int[] myIndices = new int[mydimlen]; int i = 0; for (; i < mydimlen; i++) { myIndices[i] = indices[i]; } for (int n = 0; i < indices.Length; i++) { innerIndices[n++] = indices[i]; } ILBaseArray innerElement = GetValue(myIndices); if (innerElement is ILCell) { return(((ILCell)innerElement)[innerIndices]); } else if (innerElement is ILArray <double> ) { return(((ILArray <double>)innerElement)[innerIndices]); } else { throw new ILArgumentTypeException("inner cell element type is not supported for deep index access!"); } } } set { if (Object.ReferenceEquals(value, null)) { throw new ILArgumentException("cell removal is not supported for single integer indexing! The value specified must not be null!"); } int mydimlen = m_dimensions.NumberOfDimensions; if (indices.Length <= mydimlen) { // address this ILCell SetValue((ILBaseArray)value.Clone(), indices); } else { // address element of an element of this ILCell int[] innerIndices = new int[indices.Length - mydimlen]; int[] myIndices = new int[mydimlen]; int i = 0; for (; i < mydimlen; i++) { myIndices[i] = indices[i]; } for (int n = 0; i < indices.Length; i++) { innerIndices[n++] = indices[i]; } ILBaseArray innerElement = GetValue(myIndices); if (innerElement is ILCell) { ((ILCell)innerElement)[innerIndices] = (ILBaseArray)value.Clone(); } else if (value is ILArray <double> && innerElement is ILArray <double> ) { ((ILArray <double>)innerElement)[innerIndices] = ((ILArray <double>)value).C; } else if (value is ILArray <complex> && innerElement is ILArray <complex> ) { ((ILArray <complex>)innerElement)[innerIndices] = ((ILArray <complex>)value).C; } else if (value is ILArray <byte> && innerElement is ILArray <byte> ) { ((ILArray <byte>)innerElement)[innerIndices] = ((ILArray <byte>)value).C; } else { throw new ILArgumentTypeException("right side argument type is not supported in this context! The value must have the same type as the inner array of the cell!"); } } } }
/// <summary> /// constructor creating ILCell from base type /// </summary> /// <param name="input"></param> internal ILCell(ILArray <ILBaseArray> input) : base(input) { }
/// <summary> /// create physical copy from this physical array and shift dimensions /// </summary> /// <param name="indices">sequential indices. may be of any size</param> /// <param name="shift">number of dimensions to shift the result</param> /// <returns>physical copy of elements addressed by indices.shape of shifted indices</returns> private ILArray <BaseT> CreatePhysicalSubarrayFromPhysicalSequentialShifted(/*!HC:inCls1*/ ILArray <double> indices, int shift) { if (shift < 0) { shift = 0; } if (shift > indices.m_dimensions.NumberOfDimensions) { shift %= indices.m_dimensions.NumberOfDimensions; } ILDimension dim = indices.m_dimensions.GetShifted(shift); int outLen = dim.NumberOfElements; BaseT[] outdata = ILMemoryPool.Pool.New <BaseT> (outLen--); int outPos = 0, outInc = dim.SequentialIndexDistance(dim.NumberOfDimensions - shift); /*!HC:inArr1*/ double [] indData = indices.m_data; for (int i = 0; i < outLen; i++) { outdata[outPos] = m_data[(int)indData[i]]; outPos += outInc; if (outPos > outLen) { outPos %= outLen; } } outdata[outLen] = m_data[(int)indData[outLen]]; return(new ILArray <BaseT>(outdata, dim)); }
/*!HC:TYPELIST: * <hycalper> * <type> * <source locate="after"> * inCls1 * </source> * <destination><![CDATA[ILArray<byte>]]></destination> * <destination><![CDATA[ILArray<complex>]]></destination> * </type> * <type> * <source locate="after"> * inArr1 * </source> * <destination>byte</destination> * <destination>complex</destination> * </type> * </hycalper> */ /// <summary> /// create physical copy from this physical array /// </summary> /// <param name="indices">sequential indices. may be of any size</param> /// <returns>physical copy of elements addressed by indices.shape of indices</returns> private ILArray <BaseT> CreatePhysicalSubarrayFromPhysicalSequential(/*!HC:inCls1*/ ILArray <double> indices) { ILDimension dim = indices.m_dimensions; int outLen = dim.NumberOfElements; BaseT[] outdata = ILMemoryPool.Pool.New <BaseT> (outLen); /*!HC:inArr1*/ double [] indData = indices.m_data; for (int i = 0; i < outLen; i++) { outdata[i] = m_data[(int)indData[i]]; } return(new ILArray <BaseT>(outdata, dim)); }
/// <summary> /// implicit copy constructor /// </summary> /// <param name="inp">ILArray to be copied</param> /// <remarks>This is used in C++ derivate as assignment operator</remarks> public void MarshalCopy(ILArray <BaseT> inp) { m_data = inp.m_data; m_dimensions = inp.Dimensions; m_name = inp.Name; }
/// <summary> /// 'Copy' Constructor. Creates a new ILArray as exact copy of input array /// </summary> /// <param name="inp"> /// ILArray object to create a copy from /// </param> /// <remarks> /// <para> /// The ILArray given will be copied and the reference counter will get increased. The resulting /// new ILArray will be an exact - but shallow - copy of inp. /// Use this constructor only for casting purposes! For copy/clone operations /// use the Subarray/CreateReference/Copy/Clone functions or the index access instead!</para> /// </remarks> internal ILArray(ILArray <BaseT> inp) { m_data = (BaseT[])inp.m_data; m_dimensions = inp.m_dimensions; m_name = inp.Name; }
/// <summary> /// helper function to prepare parameters for partial removal /// </summary> /// <param name="range">object with index specification.May be of /// type ILBaseArray[] with numeric arrays or a string array according /// to the format of <see cref="ILNumerics.Storage.ILRange"/>. /// </param> /// <param name="dimensionIdx">out parameter: number of dimension the indices to be removed lay in</param> /// <param name="indices">indices to be removed</param> /// <param name="dimensions">dimension structure, may be used if the array must be /// reshaped <b>before</b> the removal.</param> /// <remarks>if range consists out of a range specification wich is smaller than /// the actual dimension length of this array, the array must also be reshaped in order to remove /// the data accordingly. This reshape proccess will <b>not</b> be done inside of this function! However /// ther <c>dimension</c> value returned reflect the size of the array before removing and therefore /// may comfortable be used for reshaping the array.</remarks> /// <exception cref="ILNumerics.Exceptions.ILArgumentException">if <list type="bullet"> /// <item>the length of range exceeds the dimensions of this array</item> /// <item>more or less than exactly one dimension of <c>range</c> was not null</item> /// <item>the type of range was invalid, or</item> /// <item>range is of type array of <see cref="ILNumerics.ILBaseArray"/>, but the elements are non numeric ILArray's</item> /// </list></exception> private void ExtractRemovalParameter(object[] range, out int dimensionIdx, out int[] indices, out ILDimension dimensions) { dimensionIdx = 0; indices = null; dimensions = null; int inDimCount = 0; // if (range.Length > m_dimensions.NumberOfDimensions) { throw new ILArgumentException("Error removing: dimension specification exceeds matrix dimensions."); } int specCount = 0; int tmp = 0; inDimCount = range.Length; // for (int i = 0; i < range.Length; i++) { if (range[i] is ILBaseArray) { #region ILBaseArray input ILBaseArray rng = (ILBaseArray)range[i]; if (rng != null && !rng.IsEmpty) { dimensionIdx = i; if (specCount++ > 0) { throw new ILArgumentException("Error removing: only one dimension must be non-empty!"); } if (false) { } else if (rng is ILLogicalArray) { ILArray <double> ind = ILNumerics.BuiltInFunctions.ILMath.find((ILLogicalArray)rng); tmp = ind.Dimensions.NumberOfElements; indices = new int[tmp]; for (int p = 0; p < tmp; p++) { indices[p] = (int)ind.GetValue(p); } #region HYCALPER LOOPSTART /* !HC:TYPELIST: * <hycalper> * <type> * <source locate="after"> * inCls1 * </source> * <destination><![CDATA[ILArray<float>]]></destination> * <destination><![CDATA[ILArray<Int16>]]></destination> * <destination><![CDATA[ILArray<Int32>]]></destination> * <destination><![CDATA[ILArray<Int64>]]></destination> * <destination><![CDATA[ILArray<UInt16>]]></destination> * <destination><![CDATA[ILArray<UInt32>]]></destination> * <destination><![CDATA[ILArray<UInt64>]]></destination> * <destination><![CDATA[ILArray<char>]]></destination> * <destination><![CDATA[ILArray<byte>]]></destination> * <destination><![CDATA[ILArray<complex>]]></destination> * <destination><![CDATA[ILArray<fcomplex>]]></destination> * </type> * </hycalper> */ } else if (rng is /*!HC:inCls1*/ ILArray <double> ) { /*!HC:inCls1*/ ILArray <double> ind = (/*!HC:inCls1*/ ILArray <double>)rng; tmp = ind.Dimensions.NumberOfElements; indices = new int[tmp]; for (int p = 0; p < tmp; p++) { indices[p] = (int)ind.GetValue(p); } #endregion HYCALPER LOOPEND #region HYCALPER AUTO GENERATED CODE // DO NOT EDIT INSIDE THIS REGION !! CHANGES WILL BE LOST !! /* !HC:TYPELIST: * */ } else if (rng is ILArray <fcomplex> ) { ILArray <fcomplex> ind = (ILArray <fcomplex>)rng; tmp = ind.Dimensions.NumberOfElements; indices = new int[tmp]; for (int p = 0; p < tmp; p++) { indices[p] = (int)ind.GetValue(p); } /* !HC:TYPELIST: * */ } else if (rng is ILArray <complex> ) { ILArray <complex> ind = (ILArray <complex>)rng; tmp = ind.Dimensions.NumberOfElements; indices = new int[tmp]; for (int p = 0; p < tmp; p++) { indices[p] = (int)ind.GetValue(p); } /* !HC:TYPELIST: * */ } else if (rng is ILArray <byte> ) { ILArray <byte> ind = (ILArray <byte>)rng; tmp = ind.Dimensions.NumberOfElements; indices = new int[tmp]; for (int p = 0; p < tmp; p++) { indices[p] = (int)ind.GetValue(p); } /* !HC:TYPELIST: * */ } else if (rng is ILArray <char> ) { ILArray <char> ind = (ILArray <char>)rng; tmp = ind.Dimensions.NumberOfElements; indices = new int[tmp]; for (int p = 0; p < tmp; p++) { indices[p] = (int)ind.GetValue(p); } /* !HC:TYPELIST: * */ } else if (rng is ILArray <UInt64> ) { ILArray <UInt64> ind = (ILArray <UInt64>)rng; tmp = ind.Dimensions.NumberOfElements; indices = new int[tmp]; for (int p = 0; p < tmp; p++) { indices[p] = (int)ind.GetValue(p); } /* !HC:TYPELIST: * */ } else if (rng is ILArray <UInt32> ) { ILArray <UInt32> ind = (ILArray <UInt32>)rng; tmp = ind.Dimensions.NumberOfElements; indices = new int[tmp]; for (int p = 0; p < tmp; p++) { indices[p] = (int)ind.GetValue(p); } /* !HC:TYPELIST: * */ } else if (rng is ILArray <UInt16> ) { ILArray <UInt16> ind = (ILArray <UInt16>)rng; tmp = ind.Dimensions.NumberOfElements; indices = new int[tmp]; for (int p = 0; p < tmp; p++) { indices[p] = (int)ind.GetValue(p); } /* !HC:TYPELIST: * */ } else if (rng is ILArray <Int64> ) { ILArray <Int64> ind = (ILArray <Int64>)rng; tmp = ind.Dimensions.NumberOfElements; indices = new int[tmp]; for (int p = 0; p < tmp; p++) { indices[p] = (int)ind.GetValue(p); } /* !HC:TYPELIST: * */ } else if (rng is ILArray <Int32> ) { ILArray <Int32> ind = (ILArray <Int32>)rng; tmp = ind.Dimensions.NumberOfElements; indices = new int[tmp]; for (int p = 0; p < tmp; p++) { indices[p] = (int)ind.GetValue(p); } /* !HC:TYPELIST: * */ } else if (rng is ILArray <Int16> ) { ILArray <Int16> ind = (ILArray <Int16>)rng; tmp = ind.Dimensions.NumberOfElements; indices = new int[tmp]; for (int p = 0; p < tmp; p++) { indices[p] = (int)ind.GetValue(p); } /* !HC:TYPELIST: * */ } else if (rng is ILArray <float> ) { ILArray <float> ind = (ILArray <float>)rng; tmp = ind.Dimensions.NumberOfElements; indices = new int[tmp]; for (int p = 0; p < tmp; p++) { indices[p] = (int)ind.GetValue(p); } #endregion HYCALPER AUTO GENERATED CODE } else { throw new ILArgumentTypeException("error removing: dimensions specifier must be numeric type!"); } } if (indices == null) { dimensionIdx = 0; dimensions = m_dimensions; indices = new int[0] { }; return; } #endregion } else if (range[i] is Slice) { #region Python slice input Slice rng = (Slice)range[i]; if ((rng != null) && !(rng.start == null && rng.stop == null && rng.step == null)) { dimensionIdx = i; if (specCount++ > 0) { throw new ILArgumentException("Error removing: only one dimension must be non-empty!"); } List <int> ids = new List <int>(); int start, ende, step; if (rng.start == null) { start = 0; } else { start = (int)(rng.start); } if (rng.stop == null) { ende = m_dimensions[i]; } else { ende = (int)(rng.stop) + 1; } if (rng.step == null) { step = 1; } else { step = (int)(rng.step); } try { for (int r = start; r < ende; r += step) { ids.Add(r); } indices = ids.ToArray(); } catch (FormatException e) { throw new ILArgumentException("remove: invalid index in " + i.ToString() + "th dimension! (" + e.Message + ")"); } if (indices == null) { dimensionIdx = 0; dimensions = m_dimensions; indices = new int[0] { }; return; } } #endregion } else if (range is string[]) { #region string input string rng = (string)range[i]; if (rng.Contains(";")) { throw new ILArgumentException("Error removing: ';' not valid"); } if (rng != null && rng.Trim() != ":") { dimensionIdx = i; if (specCount++ > 0) { throw new ILArgumentException("Error removing: only one dimension must be non-empty!"); } rng = rng.Replace("end", (m_dimensions[i] - 1).ToString()); string[] tmpIdx = rng.Split(','); List <int> ids = new List <int>(); try { for (int c = 0; c < tmpIdx.Length; c++) { string[] tmprng = tmpIdx[c].Split(':'); switch (tmprng.Length) { case 1: // no range spec. ids.Add(int.Parse(tmprng[0].Trim())); break; case 2: // single range: spacing 1 int start = int.Parse(tmprng[0].Trim()); int ende = int.Parse(tmprng[1].Trim()) + 1; for (int r = start; r < ende; r++) { ids.Add(r); } break; case 3: // single range: spacing 1 start = int.Parse(tmprng[0].Trim()); ende = int.Parse(tmprng[2].Trim()) + 1; int step = int.Parse(tmprng[1].Trim()); for (int r = start; r < ende; r += step) { ids.Add(r); } break; } } indices = ids.ToArray(); } catch (FormatException e) { throw new ILArgumentException("remove: invalid index in " + i.ToString() + "th dimension! Did you seperate dimensions by ';'? (" + e.Message + ")"); } } if (indices == null) { dimensionIdx = 0; dimensions = m_dimensions; indices = new int[0] { }; return; } #endregion } else { throw new ILArgumentException("Invalid range specification. The type of indices specified is invalid. Remove failed."); } } // check if array must be reshaped int[] tmpDim = new int[(inDimCount > 1) ? inDimCount : 2]; int pos = 0; while (pos < m_dimensions.NumberOfDimensions) { if (pos < inDimCount) { tmpDim[pos] = m_dimensions[pos]; } else { int mult = 1; int i = pos; while (i < m_dimensions.NumberOfDimensions) { mult *= m_dimensions[i++]; } tmpDim[pos - 1] *= mult; break; } pos++; } // if only one dimension specified -> make row vector if (pos == 1) { tmpDim[1] = tmpDim[0]; tmpDim[0] = 1; dimensionIdx = 1; } dimensions = new ILDimension(tmpDim); }