Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Artemis: Proposed changes for increased performance #34

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions src/control/double.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@
* @param n
* @return the sum of all values squared from 0 to n
*/
long
DoubleForLoop::SumSquare(int n) {
long DoubleForLoop::SumSquare(int n) {
long sum = 0;
for (int i = 0; i < n; i += 1) {
for (int j = 0; j < n; j += 1) {
if (i == j) {
sum = sum + (long) (i * j);
sum = sum + (long) i * j;
}
}
}
Expand Down Expand Up @@ -98,4 +97,4 @@ DoubleForLoop::SumMatrix(std::vector<std::vector<int>> matrix) {
}
}
return sum;
}
}
5 changes: 2 additions & 3 deletions src/datastructures/linkedlist.cc
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@ LinkedList::Print() {
*
* @param n Data to add to the new node
*/
void
LinkedList::AddNode(int n) {
void LinkedList::AddNode(int n) {
Node *current = head;
while (current->next != nullptr) {
current = current->next;
Expand Down Expand Up @@ -120,4 +119,4 @@ LinkedList::At(int n) {
current = current->next;
}
return current->data;
}
}
5 changes: 2 additions & 3 deletions src/datastructures/vector.cc
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,7 @@ OpsVector::ReverseVector(std::vector<int> &v) {
* @param n Number of elements to rotate by.
* @return The rotated vector.
*/
std::vector<int>
OpsVector::RotateVector(std::vector<int> &v, int n) {
std::vector<int> OpsVector::RotateVector(std::vector<int> &v, int n) {
std::vector<int> ret;

for (int i = n; i < (int) v.size(); i += 1) {
Expand Down Expand Up @@ -126,4 +125,4 @@ OpsVector::MergeVectors(std::vector<int> &v1, std::vector<int> &v2) {
}

return ret;
}
}
13 changes: 6 additions & 7 deletions src/math/vectoralgebra.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,23 +32,22 @@ MathVectorAlgebra::Cubic(int a, int b, int c, int d, std::vector<double> &x) {
*
* @return Pointer to array of y values (output)
*/
std::vector<double>
MathVectorAlgebra::Convolve(int offset, std::vector<double> &h, std::vector<double> &x) {
std::vector<double> MathVectorAlgebra::Convolve(int offset, std::vector<double> &h, std::vector<double> &x) {
int m = h.size();
int n = x.size();
int sum_h = 0;
std::vector<double> y = std::vector<double>(n);
double sum_h = 0;
std::vector<double> y(n, 0);
for (int i = 0; i < m; i += 1) {
sum_h += std::abs(h[i]);
}
if (sum_h == 0) {
sum_h = 1;
}
for (int i = 0; i < n; i += 1) {
y[i] = 0;
for (int j = 0; j < m; j += 1) {
if (i - offset + j >= 0 && i - offset + j < n) {
y[i] += h[j] * x[i - offset + j] / sum_h;
int idx = i - offset + j;
if (idx >= 0 && idx < n) {
y[i] += h[j] * x[idx] / sum_h;
}
}
}
Expand Down