No more than 8 dimensions in Array! :-(

New to FreeBASIC? Post your questions here.
Luis Babboni
Posts: 303
Joined: Mar 15, 2015 12:41

Re: No more than 8 dimensions in Array! :-(

Postby Luis Babboni » Jul 07, 2015 12:33

It seems I solved using the double.
It seems it takes more time with Callocate as you said:
Image
Luis Babboni
Posts: 303
Joined: Mar 15, 2015 12:41

Re: No more than 8 dimensions in Array! :-(

Postby Luis Babboni » Jul 07, 2015 12:37

The dodicat suggestion scared me!! :-D
Is the best?
It seems I need too to test its speed against Callocate...
fxm
Posts: 9720
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: No more than 8 dimensions in Array! :-(

Postby fxm » Jul 07, 2015 13:19

Or let the program do the calculations itself:

Code: Select all

Type Array5
  Dim As Integer Larray(9, 3, 3, 3, 2)
End Type

Type Array10
  Dim As Array5 Uarray(9, 3, 3, 3, 2)
End Type


Dim Shared As Array10 a10

'Just to have a better syntax than the second line
#Define array(n1, n2, n3, n4, n5, n6, n7, n8, n9, n10) _
  a10.Uarray(n1, n2, n3, n4, n5).Larray(n6, n7, n8, n9, n10)

dim as integer n1, n2, n3, n4, n5, n6, n7, n8, n9, n10
dim as integer counter
for n1 = 0 to 9
    for n2 = 0 to 3
        for n3 = 0 to 3
            for n4 = 0 to 3
                for n5 = 0 to 2
                    for n6 = 0 to 9
                        for n7 = 0 to 3
                            for n8 = 0 to 3
                                for n9 = 0 to 3
                                    for n10=0 to 2
                      'get some values                         
              array(n1, n2, n3, n4, n5, n6, n7, n8, n9, n10) = counter                                 
                 counter+=1                             
next: next: next: next: next: next: next: next: next: next

Print array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
Print array(3, 0, 3, 2, 1, 2, 3, 2, 1, 0)
Print array(9, 3, 3, 3, 2, 9, 3, 3, 3, 2)
Luis Babboni
Posts: 303
Joined: Mar 15, 2015 12:41

Re: No more than 8 dimensions in Array! :-(

Postby Luis Babboni » Jul 07, 2015 13:42

Trying dodicat/fxm way! ;-)
Luis Babboni
Posts: 303
Joined: Mar 15, 2015 12:41

Re: No more than 8 dimensions in Array! :-(

Postby Luis Babboni » Jul 07, 2015 14:01

Mmmm.... I see it works but still not sure how.
This example has a pair number of dimensions, what about with 9 or 11 dimensions with these lines having Array5 5 dimensions?:

Code: Select all

Type Array10
  Dim As Array5 Uarray(9, 3, 3, 3, 2)
End Type
dodicat
Posts: 6557
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: No more than 8 dimensions in Array! :-(

Postby dodicat » Jul 07, 2015 14:40

You cannot use an integer pointer and say that B[i*j] could represent A(i,j) or any other value because [i*j] is not unique.

Code: Select all

dim as integer SomeIndex=1244
for i as integer =1 to 5000
    for j as integer =1 to 5000
        if i*j= SomeIndex then print i,j
    next j
next i

print "done"
sleep
grindstone
Posts: 737
Joined: May 05, 2015 5:35
Location: Germany

Re: No more than 8 dimensions in Array! :-(

Postby grindstone » Jul 07, 2015 14:41

Luis Babboni wrote:No, no, in FB.
Then "Timer" delivers a DOUBLE value with the same resolution as your system clock (~µs range).

EDIT: Sorry, I didn't notice there was a 2nd page in the meantime.
fxm
Posts: 9720
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: No more than 8 dimensions in Array! :-(

Postby fxm » Jul 07, 2015 15:54

Luis Babboni wrote:Mmmm.... I see it works but still not sure how.
This example has a pair number of dimensions, what about with 9 or 11 dimensions with these lines having Array5 5 dimensions?:

Code: Select all

Type Array10
  Dim As Array5 Uarray(9, 3, 3, 3, 2)
End Type

No problem, and different solutions for the two Types:
11 dimensions = 8 dimensions + 3 dimensions
11 dimensions = 7 dimensions + 4 dimensions
11 dimensions = 6 dimensions + 5 dimensions
11 dimensions = 5 dimensions + 6 dimensions
11 dimensions = 4 dimensions + 7 dimensions
11 dimensions = 3 dimensions + 8 dimensions

Example:

Code: Select all

Type Array8
  Dim As Integer Larray(3, 3, 2, 9, 3, 3, 3, 2)
End Type

Type Array11
  Dim As Array8 Uarray(3, 9, 3)
End Type


Dim Shared As Array11 a11

'Just to have a better syntax than the second line
#Define array(n0, n1, n2, n3, n4, n5, n6, n7, n8, n9, n10) _
  a11.Uarray(n0, n1, n2).Larray(n3, n4, n5, n6, n7, n8, n9, n10)

dim as integer n0, n1, n2, n3, n4, n5, n6, n7, n8, n9, n10
dim as integer counter
for n0 = 0 to 3
  for n1 = 0 to 9
    for n2 = 0 to 3
      for n3 = 0 to 3
        for n4 = 0 to 3
          for n5 = 0 to 2
            for n6 = 0 to 9
              for n7 = 0 to 3
                for n8 = 0 to 3
                  for n9 = 0 to 3
                    for n10=0 to 2
                      'get some values                         
                      array(n0, n1, n2, n3, n4, n5, n6, n7, n8, n9, n10) = counter                                 
                      counter+=1                             
next: next: next: next: next: next: next: next: next: next: next

Print array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
Print array(1, 3, 0, 3, 2, 1, 2, 3, 2, 1, 0)
Print array(3, 9, 3, 3, 3, 2, 9, 3, 3, 3, 2)
Luis Babboni
Posts: 303
Joined: Mar 15, 2015 12:41

Re: No more than 8 dimensions in Array! :-(

Postby Luis Babboni » Jul 07, 2015 18:20

dodicat wrote:You cannot use an integer pointer and say that B[i*j] could represent A(i,j) or any other value because [i*j] is not unique.

Code: Select all

dim as integer SomeIndex=1244
for i as integer =1 to 5000
    for j as integer =1 to 5000
        if i*j= SomeIndex then print i,j
    next j
next i

print "done"
sleep


Very stupid by my side!! :-D
So the difference in time are even greater cause I need to make an algorithm to find the correct value for i and j :-/
Can´t imagine why arrays are faster cause in my mind, in the lower level, to use arrays you need to write and read values from memory that is what Allocate do.... where is my mistake?
Last edited by Luis Babboni on Jul 07, 2015 18:23, edited 1 time in total.
Luis Babboni
Posts: 303
Joined: Mar 15, 2015 12:41

Re: No more than 8 dimensions in Array! :-(

Postby Luis Babboni » Jul 07, 2015 18:22

Thanks fxm..... I need to understand what "...Array8 Uarray(3, 9, 3)..." means without any operator in between.
St_W
Posts: 1494
Joined: Feb 11, 2009 14:24
Location: Austria
Contact:

Re: No more than 8 dimensions in Array! :-(

Postby St_W » Jul 07, 2015 19:39

Luis Babboni wrote:Thanks fxm..... I need to understand what "...Array8 Uarray(3, 9, 3)..." means without any operator in between.

You can also write it as

Code: Select all

dim Uarray(3,9,3) as Array8

UArray is a 3-dimensional array of the type Array8, which itself is a structure describing a 8-dimensional array. So you effectively have a 3-dimensional array holding instances of 8-dimensional arrays, which results in a 11-dimensional array altoghether.
fxm
Posts: 9720
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: No more than 8 dimensions in Array! :-(

Postby fxm » Jul 07, 2015 20:02

Exactly :-)
Luis Babboni
Posts: 303
Joined: Mar 15, 2015 12:41

Re: No more than 8 dimensions in Array! :-(

Postby Luis Babboni » Jul 15, 2015 12:04

St_W wrote:
Luis Babboni wrote:Thanks fxm..... I need to understand what "...Array8 Uarray(3, 9, 3)..." means without any operator in between.

You can also write it as

Code: Select all

dim Uarray(3,9,3) as Array8

UArray is a 3-dimensional array of the type Array8, which itself is a structure describing a 8-dimensional array. So you effectively have a 3-dimensional array holding instances of 8-dimensional arrays, which results in a 11-dimensional array altoghether.


After some weeks out Im here again.... and just now I understood the idea!!! :-)

Thanks guys!
Luis Babboni
Posts: 303
Joined: Mar 15, 2015 12:41

Re: No more than 8 dimensions in Array! :-(

Postby Luis Babboni » Jul 15, 2015 13:33

"...

Dim Shared As Array11 a11

'Just to have a better syntax than the second line
#Define array(n0, n1, n2, n3, n4, n5, n6, n7, n8, n9, n10) _
a11.Uarray(n0, n1, n2).Larray(n3, n4, n5, n6, n7, n8, n9, n10)

..."

Question: I´m not using near double memory space doing this?
I mean, I think I need some memory space for a11... the action of "defining" array not need at least another equal new amount of memory space than I needed for a11?
May be I´m not sure about the meaning of "'Just to have a better syntax than the second line". Wich line you referred to?
St_W
Posts: 1494
Joined: Feb 11, 2009 14:24
Location: Austria
Contact:

Re: No more than 8 dimensions in Array! :-(

Postby St_W » Jul 15, 2015 13:50

Luis Babboni wrote:Question: I´m not using near double memory space doing this?
I mean, I think I need some memory space for a11... the action of "defining" array not need at least another equal new amount of memory space than I needed for a11?
May be I´m not sure about the meaning of "'Just to have a better syntax than the second line". Wich line you referred to?

The next line: #define ....
You really should have looked into FreeBasic's Manual: #define does not allocate any memory at all at runtime. see the manual for what it does / can be used for.

Return to “Beginners”

Who is online

Users browsing this forum: No registered users and 4 guests