Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Problems.GaussianProcessTuning/ILNumerics.2.14.4735.573/Storage/ILDenseStorage.cs @ 12518

Last change on this file since 12518 was 9102, checked in by gkronber, 12 years ago

#1967: ILNumerics source for experimentation

File size: 146.1 KB
Line 
1///
2///    This file is part of ILNumerics Community Edition.
3///
4///    ILNumerics Community Edition - high performance computing for applications.
5///    Copyright (C) 2006 - 2012 Haymo Kutschbach, http://ilnumerics.net
6///
7///    ILNumerics Community Edition is free software: you can redistribute it and/or modify
8///    it under the terms of the GNU General Public License version 3 as published by
9///    the Free Software Foundation.
10///
11///    ILNumerics Community Edition is distributed in the hope that it will be useful,
12///    but WITHOUT ANY WARRANTY; without even the implied warranty of
13///    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14///    GNU General Public License for more details.
15///
16///    You should have received a copy of the GNU General Public License
17///    along with ILNumerics Community Edition. See the file License.txt in the root
18///    of your distribution package. If not, see <http://www.gnu.org/licenses/>.
19///
20///    In addition this software uses the following components and/or licenses:
21///
22///    =================================================================================
23///    The Open Toolkit Library License
24///   
25///    Copyright (c) 2006 - 2009 the Open Toolkit library.
26///   
27///    Permission is hereby granted, free of charge, to any person obtaining a copy
28///    of this software and associated documentation files (the "Software"), to deal
29///    in the Software without restriction, including without limitation the rights to
30///    use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
31///    the Software, and to permit persons to whom the Software is furnished to do
32///    so, subject to the following conditions:
33///
34///    The above copyright notice and this permission notice shall be included in all
35///    copies or substantial portions of the Software.
36///
37///    =================================================================================
38///   
39
40using System;
41using System.Collections.Generic;
42using System.Text;
43using System.IO;
44using System.Runtime.Serialization;
45using System.Runtime.CompilerServices;
46using System.Numerics;
47using ILNumerics.Misc;
48using ILNumerics.Data;
49using ILNumerics.Exceptions;
50using System.Linq.Expressions;
51
52namespace ILNumerics.Storage {
53
54    /// <summary>
55    /// The class realizes an internal storage wrapper. It stores the internal data array
56    /// and the dimension specifications for both: ILRetArray and ILDenseStorage (reference and solid).
57    /// </summary>
58    [System.Diagnostics.DebuggerTypeProxy(typeof(ILNumerics.Misc.ILArrayDebuggerProxy<>))]
59    [System.Diagnostics.DebuggerDisplay("{ShortInfo(),nq}")]
60    [Serializable]
61    internal partial class ILDenseStorage<ElementType> : ILStorage<ElementType> {
62
63        #region attributes
64        /// <summary>
65        /// Internal storage object. Contains the final System.Array storage and a reference counter.
66        /// </summary>
67        [System.Diagnostics.DebuggerBrowsable(System.Diagnostics.DebuggerBrowsableState.Never)]
68        protected ILCountableArray<ElementType> m_data;
69        #endregion
70
71        #region properties
72
73        /// <summary>
74        /// number of storages referencing the current data array
75        /// </summary>
76        internal int ReferenceCount {
77            get {
78                return m_data.ReferenceCount;
79            }
80        }
81
82        /// <summary>
83        /// Determine, if this storage has already been disposed.
84        /// </summary>
85        internal override bool IsDisposed {
86            get {
87                return m_data == null;
88            }
89        }
90        protected ILCountableArray<ElementType> Data {
91            get {
92                return m_data;
93            }
94            set {
95                ILCountableArray<ElementType> old = m_data;
96                m_data = value;
97                m_data.IncreaseReference();
98                if (old != null)
99                    old.DecreaseReference();
100            }
101        }
102        /// <summary>
103        /// Get minimum and maximum value of all elements - if these exist.
104        /// </summary>
105        /// <param name="minValue">Output: minimum value.</param>
106        /// <param name="maxValue">Output: maximum value.</param>
107        /// <returns>True if the limits exists and could be computed, false otherwise.</returns>
108        /// <remarks>Empty arrays will return false. The output parameter will be default(type).</remarks>
109        internal override bool GetLimits(out ElementType minValue, out ElementType maxValue) {
110            return GetLimits(out minValue, out maxValue, true);
111        }
112        /// <summary>
113        /// Get minimum and maximum value of all elements - if existing
114        /// </summary>
115        /// <param name="minValue">Output: minimum value.</param>
116        /// <param name="maxValue">Output: maximum value.</param>
117        /// <param name="includeInfNaNs">true: recognize Inf, NaN values; false: ignore those values</param>
118        /// <returns>True if the limits exists and could be computed, false otherwise.</returns>
119        /// <remarks>Empty arrays will return false. The output parameter will be default(ElementType) then.</remarks>
120        internal override bool GetLimits(out ElementType minValue, out ElementType maxValue, bool includeInfNaNs) {
121            minValue = default(ElementType);   
122            maxValue = default(ElementType);
123            if (m_size.NumberOfElements == 0)
124                return false;
125            if (false) {
126
127   
128                } else if (this is ILDenseStorage<double> ) {   
129                     double [] data = ( double [])(object) GetArrayForRead();
130                     double curVal;
131                     double curMin =  Double.PositiveInfinity ;
132                     double curMax =  Double.NegativeInfinity ;
133                    int curMinInd = 0;
134                    int curMaxInd = 0;
135                    int len = m_size.NumberOfElements;
136
137                    for (int i = 0; i < len; i++) {
138                        curVal = data[i];
139                       
140                        if (double.IsInfinity(curVal)) continue;
141                        if (curVal < curMin) {
142                            curMin = curVal;
143                            curMinInd = i;
144                        }
145                        if (curVal > curMax) {
146                            curMax = curVal;
147                            curMaxInd = i;
148                        }
149                    }
150                    maxValue = m_data.Data[curMaxInd];
151                    minValue = m_data.Data[curMinInd];
152                    return (curMax >  Double.NegativeInfinity || curMin <  Double.PositiveInfinity );
153
154#region HYCALPER AUTO GENERATED CODE
155
156   
157                } else if (this is ILDenseStorage<fcomplex> ) {   
158                    fcomplex [] data = ( fcomplex [])(object) GetArrayForRead();
159                    fcomplex curVal;
160                    fcomplex curMin =  new fcomplex(float.PositiveInfinity,float.PositiveInfinity) ;
161                    fcomplex curMax =  new fcomplex(float.NegativeInfinity,float.NegativeInfinity) ;
162                    int curMinInd = 0;
163                    int curMaxInd = 0;
164                    int len = m_size.NumberOfElements;
165
166                    for (int i = 0; i < len; i++) {
167                        curVal = data[i];
168                        if (fcomplex.IsInfinity(curVal)) continue;
169                        if (curVal < curMin) {
170                            curMin = curVal;
171                            curMinInd = i;
172                        }
173                        if (curVal > curMax) {
174                            curMax = curVal;
175                            curMaxInd = i;
176                        }
177                    }
178                    maxValue = m_data.Data[curMaxInd];
179                    minValue = m_data.Data[curMinInd];
180                    return (curMax >  new fcomplex(float.NegativeInfinity,float.NegativeInfinity) || curMin <  new fcomplex(float.NegativeInfinity,float.NegativeInfinity) );
181   
182                } else if (this is ILDenseStorage<complex> ) {   
183                    complex [] data = ( complex [])(object) GetArrayForRead();
184                    complex curVal;
185                    complex curMin =  new complex(Double.PositiveInfinity,Double.PositiveInfinity) ;
186                    complex curMax =  new complex(Double.NegativeInfinity,Double.NegativeInfinity) ;
187                    int curMinInd = 0;
188                    int curMaxInd = 0;
189                    int len = m_size.NumberOfElements;
190
191                    for (int i = 0; i < len; i++) {
192                        curVal = data[i];
193                        if (complex.IsInfinity(curVal)) continue;
194                        if (curVal < curMin) {
195                            curMin = curVal;
196                            curMinInd = i;
197                        }
198                        if (curVal > curMax) {
199                            curMax = curVal;
200                            curMaxInd = i;
201                        }
202                    }
203                    maxValue = m_data.Data[curMaxInd];
204                    minValue = m_data.Data[curMinInd];
205                    return (curMax >  new complex(Double.NegativeInfinity,Double.NegativeInfinity) || curMin <  new complex(Double.NegativeInfinity,Double.NegativeInfinity) );
206   
207                } else if (this is ILDenseStorage<byte> ) {   
208                    byte [] data = ( byte [])(object) GetArrayForRead();
209                    byte curVal;
210                    byte curMin =  Byte.MaxValue ;
211                    byte curMax =  Byte.MinValue ;
212                    int curMinInd = 0;
213                    int curMaxInd = 0;
214                    int len = m_size.NumberOfElements;
215
216                    for (int i = 0; i < len; i++) {
217                        curVal = data[i];
218                       
219                        if (curVal < curMin) {
220                            curMin = curVal;
221                            curMinInd = i;
222                        }
223                        if (curVal > curMax) {
224                            curMax = curVal;
225                            curMaxInd = i;
226                        }
227                    }
228                    maxValue = m_data.Data[curMaxInd];
229                    minValue = m_data.Data[curMinInd];
230                    return (curMax >  Byte.MinValue || curMin <  Byte.MinValue );
231   
232                } else if (this is ILDenseStorage<Int64> ) {   
233                    Int64 [] data = ( Int64 [])(object) GetArrayForRead();
234                    Int64 curVal;
235                    Int64 curMin =  Int64.MaxValue ;
236                    Int64 curMax =  Int64.MinValue ;
237                    int curMinInd = 0;
238                    int curMaxInd = 0;
239                    int len = m_size.NumberOfElements;
240
241                    for (int i = 0; i < len; i++) {
242                        curVal = data[i];
243                       
244                        if (curVal < curMin) {
245                            curMin = curVal;
246                            curMinInd = i;
247                        }
248                        if (curVal > curMax) {
249                            curMax = curVal;
250                            curMaxInd = i;
251                        }
252                    }
253                    maxValue = m_data.Data[curMaxInd];
254                    minValue = m_data.Data[curMinInd];
255                    return (curMax >  Int64.MinValue || curMin <  Int64.MinValue );
256   
257                } else if (this is ILDenseStorage<Int32> ) {   
258                    Int32 [] data = ( Int32 [])(object) GetArrayForRead();
259                    Int32 curVal;
260                    Int32 curMin =  Int32.MaxValue ;
261                    Int32 curMax =  Int32.MinValue ;
262                    int curMinInd = 0;
263                    int curMaxInd = 0;
264                    int len = m_size.NumberOfElements;
265
266                    for (int i = 0; i < len; i++) {
267                        curVal = data[i];
268                       
269                        if (curVal < curMin) {
270                            curMin = curVal;
271                            curMinInd = i;
272                        }
273                        if (curVal > curMax) {
274                            curMax = curVal;
275                            curMaxInd = i;
276                        }
277                    }
278                    maxValue = m_data.Data[curMaxInd];
279                    minValue = m_data.Data[curMinInd];
280                    return (curMax >  Int32.MinValue || curMin <  Int32.MinValue );
281   
282                } else if (this is ILDenseStorage<float> ) {   
283                    float [] data = ( float [])(object) GetArrayForRead();
284                    float curVal;
285                    float curMin =  float.PositiveInfinity ;
286                    float curMax =  float.NegativeInfinity ;
287                    int curMinInd = 0;
288                    int curMaxInd = 0;
289                    int len = m_size.NumberOfElements;
290
291                    for (int i = 0; i < len; i++) {
292                        curVal = data[i];
293                        if(float.IsInfinity(curVal)) continue;
294                        if (curVal < curMin) {
295                            curMin = curVal;
296                            curMinInd = i;
297                        }
298                        if (curVal > curMax) {
299                            curMax = curVal;
300                            curMaxInd = i;
301                        }
302                    }
303                    maxValue = m_data.Data[curMaxInd];
304                    minValue = m_data.Data[curMinInd];
305                    return (curMax >  float.NegativeInfinity || curMin <  float.NegativeInfinity );
306
307#endregion HYCALPER AUTO GENERATED CODE
308           } else if ((typeof(ElementType) is IComparable<ElementType>)) {
309                ElementType[] tmpArr = GetArrayForRead();
310                for (int i = 0; i < m_size.NumberOfElements; i++) {
311                    ElementType val = tmpArr[i];
312                    if (((IComparable<ElementType>)val).CompareTo(minValue) < 0)
313                        minValue = val;
314                    if (((IComparable<ElementType>)val).CompareTo(minValue) > 0)
315                        maxValue = val;
316                }
317                return true;
318            }
319            return false;
320        }
321#endregion
322
323        #region overriding object.ToString(), Equals()
324        /// <summary>
325        /// Write information about the ILDenseStorage to string.
326        /// </summary>
327        /// <returns>String containing general information about the current instance of
328        /// ILDenseStorage and the formatted elements' values.</returns>
329        /// <remarks>If the number of elements exceeds a certain amount, the display will be abreviated.</remarks>
330        public override string ToString() {
331            return ValuesToString(0).ToString();
332        }
333        /// <summary>
334        /// print formated values to string
335        /// </summary>
336        /// <param name="maxLength">Maximum number of characters per line. 0: no limit</param>
337        /// <returns>StringBuilder object filled with formated values.</returns>
338        internal override StringBuilder ValuesToString(int maxLength) {
339            StringBuilder s = new StringBuilder();
340            if (maxLength <= 0) maxLength = int.MaxValue;
341            //if (m_dimensions.NumberOfElements > 100000) {
342            //    s.Append(String.Format("({0})", m_dimensions.ToString()));
343            //    return s;
344            //}
345            if (m_size.NumberOfElements < 1)
346                return new StringBuilder("(Empty)");
347            int[] acc = new int[m_size.NumberOfDimensions];
348            int d;
349            String sElement;
350            int elemLength = 10;
351            //string format = "{0,20: E13;-E13; 0.0         } ";
352            int curLineLength = 0, curRowsCount = 0;
353            int maxRows = (maxLength == int.MaxValue) ? int.MaxValue : 500; // limit data rows in debugger view
354            if (false) {
355
356               
357            } else if (this.Data.Data.GetType() == typeof(  double [] )) {
358                #region
359                 double element;
360                 double [] elements = (this.Data.Data as  double []);
361                elemLength =  10 ;
362                 
363                double scaling = getScalingForPrint();
364                elemLength++;
365                while (acc[m_size.NumberOfDimensions - 1] <
366                        m_size[m_size.NumberOfDimensions - 1]) {
367                    // show only two first dimensions at the same time ...
368                    // print header
369                    if (m_size.NumberOfDimensions > 2 || scaling != 1) {
370                        if (s.Length > 0) s.Append(Environment.NewLine);
371                        s.Append("(:,:");
372                        for (d = 2; d < m_size.NumberOfDimensions; d++)
373                            s.Append(String.Format(",{0}", acc[d]));
374                        s.Append(") " + ((scaling!=1.0)? (scaling.ToString("e0") + " * "):""));
375                    }
376                    // show this for 2 leading dimensions
377                    for (int d0 = 0; d0 < m_size[0]; d0++) {
378                        if (++curRowsCount > maxRows) {
379                            s.Append(Environment.NewLine + "( ... more rows exist)");   
380                            return s;
381                        }
382                        if (s.Length > 0) s.Append(Environment.NewLine);
383                        acc[0] = d0; curLineLength = 0;
384                        for (int d1 = 0; d1 < m_size[1]; d1++) {
385                            acc[1] = d1;
386                            element = elements [m_size.IndexFromArray(acc)];
387                            if (!Object.ReferenceEquals(element,null)) {
388                               
389                                sElement = String.Format ((scaling == 1 && (int)element == element) ? "{0} " : "{0:f5} ", element / scaling).PadLeft(elemLength);
390                            } else {
391                                sElement = "(null)".PadLeft(elemLength);
392                            }
393                            curLineLength += sElement.Length;
394                            if (curLineLength > maxLength - " ...".Length) {
395                                s.Append(" ...");
396                                break; 
397                            } else {
398                                s.Append(sElement);
399                            }
400                        }
401                    }
402                    // increase higher dimension
403                    d = 2;
404                    while (d <= m_size.NumberOfDimensions - 1) {
405                        acc[d]++;
406                        if (acc[d] < m_size[d]) break;
407                        acc[d] = 0;
408                        d++;
409                    }
410                    if (d >= m_size.NumberOfDimensions) break;
411                }
412                #endregion
413
414#region HYCALPER AUTO GENERATED CODE
415
416               
417            } else if (this.Data.Data.GetType() == typeof(  float [] )) {
418                #region
419                float element;
420                float [] elements = (this.Data.Data as  float []);
421                elemLength =  5 ;
422                float scaling = (float)getScalingForPrint();
423                elemLength++;
424                while (acc[m_size.NumberOfDimensions - 1] <
425                        m_size[m_size.NumberOfDimensions - 1]) {
426                    // show only two first dimensions at the same time ...
427                    // print header
428                    if (m_size.NumberOfDimensions > 2 || scaling != 1) {
429                        if (s.Length > 0) s.Append(Environment.NewLine);
430                        s.Append("(:,:");
431                        for (d = 2; d < m_size.NumberOfDimensions; d++)
432                            s.Append(String.Format(",{0}", acc[d]));
433                        s.Append(") " + ((scaling!=1.0)? (scaling.ToString("e0") + " * "):""));
434                    }
435                    // show this for 2 leading dimensions
436                    for (int d0 = 0; d0 < m_size[0]; d0++) {
437                        if (++curRowsCount > maxRows) {
438                            s.Append(Environment.NewLine + "( ... more rows exist)");   
439                            return s;
440                        }
441                        if (s.Length > 0) s.Append(Environment.NewLine);
442                        acc[0] = d0; curLineLength = 0;
443                        for (int d1 = 0; d1 < m_size[1]; d1++) {
444                            acc[1] = d1;
445                            element = elements [m_size.IndexFromArray(acc)];
446                            if (!Object.ReferenceEquals(element,null)) {
447                                sElement = String.Format ("{0:f5} ", element / scaling).PadLeft(elemLength);
448                            } else {
449                                sElement = "(null)".PadLeft(elemLength);
450                            }
451                            curLineLength += sElement.Length;
452                            if (curLineLength > maxLength - " ...".Length) {
453                                s.Append(" ...");
454                                break; 
455                            } else {
456                                s.Append(sElement);
457                            }
458                        }
459                    }
460                    // increase higher dimension
461                    d = 2;
462                    while (d <= m_size.NumberOfDimensions - 1) {
463                        acc[d]++;
464                        if (acc[d] < m_size[d]) break;
465                        acc[d] = 0;
466                        d++;
467                    }
468                    if (d >= m_size.NumberOfDimensions) break;
469                }
470                #endregion
471               
472            } else if (this.Data.Data.GetType() == typeof(  fcomplex [] )) {
473                #region
474                fcomplex element;
475                fcomplex [] elements = (this.Data.Data as  fcomplex []);
476                elemLength =  24 ;
477                float scaling = (float)getScalingForPrint();
478                elemLength++;
479                while (acc[m_size.NumberOfDimensions - 1] <
480                        m_size[m_size.NumberOfDimensions - 1]) {
481                    // show only two first dimensions at the same time ...
482                    // print header
483                    if (m_size.NumberOfDimensions > 2 || scaling != 1) {
484                        if (s.Length > 0) s.Append(Environment.NewLine);
485                        s.Append("(:,:");
486                        for (d = 2; d < m_size.NumberOfDimensions; d++)
487                            s.Append(String.Format(",{0}", acc[d]));
488                        s.Append(") " + ((scaling!=1.0)? (scaling.ToString("e0") + " * "):""));
489                    }
490                    // show this for 2 leading dimensions
491                    for (int d0 = 0; d0 < m_size[0]; d0++) {
492                        if (++curRowsCount > maxRows) {
493                            s.Append(Environment.NewLine + "( ... more rows exist)");   
494                            return s;
495                        }
496                        if (s.Length > 0) s.Append(Environment.NewLine);
497                        acc[0] = d0; curLineLength = 0;
498                        for (int d1 = 0; d1 < m_size[1]; d1++) {
499                            acc[1] = d1;
500                            element = elements [m_size.IndexFromArray(acc)];
501                            if (!Object.ReferenceEquals(element,null)) {
502                                sElement = String.Format ("{0} ", (element / scaling).ToString(5)).PadLeft(elemLength);
503                            } else {
504                                sElement = "(null)".PadLeft(elemLength);
505                            }
506                            curLineLength += sElement.Length;
507                            if (curLineLength > maxLength - " ...".Length) {
508                                s.Append(" ...");
509                                break; 
510                            } else {
511                                s.Append(sElement);
512                            }
513                        }
514                    }
515                    // increase higher dimension
516                    d = 2;
517                    while (d <= m_size.NumberOfDimensions - 1) {
518                        acc[d]++;
519                        if (acc[d] < m_size[d]) break;
520                        acc[d] = 0;
521                        d++;
522                    }
523                    if (d >= m_size.NumberOfDimensions) break;
524                }
525                #endregion
526               
527            } else if (this.Data.Data.GetType() == typeof(  complex [] )) {
528                #region
529                complex element;
530                complex [] elements = (this.Data.Data as  complex []);
531                elemLength =  36 ;
532                double scaling = getScalingForPrint();
533                elemLength++;
534                while (acc[m_size.NumberOfDimensions - 1] <
535                        m_size[m_size.NumberOfDimensions - 1]) {
536                    // show only two first dimensions at the same time ...
537                    // print header
538                    if (m_size.NumberOfDimensions > 2 || scaling != 1) {
539                        if (s.Length > 0) s.Append(Environment.NewLine);
540                        s.Append("(:,:");
541                        for (d = 2; d < m_size.NumberOfDimensions; d++)
542                            s.Append(String.Format(",{0}", acc[d]));
543                        s.Append(") " + ((scaling!=1.0)? (scaling.ToString("e0") + " * "):""));
544                    }
545                    // show this for 2 leading dimensions
546                    for (int d0 = 0; d0 < m_size[0]; d0++) {
547                        if (++curRowsCount > maxRows) {
548                            s.Append(Environment.NewLine + "( ... more rows exist)");   
549                            return s;
550                        }
551                        if (s.Length > 0) s.Append(Environment.NewLine);
552                        acc[0] = d0; curLineLength = 0;
553                        for (int d1 = 0; d1 < m_size[1]; d1++) {
554                            acc[1] = d1;
555                            element = elements [m_size.IndexFromArray(acc)];
556                            if (!Object.ReferenceEquals(element,null)) {
557                                sElement = String.Format ("{0} ", (element / scaling).ToString(5)).PadLeft(elemLength);
558                            } else {
559                                sElement = "(null)".PadLeft(elemLength);
560                            }
561                            curLineLength += sElement.Length;
562                            if (curLineLength > maxLength - " ...".Length) {
563                                s.Append(" ...");
564                                break; 
565                            } else {
566                                s.Append(sElement);
567                            }
568                        }
569                    }
570                    // increase higher dimension
571                    d = 2;
572                    while (d <= m_size.NumberOfDimensions - 1) {
573                        acc[d]++;
574                        if (acc[d] < m_size[d]) break;
575                        acc[d] = 0;
576                        d++;
577                    }
578                    if (d >= m_size.NumberOfDimensions) break;
579                }
580                #endregion
581               
582            } else if (this.Data.Data.GetType() == typeof(  Complex [] )) {
583                #region
584                Complex element;
585                Complex [] elements = (this.Data.Data as  Complex []);
586                elemLength =  36 ;
587                double scaling = getScalingForPrint();
588                elemLength++;
589                while (acc[m_size.NumberOfDimensions - 1] <
590                        m_size[m_size.NumberOfDimensions - 1]) {
591                    // show only two first dimensions at the same time ...
592                    // print header
593                    if (m_size.NumberOfDimensions > 2 || scaling != 1) {
594                        if (s.Length > 0) s.Append(Environment.NewLine);
595                        s.Append("(:,:");
596                        for (d = 2; d < m_size.NumberOfDimensions; d++)
597                            s.Append(String.Format(",{0}", acc[d]));
598                        s.Append(") " + ((scaling!=1.0)? (scaling.ToString("e0") + " * "):""));
599                    }
600                    // show this for 2 leading dimensions
601                    for (int d0 = 0; d0 < m_size[0]; d0++) {
602                        if (++curRowsCount > maxRows) {
603                            s.Append(Environment.NewLine + "( ... more rows exist)");   
604                            return s;
605                        }
606                        if (s.Length > 0) s.Append(Environment.NewLine);
607                        acc[0] = d0; curLineLength = 0;
608                        for (int d1 = 0; d1 < m_size[1]; d1++) {
609                            acc[1] = d1;
610                            element = elements [m_size.IndexFromArray(acc)];
611                            if (!Object.ReferenceEquals(element,null)) {
612                                sElement = String.Format ("{0} ", ComplexHelper(element / scaling,5)).PadLeft(elemLength);
613                            } else {
614                                sElement = "(null)".PadLeft(elemLength);
615                            }
616                            curLineLength += sElement.Length;
617                            if (curLineLength > maxLength - " ...".Length) {
618                                s.Append(" ...");
619                                break; 
620                            } else {
621                                s.Append(sElement);
622                            }
623                        }
624                    }
625                    // increase higher dimension
626                    d = 2;
627                    while (d <= m_size.NumberOfDimensions - 1) {
628                        acc[d]++;
629                        if (acc[d] < m_size[d]) break;
630                        acc[d] = 0;
631                        d++;
632                    }
633                    if (d >= m_size.NumberOfDimensions) break;
634                }
635                #endregion
636               
637            } else if (this.Data.Data.GetType() == typeof(  byte [] )) {
638                #region
639                byte element;
640                byte [] elements = (this.Data.Data as  byte []);
641                elemLength =  3 ;
642                double scaling = 1.0;
643                elemLength++;
644                while (acc[m_size.NumberOfDimensions - 1] <
645                        m_size[m_size.NumberOfDimensions - 1]) {
646                    // show only two first dimensions at the same time ...
647                    // print header
648                    if (m_size.NumberOfDimensions > 2 || scaling != 1) {
649                        if (s.Length > 0) s.Append(Environment.NewLine);
650                        s.Append("(:,:");
651                        for (d = 2; d < m_size.NumberOfDimensions; d++)
652                            s.Append(String.Format(",{0}", acc[d]));
653                        s.Append(") " + ((scaling!=1.0)? (scaling.ToString("e0") + " * "):""));
654                    }
655                    // show this for 2 leading dimensions
656                    for (int d0 = 0; d0 < m_size[0]; d0++) {
657                        if (++curRowsCount > maxRows) {
658                            s.Append(Environment.NewLine + "( ... more rows exist)");   
659                            return s;
660                        }
661                        if (s.Length > 0) s.Append(Environment.NewLine);
662                        acc[0] = d0; curLineLength = 0;
663                        for (int d1 = 0; d1 < m_size[1]; d1++) {
664                            acc[1] = d1;
665                            element = elements [m_size.IndexFromArray(acc)];
666                            if (!Object.ReferenceEquals(element,null)) {
667                                sElement = String.Format ("{0,3:G} ", element).PadLeft(elemLength);
668                            } else {
669                                sElement = "(null)".PadLeft(elemLength);
670                            }
671                            curLineLength += sElement.Length;
672                            if (curLineLength > maxLength - " ...".Length) {
673                                s.Append(" ...");
674                                break; 
675                            } else {
676                                s.Append(sElement);
677                            }
678                        }
679                    }
680                    // increase higher dimension
681                    d = 2;
682                    while (d <= m_size.NumberOfDimensions - 1) {
683                        acc[d]++;
684                        if (acc[d] < m_size[d]) break;
685                        acc[d] = 0;
686                        d++;
687                    }
688                    if (d >= m_size.NumberOfDimensions) break;
689                }
690                #endregion
691               
692            } else if (this.Data.Data.GetType() == typeof(  char [] )) {
693                #region
694                char element;
695                char [] elements = (this.Data.Data as  char []);
696                elemLength =  3 ;
697                double scaling = 1.0;
698                elemLength++;
699                while (acc[m_size.NumberOfDimensions - 1] <
700                        m_size[m_size.NumberOfDimensions - 1]) {
701                    // show only two first dimensions at the same time ...
702                    // print header
703                    if (m_size.NumberOfDimensions > 2 || scaling != 1) {
704                        if (s.Length > 0) s.Append(Environment.NewLine);
705                        s.Append("(:,:");
706                        for (d = 2; d < m_size.NumberOfDimensions; d++)
707                            s.Append(String.Format(",{0}", acc[d]));
708                        s.Append(") " + ((scaling!=1.0)? (scaling.ToString("e0") + " * "):""));
709                    }
710                    // show this for 2 leading dimensions
711                    for (int d0 = 0; d0 < m_size[0]; d0++) {
712                        if (++curRowsCount > maxRows) {
713                            s.Append(Environment.NewLine + "( ... more rows exist)");   
714                            return s;
715                        }
716                        if (s.Length > 0) s.Append(Environment.NewLine);
717                        acc[0] = d0; curLineLength = 0;
718                        for (int d1 = 0; d1 < m_size[1]; d1++) {
719                            acc[1] = d1;
720                            element = elements [m_size.IndexFromArray(acc)];
721                            if (!Object.ReferenceEquals(element,null)) {
722                                sElement = String.Format ("{0,3:G} ", element).PadLeft(elemLength);
723                            } else {
724                                sElement = "(null)".PadLeft(elemLength);
725                            }
726                            curLineLength += sElement.Length;
727                            if (curLineLength > maxLength - " ...".Length) {
728                                s.Append(" ...");
729                                break; 
730                            } else {
731                                s.Append(sElement);
732                            }
733                        }
734                    }
735                    // increase higher dimension
736                    d = 2;
737                    while (d <= m_size.NumberOfDimensions - 1) {
738                        acc[d]++;
739                        if (acc[d] < m_size[d]) break;
740                        acc[d] = 0;
741                        d++;
742                    }
743                    if (d >= m_size.NumberOfDimensions) break;
744                }
745                #endregion
746               
747            } else if (this.Data.Data.GetType() == typeof(  UInt64 [] )) {
748                #region
749                UInt64 element;
750                UInt64 [] elements = (this.Data.Data as  UInt64 []);
751                elemLength =  18 ;
752                double scaling = 1.0;
753                elemLength++;
754                while (acc[m_size.NumberOfDimensions - 1] <
755                        m_size[m_size.NumberOfDimensions - 1]) {
756                    // show only two first dimensions at the same time ...
757                    // print header
758                    if (m_size.NumberOfDimensions > 2 || scaling != 1) {
759                        if (s.Length > 0) s.Append(Environment.NewLine);
760                        s.Append("(:,:");
761                        for (d = 2; d < m_size.NumberOfDimensions; d++)
762                            s.Append(String.Format(",{0}", acc[d]));
763                        s.Append(") " + ((scaling!=1.0)? (scaling.ToString("e0") + " * "):""));
764                    }
765                    // show this for 2 leading dimensions
766                    for (int d0 = 0; d0 < m_size[0]; d0++) {
767                        if (++curRowsCount > maxRows) {
768                            s.Append(Environment.NewLine + "( ... more rows exist)");   
769                            return s;
770                        }
771                        if (s.Length > 0) s.Append(Environment.NewLine);
772                        acc[0] = d0; curLineLength = 0;
773                        for (int d1 = 0; d1 < m_size[1]; d1++) {
774                            acc[1] = d1;
775                            element = elements [m_size.IndexFromArray(acc)];
776                            if (!Object.ReferenceEquals(element,null)) {
777                                sElement = String.Format ("{0,18:G} ", element).PadLeft(elemLength);
778                            } else {
779                                sElement = "(null)".PadLeft(elemLength);
780                            }
781                            curLineLength += sElement.Length;
782                            if (curLineLength > maxLength - " ...".Length) {
783                                s.Append(" ...");
784                                break; 
785                            } else {
786                                s.Append(sElement);
787                            }
788                        }
789                    }
790                    // increase higher dimension
791                    d = 2;
792                    while (d <= m_size.NumberOfDimensions - 1) {
793                        acc[d]++;
794                        if (acc[d] < m_size[d]) break;
795                        acc[d] = 0;
796                        d++;
797                    }
798                    if (d >= m_size.NumberOfDimensions) break;
799                }
800                #endregion
801               
802            } else if (this.Data.Data.GetType() == typeof(  UInt32 [] )) {
803                #region
804                UInt32 element;
805                UInt32 [] elements = (this.Data.Data as  UInt32 []);
806                elemLength =  10 ;
807                double scaling = 1.0;
808                elemLength++;
809                while (acc[m_size.NumberOfDimensions - 1] <
810                        m_size[m_size.NumberOfDimensions - 1]) {
811                    // show only two first dimensions at the same time ...
812                    // print header
813                    if (m_size.NumberOfDimensions > 2 || scaling != 1) {
814                        if (s.Length > 0) s.Append(Environment.NewLine);
815                        s.Append("(:,:");
816                        for (d = 2; d < m_size.NumberOfDimensions; d++)
817                            s.Append(String.Format(",{0}", acc[d]));
818                        s.Append(") " + ((scaling!=1.0)? (scaling.ToString("e0") + " * "):""));
819                    }
820                    // show this for 2 leading dimensions
821                    for (int d0 = 0; d0 < m_size[0]; d0++) {
822                        if (++curRowsCount > maxRows) {
823                            s.Append(Environment.NewLine + "( ... more rows exist)");   
824                            return s;
825                        }
826                        if (s.Length > 0) s.Append(Environment.NewLine);
827                        acc[0] = d0; curLineLength = 0;
828                        for (int d1 = 0; d1 < m_size[1]; d1++) {
829                            acc[1] = d1;
830                            element = elements [m_size.IndexFromArray(acc)];
831                            if (!Object.ReferenceEquals(element,null)) {
832                                sElement = String.Format ("{0,10:G} ", element).PadLeft(elemLength);
833                            } else {
834                                sElement = "(null)".PadLeft(elemLength);
835                            }
836                            curLineLength += sElement.Length;
837                            if (curLineLength > maxLength - " ...".Length) {
838                                s.Append(" ...");
839                                break; 
840                            } else {
841                                s.Append(sElement);
842                            }
843                        }
844                    }
845                    // increase higher dimension
846                    d = 2;
847                    while (d <= m_size.NumberOfDimensions - 1) {
848                        acc[d]++;
849                        if (acc[d] < m_size[d]) break;
850                        acc[d] = 0;
851                        d++;
852                    }
853                    if (d >= m_size.NumberOfDimensions) break;
854                }
855                #endregion
856               
857            } else if (this.Data.Data.GetType() == typeof(  UInt16 [] )) {
858                #region
859                UInt16 element;
860                UInt16 [] elements = (this.Data.Data as  UInt16 []);
861                elemLength =  5 ;
862                double scaling = 1.0;
863                elemLength++;
864                while (acc[m_size.NumberOfDimensions - 1] <
865                        m_size[m_size.NumberOfDimensions - 1]) {
866                    // show only two first dimensions at the same time ...
867                    // print header
868                    if (m_size.NumberOfDimensions > 2 || scaling != 1) {
869                        if (s.Length > 0) s.Append(Environment.NewLine);
870                        s.Append("(:,:");
871                        for (d = 2; d < m_size.NumberOfDimensions; d++)
872                            s.Append(String.Format(",{0}", acc[d]));
873                        s.Append(") " + ((scaling!=1.0)? (scaling.ToString("e0") + " * "):""));
874                    }
875                    // show this for 2 leading dimensions
876                    for (int d0 = 0; d0 < m_size[0]; d0++) {
877                        if (++curRowsCount > maxRows) {
878                            s.Append(Environment.NewLine + "( ... more rows exist)");   
879                            return s;
880                        }
881                        if (s.Length > 0) s.Append(Environment.NewLine);
882                        acc[0] = d0; curLineLength = 0;
883                        for (int d1 = 0; d1 < m_size[1]; d1++) {
884                            acc[1] = d1;
885                            element = elements [m_size.IndexFromArray(acc)];
886                            if (!Object.ReferenceEquals(element,null)) {
887                                sElement = String.Format ("{0,5:G} ", element).PadLeft(elemLength);
888                            } else {
889                                sElement = "(null)".PadLeft(elemLength);
890                            }
891                            curLineLength += sElement.Length;
892                            if (curLineLength > maxLength - " ...".Length) {
893                                s.Append(" ...");
894                                break; 
895                            } else {
896                                s.Append(sElement);
897                            }
898                        }
899                    }
900                    // increase higher dimension
901                    d = 2;
902                    while (d <= m_size.NumberOfDimensions - 1) {
903                        acc[d]++;
904                        if (acc[d] < m_size[d]) break;
905                        acc[d] = 0;
906                        d++;
907                    }
908                    if (d >= m_size.NumberOfDimensions) break;
909                }
910                #endregion
911               
912            } else if (this.Data.Data.GetType() == typeof(  Int64 [] )) {
913                #region
914                Int64 element;
915                Int64 [] elements = (this.Data.Data as  Int64 []);
916                elemLength =  18 ;
917                double scaling = 1.0;
918                elemLength++;
919                while (acc[m_size.NumberOfDimensions - 1] <
920                        m_size[m_size.NumberOfDimensions - 1]) {
921                    // show only two first dimensions at the same time ...
922                    // print header
923                    if (m_size.NumberOfDimensions > 2 || scaling != 1) {
924                        if (s.Length > 0) s.Append(Environment.NewLine);
925                        s.Append("(:,:");
926                        for (d = 2; d < m_size.NumberOfDimensions; d++)
927                            s.Append(String.Format(",{0}", acc[d]));
928                        s.Append(") " + ((scaling!=1.0)? (scaling.ToString("e0") + " * "):""));
929                    }
930                    // show this for 2 leading dimensions
931                    for (int d0 = 0; d0 < m_size[0]; d0++) {
932                        if (++curRowsCount > maxRows) {
933                            s.Append(Environment.NewLine + "( ... more rows exist)");   
934                            return s;
935                        }
936                        if (s.Length > 0) s.Append(Environment.NewLine);
937                        acc[0] = d0; curLineLength = 0;
938                        for (int d1 = 0; d1 < m_size[1]; d1++) {
939                            acc[1] = d1;
940                            element = elements [m_size.IndexFromArray(acc)];
941                            if (!Object.ReferenceEquals(element,null)) {
942                                sElement = String.Format ("{0,18:G} ", element).PadLeft(elemLength);
943                            } else {
944                                sElement = "(null)".PadLeft(elemLength);
945                            }
946                            curLineLength += sElement.Length;
947                            if (curLineLength > maxLength - " ...".Length) {
948                                s.Append(" ...");
949                                break; 
950                            } else {
951                                s.Append(sElement);
952                            }
953                        }
954                    }
955                    // increase higher dimension
956                    d = 2;
957                    while (d <= m_size.NumberOfDimensions - 1) {
958                        acc[d]++;
959                        if (acc[d] < m_size[d]) break;
960                        acc[d] = 0;
961                        d++;
962                    }
963                    if (d >= m_size.NumberOfDimensions) break;
964                }
965                #endregion
966               
967            } else if (this.Data.Data.GetType() == typeof(  Int32 [] )) {
968                #region
969                Int32 element;
970                Int32 [] elements = (this.Data.Data as  Int32 []);
971                elemLength =  10 ;
972                double scaling = 1.0;
973                elemLength++;
974                while (acc[m_size.NumberOfDimensions - 1] <
975                        m_size[m_size.NumberOfDimensions - 1]) {
976                    // show only two first dimensions at the same time ...
977                    // print header
978                    if (m_size.NumberOfDimensions > 2 || scaling != 1) {
979                        if (s.Length > 0) s.Append(Environment.NewLine);
980                        s.Append("(:,:");
981                        for (d = 2; d < m_size.NumberOfDimensions; d++)
982                            s.Append(String.Format(",{0}", acc[d]));
983                        s.Append(") " + ((scaling!=1.0)? (scaling.ToString("e0") + " * "):""));
984                    }
985                    // show this for 2 leading dimensions
986                    for (int d0 = 0; d0 < m_size[0]; d0++) {
987                        if (++curRowsCount > maxRows) {
988                            s.Append(Environment.NewLine + "( ... more rows exist)");   
989                            return s;
990                        }
991                        if (s.Length > 0) s.Append(Environment.NewLine);
992                        acc[0] = d0; curLineLength = 0;
993                        for (int d1 = 0; d1 < m_size[1]; d1++) {
994                            acc[1] = d1;
995                            element = elements [m_size.IndexFromArray(acc)];
996                            if (!Object.ReferenceEquals(element,null)) {
997                                sElement = String.Format ("{0,10:G} ", element).PadLeft(elemLength);
998                            } else {
999                                sElement = "(null)".PadLeft(elemLength);
1000                            }
1001                            curLineLength += sElement.Length;
1002                            if (curLineLength > maxLength - " ...".Length) {
1003                                s.Append(" ...");
1004                                break; 
1005                            } else {
1006                                s.Append(sElement);
1007                            }
1008                        }
1009                    }
1010                    // increase higher dimension
1011                    d = 2;
1012                    while (d <= m_size.NumberOfDimensions - 1) {
1013                        acc[d]++;
1014                        if (acc[d] < m_size[d]) break;
1015                        acc[d] = 0;
1016                        d++;
1017                    }
1018                    if (d >= m_size.NumberOfDimensions) break;
1019                }
1020                #endregion
1021               
1022            } else if (this.Data.Data.GetType() == typeof(  Int16 [] )) {
1023                #region
1024                Int16 element;
1025                Int16 [] elements = (this.Data.Data as  Int16 []);
1026                elemLength =  5 ;
1027                double scaling = 1.0;
1028                elemLength++;
1029                while (acc[m_size.NumberOfDimensions - 1] <
1030                        m_size[m_size.NumberOfDimensions - 1]) {
1031                    // show only two first dimensions at the same time ...
1032                    // print header
1033                    if (m_size.NumberOfDimensions > 2 || scaling != 1) {
1034                        if (s.Length > 0) s.Append(Environment.NewLine);
1035                        s.Append("(:,:");
1036                        for (d = 2; d < m_size.NumberOfDimensions; d++)
1037                            s.Append(String.Format(",{0}", acc[d]));
1038                        s.Append(") " + ((scaling!=1.0)? (scaling.ToString("e0") + " * "):""));
1039                    }
1040                    // show this for 2 leading dimensions
1041                    for (int d0 = 0; d0 < m_size[0]; d0++) {
1042                        if (++curRowsCount > maxRows) {
1043                            s.Append(Environment.NewLine + "( ... more rows exist)");   
1044                            return s;
1045                        }
1046                        if (s.Length > 0) s.Append(Environment.NewLine);
1047                        acc[0] = d0; curLineLength = 0;
1048                        for (int d1 = 0; d1 < m_size[1]; d1++) {
1049                            acc[1] = d1;
1050                            element = elements [m_size.IndexFromArray(acc)];
1051                            if (!Object.ReferenceEquals(element,null)) {
1052                                sElement = String.Format ("{0,5:G} ", element).PadLeft(elemLength);
1053                            } else {
1054                                sElement = "(null)".PadLeft(elemLength);
1055                            }
1056                            curLineLength += sElement.Length;
1057                            if (curLineLength > maxLength - " ...".Length) {
1058                                s.Append(" ...");
1059                                break; 
1060                            } else {
1061                                s.Append(sElement);
1062                            }
1063                        }
1064                    }
1065                    // increase higher dimension
1066                    d = 2;
1067                    while (d <= m_size.NumberOfDimensions - 1) {
1068                        acc[d]++;
1069                        if (acc[d] < m_size[d]) break;
1070                        acc[d] = 0;
1071                        d++;
1072                    }
1073                    if (d >= m_size.NumberOfDimensions) break;
1074                }
1075                #endregion
1076               
1077            } else if (this.Data.Data.GetType() == typeof(  ILStorage [] )) {
1078                #region
1079                ILStorage element;
1080                ILStorage [] elements = (this.Data.Data as  ILStorage []);
1081                elemLength =  0 ;
1082                double scaling = 1.0;
1083                for (int i = 0; i < m_size.NumberOfElements; i++) {
1084                    element = elements[i];
1085                    int l = (element == null)? 6 : element.ShortInfo().Length;
1086                    if (l > elemLength) elemLength = l;
1087                }
1088
1089                elemLength++;
1090                while (acc[m_size.NumberOfDimensions - 1] <
1091                        m_size[m_size.NumberOfDimensions - 1]) {
1092                    // show only two first dimensions at the same time ...
1093                    // print header
1094                    if (m_size.NumberOfDimensions > 2 || scaling != 1) {
1095                        if (s.Length > 0) s.Append(Environment.NewLine);
1096                        s.Append("(:,:");
1097                        for (d = 2; d < m_size.NumberOfDimensions; d++)
1098                            s.Append(String.Format(",{0}", acc[d]));
1099                        s.Append(") " + ((scaling!=1.0)? (scaling.ToString("e0") + " * "):""));
1100                    }
1101                    // show this for 2 leading dimensions
1102                    for (int d0 = 0; d0 < m_size[0]; d0++) {
1103                        if (++curRowsCount > maxRows) {
1104                            s.Append(Environment.NewLine + "( ... more rows exist)");   
1105                            return s;
1106                        }
1107                        if (s.Length > 0) s.Append(Environment.NewLine);
1108                        acc[0] = d0; curLineLength = 0;
1109                        for (int d1 = 0; d1 < m_size[1]; d1++) {
1110                            acc[1] = d1;
1111                            element = elements [m_size.IndexFromArray(acc)];
1112                            if (!Object.ReferenceEquals(element,null)) {
1113                                sElement = element.ShortInfo().PadRight(elemLength);
1114                            } else {
1115                                sElement = "(null)".PadLeft(elemLength);
1116                            }
1117                            curLineLength += sElement.Length;
1118                            if (curLineLength > maxLength - " ...".Length) {
1119                                s.Append(" ...");
1120                                break; 
1121                            } else {
1122                                s.Append(sElement);
1123                            }
1124                        }
1125                    }
1126                    // increase higher dimension
1127                    d = 2;
1128                    while (d <= m_size.NumberOfDimensions - 1) {
1129                        acc[d]++;
1130                        if (acc[d] < m_size[d]) break;
1131                        acc[d] = 0;
1132                        d++;
1133                    }
1134                    if (d >= m_size.NumberOfDimensions) break;
1135                }
1136                #endregion
1137               
1138            } else if (this.Data.Data.GetType() == typeof(  object [] )) {
1139                #region
1140                object element;
1141                object [] elements = (this.Data.Data as  object []);
1142                elemLength =  18 ;
1143                double scaling = 1.0;
1144                elemLength++;
1145                while (acc[m_size.NumberOfDimensions - 1] <
1146                        m_size[m_size.NumberOfDimensions - 1]) {
1147                    // show only two first dimensions at the same time ...
1148                    // print header
1149                    if (m_size.NumberOfDimensions > 2 || scaling != 1) {
1150                        if (s.Length > 0) s.Append(Environment.NewLine);
1151                        s.Append("(:,:");
1152                        for (d = 2; d < m_size.NumberOfDimensions; d++)
1153                            s.Append(String.Format(",{0}", acc[d]));
1154                        s.Append(") " + ((scaling!=1.0)? (scaling.ToString("e0") + " * "):""));
1155                    }
1156                    // show this for 2 leading dimensions
1157                    for (int d0 = 0; d0 < m_size[0]; d0++) {
1158                        if (++curRowsCount > maxRows) {
1159                            s.Append(Environment.NewLine + "( ... more rows exist)");   
1160                            return s;
1161                        }
1162                        if (s.Length > 0) s.Append(Environment.NewLine);
1163                        acc[0] = d0; curLineLength = 0;
1164                        for (int d1 = 0; d1 < m_size[1]; d1++) {
1165                            acc[1] = d1;
1166                            element = elements [m_size.IndexFromArray(acc)];
1167                            if (!Object.ReferenceEquals(element,null)) {
1168                                sElement = String.Format ("{0} ", element).PadLeft(elemLength);
1169                            } else {
1170                                sElement = "(null)".PadLeft(elemLength);
1171                            }
1172                            curLineLength += sElement.Length;
1173                            if (curLineLength > maxLength - " ...".Length) {
1174                                s.Append(" ...");
1175                                break; 
1176                            } else {
1177                                s.Append(sElement);
1178                            }
1179                        }
1180                    }
1181                    // increase higher dimension
1182                    d = 2;
1183                    while (d <= m_size.NumberOfDimensions - 1) {
1184                        acc[d]++;
1185                        if (acc[d] < m_size[d]) break;
1186                        acc[d] = 0;
1187                        d++;
1188                    }
1189                    if (d >= m_size.NumberOfDimensions) break;
1190                }
1191                #endregion
1192
1193#endregion HYCALPER AUTO GENERATED CODE
1194           } else if (this is ILDenseStorage<string> ) {
1195                #region
1196                string element;
1197                string[] elements = (this.Data.Data as string[]);
1198                elemLength = 18;
1199                int maxElemLength = 50;  // todo: may better be a setting? abreviate after as many chars
1200                elemLength++;
1201                while (acc[m_size.NumberOfDimensions - 1] <
1202                        m_size[m_size.NumberOfDimensions - 1]) {
1203                    // show only two first dimensions at the same time ...
1204                    // print header
1205                    if (m_size.NumberOfDimensions > 2) {
1206                        if (s.Length > 0) s.Append(Environment.NewLine);
1207                        s.Append("(:,:");
1208                        for (d = 2; d < m_size.NumberOfDimensions; d++)
1209                            s.Append(String.Format(",{0}", acc[d]));
1210                        s.Append(") ");
1211                    }
1212                    // show this for 2 leading dimensions
1213                    for (int d0 = 0; d0 < m_size[0]; d0++) {
1214                        if (++curRowsCount > maxRows) {
1215                            s.Append(Environment.NewLine + "( ... more rows exist)");
1216                            return s;
1217                        }
1218                        if (s.Length > 0) s.Append(Environment.NewLine);
1219                        acc[0] = d0; curLineLength = 0;
1220                        for (int d1 = 0; d1 < m_size[1]; d1++) {
1221                            acc[1] = d1;
1222                            element = elements[m_size.IndexFromArray(acc)];
1223                            if (!Object.ReferenceEquals(element, null)) {
1224                                if (element.Length > maxElemLength) {
1225                                    sElement = element.Substring(0,maxElemLength - 3) + "...";
1226                                } else {
1227                                    sElement = String.Format("{0} ", element).PadLeft(elemLength);
1228                                }
1229                            } else {
1230                                sElement = "(null)".PadLeft(elemLength);
1231                            }
1232                            curLineLength += sElement.Length;
1233                            if (curLineLength > maxLength - " ...".Length) {
1234                                s.Append(" ...");
1235                                break;
1236                            } else {
1237                                s.Append(sElement);
1238                            }
1239                        }
1240                    }
1241                    // increase higher dimension
1242                    d = 2;
1243                    while (d <= m_size.NumberOfDimensions - 1) {
1244                        acc[d]++;
1245                        if (acc[d] < m_size[d]) break;
1246                        acc[d] = 0;
1247                        d++;
1248                    }
1249                    if (d >= m_size.NumberOfDimensions) break;
1250                }
1251                #endregion
1252            } else {
1253                return new StringBuilder ("(Unknown data type.)");
1254           }
1255            return s;
1256        }
1257        private double getScalingForPrint() {
1258            ElementType min, max;
1259            if (GetLimits(out min, out max, false)) {
1260                try {
1261                    double scaling = Math.Max(
1262                                        Math.Abs(double.Parse(min.ToString())),
1263                                        Math.Abs( double.Parse(max.ToString()))
1264                                     );
1265                    if (scaling == 0  || (scaling > 1e-1 && scaling < 1e1))
1266                        scaling = 1;
1267                    scaling = Math.Pow(10,Math.Floor(Math.Log10(scaling)));
1268                    if (scaling < 10000 && scaling >= 1)
1269                        scaling = 1;
1270                    return scaling;
1271                } catch (Exception) {
1272                    return 1.0;
1273                }
1274            } else {
1275                return 1.0;
1276            }
1277        }
1278        private int GetTypedElementStringProperties(double scaling, out string format) {
1279            format = "E+00000000000000;0.0;-E+00000000000000";
1280            if (this is ILDenseStorage<double>) {
1281                return double.MaxValue.ToString().Length;
1282            } else if (this is ILDenseStorage<float>) {
1283                return float.MaxValue.ToString().Length;
1284            } else if (this is ILDenseStorage<Complex>) {
1285                return double.MaxValue.ToString().Length * 2 + 2;
1286            } else if (this is ILDenseStorage<complex>) {
1287                return double.MaxValue.ToString().Length * 2 + 2;
1288            } else if (this is ILDenseStorage<fcomplex>) {
1289                return float.MaxValue.ToString().Length * 2 + 2;
1290            } else if (this is ILDenseStorage<char>) {
1291                return char.MaxValue.ToString().Length;
1292            } else if (this is ILDenseStorage<byte>) {
1293                return byte.MaxValue.ToString().Length;
1294            } else if (this is ILDenseStorage<Int16>) {
1295                return Int16.MaxValue.ToString().Length;
1296            } else if (this is ILDenseStorage<Int32>) {
1297                return Int32.MaxValue.ToString().Length;
1298            } else if (this is ILDenseStorage<Int64>) {
1299                return Int64.MaxValue.ToString().Length;
1300            } else if (this is ILDenseStorage<UInt16>) {
1301                return UInt16.MaxValue.ToString().Length;
1302            } else if (this is ILDenseStorage<UInt32>) {
1303                return UInt32.MaxValue.ToString().Length;
1304            } else if (this is ILDenseStorage<UInt64>) {
1305                return UInt64.MaxValue.ToString().Length;
1306            } else
1307                return 10;
1308        }
1309        private string ComplexHelper(Complex a, int digits) {
1310            if (digits < 1) return "";
1311            if (a.Imaginary >= 0) {
1312                return String.Format("{0:f10}+{1:f10}", a.Real, a.Imaginary);
1313            } else {
1314                return String.Format("{0:f10}-{1:f10}", a.Real, -a.Imaginary);
1315            }
1316        }
1317        /// <summary>
1318        /// Check if the content of this array equals the content of obj.
1319        /// </summary>
1320        /// <param name="obj">storage containing the values with which to compare this array.</param>
1321        /// <returns>True if all elements contained in obj are equal to the
1322        /// elements of this array, false otherwise.</returns>
1323        /// <remarks>This method compares the object references of corresponding elements.
1324        /// The size and type of both arrays must match. Otherwise false will be returned.</remarks>
1325        internal override bool Equals(object obj) {
1326            if (object.Equals(obj,null)) return false;
1327            if (obj is ElementType)
1328                if (Size.NumberOfElements == 1
1329                    && obj.ToString() == GetValueTyped(0).ToString())
1330                    return true;
1331                else
1332                    return false;
1333            ILDenseStorage<ElementType> denseStorage = obj as ILDenseStorage<ElementType>;
1334            if (object.Equals(denseStorage,null))
1335                return false;
1336            return Equals(denseStorage);
1337        }
1338        /// <summary>
1339        /// Test if this dense storage equals another dense storage.
1340        /// </summary>
1341        /// <param name="A">storage to compare this storage with</param>
1342        /// <returns>True if all elements and dimension sizes match, false otherwise.</returns>
1343        internal bool Equals(ILDenseStorage<ElementType> A) {
1344            if (A == null) return false;
1345            if (!A.Size.IsSameSize(m_size))
1346                return false;
1347            int len = m_size.NumberOfElements;
1348            if (typeof(ElementType).IsValueType) {
1349                for (int i = 0; i < len;i++) {
1350                    if (!GetValueTyped(i).Equals(A.GetValueTyped(i)))
1351                        return false;
1352                }
1353            } else {
1354                // references may contain null element values!
1355                for (int i = 0; i < len;i++) {
1356                    ElementType t1 = GetValueTyped(i);
1357                    if (t1 == null) {
1358                        if (!A.GetValueTyped(i).Equals(null))
1359                            return false;
1360                    } else {
1361                        if (!t1.Equals(A.GetValueTyped(i)))
1362                            return false;
1363                    }
1364                }
1365            }
1366            return true;
1367        }
1368        /// <summary>
1369        /// generate a hash code based on the current arrays values
1370        /// </summary>
1371        /// <returns>hash code</returns>
1372        /// <remarks>The hashcode is generated by taking the values currently stored in the array into account.
1373        /// Therefore, the function must iterate over all elements in the array - which makes it somehow a expensive
1374        /// operation. Take this into account, if you consider using large arrays in collections like dictionaries
1375        /// or hashtables, which make great use of hash codes.</remarks>
1376        public override int GetHashCode() {
1377            if (IsDisposed) return base.GetHashCode();
1378            int ret = Size.GetHashCode();
1379            ElementType[] data = GetArrayForRead();
1380            ret = (ret * 17) + data.Length;
1381            foreach (ElementType t in data) {
1382                ret = unchecked( ret * 17 );
1383                if (t != null)
1384                    ret = unchecked(ret + t.GetHashCode());
1385            }
1386            return (int)ret;
1387        }
1388        #endregion
1389
1390        #region subarray + range get / set
1391        /// <summary>
1392        /// Alter values specified by range.
1393        /// </summary>
1394        /// <param name="range">ILRange specifying the dimensions/indices to be altered.</param>
1395        /// <param name="values">new values</param>
1396        /// <remarks>
1397        /// The values pointed to by range will be replaced with the values
1398        /// found in 'values'. Important: the range cannot specify indices outside of my dimensions!
1399        /// Therefore, the storage must have been expanded in advance, if needed!</remarks>
1400        public virtual void SetRange(ILRange range, ILDenseStorage<ElementType> values) {
1401            if (range.Size.NumberOfElements == 0) return;
1402            int rangeDimLen = range.RangeArray.Length,higherDimSum = 0;
1403            int leadDimLenRange = range[0].Count, leadDimLen = m_size[0];
1404            int d, outElemCount = range.Size.NumberOfElements;
1405            ElementType[] myArr = GetArrayForWrite();
1406            int[] idxArr = new int[rangeDimLen];    // used to store current position inside higher dims
1407            ILIntList[] rng = range.RangeArray;
1408            int[] seqDistances = m_size.GetSequentialIndexDistances(range.Size.NumberOfDimensions);
1409            int[] inFullDim = new int[rangeDimLen];
1410            // initialize higher dimension summand and inFullDim[] flag array
1411            for (int i = 1; i < idxArr.Length; i++) {
1412                if (rng[i][0] < 0) {
1413                    inFullDim[i] = rng[i][0];
1414                } else {
1415                    inFullDim[i] = 0;
1416                    higherDimSum += seqDistances[i] * rng[i][0];
1417                }
1418            }
1419            //for (int lIdx = 0; lIdx < leadDimLenRange; lIdx ++) {
1420            //    retArr[curPosOut++] = myArr[higherDimSum + rleadDim[lIdx]];
1421            //}
1422            if (values.Size.NumberOfElements == 1) {
1423#region scalar case
1424                ElementType scalar = values.GetValueTyped(0);
1425                while (true) {
1426                    // copy along leading dimension
1427                    for (int i = 0; i < rng[0].Count; i++) {
1428                        if (rng[0][i] < 0) {
1429                            for (int c = -rng[0][i]; c-- >= 0; ) {
1430                                // we need a upward counter variable anyway, initialized with
1431                                // higherDimSum. So we simply take that and reset it after the loop:
1432                                myArr[ higherDimSum++ ] = scalar; 
1433                            }
1434                            higherDimSum += (rng[0][i]-1); // negative value in rng! 
1435                        } else {
1436                             myArr[ higherDimSum + rng[0][i] ] = scalar;
1437                        }
1438
1439                    }
1440               
1441                    // increase higher dims
1442                    d = 1;
1443                    while  (d < idxArr.Length) {
1444                        if (inFullDim[d] < 0)  {
1445                            higherDimSum += seqDistances[d]; 
1446                            inFullDim[d]++;
1447                            break;
1448                        }
1449
1450                        if (rng[d][idxArr[d]] >= 0) {
1451                            higherDimSum -= (rng[d][idxArr[d]] * seqDistances[d]);
1452                        } else {
1453                            higherDimSum += (rng[d][idxArr[d]] * seqDistances[d]);
1454                        }
1455                        idxArr[d]++;
1456                        if (idxArr[d] == rng[d].Count) {
1457                            idxArr[d] = 0;
1458                            if (rng[d][0] < 0) {
1459                                inFullDim[d] = rng[d][idxArr[d]];
1460                            } else {
1461                                higherDimSum += (rng[d][0] * seqDistances[d]);
1462                            }
1463                            d++;
1464                        } else if (rng[d][idxArr[d]] < 0) {
1465                            inFullDim[d] = rng[d][idxArr[d]];
1466                            break;
1467                        } else {
1468                            higherDimSum += seqDistances[d] * rng[d][idxArr[d]];
1469                            break;
1470                        }
1471
1472                    }
1473                    if (d >= idxArr.Length)
1474                        break;
1475                }
1476#endregion
1477            } else {
1478#region non scalar case
1479                ElementType [] valuesArr = values.GetArrayForRead();
1480                int valuesPos = 0;
1481                while (true) {
1482                    // copy along leading dimension
1483                    for (int i = 0; i < rng[0].Count; i++) {
1484                        if (rng[0][i] < 0) {
1485                            for (int c = -rng[0][i]; c-- >= 0; ) {
1486                                myArr[ higherDimSum++ ] = valuesArr[ valuesPos++ ]; 
1487                            }
1488                            higherDimSum += (rng[0][i]-1); // negative value in rng! 
1489                        } else {
1490                            myArr[ higherDimSum + rng[0][i] ] = valuesArr[ valuesPos++ ];
1491                        }
1492                    }
1493               
1494                    // increase higher dims
1495                    d = 1;
1496                    while  (d < idxArr.Length) {
1497                        if (inFullDim[d] < 0)  {
1498                            higherDimSum += seqDistances[d]; 
1499                            inFullDim[d]++;
1500                            break;
1501                        }
1502
1503                        if (rng[d][idxArr[d]] >= 0) {
1504                            higherDimSum -= (rng[d][idxArr[d]] * seqDistances[d]);
1505                        } else {
1506                            higherDimSum += (rng[d][idxArr[d]] * seqDistances[d]);
1507                        }
1508                        idxArr[d]++;
1509                        if (idxArr[d] == rng[d].Count) {
1510                            idxArr[d] = 0;
1511                            if (rng[d][idxArr[d]] < 0) {
1512                                inFullDim[d] = rng[d][idxArr[d]];
1513                            } else {
1514                                higherDimSum += (rng[d][0] * seqDistances[d]);
1515                            }
1516                            d++;
1517                        } else if (rng[d][idxArr[d]] < 0) {
1518                            inFullDim[d] = rng[d][idxArr[d]];
1519                            break;
1520                        } else {
1521                            higherDimSum += seqDistances[d] * rng[d][idxArr[d]];
1522                            break;
1523                        }
1524
1525                    }
1526                    if (d >= idxArr.Length)
1527                        break;
1528                }
1529#endregion
1530            }
1531        }
1532
1533        internal virtual void SetRangeFull(ILDenseStorage<ElementType> values) {
1534            if (values.Size.NumberOfElements != 1 && values.Size.NumberOfElements != Size.NumberOfElements)
1535                throw new ILArgumentException("source and destination array must have the same number of arguments");
1536            ElementType[] myArr = GetArrayForWrite();
1537            if (values.Size.NumberOfElements == 1) {
1538                ElementType scal = values.GetValueTyped(0);
1539                for (int i = 0; i < myArr.Length; i++) {
1540                    myArr[i] = scal;
1541                }
1542            } else {
1543                ElementType[] valArr = values.GetArrayForRead();
1544                System.Array.Copy(valArr,myArr,Size.NumberOfElements);
1545            }
1546        }
1547       
1548
1549       
1550        /// <summary>
1551        /// Alter elements of this storage adressed by sequential indices
1552        /// </summary>
1553        /// <param name="indices">array specifying the elements to be altered, sequential indexing</param>
1554        /// <param name="values">ILBaseArray of the same type than this array, holding the new values.
1555        /// The number of elements of storage must match the
1556        /// number of elements of indices. The only exception to this rule is if 'values' is a scalar array. The
1557        /// single value of 'values' is than used to set all elements addressed by 'indices'.</param>
1558        /// <remarks><para>For empty arrays, scalar or vectors, indices outside the current bounds for
1559        /// this array will expand this array to the size neccessary.
1560        /// For other arrays the sequential indices given must fit inside this arrays dimensions. </para></remarks>
1561        public virtual void SetRange(ILBaseArray<double> indices, ILDenseStorage<ElementType> values) {
1562            //if (object.Equals(indices,null))
1563            //    throw new ILArgumentException("indices given must not be null");
1564            if (object.Equals(values, null))
1565                throw new ILArgumentException("values given must not be null. Use A[ind] = null; if removal was intended.");
1566            using (ILScope.Enter(indices)) {
1567                #region set full shortcut
1568                if (indices is ILFullRange || object.Equals(indices, null)) {
1569                    int pos;
1570                    ElementType[] myArray = GetArrayForWrite();
1571                    if (values.Size.NumberOfElements == 1) {
1572                        pos = Size.NumberOfElements;
1573                        ElementType val = values.GetValueTyped(0);
1574                        while (pos-- > 0)
1575                            myArray[pos] = val;
1576                    } else {
1577                        if (values.Size.NumberOfElements != Size.NumberOfElements)
1578                            throw new ILArgumentException("number of elements in source must match number of elements in destination array");
1579                        pos = 0;
1580                        foreach (ElementType val in values) {
1581                            myArray[pos++] = val;
1582                        }
1583                    }
1584                } else if (indices.Size.NumberOfElements != values.Size.NumberOfElements
1585                    && values.Size.NumberOfElements != 1)
1586                    throw new ILArgumentException("number of elements in source must match number of elements in destination array");
1587                #endregion
1588                if (indices.IsEmpty)
1589                    return;
1590                if (indices.Storage is ILDenseStorage< double>) {
1591                   
1592                    double maxIndex, minIndex;
1593                    ILDenseStorage< double> indStorage = indices.Storage as ILDenseStorage< double>;
1594                    indStorage.GetLimits(out minIndex, out maxIndex);
1595                    if (minIndex < 0)
1596                        throw new ILArgumentException("sequential indices can not be negative");
1597                    if ((int)maxIndex >= m_size.NumberOfElements) {
1598                        // handle resize
1599                        if (m_size.NumberOfDimensions == 2) {
1600                            if (m_size.NumberOfElements <= 1) {
1601                                // scalar or empty -> expand along 1
1602                                ExpandArray(new int[] { (int)maxIndex + 1, 1 });
1603                            } else if (m_size[0] > 1 && m_size[1] == 1) {
1604                                ExpandArray(new int[] { (int)maxIndex + 1, 1 });
1605                            } else if (m_size[0] == 1 && m_size[1] > 1) {
1606                                ExpandArray(new int[] { 1, (int)maxIndex + 1 });
1607                            } else
1608                                throw new ILArgumentException("resizing array via sequential index access is supported for empty, scalar or vector only");
1609                        } else
1610                            throw new ILArgumentException("resizing array via sequential index access is supported for empty, scalar or vector only");
1611                    }
1612                    ElementType[] myArray = GetArrayForWrite();
1613                   
1614                    double[] indArray = indStorage.GetArrayForRead();
1615
1616                    int len = indices.Size.NumberOfElements;
1617                    if (values.Size.NumberOfElements == 1) {
1618                        ElementType scalarElement = values.GetValueTyped(0);
1619                        for (int i = 0; i < len; ) {
1620                            myArray[(int)indArray[i++]] = scalarElement;
1621                        }
1622                    } else {
1623                        ElementType[] valArray = values.GetArrayForRead();
1624                        for (int i = 0; i < len; ) {
1625                            myArray[(int)indArray[i]] = valArray[i++];
1626                        }
1627                    }
1628                } else {
1629                    throw new ILArgumentException("storage type of given indices is not supported");
1630                }
1631            }
1632        } 
1633
1634#region HYCALPER AUTO GENERATED CODE
1635
1636       
1637        /// <summary>
1638        /// Alter elements of this storage adressed by sequential indices
1639        /// </summary>
1640        /// <param name="indices">array specifying the elements to be altered, sequential indexing</param>
1641        /// <param name="values">ILBaseArray of the same type than this array, holding the new values.
1642        /// The number of elements of storage must match the
1643        /// number of elements of indices. The only exception to this rule is if 'values' is a scalar array. The
1644        /// single value of 'values' is than used to set all elements addressed by 'indices'.</param>
1645        /// <remarks><para>For empty arrays, scalar or vectors, indices outside the current bounds for
1646        /// this array will expand this array to the size neccessary.
1647        /// For other arrays the sequential indices given must fit inside this arrays dimensions. </para></remarks>
1648        public virtual void SetRange(ILBaseArray<Int64> indices, ILDenseStorage<ElementType> values) {
1649            //if (object.Equals(indices,null))
1650            //    throw new ILArgumentException("indices given must not be null");
1651            if (object.Equals(values, null))
1652                throw new ILArgumentException("values given must not be null. Use A[ind] = null; if removal was intended.");
1653            using (ILScope.Enter(indices)) {
1654                #region set full shortcut
1655                if (indices is ILFullRange || object.Equals(indices, null)) {
1656                    int pos;
1657                    ElementType[] myArray = GetArrayForWrite();
1658                    if (values.Size.NumberOfElements == 1) {
1659                        pos = Size.NumberOfElements;
1660                        ElementType val = values.GetValueTyped(0);
1661                        while (pos-- > 0)
1662                            myArray[pos] = val;
1663                    } else {
1664                        if (values.Size.NumberOfElements != Size.NumberOfElements)
1665                            throw new ILArgumentException("number of elements in source must match number of elements in destination array");
1666                        pos = 0;
1667                        foreach (ElementType val in values) {
1668                            myArray[pos++] = val;
1669                        }
1670                    }
1671                } else if (indices.Size.NumberOfElements != values.Size.NumberOfElements
1672                    && values.Size.NumberOfElements != 1)
1673                    throw new ILArgumentException("number of elements in source must match number of elements in destination array");
1674                #endregion
1675                if (indices.IsEmpty)
1676                    return;
1677                if (indices.Storage is ILDenseStorage< Int64>) {
1678                   
1679                    Int64 maxIndex, minIndex;
1680                    ILDenseStorage< Int64> indStorage = indices.Storage as ILDenseStorage< Int64>;
1681                    indStorage.GetLimits(out minIndex, out maxIndex);
1682                    if (minIndex < 0)
1683                        throw new ILArgumentException("sequential indices can not be negative");
1684                    if ((int)maxIndex >= m_size.NumberOfElements) {
1685                        // handle resize
1686                        if (m_size.NumberOfDimensions == 2) {
1687                            if (m_size.NumberOfElements <= 1) {
1688                                // scalar or empty -> expand along 1
1689                                ExpandArray(new int[] { (int)maxIndex + 1, 1 });
1690                            } else if (m_size[0] > 1 && m_size[1] == 1) {
1691                                ExpandArray(new int[] { (int)maxIndex + 1, 1 });
1692                            } else if (m_size[0] == 1 && m_size[1] > 1) {
1693                                ExpandArray(new int[] { 1, (int)maxIndex + 1 });
1694                            } else
1695                                throw new ILArgumentException("resizing array via sequential index access is supported for empty, scalar or vector only");
1696                        } else
1697                            throw new ILArgumentException("resizing array via sequential index access is supported for empty, scalar or vector only");
1698                    }
1699                    ElementType[] myArray = GetArrayForWrite();
1700                   
1701                    Int64[] indArray = indStorage.GetArrayForRead();
1702
1703                    int len = indices.Size.NumberOfElements;
1704                    if (values.Size.NumberOfElements == 1) {
1705                        ElementType scalarElement = values.GetValueTyped(0);
1706                        for (int i = 0; i < len; ) {
1707                            myArray[(int)indArray[i++]] = scalarElement;
1708                        }
1709                    } else {
1710                        ElementType[] valArray = values.GetArrayForRead();
1711                        for (int i = 0; i < len; ) {
1712                            myArray[(int)indArray[i]] = valArray[i++];
1713                        }
1714                    }
1715                } else {
1716                    throw new ILArgumentException("storage type of given indices is not supported");
1717                }
1718            }
1719        } 
1720       
1721        /// <summary>
1722        /// Alter elements of this storage adressed by sequential indices
1723        /// </summary>
1724        /// <param name="indices">array specifying the elements to be altered, sequential indexing</param>
1725        /// <param name="values">ILBaseArray of the same type than this array, holding the new values.
1726        /// The number of elements of storage must match the
1727        /// number of elements of indices. The only exception to this rule is if 'values' is a scalar array. The
1728        /// single value of 'values' is than used to set all elements addressed by 'indices'.</param>
1729        /// <remarks><para>For empty arrays, scalar or vectors, indices outside the current bounds for
1730        /// this array will expand this array to the size neccessary.
1731        /// For other arrays the sequential indices given must fit inside this arrays dimensions. </para></remarks>
1732        public virtual void SetRange(ILBaseArray<Int32> indices, ILDenseStorage<ElementType> values) {
1733            //if (object.Equals(indices,null))
1734            //    throw new ILArgumentException("indices given must not be null");
1735            if (object.Equals(values, null))
1736                throw new ILArgumentException("values given must not be null. Use A[ind] = null; if removal was intended.");
1737            using (ILScope.Enter(indices)) {
1738                #region set full shortcut
1739                if (indices is ILFullRange || object.Equals(indices, null)) {
1740                    int pos;
1741                    ElementType[] myArray = GetArrayForWrite();
1742                    if (values.Size.NumberOfElements == 1) {
1743                        pos = Size.NumberOfElements;
1744                        ElementType val = values.GetValueTyped(0);
1745                        while (pos-- > 0)
1746                            myArray[pos] = val;
1747                    } else {
1748                        if (values.Size.NumberOfElements != Size.NumberOfElements)
1749                            throw new ILArgumentException("number of elements in source must match number of elements in destination array");
1750                        pos = 0;
1751                        foreach (ElementType val in values) {
1752                            myArray[pos++] = val;
1753                        }
1754                    }
1755                } else if (indices.Size.NumberOfElements != values.Size.NumberOfElements
1756                    && values.Size.NumberOfElements != 1)
1757                    throw new ILArgumentException("number of elements in source must match number of elements in destination array");
1758                #endregion
1759                if (indices.IsEmpty)
1760                    return;
1761                if (indices.Storage is ILDenseStorage< Int32>) {
1762                   
1763                    Int32 maxIndex, minIndex;
1764                    ILDenseStorage< Int32> indStorage = indices.Storage as ILDenseStorage< Int32>;
1765                    indStorage.GetLimits(out minIndex, out maxIndex);
1766                    if (minIndex < 0)
1767                        throw new ILArgumentException("sequential indices can not be negative");
1768                    if ((int)maxIndex >= m_size.NumberOfElements) {
1769                        // handle resize
1770                        if (m_size.NumberOfDimensions == 2) {
1771                            if (m_size.NumberOfElements <= 1) {
1772                                // scalar or empty -> expand along 1
1773                                ExpandArray(new int[] { (int)maxIndex + 1, 1 });
1774                            } else if (m_size[0] > 1 && m_size[1] == 1) {
1775                                ExpandArray(new int[] { (int)maxIndex + 1, 1 });
1776                            } else if (m_size[0] == 1 && m_size[1] > 1) {
1777                                ExpandArray(new int[] { 1, (int)maxIndex + 1 });
1778                            } else
1779                                throw new ILArgumentException("resizing array via sequential index access is supported for empty, scalar or vector only");
1780                        } else
1781                            throw new ILArgumentException("resizing array via sequential index access is supported for empty, scalar or vector only");
1782                    }
1783                    ElementType[] myArray = GetArrayForWrite();
1784                   
1785                    Int32[] indArray = indStorage.GetArrayForRead();
1786
1787                    int len = indices.Size.NumberOfElements;
1788                    if (values.Size.NumberOfElements == 1) {
1789                        ElementType scalarElement = values.GetValueTyped(0);
1790                        for (int i = 0; i < len; ) {
1791                            myArray[(int)indArray[i++]] = scalarElement;
1792                        }
1793                    } else {
1794                        ElementType[] valArray = values.GetArrayForRead();
1795                        for (int i = 0; i < len; ) {
1796                            myArray[(int)indArray[i]] = valArray[i++];
1797                        }
1798                    }
1799                } else {
1800                    throw new ILArgumentException("storage type of given indices is not supported");
1801                }
1802            }
1803        } 
1804       
1805        /// <summary>
1806        /// Alter elements of this storage adressed by sequential indices
1807        /// </summary>
1808        /// <param name="indices">array specifying the elements to be altered, sequential indexing</param>
1809        /// <param name="values">ILBaseArray of the same type than this array, holding the new values.
1810        /// The number of elements of storage must match the
1811        /// number of elements of indices. The only exception to this rule is if 'values' is a scalar array. The
1812        /// single value of 'values' is than used to set all elements addressed by 'indices'.</param>
1813        /// <remarks><para>For empty arrays, scalar or vectors, indices outside the current bounds for
1814        /// this array will expand this array to the size neccessary.
1815        /// For other arrays the sequential indices given must fit inside this arrays dimensions. </para></remarks>
1816        public virtual void SetRange(ILBaseArray<Int16> indices, ILDenseStorage<ElementType> values) {
1817            //if (object.Equals(indices,null))
1818            //    throw new ILArgumentException("indices given must not be null");
1819            if (object.Equals(values, null))
1820                throw new ILArgumentException("values given must not be null. Use A[ind] = null; if removal was intended.");
1821            using (ILScope.Enter(indices)) {
1822                #region set full shortcut
1823                if (indices is ILFullRange || object.Equals(indices, null)) {
1824                    int pos;
1825                    ElementType[] myArray = GetArrayForWrite();
1826                    if (values.Size.NumberOfElements == 1) {
1827                        pos = Size.NumberOfElements;
1828                        ElementType val = values.GetValueTyped(0);
1829                        while (pos-- > 0)
1830                            myArray[pos] = val;
1831                    } else {
1832                        if (values.Size.NumberOfElements != Size.NumberOfElements)
1833                            throw new ILArgumentException("number of elements in source must match number of elements in destination array");
1834                        pos = 0;
1835                        foreach (ElementType val in values) {
1836                            myArray[pos++] = val;
1837                        }
1838                    }
1839                } else if (indices.Size.NumberOfElements != values.Size.NumberOfElements
1840                    && values.Size.NumberOfElements != 1)
1841                    throw new ILArgumentException("number of elements in source must match number of elements in destination array");
1842                #endregion
1843                if (indices.IsEmpty)
1844                    return;
1845                if (indices.Storage is ILDenseStorage< Int16>) {
1846                   
1847                    Int16 maxIndex, minIndex;
1848                    ILDenseStorage< Int16> indStorage = indices.Storage as ILDenseStorage< Int16>;
1849                    indStorage.GetLimits(out minIndex, out maxIndex);
1850                    if (minIndex < 0)
1851                        throw new ILArgumentException("sequential indices can not be negative");
1852                    if ((int)maxIndex >= m_size.NumberOfElements) {
1853                        // handle resize
1854                        if (m_size.NumberOfDimensions == 2) {
1855                            if (m_size.NumberOfElements <= 1) {
1856                                // scalar or empty -> expand along 1
1857                                ExpandArray(new int[] { (int)maxIndex + 1, 1 });
1858                            } else if (m_size[0] > 1 && m_size[1] == 1) {
1859                                ExpandArray(new int[] { (int)maxIndex + 1, 1 });
1860                            } else if (m_size[0] == 1 && m_size[1] > 1) {
1861                                ExpandArray(new int[] { 1, (int)maxIndex + 1 });
1862                            } else
1863                                throw new ILArgumentException("resizing array via sequential index access is supported for empty, scalar or vector only");
1864                        } else
1865                            throw new ILArgumentException("resizing array via sequential index access is supported for empty, scalar or vector only");
1866                    }
1867                    ElementType[] myArray = GetArrayForWrite();
1868                   
1869                    Int16[] indArray = indStorage.GetArrayForRead();
1870
1871                    int len = indices.Size.NumberOfElements;
1872                    if (values.Size.NumberOfElements == 1) {
1873                        ElementType scalarElement = values.GetValueTyped(0);
1874                        for (int i = 0; i < len; ) {
1875                            myArray[(int)indArray[i++]] = scalarElement;
1876                        }
1877                    } else {
1878                        ElementType[] valArray = values.GetArrayForRead();
1879                        for (int i = 0; i < len; ) {
1880                            myArray[(int)indArray[i]] = valArray[i++];
1881                        }
1882                    }
1883                } else {
1884                    throw new ILArgumentException("storage type of given indices is not supported");
1885                }
1886            }
1887        } 
1888       
1889        /// <summary>
1890        /// Alter elements of this storage adressed by sequential indices
1891        /// </summary>
1892        /// <param name="indices">array specifying the elements to be altered, sequential indexing</param>
1893        /// <param name="values">ILBaseArray of the same type than this array, holding the new values.
1894        /// The number of elements of storage must match the
1895        /// number of elements of indices. The only exception to this rule is if 'values' is a scalar array. The
1896        /// single value of 'values' is than used to set all elements addressed by 'indices'.</param>
1897        /// <remarks><para>For empty arrays, scalar or vectors, indices outside the current bounds for
1898        /// this array will expand this array to the size neccessary.
1899        /// For other arrays the sequential indices given must fit inside this arrays dimensions. </para></remarks>
1900        public virtual void SetRange(ILBaseArray<float> indices, ILDenseStorage<ElementType> values) {
1901            //if (object.Equals(indices,null))
1902            //    throw new ILArgumentException("indices given must not be null");
1903            if (object.Equals(values, null))
1904                throw new ILArgumentException("values given must not be null. Use A[ind] = null; if removal was intended.");
1905            using (ILScope.Enter(indices)) {
1906                #region set full shortcut
1907                if (indices is ILFullRange || object.Equals(indices, null)) {
1908                    int pos;
1909                    ElementType[] myArray = GetArrayForWrite();
1910                    if (values.Size.NumberOfElements == 1) {
1911                        pos = Size.NumberOfElements;
1912                        ElementType val = values.GetValueTyped(0);
1913                        while (pos-- > 0)
1914                            myArray[pos] = val;
1915                    } else {
1916                        if (values.Size.NumberOfElements != Size.NumberOfElements)
1917                            throw new ILArgumentException("number of elements in source must match number of elements in destination array");
1918                        pos = 0;
1919                        foreach (ElementType val in values) {
1920                            myArray[pos++] = val;
1921                        }
1922                    }
1923                } else if (indices.Size.NumberOfElements != values.Size.NumberOfElements
1924                    && values.Size.NumberOfElements != 1)
1925                    throw new ILArgumentException("number of elements in source must match number of elements in destination array");
1926                #endregion
1927                if (indices.IsEmpty)
1928                    return;
1929                if (indices.Storage is ILDenseStorage< float>) {
1930                   
1931                    float maxIndex, minIndex;
1932                    ILDenseStorage< float> indStorage = indices.Storage as ILDenseStorage< float>;
1933                    indStorage.GetLimits(out minIndex, out maxIndex);
1934                    if (minIndex < 0)
1935                        throw new ILArgumentException("sequential indices can not be negative");
1936                    if ((int)maxIndex >= m_size.NumberOfElements) {
1937                        // handle resize
1938                        if (m_size.NumberOfDimensions == 2) {
1939                            if (m_size.NumberOfElements <= 1) {
1940                                // scalar or empty -> expand along 1
1941                                ExpandArray(new int[] { (int)maxIndex + 1, 1 });
1942                            } else if (m_size[0] > 1 && m_size[1] == 1) {
1943                                ExpandArray(new int[] { (int)maxIndex + 1, 1 });
1944                            } else if (m_size[0] == 1 && m_size[1] > 1) {
1945                                ExpandArray(new int[] { 1, (int)maxIndex + 1 });
1946                            } else
1947                                throw new ILArgumentException("resizing array via sequential index access is supported for empty, scalar or vector only");
1948                        } else
1949                            throw new ILArgumentException("resizing array via sequential index access is supported for empty, scalar or vector only");
1950                    }
1951                    ElementType[] myArray = GetArrayForWrite();
1952                   
1953                    float[] indArray = indStorage.GetArrayForRead();
1954
1955                    int len = indices.Size.NumberOfElements;
1956                    if (values.Size.NumberOfElements == 1) {
1957                        ElementType scalarElement = values.GetValueTyped(0);
1958                        for (int i = 0; i < len; ) {
1959                            myArray[(int)indArray[i++]] = scalarElement;
1960                        }
1961                    } else {
1962                        ElementType[] valArray = values.GetArrayForRead();
1963                        for (int i = 0; i < len; ) {
1964                            myArray[(int)indArray[i]] = valArray[i++];
1965                        }
1966                    }
1967                } else {
1968                    throw new ILArgumentException("storage type of given indices is not supported");
1969                }
1970            }
1971        } 
1972
1973#endregion HYCALPER AUTO GENERATED CODE
1974
1975        /// <summary>
1976        /// Create referencing or solid array from this array, with shifted dimensions.
1977        /// </summary>
1978        /// <param name="shift">Number of dimensions to shift the array.</param>
1979        /// <returns>Shifted ILDenseStorage of the same type.</returns>
1980        /// <remarks><para>Shift is done 'to the left'.</para></remarks>
1981    public virtual ILDenseStorage<ElementType> ShiftDimensions (int shift) {
1982            return CreateShiftedStorage(shift);
1983        }
1984
1985        #endregion
1986
1987        #region Reshape, Concat, Repmat  - overriding ILBaseArray<ElementType>
1988
1989        /// <summary>
1990        /// reshape <b>this</b> storage
1991        /// </summary>
1992        /// <param name="newDimensions">new dimensions of the storage.</param>
1993        /// <remarks><para>This storage will be changed! The operation is cheap, since the
1994        /// number of elements (and their values) do not change. The same countable array
1995        /// is used in conjunction with a new dimension specifier. </para>
1996        /// </remarks>
1997        /// <exception cref="ILNumerics.Exceptions.ILArgumentException">If the number of elements in 'newDimension'
1998        /// do not match the number of elements in this storage.</exception>
1999        internal void Reshape(ILSize newDimensions) {
2000            if (newDimensions.NumberOfElements != m_size.NumberOfElements)
2001                throw new ILArgumentSizeException ("the number of elements must not change");
2002            m_size = newDimensions;
2003        }
2004        /// <summary>
2005        /// reshape <b>this</b> storage
2006        /// </summary>
2007        /// <param name="dims">new dimension length of the storage.</param>
2008        /// <remarks><para>This storage will be changed! The operation is cheap, since the
2009        /// number of elements (and their values) do not change. The same underlying storage
2010        /// is used in conjunction with the new dimension specifier.</para>
2011        /// </remarks>
2012        /// <exception cref="ILNumerics.Exceptions.ILArgumentException">If the number of elements in 'newDimension'
2013        /// do not match the number of elements in this storage.</exception>
2014        public void Reshape(params int[] dims) {
2015            ILSize newDimension = new ILSize(dims);
2016            Reshape(newDimension);
2017        }
2018        /// <summary>
2019        /// concatenate this storage
2020        /// </summary>
2021        /// <param name="A">n dimensional storage</param>
2022        /// <param name="dim">Index of dimension along which to concatenate the arrays.
2023        /// If dim is larger than the number of dimensions of one of the arrays
2024        /// its value will be used in modulus.</param>
2025        /// <returns>Array having the size of both input arrays laid beside one
2026        /// another along the <paramref name="dim"/>'s-dimension</returns>
2027        /// <remarks>The array returned will be a copy of both arrays involved. None
2028        /// of the input arrays will be altered.</remarks>
2029        public virtual ILDenseStorage<ElementType> Concat(ILDenseStorage<ElementType> A, int dim) {
2030            ILSize inDim = A.m_size;
2031            for (int i = 0; i < Math.Max(inDim.NumberOfDimensions, m_size.NumberOfDimensions); i++) {
2032                if (i != dim)
2033                    if (m_size[i] != inDim[i])
2034                        throw new ILArgumentSizeException("the length of dimensions of both arrays (except the dimension "
2035                                            + "to be concatenated) must match");
2036            }
2037            // concatenate
2038            if (inDim.NumberOfElements == 1 && m_size.NumberOfElements == 1) {
2039                // both scalars
2040                int[] dims = new int[2] { 1, 1 };
2041                dims[dim] = 2;
2042                ElementType[] retArr = ILMemoryPool.Pool.New<ElementType>(2);
2043                retArr[0] = m_data.Data[0];
2044                retArr[1] = A.m_data.Data[0];
2045                return CreateSelf(retArr, new ILSize(dims));
2046            }
2047            int lenOutArr = m_size.NumberOfElements + inDim.NumberOfElements;
2048            int[] retDims = m_size.ToIntArray(dim+1);
2049            retDims[dim] += inDim[dim];
2050            ILSize retDimension = new ILSize(retDims);
2051            ElementType[] retData = ILMemoryPool.Pool.New<ElementType>(retDimension.NumberOfElements);
2052            ElementType[] myData = GetArrayForRead();
2053            ElementType[] inData = A.GetArrayForRead();
2054
2055            int len1 = m_size.SequentialIndexDistance(dim + 1);
2056            int len2 = inDim.SequentialIndexDistance(dim + 1);
2057            int posOutArr = 0, inPos = 0, myPos = 0;
2058            while (posOutArr < lenOutArr) {
2059                for (int i = 0; i < len1; i++)
2060                    retData[posOutArr++] = myData[myPos++];
2061                for (int i = 0; i < len2; i++)
2062                    retData[posOutArr++] = inData[inPos++];
2063            }
2064            return CreateSelf(retData,retDimension);
2065        }
2066
2067        /// <summary>
2068        /// Replicate this storage to create a larger array.
2069        /// </summary>
2070        /// <param name="sizes">Sizes description. This may be a
2071        /// list or an array of integer values. If the number of elements in <paramref name="sizes"/> is
2072        /// less the number of dimensions in this array, the trailing dimensions will
2073        /// be set to 1 (singleton dimensions). On the other hand, if the number specified
2074        /// is larger then the number of dimensions of this array, the result
2075        /// will have its number of dimensions extended accordingly. </param>
2076        /// <returns>array which is made out of multiple copies of this array along
2077        /// specified dimensions, according to <paramref name="sizes"/>.</returns>
2078        internal virtual ILDenseStorage<ElementType> Repmat(params int[] sizes) {
2079            if (m_size.NumberOfElements == 0)
2080                return CreateSelf(new ILSize(sizes));
2081            ILRightSideRange rsRange = new ILRightSideRange(m_size, sizes);
2082            return CreateSubarrayStorage(rsRange);
2083
2084           
2085            // experimental: via subindexing full dimensions
2086            //ILBaseArray[] dimArrays = new ILBaseArray[dims.Length];
2087            //for (int i = 0; i < dimArrays.Length; i++) {
2088            //    dimArrays[i] = ILMath.cell(ILMath.full)[ILMath.zeros(1,dims[i])];
2089            //}
2090            //return Subarray(dimArrays);
2091           
2092            //build return dimensions
2093            //int[] newDim = new int[Math.Max(dims.Length, m_dimensions.NumberOfDimensions)];
2094            //for (int d = 0; d < newDim.Length; d++) {
2095            //    if (d < dims.Length) {
2096            //        newDim[d] = m_dimensions[d] * dims[d];
2097            //    } else {
2098            //        newDim[d] = m_dimensions[d];
2099            //    }
2100            //}
2101            //ILSize outDim = new ILSize(true, newDim);
2102            //if (m_dimensions.NumberOfElements == 0 || outDim.NumberOfElements == 0)
2103            //    return new ILDenseStorage<ElementType>(new ILCountableArray<ElementType>(0), outDim);
2104            //ILDenseStorage<ElementType> ret = new ILDenseStorage<ElementType>(
2105            //                    new ILCountableArray<ElementType>(outDim.NumberOfElements), outDim);
2106            //ElementType[] retArray = ret.GetArrayForWrite();
2107            //ElementType[] myArray = GetArrayForRead();
2108            //int[] outStrides = outDim.GetSequentialIndexDistances(m_dimensions.NumberOfDimensions);
2109            //int[] myStrides = m_dimensions.GetSequentialIndexDistances(m_dimensions.NumberOfDimensions);
2110            //retArray[0] = myArray[0];
2111            //if (outDim.NumberOfElements < ILNumerics.Settings.s_minParallelElement1Count) {
2112            //    for (int outPos = 1; outPos < outDim.NumberOfElements; ) {
2113            //        int inPos = 0;
2114            //        for (int d = m_dimensions.NumberOfDimensions; d-- > 0; ) {
2115            //            inPos += ((outPos / outStrides[d]) % m_dimensions[d])
2116            //                     * myStrides[d];
2117            //        }
2118            //        retArray[outPos++] = myArray[inPos];
2119            //    }
2120            //} else {
2121            //    System.Threading.Tasks.Parallel.For(1,outDim.NumberOfElements, i => {
2122            //        int inPos = 0;
2123            //        for (int d = m_dimensions.NumberOfDimensions; d-- > 0; ) {
2124            //            inPos += ((i / outStrides[d]) % m_dimensions[d])
2125            //                     * myStrides[d];
2126            //        }
2127            //        retArray[i] = myArray[inPos];
2128            //    });
2129            //}
2130            //return ret;
2131        }
2132
2133        /// <summary>
2134        /// Remove individual parts of a dimension from <b>this</b> storage
2135        /// </summary>
2136        /// <param name="dimension">index of the dimension, where <c>indices</c> are to be removed</param>
2137        /// <param name="indices">indices to be removed from <paramref name="dimension"/>, -1 for "wipe" (make this an empty storage)</param>
2138        /// <remarks>The function directly operates on <b>this</b> storage! After the function returns,
2139        /// this storage may have its dimensions changed!</remarks>
2140        internal virtual void Remove(int dimension, ILIntList indices) {
2141            using (ILScope.Enter()) {
2142                if (dimension >= Size.NumberOfDimensions)
2143                    throw new ILArgumentException("index out of range");
2144                if (dimension == -1) {
2145                    Data = new ILCountableArray<ElementType>(0);
2146                    m_size = ILSize.Empty00;
2147                    return;
2148                }
2149                // TODO: may should be replaced with a faster (&fancier? ) version... ??
2150                ILBaseArray[] dims = new ILBaseArray[Size.NumberOfDimensions];
2151                ILIntList keepInd = ILIntList.Create();
2152                ILIntList remvInd = indices;
2153                int max = Size[dimension];
2154                foreach (int i in indices)
2155                    if (i >= max || i < 0) throw new ILArgumentException("removal index out of range");
2156                for (int i = 0; i < max; i++) {
2157                    if (!remvInd.Contains(i)) {
2158                        keepInd.Add(i);
2159                    }
2160                }
2161                // we give the indices to _keep_ to the subarray function
2162                int keepIndCount = keepInd.Count;
2163                ILArray<int> remIndices = ILMath.array<int>(keepInd.GetArray(), new ILSize(1, keepIndCount));
2164                if (remIndices.Size.NumberOfElements == Size[dimension]) {
2165                    // nothing to do
2166                    return;
2167                }
2168                for (int i = 0; i < dims.Length; i++) {
2169                    dims[i] = ILMath.full;
2170                }
2171                dims[dimension] = remIndices;
2172                ILDenseStorage<ElementType> ret = Subarray(dims);
2173                Dispose();  // this will for reference element types (e.g. ILCell) also dispose the removed elements
2174               
2175                Data = ret.Data;
2176                m_size = ret.Size;
2177               
2178            }
2179        }
2180
2181        #endregion
2182
2183        #region serialize
2184        /// <summary>
2185        /// Prepare for serialization.
2186        /// </summary>
2187        /// <param name="context">Streaming Context - provided by the formatter.</param>
2188        /// <remarks>nothing to do here</remarks>
2189        [OnSerializing]
2190        private void OnSerialize(StreamingContext context) {
2191        }
2192
2193        /// <summary>
2194        /// Post operations aftre deserializing is finished.
2195        /// </summary>
2196        /// <param name="context">Streaming context provided by the formatter.</param>
2197        /// <remarks>nothing to do here</remarks>
2198        [OnDeserialized]
2199        void OnDeserialized(StreamingContext context) {
2200        }
2201
2202        #endregion
2203
2204        #region single element access
2205
2206        /// <summary>
2207        /// Get single value from this storage.
2208        /// </summary>
2209        /// <param name="idx">Integer array holding the dimension specifier</param>
2210        /// <returns>Element at the position pointed to by idx.</returns>
2211        internal override object GetValue(params int[] idx) {
2212            return GetValueTyped(idx);
2213        }
2214        /// <summary>
2215        /// Get single value from this storage.
2216        /// </summary>
2217        /// <param name="idx">Integer array holding the dimension specifier</param>
2218        /// <returns>Element at the position pointed to by idx.</returns>
2219        internal override ElementType GetValueTyped(params int[] idx) {
2220            if (idx.Length == 1)
2221                return m_data.Data[idx[0]];
2222            int destIdx = idx[0], d, highDims;
2223            if (destIdx >= m_size[0] || destIdx < 0)
2224                    throw new ILArgumentException("GetValue: index out of bound for dimensions: 0");
2225            int [] seqDist = m_size.GetSequentialIndexDistances(0);
2226            if (idx.Length <= m_size.NumberOfDimensions) {
2227                for (d = 1; d < idx.Length - 1; d++) {
2228                    if (idx[d] >= m_size[d] || idx[d] < 0)
2229                        throw new ILArgumentException("GetValue: index out of bound for dimensions: " + d.ToString());
2230                    destIdx += idx[d] * seqDist[d];
2231                }
2232                for (highDims = idx[d]; d<m_size.NumberOfDimensions && highDims > 0; d++) {
2233                    destIdx += (highDims % m_size[d]) * seqDist[d];
2234                    highDims /= m_size[d];
2235                }
2236                if (highDims > 0) throw new ILArgumentException ("GetValue: index out of bound!");
2237                return m_data.Data[destIdx];
2238            } else {
2239                highDims = m_size.NumberOfDimensions;
2240                for (d = 1; d < highDims; d++) {
2241                    if (idx[d] >= m_size[d] || idx[d] < 0)
2242                        throw new ILArgumentException("GetValue: index out of bound for dimensions: " + d.ToString());
2243                    destIdx += idx[d] * seqDist[d];
2244                }
2245                for (; d<idx.Length; d++) {
2246                    if (idx[d] != 0)
2247                        throw new ILArgumentException("GetValue: index out of bound for dimension: " + d.ToString() + ". Trailing indices must be 0!");
2248                }
2249                return m_data.Data[destIdx];
2250            }
2251        }
2252        internal override ILStorage GetValueAsStorage(params int[] innerIndices) {
2253            return new ILDenseStorage<ElementType>(new ElementType[1] { GetValueTyped(innerIndices) }, ILSize.Scalar1_1); 
2254        }
2255        internal override ILBaseArray GetAsBaseArray() {
2256            return new ILRetArray<ElementType>((ILDenseStorage<ElementType>)Clone());
2257        }
2258
2259        /// <summary>
2260        /// Get single value from this storage by a single sequential access.
2261        /// </summary>
2262        /// <param name="idx">Integer array holding the dimension specifier
2263        /// pointing to the value.</param>
2264        /// <param name="dims">Out value: return position mapped to dimensions.</param>
2265        /// <returns>Object in the position pointed to by idx.</returns>
2266        /// <remarks>dims is the final position into the array for the sequential index specification <c>idx</c>.</remarks>
2267        internal override object GetValueSeq(int idx, ref int[] dims) {
2268            int IdxCpy = idx;
2269            for (int d = 0; d<m_size.NumberOfDimensions; d++) {
2270                dims[d] = (IdxCpy % m_size[d]);
2271                IdxCpy /= m_size[d];  // must go to end, to fully clear dims
2272            }
2273            return m_data.Data[idx];
2274        }
2275        /// <summary>
2276        /// Set single value to element at the specified index.
2277        /// </summary>
2278        /// <param name="value">New value.</param>
2279        /// <param name="idx">Index of the element to be altered.</param>
2280        internal override void SetValue(object value, params int[] idx) {
2281            try {
2282                SetValueTyped((ElementType)value, idx);
2283            } catch (InvalidCastException) {
2284                SetValueTyped((ElementType)Convert.ChangeType(value, typeof(ElementType)), idx);
2285            }
2286        }
2287        /// <summary>
2288        /// Set value of element at the specified position.
2289        /// </summary>
2290        /// <param name="value">new value</param>
2291        /// <param name="idx">position of the element to be altered</param>
2292        /// <remarks><para>This function does support automatic expansion of the array
2293        /// if indices lay outside the dimension limits of the array. However, because
2294        /// of ambiguity reasons this is not reliable supported for vector sized arrays.</para></remarks>
2295        internal override void SetValueTyped(ElementType value, params int[] idx) {
2296            try {
2297                if (idx.Length < 2) {
2298                    if (idx.Length == 1) {
2299                        if (idx[0] >= m_size.NumberOfElements)
2300                            throw new IndexOutOfRangeException();
2301                        GetArrayForWrite()[idx[0]] = value;
2302                    }
2303                    return;
2304                }
2305                int i = m_size.IndexFromArray(idx);
2306                if (i >= m_size.NumberOfElements)
2307                    throw new IndexOutOfRangeException();
2308                GetArrayForWrite()[i] = (ElementType)value;
2309            } catch (Exception exc) {
2310                if (exc is ILArgumentException
2311                    || exc is IndexOutOfRangeException ) {
2312                    // expanding ?
2313                    int [] dimensions = m_size.ToIntArray(Math.Max(idx.Length,m_size.NumberOfDimensions)); 
2314                    bool mustExpand = false;
2315                    int i = m_size.IndexFromArray(ref mustExpand, ref dimensions, idx); 
2316                    if (mustExpand) {
2317                        ExpandArray(dimensions);
2318                        m_data.Data[i] = value;
2319                    } else {
2320                        throw;
2321                    }
2322                }
2323            }
2324        }
2325
2326        /// <summary>
2327        /// [depricated] Convert index array into sequential index for storage access.
2328        /// </summary>
2329        /// <param name="idx">int array with dimension specification.</param>
2330        /// <returns>Index of requested value inside the solid storage. This
2331        /// value can directly be used to query the corresponding value via GetArrayForRead()[return_value].
2332        /// </returns>
2333        /// <remarks><b>This function is deprecated! Use <see cref="ILNumerics.ILSize.IndexFromArray(int[])"/> instead!</b><br/>
2334        /// If the length of idx is smaler than the number of dimensions
2335        /// of this storage, the trailing dimensions will be replaced with "0". I.e
2336        /// the first index of each non specified dimension will be used.
2337        /// If length of idx is larger than the dimensions of this storage, the behavior
2338        /// is undefined. Therefore this function should be enclosed in try, catch blocks
2339        /// to handle this case!</remarks>
2340        internal int getBaseIndex(params int[] idx) {
2341            // arghs! -> ugly! piuh!!
2342            if (idx == null) throw new ILArgumentException("indices specified must not be null");
2343            if (idx.Length < m_size.NumberOfDimensions) {
2344                bool dummy;
2345                int [] tmp = ILMemoryPool.Pool.New<int>(m_size.NumberOfDimensions,true, out dummy);
2346                for (int i = 0; i < idx.Length; i++) {
2347                    tmp[i] = idx[i];
2348                }
2349                return m_size.IndexFromArray(tmp);
2350            }
2351            return m_size.IndexFromArray(idx);
2352        }
2353        /// <summary>
2354        /// [depricated] Convert index array into sequential index for storage access. Ommit any bound checking.
2355        /// </summary>
2356        /// <param name="idx">int array with dimensions specification.</param>
2357        /// <param name="MustExpand">Output parameter. On return determine, if the index
2358        /// specification points outside of the dimensions of this ILDenseStorage and the array
2359        /// must be expanded before accessing elements on that position.</param>
2360        /// <param name="dimensions">if the array was found to be expanded, this are the
2361        /// needed dimension sizes for the new array. The sizes are computed from the range
2362        /// specification given.</param>
2363        /// <returns>Index of requested value inside the solid storage. This
2364        /// value may directly be used to query the value via m_data[return_value].
2365        /// The value returned is valid for solid storages as well as for reference
2366        /// storages.
2367        /// </returns>
2368        /// <remarks>
2369        /// <para>idx must be not null and must contain at least one element.</para>
2370        /// <para>If the length of idx is smaler than the number of dimensions
2371        /// of this storage, the trailing dimensions will be replaced with "0". I.e
2372        /// the first index of each non specified dimensions will be used.
2373        /// If length of idx is larger than the dimensions of this storage, the index of
2374        /// the expanded array will be returned.</para></remarks>
2375        internal int getBaseIndex(ref bool MustExpand, ref int[] dimensions, params int[] idx) {
2376            int destIdx = 0;
2377            if (idx.Length == 1) {
2378                destIdx = idx[0];
2379                if (destIdx < 0)
2380                    throw new ILArgumentException("check index for dimension 0!");
2381                if (destIdx >= m_size.NumberOfElements) {
2382                    MustExpand = true;
2383                    dimensions[0] = destIdx + 1;
2384                }
2385                return destIdx;
2386            }
2387            return m_size.IndexFromArray(ref MustExpand, ref dimensions, idx);
2388        }
2389        /// <summary>
2390        /// Copy values of all elements into System.Array.
2391        /// </summary>
2392        /// <param name="result">System.Array, holding all element values of this ILDenseStorage.</param>
2393        /// <remarks>The System.Array may be predefined. If its length is sufficient, it will be used and
2394        /// its leading elements will be overwritten when function returns. If 'result' is null or has too few elements,
2395        /// it will be recreated from the ILNumerics memory pool.</remarks>
2396        public void ExportValues(ref ElementType[] result) {
2397            if (result == null || result.Length < m_size.NumberOfElements)
2398                result = ILMemoryPool.Pool.New<ElementType>(m_size.NumberOfElements);
2399            int pos = 0;
2400            foreach (ElementType v in this) {
2401                result[pos++] = v;
2402            }
2403        }
2404        /// <summary>
2405        /// Get direct reference to inner System.Array storage for <b>write access</b>
2406        /// </summary>
2407        /// <returns>reference to inner System.Array</returns>
2408        /// <remarks>Altering this array can be done directly. If necessary, the array is detached before
2409        /// returned. Watch the column order format of storages in ILNumerics! Keep in minds, the length
2410        /// of the array may exceeds the number of elements.
2411        /// <para>Accessing the inner system array directly should be left to ILNumerics experts only!
2412        /// Unless you really know, what you are doing, you should rather use the higher order access
2413        /// methods provided by ILArray&lt;T>! (You have been warned!)</para></remarks>
2414        internal ElementType[] GetArrayForWrite() {
2415            if (m_data.ReferenceCount > 1) {
2416                Detach();
2417            }
2418            return m_data.Data;
2419        }
2420        /// <summary>
2421        /// Get direct reference to inner System.Array storage for <b>read access</b>
2422        /// </summary>
2423        /// <returns>reference to inner System.Array for reading</returns>
2424        /// <remarks>This method is provided for experts only! Altering elements of this
2425        /// array may cause the data to be invalidated or corrupted! Use this array only for reading! Note
2426        /// the ILNumerics array storage format (column major). Keep in mind, the length
2427        /// of the array may exceeds the number of elements!
2428        /// <para>Accessing the inner system array directly should be left to ILNumerics experts only!
2429        /// Unless you really know, what you are doing, you should rather use the higher order access
2430        /// methods provided by ILArray&lt;T>! (You have been warned!)</para></remarks>
2431        internal ElementType[] GetArrayForRead() {
2432            //if (PendingTasks > 0)
2433            //    System.Threading.SpinWait.SpinUntil(() => { return PendingTasks == 0; });
2434            return m_data.Data;
2435        }
2436
2437        #endregion
2438
2439        /// <summary>
2440        /// Create lazy,shallow copy of this array
2441        /// </summary>
2442        /// <returns>ILDenseStorage as copy of this storage.</returns>
2443        /// <remarks>The ILDenseStorage object returned will be of the same size and type than this object.
2444        /// <para>The copy is done lazy. This means, the new storage will at first share the memory
2445        /// with that storage. This will take almost no memory / processor time. As soon as attempts
2446        /// are made to <b>alter</b> the new storage, it will be detached from this storage and use own memeory.</para></remarks>
2447        internal override ILStorage Clone() {
2448            return CreateSelf(m_data,m_size);
2449        }
2450        internal ILCountableArray<ElementType> GetDataArray() {
2451            return m_data;
2452        }
2453        internal virtual void IndexSubrange(ILDenseStorage<ElementType> value, ILBaseArray[] range) {
2454            using (ILScope.Enter(range)) {
2455                if (Object.ReferenceEquals(value, null) || value.Size.NumberOfElements == 0) {
2456                    #region remove
2457                    if (range == null) return;
2458
2459                    ILLeftSideRange rng = new ILLeftSideRange(Size, range);
2460                    if (rng.Expanding) {
2461                        throw new ILArgumentException("invalid range for removal specified");
2462                    }
2463                    if (rng.Size.NumberOfElements == 0) {
2464                        return;
2465                    }
2466                    int nonFullDims = 0;
2467                    int dimIdx = -1;
2468                    // check validity
2469                    for (int i = 0; i < rng.RangeArray.Length; i++) {
2470                        if (rng[i].Count != 1 || rng[i][0] >= 0) {
2471                            if (++nonFullDims > 1)
2472                                throw new ILArgumentException("for removal only one dimension can be 'non-full'");
2473                            dimIdx = i;
2474                            foreach (int ind in rng[i]) {
2475                                if (ind < 0) {
2476                                    throw new ILArgumentException("invalid removal indices: all but at most one dimensions must be specified as 'full'. check dimension #" + i.ToString());
2477                                }
2478                            }
2479                        }
2480                    }
2481                    // remove
2482                    ILSize newDim = new ILSize(Size.ToIntArrayEx(rng.RangeArray.Length));
2483                    ILSize oldDimensions = Size;
2484                    try {
2485                        Reshape(newDim); // <- cheap!
2486                        if (dimIdx >= 0) {
2487                            Remove(dimIdx, rng[dimIdx]); // <- expensive!
2488                        } else {
2489                            // all dims full specified
2490                            Remove(dimIdx, null); // <- expensive!
2491                        }
2492                    } catch (Exception) {
2493                        Reshape(oldDimensions);
2494                        throw;
2495                    }
2496                    #endregion
2497                } else {
2498                    #region setrange
2499                    if (range == null || range.Length == 0) {
2500                        return;
2501                    } else if (range.Length == 1) {
2502                        if (range[0] is ILDenseArray<double>) {
2503                            SetRange(range[0] as ILDenseArray<double>, value);
2504                            return;
2505                        } else if (range[0] is ILDenseArray<string>) {
2506                            // special case? A[":;0:3;0:end;..."] -> multiple dimensions given as single string
2507                            string indStr = (string)(range[0] as ILDenseArray<string>).GetValue(0);
2508                            string[] dimParts = indStr.Split(';');
2509                            if (dimParts.Length == 0) {
2510                                // empty range given
2511                                return;
2512                            } else if (dimParts.Length > 1) {
2513                                range = new ILBaseArray[dimParts.Length];
2514                                for (int i = 0; i < dimParts.Length; i++) {
2515                                    range[i] = dimParts[i];
2516                                }
2517                                // re-enter function to push the new arrays into scope
2518                                IndexSubrange(value,range);
2519                                return;
2520                            } else {
2521                                ILBaseArray indices = ILRange.ParseDimension(indStr, Size.NumberOfElements);
2522                                if (indices is ILBaseArray<Misc.ILFullRange>) {
2523                                    SetRangeFull(value);
2524                                } else {
2525                                    SetRange(indices as ILDenseArray<int>, value);
2526                                }
2527                                return;
2528                            }
2529                        } else if (range[0] is ILDenseArray<float>) {
2530                            SetRange(range[0] as ILDenseArray<float>, value);
2531                            return;
2532                        } else if (range[0] is ILDenseArray<Int32>) {
2533                            SetRange(range[0] as ILDenseArray<Int32>, value);
2534                            return;
2535                        } else if (range[0] is ILDenseArray<Int64>) {
2536                            SetRange(range[0] as ILDenseArray<Int64>, value);
2537                            return;
2538                        } else if (range[0] is ILLogical) {
2539                            SetRange(ILNumerics.ILMath.find(range[0] as ILLogical), value);
2540                            return;
2541                        } else if (range[0] is ILRetLogical) {
2542                            SetRange(ILNumerics.ILMath.find(range[0] as ILRetLogical), value);
2543                            return;
2544                        }
2545                    }
2546                    ILLeftSideRange rng = new ILLeftSideRange(Size, range);
2547                    if (rng.Expanding) {
2548                        ExpandArray(rng);
2549                    }
2550                    SetRange(rng, value);
2551                    #endregion
2552                }
2553            }
2554        }
2555
2556        #region IEnumerable<ILBaseArray<ElementType>> Member
2557
2558        /// <summary>
2559        /// enumerator returning elements as ElementType
2560        /// </summary>
2561        public override IEnumerator<ElementType> GetEnumerator ( ) {
2562            int len = m_size.NumberOfElements;
2563            ElementType[] myData = GetArrayForRead();
2564            for (int i = 0; i < len; i++)
2565                yield return myData[i];
2566        }
2567        #endregion
2568
2569        #region private helper
2570        /// <summary>
2571        /// helper function to gather some parameters for partial dimension removal
2572        /// </summary>
2573        /// <param name="rng">object with index specifications. May be of
2574        /// type ILBaseArray[] with numeric arrays or a string array according
2575        /// to the format of <see cref="ILNumerics.Storage.ILRange"/>.
2576        /// </param>
2577        /// <param name="dimensionIdx">Out parameter: index of dimension the indices to be removed lie in.</param>
2578        /// <param name="indices">Indices to be removed.</param>
2579        /// <param name="dimensions">Dimension structure, can be used to reshape the storage <b>before</b> the removal</param>
2580        /// <remarks>If range comprises a range dimension specification which is smaller than
2581        /// the actual number of dimension of this storage, the storage must be reshaped in advance of the removal.
2582        /// This reshaping proccess will <b>not</b> be done inside this function! However
2583        /// the <c>dimension</c> value returned reflects the size of the storage before removing and therefore
2584        /// can be utilized for reshaping the storage.</remarks>
2585        /// <exception cref="ILNumerics.Exceptions.ILArgumentException">If:<list type="bullet">
2586        /// <item>The length of range exceeds the dimensions of this storage.</item>
2587        /// <item>More than one or less than one dimension of <c>range</c> was not null.</item>
2588        /// <item>The type of range was invalid, or</item>
2589        /// <item>Range is of type <see cref="ILNumerics.ILBaseArray"/>, but the element type is not numeric</item>
2590        /// </list></exception>
2591        internal void ExtractRemovalParameter(ILBaseArray[] rng, out int dimensionIdx, ref ILIntList indices, out ILSize dimensions) {
2592            dimensionIdx = 0;
2593            dimensions = null;
2594            if (rng.Length > m_size.NumberOfDimensions)
2595                throw new ILArgumentException("Error removing: dimension specification exceeds matrix dimensions.");
2596            int specCount = 0;
2597            int tmp = 0;
2598            if (rng.Length == 1 && rng[0] is ILBaseArray<string>) {
2599                string allRangeString = (string)(rng[0] as ILBaseArray<string>).GetValue(0);
2600                string[] ranges = allRangeString.Split(';');
2601                if (ranges.Length > 1) {
2602                    rng = new ILBaseArray[ranges.Length];
2603                    for (int i = 0; i < ranges.Length; i++) {
2604                        rng[i] = ranges[i];
2605                    }
2606                }
2607            }
2608            int[] outDim = Size.GetReshapedSize(rng.Length);
2609            for (int i = 0; i < rng.Length; i++) {
2610                if (object.Equals(rng[i], null)) {
2611                    // nothing to remove
2612                    if (indices != null) {
2613                        indices.Clear();
2614                    }
2615                    return;
2616                } else if (!rng[i].IsEmpty) {
2617                    if (rng[i] is ILDenseArray<string>) {
2618                        string stringVal = (rng[i] as ILDenseArray<string>).GetValue(0); 
2619                        ILBaseArray indFromString = ILRange.ParseDimension(stringVal,outDim[i]);
2620                        if (!(indFromString is ILBaseArray<ILFullRange>)) {
2621                            if (specCount++ > 0) {
2622                                throw new ILArgumentException("only one dimension can be non-fully specified for removal");
2623                            }
2624                            dimensionIdx = i;
2625                            indices = new ILIntList(indFromString as ILDenseArray<int>);
2626                        }
2627                        continue;
2628                    }
2629                    dimensionIdx = i;
2630                    if (specCount++ > 0) {
2631                        throw new ILArgumentException("only one dimension can be non-fully specified for removal");
2632                    }
2633                    if (rng[i] is ILBaseArray<Expression>) {
2634                        // A[end + ...] given
2635                        Expression expr = (rng[i] as ILBaseArray<Expression>).GetValue(0);
2636                        int exprVal = ILExpression.Evaluate(expr, Size[i] - 1);
2637                        indices = ILIntList.Create();
2638                        for (int p = 0; p < tmp; p++) {
2639                            indices.Add(exprVal);
2640                        }
2641                    } else if (rng[i] is ILLogical) {
2642                        ILArray<double> ind = ILNumerics.ILMath.find((ILLogical) rng[i]);
2643                        tmp = ind.Size.NumberOfElements;
2644                        indices = ILIntList.Create();
2645                        for (int p = 0; p < tmp; p++) {
2646                            indices.Add((int)ind.GetValue(p));
2647                        }
2648                    } else if (rng[i] is ILRetLogical) {
2649                        ILArray<double> ind = ILNumerics.ILMath.find((ILRetLogical) rng[i]);
2650                        tmp = ind.Size.NumberOfElements;
2651                        indices = ILIntList.Create();
2652                        for (int p = 0; p < tmp; p++) {
2653                            indices.Add((int)ind.GetValue(p));
2654                        }
2655
2656/* !HC:TYPELIST:
2657<hycalper>
2658<type>
2659<source locate="after">
2660    inArr1
2661</source>
2662<destination>float</destination>
2663<destination>Int16</destination>
2664<destination>Int32</destination>
2665<destination>Int64</destination>
2666<destination>byte</destination>
2667</type>
2668</hycalper>
2669*/
2670
2671                    } else if (rng[i] is ILDenseArray<double> ) {
2672                        ILDenseArray<double> ind = rng[i] as ILDenseArray<double> ;
2673                        tmp = ind.Size.NumberOfElements;
2674                        indices = ILIntList.Create();
2675                        for (int p = 0; p < tmp; p++) {
2676                            indices.Add((int)ind.GetValue(p));
2677                        }
2678
2679#region HYCALPER AUTO GENERATED CODE
2680
2681/* !HC:TYPELIST:
2682
2683*/
2684
2685                    } else if (rng[i] is ILDenseArray<byte> ) {
2686                        ILDenseArray<byte> ind = rng[i] as ILDenseArray<byte> ;
2687                        tmp = ind.Size.NumberOfElements;
2688                        indices = ILIntList.Create();
2689                        for (int p = 0; p < tmp; p++) {
2690                            indices.Add((int)ind.GetValue(p));
2691                        }
2692/* !HC:TYPELIST:
2693
2694*/
2695
2696                    } else if (rng[i] is ILDenseArray<Int64> ) {
2697                        ILDenseArray<Int64> ind = rng[i] as ILDenseArray<Int64> ;
2698                        tmp = ind.Size.NumberOfElements;
2699                        indices = ILIntList.Create();
2700                        for (int p = 0; p < tmp; p++) {
2701                            indices.Add((int)ind.GetValue(p));
2702                        }
2703/* !HC:TYPELIST:
2704
2705*/
2706
2707                    } else if (rng[i] is ILDenseArray<Int32> ) {
2708                        ILDenseArray<Int32> ind = rng[i] as ILDenseArray<Int32> ;
2709                        tmp = ind.Size.NumberOfElements;
2710                        indices = ILIntList.Create();
2711                        for (int p = 0; p < tmp; p++) {
2712                            indices.Add((int)ind.GetValue(p));
2713                        }
2714/* !HC:TYPELIST:
2715
2716*/
2717
2718                    } else if (rng[i] is ILDenseArray<Int16> ) {
2719                        ILDenseArray<Int16> ind = rng[i] as ILDenseArray<Int16> ;
2720                        tmp = ind.Size.NumberOfElements;
2721                        indices = ILIntList.Create();
2722                        for (int p = 0; p < tmp; p++) {
2723                            indices.Add((int)ind.GetValue(p));
2724                        }
2725/* !HC:TYPELIST:
2726
2727*/
2728
2729                    } else if (rng[i] is ILDenseArray<float> ) {
2730                        ILDenseArray<float> ind = rng[i] as ILDenseArray<float> ;
2731                        tmp = ind.Size.NumberOfElements;
2732                        indices = ILIntList.Create();
2733                        for (int p = 0; p < tmp; p++) {
2734                            indices.Add((int)ind.GetValue(p));
2735                        }
2736
2737#endregion HYCALPER AUTO GENERATED CODE
2738                   } else
2739                        throw new ILArgumentTypeException("error removing: invalid dimensions specifier, dimension #" + i.ToString());
2740                }
2741            }
2742            if (indices == null) {
2743                dimensionIdx = 0;
2744                dimensions = m_size;
2745                //indices = new int[0] { };
2746                return;
2747            }
2748            // if only one dimension specified -> make row vector
2749            //if (rng.Length < 2) {
2750            //    outDim[1] = outDim[0];
2751            //    outDim[0] = 1;
2752            //    dimensionIdx = 1;
2753            //}
2754            dimensions = new ILSize(outDim);
2755        }
2756
2757        /// <summary>
2758        /// Expanded <b>this</b> storage for index addressing outside of my dimensions
2759        /// </summary>
2760        /// <param name="range">range specification with size for destination array</param>
2761        internal void ExpandArray (ILLeftSideRange range) {
2762            int[] outDims;
2763            int i= 0;
2764            ILSize outDimensions;
2765            if (range.Size.NumberOfDimensions > m_size.NumberOfDimensions) {
2766                outDims = new int[range.Size.NumberOfDimensions];
2767                for (; i < m_size.NumberOfDimensions; i ++) {
2768                    outDims[i] = (range.ExpandDimensions[i] > m_size[i]) ?
2769                        range.ExpandDimensions[i] : m_size[i];
2770                }
2771                for(; i < range.Size.NumberOfDimensions; i++)
2772                    outDims[i] = range.ExpandDimensions[i];
2773            } else {
2774                outDims = new int[m_size.NumberOfDimensions];
2775                for (; i < range.Size.NumberOfDimensions; i ++) {
2776                    outDims[i] = (range.ExpandDimensions[i] > m_size[i]) ?
2777                        range.ExpandDimensions[i] : m_size[i];
2778                }
2779                for(; i < m_size.NumberOfDimensions; i++)
2780                    outDims[i] = m_size[i];
2781            }
2782            outDimensions = new ILSize(outDims);
2783            ElementType [] outData = ILMemoryPool.Pool.New<ElementType>(outDimensions.NumberOfElements);
2784            // transfer old data to new array
2785            int [] tmpIdx = new int[outDims.Length];
2786            for (i = 0; i < m_size.NumberOfElements; i++) {
2787                ElementType tmp = (ElementType)GetValueSeq(i,ref tmpIdx);
2788                outData[outDimensions.IndexFromArray(tmpIdx)] = tmp;
2789            }
2790            // exchange my data
2791            Data = new ILCountableArray<ElementType>(outData, outDimensions.NumberOfElements);
2792            m_size = outDimensions;
2793        }
2794        /// <summary>
2795        /// Expand <b>this</b> storage for index addressing outside of my dimensions
2796        /// </summary>
2797        /// <param name="indices">sizes of dimensions for the new storage</param>
2798        protected void ExpandArray(int[] indices) {
2799            if (indices.Length == 2 && (indices[0] * indices[1] == 0)) {
2800               if (indices[0] > 0)
2801                   indices[1] = 1;
2802               else if (indices[1] > 0)
2803                   indices[0] = 1;
2804            }
2805            ILSize outDimensions = new ILSize(indices);
2806            bool cleared;
2807            ElementType [] outData = ILMemoryPool.Pool.New<ElementType>(outDimensions.NumberOfElements,true,out cleared);
2808            // transfer old data to new array
2809            int [] tmpIdx = new int[indices.Length];
2810            for (int i = 0; i < m_size.NumberOfElements; i++) {
2811                ElementType tmpData = (ElementType)GetValueSeq(i,ref tmpIdx);
2812                outData[outDimensions.IndexFromArray(tmpIdx)] = tmpData;
2813            }
2814            // replace with my data
2815            Data = new ILCountableArray<ElementType>(outData,outDimensions.NumberOfElements);
2816            m_size = outDimensions;
2817        }
2818        /// <summary>
2819        /// Copy upper triangular part of this array into new solid array.
2820        /// </summary>
2821        /// <param name="n">Length of first dimension of destination array.</param>
2822        /// <returns>Solid array of size [n x {ThisColumnCount})].</returns>
2823        internal ILDenseStorage<ElementType> copyUpperTriangle(int n) {
2824            ILDenseStorage<ElementType> ret = new ILDenseStorage<ElementType>(new ILSize(n,n));
2825            ElementType[] arr = ret.GetArrayForWrite();
2826            ElementType[] myData = GetArrayForRead();
2827            if (m_size[0] == n) {
2828                for (int rcount = 0 , pos = 0; rcount < n; rcount++) {
2829                    for (int i = 0; i <= rcount; i++) {
2830                        arr[pos] = myData[pos++];
2831                    }
2832                    pos += (n - rcount - 1);
2833                }
2834            } else {
2835                for (int rcount = 0 , posIn = 0, posOut = 0, lenA = m_size[0]; rcount < n; rcount++) {
2836                    for (int i = 0; i <= rcount; i++) {
2837                        arr[posOut++] = myData[posIn++];
2838                    }
2839                    posOut += (n - rcount - 1);
2840                    posIn += (lenA - rcount - 1);
2841                }
2842            }
2843            return ret;
2844        }
2845        /// <summary>
2846        /// Copy lower triangular part of this array into new solid array.
2847        /// </summary>
2848        /// <returns>Solid array of same size than this array.</returns>
2849        /// <remarks>If this is not a 2D array, only the first dimension is referenced.</remarks>
2850        internal ILDenseStorage<ElementType> copyLowerTriangle() {
2851            int n = m_size[0],pos = 0;
2852            ILDenseStorage<ElementType> ret = new ILDenseStorage<ElementType>(new ILSize(n,n));
2853            ElementType[] arr = ret.GetArrayForRead();
2854            ElementType[] myData = GetArrayForRead();
2855            for (int c = 0; c < m_size[1]; c++) {
2856                pos += c;
2857                for (int r = c; r < n; r++,pos++) {
2858                    arr[pos] = myData[pos];
2859                    pos++;
2860                }
2861            }
2862            return ret;
2863        }
2864
2865        #endregion
2866
2867    }
2868}
Note: See TracBrowser for help on using the repository browser.