We planned to upgrade GitLab and Mattermost to the latest version this Friday morning (early). You may experience some downtime!

Commit 13fc77e1 authored by Job Cuppen's avatar Job Cuppen

initial commit

parents
Pipeline #29276 failed with stages
in 52 seconds
# Created by https://www.gitignore.io/api/macos
# Edit at https://www.gitignore.io/?templates=macos
### macOS ###
# General
.DS_Store
.AppleDouble
.LSOverride
# Icon must end with two \r
Icon
# Thumbnails
._*
# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent
# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk
# End of https://www.gitignore.io/api/macos
\ No newline at end of file
File added
This source diff could not be displayed because it is too large. You can view the blob instead.
# Week 1
## Exercise 1
I suspect that when the condition of matching dimentionalities does not hold the compiler will throw an exception.
## Exercise 3
```c
use StdIO: all;
use Array: all;
int main()
{
print(reshape([5,2,2], genarray([4], [0,0,0,0,1])));
// Explanation:
// 1. generate a vector of size 4
// 2. fill each cell with [0,0,0,0,1]
// 2.1 this results in a 4 x 5 matrix;
// 3. this contains 2 x 2 x 5 = 20 elements, therefor it can be reshaped to 5x2x2
return 0;
}
```
## Exercise 4
I expect the result of
```c
use StdIO: all;
use Array: all;
int main()
{
a = [1,2,3,4];
b = [a,a];
a = modarray(modarray(a, [0], 0), [1], 0);
b = modarray(b, [0], a);
print(b);
return 0;
}
```
to be:
```
Dimension: 2
Shape : < 2, 4>
< 0 0 3 4 >
< 1 2 3 4 >
```
it was:
```
Dimension: 2
Shape : < 2, 4>
| 0 0 3 4 |
| 1 2 3 4 |
```
## Exercise 5
### a)
I expect the outcome of `print(reshape([3,0,5], [])[[]])` to be:
```
Dimension: 3
Shape : < 3, 0, 5>
<>
<>
<>
```
but it was:
```
Dimension: 3
Shape : < 3, 0, 5>
<>
```
### b)
I expect the outcome of `print(reshape([3,0,5], [])[[1]])` to be:
```
Dimension: 2
Shape : < 0, 5>
<>
```
and i was correct.
### c)
I expect the outcome of `print(reshape([3,0,5], [])[[1,0]])` to be:
```
Dimension: 1
Shape : < 5>
| |
```
but it was:
```
error: line 152 in file /Users/job/GitRepositories/Stdlib/src/structures/ArrayBasics.xsac:
error: argument #1 of "_sel_VxA_" should be legal index into argument #2; types found: int[3]{1,0...} and int[3,0,5]{}
compilation failed while Running SAC optimizations.
```
### d)
I expect the outcome of `print(mat[reshape([2,0], [])])` to be:
```
Dimension: 2
Shape : < 3, 4>
| 1 2 3 4|
| 5 6 7 8|
| 9 10 11 12|
```
but it was:
```
error: No matching definition found for the application of "Array::sel" to arguments ( int[.,.], int[.,.])
compilation failed while Running type inference system, 1 error(s).
```
This is due to the fact that the dimensionality of `reshape([2,0], [])` is 2 while sel requires it to be 1.
## Exercise 6
### a)
I expect the outcome of `print(min(reshape([3,0,5], []), 42))` to be:
```
error
```
but it (seemingly) is:
```
Dimension: 3
Shape : < 3, 0, 5>
<>
```
this is likely due to the fact that an empty matrix is a zero-like/zero-ish value.
### b)
I expect the outcome of `print(reshape([3,0,5], []) + reshape([3,0,5], []))` to be:
```
Dimension: 3
Shape : <3 ,0, 5>
<>
```
and this is true.
### c)
I expect the outcome of `print(reshape([1,1], [1]) + reshape([1], [1]))` to be:
```
Dimension: 2
Shape : <1 ,1>
| 2 |
```
but is was:
```
error: line 148 in file /Users/job/GitRepositories/Stdlib/src/structures/ArrayArith.xsac:
error: Shape of argument #1 of "_sel_VxA_" should match dimensionality of argument #2; types found: int[1] and int[1,1]
error: line 12 in file ./ex6.sac:
error: -- in Array::+( int[1,1]{1}, int[1]{1})
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)
use StdIO: all;
use Array: all;
int main()
{
print(reshape([5,2,2], genarray([2,2], [0,0,0,0,1])));
// Explanation:
// 1. generate a 2 x 2 matrix
// 2. fill each cell with [0,0,0,0,1]
// 3. this contains 2 x 2 x 5 = 20 elements, therefor it can be reshaped to 5x2x2
return 0;
}
\ No newline at end of file
use StdIO: all;
use Array: all;
int main()
{
a = [1,2,3,4];
b = [a,a];
a = modarray(modarray(a, [0], 0), [1], 0);
b = modarray(b, [0], a);
print(b);
return 0;
}
\ No newline at end of file
use StdIO: all;
use Array: all;
int main()
{
// print(reshape([3,0,5], [])[[]]);
// print(reshape([3,0,5], [])[[1]]);
// print(reshape([3,0,5], [])[[1,0]]);
vect = [1,2,3,4,5,6,7,8,9,10,11,12];
mat = reshape([3,4], vect);
print(mat[reshape([2,0], [])]);
return 0;
}
\ No newline at end of file
use StdIO: all;
use Array: all;
int main()
{
// print(min(reshape([3,0,5], []), 42));
// print(reshape([3,0,5], []) + reshape([3,0,5], []));
// print(reshape([1,1], [1]) + reshape([1], [1]));
return 0;
}
take([-1], [1,2,3,4]) // [4]
drop([1], [1,2,3,4]) // [2,3,4]
\ No newline at end of file
use StdIO: all;
use Array: all;
int main()
{
vec = [1,2,3,4,5,6];
sv = [1];
// vec = reshape([3,2], vec);
//a
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]
print(d);
print(t);
return 0;
}
// [3,2] - [2] = [1]
\ 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