Skip to content

Symmetric matrix is not symmetric #37

Open
@olekscode

Description

@olekscode

We have two ways of instantiating PMSymmetricMatrix:

  1. by using the rows: method, inherited from PMMatrix
m := PMSymmetricMatrix rows: #(
    (1 2)
    (2 3)).
  1. by converting a PMMatrix to PMSymmetricMatrix using asSymmetricMatrix.
m := PMMatrix rows: #(
    (1 2)
    (2 3)).

m := m asSymmetricMatrix.

Neither of these methods checks whether a given matrix is really symmetric. This results in a better performance, especially in case of large matrices, when doing such test every time we create (or convert) a matrix could be expensive.

However, PMMatrix implements a method isSymmetric

isSymmetric
    ^ self = self transpose 

which is overridden by PMSymmetricMatrix to always return true

isSymmetric
    "Answers true because the receiver is a symmetric matrix"
    ^true

Which gives some confusing results

m := PMSymmetricMatrix rows: #(
    (1 0)
    (2 3)).

m isSymmetric. "true"
m := PMMatrix rows: #(
    (1 0)
    (2 3)).

m := m asSymmetricMatrix.
m isSymmetric. "true"

I think that either we should not allow initializingPMSymmetricMatrix with non-symmetric matrix (which is confusing already), or if we do (for the sake of performance), we should at least leave the method isSymmetric for testing if a symmetric matrix is actually symmetric.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions