1. Multidimensional arrays

Hello everybody!

Me, being working for a lot of time with Matlab, I like and use array
 (sequence) programming.
Euphoria would be an interesting solution for calculus and GUI mixed software.
 However, a focused question:
It is planned to intoduce the following feature in euphoria (for
 multidimensional sequences):
seq[:][2] to select the second column and seq[3][:] to select the third line of
 a 2D sequence (and so on...)? It would be very interesting (for me)
to have it ...

 Thanks a lot. Felix

new topic     » topic index » view message » categorize

2. Re: Multidimensional arrays

felix wrote:
> 
> 
>  Hello everybody!
> 
>  Me, being working for a lot of time with Matlab, I like and use array
>  (sequence) programming.
>  Euphoria would be an interesting solution for calculus and GUI mixed
>  software. However,
> a focused question:
>  It is planned to intoduce the following feature in euphoria (for
>  multidimensional
> sequences):
>  seq[:][2] to select the second column and seq[3][:] to select the third line
>  of a
> 2D sequence (and so on...)? It would be very interesting (for me)
> to have it ...
> 
I just use a function like this:

-- this functions assumes that you've 
-- got a 2-d table/matrix and there are the
-- same number of elements (columns) in each row 
function cx(sequence M, integer ci)
sequence c
	if ci < 0 then
		ci = length(M[1]) + ci + 1
	end if
	c = repeat(0,length(M))
	for i = 1 to length(c) do
		c[i] = M[i][ci]
	end for
	return c
end function

So cx(s,3) extracts column 3 of matrix s.  Works pretty fast.

To invert the rows & columns, use this:

global function rotate(sequence x)
sequence rotated
atom dim1, dim2

	if not length(x) then
		return x -- empty returns empty
	end if

	dim1 = length(x[1])
	dim2 = length(x)
	rotated = repeat(repeat(0,dim2),dim1)

	for i = 1 to dim1 do
		for j = 1 to dim2 do
			rotated[i][j] = x[j][i]
		end for
	end for

	return rotated

end function

new topic     » goto parent     » topic index » view message » categorize

3. Re: Multidimensional arrays

Andy Serpa wrote:
> 

> function cx(sequence M, integer ci)
> sequence c
> 	if ci < 0 then
> 		ci = length(M[1]) + ci + 1
> 	end if
> 	c = repeat(0,length(M))
> 	for i = 1 to length(c) do
> 		c[i] = M[i][ci]
> 	end for
> 	return c
> end function
> 

Oh yeah, and cx(s,-2) selects the 2nd column from the end...

new topic     » goto parent     » topic index » view message » categorize

4. Re: Multidimensional arrays

On 24 Nov 2004, at 6:06, felix wrote:

> 
> 
> posted by: felix <axeoth at yahoo.fr>
> 
> 
>  Hello everybody!
> 
>  Me, being working for a lot of time with Matlab, I like and use array
>  (sequence) programming. Euphoria would be an interesting solution for
>  calculus
>  and GUI mixed software. However, a focused question: It is planned to
>  intoduce
>  the following feature in euphoria (for multidimensional sequences): seq[:][2]
>  to select the second column and seq[3][:] to select the third line of a 2D
>  sequence (and so on...)? It would be very interesting (for me)
> to have it ...

We've asked RDS for it for years, they decline to provide that. But you can 
simulate it, see email archives for column.

Kat

new topic     » goto parent     » topic index » view message » categorize

5. Re: Multidimensional arrays

On Wed, 24 Nov 2004 14:18:51 -0600, Kat <gertie at visionsix.com> wrote:
> >  Hello everybody!
> >
> >  Me, being working for a lot of time with Matlab, I like and use array
> >  (sequence) programming. Euphoria would be an interesting solution for
> >  calculus
> >  and GUI mixed software. However, a focused question: It is planned to
> >  intoduce
> >  the following feature in euphoria (for multidimensional sequences):
> >  seq[:][2]
> >  to select the second column and seq[3][:] to select the third line of a 2D
> >  sequence (and so on...)? It would be very interesting (for me)
> > to have it ...
> 
> We've asked RDS for it for years, they decline to provide that. But you can
> simulate it, see email archives for column.

I'm going to go out on a limb here, and say that it's *very* inefficient.
The statement seq[3] retreives the internal pointer to the third
element. Fair enough.

The statement seq[:][3] (if it existed) would have to load every
element pointer, find the internal pointer to the third element of
that sequence, and collate all those pointers in a new sequence, then
return it.

I think that if you need to access the 3rd sub-element of every
element in a sequence, you can either write your algorithm in such a
way that it accesses those sub-elements 1 by 1, or use a simple
function that will do it for you.

But to have it built-in to the language will encourage inefficient
programming.. IMO.

-- 
MrTrick

new topic     » goto parent     » topic index » view message » categorize

6. Re: Multidimensional arrays

On 25 Nov 2004, at 9:05, Patrick Barnes wrote:

> 
> On Wed, 24 Nov 2004 14:18:51 -0600, Kat <gertie at visionsix.com> wrote:
> > >  Hello everybody!
> > >
> > >  Me, being working for a lot of time with Matlab, I like and use array
> > >  (sequence) programming. Euphoria would be an interesting solution for
> > >  calculus and GUI mixed software. However, a focused question: It is
> > >  planned
> > >  to intoduce the following feature in euphoria (for multidimensional
> > >  sequences): seq[:][2] to select the second column and seq[3][:] to select
> > >  the third line of a 2D sequence (and so on...)? It would be very
> > >  interesting (for me)
> > > to have it ...
> > 
> > We've asked RDS for it for years, they decline to provide that. But you can
> > simulate it, see email archives for column.
> 
> I'm going to go out on a limb here, and say that it's *very* inefficient.
> The statement seq[3] retreives the internal pointer to the third
> element. Fair enough.
> 
> The statement seq[:][3] (if it existed) would have to load every
> element pointer, find the internal pointer to the third element of
> that sequence, and collate all those pointers in a new sequence, then
> return it.
> 
> I think that if you need to access the 3rd sub-element of every
> element in a sequence, you can either write your algorithm in such a
> way that it accesses those sub-elements 1 by 1, or use a simple
> function that will do it for you.
> 
> But to have it built-in to the language will encourage inefficient
> programming.. IMO.

Having it in C code in the language, should be faster than doing it Eu, written 
by a programmer inexperienced in Eu code. And the question has come up 
before, many times. 


Kat

new topic     » goto parent     » topic index » view message » categorize

7. Re: Multidimensional arrays

On Wed, 24 Nov 2004 17:29:14 -0600, Kat <gertie at visionsix.com> wrote:
> > But to have it built-in to the language will encourage inefficient
> > programming.. IMO.
> 
> Having it in C code in the language, should be faster than doing it Eu,
> written
> by a programmer inexperienced in Eu code. And the question has come up
> before, many times.

That is true...
To do something like that efficiently though, you'd need a doubly
indexed array... and it'd be slower for non-doubly indexed purposes.

You know what would be truly ground-breaking, I think? A way to define
the internal structure of a collection of data (like a tree, a list, a
doubly indexed array, a heap, etc...) then access them using
high-level, homogenous terms.
It'd be fast, because it could use optimal organisation, rather that
sitting everything in multiply nested arrays as we do now.
Not sure where to begin though.

-- 
MrTrick

new topic     » goto parent     » topic index » view message » categorize

8. Re: Multidimensional arrays

First of all, thank you very much for your answers.
I am not an active Euphoria developper, at the moment Matlab is the only piece
of software
where I develop quite complex applications, due to the scientifical part.
However, exactly for this one, scientifical programming, that kind of row/column
selection seemd to me great.
Also for multidimensional arrays...
I understand it would not be very efficient. However, I tend to agree with the
point of view that this kind of
selection would be faster if implemented in the core part of the language
(written in C), than if written each time in Eu.
About the syntax, I gave only one example. Using a function to return that
sequence should not be too difficult.
Also, multidimensional arrays could have their dimensions permuted (by example,
an array of [2x3x4] could become
an array [3x2x4]). Doing this in Matlab is easy (and fast enough), so why it
could not be implemented in Eu?
Sorry if my point of view is too much Matlab-oriented ... It is not a critic to
Eu, I think is great, but I would also like it
to meeat my needs...

Best regards.

 Felix

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu