-
Notifications
You must be signed in to change notification settings - Fork 220
Open
Labels
dslxDSLX (domain specific language) implementation / front-endDSLX (domain specific language) implementation / front-endenhancementNew feature or requestNew feature or request🧦 sox
Description
What's hard to do? (limit 100 words)
Currently one can't cast one DSLX array to another one of compatible size (same element_size*element_depth).
0243: fn array_reshape_test() {
0244: assert_eq(
0245: u32[8]:[0, 1, 2, 3, 4, 5, 6, 8] as u64[4],
~~~~~~~~~~~~~~~~~~~~~^--------------------------------^ TypeInferenceError: uN[64][4] Cannot cast from type `uN[32][8]` to type `uN[64][4]`
Related #725
Current best alternative workaround (limit 100 words)
Have a reshape util function that first convert to bits and then to the target array:
fn array_reshape<OUT_WIDTH: u32, OUT_DEPTH: u32, IN_WIDTH: u32, IN_DEPTH: u32>
(arr: bits[IN_WIDTH][IN_DEPTH]) -> bits[OUT_WIDTH][OUT_DEPTH] {
const_assert!(OUT_WIDTH * OUT_DEPTH == IN_WIDTH * IN_DEPTH);
let in_bits = for (i, in_bits) in u32:0..IN_DEPTH {
bit_slice_update(in_bits, i * IN_WIDTH, arr[i])
}(zero!<bits[IN_WIDTH * IN_DEPTH]>());
let out_arr = for (i, out_arr) in u32:0..OUT_DEPTH {
update(out_arr, i, in_bits[(i * OUT_WIDTH)+:bits[OUT_WIDTH]])
}(zero!<bits[OUT_WIDTH][OUT_DEPTH]>());
out_arr
}
Your view of the "best case XLS enhancement" (limit 100 words)
We could potentially make this easier by adding ToBits trait support for array (see #3383), but I think that instead it would be preferrable to support casting operation when element_size*element_depth doesn't change.
Metadata
Metadata
Assignees
Labels
dslxDSLX (domain specific language) implementation / front-endDSLX (domain specific language) implementation / front-endenhancementNew feature or requestNew feature or request🧦 sox
Type
Projects
Status
No status