[ https://issues.apache.org/jira/browse/MAHOUT-208?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12788857#action_12788857 ]
Jake Mannix commented on MAHOUT-208: ------------------------------------ We could remove it, but I actually did something like this in decomposer, and kept track of a single boolean (isCacheValid or whatever) which would get set to false whenever a mutating method was called (not worrying about the case where you were setting it to something which didn't change the lengthNorm - ie be as conservative as possible). But with iterator methods which can mutate the vector entries as well, tracking down all the places where things can change could be tricky (and adding another isCacheValid = false in all the inner loops... is there a perf impact?). The other option is to just have a immutable subclasses which do keep track of things like this where we know it won't change, and as you say, the caller can keep track of it in the mutable case. There is a use-case for this though, if you're running over a huge set of vectors (say, a big matrix of them), and need to do dot products with them and then divide or multiply by norms or whatnot, keeping track of all of these norms externally is a lot of overhead, but recomputing them every time doubles your run time. > Vector.getLengthSquared() is dangerously optimized > -------------------------------------------------- > > Key: MAHOUT-208 > URL: https://issues.apache.org/jira/browse/MAHOUT-208 > Project: Mahout > Issue Type: Bug > Components: Matrix > Affects Versions: 0.1 > Environment: all > Reporter: Jake Mannix > Assignee: Sean Owen > Fix For: 0.3 > > > SparseVector and DenseVector both cache the value of lengthSquared, so that > subsequent calls to it get the cached value. Great, except the cache is > never cleared - calls to set/setQuick or assign or anything, all leave the > cached value unchanged. > Mutating method calls should set lengthNorm to -1 so that the cache is > cleared. > This could be a really nasty bug if hit. -- This message is automatically generated by JIRA. - You can reply to this email to add a comment to the issue online.