POV-Ray : Newsgroups : povray.bugreports : The way to an ideal array is a kick in the face Server Time
28 Mar 2024 20:04:05 EDT (-0400)
  The way to an ideal array is a kick in the face (Message 1 to 4 of 4)  
From: BGimeno
Subject: The way to an ideal array is a kick in the face
Date: 26 Sep 2018 17:52:27
Message: <5babff9b$1@news.povray.org>
While I was trying to generate and list a huge array with pairs of 
numbers of this style,
/*
#declare T_arr = array [n]]2]
  {
     {1,1},
     {1,2},
     {1,3},
     {1,4},
     {1,5},
...
     {2,2},
     {2,3},
     {2,4},
...
     {n,n},
}
*/

testing and failing again and again ... Well, in addition to some error 
messages that I had not seen before

/*
"Invalid dimension size for an array"
"array subscript out of range"
"Negative subscript"
"std: bad_alloc"
*/

I ended up giving with a code that besides being wrong kicked my Ubuntu 
in the face, (with pov under Wine it took a while to recover, but it 
comes out.) Be careful not to have anything important open if you try 
it, the lines that generate the error are in comment lines on purpose I 
do not ask for a solution and I do not think that it is exactly a 
mistake of the program, but I leave it there as a curiosity.

BGimeno

pd. Factorial(n) code isn't mine, I've found it today, and very useful.


#include "math.inc"
// ************************************
#macro ArrayWriter (filename,n_sides)
  // --------------------------------------
#local n_sides = int(n_sides);
#macro Factorial(N)
   #local Result = 1;
   #local Ind = 2;
   #while(Ind <= N)
     #local Result = Result*Ind;
     #local Ind = Ind+1;
   #end
   Result
#end
  // -----------------------------------------------------------
/* // BEWARE OF NEXT CODE
// Creates an array with every pair of numbers
// #local Pairs_arr = array [Factorial(n_sides*2)][(n_sides*2)-1]
// #local C = 0 ;  #while (C<=(n_sides*2)-1)
// #local C2 = 0 ;  #while (C2<=(n_sides*2)-1)
//
//   #local Pairs_arr [C][C2] = C2 ;
//
// #local C2 = C2 + 1 ; #end
// #local C = C + 1 ; #end
*/
  // --------------------------------------
  #fopen My_arr concat(filename,".txt") write #fclose My_arr
  #fopen My_arr concat(filename".txt") append
  // ---------Header  ---------------------
  #write (My_arr,concat("#declare The_",str(n_sides,0,0),"_array ["
          str(Factorial(n_sides),0,0)"],["
          str(n_sides*2,0,0)"]{\n"))
  // ---------Array -----------------------
  #local n_sides_r=1;
  #while (n_sides_r<=n_sides*2)
  #write (
          My_arr,concat(
                        #if (n_sides_r=1) " {" #end
                        #if (odd(n_sides_r)=true) 
"T"str(n_sides,0,0)"_"#end
                        str(Pairs_arr[n_sides_r-1],-2,0),
                        #if (even(n_sides_r)=true) #if 
(n_sides_r<(n_sides*2)-1)"," #else "}\n" #end
                        #else "_" #end
                       )
  )
  #local n_sides_r=n_sides_r+1;
  #end
#write (My_arr,concat("}\n"))

  // --------------------------------------
  #fclose My_arr
#end // end of macro
ArrayWriter("test",6)


Post a reply to this message

From: clipka
Subject: Re: The way to an ideal array is a kick in the face
Date: 26 Sep 2018 20:58:49
Message: <5bac2b49$1@news.povray.org>
Am 26.09.2018 um 23:52 schrieb BGimeno:
> 
> While I was trying to generate and list a huge array with pairs of
> numbers of this style,

Version information, please. There have been recent changes regarding
arrays that are likely to be relevant.


Post a reply to this message

From: clipka
Subject: Re: The way to an ideal array is a kick in the face
Date: 26 Sep 2018 22:23:09
Message: <5bac3f0d$1@news.povray.org>
Am 26.09.2018 um 23:52 schrieb BGimeno:

> I ended up giving with a code that besides being wrong kicked my Ubuntu
> in the face, (with pov under Wine it took a while to recover, but it
> comes out.) Be careful not to have anything important open if you try
> it, the lines that generate the error are in comment lines on purpose I
> do not ask for a solution and I do not think that it is exactly a
> mistake of the program, but I leave it there as a curiosity.

Fun fact: 32-bit versions of POV-Ray may be immune to the scene. I've
just seen "bad allocation", and that's it.

Maybe that's because you'd need 20 GiB (or 40 GiB on a 64-bit machine)
of memory for that empty array alone.


> pd. Factorial(n) code isn't mine, I've found it today, and very useful.

Factorial's a bitch. The numbers tend to explode in your face.


Post a reply to this message

From: BGimeno
Subject: Re: The way to an ideal array is a kick in the face
Date: 27 Sep 2018 04:00:13
Message: <5bac8e0d$1@news.povray.org>
El 27/09/18 a las 02:58, clipka escribió:

> Version information, please. There have been recent changes regarding
> arrays that are likely to be relevant.
> 
// ---------------------------------------------------
POV-Ray 3.7.0.4.unofficial

This is an unofficial version compiled by:
  Andreas Beckmann <anbe at debian dot org> for Debian <www.debian.org>
  The POV-Ray Team is not responsible for supporting this version.

Copyright 1991-2013 Persistence of Vision Raytracer Pty. Ltd.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Built-in features:
   I/O restrictions:          enabled
   X Window display:          enabled (using SDL)
   Supported image formats:   gif tga iff ppm pgm hdr png jpeg tiff openexr
   Unsupported image formats: -

Compilation settings:
   Build architecture:  x86_64-pc-linux-gnu
   Built/Optimized for: x86_64-pc-linux-gnu
   Compiler vendor:     gnu
   Compiler version:    g++ 7
   Compiler flags:      -pipe -Wno-multichar -Wno-write-strings 
-fno-enforce-eh-specs -Wno-non-template-friend -g -O2 
-fdebug-prefix-map=/build/povray-nyWGZ3/povray-3.7.0.4=. 
-fstack-protector-strong -Wformat -Werror=format-security -O3 -pthread

-----------OS---------------------------
#> uname -a
Linux bgimeno-HP-Elite-7500-Series-MT 4.15.0-34-generic #37-Ubuntu SMP 
Mon Aug 27 15:21:48 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux


I bet the problem is due to an idea carried out in the wrong way mixed 
with factorials and loops. Declaring "blind" arrays like this implies 
knowing exactly what and how you are doing. It's not my case. The kick 
should be in my face for believing that the KISS principle was to listen 
to Gene Simmons until 2AM

BGimeno


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.