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

Sean Owen commented on MAHOUT-435:
----------------------------------

This overriding is legal (it compiles after all). It does not change run-time 
behavior, but, changes compile-time behavior. Passing a reference of type 
DenseVector will statically bind to the second one. Calling with a reference of 
type Vector than points to a DenseVector will statically bind to the first.

The major drawback to this approach is simply that it requires the caller to 
understand those semantics and get the reference type right to take advantage. 
An alternative, but one with equal but different design issues, is one method 
with "instanceof" checks.

I think the right-er design would be an isDense() flag or something that 
affects behavior within one method. However for now I was just committing the 
patch.

> Add assign(DenseVector)/assign(DenseMatrix) function to 
> DenseVector/DenseMatrix
> -------------------------------------------------------------------------------
>
>                 Key: MAHOUT-435
>                 URL: https://issues.apache.org/jira/browse/MAHOUT-435
>             Project: Mahout
>          Issue Type: New Feature
>          Components: Math
>            Reporter: Max Heimel
>            Assignee: Sean Owen
>            Priority: Minor
>             Fix For: 0.5
>
>         Attachments: MAHOUT-435.diff
>
>
> This new feature would add a new overloaded assign function to 
> (Dense)Vector/(Dense)Matrix, that allows to assign the content of another 
> (Dense)Vector / (Dense)Matrix by overwriting the content of the internal 
> double array. Compared to using .clone(), this feature would reduce the 
> number of memory allocations. 
> For example in case of an iterative algorithm, that needs to check for 
> convergence;
> {code:title=Convergence check using .clone()|borderStyle=solid}
> Densematrix newMatrix = oldMatrix.clone();
> while(!converged)
> {
>     // perform iteration computation on newMatrix
>     converged=checkConvergence(newMatrix,oldMatrix);
>     oldMatrix = newMatrix.clone(); // results in memory allocation
> }
> {code}
> {code:title=Convergence check using .assign(Matrix)|borderStyle=solid}
> Densematrix newMatrix = oldMatrix.clone();
> while(!converged)
> {
>     // perform iteration computation on newMatrix
>     converged=checkConvergence(newMatrix,oldMatrix);
>     oldMatrix.assign(newMatrix); // no memory allocation
> }
> {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