04: Try to reduce the copy overhead

I failed.
This commit is contained in:
2022-10-04 10:20:27 +02:00
parent 7f1f840e4a
commit 850494fcdc

View File

@ -916,11 +916,35 @@
"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",
" otherwise False.'''\n",
" # We need to create a copy as not to alter the original x\n",
" # outside this function.\n",
" copy_x = np.copy(x)\n",
" copy_x[i] = next_position\n",
" return disk_config_valid(copy_x, L)"
" # We need to ensure that x is not changed after this function,\n",
" # as alterations done on x will affect x outside the 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",
" # L = 11.3\n",
" # N = 20\n",
" # delta = .3\n",
" # x = generate_initial_positions(N, L)\n",
" # %timeit [MH_disk_move(x, L, delta) for _ in range(1000)]\n",
" #\n",
" # 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)"
]
},
{