add space_idx_formatter and einsum_str_formatter#3
add space_idx_formatter and einsum_str_formatter#3yangjunjie0320 wants to merge 7 commits intoawhite862:masterfrom
space_idx_formatter and einsum_str_formatter#3Conversation
awhite862
left a comment
There was a problem hiding this comment.
Thanks for making these additions! I'm happy to accept the changes if these comments (just minor code style stuff) are addressed.
| PYTHON_FILE_TAB = " " | ||
|
|
||
|
|
||
| def space_idx_formatter(name, space_list): |
There was a problem hiding this comment.
I think this function can be done in one line, something like: return name + str([space + "_idx" for space in space_list])
| function_str += PYTHON_FILE_TAB + "t2 = t2oovv.transpose(2, 3, 0, 1)\n\n" | ||
|
|
||
| einsum_str = final._print_einsum(return_str, exprs_with_space=[H], | ||
| space_idx_formatter=space_idx_formatter, einsum_str_formatter=einsum_str_formatter) |
| space_idx_formatter=space_idx_formatter, einsum_str_formatter=einsum_str_formatter) | ||
| einsum_str = einsum_str.split("\n") | ||
|
|
||
| for i, line in enumerate(einsum_str): |
There was a problem hiding this comment.
I think the index is unnecessary, you can just do for line in einsum_str:
| return out | ||
|
|
||
| def _einsum_str(self): | ||
| def _einsum_str(self, exprs_with_space = None, names_with_space = None, space_idx_formatter = None, einsum_str_formatter = None): |
There was a problem hiding this comment.
Line is too long, there shouldn't be spaces around the = signs in the function definition.
|
|
||
| if einsum_str_formatter is not None: | ||
| return einsum_str_formatter(sstr, istr, fstr, tstr) | ||
| else: |
There was a problem hiding this comment.
This else is unnecessary, you can just have an unintended return after the the if statement
| return out[:-1] | ||
|
|
||
| def _print_einsum(self, lhs=None): | ||
| def _print_einsum(self, lhs=None, exprs_with_space = None, names_with_space = None, space_idx_formatter = None, einsum_str_formatter = None): |
There was a problem hiding this comment.
The line is too long and there shouldn't be spaces around the = in the function definition
| for t in self.terms[:-1]: | ||
| out += X + " += " + t._einsum_str() + "\n" | ||
| out += X + " += " + t._einsum_str( | ||
| exprs_with_space = exprs_with_space, |
There was a problem hiding this comment.
The extra spaces used to align the = here are unnecessary
No description provided.