Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
documentation:language_reference:objects:matrix:functions:touserdata [2018/09/25 15:34] – Added Code Example Simon Heinzedocumentation:language_reference:objects:matrix:functions:touserdata [2024/12/12 18:14] (current) Maurits W. Haverkort
Line 5: Line 5:
 Matrices are, per default, tables of tables in Lua. When algebraic operations are performed on them, they are repeatedly copied and moved, which can lead to severe performance issues if the matrices are large objects. Matrices are, per default, tables of tables in Lua. When algebraic operations are performed on them, they are repeatedly copied and moved, which can lead to severe performance issues if the matrices are large objects.
  
-A call of Matrix.ToUserdata($M$) takes a matrix and transforms it, from Lua's point of view, from a table of tables to a mere pointer, which it returns. This means that the object still has all functionalities Quanty defines on it with increased performance. The downside is that any functionalities Lua defines on tables is not necessarily longer available, most notably the element-wise access via the Bracket operator [].+A call of Matrix.ToUserdata($M$) takes a matrix and transforms it, from Lua's point of view, from a table of tables to a mere pointer, which it returns. This means that the object still has all functionalities Quanty defines on it, but with increased performance. The downside is that any functionalities Lua defines on tables are not necessarily available any more.
  
 The inverse operation of Matrix.ToUserdata() is //[[documentation:language_reference:objects:matrix:functions:ToTable|Matrix.ToTable()]]//. The inverse operation of Matrix.ToUserdata() is //[[documentation:language_reference:objects:matrix:functions:ToTable|Matrix.ToTable()]]//.
Line 15: Line 15:
 <code Quanty Example.Quanty> <code Quanty Example.Quanty>
 --This creates a table of tables --This creates a table of tables
-A = Matrix.Random({-2,2},{10000,10000}+A = Matrix.Random({-2,2},{10000,10000},{{"userdata",false}}
-setmetatable(AMatrixMeta+ 
 TimeStart("Table of Tables") TimeStart("Table of Tables")
 B = Matrix.Transpose(A) B = Matrix.Transpose(A)
Line 25: Line 24:
 print(B[1][1]) print(B[1][1])
 TimeEnd("Table of Tables") TimeEnd("Table of Tables")
 + 
 AUData = Matrix.ToUserdata(A) AUData = Matrix.ToUserdata(A)
---A is, after this point, no longer needed. + 
-A = nil +
-B = nil +
-collectgarbage() +
 TimeStart("Userdata") TimeStart("Userdata")
 B = Matrix.Transpose(AUData) B = Matrix.Transpose(AUData)
Line 37: Line 32:
 B = Matrix.ConjugateTranspose(B) B = Matrix.ConjugateTranspose(B)
 B = B - AUData B = B - AUData
---In case we want to access the first element. 
-B = Matrix.ToTable(B) 
 print(B[1][1]) print(B[1][1])
 TimeEnd("Userdata") TimeEnd("Userdata")
 + 
 TimePrint() TimePrint()
 </code> </code>
Line 56: Line 49:
  
 ===== Table of contents ===== ===== Table of contents =====
-{{indexmenu>.#1|msort}}+{{indexmenu>..:#2|tsort}}
  
Print/export