Skip to content

Instantly share code, notes, and snippets.

@csgillespie
Created October 27, 2017 11:41
Show Gist options
  • Save csgillespie/441e087da6498a0ac81a465995d298a1 to your computer and use it in GitHub Desktop.
Save csgillespie/441e087da6498a0ac81a465995d298a1 to your computer and use it in GitHub Desktop.

Revisions

  1. csgillespie created this gist Oct 27, 2017.
    33 changes: 33 additions & 0 deletions toeplitz.R
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,33 @@
    ##R version 3.4.2 (2017-09-28)
    ##Platform: x86_64-pc-linux-gnu (64-bit)
    ##Running under: Ubuntu 16.04.3 LTS

    bm_prog_toeplitz = function() {
    N = 3000
    ans = rep(0, N*N)
    dim(ans) = c(N, N)
    system.time({
    for (j in 1:N) {
    for (k in 1:N) {
    ans[k,j] = abs(j - k) + 1
    }
    }
    }
    )
    }
    ## Takes around 7 seconds
    bm_prog_toeplitz()


    ## Around 2 seconds
    N = 3000
    ans = rep(0, N*N)
    dim(ans) = c(N, N)
    system.time({
    for (j in 1:N) {
    for (k in 1:N) {
    ans[k,j] = abs(j - k) + 1
    }
    }
    })