LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-17-2015, 08:05 AM   #1
rdx
Member
 
Registered: Apr 2007
Location: Dallas
Distribution: Slackware64 14.2
Posts: 283

Rep: Reputation: 25
program in python, using numpy is disappointingly slow.


Is there some trick to telling python (2.7) about ATLAS? I wrote a function to find the intersection of a line and a plane, first in C++, then in Python and then in PHP. Even PHP, which is mathematically challenged, run 3x faster than Python.

Code:
def ray_test( ray, plane ) :
    d = ray.get_delta()
    if np.dot( d, plane.normal() ) > -1e-9 :
        return 0
    p0 = plane.get_p0()
    A = np.transpose( [-d, plane.get_p1() - p0, plane.get_p2() - p0] )
    return np.linalg.solve( A, ray.get_origin() - p0 )
As you can see, I call dot and cross products, transpose and solve, which should be passed on to the ATLAS library but it doesn't seem like it is. What am I doing wrong?

Last edited by rdx; 11-17-2015 at 08:08 AM.
 
Old 11-18-2015, 04:53 PM   #2
genss
Member
 
Registered: Nov 2013
Posts: 741

Rep: Reputation: Disabled
idk python but isn't numpy made for such things ?
 
Old 11-19-2015, 09:35 AM   #3
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 11,225

Rep: Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320
numpy needs to have ATLAS support compiled into it. Check that.
 
1 members found this post helpful.
Old 11-19-2015, 11:39 AM   #4
rdx
Member
 
Registered: Apr 2007
Location: Dallas
Distribution: Slackware64 14.2
Posts: 283

Original Poster
Rep: Reputation: 25
Quote:
Originally Posted by dugan View Post
numpy needs to have ATLAS support compiled into it. Check that.
Okay, that sounds promising. I'm not sure how to do that but I'll look into it. The same function in C++:
Code:
#include    <armadillo>

vec ray_test( Ray3D &ray, Plane3D &plane )
{
    vec     d, p0, p1, p2, vi, vo ;
    mat     A ;

    d = ray.delta() ;
    if( ( dot( d, plane.normal() )) > -1e-9 )
        return vo ;
    p0 = plane.point( 0 ) ;
    p1 = plane.point( 1 ) - p0 ;
    p2 = plane.point( 2 ) - p0 ;

    A = join_rows( -d, p1 ) ;
    A = join_rows( A, p2 ) ;
    return solve( A, ray.origin() - p0 ) ;
}
This is more than 300x faster than python.
 
Old 11-19-2015, 12:56 PM   #5
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 11,225

Rep: Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320
Quote:
Originally Posted by rdx View Post
Okay, that sounds promising. I'm not sure how to do that but I'll look into it.
If you're building numpy from source, then you simply have ATLAS installed when you build numpy. While I haven't confirmed this personally, you would likely see in the console output that ATLAS was detected at compile time.

http://docs.scipy.org/doc/numpy/user/install.html

If you're downloading prebuilt numpy packages from your distribution's repositories, then they should have ATLAS as a dependency.
 
Old 11-20-2015, 08:53 AM   #6
rdx
Member
 
Registered: Apr 2007
Location: Dallas
Distribution: Slackware64 14.2
Posts: 283

Original Poster
Rep: Reputation: 25
What I did was grab Numpy 1.9.1 from Slackbuilds.org and process it as usual ( bash numpy.Slackbuild) which compiles th source and creates a Slackware package, and then installpkg on the package it created. Atlas is installed as lapack-atlas-3.3.1-x86-64-1_SBo according to my package list ( in /var/log/packages ). I saw no indication on an option to include ATLAS nor any mention that it has done so. I'm pretty sure the Armadillo package and C++ are using it though.
 
Old 11-20-2015, 11:42 AM   #7
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 11,225

Rep: Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320
I'm out of ideas. I'd recommend contacting the person who maintains those SlackBuilds and pointing the maintainer to this thread.
 
Old 11-21-2015, 12:50 PM   #8
rdx
Member
 
Registered: Apr 2007
Location: Dallas
Distribution: Slackware64 14.2
Posts: 283

Original Poster
Rep: Reputation: 25
I suppose what I need to do is link the C++ version into a Python lib so I can import it and use it. I'll put that on my list of things to do and maybe, in a year ot two, ... lol
 
Old 11-22-2015, 03:47 AM   #9
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 11,225

Rep: Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320
Quote:
Originally Posted by rdx View Post
I suppose what I need to do is link the C++ version into a Python lib so I can import it and use it. I'll put that on my list of things to do and maybe, in a year ot two, ... lol
Or you could contact the SlackBuild maintainer like I recommended?
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: NumPy python tutorial LXer Syndicated Linux News 0 11-13-2014 12:11 AM
New user: python numpy import error CosmicThespian Linux - Newbie 13 10-17-2011 09:14 PM
Installing Python NUMPY on Godaddy server strimp099 Linux - Server 0 02-12-2011 07:03 AM
python error , import numpy ufmale Programming 2 08-25-2008 11:59 PM
Visual Python/Numpy uranologist Linux - Software 0 09-28-2003 10:08 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:13 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration