0

I made a Class for matrix operations, [MatrixObject]. I am mainly concerned with the inverse; I need to calculate many large matrix inverse's for this application.( size:~[R100xC100])

Right now the performance for computing the inverse is:

  • size:50x50 ---- time:~200ms
  • size:100x100 - time:~2.3s
  • size:200x200 - time:~29s

That sounds slow but its not, try beating that without purchasing libraries, its hard...

I can probably squeeze out a tiny bit more speed by cleaning the loops... But I'm wondering if turning this into a Structure would have major performance gains and makes sense ('would a smarter better looking programmer do this?').

The speed of this inverse calculation is essential to the application but it contains a large dynamic array. The internet says large arrays are a no go for Structs... But are there circumstances where you would use a Struct anyway? Also, what happens if the Struct w/ methods is wrapped in Class?

My knowledge of stack and heap is to the extent of stuff said in youtube videos. I don't have a deep enough understanding to answer this question.

Here as example of the Code:

As a Class (current version)

' Every thing inside a Class ----------------
Public Class MatrixObject1

    Private Structure Matrix4F_Array
        Dim A() As Matrix4x4
    End Structure

    Private m_ROW_Arrays() As Matrix4F_Array    '<-- array of [Matrix4x4] arrays 
    '
    '   m_ROW_Arrays(0)     .A(0)   .A(1)   .A(3)    ...
    '                       M11     M12     M13   
    '   m_ROW_Arrays(1)     .A(0)   .A(1)   .A(3)    ...
    '                       M21     M22     M23 
    '   m_ROW_Arrays(2)     .A(0)   .A(1)   .A(3)    ...
    '         :             M31     M32     M33 
    '         :

    Public Sub New()
        '...
    End Sub

    Public Shared Function Multiply(ByRef Mat1 As MatrixObject1, ByRef Mat2 As MatrixObject1) As MatrixObject1
        ' ....
    End Function

    Public Shared Function Inverse(ByRef i_Mat As MatrixObject1, ByRef success As Boolean) As MatrixObject1
        ' ....
    End Function

    ' * also includes propertys for size and shared operators: *,+,-
    '   and misc. functions.

End Class

As a Structure w/methods, and wrapper Class (for non essiential/slow methods); what i'm considering doing

' Structure with only essential, tight functions
Public Structure MatrixStruct

    Private Structure Matrix4F_Array
        Dim A() As Matrix4x4
    End Structure

    Private m_ROW_Arrays() As Matrix4F_Array    '<-- array of [Matrix4x4] arrays 

    Public Shared Function Multiply(ByRef Mat1 As MatrixStruct, ByRef Mat2 As MatrixStruct) As MatrixStruct
        ' ....
    End Function

    Public Shared Function Inverse(ByRef i_Mat As MatrixStruct, ByRef success As Boolean) As MatrixStruct
        ' ....
    End Function

End Structure


' 
' Matrix Class that inlcudes [MatrixStruct] member
'   -Class Methods have error checks and other misc. stuff
Public Class MatrixObject2

    Private m_Struct As MatrixStruct

    Public Sub New()
        '...
    End Sub

    Public Shared Function Multiply(ByRef Mat1 As MatrixObject2, ByRef Mat2 As MatrixObject2) As MatrixObject2
        ' ....
        Dim ret As New MatrixObject2
        ret.m_Struct = MatrixStruct.Multiply(Mat1.m_Struct, Mat2.m_Struct)
        Return ret
    End Function

    '   :
    '   :
    '   :
    ' * also includes propertys for size and shared operators: *,+,-
    '   and misc. functions.
End Class
3
  • I’m going to be honest, I’m really confused by this question and not really 100% sure what exactly you asking. If you’ve got an issue with your code, then you need to update your post with actual implementation of your methods. If not perhaps your asking in the wrong place as it reads more as a design question , maybe on the software engineering or code review might be more appropriate
    – Hursey
    Commented Sep 11, 2022 at 1:52
  • Of course you could actually try the different options you’ve posted and test results yourself
    – Hursey
    Commented Sep 11, 2022 at 1:53
  • Code works fine... Its a question of correct/ best practices of Struct & Class usage. I got some hits in another forum. If I figured out the solution I'll post it hear as well.
    – Tony
    Commented Sep 14, 2022 at 13:33

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.