Most efficient way to build SMath matrix in VB.NET (plugin development)

Most efficient way to build SMath matrix in VB.NET (plugin development) - Messages

#1 Posted: 12/7/2015 6:23:57 PM
Alexander O. Melnik

Alexander O. Melnik

127 likes in 494 posts.

Group: Moderator

Hi all,

I have discovered recently that excel_IO plugin is way too slow in outputting LARGE excel ranges to SMath (30000+ elements).

The slowness narrows down to this part of the code:

        Dim myResult As List(Of Term) = New List(Of Term)
            For Each matValue As String In result_temp3
                myResult.AddRange(SMath.Manager.Converter.ToTerms(matValue))
            Next
            If counter > 2 Then
                myResult.AddRange(SMath.Manager.Converter.ToTerms(range_rows.ToString))
                myResult.AddRange(SMath.Manager.Converter.ToTerms(range_cols.ToString))
                myResult.Add(New Term(Functions.Mat, TermType.Function, (2 + (range_cols * range_rows))))
            End If

I am certain about the source of slowness because initially my code had two For Loops: one to format strings to satisfy SMath requirements and another one listed above. Later I have condensed those two For Loops into one. Performance DID NOT improve.

Is there any other way to pass a matrix to SMAth?

Any input is appreciated.

Thanks!
#2 Posted: 12/8/2015 2:11:52 PM
Dionysios J. Pantazis

Dionysios J. Pantazis

16 likes in 179 posts.

Group: User

Alex-

What is the last line doing for you?

Are you trying to size/format the matrix and then populate it element by element?

The code is hard for me, so maybe I don't recognize your approach.

Could you simply read the data line by line and append the set with each one and then at the end with range_rows, range_columns) for the same effect?

Since SMath syntax seems to be

mat(R1C1,R1C2,R1C3,R2C1,R2C2,R2C3,nROWs,nCOLS)

to get matrix of

R1C1 R1C2 R1C3
R2C1 R2C2 R2C3

I have been 'making' matrices to use in SMath via Excel in .csv files and text editor.

Using the .csv file already has everything formatted as needed. I take my data in csv, open it in editor, delete the CR/LF's so it becomes one long line and append the rows,cols) at the end. Copy and paste into SMAth and its there. My only trouble sometimes is counting the right number of rows/columns if I change things.
Join the SMath Studio Users Discord Channel: https://discord.gg/PayZpJW
#3 Posted: 12/8/2015 5:19:45 PM
Alexander O. Melnik

Alexander O. Melnik

127 likes in 494 posts.

Group: Moderator

Wrote

Alex-
Since SMath syntax seems to be

mat(R1C1,R1C2,R1C3,R2C1,R2C2,R2C3,nROWs,nCOLS)

I have been 'making' matrices to use in SMath via Excel in .csv files and text editor.



Do you have a plugin code (C# or VB.NET) that would pass a string mat(R1C1,R1C2,R1C3,R2C1,R2C2,R2C3,nROWs,nCOLS) back to SMath without an error?

I have tried it in the past, but passing a simple string did not quite work...

#4 Posted: 12/10/2015 12:09:25 PM
Davide Carpi

Davide Carpi

1416 likes in 2873 posts.

Group: Moderator

How much slow? With importData.XLSX I can import a 1100x111 matrix of numbers in ~7-8 seconds (optimization: numeric)

2015-12-10 16_07_07-SMath Studio Desktop - [Book1.sm_].png

The code is the same:

			// return selectionContent values to SMath
			List<Term> myResult = new List<Term>();
			foreach (string matValue in selectionContent)
			{
				myResult.AddRange(Converter.ToTerms(matValue));
			}
			myResult.AddRange(Converter.ToTerms(selectionHeight.ToString()));
			myResult.AddRange(Converter.ToTerms(selectionWidth.ToString()));
			myResult.Add(new Term(Functions.Mat, TermType.Function, 2 + (selectionHeight * selectionWidth)));
			
			// output to SMath
			return myResult.ToArray();
If you like my plugins please consider to support the program buying a license; for personal contributions to me: paypal.me/dcprojects
  • New Posts New Posts
  • No New Posts No New Posts