1

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.

  • What is the problem? just `return myData;` and everything works? – user492238 Aug 04 '14 at 20:42
  • @user492238 You are right; I am troubled. Now it seems working with return myData, so possibly it is not the .a or the [full,full] solving the issue. I have experienced several times this kind of error inside the ILNumerics Array Visualizer: function evaluation disabled because a previous function evaluation timed out. You must continue execution to reenable function evaluation. Then, inspecting the content of the variable myData it seemed corrupted; now it seems working with return myData; as expected. If I can reproduce the issue, I ll modify the question. Thanks, anyway – alea_iacta_est Aug 04 '14 at 20:51
  • Would be interesting to know the cause of the error. Thanks for posting – user492238 Aug 04 '14 at 21:06
  • @user492238 Yes, thanks for your comments; if I can replicate the problem I will update the question (which turned to be not a question anymore). – alea_iacta_est Aug 05 '14 at 07:19

0 Answers0