I have another question for the IL sub-community.
I am finding my way through ILArrays and similar, but I would like another clarification. In the example reported on the ILNumerics website, we have (simplifying what is not needed)
public class Computing_Module1 : ILMath
{
public static ILRetArray<double> SimpleMethod()
{ using (ILScope.Enter() )
{
ILArray<double> C = ILSpecialData.sinc(40, 50);
return C[0, full];
}
}
}
If you run this code everything works perfectly because of the final C[0,full], from what I can understand. On converse, I have the following wrapping code around ILMath.csvread:
public static ILRetArray<double> ReadCsvIL(string aFileName)
{
using (ILScope.Enter())
{
string stringData;
try
{ stringData = getDataFromText(aFileName);
ILArray<double> myData = ILMath.csvread<double>(stringData);
return myData ;
}
catch (FileNotFoundException anExc)
{
Console.WriteLine(anExc.Message);
return null;
}
}
}
That will not work: two workarounds: either use the same trick provided in the example substituting
ILArray<double> myData = ILMath.csvread<double>(stringData);
return myData ;
with
ILArray<double> myData = ILMath.csvread<double>(stringData);
return myData[ILMath.full, ILMath.full] ;
or adopting the .a property of the ILArrays, so it should be written as:
ILArray<double> myData = ILMath.csvread<double>(stringData);
myData.a = myData;
return myData ;
Question: do we always have to use the .a property to assign an ILRetArray? Am I right in understanding that if return anArray[full, full] then some deep copy is performed behind the scenes, basically assigning to the .a property? Are there other ways to do this and what is the most efficient way?
For completeness the function to retrieve the text from the file is just a wrapping function around streamreader.ReadToEnd(), here it is the code:
public static string getDataFromText(string aFileName)
{
if (!File.Exists(aFileName))
throw new FileNotFoundException("The file does not exist.");
string stringData = String.Empty;
using (StreamReader streamReader = new StreamReader(aFileName))
{
stringData = streamReader.ReadToEnd();
}
return stringData;
}
Hope this makes sense; thanks you very much in advance.