Skip to content

Matrix functions should call error() on error conditions, not print() #7

@dcuny

Description

@dcuny

Errors caused by wrong-sized matrices in Matrix.lua use print() and then return.

For example:

  function mat.dot(m1,m2)
    if m1.cols ~= m2.rows then
      print("Erro in matrix dot, cols rows erro")
      return
    end
   ...

Because return does not return a matrix as expected (it will return nil), the code will fail later on when it attempts an operation on the non-existent matrix.

The routines should instead call error, so the call stack trace will reflect how the routine was called. For example:

  function mat.dot(m1,m2)
    if m1.cols ~= m2.rows then
      print("Error in mat.dot: "..(m1.cols).." columns in m1 do not match "..(m2.rows).."in m2")
      return
    end
   ...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions