Questions tagged [accumulator]

An accumulator is a register in a computer processor in which intermediate arithmetic and logic results are stored.

269 questions
19
votes
2 answers

Spark losing println() on stdout

I have the following code: val blueCount = sc.accumulator[Long](0) val output = input.map { data => for (value <- data.getValues()) { if (record.getEnum() == DataEnum.BLUE) { blueCount += 1 println("Enum = BLUE : " +…
Edamame
  • 23,718
  • 73
  • 186
  • 320
18
votes
7 answers

Is there a MATLAB accumarray equivalent in numpy?

I'm looking for a fast solution to MATLAB's accumarray in numpy. The accumarray accumulates the elements of an array which belong to the same index. An example: a = np.arange(1,11) # array([ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) accmap =…
petrichor
  • 6,459
  • 4
  • 36
  • 48
17
votes
2 answers

Is the accumulator of reduce in Java 8 allowed to modify its arguments?

In Java 8, Stream has a method reduce: T reduce(T identity, BinaryOperator accumulator); Is the accumulator operator allowed to modify either of its arguments? I presume not since the JavaDoc says the accumulator should be NonInterfering,…
Graeme Moss
  • 7,995
  • 4
  • 29
  • 42
16
votes
7 answers

What is the 'accumulator' in HQ9+?

I was just reading a bit about the HQ9+ programming language: https://esolangs.org/wiki/HQ9+, https://en.wikipedia.org/wiki/HQ9+, and https://cliffle.com/esoterica/hq9plus, and it tells me something about a so-called “accumulator” which can be…
user142019
14
votes
3 answers

Is it possible to use boost accumulators with vectors?

I wanted to use boost accumulators to calculate statistics of a variable that is a vector. Is there a simple way to do this. I think it's not possible to use the dumbest thing: using namespace boost::accumulators; //stuff... …
Rafael S. Calsaverini
  • 13,582
  • 19
  • 75
  • 132
14
votes
1 answer

Irrefutable pattern does not leak memory in recursion, but why?

The mapAndSum function in the code block all the way below combines map and sum (never mind that another sum is applied in the main function, it just serves to make the output compact). The map is computed lazily, while the sum is computed using an…
buechse
  • 163
  • 6
13
votes
3 answers

SQLite: accumulator (sum) column in a SELECT statement

I have a table like this one: SELECT value FROM table; value 1 3 13 1 5 I would like to add an accumulator column, so that I have this result: value accumulated 1 1 3 4 13 17 1 18 5 23 How can I do this? What's the real…
moala
  • 5,094
  • 9
  • 45
  • 66
13
votes
5 answers

Should I avoid tail recursion in Prolog and in general?

I'm working through "Learn Prolog now" online book for fun. I'm trying to write a predicate that goes through each member of a list and adds one to it, using accumulators. I have already done it easily without tail…
13
votes
5 answers

Accumulators, conj and recursion

I've solved 45 problems from 4clojure.com and I noticed a recurring problem in the way I try to solve some problems using recursion and accumulators. I'll try to explain the best I can what I'm doing to end up with fugly solutions hoping that some…
Cedric Martin
  • 5,945
  • 4
  • 34
  • 66
12
votes
3 answers

Prolog Accumulators. Are they really a "different" concept?

I am learning Prolog under my Artificial Intelligence Lab, from the source Learn Prolog Now!. In the 5th Chapter we come to learn about Accumulators. And as an example, these two code snippets are given. To Find the Length of a List without…
tmj
  • 1,750
  • 2
  • 19
  • 34
11
votes
6 answers

In (reduce f val coll), is the val an accumulator?

When you call reduce and pass it a function and two arguments, can the first argument be considered to be an accumulator? Is it always an accumulator? Is it sometimes an accumulator? I was reading a blog entry about using Clojure to parse big files…
Cedric Martin
  • 5,945
  • 4
  • 34
  • 66
10
votes
3 answers

Scheme / Racket Best Practice - Recursion vs Variable Accumulation

I'm new to Scheme (via Racket) and (to a lesser extent) functional programming, and could use some advise on the pros and cons of accumulation via variables vs recursion. For the purposes of this example, I'm trying to calculate a moving average. …
Scott Klarenbach
  • 37,171
  • 15
  • 62
  • 91
10
votes
3 answers

readline() is skipping lines in source file

I have a .txt file that I created with multiple lines. When I run a for loop, with a count accumulator, it skips lines. It skips the top line, and starts with the second, prints the fourth, the sixth, etc. What is it I'm missing? def main(): #…
Alli OGrady
  • 287
  • 3
  • 4
  • 13
9
votes
4 answers

Does it matter which registers you use when writing assembly?

If you're writing assembly, does it matter which registers you allocate values to? Say, you store an accumulated/intermediate value in %ebx instead of %eax, which was traditionally used for that purpose. Is that bad practice? Will it affect…
heapoverflow
  • 153
  • 1
  • 8
8
votes
2 answers

Recursive state monad for accumulating a value while building a list?

I'm totally new to Haskell so apologies if the question is silly. What I want to do is recursively build a list while at the same time building up an accumulated value based on the recursive calls. This is for a problem I'm doing for a Coursera…
Russell
  • 12,261
  • 4
  • 52
  • 75
1
2 3
17 18