kronenthaler / libai

4 stars 2 forks source link

About Matrix#applyInIdentity() #34

Closed dktcoding closed 7 years ago

dktcoding commented 7 years ago

I was doing the input validation and JavaDoc for Matrix and have a small question about Matrix#applyInIdentity(), this function is not currently used within libai, but I was wondering what it's supposed to do... the current JavaDoc makes little sense a(i,i) = F(this(i,j)) but it actually does a(i,i) = F(this(i,0)) there's also no identity involved.

kronenthaler commented 7 years ago

The purpose of this function was a bit obscure at the time, but the idea is that this function allows to convert a column matrix, into a square matrix with the same elements in the identity after applying a function f over it. For example: imagine a m = [1,2,3], f(x)=x*x and a = [[1,0,0],[0,1,0],[0,0,1]] (3x3 matrix) If you execute m.applyInIdentity(f, a) will end up with: a = [[1,0,0], [0,4,0], [0,0,9]]

Basically it projected the column matrix into a square matrix and applied a function in the process. It's a bit more efficient than doing m.apply(f) then convert it into a square matrix.

dktcoding commented 7 years ago

Ahhhhhhhh ok! (I was confused by the name and the doc, I see it now)