Пример #1
0
 public void CopyFrom(ArraySubCollection <T> source)
 {
     this.TheArray          = source.TheArray;
     this.StartOffset       = source.StartOffset;
     this.NumberSubArrays   = source.NumberSubArrays;
     this.SubArrayChunkSize = source.SubArrayChunkSize;
 }
Пример #2
0
        public void DeepCopyTo(ArraySubCollection <T> target)
        {
            target.CopyFrom(this);

            target.TheArray = new T[this.TheArray.Length];

            Array.Copy(TheArray, target.TheArray, TheArray.Length);
        }
Пример #3
0
        public static TensorOld <double> Dot(this TensorOld <double> t1, TensorOld <double> t2)
        {
            if (t1.NumberDimensions > 2 || t2.NumberDimensions > 2)
            {
                throw new ProgrammingError("Dot product is not defined for tensors more that dimension 2");
            }

            if (t1.NumberDimensions == 1)
            {
                t1 = t1.Reshape(t1.Len, 1);
            }

            if (t2.NumberDimensions == 1)
            {
                t2.Reshape(1, t2.Len);
            }

            if (t1.ShapeDimensions[1] != t2.ShapeDimensions[0])
            {
                throw new ProgrammingError($"number of colums of the first matrix '{t1.ShapeDimensions[1]}' is not equal to the number of rows of the second: '{t2.ShapeDimensions[0]}'");
            }

            int convolutionSize = t1.ShapeDimensions[1];

            TensorOld <double> result = new TensorOld <double>(new[] { t1.ShapeDimensions[0], t2.ShapeDimensions[1] });

            int numRows = t1.ShapeDimensions[0];
            int numCols = t2.ShapeDimensions[1];

            for (int col = 0; col < numCols; col++)
            {
                result.GetTensorSpan(1, col);
                for (int row = 0; row < numRows; row++)
                {
                    ArraySubCollection <double> iter1 = t1.GetTensorSpan(1, row);
                    ArraySubCollection <double> iter2 = t2.GetTensorSpan(0, 0, col);

                    double cellValue = 0;

                    for (int i = 0; i < convolutionSize; i++)
                    {
                        cellValue += iter1[i] * iter2[i];
                    }
                }
            }

            return(result);
        }
        public static void Test()
        {
            int len = 30;

            int[] array = new int[len];

            for (int i = 0; i < len; i++)
            {
                array[i] = i;
            }

            TensorData <int> tensorData = new TensorData <int>(array, new[] { 2, 3, 5 });

            tensorData.TheDimensionsPermutations = new Permutation(0, 1, 2);

            ArraySubCollection <int> coll1 = new ArraySubCollection <int>(array, tensorData.TotalShapeDimensionChunkSizes[0], 0, tensorData.TotalSpaceDimensions[0]);

            ArraySubIter <int> iter1          = coll1.GetIter();
            List <int>         arrayOfNumbers = new List <int>();

            while (iter1.MoveNext())
            {
                Console.Write("[");
                var iter2 = iter1.GetSubArray(tensorData.TotalSpaceDimensions[1], tensorData.TotalShapeDimensionChunkSizes[1]).GetIter();
                while (iter2.MoveNext())
                {
                    var  iter3   = iter2.GetSubArray(tensorData.TotalSpaceDimensions[2], tensorData.TotalShapeDimensionChunkSizes[2]).GetIter();
                    bool isFirst = true;
                    Console.Write("[");
                    while (iter3.MoveNext())
                    {
                        arrayOfNumbers.Add(iter3.Current);

                        if (!isFirst)
                        {
                            Console.Write(", ");
                        }

                        Console.Write(iter3.Current);

                        isFirst = false;
                    }
                    Console.Write("]\n");
                }
                Console.Write("]\n");
            }
        }
Пример #5
0
 public ArraySubIter(ArraySubCollection <T> collection) : base(collection)
 {
     Reset();
 }
Пример #6
0
 public ArraySubCollection(ArraySubCollection <T> tensorSpan)
 {
     this.CopyFrom(tensorSpan);
 }