New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PR: Remove "colour.io.luts.common.parse_array" definition usage. #596
PR: Remove "colour.io.luts.common.parse_array" definition usage. #596
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @njwardhan!
I left a few comments!
colour/io/luts/cinespace_csp.py
Outdated
pre_LUT = [parse_array(lines[i]) for i in [1, 2, 4, 5, 7, 8]] | ||
pre_LUT = [] | ||
for i in [1, 2, 4, 5, 7, 8]: | ||
tokens = lines[i].split() | ||
pre_LUT.append(as_float_array(tokens)) | ||
pre_LUT_padded = [] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should really be something like that:
pre_LUT = as_float_array([lines[i] for i in [1, 2, 4, 5, 7, 8]])
No need to unroll the list comprehension into a loop, unless it is causing issues.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@KelSolaar, the intention was indeed to keep the code simple and clean. However, the as_float_array
has its limitation in doing the direct conversion of a string of numbers to an array of specified type (unlike the parse_array
function, which could do it directly). That's why I've used it the way I have. (Obviously instead of changing the actual definition of the as_float_array
function).
I am attaching a quick link to a short .ipynb file that should clear my point.
Looking forward to your feedback and suggestions :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, you should be able to do that though:
pre_LUT = [as_float_array(lines[i].split()) for i in [1, 2, 4, 5, 7, 8]]
You cannot convert the entire pre_LUT because it is not necessarily uniform though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it @KelSolaar , will update the change. Thankyou!
colour/io/luts/cinespace_csp.py
Outdated
size = parse_array(lines[0]).astype(int) | ||
table = np.array([parse_array(line) for line in lines[1:]]) | ||
size = [] | ||
for i in lines[0].split(): | ||
size.append(i) | ||
size = as_int_array(size) | ||
|
||
table = [] | ||
for line in lines[1:]: | ||
tokens = line.split() | ||
table.append(tokens) | ||
table = as_float_array(table) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Likewise here, same as previously.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
E.g.
size = as_int_array(lines[0].split())
table = as_float_array([line.split() for line in lines[1:]])
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it, Thankyou!
colour/io/luts/common.py
Outdated
LUT Processing Common Utilities | ||
=============================== | ||
|
||
Defines LUT Processing common utilities objects that don't fall in any specific | ||
A Common Utility for LUT Processing | ||
==================================== | ||
Defines a LUT Processing common utility object that doesn't fall in any specific | ||
category. | ||
""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There might be more utilities here as you go-on, let's keep it plural for now if you don't mind please! :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok sure haha, I didn't think that way. Will make that change! Thankyou!
colour/io/luts/common.py
Outdated
|
||
Parameters | ||
---------- | ||
path : unicode | ||
File path to convert to title. | ||
|
||
Returns | ||
------- | ||
unicode | ||
File path converted to title. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Careful with the missing break lines!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Noted
colour/io/luts/common.py
Outdated
@@ -83,4 +42,4 @@ def path_to_title(path): | |||
u'ColourCorrect' | |||
""" | |||
|
|||
return re.sub('_|-|\\.', ' ', os.path.splitext(os.path.basename(path))[0]) | |||
return re.sub('_|-|\\.', ' ', os.path.splitext(os.path.basename(path))[0]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here, it is missing the end-of-file return.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Noted
colour/io/luts/sony_spi3d.py
Outdated
indexes.append(parse_array(tokens[:3])) | ||
table.append(parse_array(tokens[3:])) | ||
indexes.append(as_float_array(tokens[:3])) | ||
table.append(as_float_array(tokens[3:])) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Careful here! The indexes/indices should be of type int, so you should use as_int_array
:
indexes.append(as_int_array(tokens[:3]))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK missed that, will make the change ASAP!
indexes.append(parse_array(tokens[:3], DEFAULT_INT_DTYPE)) | ||
indexes.append(as_float_array(tokens[:3])) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Careful here also! The indexes/indices should be of type int, so you should use as_int_array
:
indexes.append(as_int_array(tokens[:3]))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Noted
Here is an overview of what got changed by this pull request: Complexity decreasing per file
==============================
+ colour/io/luts/common.py -3
See the complete overview on Codacy |
LGTM! Thanks @njwardhan! |
This change makes colour more optimized with respect to its LUT I/O capabilities, and also address the issue: #573.