public void ValidateRowKeysPairAnsiGetInstanceFromRowKeysAnsiFileAccess() { DenseMatrix <string, string, double> denseMatObj = GetDenseMatrix(); ParallelOptions parOptObj = new ParallelOptions(); denseMatObj.WritePaddedDouble(Constants.FastQTempTxtFileName, parOptObj); using (RowKeysPaddedDouble rkpdObj = RowKeysPaddedDouble.GetInstanceFromPaddedDouble(Constants.FastQTempTxtFileName, parOptObj)) { rkpdObj.WriteRowKeys(Constants.KeysTempFile); } using (RowKeysPaddedDouble rkaObj = RowKeysPaddedDouble.GetInstanceFromRowKeys( Constants.KeysTempFile, parOptObj, FileAccess.ReadWrite, FileShare.ReadWrite)) { Assert.AreEqual(denseMatObj.ColCount, rkaObj.ColCount); Assert.AreEqual(denseMatObj.RowCount, rkaObj.RowCount); Assert.AreEqual(denseMatObj.RowKeys.Count, rkaObj.RowKeys.Count); Assert.AreEqual(denseMatObj.ColKeys.Count, rkaObj.ColKeys.Count); } if (File.Exists(Constants.FastQTempTxtFileName)) { File.Delete(Constants.FastQTempTxtFileName); } if (File.Exists(Constants.KeysTempFile)) { File.Delete(Constants.KeysTempFile); } ApplicationLog.WriteLine( "RowKeysPairAnsi BVT : Validation of GetInstanceFromRowKeysAnsi(file-access) method successful"); }
private Matrix <string, string, TValue> LoadParentMatrix(string name) { if (Verbose) { Console.WriteLine("Loading " + name); } if (LeaveOnDiskIfPossible) { try { RowKeysAnsi predictorCharOriginal0 = RowKeysAnsi.GetInstanceFromRowKeysAnsi(name, ParallelOptionsScope.Current); Matrix <string, string, TValue> predictorCharOriginal = predictorCharOriginal0.ConvertValueView(CharToTValConverter, MissingValueForParse); //Matrix<string,string,TValue> predictorCharOriginal = predictorCharOriginal0.ConvertValueView(Bio.Util.ValueConverter.CharToDouble, double.NaN); Helper.CheckCondition(null == CreateRowKeysFileOrNull, "Already reading from a RowKeyAnsi file, so can't create one."); return(predictorCharOriginal); } catch (MatrixFormatException) {//ignore } try { RowKeysAnsi predictorCharOriginal0 = RowKeysAnsi.GetInstanceFromDenseAnsi(name, ParallelOptionsScope.Current); if (null != CreateRowKeysFileOrNull) { predictorCharOriginal0.WriteRowKeys(CreateRowKeysFileOrNull); } Matrix <string, string, TValue> predictorCharOriginal = predictorCharOriginal0.ConvertValueView(CharToTValConverter, MissingValueForParse); //Matrix<string, string, TValue> predictorCharOriginal = predictorCharOriginal0.ConvertValueView(Bio.Util.ValueConverter.CharToDouble, double.NaN); return(predictorCharOriginal); } catch (MatrixFormatException) {//ignore } try { RowKeysPaddedDouble predictorCharOriginal0 = RowKeysPaddedDouble.GetInstanceFromRowKeys(name, ParallelOptionsScope.Current); Matrix <string, string, TValue> predictorCharOriginal = predictorCharOriginal0.ConvertValueView(DoubleToTValConverter, MissingValueForParse); //Matrix<string,string,TValue> predictorCharOriginal = predictorCharOriginal0.ConvertValueView(Bio.Util.ValueConverter.CharToDouble, double.NaN); Helper.CheckCondition(null == CreateRowKeysFileOrNull, "Already reading from a RowKeyAnsi file, so can't create one."); return(predictorCharOriginal); } catch (MatrixFormatException) {//ignore } try { RowKeysPaddedDouble predictorCharOriginal0 = RowKeysPaddedDouble.GetInstanceFromPaddedDouble(name, ParallelOptionsScope.Current); if (null != CreateRowKeysFileOrNull) { predictorCharOriginal0.WriteRowKeys(CreateRowKeysFileOrNull); } Matrix <string, string, TValue> predictorCharOriginal = predictorCharOriginal0.ConvertValueView(DoubleToTValConverter, MissingValueForParse); //Matrix<string, string, TValue> predictorCharOriginal = predictorCharOriginal0.ConvertValueView(Bio.Util.ValueConverter.CharToDouble, double.NaN); return(predictorCharOriginal); } catch (MatrixFormatException) {//ignore } } Matrix <string, string, TValue> predictorCharOriginalX = MatrixFactory.Parse(name, MissingValueForParse, ParallelOptionsScope.Current); Helper.CheckCondition(null == CreateRowKeysFileOrNull, "Not creating from a DenseAnsi file, so can't create a RowKeyAnsi file."); return(predictorCharOriginalX); }
/// <summary> /// Preforms unit tests related to setting and reading value on all the built-in matrix types. /// </summary> /// <param name="doOutOfRangeTest">If true performs a test should throw a caught exception.</param> /// <param name="parallelOptions">A ParallelOptions instance that configures the multithreaded behavior of this operation.</param> public static void MainTest(bool doOutOfRangeTest, ParallelOptions parallelOptions) { //densematrix TestByKeysAndIndexes(() => CreateModelMatrix().ToDenseMatrix(), doOutOfRangeTest); //sparsematrix TestByKeysAndIndexes(() => CreateModelMatrix().ToSparseMatrix(), doOutOfRangeTest); //TransposeView TestByKeysAndIndexes(() => CreateModelMatrix().TransposeView().ToDenseMatrix().TransposeView(), doOutOfRangeTest); //ConvertValueView TestByKeysAndIndexes(() => CreateModelMatrix().ConvertValueView(ValueConverter.DoubleToInt, int.MaxValue).ToDenseMatrix().ConvertValueView(ValueConverter.IntToDouble, double.NaN), doOutOfRangeTest); //SelectRowsAndColsView TestByKeysAndIndexes(() => CreateModelMatrix().SelectRowsAndColsView(new int[] { 2, 1, 0 }, new int[] { 2, 1, 0 }).ToDenseMatrix().SelectRowsAndColsView(new int[] { 2, 1, 0 }, new int[] { 2, 1, 0 }), doOutOfRangeTest); //RenameColsView TestByKeysAndIndexes(() => CreateModelMatrix().RenameColsView(new Dictionary <string, string> { { "x", "X" }, { "y", "Y" }, { "z", "Z" } }).ToDenseMatrix().RenameColsView(new Dictionary <string, string> { { "X", "x" }, { "Y", "y" }, { "Z", "z" } }), doOutOfRangeTest); //PermuteColValuesForEachRowView TestByKeysAndIndexes(() => CreateModelMatrix().PermuteColValuesForEachRowView(new int[] { 2, 1, 0 }).ToDenseMatrix().PermuteColValuesForEachRowView(new int[] { 2, 1, 0 }), doOutOfRangeTest); //MergeColsView TestByKeysAndIndexes(() => CreateModelMatrix().SelectColsView(0).ToDenseMatrix().MergeColsView(/*rowsMustMatch*/ true, CreateModelMatrix().SelectColsView(1, 2).ToDenseMatrix()), doOutOfRangeTest); //MergeRowsView TestByKeysAndIndexes(() => CreateModelMatrix().SelectRowsView(0).ToDenseMatrix().MergeRowsView(/*colsMustMatch*/ true, CreateModelMatrix().SelectRowsView(1, 2).ToDenseMatrix()), doOutOfRangeTest); //rowkeyspaddeddouble TestByKeysAndIndexes(() => CreateModelMatrix().ToPaddedDouble(parallelOptions), doOutOfRangeTest); //rowkeysansi TestByKeysAndIndexes(() => CreateModelMatrix().ConvertValueView(ValueConverter.DoubleToChar, '?').ToDenseAnsi(parallelOptions).ConvertValueView(ValueConverter.CharToDouble, double.NaN), doOutOfRangeTest); //densepairansi ValueConverter <double, UOPair <char> > doubleToUOPairConvert = new ValueConverter <double, UOPair <char> >( r => new UOPair <char>(((int)r).ToString((IFormatProvider)null)[0], ((int)r).ToString((IFormatProvider)null)[0]), pair => double.Parse(pair.First.ToString((IFormatProvider)null), (IFormatProvider)null)); TestByKeysAndIndexes(() => CreateModelMatrix().ConvertValueView(doubleToUOPairConvert, DensePairAnsi.StaticMissingValue).ToDensePairAnsi(parallelOptions).ConvertValueView(doubleToUOPairConvert.Inverted, double.NaN), doOutOfRangeTest); //RowKeysPaddedDouble string paddedDoubleFile = Path.GetTempFileName(); CreateModelMatrix().WritePaddedDouble(paddedDoubleFile, parallelOptions); using (RowKeysPaddedDouble rowKeysPaddedDouble = RowKeysPaddedDouble.GetInstanceFromPaddedDouble(paddedDoubleFile, parallelOptions, FileAccess.ReadWrite, FileShare.ReadWrite)) { TestByKeys(rowKeysPaddedDouble, doOutOfRangeTest); } CreateModelMatrix().WritePaddedDouble(paddedDoubleFile, parallelOptions); using (RowKeysPaddedDouble rowKeysPaddedDouble = RowKeysPaddedDouble.GetInstanceFromPaddedDouble(paddedDoubleFile, parallelOptions, FileAccess.ReadWrite, FileShare.ReadWrite)) { TestByIndexes(rowKeysPaddedDouble, doOutOfRangeTest); } File.Delete(paddedDoubleFile); //RowKeysRowKeysAnsi string rowKeysAnsiFile = Path.GetTempFileName(); CreateModelMatrix().WriteDenseAnsi(rowKeysAnsiFile, parallelOptions); using (RowKeysAnsi rowKeysRowKeysAnsi = RowKeysAnsi.GetInstanceFromDenseAnsi(rowKeysAnsiFile, parallelOptions, FileAccess.ReadWrite, FileShare.ReadWrite)) { TestByKeys(rowKeysRowKeysAnsi.ConvertValueView(ValueConverter.CharToDouble, double.NaN), doOutOfRangeTest); } CreateModelMatrix().WriteDenseAnsi(rowKeysAnsiFile, parallelOptions); using (RowKeysAnsi rowKeysRowKeysAnsi = RowKeysAnsi.GetInstanceFromDenseAnsi(rowKeysAnsiFile, parallelOptions, FileAccess.ReadWrite, FileShare.ReadWrite)) { TestByIndexes(rowKeysRowKeysAnsi.ConvertValueView(ValueConverter.CharToDouble, double.NaN), doOutOfRangeTest); } File.Delete(rowKeysAnsiFile); //RowKeysRowKeysPairAnsi string rowKeysPairAnsiFile = Path.GetTempFileName(); CreateModelMatrix().ConvertValueView(doubleToUOPairConvert, DensePairAnsi.StaticMissingValue).WriteDensePairAnsi(rowKeysPairAnsiFile, parallelOptions); using (RowKeysPairAnsi rowKeysAnsiPair = RowKeysPairAnsi.GetInstanceFromPairAnsi(rowKeysPairAnsiFile, parallelOptions, FileAccess.ReadWrite, FileShare.ReadWrite)) { TestByKeys(rowKeysAnsiPair.ConvertValueView(doubleToUOPairConvert.Inverted, double.NaN), doOutOfRangeTest); } CreateModelMatrix().ConvertValueView(doubleToUOPairConvert, DensePairAnsi.StaticMissingValue).WriteDensePairAnsi(rowKeysPairAnsiFile, parallelOptions); using (RowKeysPairAnsi rowKeysRowKeysAnsi = RowKeysPairAnsi.GetInstanceFromPairAnsi(rowKeysPairAnsiFile, parallelOptions, FileAccess.ReadWrite, FileShare.ReadWrite)) { TestByIndexes(rowKeysRowKeysAnsi.ConvertValueView(doubleToUOPairConvert.Inverted, double.NaN), doOutOfRangeTest); } File.Delete(rowKeysPairAnsiFile); }