[ 
https://issues.apache.org/jira/browse/SYSTEMML-619?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15229134#comment-15229134
 ] 

Mike Dusenberry edited comment on SYSTEMML-619 at 4/6/16 9:18 PM:
------------------------------------------------------------------

It continues:

Replace {{dX = 2 * X}} with the equivalent {{dX = 2 * (X+0.1-0.1)}}:

{code}
# Generate data
N = 3
D = 2
X = rand(rows=N, cols=D)

# Function
dX = 2 * (X+0.1-0.1)

# Print elements of dX
for (i in 1:nrow(dX)) {
  for (j in 1:ncol(dX)) {
    print("dX["+i+","+j+"]: " + as.scalar(dX[i,j]))
  }
}
print("")

# Function
dX = 2 * (X+0.1-0.1)

# Print elements of dX
for (i in 1:nrow(dX)) {
  for (j in 1:ncol(dX)) {
    print("dX["+i+","+j+"]: " + as.scalar(dX[i,j]))
  }
}
print("")


print("")
print("")
print("")
{code}

{code}
dX[1,1]: 0.3631027757233218
dX[1,2]: 0.7463204132762002
dX[2,1]: 1.396631386586599
dX[2,2]: 0.4570007065789227
dX[3,1]: 0.7576032950257092
dX[3,2]: 1.191150376801223

dX[1,1]: 1.0917431959015071
dX[1,2]: 1.0804855841809473
dX[2,1]: 0.36778443121041454
dX[2,2]: 1.2503688857941493
dX[3,1]: 1.8974469686808841
dX[3,2]: 0.20545803320254397
{code}

Now, swap the order of the addition and subtraction and replace it with {{dX = 
2 * (X-0.1+0.1)}}:

{code}
# Generate data
N = 3
D = 2
X = rand(rows=N, cols=D)

# Function
dX = 2 * (X-0.1+0.1)

# Print elements of dX
for (i in 1:nrow(dX)) {
  for (j in 1:ncol(dX)) {
    print("dX["+i+","+j+"]: " + as.scalar(dX[i,j]))
  }
}
print("")

# Function
dX = 2 * (X-0.1+0.1)

# Print elements of dX
for (i in 1:nrow(dX)) {
  for (j in 1:ncol(dX)) {
    print("dX["+i+","+j+"]: " + as.scalar(dX[i,j]))
  }
}
print("")


print("")
print("")
print("")
{code}

{code}
dX[1,1]: 0.5866339382864822
dX[1,2]: 0.23074794178126168
dX[2,1]: 0.46171941318733056
dX[2,2]: 0.2481946969297868
dX[3,1]: 1.6808807265603098
dX[3,2]: 1.6798556486631278

dX[1,1]: 0.5866339382864822
dX[1,2]: 0.23074794178126168
dX[2,1]: 0.4617194131873305
dX[2,2]: 0.2481946969297868
dX[3,1]: 1.6808807265603098
dX[3,2]: 1.6798556486631278
{code}


was (Author: mwdus...@us.ibm.com):
It continues:

Replace {{dX = 2 * X}} with the equivalent {{dX = 2 * (X+0.1-0.1)}}:

{code}
# Generate data
N = 3
D = 2
X = rand(rows=N, cols=D)

# Function
dX = 2 * (X+0.1-0.1)

# Print elements of dX
for (i in 1:nrow(dX)) {
  for (j in 1:ncol(dX)) {
    print("dX["+i+","+j+"]: " + as.scalar(dX[i,j]))
  }
}
print("")

# Function
dX = 2 * (X+0.1-0.1)

# Print elements of dX
for (i in 1:nrow(dX)) {
  for (j in 1:ncol(dX)) {
    print("dX["+i+","+j+"]: " + as.scalar(dX[i,j]))
  }
}
print("")


print("")
print("")
print("")
{code}

{code}
dX[1,1]: 0.3631027757233218
dX[1,2]: 0.7463204132762002
dX[2,1]: 1.396631386586599
dX[2,2]: 0.4570007065789227
dX[3,1]: 0.7576032950257092
dX[3,2]: 1.191150376801223

dX[1,1]: 1.0917431959015071
dX[1,2]: 1.0804855841809473
dX[2,1]: 0.36778443121041454
dX[2,2]: 1.2503688857941493
dX[3,1]: 1.8974469686808841
dX[3,2]: 0.20545803320254397
{code}

Now, swap the order of the addition and subtraction and replace it with {{{{dX 
= 2 * (X-0.1+0.1}}:

{code}
# Generate data
N = 3
D = 2
X = rand(rows=N, cols=D)

# Function
dX = 2 * (X-0.1+0.1)

# Print elements of dX
for (i in 1:nrow(dX)) {
  for (j in 1:ncol(dX)) {
    print("dX["+i+","+j+"]: " + as.scalar(dX[i,j]))
  }
}
print("")

# Function
dX = 2 * (X-0.1+0.1)

# Print elements of dX
for (i in 1:nrow(dX)) {
  for (j in 1:ncol(dX)) {
    print("dX["+i+","+j+"]: " + as.scalar(dX[i,j]))
  }
}
print("")


print("")
print("")
print("")
{code}

{code}
dX[1,1]: 0.5866339382864822
dX[1,2]: 0.23074794178126168
dX[2,1]: 0.46171941318733056
dX[2,2]: 0.2481946969297868
dX[3,1]: 1.6808807265603098
dX[3,2]: 1.6798556486631278

dX[1,1]: 0.5866339382864822
dX[1,2]: 0.23074794178126168
dX[2,1]: 0.4617194131873305
dX[2,2]: 0.2481946969297868
dX[3,1]: 1.6808807265603098
dX[3,2]: 1.6798556486631278
{code}

> Same usage of same random matrix leads to different results
> -----------------------------------------------------------
>
>                 Key: SYSTEMML-619
>                 URL: https://issues.apache.org/jira/browse/SYSTEMML-619
>             Project: SystemML
>          Issue Type: Bug
>            Reporter: Mike Dusenberry
>
> Interesting bug, as of [commit e16fe1d | 
> https://github.com/apache/incubator-systemml/commit/e16fe1df586371408a9dc3de29b13c98982ff57c]:
> Start by creating a random matrix {{X}}, multiplying it by 2 and assigning to 
> a variable {{dX}}, and then print the results:
> {code}
> # Generate data
> N = 3
> D = 2
> X = rand(rows=N, cols=D)
> # Function
> dX = 2 * X
> # Print elements of dX
> for (i in 1:nrow(dX)) {
>   for (j in 1:ncol(dX)) {
>     print("dX["+i+","+j+"]: " + as.scalar(dX[i,j]))
>   }
> }
> print("")
> print("")
> print("")
> print("")
> {code}
> Output:
> {code}
> dX[1,1]: 1.0743268190621265
> dX[1,2]: 1.403590780383033
> dX[2,1]: 1.9404746268735837
> dX[2,2]: 0.8689030633611705
> dX[3,1]: 0.2589227727050818
> dX[3,2]: 0.342402157694327
> {code}
> Now, copy and paste the assignment to {{dX}} and the print statement, thus 
> literally repeating the same code again.
> {code}
> # Generate data
> N = 3
> D = 2
> X = rand(rows=N, cols=D)
> # Function
> dX = 2 * X
> # Print elements of dX
> for (i in 1:nrow(dX)) {
>   for (j in 1:ncol(dX)) {
>     print("dX["+i+","+j+"]: " + as.scalar(dX[i,j]))
>   }
> }
> print("")
> # Function
> dX = 2 * X
> # Print elements of dX
> for (i in 1:nrow(dX)) {
>   for (j in 1:ncol(dX)) {
>     print("dX["+i+","+j+"]: " + as.scalar(dX[i,j]))
>   }
> }
> print("")
> print("")
> print("")
> print("")
> {code}
> Output:
> {code}
> dX[1,1]: 1.5299997333070705
> dX[1,2]: 1.951679510186853
> dX[2,1]: 0.9372371721327426
> dX[2,2]: 0.11462997451231827
> dX[3,1]: 0.3913879515630596
> dX[3,2]: 0.4411374996556454
> dX[1,1]: 0.15757825641372136
> dX[1,2]: 1.6331143898957619
> dX[2,1]: 0.7271506546939133
> dX[2,2]: 0.648694276576909
> dX[3,1]: 1.4763697903577369
> dX[3,2]: 1.2645782773949483
> {code}
> Notice that the outputs are different... magic!



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to