Post Reply 
MC: Faster User-RPL HILBERT
07-10-2018, 01:58 AM (This post was last modified: 07-10-2018 11:55 AM by Thomas Okken.)
Post: #10
RE: MC: Faster User-RPL HILBERT
To elaborate a bit...

A naive Java implementation would be like this:

Code:
double[][] hilbert(int n) {
    double[][] h = new double[n][n];
    for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++)
            h[i][j] = 1.0 / (i + j + 1);
    return h;
}

while the division-minimizing approach could also be coded with nested loops, like this:

Code:
double[][] hilbert(int n) {
    double[][] h = new double[n][n];
    for (int j = 0; j < n; j++)
        h[0][j] = 1.0 / (j + 1);
    for (int i = 1; i < n; i++) {
        for (int j = 0; j < n - 1; j++)
            h[i][j] = h[i - 1][j + 1];
        h[i][n - 1] = 1.0 / (i + n);
    }
    return h;
}
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
MC: Faster User-RPL HILBERT - Joe Horn - 07-09-2018, 01:28 PM
RE: MC: Faster User-RPL HILBERT - Joe Horn - 07-09-2018, 05:25 PM
RE: MC: Faster User-RPL HILBERT - Joe Horn - 07-09-2018, 11:43 PM
RE: MC: Faster User-RPL HILBERT - Gerald H - 07-10-2018, 09:50 AM
RE: MC: Faster User-RPL HILBERT - ttw - 07-09-2018, 05:10 PM
RE: MC: Faster User-RPL HILBERT - Thomas Okken - 07-10-2018 01:58 AM
RE: MC: Faster User-RPL HILBERT - Werner - 07-10-2018, 07:20 AM
RE: MC: Faster User-RPL HILBERT - Juan14 - 08-05-2018, 06:31 PM



User(s) browsing this thread: 3 Guest(s)