Beispiel #1
0
        static public Matrix <TRowKey, TColKey, TValue2> MergeRowsAndColsView <TRowKey, TColKey, TValue2>(Matrix <TRowKey, TColKey, TValue2>[,] matrixPieces2D)
        {
            var mergeMatrixList = new List <Matrix <TRowKey, TColKey, TValue2> >();

            for (int rowIndex = 0; rowIndex < matrixPieces2D.GetLength(0); ++rowIndex)
            {
                var row = Enumerable.Range(0, matrixPieces2D.GetLength(1)).Select(colIndex => matrixPieces2D[rowIndex, colIndex]).ToArray();
                if (row.Length == 1)
                {
                    mergeMatrixList.Add(row[0]);
                }
                else
                {
                    mergeMatrixList.Add(new MergeColsView <TRowKey, TColKey, TValue2>(/*mustMatch*/ true, row));
                }
            }
            if (mergeMatrixList.Count == 1)
            {
                return(mergeMatrixList[0]);
            }

            var output = new MergeRowsView <TRowKey, TColKey, TValue2>(/*mustMatch*/ true, mergeMatrixList.ToArray());

            return(output);
        }
Beispiel #2
0
        /// <summary>
        /// Loads a single mergeView matrix from the list of files.
        /// </summary>
        /// <typeparam name="TRowKey"></typeparam>
        /// <typeparam name="TColKey"></typeparam>
        /// <typeparam name="TVal"></typeparam>
        /// <param name="files"></param>
        /// <param name="missingVal"></param>
        /// <param name="colsMustMatch"></param>
        /// <returns></returns>
        public static Matrix <TRowKey, TColKey, TVal> LoadAsSingleMatrix <TRowKey, TColKey, TVal>(this IEnumerable <FileInfo> files, TVal missingVal, bool colsMustMatch = false)
        {
            MatrixFactory <TRowKey, TColKey, TVal> mf = MatrixFactory <TRowKey, TColKey, TVal> .GetInstance();

            //var matrices = files.Select(dataFile => mf.Parse(dataFile.FullName, missingVal, ParallelOptionsScope.Current)).ToArray();
            var matrices = (from f in files
                            let name = f.Name == "-" ? MBT.Escience.FileUtils.WriteStdInToTempFile() : f.FullName
                                       select mf.Parse(name, missingVal, ParallelOptionsScope.Current)).ToArray();

            var result = new MergeRowsView <TRowKey, TColKey, TVal>(colsMustMatch, matrices);

            return(result);
        }