1cimport cython 2 3from cython cimport _testscope as tester 4from cython cimport TestClass, _testclass_new as TestClass_New 5from cython cimport test_call, test_dep 6from cython.view cimport _testscope as viewtester 7 8from cpython cimport PyObject 9 10cdef extern from *: 11 # TestClass stuff 12 cdef struct __pyx_TestClass_obj: 13 int value 14 15 # Type pointer 16 cdef PyObject *TestClassType "__pyx_TestClass_type" 17 18 # This is a cdef function 19 cdef __pyx_TestClass_New(int) 20 21 # These are methods and therefore have no prototypes 22 cdef __pyx_TestClass_cdef_method(TestClass self, int value) 23 cdef __pyx_TestClass_cpdef_method(TestClass self, int value, int skip_dispatch) 24 cdef __pyx_TestClass_def_method(object self, object value) 25 26 cdef __pyx_TestClass_cdef_cname(TestClass self, int value) 27 cdef __pyx_TestClass_cpdef_cname(TestClass self, int value, int skip_dispatch) 28 cdef __pyx_TestClass_def_cname(object self, object value) 29 30 cdef __pyx_test_dep(object) 31 cdef __pyx_test_call_other_cy_util(object) 32 33 34def test_cdef_cython_utility(): 35 """ 36 >>> test_cdef_cython_utility() 37 hello from cython scope, value=4 38 hello from cython.view scope, value=4 39 hello from cython scope, value=3 40 hello from cython.view scope, value=3 41 """ 42 print cython._testscope(4) 43 print cython.view._testscope(4) 44 print tester(3) 45 print viewtester(3) 46 47def test_cdef_class_cython_utility(): 48 """ 49 >>> test_cdef_class_cython_utility() 50 7 51 14 52 TestClass(20) 53 TestClass(50) 54 """ 55 cdef __pyx_TestClass_obj *objstruct 56 57 obj = TestClass_New(7) 58 objstruct = <__pyx_TestClass_obj *> obj 59 print objstruct.value 60 61 obj = __pyx_TestClass_New(14) 62 objstruct = <__pyx_TestClass_obj *> obj 63 print objstruct.value 64 65 print (<object> TestClassType)(20) 66 print TestClass(50) 67 68def test_extclass_c_methods(): 69 """ 70 >>> test_extclass_c_methods() 71 Hello from cdef_method 1 72 Hello from cpdef_method 2 73 Hello from def_method 3 74 Hello from cdef_cname_method 4 75 Hello from cpdef_cname_method 5 76 Hello from def_cname_method 6 77 Hello from cdef_method 1 78 Hello from cpdef_method 2 79 Hello from def_method 3 80 Hello from cdef_cname_method 4 81 Hello from cpdef_cname_method 5 82 Hello from def_cname_method 6 83 """ 84 cdef TestClass obj1 = TestClass(11) 85 cdef TestClass obj2 = TestClass_New(22) 86 87 __pyx_TestClass_cdef_method(obj1, 1) 88 __pyx_TestClass_cpdef_method(obj1, 2, True) 89 __pyx_TestClass_def_method(obj1, 3) 90 91 __pyx_TestClass_cdef_cname(obj1, 4) 92 __pyx_TestClass_cpdef_cname(obj1, 5, True) 93 __pyx_TestClass_def_cname(obj1, 6) 94 95 __pyx_TestClass_cdef_method(obj2, 1) 96 __pyx_TestClass_cpdef_method(obj2, 2, True) 97 __pyx_TestClass_def_method(obj2, 3) 98 99 __pyx_TestClass_cdef_cname(obj2, 4) 100 __pyx_TestClass_cpdef_cname(obj2, 5, True) 101 __pyx_TestClass_def_cname(obj2, 6) 102 103def test_extclass_cython_methods(): 104 """ 105 >>> test_extclass_cython_methods() 106 Hello from cdef_method 1 107 Hello from cpdef_method 2 108 Hello from def_method 3 109 Hello from cdef_cname_method 4 110 Hello from cpdef_cname_method 5 111 Hello from def_cname_method 6 112 Hello from cdef_method 1 113 Hello from cpdef_method 2 114 Hello from def_method 3 115 Hello from cdef_cname_method 4 116 Hello from cpdef_cname_method 5 117 Hello from def_cname_method 6 118 """ 119 cdef TestClass obj1 = TestClass(11) 120 cdef TestClass obj2 = TestClass_New(22) 121 122 obj1.cdef_method(1) 123 obj1.cpdef_method(2) 124 obj1.def_method(3) 125 obj1.cdef_cname_method(4) 126 obj1.cpdef_cname_method(5) 127 obj1.def_cname_method(6) 128 129 obj2.cdef_method(1) 130 obj2.cpdef_method(2) 131 obj2.def_method(3) 132 obj2.cdef_cname_method(4) 133 obj2.cpdef_cname_method(5) 134 obj2.def_cname_method(6) 135 136def test_cython_utility_dep(): 137 """ 138 >>> test_cython_utility_dep() 139 test_dep first 140 test_call 141 test_dep second 142 test_dep third 143 test_call 144 test_dep fourth 145 """ 146 test_dep('first') 147 test_call('second') 148 __pyx_test_dep('third') 149 __pyx_test_call_other_cy_util('fourth') 150 151def viewobjs(): 152 """ 153 >>> viewobjs() 154 <strided and direct or indirect> 155 <strided and direct> 156 <strided and indirect> 157 <contiguous and direct> 158 <contiguous and indirect> 159 """ 160 print cython.view.generic 161 print cython.view.strided 162 print cython.view.indirect 163 #print cython.view.generic_contiguous 164 print cython.view.contiguous 165 print cython.view.indirect_contiguous 166