Skip to content

[Primitives] Fix slice primitives#1139

Open
leonardt wants to merge 5 commits into
masterfrom
fix-1135
Open

[Primitives] Fix slice primitives#1139
leonardt wants to merge 5 commits into
masterfrom
fix-1135

Conversation

@leonardt
Copy link
Copy Markdown
Collaborator

  • Promote int-like values in get_slice/set_slice
  • Update doc to refer to set_index instead of set_bit
  • Support set_slice of length 1 for constant values

* Promote int-like values in get_slice/set_slice
* Update doc to refer to set_index instead of set_bit
* Support set_slice of length 1 for constant values
@leonardt leonardt requested a review from rsetaluri September 14, 2022 22:40
Comment thread magma/primitives/slice.py Outdated
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Sep 14, 2022

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 92.85714% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 85.03%. Comparing base (42b8850) to head (4edeeae).
⚠️ Report is 265 commits behind head on master.

Files with missing lines Patch % Lines
magma/primitives/slice.py 92.85% 1 Missing ⚠️
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1139      +/-   ##
==========================================
+ Coverage   85.00%   85.03%   +0.02%     
==========================================
  Files         154      154              
  Lines       16368    16375       +7     
==========================================
+ Hits        13914    13924      +10     
+ Misses       2454     2451       -3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@rsetaluri rsetaluri changed the title Fix slice primitives [Primitives] Fix slice primitives Sep 15, 2022
Comment thread docs/primitives.md


### set_bit
### set_index
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I would be in favor of renaming the function (publicly, i.e. in the docs) to set_bit. We could deprecate set_index for now with warning (doubt anyone is using it anyway...)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

It was changed to set_index because the pattern is more general than just set_bit (i.e. you can use it on generic arrays, rather than just on Bits), so I think it makes more sense to keep it as set_index for generality

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I see. In that case, why do we need a separate function? I.e. why is it not covered by set slice with width 1?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Simpler to use when you know you're only interested in one index. For the same reasons in Python we have x[1] versus having to do x[1:2].

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Makes sense -- but I would argue x[1] and x[1:2] is the same interface with different arguments (in fact it literally is the function __getitem__).

Maybe we don't need to do this in this change, but seems reasonable to refactor to have the following interface:

"""
* target: Array[N, T]
* value: Union[Array[M, T], T]
* start: UInt[W]

where M < N and W <= clog2(N)
"""
def set(target: Array, value: Union[Type, Array], start: UInt):
    ...

Now that I think about it there are few new concerns here:

  • Should this function work with all Arrays and not just Bits? I kind of assumed it did, but looking at the code closer I'm not certain.
  • Do we need a width argument? Can it just be inferred from value? If value is an array of the same dimensionality as target then it is a slice set; else if it is of dimensionality one less than value then it is an index set (of course assuming the contained types match up and all).
  • In the case start being a constant value, should we optimize for the simple wiring (non-dynamic mux) case?

@rsetaluri
Copy link
Copy Markdown
Collaborator

Moving this conversation here:

I'm not sure if set_slice of length makes sense unless the start value is a constant 0. Otherwise, the smallest start value we could have is a Bit which could take on value 1 or 0. A start index of 1 would be invalid for setting a slice on length 1.

I think my note was unclear. I meant the case when width is 1, i.e. value is of length 1 -- not target being length 1. This seems like it should be uniform with any other width value. Right now it seems to be broken.

@leonardt leonardt requested a review from rsetaluri September 15, 2022 18:24
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