torch-dftd icon indicating copy to clipboard operation
torch-dftd copied to clipboard

use `get_cell().array`

Open PythonFZ opened this issue 1 year ago • 4 comments

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

PythonFZ avatar Nov 21 '23 10:11 PythonFZ

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

corochann avatar Dec 07 '23 10:12 corochann

I commented on issue #16

corochann avatar Dec 08 '23 02:12 corochann

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.

PythonFZ avatar Dec 08 '23 09:12 PythonFZ

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.

corochann avatar Dec 08 '23 10:12 corochann