Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion coding maxstar
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Neal Becker  
View profile  
 More options Nov 9 2012, 9:07 am
From: Neal Becker <ndbeck...@gmail.com>
Date: Fri, 9 Nov 2012 09:07:19 -0500
Local: Fri, Nov 9 2012 9:07 am
Subject: Re: [numexpr] coding maxstar

Wow!  I'm impressed!  Even without MKL, I'm measuring:

c++ version:
%time test1()
CPU times: user 4.16 s, sys: 0.00 s, total: 4.16 s
Wall time: 4.15 s

numexpr version:
In [34]: %time test1()
CPU times: user 3.53 s, sys: 0.01 s, total: 3.53 s
Wall time: 1.87 s

The full function, which accepts n-ary args is:

def maxstar (*args):
    if len(args) == 1:
        return args[0]
    elif len(args) == 2:
        return maxstar2 (*args)
    else:
        return maxstar2 (
            maxstar (*args[:len(args)/2]),
            maxstar (*args[len(args)/2:])
            )

I'm guessing to just leave this function as pure python - nothing numexpr
can do to help here.

On Fri, Nov 9, 2012 at 8:52 AM, Francesc Alted <fal...@gmail.com> wrote:
> On 11/9/12 1:26 PM, Neal Becker wrote:

>> My problem is to code maxstar function.  For 2 arguments, it is:

>> def maxstar2 (a, b):
>>     return max (a, b ) + log1p (exp (-abs (a - b)))

>> What I have now, is using 'ndarray'
>> https://github.com/ndarray/**ndarray.git<https://github.com/ndarray/ndarray.git>

>> to convert the corresponding c++ code into a binary ufunc.

>> The way this would be applied is to pass 2 large vectors, and the
>> maxstar2 would be applied to the pairs of elements of these vectors.

>> Ultimately, it is intended to operate any more than 2 inputs, but I
>> already have recursive code in python based on maxstar2 which extends to
>> arbitrary # of inputs, and for large vectors the python overhead is
>> probably OK.

>> So I'm wondering if I can use numexpr here.  The above maxstar2 isn't
>> usable directly - it has to be converted to a binary ufunc first (as
>> written it only works on 2 scalars - not 2 vectors).

> If I understand you correctly, you can evaluate the above expression as:

> ne.evaluate('where(a>b, a, b) + log1p (exp (-abs (a - b)))')

> Here it is an actual example:

> In []: a = np.arange(1e7)

> In []: b = a + 1

> In []: time np.where(a>b, a, b) + np.log1p (np.exp (-np.abs (a - b)))
> CPU times: user 1.11 s, sys: 1.20 s, total: 2.31 s
> Wall time: 6.36 s
> Out[]:
> array([  1.31326169e+00,   2.31326169e+00,   3.31326169e+00, ...,
>          9.99999831e+06,   9.99999931e+06,   1.00000003e+07])

> In []: time ne.evaluate('where(a>b, a, b) + log1p (exp (-abs (a - b)))')
> CPU times: user 0.55 s, sys: 0.12 s, total: 0.68 s
> Wall time: 0.43 s
> Out[]:
> array([  1.31326169e+00,   2.31326169e+00,   3.31326169e+00, ...,
>          9.99999831e+06,   9.99999931e+06,   1.00000003e+07])

> [not using VML here]

> --
> Francesc Alted

> --
> You received this message because you are subscribed to the Google Groups
> "numexpr" group.
> To post to this group, send email to numexpr@googlegroups.com.
> To unsubscribe from this group, send email to numexpr+unsubscribe@**
> googlegroups.com <numexpr%2Bunsubscribe@googlegroups.com>.
> For more options, visit this group at http://groups.google.com/**
> group/numexpr?hl=en <http://groups.google.com/group/numexpr?hl=en>.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.