-
Notifications
You must be signed in to change notification settings - Fork 8
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
set_subparts!
behavior
#53
Comments
Adding the method using ACSets
SchAttrs2 = BasicSchema([:X,:Y], [], [:Attr], [(:attr1,:X,:Attr),(:attr2,:X,:Attr),(:attr3,:Y,:Attr),(:attr4,:Y,:Attr)])
@acset_type DataAttrs2(SchAttrs2)
mydata = @acset DataAttrs2{Int} begin
X=3
Y=2
end
attr1=[1,2,3]
attr2=[4,5,6]
attr3=[7,8]
attr4=[9,10]
set_subparts!(
mydata,
attr1=attr1, attr2=attr2, attr3=attr3, attr4=attr4
) |
I think that this api makes sense to me. Although is there a readability problem with omitting the You would check the arguments for length and then dispatch to putting the colon in. I guess that makes sense to me. Any objection from @epatters or @olynch? |
There's no problem, I was just curious about the apparent inconsistency of allowing a user to omit the |
This came up again with a new user, so want to ask @epatters, should |
Well, I guess it is fine to allow setting subparts for multiple tables in the same operation when the row index is omitted. So in you example: using ACSets
SchAttrs2 = BasicSchema([:X,:Y], [], [:Attr], [(:attr1,:X,:Attr),(:attr2,:X,:Attr),(:attr3,:Y,:Attr),(:attr4,:Y,:Attr)])
@acset_type DataAttrs2(SchAttrs2)
mydata = @acset DataAttrs2{Int} begin
X=3
Y=2
end
attr1=[1,2,3]
attr2=[4,5,6]
attr3=[7,8]
attr4=[9,10]
# this should work because you are referring to all the rows in the table
# and the order of the rows needs to match the order of the columns you are setting.
set_subparts!(
mydata,
attr1=attr1, attr2=attr2, attr3=attr3, attr4=attr4
)
# this should NOT work because the entries of the list [1,3] are referring to specific rows of the X
# table (for `attr{1,2}`) or specific rows of the Y table (for `attr{3,4}`).
# And we will only introduce errors if people luck into getting the
# correct results sometimes when the rows happen to be the same.
set_subparts!(
mydata, [1,3]
attr1=attr1[1:2], attr2=attr2[1:2], attr3=attr3[1:2], attr4=attr4[1:2]
)
|
sounds good, thanks @jpfairbanks! |
The methods for
set_subpart!
allow a user ignore theparts
argument when it's assumed that the vectorvals
is the same as the number of parts ofname
, in this case it dispatches to the method where::Colon
is the 2nd argument.set_subparts!
does not seem to have this behavior, see ex below. Is this intended? If not, I'd be happy to get a simple PR to implement it (and also tests forset_subparts!
).The text was updated successfully, but these errors were encountered: