Skip to content

Commit

Permalink
Data loading and saving in different sparse and dense format.
Browse files Browse the repository at this point in the history
  • Loading branch information
rcamino committed Jul 9, 2018
1 parent 3be3572 commit 7c25f31
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions multi_categorical_gans/datasets/formats.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import numpy as np

from scipy.sparse import load_npz, save_npz


def load_dense(features_path, transform=True):
features = np.load(features_path)
if transform:
features = features.astype(np.float32)
return features


def load_sparse(features_path, transform=True):
features = load_npz(features_path)
if transform:
features = np.asarray(features.todense()).astype(np.float32)
return features


def save_dense(features_path, features):
np.save(features_path, features)


def save_sparse(features_path, features):
save_npz(features_path, features)


loaders = {
"dense": load_dense,
"sparse": load_sparse,
}

savers = {
"dense": save_dense,
"sparse": save_sparse,
}

data_formats = loaders.keys()

0 comments on commit 7c25f31

Please sign in to comment.