Skip to content

Commit

Permalink
add missing fill() abstract method to StorageBase (#1119)
Browse files Browse the repository at this point in the history
  • Loading branch information
slayoo authored Aug 19, 2023
1 parent 31428dc commit 679b6b8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
4 changes: 4 additions & 0 deletions PySDM/backends/impl_common/storage_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ def urand(self, generator):
def upload(self, data):
raise NotImplementedError()

@abstractmethod
def fill(self, other):
raise NotImplementedError()


def get_data_from_ndarray(array, storage_class: Type[StorageBase], copy_fun):
if str(array.dtype).startswith("int"):
Expand Down
14 changes: 7 additions & 7 deletions PySDM/backends/impl_thrust_rtc/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -497,14 +497,14 @@ def divide_if_not_zero(self, divisor):
Impl.divide_if_not_zero(self, divisor)
return self

def fill(self, value):
if isinstance(value, Storage):
trtc.Copy(value.data, self.data)
def fill(self, other):
if isinstance(other, Storage):
trtc.Copy(other.data, self.data)
else:
if isinstance(value, int):
dvalue = trtc.DVInt64(value)
elif isinstance(value, float):
dvalue = BACKEND._get_floating_point(value)
if isinstance(other, int):
dvalue = trtc.DVInt64(other)
elif isinstance(other, float):
dvalue = BACKEND._get_floating_point(other)
else:
raise TypeError("Only Storage, int and float are supported.")
trtc.Fill(self.data, dvalue)
Expand Down

0 comments on commit 679b6b8

Please sign in to comment.