Nested rolling sum in vector

I am struggling to produce an efficient code to compute the vector result r result from an input vector v using this function. r(i) = \sum_{j=i}^{i-N} [o(i)-o(j)] * exp(o(i)-o(j)) where i loops (from N to M) over the vector v. Size of v is M&...
more »

2017-06-15 14:06 (2) Answers

How to nest unboxed vectors?

This may be a pretty basic question, but I've searched around and I cannot seem to find the answer. I would like to represent a 2D list using unboxed Vectors. This is easily done with normal vectors: > import qualified Data.Vector as V >
more »

2017-05-20 08:05 (1) Answers

Strange error in c++ class construction

I have recently started learning c++ and I am now trying to make a simple vector class as an exercise. But somehow my code doesn't seem to work. #include <iostream> #include <cmath> class Vec2 { public: float x1; float x2; Ve...
more »

2017-05-17 11:05 (4) Answers

C++ Static vectors in classes

I am working on a restraunt order system as a project for my computer science class and I was wondering if it would be best practice to use a static vector within my Order class to contain all of my orders or should I have it in my main program? I'm ...
more »

2017-05-10 22:05 (1) Answers

Vectorizing nearest neighbor computation

I have the following function which is returning an array calculating the nearest neighbor: def p_batch(U,X,Y): return [nearest(u,X,Y) for u in U] I would like to replace the for loop using numpy. I've been looking into numpy.vectorize() as th...
more »

2017-05-08 19:05 (1) Answers

using prolog & clpr for a system of constraints

I'm looking to use prolog in a desktop application to generate a random vector that satisfies a system of constraints. As an example, our user might provide our software with the following information at runtime: Given a vector <x1, x2, x3, ... ...
more »

2017-05-08 09:05 (1) Answers

Sorting 2d vector passed by reference

I implemented Prim's algorithm. It returns a std::vector<std::vector<int>> (which is a vector of vectors : [vertice, vertice, weight]). The results are correct, but when I compare it with my lab guys results, sometimes there is a differen...
more »

2017-05-07 19:05 (1) Answers

How to create a vector between 2 dates in R

I am new to R and I would like to create a vector between 2 dates a Here is my code start.plot <- c("2011-01-01", "2012-12-31") plot1 <- substr(start.plot[1],1,7) plot2 <- substr(start.plot[2],1,7) Month_test <- as.character(seq(as...
more »

2017-05-05 16:05 (1) Answers

Switch input for sorting algorithm

I wrote an insertion sort below: int i, j; Book temp; for (j = 1; j < books.size(); j++) { temp = books[j]; i = j - 1; while (i >= 0) { if (temp.getAuthor().compare(books[i].getAuthor()) > 0) { break; ...
more »

2017-04-28 15:04 (3) Answers