Skip to content

Commit

Permalink
Add in fixes to scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
weiya711 committed Sep 30, 2023
1 parent 5dbbfdc commit 46ce268
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 53 deletions.
51 changes: 0 additions & 51 deletions sam/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -602,54 +602,3 @@ def safeCastPydataTensorToInts(tensor):
# data[i] = int(tensor.data[i])
data[i] = round_sparse(tensor.data[i])
return sparse.COO(tensor.coords, data, tensor.shape)


def parse_taco_format(infilename, outdir, tensorname, format_str):
with open(infilename, 'r') as inf:
level = -1
count = 0
seg = True
level_done = False
for line in inf:
if count == 0:
dim_start = line.find('(') + 1
dim_end = line.find(')')
dims = line[dim_start: dim_end]
dims = dims.split('x')

shapefile = os.path.join(outdir, tensorname + '_shape.txt')
with open(shapefile, 'w+') as shapef:
shapef.write(array_newline_str(dims))
else:
if line.find(':') > -1:
level += 1
seg = True
level_done = False
else:
start = line.find('[') + 1
end = line.find(']')
line = line[start: end]
line = line.split(', ')

if level_done:
# This is a values array
valfile = os.path.join(outdir, tensorname + '_vals.txt')
with open(valfile, 'w+') as valf:
valf.write(array_newline_str(line))
else:
level_format = format_str[level]
if level_format == 's':
if seg:
segfile = os.path.join(outdir, tensorname + str(level) +
'_seg.txt')
with open(segfile, 'w+') as segf:
segf.write(array_newline_str(line))
seg = False
else:
crdfile = os.path.join(outdir, tensorname + str(level) +
'_crd.txt')
with open(crdfile, 'w+') as crdf:
crdf.write(array_newline_str(line))
level_done = True

count += 1
2 changes: 1 addition & 1 deletion scripts/formatting/datastructure_tns.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import argparse
import os
from pathlib import Path
from sam.util import parse_taco_format
from scripts.util.util import parse_taco_format

cwd = os.getcwd()

Expand Down
2 changes: 1 addition & 1 deletion scripts/formatting/generate_suitesparse_formats.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ OTHERBENCHES='["mat_residual", "mat_mattransmul", "mat_vecmul"]'
# THIS FILE MUST BE RUN FROM sam/ location
outdir=${SUITESPARSE_FORMATTED_PATH}
basedir=$(pwd)
textfile=$basedir/scripts/tensor_names/$1
textfile=$basedir/$1

mkdir -p $outdir
cd $outdir
Expand Down

0 comments on commit 46ce268

Please sign in to comment.