// Tries to parse a DenseAnsi file as a DenseAnsi-backed matrix with a Converter to type TValue. This generic // version using CharToGeneric, which does conversion through reflection on a Parse method. This is not very efficient. internal static bool TryGetInstance <TValue1>(string filename, TValue1 missingValue, ParallelOptions parallelOptions, out Matrix <string, string, TValue1> matrix) { matrix = null; Matrix <string, string, char> sscMatrix; if (!DenseAnsi.TryGetInstance(filename, '?', parallelOptions, out sscMatrix)) { return(false); } matrix = sscMatrix.ConvertValueView(new CharToGenericConverter <TValue1>(), missingValue); return(true); }
internal static bool TryGetInstance(string filename, double missingValue, ParallelOptions parallelOptions, out Matrix <string, string, double> matrix) { matrix = null; Matrix <string, string, char> sscMatrix; if (!DenseAnsi.TryGetInstance(filename, '?', parallelOptions, out sscMatrix)) { return(false); } matrix = sscMatrix.ConvertValueView(ValueConverter.CharToDouble, missingValue); return(true); }
/// <summary> /// Tries to read a file in DenseAnsi format and then creates a DenseAnsi class with values of the desired type. /// </summary> /// <typeparam name="TValue">The type of values wanted, for example, double</typeparam> /// <param name="filename">The dense ansi formatted file to read from.</param> /// <param name="missingValue">The special value that represents missing</param> /// <param name="parallelOptions">A ParallelOptions instance that configures the multithreaded behavior of this operation.</param> /// <param name="matrix">A matrix that internally stores values in a DenseAnsi object.</param> /// <returns>true, if the file can be parsed; false, otherwise.</returns> public static bool TryParseDenseAnsiFormatAsGenericMatrix <TValue>(string filename, TValue missingValue, ParallelOptions parallelOptions, out Matrix <string, string, TValue> matrix) { matrix = null; Matrix <string, string, char> sscMatrix; if (!DenseAnsi.TryGetInstance(filename, '?', parallelOptions, out sscMatrix)) { return(false); } matrix = sscMatrix.ConvertValueView(new CharToGenericConverter <TValue>(), missingValue); //matrix = sscMatrix.ConvertValueView(c => Parser.Parse<TValue>(c.ToString()), val => SpecialFunctions.FirstAndOnly<char>(val.ToString()), missingValue); return(true); }