Memory usage for lazy datatypes

I've written a program that analyzes and performs operations on data from a file. My first implementation uses Data.ByteString to read the contents of the file. This contents is then converted to a Vector of samples, using Data.Vector.Unboxed. I then...
more »

2017-02-18 19:02 (2) Answers

Python: random matrix from array

I would like to generate from a vector that for simplicity we can call "serie1" another vector of dimension 1000x1 where each element of this new vector is the sum of j random elements of the vector "serie1". I was thinking about creating a random m...
more »

2017-02-15 11:02 (3) Answers

Monadic concatMap for Data.Vector?

I'm looking for something from the Data.Vector package which works like concatMap but works with monads. concatMap has type... (a -> Vector b) -> Vector a -> Vector b but I'm looking for something with type... (Monad m) => (a -> ...
more »

2017-02-14 20:02 (1) Answers

C++ Find N-th highest element of a map

I have a string vector std::vector<string> list and I am trying to find N-th highest repeated element of the vector. I got a map include elements of the vector and repetition number of them. std::map<std::string , int> mapa; for(int i ...
more »

2017-02-11 14:02 (1) Answers

Replicate alternating vector values

I can't figure out how to produce a vector from 3 to 50 where the even numbers are replicated twice and the uneven numbers once, such that the vector would be 3, 4, 4, 5, 6, 6, 7, 8, 8, 9, ..., 50, 50 ...
more »

2017-02-09 21:02 (3) Answers

If-Else/Function Debugging

R beginner here. I'm trying to create a function that converts values for a list in R using if-else. I'm pretty sure I'm violating some cardinal rule(s) with syntax/logic in R and I've read several manuals/online help tools for functions and if/else ...
more »

2017-02-06 05:02 (2) Answers

C++ Invalid Comparator sorting Vector of Structs

I'm trying to Sort a std::vector containing custom structures, each of which has its own vector of int values. The key is that I want to sort based on the ordering of the internal int vector... i.e. {1, 1, 2, 3, 4} is less than {1, 2, 2, 3, 4} becau...
more »

2017-02-05 15:02 (1) Answers

Performance of DIM1 Repa Array vs Vector

I've written a program to process a large amount of data samples using Repa. Performance is key for this program. A large part of the operations require parallel maps/folds over a multi-dimensional arrays and Repa is perfect for this. However, there ...
more »

2017-01-25 14:01 (1) Answers

ByteString to Vector conversion

I have a ByteString that is containing the representation of Floats. Each Float is represented by 3 bytes in the ByteString. I need to do some processing on the Float values, so I would like to perform that processing on an Vector of Float values. ...
more »

2017-01-25 10:01 (2) Answers

Selectively sort vector c++

I have the following vector: vector<unsigned> vec = {5, 6, 5, 4, 1, 3, 0, 4} Now I want to sort this vector lexicographically by odd indices (and if odd indices are equal, then by the even indices). Such that the sorted vector "vec" is: ...
more »

2017-01-24 14:01 (4) Answers

zeros of a vector-valued function

Is there any function in MATLAB that can find the zeros of a vector-valued function? The commonly used function fzero is just for scalar functions and also cannot find the zeros of any scalar function such as f(x)=x^2. ...
more »

2017-01-23 04:01 (2) Answers

Building MaxHeap Largest Not Being Sent To Top

I am trying to build a max heap out of a vector of size 10. It contains numbers 1-10. Yet my program will not set the largest value 10 to the largest variable because when comparing it exceeds my vector's range. if ((l <= v.size()) && (v....
more »

2017-01-22 23:01 (1) Answers

Merge Sort Using Vectors c++

I'm trying to sort a text file using the merge sort method using vectors instead of arrays. The code builds but when I run it I get a an out bounds error on one of my vectors. Specifically : for (int k = start; k < end; k++) { if (L.at(x) &...
more »

2017-01-22 19:01 (1) Answers

How to pass vector's cell to a function in C++?

I want to make a function that takes an object from a vector's cell and modifies it. First I need to pass this cell by reference to the function and I can not do it. void circleChoiceOne(Circle& object); vector<Shape*> shapeArr; int main()...
more »

2017-01-13 16:01 (2) Answers

C++ sort vectors time complexity

Suppose I have a vector<vector<int>> L with N vectors, and total number of ints summed across all vectors is at most M. What is the tightest time complexity of the standard C++ sort sort(L.begin(), L.end())? The vector<int> compari...
more »

2017-01-12 23:01 (2) Answers

Multidimensional data type in Scala

I have a generic class, which is constructed from multi-dimensional data (i.e. n-dimensional Ararys or Vectors). In this case, I would like the class to be instantiated by one type only (e.g. Vector), aside from its dimensionality (Vector[Vector[T]] ...
more »

2017-01-09 17:01 (1) Answers