torch-dftd
torch-dftd copied to clipboard
use `get_cell().array`
To fix the following error
UserWarning: Creating a tensor from a list of numpy.ndarrays is extremely slow. Please consider converting the list to a single numpy.ndarray with numpy.array() before converting to a tensor. (Triggered internally at ../torch/csrc/utils/tensor_new.cpp:261.)
One can access the get_cell().array
attribute instead to get a np.ndarray
instead of list[np.ndarray]
potential fix for #16
Thank you for the PR!
Let me check my understanding. get_cell()
always returns Cell
class, and it is safe to assume that we can always access .array
attribute to get 3x3 np.ndarray?
https://wiki.fysik.dtu.dk/ase/_modules/ase/atoms.html#Atoms.get_cell
I commented on issue #16
From my understanding from https://wiki.fysik.dtu.dk/ase/_modules/ase/cell.html#Cell the conversion to numpy just does:
def __array__(self, dtype=float):
if dtype != float:
raise ValueError('Cannot convert cell to array of type {}'
.format(dtype))
return self.array
such that using .array
should not be an issue. It's a strange error in the first place tbh.
If get_cell()
always returns Cell
it's ok, but I want to confirm get_cell()
does not return numpy array or any other types? If such a case exists, .array
is not accessible.