Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adjusted L8 to TP and TC #1

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 17 additions & 24 deletions L8_case-study_mandelbrot/Fractal_tier1.sac
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export all;

/** <!--*******************************************************************-->
*
* @fn : complex[.,.] genComplexArray( int[2] shp, complex cmin, complex cmax)
* @fn : complex[2:shp] genComplexArray( int[2] shp, complex cmin, complex cmax)
*
* @brief generates an array of complex numbers with shape "shp" and
* linearly increasing/decreasing values between "cmin" and "cmax".
Expand All @@ -17,13 +17,12 @@ export all;
*
*****************************************************************************/
inline
complex[.,.] genComplexArray( int[2] shp, complex cmin, complex cmax)
complex[2:shp] genComplexArray( int[2] shp, complex cmin, complex cmax)
{
res = with {
( . <= iv <= .) : cmin + toc( reverse( (tod(iv) / tod(shp))
* reverse( todv(cmax-cmin))));
} : genarray( shp, toc( 0,0));
return( res);
diff = cmax - cmin;
delta = [imag (diff) / tod( shp[0]) , real (diff) / tod (shp[1])];

return { iv -> cmin + toc (tod (iv) * delta) | iv < shp };
}


Expand All @@ -41,31 +40,27 @@ complex[.,.] genComplexArray( int[2] shp, complex cmin, complex cmax)
inline
int escapeTime(complex z, int depth)
{
i=0; c=z;
i=0; c=z;

while( (normSq( c) <= 4d) && (i <= depth)) {
c=c*c+z; i++;
}
while( (normSq( c) <= 4d) && (i <= depth)) {
c=c*c+z; i++;
}

return(i);
return(i);
}

/** <!--*******************************************************************-->
*
* @fn int[*] escapeTime(complex[*] z, int depth)
* @fn int[n:shp] escapeTime(complex[n:shp] z, int depth)
*
* @brief maps escapeTime to an entire array of complex numbers
*
*****************************************************************************/

inline
int[*] escapeTime( complex[*] plane, int depth)
int[n:shp] escapeTime( complex[n:shp] plane, int depth)
{
values = with {
( . <= iv <= .) : escapeTime( plane[iv], depth);
} : genarray( shape( plane), 0);

return( values);
return { iv -> escapeTime (plane[iv], depth) };
}

/** <!--*******************************************************************-->
Expand All @@ -78,13 +73,11 @@ int[*] escapeTime( complex[*] plane, int depth)
inline
Color8::color[.,.] intArrayToMonochrome( int[.,.] a)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add type patterns here as well?

Color8::color[n,m] intArrayToMonochrome( int[n,m] a)

{
clut = genLogarithmicClut( 0.4d, 0.9d, Color8::black(), Color8::red());
clut = genLogarithmicClut( 0.4d, 0.9d, Color8::black(), Color8::red());

a = (a * 255) / maxval(a);
a = (a * 255) / maxval(a);

d = with {
( .<= iv <= .) : clut[ a[ iv]];
} : genarray( shape(a), Color8::black());
return { iv -> clut[ a[ iv]] };

return( d);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return( d); needs to be deleted

}
Expand Down
37 changes: 18 additions & 19 deletions L8_case-study_mandelbrot/Fractal_tier1_empty.sac
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,20 @@ export all;

/** <!--*******************************************************************-->
*
* @fn : complex[.,.] genComplexArray( int[2] shp, complex cmin, complex cmax)
* @fn : complex[2:shp] genComplexArray( int[2] shp, complex cmin, complex cmax)
*
* @brief generates an array of complex numbers with shape "shp" and
* linearly increasing/decreasing values between "cmin" and "cmax".
* The element at index [0,0] should be "cmin". Increases in the
* The element at index [0,0] should be "cmin". Increases in the
* 2nd index (!) should reflect increases in the real values!
*
*****************************************************************************/
inline
complex[.,.] genComplexArray( int[2] shp, complex cmin, complex cmax)
complex[2:shp] genComplexArray( int[2] shp, complex cmin, complex cmax)
{
/**
* fill in here...
*/
/**
* fill in here...
*/
}


Expand All @@ -39,24 +39,25 @@ complex[.,.] genComplexArray( int[2] shp, complex cmin, complex cmax)
inline
int escapeTime(complex z, int depth)
{
/**
* fill in here...
*/
/**
* fill in here...
*/
}

/** <!--*******************************************************************-->
*
* @fn int[*] escapeTime(complex[*] z, int depth)
* @fn int[n:shp] escapeTime(complex[n:shp] z, int depth)
*
* @brief maps escapeTime to an entire array of complex numbers
*
*****************************************************************************/

inline int[*] escapeTime( complex[*] plane, int depth)
inline
int[n:shp] escapeTime( complex[n:shp] plane, int depth)
{
/**
* fill in here...
*/
/**
* fill in here...
*/
}

/** <!--*******************************************************************-->
Expand All @@ -69,13 +70,11 @@ inline int[*] escapeTime( complex[*] plane, int depth)
inline
Color8::color[.,.] intArrayToMonochrome( int[.,.] a)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add type patterns here as well?

Color8::color[n,m] intArrayToMonochrome( int[n,m] a)

{
clut = genLogarithmicClut( 0.4d, 0.9d, Color8::black(), Color8::red());
clut = genLogarithmicClut( 0.4d, 0.9d, Color8::black(), Color8::red());

a = (a * 256) / maxval(a);
a = (a * 255) / maxval(a);

d = with {
( .<= iv <= .) : clut[ a[ iv]];
} : genarray( shape(a), Color8::black());
return { iv -> clut[ a[ iv]] };

return( d);
}
Expand Down
40 changes: 14 additions & 26 deletions L8_case-study_mandelbrot/Fractal_tier2.sac
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export all;

/** <!--*******************************************************************-->
*
* @fn complex escapeValue(complex z, int depth)
* @fn int, complex escapeTimeAndValue (complex z, int depth)
*
* @brief iteratively computes c = c*c + z starting from c=z.
* terminates either when |c| > 2 or depth iterations
Expand All @@ -16,46 +16,34 @@ export all;
*
* @return final complex value
*****************************************************************************/
int, complex escapeTimeAndValue(complex z, int depth)
int, complex escapeTimeAndValue (complex z, int depth)
{
i=0; c=z;
i=0; c=z;

while( (normSq( c) <= 4d) && (i <= depth)) {
c=c*c+z; i++;
}
while( (normSq( c) <= 4d) && (i <= depth)) {
c=c*c+z; i++;
}

return(i, c);
return(i, c);
}

/** <!--*******************************************************************-->
*
* @fn complex[*] escapeValue(complex[*] z, int depth)
* @fn int[m,n], complex[m,n] escapeTimeAndValue (complex[m,n] z, int depth)
*
* @brief maps escapeValue to an entire array of complex numbers
*
*****************************************************************************/
inline
int[.,.], complex[.,.] escapeTimeAndValue( complex[.,.] plane, int depth)
int[m,n], complex[m,n] escapeTimeAndValue ( complex[m,n] plane, int depth)
{
times = with {
( . <= x <= .) {
t, v = escapeTimeAndValue( plane[x], depth);
} : t;
} : genarray( shape( plane), 0);

values = with {
( . <= x <= .) {
t, v = escapeTimeAndValue( plane[x], depth);
} : v;
} : genarray( shape( plane), toc(0));

return( times, values);
return { iv -> escapeTimeAndValue (plane[iv]) };

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does not compile for 3 reasons: parser cannot handle the implicated 2 return arguments, escapeTimeAndValue also needs depth, and iv will become an int[3] instead of int[2] as complex[m, n] is typedef'd to double[m, n, 2] currently. This works

    escape, values = { iv -> escapeTimeAndValue (plane[iv], depth) 
                          | iv < [m, n] };
    return (escape, values);

}


/** <!--*******************************************************************-->
*
* @fn double normalizedIterationCount(int n, complex zn)
* @fn double[d:shp] normalizedIterationCount (int[d:shp] n, complex[d:shp] zn)
*
* @brief normalizes the iteration counts in "n" taking the distance of the
* corresponding final complex numbers from the origin into account.
Expand All @@ -66,15 +54,15 @@ int[.,.], complex[.,.] escapeTimeAndValue( complex[.,.] plane, int depth)
* @return the normalized iteration counts
*****************************************************************************/
inline
double[*] normalizedIterationCount(int[*] n, complex[*] zn)
double[d:shp] normalizedIterationCount(int[d:shp] n, complex[d:shp] zn)
{
return( where( (norm( zn) <= 2d) , 0d , tod(n+1) - log2( log2( norm( zn)))));
}


/** <!--*******************************************************************-->
*
* @fn color[.,.] doubleArrayToRGB( double[.,.] a)
* @fn color[d:shp] doubleArrayToRGB( double[d:shp] a)
*
* @brief transforms an array of doubles into RGB values, by
* FIRST scaling them into values between 0.0 and 360.0, and
Expand All @@ -85,7 +73,7 @@ double[*] normalizedIterationCount(int[*] n, complex[*] zn)
* @return RGB values
*****************************************************************************/
inline
Color8::color[.,.] doubleArrayToRGB( double[.,.] a)
Color8::color[d:shp] doubleArrayToRGB( double[d:shp] a)
{
max = maxval( a);
min = minval( a);
Expand Down
45 changes: 20 additions & 25 deletions L8_case-study_mandelbrot/Fractal_tier2_empty.sac
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export all;

/** <!--*******************************************************************-->
*
* @fn complex escapeValue(complex z, int depth)
* @fn int, complex escapeTimeAndValue (complex z, int depth)
*
* @brief iteratively computes c = c*c + z starting from c=z.
* terminates either when |c| > 2 or depth iterations
Expand All @@ -16,39 +16,34 @@ export all;
*
* @return final complex value
*****************************************************************************/
inline
complex escapeValue(complex z, int depth)
int, complex escapeTimeAndValue (complex z, int depth)
{
i=0; c=z;
i=0; c=z;

while( (normSq( c) <= 4d) && (i <= depth)) {
c=c*c+z; i++;
}
while( (normSq( c) <= 4d) && (i <= depth)) {
c=c*c+z; i++;
}

return(c);
return(i, c);
}

/** <!--*******************************************************************-->
*
* @fn complex[*] escapeValue(complex[*] z, int depth)
* @fn int[m,n], complex[m,n] escapeTimeAndValue (complex[m,n] z, int depth)
*
* @brief maps escapeValue to an entire array of complex numbers
*
*****************************************************************************/
inline
complex[.,.] escapeValue( complex[.,.] plane, int depth)
int[m,n], complex[m,n] escapeTimeAndValue ( complex[m,n] plane, int depth)
{
values = with {
( . <= x <= .) : escapeValue( plane[x], depth);
} : genarray( shape( plane), toc(0));

return( values);
return { iv -> escapeTimeAndValue (plane[iv]) };
}


/** <!--*******************************************************************-->
*
* @fn double normalizedIterationCount(int n, complex zn)
* @fn double[d:shp] normalizedIterationCount (int[d:shp] n, complex[d:shp] zn)
*
* @brief normalizes the iteration counts in "n" taking the distance of the
* corresponding final complex numbers from the origin into account.
Expand All @@ -59,17 +54,17 @@ complex[.,.] escapeValue( complex[.,.] plane, int depth)
* @return the normalized iteration counts
*****************************************************************************/
inline
double[*] normalizedIterationCount(int[*] n, complex[*] zn)
double[d:shp] normalizedIterationCount(int[d:shp] n, complex[d:shp] zn)
{
/**
* fill in here...
*/
/**
* fill in here...
*/
}


/** <!--*******************************************************************-->
*
* @fn color[.,.] doubleArrayToRGB( double[.,.] a)
* @fn color[d:shp] doubleArrayToRGB( double[d:shp] a)
*
* @brief transforms an array of doubles into RGB values, by
* FIRST scaling them into values between 0.0 and 360.0, and
Expand All @@ -80,11 +75,11 @@ double[*] normalizedIterationCount(int[*] n, complex[*] zn)
* @return RGB values
*****************************************************************************/
inline
Color8::color[.,.] doubleArrayToRGB( double[.,.] a)
Color8::color[d:shp] doubleArrayToRGB( double[d:shp] a)
{
/**
* fill in here...
*/
/**
* fill in here...
*/
}


Expand Down
7 changes: 2 additions & 5 deletions L8_case-study_mandelbrot/mandelbrot.sac
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,9 @@ use Fractal_tier2 : all;
use Stencil_tier3 : all;

inline
color[.,.] stretchRgb( color[.,.] pic, int stretch)
color[ms,ns] stretchRgb( color[m,n] pic, int stretch)
{
res = with {
(. <= iv <= .): pic[ iv / stretch];
} : genarray( shape(pic) * stretch, black());
return( res);
return { iv -> pic[ iv / stretch] | iv < shape(pic) * stretch };
}

/* Main ******************************************************************** */

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

plane does not have a fixed shape, as it increases during the do-while loop.

It is then used outside of this do-while loop in:

q, zoom_coords = getSelectionMulti( disp, [2,2]);
if (all( zoom_coords >= 0)) {
  cmin = [plane[ zoom_coords[[0]]]] ++ cmin;
  cmax = [plane[ zoom_coords[[1]]]] ++ cmax;
} else {
  cmin = all( shape(cmin) > 1) ? drop( [1], cmin) : cmin;
  cmax = all( shape(cmax) > 1) ? drop( [1], cmax) : cmax;
}

Which seems to be problematic.
Easiest fix would be to just recalculate plane with the correct shape, it is relatively cheap anyways.

q, zoom_coords = getSelectionMulti( disp, [2,2]);
if (all( zoom_coords >= 0)) {
  plane = genComplexArray(EXPAND * [YRES,XRES], cmin[0], cmax[0]);
  cmin = [plane[ zoom_coords[[0]]]] ++ cmin;
  cmax = [plane[ zoom_coords[[1]]]] ++ cmax;
} else {
  cmin = all( shape(cmin) > 1) ? drop( [1], cmin) : cmin;
  cmax = all( shape(cmax) > 1) ? drop( [1], cmax) : cmax;
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

???? as you correctly noticed, this is outside the do-loop..... so plane should be at maximum size here anyways.... how can this be "problematic"????

Expand Down
7 changes: 2 additions & 5 deletions L8_case-study_mandelbrot/mandelbrot_simple.sac
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,9 @@ use Fractal_tier1 : all;
use Fractal_tier2 : all;

inline
color[.,.] stretchRgb( color[.,.] pic, int stretch)
color[ms,ns] stretchRgb( color[m,n] pic, int stretch)
{
res = with {
(. <= iv <= .): pic[ iv / stretch];
} : genarray( shape(pic) * stretch, black());
return( res);
return { iv -> pic[ iv / stretch] | iv < shape(pic) * stretch };
}

/* Main ******************************************************************** */
Expand Down
Loading