Skip to content

Commit

Permalink
Merge branch '_numpy' of git://github.com/dagss/cython into release
Browse files Browse the repository at this point in the history
  • Loading branch information
markflorisson committed Apr 10, 2012
2 parents bd7284c + 6f2271d commit 315efe4
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 13 deletions.
9 changes: 4 additions & 5 deletions Cython/Compiler/ExprNodes.py
Expand Up @@ -34,6 +34,8 @@
import Options
from Cython import Utils
from Annotate import AnnotationItem
from NumpySupport import numpy_transform_attribute_node, \
should_apply_numpy_hack

from Cython.Debugging import print_call_chain
from DebugFlags import debug_disposal_code, debug_temp_alloc, \
Expand Down Expand Up @@ -4459,18 +4461,15 @@ def analyse_attribute(self, env, obj_type = None):
# attribute.
pass
# NumPy hack
if (getattr(self.obj, 'type', None) and
obj_type.is_extension_type and
obj_type.objstruct_cname == 'PyArrayObject'):
from NumpySupport import numpy_transform_attribute_node
if (getattr(self.obj, 'type', None) and obj_type.is_extension_type
and should_apply_numpy_hack(obj_type)):
replacement_node = numpy_transform_attribute_node(self)
# Since we can't actually replace our node yet, we only grasp its
# type, and then the replacement happens in
# AnalyseExpresssionsTransform...
self.type = replacement_node.type
if replacement_node is not self:
return

# If we get here, the base object is not a struct/union/extension
# type, or it is an extension type and the attribute is either not
# declared or is declared as a Python method. Treat it as a Python
Expand Down
6 changes: 4 additions & 2 deletions Cython/Compiler/Main.py
Expand Up @@ -24,6 +24,10 @@

verbose = 0

standard_include_path = os.path.abspath(os.path.normpath(
os.path.join(os.path.dirname(__file__), os.path.pardir, 'Includes')))


class CompilationData(object):
# Bundles the information that is passed from transform to transform.
# (For now, this is only)
Expand Down Expand Up @@ -70,8 +74,6 @@ def __init__(self, include_directories, compiler_directives, cpp=False,

self.pxds = {} # full name -> node tree

standard_include_path = os.path.abspath(os.path.normpath(
os.path.join(os.path.dirname(__file__), os.path.pardir, 'Includes')))
self.include_directories = include_directories + [standard_include_path]

self.set_language_level(language_level)
Expand Down
17 changes: 14 additions & 3 deletions Cython/Compiler/NumpySupport.py
Expand Up @@ -2,13 +2,24 @@
# the NumPy ABI changed so that the shape, ndim, strides, etc. fields were
# no longer available, however the use of these were so entrenched in
# Cython codes

import PyrexTypes
import ExprNodes
import os
from StringEncoding import EncodedString

def should_apply_numpy_hack(obj_type):
if not obj_type.is_extension_type or obj_type.objstruct_cname != 'PyArrayObject':
return False
from Scanning import FileSourceDescriptor
from Main import standard_include_path
type_source = obj_type.pos[0]
if isinstance(type_source, FileSourceDescriptor):
type_source_path = os.path.abspath(os.path.normpath(type_source.filename))
return type_source_path == os.path.join(standard_include_path, 'numpy.pxd')
else:
return False

def numpy_transform_attribute_node(node):
import PyrexTypes
import ExprNodes
assert isinstance(node, ExprNodes.AttributeNode)

if node.obj.type.objstruct_cname != 'PyArrayObject':
Expand Down
6 changes: 3 additions & 3 deletions Cython/Compiler/ParseTreeTransforms.py
Expand Up @@ -18,7 +18,8 @@
from Cython.Compiler.StringEncoding import EncodedString
from Cython.Compiler.Errors import error, warning, CompileError, InternalError
from Cython.Compiler.Code import UtilityCode

from Cython.Compiler.NumpySupport import (should_apply_numpy_hack,
numpy_transform_attribute_node)
import copy


Expand Down Expand Up @@ -1797,8 +1798,7 @@ def visit_AttributeNode(self, node):
#print node.dump()
#return node
type = node.obj.type
if type.is_extension_type and type.objstruct_cname == 'PyArrayObject':
from NumpySupport import numpy_transform_attribute_node
if type.is_extension_type and should_apply_numpy_hack(type):
node = numpy_transform_attribute_node(node)

self.visitchildren(node)
Expand Down

0 comments on commit 315efe4

Please sign in to comment.