Commit 26fee0d8 authored by Job Cuppen's avatar Job Cuppen

added answers for drop shift1 rotate1 and tile

parent 522b4975
......@@ -172,6 +172,23 @@ compilation failed while Running type inference system, 1 error(s).
this is because `reshape([1,1], [1])` and `reshape([1], [1])` do not have the same dimensionality.
## Exercise 7
### a)
### a) drop
`take(-(shape(vec) - sv), vec)`
### b) tile
`take(sv, take(-(shape(vec) - ov), vec))`
### c) shift 1
`genarray(ov, expr) ++ take(shape(vec) - ov;, vec)`
### d) shift 2
???
### e) rotate 1
`take(-ov, vec) ++ take((shape(vec) - ov), vec)`
### f) rotate 2
???
......@@ -4,22 +4,68 @@ use Array: all;
int main()
{
vec = [1,2,3,4,5,6];
sv = [1];
sv = [2,2];
ov = [2];
// vec = reshape([3,2], vec);
//a
printf("Drop as Take\n");
// printf("Drop as Take\n");
// print(shape(vec));
// print(shape(vec) - sv);
d = drop(sv, vec); // [3,4,5,6,7]
t = take(-(shape(vec) - sv), vec); // [1,2]
// d = drop(sv, vec);
// td = take(-(shape(vec) - sv), vec);
print(d);
print(t);
// print(d);
// print(td);
//b
// printf("Tile as Take\n");
return 0;
}
// t = tile(sv, ov, vec);
// ttd = take(sv, drop(ov, vec));
// tt = take(sv, take(-(shape(vec) - ov), vec));
// print(t);
// print(ttd);
// print(tt);
//c
// printf("Shift 1 as Take\n");
// expr = -1;
// s = shift(ov, expr, vec);
// st = genarray(ov, expr) ++ take(shape(vec) - ov;, vec);
// print(s);
// print(st);
//d
// printf("Shift 2 as Take\n");
// expr = -1;
// s = shift(ov, expr, vec);
// st = genarray(ov, expr) ++ take(sh, vec);
// [3,2] - [2] = [1]
\ No newline at end of file
// print(s);
// print(st);
//e
// printf("Rotate 1 as Take\n");
// r1 = rotate(ov, vec);
// r1t = take(-ov, vec) ++ take((shape(vec) - ov), vec);
// print(r1);
// print(r1t);
//f
// printf("Rotate 2 as Take\n");
// r2 = rotate(ov, vec);
// print(r2);
// print(r2t);
return 0;
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment