Пример #1
0
 /// <summary>
 /// Create a new 3D tensor initialised to zero
 /// </summary>
 /// <param name="rowCount">Row count of each matrix</param>
 /// <param name="columnCount">Column count of each matrix</param>
 /// <param name="depth">Depth of the 3D tensor (number of matrices)</param>
 public static FloatTensor Create(int rowCount, int columnCount, int depth)
 {
     return(new FloatTensor
     {
         Matrix = Enumerable.Range(0, depth).
                  Select(i => FloatMatrix.Create(rowCount, columnCount)).ToArray()
     });
 }
Пример #2
0
        /// <summary>
        /// Creates a float tensor from a binary reader
        /// </summary>
        /// <param name="reader">The binary reader</param>
        public static FloatTensor ReadFrom(BinaryReader reader)
        {
            var len = reader.ReadInt32();
            var ret = new FloatMatrix[len];

            for (var i = 0; i < len; i++)
            {
                ret[i] = FloatMatrix.ReadFrom(reader);
            }
            return(Create(ret));
        }
Пример #3
0
        /// <summary>
        /// Tests if the matrices are the same
        /// </summary>
        /// <param name="matrix">The matrix to compare</param>
        /// <param name="comparer">Optional IEqualityComparer to use</param>
        /// <returns></returns>
        public bool IsEqualTo(FloatMatrix matrix, IEqualityComparer <float> comparer = null)
        {
            if (matrix == null || RowCount != matrix.RowCount || ColumnCount != matrix.ColumnCount)
            {
                return(false);
            }

            for (int i = 0, len = RowCount; i < len; i++)
            {
                if (!Row[i].IsEqualTo(matrix.Row[i], comparer))
                {
                    return(false);
                }
            }
            return(true);
        }