[ 
https://issues.apache.org/jira/browse/MAHOUT-34?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12588184#action_12588184
 ] 

Samee Zahur commented on MAHOUT-34:
-----------------------------------

Well the reason I added VectorPair is that I was going through the MAHOUT-20 
codes and sought to remove every single for loop there :p I'm not sure what you 
mean by "static inner classes of the test" but yes, the thought of putting 
VectorPairElement and VectorPairIterator as inner classes to VectorPair did 
occur to me. At the time, I guess I just wanted to keep each file short and 
simple. And the thing is I really didn't see anything gained by making 
VectorPairElement inner. As for VectorPairIterator, we can simply make it a 
package private rather than inner, as users are supposed to access it as 
Iterator<VectorPairElement> anyway. That's pretty much all the factoring I 
could come up with.

And yes, in fact more generic solutions are possible. But the most elegant ones 
I could come up with entailed modifying the Vector interface by making it use 
Java generics, like java.lang do. Presently the Vectors are tied down to Double 
values (might even be useful if we need complex-valued vectors later). That 
would allow the users to use a more or less uniform interface, and might even 
allow the "Element" class to be factored out. Problems with such a change might 
be:

The Iterator logics used in each (VectorPair, SparseVector, DenseVector) are 
quite distinct and hard to specify from a generic class given that Java do not 
support the kind of template specialization features of C++. But still, I guess 
doable by implementing a generic interface by concrete classes. Would enable 
the users to write codes like:

VectorIterator<Double> it = sparsevec.iterator();
VectorIterator<Complex> jt = cmplxdensevec.iterator();
VectorIterator<Pair<Double,Complex>> kt = 
Vector.pairiterator(sparsevec,cmplxdensevec);

Could design it this way if you want me to. But is there any specific 
redundancy in these Iterator classes that you have in mind? And do bear in mind 
this would probably mean changing the Vector interface to a generic one - 
meaning other classes that depend on it will have to be tweaked accordingly 
(probably just by simply replacing Vector by Vector<Double>). This is why I 
opted in for the simpler designs here.

> Iterator interface for Vectors
> ------------------------------
>
>                 Key: MAHOUT-34
>                 URL: https://issues.apache.org/jira/browse/MAHOUT-34
>             Project: Mahout
>          Issue Type: New Feature
>            Reporter: Samee Zahur
>            Assignee: Karl Wettin
>         Attachments: VectorIterator.3.patch.bz2, 
> VectorIterator.patch.2.tar.bz2, VectorIterator.patch.tar.bz2
>
>
> Implemented an Iterator interface for the Vector classes. Was necessary for 
> porting from Float[] used in some parts of the code.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to