fixed errors
This commit is contained in:
parent
875d4bd72e
commit
dea72060c2
3 changed files with 62 additions and 56 deletions
|
|
@ -13,7 +13,7 @@
|
|||
#include <stdexcept>
|
||||
using namespace std;
|
||||
|
||||
void task_a() {
|
||||
static void task_a() {
|
||||
printf("\n\n-------------- Task A --------------\n\n");
|
||||
|
||||
auto [a,b,c] = means0(1,4,16);
|
||||
|
|
@ -30,7 +30,7 @@ void task_a() {
|
|||
|
||||
}
|
||||
|
||||
void task_b() {
|
||||
static void task_b() {
|
||||
printf("\n\n-------------- Task B --------------\n\n");
|
||||
|
||||
// Read vector
|
||||
|
|
@ -57,11 +57,11 @@ void task_b() {
|
|||
printf("Harmonic: %f\n", z);
|
||||
|
||||
// deviation
|
||||
double deviation;
|
||||
double deviation(0.0);
|
||||
for (long unsigned int i=0; i<a.size(); i++){
|
||||
deviation += pow(x - a.at(i),2);
|
||||
}
|
||||
deviation = sqrt(deviation/a.size());
|
||||
deviation = sqrt(deviation/static_cast<double>(a.size()));
|
||||
printf("Deviation: %f\n", deviation);
|
||||
|
||||
// write results to file
|
||||
|
|
@ -70,14 +70,14 @@ void task_b() {
|
|||
|
||||
}
|
||||
|
||||
void task_c() {
|
||||
static void task_c() {
|
||||
printf("\n\n-------------- Task C --------------\n\n");
|
||||
|
||||
vector<int> n_values = {15, 1001, 1432987};
|
||||
|
||||
for (int n : n_values) {
|
||||
printf("n = %d\n", n);
|
||||
double sum = 0;
|
||||
long int sum = 0;
|
||||
double loops = 1000;
|
||||
|
||||
// Timing first function
|
||||
|
|
@ -86,24 +86,24 @@ void task_c() {
|
|||
sum = sum_of_spec(n);
|
||||
}
|
||||
double sec1 = toc();
|
||||
printf("For-loop funtion: result = %.f | time = %f milliseconds\n", sum, sec1*1000);
|
||||
printf("For-loop funtion: result = %ld | time = %f milliseconds\n", sum, sec1*1000);
|
||||
|
||||
// Timing second function
|
||||
tic();
|
||||
for (int i=0; i<loops; i++){
|
||||
sum = formula(n);
|
||||
sum = static_cast<long int>(formula(n));
|
||||
}
|
||||
double sec2 = toc();
|
||||
printf("Formula funtion: result = %.f | time = %f milliseconds\n", sum, sec2*1000);
|
||||
printf("Formula funtion: result = %ld | time = %f milliseconds\n", sum, sec2*1000);
|
||||
}
|
||||
}
|
||||
|
||||
void task_d() {
|
||||
static void task_d() {
|
||||
printf("\n\n-------------- Task D --------------\n\n");
|
||||
printf("See folder D.\n");
|
||||
}
|
||||
|
||||
void task_e() {
|
||||
static void task_e() {
|
||||
printf("\n\n-------------- Task E --------------\n\n");
|
||||
|
||||
for (int n : {100, 1000, 10000}) {
|
||||
|
|
@ -130,7 +130,7 @@ void task_e() {
|
|||
}
|
||||
}
|
||||
|
||||
void task_f() {
|
||||
static void task_f() {
|
||||
printf("\n\n-------------- Task F --------------\n\n");
|
||||
|
||||
// single_goldbach(k)
|
||||
|
|
@ -161,7 +161,7 @@ void task_f() {
|
|||
|
||||
}
|
||||
|
||||
void task_g() {
|
||||
static void task_g() {
|
||||
printf("\n\n-------------- Task G --------------\n\n");
|
||||
|
||||
DenseMatrix const M(5,3);
|
||||
|
|
@ -188,7 +188,7 @@ void task_g() {
|
|||
// #######################################################
|
||||
|
||||
int const NLOOPS = 100;
|
||||
int const n = 1000;
|
||||
int const n = 3000;
|
||||
|
||||
// Time initialization
|
||||
tic();
|
||||
|
|
@ -200,7 +200,7 @@ void task_g() {
|
|||
// Time Mult
|
||||
tic();
|
||||
vector<double> f3 = M2.Mult(w);
|
||||
for (int k=1; k<NLOOPS; ++k){
|
||||
for (size_t k=1; k<NLOOPS; ++k){
|
||||
f3 = M2.Mult(w);
|
||||
}
|
||||
double t2 = toc();
|
||||
|
|
@ -208,8 +208,8 @@ void task_g() {
|
|||
// Time MultT
|
||||
tic();
|
||||
vector<double> f4 = M2.MultT(w);
|
||||
for (int k=1; k<NLOOPS; ++k){
|
||||
f4 = M2.Mult(w);
|
||||
for (size_t k=1; k<NLOOPS; ++k){
|
||||
f4 = M2.MultT(w);
|
||||
}
|
||||
double t3 = toc();
|
||||
|
||||
|
|
@ -220,7 +220,7 @@ void task_g() {
|
|||
printf("Time for MultT : %f seconds, %f per loop.\n", t3, t3/NLOOPS);
|
||||
|
||||
// Check if resulting vectors are equal
|
||||
for (int i = 0; i < n; i++)
|
||||
for (size_t i = 0; i < n; i++)
|
||||
{
|
||||
double err = f3[i] - f4[i];
|
||||
if(abs(err) > 1e-4)
|
||||
|
|
@ -233,14 +233,14 @@ void task_g() {
|
|||
// Time initialization
|
||||
tic();
|
||||
vector<double> x(n,0);
|
||||
for (int i=0; i<n; i++){x[i] = sigmoid( (10.0*i)/(n-1) - 5 );}
|
||||
for (int i=0; i<n; i++){x[i] = sigmoid( (10.0*static_cast<double>(i))/(n-1) - 5 );}
|
||||
DenseMatrix2 M3(x,x);
|
||||
double t4 = toc();
|
||||
|
||||
// Time Mult
|
||||
tic();
|
||||
vector<double> f5 = M3.Mult(w);
|
||||
for (int k=1; k<NLOOPS; ++k){
|
||||
for (size_t k=1; k<NLOOPS; ++k){
|
||||
f5 = M3.Mult(w);
|
||||
}
|
||||
double t5 = toc();
|
||||
|
|
@ -248,8 +248,8 @@ void task_g() {
|
|||
// Time MultT
|
||||
tic();
|
||||
vector<double> f6 = M3.MultT(w);
|
||||
for (int k=1; k<NLOOPS; ++k){
|
||||
f6 = M3.Mult(w);
|
||||
for (size_t k=1; k<NLOOPS; ++k){
|
||||
f6 = M3.MultT(w);
|
||||
}
|
||||
double t6 = toc();
|
||||
|
||||
|
|
@ -260,7 +260,7 @@ void task_g() {
|
|||
printf("Time for MultT : %f seconds, %f per loop.\n", t6, t6/NLOOPS);
|
||||
|
||||
// Check if resulting vectors are equal
|
||||
for (int i = 0; i < n; i++)
|
||||
for (size_t i = 0; i < n; i++)
|
||||
{
|
||||
double err = f5[i] - f6[i];
|
||||
if(abs(err) > 1e-4)
|
||||
|
|
@ -269,9 +269,6 @@ void task_g() {
|
|||
}
|
||||
}
|
||||
|
||||
printf("\nNOTE: difference in runtime noticable with n=10.000 (~30 seconds)\n");
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -286,4 +283,4 @@ int main(){
|
|||
task_g();
|
||||
|
||||
return 0;
|
||||
};
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue