You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@mahout.apache.org by "Lance Norskog (JIRA)" <ji...@apache.org> on 2011/08/21 03:04:27 UTC
[jira] [Issue Comment Edited] (MAHOUT-790) Redundancy in Matrix
API, view or get?
[ https://issues.apache.org/jira/browse/MAHOUT-790?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13088293#comment-13088293 ]
Lance Norskog edited comment on MAHOUT-790 at 8/21/11 1:03 AM:
---------------------------------------------------------------
Cardinality array: definitely- it is mutable from outside.
final int row;
final int column;
viewColumn v.s. getColumn: the question here is deep v.s. shallow copy?
I would go with
getColumn(int column) and getColumn(int column, Vector v)
where getColumn(int column) is assumed to give a shallow copy.
Diagonals: are they really needed now? Should there be triangular or symmetric? They have enough of their own behavior to be a separate subclass rather than some magic thing held by the main class. Example: DiagonalMatrix.invert() is a valid method, because it either blows up if there is a 0 value, or returns 1/values.
getNumNondefault: this requires being able to produce the number, which is a "design load". It is not used much in "real code". I suspect most of those users could track/deduce the number in some other way, rather than expect the object to remember it.
was (Author: lancenorskog):
Cardinality array: definitely- it is mutable from outside.
final int row;
final int column;
viewColumn v.s. getColumn: the question here is deep v.s. shallow copy?
I would go with
getColumn(int column) and getColumn(int column, Vector v)
where getColumn(int column) is assumed to give a shallow copy.
Diagonals: are they really needed now? Should there be triangular or symmetric?
getNumNondefault: this requires being able to produce the number, which is a "design load". It is not used much in "real code". I suspect most of those users could track/deduce the number in some other way, rather than expect the object to remember it.
> Redundancy in Matrix API, view or get?
> --------------------------------------
>
> Key: MAHOUT-790
> URL: https://issues.apache.org/jira/browse/MAHOUT-790
> Project: Mahout
> Issue Type: Improvement
> Reporter: Ted Dunning
>
> We have a bunch of redundant methods in our matrix interface. These include things that return views of parts of the matrix:
> {code}
> Matrix viewPart(int[] offset, int[] size);
> Matrix viewPart(int rowOffset, int rowsRequested, int columnOffset, int columnsRequested);
> Vector viewRow(int row);
> Vector viewColumn(int column);
> {code}
> and things that do the same but call refer to getting stuff
> {code}
> Vector getColumn(int column);
> Vector getRow(int row);
> double getQuick(int row, int column);
> int[] getNumNondefaultElements();
> Map<String, Integer> getColumnLabelBindings();
> Map<String, Integer> getRowLabelBindings();
> double get(String rowLabel, String columnLabel);
> {code}
> To my mind, get implies a get-by-value whereas view implies get-by-reference. As such, I would suggest that getColumn and getRow should disappear. On the other hand, getQuick and get are both correctly named.
> This raises the question of what getNumNondefaultElements really does. I certainly can't tell just from the signature. Is it too confusing to keep?
> Additionally, what do people think that getColumnLabelBindings and getRowLabelBindings return? A mutable map? Or an immutable one?
> Under the covers, viewRow and viewColumn (and the upcoming viewDiagonal) have default implementations that use MatrixVectorView, but AbstractMatrix doesn't have an implementation for getRow and getColumn.
> In sum, I suggest that:
> - getRow and getColumn go away
> - the fancy fast implementations fo getRow and getColumn that exist be migrated to be over-rides of viewRow and viewColumn
> - there be a constructor for AbstractMatrix that sets the internal size things correctly.
> - that the internal cardinality array in AbstractMatrix goes away to be replaced by two integers.
> - viewDiagonal() and viewDiagonal(length) and viewDiagonal(row, column) and viewDiagonal(int row, column, length) be added.
> I will produce a patch shortly.
--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira