Help on argmax block

Hi,

I’ve written a block that return the index of the largest element in a
vector; in other words, it implements the argmax function. Now I have
a small issue, I would relay like to get both the value and the index
of the largest element in the vector. What would be the easiest way to
do this? I am thinking of just sequencially outputing the index and
the value after each other and de-interleaving them to get each result
in a separate stream.


Trond D.

On Mon, Apr 16, 2007 at 10:20:59AM +0200, Trond D. wrote:

Hi,

I’ve written a block that return the index of the largest element in a
vector; in other words, it implements the argmax function. Now I have
a small issue, I would relay like to get both the value and the index
of the largest element in the vector. What would be the easiest way to
do this? I am thinking of just sequencially outputing the index and
the value after each other and de-interleaving them to get each result
in a separate stream.

You could either implement two separate outputs, or declare a
structure containing the two values and use that as the output type.
I suspect that interleaving is going to be confusing and bug prone.

Trond D.

Eric

2007/4/16, Eric B. [email protected]:

You could either implement two separate outputs, or declare a
structure containing the two values and use that as the output type.
I suspect that interleaving is going to be confusing and bug prone.

I decided that the most flexible and simplest solution was just to
create two separate block; one that returns max, and one that returns
argmax.


Trond D.

2007/4/16, Johnathan C. [email protected]:

Since you are generating exactly one of each (value, index) per input
vector, why not just assign your block two output streams and stuff the
value into one and the index into the other?

Of cause… Silly me!


Trond D.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs