Skip to content

Commit 84210b0

Browse files
committed
Merge master
1 parent 1f77cc2 commit 84210b0

File tree

89 files changed

+1440
-781
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

89 files changed

+1440
-781
lines changed

.devcontainer/Dockerfile

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ FROM mcr.microsoft.com/vscode/devcontainers/base:0-${VARIANT}
66

77
# [Optional] Uncomment this section to install additional OS packages.
88
RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
9-
&& apt-get -y install --no-install-recommends build-essential software-properties-common xz-utils g++ sbcl julia python3 python3-pip python3-dev ghc openjdk-11-jdk rustc libssl-dev gfortran libxml2-dev libyaml-dev libgmp-dev libz-dev libncurses5 gnuplot nodejs npm lua5.3 ocaml php ruby-full gnu-smalltalk scratch
9+
&& apt-get -y install --no-install-recommends build-essential software-properties-common xz-utils g++ sbcl julia python3 python3-pip python3-dev ghc openjdk-11-jdk rustc libssl-dev gfortran libxml2-dev libyaml-dev libgmp-dev libz-dev libncurses5 gnuplot nodejs npm lua5.3 ocaml php ruby-full gnu-smalltalk scratch libfftw3-dev
1010

1111
# Setup Crystal
1212
RUN echo 'deb http://download.opensuse.org/repositories/devel:/languages:/crystal/xUbuntu_20.04/ /' | sudo tee /etc/apt/sources.list.d/devel:languages:crystal.list
@@ -31,11 +31,10 @@ RUN sudo sh -c 'sudo dpkg -i packages-microsoft-prod.deb'
3131
RUN sudo sh -c 'rm packages-microsoft-prod.deb'
3232

3333
# Setup D Lang
34-
RUN sudo sh -c 'mkdir -p ~/dlang && wget https://dlang.org/install.sh -O ~/dlang/install.sh'
35-
RUN sudo sh -c 'bash ~/dlang/install.sh'
36-
## From Docs not needed though
37-
# RUN sudo sh -c 'source ~/dlang/dmd-2.097.2/activate'
38-
ENV PATH=$PATH:/root/dlang/dmd-2.097.2/linux/bin64
34+
ENV DLANG_VERSION=2.097.2
35+
RUN mkdir -p ~/dlang && wget https://dlang.org/install.sh -O ~/dlang/install.sh
36+
RUN bash ~/dlang/install.sh dmd-$DLANG_VERSION
37+
ENV PATH=$PATH:~/dlang/dmd-$DLANG_VERSION/linux/bin64/
3938

4039
# Setup Go
4140
RUN sudo sh -c 'wget -c https://dl.google.com/go/go1.14.2.linux-amd64.tar.gz -O - | sudo tar -xz -C /usr/local'
@@ -56,36 +55,35 @@ ENV PATH=$PATH:/usr/local/kotlinc/bin
5655
# Setup Matlab
5756
# ?????? This is a licensed language???
5857

59-
# Setup Emojicode (in progress)
60-
RUN sudo sh -c 'wget -c https://github.com/emojicode/emojicode/releases/download/v1.0-beta.2/Emojicode-1.0-beta.2-Linux-x86_64.tar.gz -O /usr/local/Emojicode-1.0-beta.2-Linux-x86_64.tar.gz'
61-
RUN sudo tar -xvzf /usr/local/Emojicode-1.0-beta.2-Linux-x86_64.tar.gz
62-
# && cd ~/emojicode/ && echo && ./install.sh'
63-
ENV PATH=$PATH:/usr/local/Emojicode-1.0-beta.2-Linux-x86_64
58+
# Setup Emojicode
59+
RUN mkdir -p ~/emojicode && wget -c https://github.com/emojicode/emojicode/releases/download/v1.0-beta.2/Emojicode-1.0-beta.2-Linux-x86_64.tar.gz -O ~/emojicode/emojicode.tar.gz && \
60+
tar -xzf ~/emojicode/emojicode.tar.gz -C ~/emojicode --strip-components=1
61+
ENV PATH=$PATH:~/emojicode
6462

65-
# Setup Factor (in progress)
66-
RUN mkdir -p ~/factor && wget https://downloads.factorcode.org/releases/0.98/factor-linux-x86-64-0.98.tar.gz -O ~/factor/factor.tar.gz
67-
RUN tar -xzf /root/factor/factor.tar.gz
68-
# && rm ~/factor/factor.tar.gz
69-
ENV PATH=$PATH:/root/factor/factor
63+
# Setup Factor
64+
RUN mkdir -p ~/factor && wget https://downloads.factorcode.org/releases/0.98/factor-linux-x86-64-0.98.tar.gz -O ~/factor/factor.tar.gz && tar -xzf ~/factor/factor.tar.gz -C ~/factor --strip-components=1
65+
ENV PATH=$PATH:~/factor/factor
7066

7167
# Setup R
7268
RUN sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E298A3A825C0D65DFD57CBB651716619E084DAB9
7369
RUN sudo add-apt-repository 'deb https://cloud.r-project.org/bin/linux/ubuntu focal-cran40/'
7470

75-
# Setup Racket
76-
## Use: https://ubunlog.com/en/racket-install-ubuntu-programming-language
77-
78-
# Setup Scheme
79-
## Use: https://github.com/ashinn/chibi-scheme
71+
# Setup Racket and Scheme
72+
# To run scheme files, use `racket -f <file.ss>`
73+
RUN sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys D9D33FCD84D82C17288BA03B3C9A6980F827E01E
74+
RUN sudo add-apt-repository 'deb http://ppa.launchpad.net/plt/racket/ubuntu focal main'
8075

8176
# Setup Scratch
8277
## using 1.x right now.... in future checkout snap or adobe air?
8378

8479
# Setup Swift
85-
## ?
80+
RUN mkdir -p ~/swift && wget https://swift.org/builds/swift-5.5-release/ubuntu2004/swift-5.5-RELEASE/swift-5.5-RELEASE-ubuntu20.04.tar.gz -O ~/swift/swift.tar.gz && \
81+
tar -xzf ~/swift/swift.tar.gz -C ~/swift --strip-components=1
82+
ENV PATH=$PATH:~/swift/usr/bin
8683

8784
# Setup viml
88-
## ?
85+
# To run vim script commands use `/usr/bin/vim -c ":source %" <path_to_file>`
86+
RUN export DEBIAN_FRONTEND=noninteractive && apt-get -y install --no-install-recommends vim
8987

9088
# Setup whitespace
9189
## ?
@@ -94,13 +92,15 @@ RUN sudo add-apt-repository 'deb https://cloud.r-project.org/bin/linux/ubuntu fo
9492
## https://github.com/elm/compiler/blob/master/installers/linux/README.md
9593

9694
# Setup V
97-
## https://github.com/vlang/v/blob/master/doc/docs.md
98-
95+
RUN mkdir -p ~/vlang && wget https://github.com/vlang/v/releases/download/weekly.2021.44/v_linux.zip -O ~/vlang/vlang.zip && \
96+
unzip ~/vlang/vlang.zip -d ~/vlang
97+
ENV PATH=$PATH:~/vlang/v
9998

10099
# Install the packages that needed extra help
101100
RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
102-
&& apt-get -y install --no-install-recommends crystal dart nim powershell scala dotnet-sdk-5.0 r-base
101+
&& apt-get -y install --no-install-recommends crystal dart nim powershell scala dotnet-sdk-5.0 r-base racket
103102

104-
RUN pip install wheel matplotlib numpy coconut
103+
RUN pip install wheel matplotlib numpy coconut scons
105104

106105
RUN sudo sh -c 'npm install -g typescript'
106+

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -517,3 +517,10 @@ vscode/
517517

518518
# aspell
519519
*.bak
520+
521+
# SCons intermidiate files
522+
.sconsign.dblite
523+
*.o
524+
525+
# SCons build directory
526+
build/

CONTRIBUTORS.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,13 @@ This file lists everyone, who contributed to this repo and wanted to show up her
5151
- Vincent Zalzal
5252
- Jonathan D B Van Schenck
5353
- James Goytia
54-
- Amaras
54+
- Sammy Plat
5555
- Jonathan Dönszelmann
5656
- Ishaan Verma
5757
- Delphi1024
5858
- ntindle
5959
- Mahdi Sarikhani
6060
- Ridham177
6161
- Hugo Salou
62+
- Dimitri Belopopsky
63+
+ Henrik Abel Christensen

SConscript

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from pathlib import Path
2+
3+
Import('*')
4+
5+
for p in Path('contents').iterdir():
6+
if (q := (p / 'code')).exists():
7+
for path in q.iterdir():
8+
if path.stem in languages:
9+
env.SConscript(path / 'SConscript', exports='env',
10+
must_exist=0)

SConstruct

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
"""
2+
SCons top-level build description (SConstruct) for the Arcane Algorithm Achive
3+
4+
This provides Builder objects for each of the language implementations in the AAA; however, this work cannot be considered exhaustive until every language has been covered.
5+
6+
Currently, the aim is to provide a way to compile or copy the implementation files to the build directory, as well as to provide ways to run them and capture their output.
7+
8+
To run the compilation for all implmeentations in one language, e.g. Rust, run the command `scons build/c`, and the resulting executables will be available in the `cuild/c` directory, each in their respective algorithm directory, containing the executable."""
9+
10+
from pathlib import Path
11+
12+
env = Environment()
13+
14+
# Add other languages here when you want to add language targets
15+
languages = ['c']
16+
17+
env.C = env.Program
18+
19+
SConscript('SConscript', exports='env languages')
20+

contents/IFS/code/c/SConscript

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Import('*')
2+
from pathlib import Path
3+
4+
dirname = Path.cwd().parents[1].stem
5+
6+
env.C(f'#/build/c/{dirname}', Glob('*.c'))

contents/approximate_counting/approximate_counting.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,8 @@ As we do not have any objects to count, we will instead simulate the counting wi
360360
{% method %}
361361
{% sample lang="jl" %}
362362
[import, lang:"julia"](code/julia/approximate_counting.jl)
363+
{% sample lang="c" %}
364+
[import, lang:"c"](code/c/approximate_counting.c)
363365
{% sample lang="cpp" %}
364366
[import, lang:"cpp"](code/c++/approximate_counting.cpp)
365367
{% sample lang="python" %}

contents/approximate_counting/code/c++/approximate_counting.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,11 @@ auto test_approximate_count(
6161
int main() {
6262
std::cout << "Counting Tests, 100 trials\n";
6363

64-
std::cout << "testing 1,000, a = 30, 1% error "
64+
std::cout << "testing 1,000, a = 30, 10% error "
6565
<< test_approximate_count(100, 1000, 30, 0.1) << "\n";
66-
std::cout << "testing 12,345, a = 10, 1% error "
66+
std::cout << "testing 12,345, a = 10, 10% error "
6767
<< test_approximate_count(100, 12345, 10, 0.1) << "\n";
6868
// Note : with a lower a, we need more trials, so a higher % error here.
69-
std::cout << "testing 222,222, a = 0.5, 10% error "
69+
std::cout << "testing 222,222, a = 0.5, 20% error "
7070
<< test_approximate_count(100, 222222, 0.5, 0.2) << "\n";
7171
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Import('*')
2+
from pathlib import Path
3+
4+
dirname = Path.cwd().parents[1].stem
5+
6+
env.C(f'#/build/c/{dirname}', Glob('*.c'), LIBS='m')
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
#include <assert.h>
2+
#include <math.h>
3+
#include <stdio.h>
4+
#include <stdlib.h>
5+
#include <time.h>
6+
7+
// This function returns a pseudo-random number between 0 and 1
8+
double drand()
9+
{
10+
return (double)rand() / RAND_MAX;
11+
}
12+
13+
// This function takes
14+
// - v: value in register
15+
// - a: a scaling value for the logarithm based on Morris's paper
16+
// It returns the approximate count
17+
double n(double v, double a)
18+
{
19+
return a * (pow(1 + 1 / a, v) - 1);
20+
}
21+
22+
// This function takes
23+
// - v: value in register
24+
// - a: a scaling value for the logarithm based on Morris's paper
25+
// It returns a new value for v
26+
double increment(double v, double a)
27+
{
28+
// delta is the probability of incrementing our counter
29+
double delta = 1 / (n(v + 1, a) - n(v, a));
30+
31+
if (drand() <= delta) {
32+
return v + 1;
33+
}
34+
return v;
35+
}
36+
37+
// This function simulates counting and takes
38+
// - n_items: number of items to count and loop over
39+
// - a: a scaling value for the logarithm based on Morris's paper
40+
// It returns n(v, a), the approximate count
41+
double approximate_count(size_t n_items, double a)
42+
{
43+
int v = 0;
44+
for (size_t i = 0; i < n_items; ++i) {
45+
v = increment(v, a);
46+
}
47+
48+
return n(v, a);
49+
}
50+
51+
// This function takes
52+
// - n_trials: the number of counting trials
53+
// - n_items: the number off items to count
54+
// - a: a scaling value for the logarithm based on Morris's paper
55+
// - threshold: the maximum percent error allowed
56+
// It terminates the program on failure
57+
void test_approximation_count(size_t n_trials, size_t n_items, double a,
58+
double threshold)
59+
{
60+
double sum = 0.0;
61+
for (size_t i = 0; i < n_trials; ++i) {
62+
sum += approximate_count(n_items, a);
63+
}
64+
double avg = sum / n_trials;
65+
66+
assert(fabs((avg - n_items) / n_items) < threshold);
67+
}
68+
69+
int main()
70+
{
71+
srand(time(NULL));
72+
73+
printf("Counting Tests, 100 trials\n");
74+
printf("testing 1000, a = 30, 10%% error\n");
75+
test_approximation_count(100, 1000, 30, 0.1);
76+
printf("testing 12345, a = 10, 10%% error\n");
77+
test_approximation_count(100, 12345, 10, 0.1);
78+
printf("testing 222222, a = 0.5, 20%% error\n");
79+
test_approximation_count(100, 222222, 0.5, 0.2);
80+
81+
return 0;
82+
}

contents/approximate_counting/code/julia/approximate_counting.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,11 @@ function test_approximate_count(n_trials, n_items, a, threshold)
5151
end
5252

5353
@testset "Counting Tests, 100 trials" begin
54-
println("testing 1,000, a = 30, 1% error")
54+
println("testing 1,000, a = 30, 10% error")
5555
test_approximate_count(100, 1000, 30, 0.1)
56-
println("testing 12,345, a = 10, 1% error")
56+
println("testing 12,345, a = 10, 10% error")
5757
test_approximate_count(100, 12345, 10, 0.1)
5858
# Note: with a lower a, we need more trials, so a higher % error here.
59-
println("testing 222,222, a = 0.5, 10% error")
59+
println("testing 222,222, a = 0.5, 20% error")
6060
test_approximate_count(100, 222222, 0.5, 0.2)
6161
end

contents/approximate_counting/code/python/approximate_counting.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ def test_approximate_count(n_trials, n_items, a, threshold):
4141
if abs((avg - n_items)/n_items) < threshold:
4242
print("passed")
4343

44-
print("testing 1,000, a = 30, 1% error")
44+
print("testing 1,000, a = 30, 10% error")
4545
test_approximate_count(100, 1000, 30, 0.1)
46-
print("testing 12,345, a = 10, 1% error")
46+
print("testing 12,345, a = 10, 10% error")
4747
test_approximate_count(100, 12345, 10, 0.1)
48-
print("testing 222,222, a = 0.5, 10% error")
48+
print("testing 222,222, a = 0.5, 20% error")
4949
test_approximate_count(100, 222222, 0.5, 0.2)

contents/barnsley/code/c/SConscript

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Import('*')
2+
from pathlib import Path
3+
4+
dirname = Path.cwd().parents[1].stem
5+
6+
env.C(f'#/build/c/{dirname}', Glob('*.c'))

contents/computus/code/c/SConscript

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Import('*')
2+
from pathlib import Path
3+
4+
dirname = Path.cwd().parents[1].stem
5+
6+
env.C(f'#/build/c/{dirname}', Glob('*.c'))

contents/convolutions/1d/1d.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ With this in mind, we can almost directly transcribe the discrete equation into
5656
[import:27-46, lang:"julia"](code/julia/1d_convolution.jl)
5757
{% sample lang="cs" %}
5858
[import:63-84, lang:"csharp"](code/csharp/1DConvolution.cs)
59+
{% sample lang="py" %}
60+
[import:20-31, lang:"python"](code/python/1d_convolution.py)
5961
{% endmethod %}
6062

6163
The easiest way to reason about this code is to read it as you might read a textbook.
@@ -189,6 +191,8 @@ Here it is again for clarity:
189191
[import:27-46, lang:"julia"](code/julia/1d_convolution.jl)
190192
{% sample lang="cs" %}
191193
[import:63-84, lang:"csharp"](code/csharp/1DConvolution.cs)
194+
{% sample lang="py" %}
195+
[import:20-31, lang:"python"](code/python/1d_convolution.py)
192196
{% endmethod %}
193197

194198
Here, the main difference between the bounded and unbounded versions is that the output array size is smaller in the bounded case.
@@ -199,6 +203,8 @@ For an unbounded convolution, the function would be called with a the output arr
199203
[import:58-59, lang:"julia"](code/julia/1d_convolution.jl)
200204
{% sample lang="cs" %}
201205
[import:96-97, lang:"csharp"](code/csharp/1DConvolution.cs)
206+
{% sample lang="py" %}
207+
[import:41-42, lang:"python"](code/python/1d_convolution.py)
202208
{% endmethod %}
203209

204210
On the other hand, the bounded call would set the output array size to simply be the length of the signal
@@ -208,6 +214,8 @@ On the other hand, the bounded call would set the output array size to simply be
208214
[import:61-62, lang:"julia"](code/julia/1d_convolution.jl)
209215
{% sample lang="cs" %}
210216
[import:98-99, lang:"csharp"](code/csharp/1DConvolution.cs)
217+
{% sample lang="py" %}
218+
[import:44-45, lang:"python"](code/python/1d_convolution.py)
211219
{% endmethod %}
212220

213221
Finally, as we mentioned before, it is possible to center bounded convolutions by changing the location where we calculate the each point along the filter.
@@ -218,6 +226,8 @@ This can be done by modifying the following line:
218226
[import:35-35, lang:"julia"](code/julia/1d_convolution.jl)
219227
{% sample lang="cs" %}
220228
[import:71-71, lang:"csharp"](code/csharp/1DConvolution.cs)
229+
{% sample lang="py" %}
230+
[import:25-25, lang:"python"](code/python/1d_convolution.py)
221231
{% endmethod %}
222232

223233
Here, `j` counts from `i-length(filter)` to `i`.
@@ -252,6 +262,8 @@ In code, this typically amounts to using some form of modulus operation, as show
252262
[import:4-25, lang:"julia"](code/julia/1d_convolution.jl)
253263
{% sample lang="cs" %}
254264
[import:38-61, lang:"csharp"](code/csharp/1DConvolution.cs)
265+
{% sample lang="py" %}
266+
[import:5-17, lang:"python"](code/python/1d_convolution.py)
255267
{% endmethod %}
256268

257269
This is essentially the same as before, except for the modulus operations, which allow us to work on a periodic domain.
@@ -269,6 +281,8 @@ For the code associated with this chapter, we have used the convolution to gener
269281
[import, lang:"julia"](code/julia/1d_convolution.jl)
270282
{% sample lang="cs" %}
271283
[import, lang:"csharp"](code/csharp/1DConvolution.cs)
284+
{% sample lang="py" %}
285+
[import, lang:"python"](code/python/1d_convolution.py)
272286
{% endmethod %}
273287

274288
At a test case, we have chosen to use two sawtooth functions, which should produce the following images:

0 commit comments

Comments
 (0)