Project

General

Profile

Feature #1296

Matrixrow-functions

Added by Julian Danner almost 5 years ago. Updated almost 5 years ago.

Status:
In Progress
Priority:
Normal
Assignee:
-
Category:
enhancing/improving
Target version:
Start date:
16 Jun 2019
Due date:
% Done:

10%

Estimated time:
Spent time:

Description

I ran into a problem concerning matrix-rows. Namely, I wanted to implement a function returning the Hamming-weight of a matrixrow (and/or vector,list,moduleelem,...). However, it turned out that it is not easy to even determine the number of columns of a given MATRIXROW without access to its corresponding matrix, for which we could just use NumCols. Also len and a cast to LIST do not work.

So, is there any way to simply find the length of a given MATRIXROW without accessing its matrix?
(One possibility I can think of is to run over all entries until an invalid-column-index error is thrown, but that seems to be a pretty ugly workaround...)


Related issues

Related to CoCoA-5 - Feature #487: ScalarProduct accepts MatrixRow?New2014-03-21

Related to CoCoA-5 - Slug #1597: GetRow/GetRows are extraordinarily slowClosed2021-05-27

History

#1 Updated by John Abbott almost 5 years ago

  • Category set to enhancing/improving
  • Target version set to CoCoA-5.?.?

The "easy solution" is to use GetRow(M,1) or R:=GetRows(M); R[1] instead of M[1]. But this makes copies of the matrix entries, so will
surely be slow for large matrices (or matrices with large entries).

As I recall MATRIXROW was created largely to support the old CoCoA-4 syntax for accessing matrix entries: namely M[1][2] was an alternative to M[1,2]. It may have allowed a slightly neater implementation of gaussian reduction... I believe a command such as M[1] := M[1]+M[2]; worked as expected, but in CoCoA-5 it is not permitted.

Currently, not many operations are permitted on a MATRIXROW.
If we do allow more, we should also ensure that CoCoALib allows
similar operations.

Note that MATRIXCOL does not exist.

#2 Updated by John Abbott almost 5 years ago

  • Status changed from New to In Progress
  • % Done changed from 0 to 10

The specific request to make len or NumCols work for a MATRIXROW should not be too hard to achieve. Which function name? I suppose NumCols is more precise...

#3 Updated by Anna Maria Bigatti almost 5 years ago

From what you say, I think you are passing a MATRIXROW as an argument (because you say you cannot call NumCols).

I have two suggestions for you:
1 - pass the MATRIX and the INT index (so you can use NumCols) - no copies
2 - pass the LIST GetRow(M,n) (so you can use len) - makes copies

John Abbott wrote:

As I recall MATRIXROW was created largely to support the old CoCoA-4 syntax for accessing matrix entries: namely M[1][2] was an alternative to M[1,2].

I confirm this: MATRIXROW is just a matrix + an index.
It behaves like a pointer, and this makes it very dodgy/dangerous/fragile, with no reference counting :scream: !!

Conclusion: I suggest limiting even further (!!) this dangerous type, so that we don't induce into temptation ;-)
In particular, we should prohibit passing MATRIXROW as function argument, because it behaves differently from other types (by ref, insteaf of by value).

#4 Updated by Anna Maria Bigatti almost 5 years ago

  • Related to Feature #487: ScalarProduct accepts MatrixRow? added

#5 Updated by John Abbott almost 3 years ago

  • Related to Slug #1597: GetRow/GetRows are extraordinarily slow added

Also available in: Atom PDF