04: Change back to copying
This commit is contained in:
@ -916,35 +916,15 @@
|
|||||||
"def remains_valid_after_move(x,i,next_position,L):\n",
|
"def remains_valid_after_move(x,i,next_position,L):\n",
|
||||||
" '''Returns True if replacing x[i] by next_position would yield a valid configuration,\n",
|
" '''Returns True if replacing x[i] by next_position would yield a valid configuration,\n",
|
||||||
" otherwise False.'''\n",
|
" otherwise False.'''\n",
|
||||||
" # We need to ensure that x is not changed after this function,\n",
|
" # We need to create a copy as not to alter the original x\n",
|
||||||
" # as alterations done on x will affect x outside the function.\n",
|
" # outside this function.\n",
|
||||||
" \n",
|
|
||||||
" #current_position = np.copy(x[i])\n",
|
|
||||||
" current_position = x[i].copy()\n",
|
|
||||||
" #print(type(current_position))\n",
|
|
||||||
" x[i] = next_position\n",
|
|
||||||
" ret = disk_config_valid(x, L)\n",
|
|
||||||
" x[i] = current_position\n",
|
|
||||||
" return ret\n",
|
|
||||||
" \n",
|
|
||||||
" # An alternative approach was to fully copy x, but that turned\n",
|
|
||||||
" # out to be a lot slower:\n",
|
|
||||||
" #copy_x = np.copy(x)\n",
|
|
||||||
" #copy_x[i] = next_position\n",
|
|
||||||
" #return disk_config_valid(copy_x, L)\n",
|
|
||||||
" \n",
|
|
||||||
" # This was tested using the following code.\n",
|
|
||||||
" #\n",
|
" #\n",
|
||||||
" # L = 11.3\n",
|
" # NOTE: The copying in this function is the heaviest operation.\n",
|
||||||
" # N = 20\n",
|
" # Reducing this overhead would be great, but I am not familiar\n",
|
||||||
" # delta = .3\n",
|
" # enough with references/pointers in Python.\n",
|
||||||
" # x = generate_initial_positions(N, L)\n",
|
" copy_x = np.copy(x)\n",
|
||||||
" # %timeit [MH_disk_move(x, L, delta) for _ in range(1000)]\n",
|
" copy_x[i] = next_position\n",
|
||||||
" #\n",
|
" return disk_config_valid(copy_x, L)"
|
||||||
" # For the full copy method:\n",
|
|
||||||
" # 2.05 s ± 46.5 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\n",
|
|
||||||
" # For the current method, changing x[i] back:\n",
|
|
||||||
" # 138 ms ± 12.3 ms per loop (mean ± std. dev. of 7 runs, 10 loops each)"
|
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user