Example #1
0
 public static string CodeRepresentation(Array a)
 {
     StringBuilder ret = new StringBuilder();
     ret.Append(a.GetType().FullName);
     ret.Append("(");
     switch (a.Rank) {
         case 1: {
                 for (int i = 0; i < a.Length; i++) {
                     if (i > 0) ret.Append(", ");
                     ret.Append(Ops.StringRepr(a.GetValue(i + a.GetLowerBound(0))));
                 }
             }
             break;
         case 2: {
                 int imax = a.GetLength(0);
                 int jmax = a.GetLength(1);
                 for (int i = 0; i < imax; i++) {
                     ret.Append("\n");
                     for (int j = 0; j < jmax; j++) {
                         if (j > 0) ret.Append(", ");
                         ret.Append(Ops.StringRepr(a.GetValue(i + a.GetLowerBound(0), j + a.GetLowerBound(1))));
                     }
                 }
             }
             break;
         default:
             ret.Append(" Multi-dimensional array ");
             break;
     }
     ret.Append(")");
     return ret.ToString();
 }
Example #2
0
        // Load data
        public void LoadData( Array array )
        {
            //
            this.array = array;

            // set column and row headers
            FixedRows = 1;
            FixedColumns = 1;

            // Redim the grid
            Redim( array.GetLength( 0 ) + FixedRows, array.GetLength( 1 ) + FixedColumns );

            // Col Header Cell Template
            columnHeader = new CellColumnHeaderTemplate( );
            columnHeader.BindToGrid( this );

            // Row Header Cell Template
            rowHeader = new CellRowHeaderTemplate( );
            rowHeader.BindToGrid( this );

            // Header Cell Template (0,0 cell)
            cellHeader = new CellHeaderTemplate( );
            cellHeader.BindToGrid( this );

            // Data Cell Template
            dataCell = new CellArrayTemplate( array ); ;
            dataCell.BindToGrid( this );

            RefreshCellsStyle( );
        }
 public Shape ConvertArrayToShape(Array data)
 {
     width = data.GetLength(1);
     height = data.GetLength(0);
     shape = new Shape();
     double[] prevRow = ReadRow(data, 0);
     for (int y = 1; y < height; y++)
     {
         double[] nextRow = ReadRow(data, y);
         Vertex[] verts = GetRowOfVertices(nextRow, prevRow, y - 1);
         shape.Vertices.AddRange(verts);
         prevRow = nextRow;
     }
     return shape;
 }
Example #4
0
 static void ArrayInfo(String name, Array a)
 {
     Console.Write("{0} has length={1} rank={2} [", name, a.Length, a.Rank);
     for (int i = 0, stop=a.Rank; i<stop; i++)
         Console.Write(" {0}", a.GetLength(i));
     Console.WriteLine(" ]");
 }
Example #5
0
        // This is the GENERIC Type constructor.
        protected CombinatorialBase(Array arrayObjects, int nKlass)
        {
            // Check the validity of the arguments
            DoArgumentCheck(arrayObjects.Length, nKlass);

            m_nKlass = nKlass;

            // Always takes the ZERO (FIRST) dimension of the array. There is no
            // problem in manipulation multidimensional arrays.
            m_nMaxIndex = arrayObjects.GetLength(0) - 1;

            m_arrayIndeces = new int[m_nKlass];
            m_arrayIndecesDummy = new int[m_nKlass];

            m_arrayCurrentObj = new TouchPoint2[m_nKlass];
            //			m_arrayCurrentCombination = Array.CreateInstance(
            //				arrayObjects.GetValue(0).GetType(), m_nKlass);

            // Make a shallow copy of the source array.
            //			m_arrayObj = Array.CreateInstance( arrayObjects.GetValue(0).GetType(), arrayObjects.Length);

            //m_arrayObj = Array.CreateInstance(Type.GetType("System.Object"), arrayObjects.Length);
            //Array.Copy(arrayObjects, m_arrayObj, arrayObjects.Length);

            //TODO: review code
            m_arrayObj = new TouchPoint2[arrayObjects.Length];
            Array.Copy(arrayObjects, m_arrayObj, arrayObjects.Length);
        }
 private static Digit BuildDigitsRepresentingAllIndices(Array subjectAsArray)
 {
     return Enumerable
         .Range(0, subjectAsArray.Rank)
         .Reverse()
         .Aggregate((Digit) null, (next, rank) => new Digit(subjectAsArray.GetLength(rank), next));
 }
Example #7
0
        //-------------------------------------------------------------------//
        /// <summary>
        ///     Converts COM like 2dim array where one dimension is of length 1 to regular array.
        /// </summary>
        /// <param name="a">COM array</param>
        /// <returns>regular array</returns>
        public static object[] Com2DArray2Array(Array a)
        {
            if (a == null)
                return null;

            object[] converted = null;
            switch (a.Rank)
            {
                case 1:
                    converted = new object[a.GetLength(0)];
                    for (var i = a.GetLowerBound(0); i <= a.GetUpperBound(0); i++)
                    {
                        converted[i] = a.GetValue(i);
                    }
                    break;
                case 2:
                {
                    var d1 = a.GetLength(0);
                    var d2 = a.GetLength(1);
                    var len = (d1 > d2) ? d1 : d2;
                    converted = new object[len];
                    var dim = (d1 > d2) ? 0 : 1;
                    for (var i = a.GetLowerBound(dim); i <= a.GetUpperBound(dim); i++)
                    {
                        converted[i - a.GetLowerBound(dim)] = a.GetValue((d1 == 1 ? a.GetLowerBound(0) : i),
                            (d2 == 1 ? a.GetLowerBound(1) : i));
                    }
                }
                    break;
            }

            return converted;
        }
Example #8
0
 static long ArrayLength(Array array, int i)
 {
     long n = 1;
     for ( ; i < array.Rank; i++ )
         n *= array.GetLength(i);
     return n;
 }
 static void AssertArray(Array array, params object[] expectedValues)
 {
     Program.Assert(array.GetLength(0) == expectedValues.Length, "The arrays lengths are differents");
     for (int i = 0; i < expectedValues.Length; i++)
     {
         Program.Assert(array.GetValue(i).Equals(expectedValues[i]), "Unexpected values");
     }
 }
Example #10
0
        // Load data
        public void LoadData( Array array )
        {
            //
            this.array = array;

            behavior = new CellBehavior( array );


            // set column and row headers
            FixedRows = 1;
            FixedColumns = 1;

            // Redim the grid
            Redim( array.GetLength( 0 ) + FixedRows, array.GetLength( 1 ) + FixedColumns );

            // Header
            this[0, 0] = new Header( );

            // Column headers
            for ( int i = 1; i < this.ColumnsCount; i++ )
            {
                ColumnHeader header = new ColumnHeader( i.ToString( ) );
                header.EnableSort = false;
                this[0, i] = header;
            }
            // Row headers
            for ( int i = 1; i < this.RowsCount; i++ )
            {
                this[i, 0] = new RowHeader( i.ToString( ) );
            }

            // Data cells
            Type type = array.GetValue( 0, 0 ).GetType( );
            for ( int i = 1, ia = 0; i < this.RowsCount; i++, ia++ )
            {
                for ( int j = 1, ja = 0; j < this.ColumnsCount; j++, ja++ )
                {
                    Cell cell = new Cell( array.GetValue( ia, ja ), type );
                    cell.Behaviors.Add( behavior );
                    this[i, j] = cell;
                }
            }

            Colorize( );
        }
Example #11
0
 public ArrayTraverse(Array array)
 {
     _maxLengths = new int[array.Rank];
     for (int i = 0; i < array.Rank; ++i)
     {
         _maxLengths[i] = array.GetLength(i) - 1;
     }
     Position = new int[array.Rank];
 }
 public ArrayTraverse(Array array)
 {
     this.Position = new int[array.Rank];
     this.maxLengths = new int[array.Rank];
     for (int i = 0; i < array.Rank; i++)
     {
         this.maxLengths[i] = array.GetLength(i) - 1;
     }
 }
Example #13
0
        /// <summary>
        /// The array to string.
        /// </summary>
        /// <param name="array">
        /// The array.
        /// </param>
        /// <returns>
        /// The <see cref="string"/>.
        /// </returns>
        public static string ArrayToString(Array array)
        {
            StringBuilder text = new StringBuilder();

            for (int i = 0; i < array.GetLength(0); i++)
            {
                if (i != array.GetLength(0) - 1)
                {
                    text.Append(array.GetValue(i) + ", ");
                }
                else
                {
                    text.Append(array.GetValue(i));
                }
            }

            return text.ToString();
        }
Example #14
0
             private void serializeArray(Array array)
             {
                m_ArrayData = new object[array.Length];
                m_ArrayDims = new int[array.Rank];
                for(var i=0; i<array.Rank; i++)
                    m_ArrayDims[i] = array.GetLength(i);

                var idx = 0;
                SerializationUtils.WalkArrayWrite(array, elm => m_ArrayData[idx++] =  elm );
             }
 private void WriteArray(BinaryWriter bw, Array a, int dimension, params int[] indices)
 {
     if (a.Rank == dimension)
         WriteCore(bw, a.GetValue(indices));
     else
     {
         for (int i = 0; i < a.GetLength(dimension); i++)
             WriteArray(bw, a, dimension + 1, indices.Append(i));
     }
 }
Example #16
0
        private static int[] GetLengths(Array array)
        {
            var lengths = new int[array.Rank];
            for (var i = 0; i < array.Rank; i++)
            {
                lengths[i] = array.GetLength(i);
            }

            return lengths;
        }
 static void Next(Array array, Int32[] indexer)
 {
   indexer[0]++;
   for (var i = 0; i < array.Rank - 1; ++i)
   {
     if (indexer[i] == array.GetLength(i))
     {
       indexer[i    ] = 0;
       indexer[i + 1]++;
     }
   }
 }
Example #18
0
		private bool ArrayDimensionsEqual(Array a1, Array a2)
		{
			for (int dimension = 0; dimension < a1.Rank; dimension++)
			{
				if (a1.GetLength(dimension) != a2.GetLength(dimension))
				{
					return false;
				}
			}

			return true;
		}
        private static PropertyDescriptorCollection CreateColumnPropertyDescriptorCollection(Array source)
        {
            var elementType = source.GetType().GetElementType();
            var n = source.GetLength(0);
            var descriptors = new Array2DIndexPropertyDescriptor[n];
            for (int i = 0; i < n; i++)
            {
                descriptors[i] = new Array2DIndexPropertyDescriptor(elementType, i);
            }

            return new PropertyDescriptorCollection(descriptors);
        }
Example #20
0
        /// <summary>
        /// Initializes a new ArrayDataView from array with custom column names.
        /// </summary>
        /// <param name="array">array of data.</param>
        /// <param name="colnames">collection of column names.</param>
        public ArrayDataView(Array array, object[] colnames)
            : this(array)
        {
            if(colnames.Length != array.GetLength(1))
                throw new ArgumentException("column names must correspond to array columns.","colnames");

            _colnames = new string[colnames.Length];
            for(int i = 0; i < colnames.Length; i++)
            {
                _colnames[i] = colnames[i].ToString();
            }
        }
Example #21
0
 private void DimensionalWriteResoursy(ByteObjectWriter writer, Array array, Type itemType, int dimensional, int[] indexes)
 {
     for (int i = 0; i < array.GetLength(dimensional); i++)
     {
         indexes[dimensional] = i;
         if (dimensional < array.Rank - 1)
             DimensionalWriteResoursy(writer, array, itemType, dimensional + 1, indexes);
         else
         {
             writer.Complex(array.GetValue(indexes), itemType);
         }
     }
 }
Example #22
0
 internal void Iterate_array_elements_in_all_dimensions(Array objectToFlatten, List<int> indexes)
 {
     var t = objectToFlatten.GetType();
     if (t.GetArrayRank() > indexes.Count)
         for (var i = 0; i < objectToFlatten.GetLength(indexes.Count); i++)
         {
             indexes.Add(i);
             Iterate_array_elements_in_all_dimensions(objectToFlatten, indexes);
             indexes.RemoveAt(indexes.Count - 1);
         }
     else
         this.Element(objectToFlatten.GetValue(indexes.ToArray()));
 }
        private static PropertyDescriptorCollection CreateRowPropertyDescriptorCollection(Array source)
        {
            var elementType = source.GetType().GetElementType();
            var n = source.GetLength(1);
            var descriptors = new Array2DIndexPropertyDescriptor[n];
            for (int i = 0; i < n; i++)
            {
                descriptors[i] = new Array2DIndexPropertyDescriptor(elementType, i);
            }

            // ReSharper disable once CoVariantArrayConversion
            return new PropertyDescriptorCollection(descriptors);
        }
        // Save array to file
        public static void Save(string file, Array array)
        {
            StreamWriter writer = null;

            try
            {
                int	height = array.GetLength(0);
                int	width = array.GetLength(1);

                // create file
                writer = File.CreateText(file);

                // write array dimensions
                writer.WriteLine("{0} {1}", height, width);

                for (int i = 0; i < height; i++)
                {
                    string[]	strs = new string[width];

                    for (int j = 0; j < width; j++)
                    {
                        strs[j] = array.GetValue(i, j).ToString();
                    }

                    writer.WriteLine(string.Join(" ", strs));
                }
            }
            catch (Exception)
            {
                throw new ApplicationException();
            }
            finally
            {
                // close file
                if (writer != null)
                    writer.Close();
            }
        }
Example #25
0
 private void DimensionalReadResoursy(ByteObjectReader reader, Array array, Type itemType, int dimensional, int[] indexes)
 {
     for (int i = 0; i < array.GetLength(dimensional); i++)
     {
         indexes[dimensional] = i;
         if (dimensional < array.Rank - 1)
             DimensionalReadResoursy(reader, array, itemType, dimensional + 1, indexes);
         else
         {
             var item = reader.Complex(itemType);
             array.SetValue(item, indexes);
         }
     }
 }
Example #26
0
        /// <summary>
        /// Initializes a new ArrayDataView from array.
        /// </summary>
        /// <param name="array">array of data.</param>
        public ArrayDataView(Array array)
        {
            if (array.Rank != 2)
                throw new ArgumentException("Supports only two dimentional arrays","array");

            _data = array;

            _rows = new ArrayRowView[array.GetLength(0)];

            for(int i = 0; i < _rows.Length; i++)
            {
                _rows[i] = new ArrayRowView(this,i);
            }
        }
Example #27
0
 //--------------------------------------------------------------------------------------------------------------
 //проигрывает один клип из массива, выбирая случайным образом. Если клип уже звучит, то не прерывает
 public void playClipsRandomFull(Array array)
 {
     if (array.Length == 0) {
         return;
     }
     AudioClip tmpClip =(AudioClip) array.GetValue(UnityEngine.Random.Range (0, array.GetLength (0)));
     if (tmpClip != null) {
         if(!source.isPlaying){//если клип уже играет, то пусть играет
             source.clip = tmpClip;
             source.Play ();
         }
     }
     else {
         //Debug.LogError("soundControl:playClipsRandom: Clip not defined!!");
     }
 }
Example #28
0
    //проигрывает один клип из массива, выбирая случайным образом. Если клип уже звучит, то  прерывает
    public void playClipsRandom(Array array)
    {
        if (array.Length == 0) {
            return;
        }
        AudioClip tmpClip =(AudioClip) array.GetValue(UnityEngine.Random.Range (0, array.GetLength (0)));
        if (tmpClip != null) {

                source.clip = tmpClip;
                source.Play ();

        }
        else {
            //Debug.LogError("soundControl:playClipsRandom: Clip not defined!!");
        }
    }
        private static bool HaveSameDimensions(object expectation, Array actual)
        {
            bool sameDimensions = true;

            for (int dimension = 0; dimension < actual.Rank; dimension++)
            {
                int expectedLength = ((Array) expectation).GetLength(dimension);
                int actualLength = actual.GetLength(dimension);

                sameDimensions = sameDimensions & AssertionScope.Current
                    .ForCondition(expectedLength == actualLength)
                    .FailWith("Expected dimension {0} to contain {1} item(s), but found {2}.", dimension, expectedLength,
                        actualLength);
            }

            return sameDimensions;
        }
		private void serialize( int[] coord, int dim, Array array, IProtocolFormatter writer )
		{
			int dimLength = array.GetLength( dim );
            writer.BeginWriteArray( dimLength );

			for( int i = 0; i < dimLength; i++ )
			{
				coord[ dim ] = i;

				if( dim == (array.Rank - 1) )
					MessageWriter.writeObject( array.GetValue( coord ), writer );					
				else
					serialize( coord, dim + 1, array, writer );
			}			

            writer.EndWriteArray();
		}