Skip to content

mat.innersum #5

@dcuny

Description

@dcuny

In Matrix.lua, the function mat.innersum() references result.rows and result.cols. However, in this context, result is a number, not a matrix:

-- Inner Sum
  function mat.innersum(m1)
    local result = 0
    for i=1,result.rows do
      for j=1,result.cols do
          result = m1.matrix[i][j] + result
      end
    end
    return result
  end

Is this intending to sum the values in the matrix m1 instead of result (which in this function isn't a matrix)?

If that's the case, perhaps this was intended?

function mat.innersum(m1)
  local result = 0
  -- iterate through all the rows in m1
  for _, m1_row in ipairs( m1.matrix ) do
    -- iterate through all the columns in the row
    for _, col in ipairs( m1_row ) do
      -- add the column value to the sum
      result = result + col
    end
  end
  return result
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