Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Memory access speed problem
#1
I have to change a lot of values in a matrix by values that only change position where to act, but never change value.

For example:
|3 3 3|
|2 2 2|
|1 1 1|

has to result to

|4 4 4|
|4 4 4|
|4 4 4|

by summing

|1 1 1|
|2 2 2|
|3 3 3|

However, this one:
|5 5 5|
|5 5 5|
|5 5 5|

sums to (which is the previous sum swapped around in a deterministic way)
|3 3 3|
|1 1 1|
|2 2 2|

resulting

|8 8 8|
|6 6 6|
|7 7 7|


So, instead of calculating what to sum to each value (which basically means to recreate the entire matrix every time), I had the (seemingly terrible) idea of pre-creating a mask matrix and swap it around as it sums values:

|1 1 1| <-first starts here
|2 2 2|
|3 3 3| <-second starts here
|1 1 1|
|2 2 2|

However, calculating each individual value to sum has been shown at least 10x faster than using a swapped mask.
grid[j][i] += 1/(1.3*(1+math.sqrt(math.pow(x-j, 2) + math.pow(y-i, 2))))
is much, much, much faster than
grid[j][i] += (1./1.3)*harmonic_mask[x - j + grid_w][y - i + grid_h]
... Why?

(Consider tested: With the proper harmonic_mask, this math is correct. It is just much slower. The example mask is NOT an harmonic mask)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Getting an error while trying to process data, low memory when memory is not low? bkeith12 0 510 Dec-20-2024, 03:06 PM
Last Post: bkeith12
  sharepoint: Access has been blocked by Conditional Access policies CAD79 0 2,144 Jul-12-2024, 09:36 AM
Last Post: CAD79
  Script problem - Illegal access to removed OSM object MarcPolo72 0 926 Jun-23-2024, 04:26 PM
Last Post: MarcPolo72
  Memory assignation problem (maybe?) Erasmus 3 3,426 Sep-20-2018, 04:45 PM
Last Post: Erasmus
  Need tutorial/direction to access shared memory ridshack 2 3,636 Feb-22-2018, 11:24 PM
Last Post: ridshack
  Creating a program that records speed in a speed trap astonavfc 7 8,880 Nov-07-2016, 06:50 PM
Last Post: nilamo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020