forked from AnonymousWu/Tensor_completion
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a9d56bb
commit 316cd76
Showing
2 changed files
with
24 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,23 @@ | ||
import gzip | ||
def read_frosst(file_name): | ||
with gzip.open(file_name + '.tns.gz', 'rb') as f_in: | ||
with open(file_name + '.tns', 'w') as f_out: | ||
file_content = f_in.read().split('\n') | ||
print(len(file_content)) | ||
for entry in file_content[:-1]: | ||
i,j,k,v = entry.split(' ') | ||
f_out.write('{} {} {} {}\n'.format(int(i)-1, int(j)-1, int(k)-1, v)) | ||
|
||
read_frosst('nell-2') | ||
import shutil | ||
import ctf | ||
|
||
modify = False | ||
|
||
def read_from_frostt(file_name, I, J, K): | ||
|
||
unzipped_file_name = file_name + '.tns' | ||
|
||
with gzip.open(file_name + '.tns.gz', 'r') as f_in: | ||
with open(unzipped_file_name, 'w') as f_out: | ||
shutil.copyfileobj(f_in, f_out) | ||
|
||
T_start = ctf.tensor((I+1, J+1, K+1), sp=True) | ||
T_start.read_from_file(unzipped_file_name) | ||
T = ctf.tensor((I,J,K), sp=True) | ||
T[:,:,:] = T_start[1:,1:,1:] | ||
|
||
if modify: | ||
T.write_to_file(unzipped_file_name) | ||
|
||
return T |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import ctf | ||
T = ctf.tensor((12092,9184,28818), sp=True) | ||
T.read_from_file('nell-2.tns') | ||
import reader | ||
T = reader.read_from_frostt('nell-2', 12092, 9184, 28818) | ||
assert(T[0,182,606] == 1.0) |