1. My sloppy ABS function ;-)

Sloppy of me, the abs function should have been as Jiri suggested.
And Carl's functions are indeed very clean, and not suprisingly, faster.

Robert, explain the speed difference between these examples:

--[Code 1]
integer a, b
a = 1
if a then b = 10 else b = 6 end if

--[Code2]
integer a,b
a = 1
b = 6 + a * 4

Why I ask ?
Cuz the '*' - approach (? spelled right ?)  is datatype independent.
And *slower*.

Anyways, if we're discussing algorithms,  here are a few more suggestions:

    * reproduce (object x, integer count) -- works like repeat, however all
elements are concato.. ? (the word behind the '&' operator)

    * turn (sequence s, integer level) -- turn the sequence s (swap the x-
and y-axis) as many levels deep as requested

    * scroll (sequence s, integer i) -- the last element becomes the first,
etc.

Three areas:
    - is it usefull (does it work with all datatypes, in all conditions) ?
    - is it fast ?
    - is the code clean or hack ?

Any one wants to have a go..
.. any one more suggestions for algorithms ?

Ralf

new topic     » topic index » view message » categorize

2. Re: My sloppy ABS function ;-)

This message is in MIME format. Since your mail reader does not understand
this format, some or all of this message may not be legible.

------_=_NextPart_001_01BDD5DE.CA4504BE
        charset="iso-8859-1"

Ralf suggested the functions:

> reproduce (object x, integer count)

I've often wanted something like this, usually to build background patterns.
Perhaps 'pattern' is a better name (but still not quite right).

> scroll (sequence s, integer i)

I'm unclear on this one. The description sounded like a reverse function,
but the name makes me think you mean something like:

        return s[i..length(s)] & s[1..i-1]

Could you clarify this?

Thanks.

-- David Cuny

------_=_NextPart_001_01BDD5DE.CA4504BE
        charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV=3D"Content-Type" CONTENT=3D"text/html; =
charset=3Diso-8859-1">
<META NAME=3D"Generator" CONTENT=3D"MS Exchange Server version =
5.5.2232.0">
<TITLE>RE: My sloppy ABS function blink</TITLE>
</HEAD>
<BODY>

<P><FONT SIZE=3D2>Ralf suggested the functions:</FONT>
</P>

<P><FONT SIZE=3D2>&gt; reproduce (object x, integer count)</FONT>
</P>

<P><FONT SIZE=3D2>I've often wanted something like this, usually to =
build background patterns. Perhaps 'pattern' is a better name (but =
still not quite right).</FONT></P>

<P><FONT SIZE=3D2>&gt; scroll (sequence s, integer i)</FONT>
</P>

<P><FONT SIZE=3D2>I'm unclear on this one. The description sounded like =
a reverse function, but the name makes me think you mean something =
like:</FONT></P>

<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <FONT SIZE=3D2>return =
s[i..length(s)] &amp; s[1..i-1]</FONT>
</P>

<P><FONT SIZE=3D2>Could you clarify this?</FONT>
</P>

<P><FONT SIZE=3D2>Thanks.</FONT>
</P>

<P><FONT SIZE=3D2>-- David Cuny</FONT>
</P>

</HTML>
------_=_NextPart_001_01BDD5DE.CA4504BE--

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

3. Re: My sloppy ABS function ;-)

David Cuny wrote:
> Ralf suggested the functions:
>> reproduce (object x, integer count)

> I've often wanted something like this, usually to build background
patterns. Perhaps 'pattern' is a better name (but still not quite right).

I have a couple of working approuches laying around, but I wanted to see
what other could come up with. Ive even got a version using power's to use
the '&' operator more efficiently though with my experience it seems the
method most heavily depending on Euphoria dynamic data management is the
fastest. A possible side effect of the policy of optimizing the most crucial
part that Robert still logically uses.

> scroll (sequence s, integer i)

> I'm unclear on this one. The description sounded like a reverse
function, but the name makes me think you mean something like:

>    return s[i..length(s)] & s[1..i-1]


>  Could you clarify this?

Yes, indeed thats what I mean, however, I doubt it is the most fast method
you can use, it is the most clean though.

Thanks for your response,

Ralf

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

4. Re: My sloppy ABS function ;-)

Ralf Nieuwenhuijsen wrote:
> Anyways, if we're discussing algorithms,  here are a few more suggestions:
>* reproduce (object x, integer count)
>-- works like repeat, however all
>elements are concato.. ? (the word behind the '&' operator)

if you meant:
   --x={1,2, {3,4, {5,6} } }
   --y=reproduce(x,3)
   --print(y)
   output:{{1,2,{3,4,{5,6}}},{1,2,{3,4,{5,6}}},{1,2,{3,4,{5,6}}}}
then there is no need for a seperate function 'reproduce'.
as function reproduce is simply:
   function reproduce(object z, integer num)
      return repeat(z,num)
   end function
which means you could have simply said:
   --y=repeat(x,3)
instead of y=reproduce(x,3) as above.

if, however, you mean something else, then i'm not
sure what that would be.

--Hawke'

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

5. Re: My sloppy ABS function ;-)

>if, however, you mean something else, then i'm not
>sure what that would be.


Well, consider the soft-coded repeat () function:

function repeat (object x, integer len)
sequence ret
    ret = {}
    for index = 1 to len do
        ret = append (ret, x)
    end for
    return ret
end function

Reproduce does the same, except:

    ret = ret & x

See the difference ?
We have two operators, but only one repeat () function..

Ralf Nieuwenhuijsen
nieuwen at xs4all.nl

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

6. Re: My sloppy ABS function ;-)

Ralf Nieuwenhuijsen wrote:
> Well, consider the soft-coded repeat () function:
>     ret = append (ret, x)
> Reproduce does the same, except:
>     ret = ret & x

okay i made several stabs at this... came up with
2 semifinalists thus far, shown below...
as far as benchmarking, the first is faster
if the number of reproductions is greater than
1000 or so... from 1 to 100 reproductions, the
second is faster... from 100-1000 they are
real close in speed... this is for variable
length sequences as well as variable dimension
sequences.  i was trying to think of applications
for this, and about the only one i could think of
was replicating bitmaps to place a line of bitmaps
on the screen along a single yaxis....if so, then
you might defnly wanna use #2 since your reproduction
count would almost assuredly be less than 100 or so.
another interesting thing i noted in testing:
for certain numbers between 1-100, the first function
seemed to *BOG DOWN* heavily... got really strange
times (120+seconds versus 1-2 seconds)... others may
wish to develop and test some benchmarks for these
functions and see if mileage varies...

take care--Hawke'

function reproduce1(object x, integer num)
--the more intuitive, perhaps even assumed answer to
--this problem. it seems to bog on certain sized
--values for num, as if the optimizations for
--x=x&y get "confused"...
sequence repro
   repro = {}
   for index = 1 to num do
       repro = repro & x
   end for
   return repro
end function

function reproduce2(object x, integer num)
--this is a routine that 'pokes' the values into an
--already properly sized sequence, saving time on
--reallocating larger and larger sequences...
--i'm sure this algorithm could be a real contender
--if someone were to recode it using "allocate" and
--"poke".  imho, it's still readable, intuitive and
--not a hack. also, for any values of num, it turns
--in consistent, steadily increasing times.
sequence repro
integer len
   len = length(x)
   repro = repeat(' ',len*num)          --allocate here
   for index = 1 to (num*len) by len do
      repro[index..index+len-1] = x     --poke here
   end for
   return repro
end function

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

Search



Quick Links

User menu

Not signed in.

Misc Menu