Skip to content
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

Ease of use improvements #38

Merged
merged 8 commits into from
Nov 17, 2022
Merged

Ease of use improvements #38

merged 8 commits into from
Nov 17, 2022

Conversation

TomHogervorst
Copy link
Contributor

Ease-of-use improvements based on user feedback.
PR also contains several fixes for bug encountered while implementing these improvements.

Also made that method work with parameter names instead of only parameter identifiers
The check should be performed on all traces that are added, and it should always be done
…modification

This allows for constructions like `new Trace(SampleCoding.FLOAT, [0] * sample_count, TraceParameterMap().add('input', bytes.fromhex('0102030405060708')))`
Issues were: incorrect comparison between ndarrays and lists, no support for multi-dimensional arrays, and no detection of empty ndarrays.
@TomHogervorst TomHogervorst force-pushed the ease-of-use-improvements branch 3 times, most recently from 1157e50 to 6da200f Compare November 8, 2022 13:46
More explicitly set types of ndarray input values

def insert(self, name: str, type: ParameterType, size: int, offset: int):
"""Insert a trace parameter definition into this map in a specified location. If the given offset would put the
new TraceParameter in the middle of a parameter already present in the map, the offset is increased to put add

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Either put or add is redundant here

def insert_std(self, name: str, size: int, offset: int):
"""Insert a trace parameter definition of a StandardTraceParameter into this map in a specified location. If
the given offset would put the new TraceParameter in the middle of a parameter already present in the map, the
offset is increased to put add the new parameter after that existing one instead. Any parameters already present

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Either put or add is redundant here

type = StandardTraceParameters.from_identifier(name).parameter_type
self.insert(name, type, size, offset)
except ValueError:
raise ValueError(f"No StandardTraceParameter found with name '{name}'. Either specify a type in this "

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Specifying a type is not possible in this method, right? Maybe you could reference the non-standard one instead?

type = StandardTraceParameters.from_identifier(name).parameter_type
self.append(name, type, size)
except ValueError:
raise ValueError(f"No StandardTraceParameter found with name '{name}'. Either specify a type in this "

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment applies here; shouldn't you reference append in this error message instead?


:param name: The name of the TraceParameter for which to add a definition. This name must match that of a
StandardTraceParameter
:param size: The size of the TraceParameter, in number of values of its type

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think number of values of its type is a confusing way to describe this parameter. It suggests to me that the type can have a number of values. How about simply number of elements instead?

Make sure to update this for the other occurrences, too

"""Test whether this RawTraceData could be interpreted by given definitions

:param definitions: The trace parameter definition map of the trs file to which the trace with this trace
raw trace data will be added

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This sentence is not what you think it is :P

return isinstance(other, type(self)) and self.value == other.value
if not isinstance(other, type(self)):
return False
if (type(self.value) == list or type(self.value) == ndarray) and \

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These lines are a bit confusing. Can you think of a way to make them more readable?

@TomHogervorst TomHogervorst merged commit 4f6fa8d into master Nov 17, 2022
@TomHogervorst TomHogervorst deleted the ease-of-use-improvements branch November 17, 2022 09:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants