Very minor thing s/piont_datas/point_datas/g;. The only reason the code doesn't generate an error is because you made this spelling mistake consistently.
What is the last line doing? $hmap->matrix simply returns a reference to the density matrix - on its own it does nothing.
If you spot any bugs in my solutions, it's because I've deliberately left them in as an exercise for the reader! :-)