Skip to content

Commit

Permalink
Add save/load for ctf/ctfview by converting to numpy
Browse files Browse the repository at this point in the history
  • Loading branch information
yuchenpang committed Apr 18, 2020
1 parent 7447edd commit 6fd9e74
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
7 changes: 7 additions & 0 deletions tensorbackends/backends/ctf/ctf_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,13 @@ def ndim(self, a):
def copy(self, a):
return a.copy()

def save(self, tsr, filename):
with open(filename, 'w+b') as file:
np.save(file, tsr.numpy(), allow_pickle=False)

def load(self, filename):
return self.astensor(np.load(filename))

def einsum(self, subscripts, *operands):
if not all(isinstance(operand, self.tensor) for operand in operands):
raise TypeError('all operands should be {}'.format(self.tensor.__qualname__))
Expand Down
7 changes: 7 additions & 0 deletions tensorbackends/backends/ctfview/ctfview_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,13 @@ def ndim(self, a):
def copy(self, a):
return a.copy()

def save(self, tsr, filename):
with open(filename, 'w+b') as file:
np.save(file, tsr.numpy(), allow_pickle=False)

def load(self, filename):
return self.astensor(np.load(filename))

def reshape(self, a, newshape):
return a.reshape(*newshape)

Expand Down

0 comments on commit 6fd9e74

Please sign in to comment.