Skip to content

Commit

Permalink
reshape changes
Browse files Browse the repository at this point in the history
  • Loading branch information
dragazo committed Oct 19, 2023
1 parent c75333c commit 8fb4dff
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 9 deletions.
8 changes: 2 additions & 6 deletions src/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1379,13 +1379,9 @@ mod ops {
Ok(res)
}
pub(super) fn reshape<'gc, C: CustomTypes<S>, S: System<C>>(mc: &Mutation<'gc>, src: &Value<'gc, C, S>, dims: &[usize]) -> Result<Value<'gc, C, S>, ErrorCause<C, S>> {
if dims.iter().any(|&x| x == 0) {
return Ok(Gc::new(mc, RefLock::new(VecDeque::default())).into())
}

let mut src = ops::flatten(src)?;
let src = ops::flatten(src)?;
if src.is_empty() {
src.push_back(empty_string().into());
return Err(ErrorCause::EmptyList);
}

fn reshape_impl<'gc, C: CustomTypes<S>, S: System<C>>(mc: &Mutation<'gc>, src: &mut Cycle<VecDequeIter<Value<'gc, C, S>>>, dims: &[usize]) -> Value<'gc, C, S> {
Expand Down
2 changes: 1 addition & 1 deletion src/test/blocks/list-reshape.xml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<blocks><block-definition s="main" type="reporter" category="custom"><header></header><code></code><translations></translations><inputs></inputs><script><block s="doDeclareVariables"><list><l>res</l><l>src</l><l>temp</l></list></block><block s="doSetVar"><l>res</l><block s="reportNewList"><list></list></block></block><block s="doSetVar"><l>temp</l><block s="reportNewList"><list><l>h</l><l>e</l><block s="reportNewList"><list><l>l</l><block s="reportNewList"><list><block s="reportNewList"><list><l>l</l></list></block></list></block></list></block></list></block></block><block s="doSetVar"><l>src</l><block s="reportNewList"><list><l>3</l><l>1</l><block s="reportNewList"><list><block var="temp"/><l>1</l><block var="temp"/><block s="reportNewList"><list></list></block></list></block><block s="reportNewList"><list></list></block><l>gh</l></list></block></block><block s="doAddToList"><block s="reportReshape"><block var="src"/><list><l>10</l></list></block><block var="res"/></block><block s="doAddToList"><block s="reportReshape"><block var="src"/><list><l>2</l><l>5</l></list></block><block var="res"/></block><block s="doAddToList"><block s="reportReshape"><block var="src"/><list><l>2</l><l>5</l><l>3</l></list></block><block var="res"/></block><block s="doAddToList"><block s="reportReshape"><block var="src"/><block s="reportNewList"><list><l>5</l><l>1</l><l>5</l></list></block></block><block var="res"/></block><block s="doAddToList"><block s="reportReshape"><block var="src"/><block s="reportNewList"><list><l>4</l><l>0</l><l>2</l></list></block></block><block var="res"/></block><block s="doAddToList"><block s="reportReshape"><block var="src"/><block s="reportNewList"><list></list></block></block><block var="res"/></block><block s="doAddToList"><block s="reportReshape"><block var="src"/><list></list></block><block var="res"/></block><block s="doAddToList"><block s="reportReshape"><block s="reportVariadicSum"><list><l>5</l><l>1</l></list></block><list><l>2</l><l>3</l></list></block><block var="res"/></block><block s="doAddToList"><block s="reportReshape"><block s="reportNewList"><list></list></block><list><l>2</l><l>2</l></list></block><block var="res"/></block><block s="doReport"><block var="res"/></block></script></block-definition></blocks>
<blocks app="NetsBlox 2.1.4, http://netsblox.org" version="2.1.4"><block-definition collabId="item_-1_116" s="main" type="reporter" category="custom"><header></header><code></code><translations></translations><inputs></inputs><script><block collabId="item_-1_110" s="doDeclareVariables"><list><l>res</l><l>src</l><l>temp</l></list></block><block collabId="item_-1_105" s="doSetVar"><l>res</l><block collabId="item_-1_103" s="reportNewList"><list></list></block></block><block collabId="item_-1_101" s="doSetVar"><l>temp</l><block collabId="item_-1_99" s="reportNewList"><list><l>h</l><l>e</l><block collabId="item_-1_95" s="reportNewList"><list><l>l</l><block collabId="item_-1_92" s="reportNewList"><list><block collabId="item_-1_90" s="reportNewList"><list><l>l</l></list></block></list></block></list></block></list></block></block><block collabId="item_-1_87" s="doSetVar"><l>src</l><block collabId="item_-1_85" s="reportNewList"><list><l>3</l><l>1</l><block collabId="item_-1_81" s="reportNewList"><list><block collabId="item_-1_79" var="temp"/><l>1</l><block collabId="item_-1_77" var="temp"/><block collabId="item_-1_76" s="reportNewList"><list></list></block></list></block><block collabId="item_-1_74" s="reportNewList"><list></list></block><l>gh</l></list></block></block><block collabId="item_-1_71" s="doAddToList"><block collabId="item_-1_70" s="reportReshape"><block collabId="item_-1_69" var="src"/><list><l>10</l></list></block><block collabId="item_-1_66" var="res"/></block><block collabId="item_-1_65" s="doAddToList"><block collabId="item_-1_64" s="reportReshape"><block collabId="item_-1_63" var="src"/><list><l>2</l><l>5</l></list></block><block collabId="item_-1_59" var="res"/></block><block collabId="item_-1_58" s="doAddToList"><block collabId="item_-1_57" s="reportReshape"><block collabId="item_-1_56" var="src"/><list><l>2</l><l>5</l><l>3</l></list></block><block collabId="item_-1_51" var="res"/></block><block collabId="item_-1_50" s="doAddToList"><block collabId="item_-1_49" s="reportReshape"><block collabId="item_-1_48" var="src"/><block collabId="item_-1_47" s="reportNewList"><list><l>5</l><l>1</l><l>5</l></list></block></block><block collabId="item_-1_42" var="res"/></block><block collabId="item_-1_41" s="doAddToList"><block collabId="item_-1_40" s="reportReshape"><block collabId="item_-1_39" var="src"/><block collabId="item_-1_38" s="reportNewList"><list><l>4</l><l>0</l><l>2</l></list></block></block><block collabId="item_-1_33" var="res"/></block><block collabId="item_-1_32" s="doAddToList"><block collabId="item_-1_31" s="reportReshape"><block collabId="item_-1_30" var="src"/><block collabId="item_-1_29" s="reportNewList"><list></list></block></block><block collabId="item_-1_27" var="res"/></block><block collabId="item_-1_26" s="doAddToList"><block collabId="item_-1_25" s="reportReshape"><block collabId="item_-1_24" var="src"/><list></list></block><block collabId="item_-1_22" var="res"/></block><block collabId="item_-1_21" s="doAddToList"><block collabId="item_-1_20" s="reportReshape"><block collabId="item_-1_19" s="reportVariadicSum"><list><l>5</l><l>1</l></list></block><list><l>2</l><l>3</l></list></block><block collabId="item_-1_12" var="res"/></block><block collabId="item_3" s="doTryCatch"><script><block collabId="item_-1_11" s="doAddToList"><block collabId="item_-1_10" s="reportReshape"><block collabId="item_-1_9" s="reportNewList"><list></list></block><list><l>2</l><l>2</l></list></block><block collabId="item_-1_4" var="res"/></block></script><l>err</l><script><block collabId="item_17" s="doAddToList"><block collabId="item_30" var="err"/><block collabId="item_29" var="res"/></block></script></block><block collabId="item_35" s="doTryCatch"><script><block collabId="item_35_1" s="doAddToList"><block collabId="item_35_5" s="reportReshape"><block collabId="item_35_7" s="reportNewList"><list></list></block><list></list></block><block collabId="item_35_6" var="res"/></block></script><l>err</l><script><block collabId="item_35_2" s="doAddToList"><block collabId="item_35_3" var="err"/><block collabId="item_35_4" var="res"/></block></script></block><block collabId="item_-1_3" s="doReport"><block collabId="item_-1_2" var="res"/></block></script></block-definition></blocks>
5 changes: 3 additions & 2 deletions src/test/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1561,11 +1561,12 @@ fn test_proc_list_reshape() {
[["e", "l", "l", "1", "h"]],
[["e", "l", "l", "gh", "3"]],
],
[],
[[], [], [], []],
"3",
"3",
[[6, 6, 6], [6, 6, 6]],
[["", ""], ["", ""]],
"EmptyList",
"EmptyList",
])).unwrap();
assert_values_eq(&res.unwrap().0.unwrap(), &expect, 1e-5, "list reshape");
});
Expand Down

0 comments on commit 8fb4dff

Please sign in to comment.