[jira] [Commented] (MATH-725) use initialized static final arrays, instead of initializing it in constructors

2012-02-02 Thread Gilles (Commented) (JIRA)

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

Gilles commented on MATH-725:
-

Those arrays cannot be "static" since their size depends on a parameter ("k") 
passed to the constructor.


> use initialized static final arrays, instead of initializing it in 
> constructors
> ---
>
> Key: MATH-725
> URL: https://issues.apache.org/jira/browse/MATH-725
> Project: Commons Math
>  Issue Type: Improvement
>Affects Versions: 2.2
>Reporter: Eldar Agalarov
>Priority: Minor
> Fix For: 3.0
>
>   Original Estimate: 1h
>  Remaining Estimate: 1h
>
> The Well PRNG's implementations have arrays iRm1, iRm2, iRm3, i1, i2, i3. All 
> these arrays are unmodifiable, so we can replace this arrays initialization 
> block
> final int w = 32;
>   final int r = (k + w - 1) / w;
>   this.v = new int[r];
>   this.index = 0;
>   
>   // precompute indirection index tables. These tables are used for 
> optimizing access
>   // they allow saving computations like "(j + r - 2) % r" with costly 
> modulo operations
>   iRm1 = new int[r];
>   iRm2 = new int[r];
>   i1 = new int[r];
>   i2 = new int[r];
>   i3 = new int[r];
>   for (int j = 0; j < r; ++j) {
>   iRm1[j] = (j + r - 1) % r;
>   iRm2[j] = (j + r - 2) % r;
>   i1[j] = (j + m1) % r;
>   i2[j] = (j + m2) % r;
>   i3[j] = (j + m3) % r;
>   }
> with inline initialized static final arrays.
> This is much better and faster implementation, freed from unnecessary costly 
> calculations (such as %).
> Another solution: leave as is, but make all these arrays static.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: 
https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira




[jira] [Commented] (MATH-725) use initialized static final arrays, instead of initializing it in constructors

2012-01-20 Thread Gilles (Commented) (JIRA)

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

Gilles commented on MATH-725:
-

Fine then.

Eldar,
Would you provide a patch along those lines ("static" initializations + getter 
methods)?
Thanks.


> use initialized static final arrays, instead of initializing it in 
> constructors
> ---
>
> Key: MATH-725
> URL: https://issues.apache.org/jira/browse/MATH-725
> Project: Commons Math
>  Issue Type: Improvement
>Affects Versions: 2.2
>Reporter: Eldar Agalarov
>Priority: Minor
>   Original Estimate: 1h
>  Remaining Estimate: 1h
>
> The Well PRNG's implementations have arrays iRm1, iRm2, iRm3, i1, i2, i3. All 
> these arrays are unmodifiable, so we can replace this arrays initialization 
> block
> final int w = 32;
>   final int r = (k + w - 1) / w;
>   this.v = new int[r];
>   this.index = 0;
>   
>   // precompute indirection index tables. These tables are used for 
> optimizing access
>   // they allow saving computations like "(j + r - 2) % r" with costly 
> modulo operations
>   iRm1 = new int[r];
>   iRm2 = new int[r];
>   i1 = new int[r];
>   i2 = new int[r];
>   i3 = new int[r];
>   for (int j = 0; j < r; ++j) {
>   iRm1[j] = (j + r - 1) % r;
>   iRm2[j] = (j + r - 2) % r;
>   i1[j] = (j + m1) % r;
>   i2[j] = (j + m2) % r;
>   i3[j] = (j + m3) % r;
>   }
> with inline initialized static final arrays.
> This is much better and faster implementation, freed from unnecessary costly 
> calculations (such as %).
> Another solution: leave as is, but make all these arrays static.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: 
https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira




[jira] [Commented] (MATH-725) use initialized static final arrays, instead of initializing it in constructors

2012-01-20 Thread Sebb (Commented) (JIRA)

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

Sebb commented on MATH-725:
---

AFAIK, getters will be inlined by optimising compilers. 
So they won't be noticeably slower than direct access.

> use initialized static final arrays, instead of initializing it in 
> constructors
> ---
>
> Key: MATH-725
> URL: https://issues.apache.org/jira/browse/MATH-725
> Project: Commons Math
>  Issue Type: Improvement
>Affects Versions: 2.2
>Reporter: Eldar Agalarov
>Priority: Minor
>   Original Estimate: 1h
>  Remaining Estimate: 1h
>
> The Well PRNG's implementations have arrays iRm1, iRm2, iRm3, i1, i2, i3. All 
> these arrays are unmodifiable, so we can replace this arrays initialization 
> block
> final int w = 32;
>   final int r = (k + w - 1) / w;
>   this.v = new int[r];
>   this.index = 0;
>   
>   // precompute indirection index tables. These tables are used for 
> optimizing access
>   // they allow saving computations like "(j + r - 2) % r" with costly 
> modulo operations
>   iRm1 = new int[r];
>   iRm2 = new int[r];
>   i1 = new int[r];
>   i2 = new int[r];
>   i3 = new int[r];
>   for (int j = 0; j < r; ++j) {
>   iRm1[j] = (j + r - 1) % r;
>   iRm2[j] = (j + r - 2) % r;
>   i1[j] = (j + m1) % r;
>   i2[j] = (j + m2) % r;
>   i3[j] = (j + m3) % r;
>   }
> with inline initialized static final arrays.
> This is much better and faster implementation, freed from unnecessary costly 
> calculations (such as %).
> Another solution: leave as is, but make all these arrays static.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: 
https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira




[jira] [Commented] (MATH-725) use initialized static final arrays, instead of initializing it in constructors

2012-01-20 Thread Gilles (Commented) (JIRA)

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

Gilles commented on MATH-725:
-

The problem is that arrays are _mutable_. If they are made "static", a buggy or 
malicious subclass of {{AbstractWell}} will be able to affect all instances.

We could do that if the arrays are never exposed, i.e. they would become 
"private" and their contents must be accessed through methods. Not sure whether 
it won't be slower in the end...



> use initialized static final arrays, instead of initializing it in 
> constructors
> ---
>
> Key: MATH-725
> URL: https://issues.apache.org/jira/browse/MATH-725
> Project: Commons Math
>  Issue Type: Improvement
>Affects Versions: 2.2
>Reporter: Eldar Agalarov
>Priority: Minor
>   Original Estimate: 1h
>  Remaining Estimate: 1h
>
> The Well PRNG's implementations have arrays iRm1, iRm2, iRm3, i1, i2, i3. All 
> these arrays are unmodifiable, so we can replace this arrays initialization 
> block
> final int w = 32;
>   final int r = (k + w - 1) / w;
>   this.v = new int[r];
>   this.index = 0;
>   
>   // precompute indirection index tables. These tables are used for 
> optimizing access
>   // they allow saving computations like "(j + r - 2) % r" with costly 
> modulo operations
>   iRm1 = new int[r];
>   iRm2 = new int[r];
>   i1 = new int[r];
>   i2 = new int[r];
>   i3 = new int[r];
>   for (int j = 0; j < r; ++j) {
>   iRm1[j] = (j + r - 1) % r;
>   iRm2[j] = (j + r - 2) % r;
>   i1[j] = (j + m1) % r;
>   i2[j] = (j + m2) % r;
>   i3[j] = (j + m3) % r;
>   }
> with inline initialized static final arrays.
> This is much better and faster implementation, freed from unnecessary costly 
> calculations (such as %).
> Another solution: leave as is, but make all these arrays static.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: 
https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira