-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix glb tiling when not fully unrolled by channel dim
- Loading branch information
1 parent
5307d24
commit 1726746
Showing
3 changed files
with
130 additions
and
4 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 |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import scipy.io | ||
import numpy as np | ||
import sys | ||
import os | ||
|
||
def mat_to_raw(input_name, output_name): | ||
print(f"[mat2raw] Converting {input_name} to {output_name}...") | ||
|
||
mat = scipy.io.loadmat(input_name) | ||
# Assuming there's only one variable of interest and it's not one of the | ||
# automatic variables added by MATLAB ('__version__', '__header__', and '__globals__') | ||
data_keys = [key for key in mat.keys() if not key.startswith('__')] | ||
if len(data_keys) != 1: | ||
raise ValueError(f"The .mat file {input_name} contains none or more than one variable.") | ||
|
||
array = np.array(mat[data_keys[0]], dtype=np.uint16) | ||
# Transpose the array. Reverse the axes. | ||
transposed_array = array.transpose(np.arange(array.ndim)[::-1]) | ||
|
||
transposed_array.byteswap().tofile(output_name) | ||
print(f"[mat2raw] Conversion of {output_name} Complete.") | ||
|
||
def convert_all_mat_files(directory): | ||
for root, dirs, files in os.walk(directory): | ||
for file in files: | ||
if file.endswith(".mat"): | ||
input_path = os.path.join(root, file) | ||
output_path = os.path.join(root, os.path.splitext(file)[0] + ".raw") | ||
mat_to_raw(input_path, output_path) | ||
|
||
if __name__ == "__main__": | ||
if len(sys.argv) != 2: | ||
print("Usage: python mat2raw_batch.py <directory_path>") | ||
sys.exit(1) | ||
|
||
directory = sys.argv[1] | ||
if not os.path.isdir(directory): | ||
print(f"Error: {directory} is not a valid directory.") | ||
sys.exit(1) | ||
|
||
convert_all_mat_files(directory) |
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
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 |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import os | ||
import sys | ||
|
||
def raw_to_txt(raw_file_path, txt_file_path): | ||
try: | ||
# Open the .raw file in binary mode | ||
with open(raw_file_path, 'rb') as raw_file: | ||
# Read the binary data | ||
raw_data = raw_file.read() | ||
|
||
# Open the .txt file in write mode | ||
with open(txt_file_path, 'w') as txt_file: | ||
# Ensure the data length is a multiple of 2 (for 16-bit words) | ||
if len(raw_data) % 2 != 0: | ||
raise ValueError("The .raw file contains incomplete 16-bit words.") | ||
|
||
# Convert the binary data to 16-bit words (2 bytes per word) | ||
word_data = [raw_data[i:i+2] for i in range(0, len(raw_data), 2)] | ||
|
||
# Write 8 words per line, with a space separating each word | ||
for i in range(0, len(word_data), 8): | ||
line_words = word_data[i:i+8] | ||
hex_words = [word.hex() for word in line_words] | ||
txt_file.write(' '.join(hex_words) + '\n') | ||
|
||
print(f"Successfully converted {raw_file_path} to {txt_file_path}") | ||
|
||
except Exception as e: | ||
print(f"An error occurred: {e}") | ||
|
||
if __name__ == "__main__": | ||
# Example usage: | ||
if len(sys.argv) != 3: | ||
print("Usage: python raw_to_txt.py <input.raw> <output.txt>") | ||
else: | ||
raw_file = sys.argv[1] | ||
txt_file = sys.argv[2] | ||
|
||
if not os.path.exists(raw_file): | ||
print(f"Error: The file {raw_file} does not exist.") | ||
else: | ||
raw_to_txt(raw_file, txt_file) |