Esempio n. 1
0
def test_capi_buffer() -> None:
    assert 2. == sample.avg(array('d', [1, 2, 3]))
    assert 2. == sample.avg(np.array([1., 2., 3.]))
    with pytest.raises(TypeError):
        assert 2. == sample.avg([1., 2., 3.])
    with pytest.raises(TypeError):
        assert 2. == sample.avg(b"HELLO")

    a = np.array([[1., 2., 3.], [4., 5., 6.]])
    with pytest.raises(ValueError):
        assert 4.5 == sample.avg(a[:, 2])
    with pytest.raises(TypeError):
        assert 3.5 == sample.avg(a)

    assert 2. == sample.avg(a[0])
Esempio n. 2
0
import sample
print(sample.gcd(35,42))
print(sample.in_mandel(0,0,500))
print(sample.in_mandel(2.0,1.0,500))
print(sample.divide(42,8))
print(sample.avg([1,2,3]))
p1 = sample.Point(1,2)
p2 = sample.Point(4,5)
print(sample.distance(p1,p2))
Esempio n. 3
0
import sample
print(sample.gcd(42, 8))
print(sample.divide(42, 8))
p1 = sample.Point(2, 3)
p2 = sample.Point(4, 5)
print(p1)
print(p2)
print(sample.distance(p1, p2))

import array
a = array.array('d', [1, 2, 3])
print(sample.avg(a))
Esempio n. 4
0
import sample
print(sample.gcd(35,42))
print(sample.in_mandel(0,0,500))
print(sample.in_mandel(2.0,1.0,500))
print(sample.divide(42,8))
print(sample.avg([1,2,3]))
p1 = sample.Point(1,2)
p2 = sample.Point(4,5)
print(sample.distance(p1,p2))
#!usr/bin/env python
# -*- coding:utf-8 -*-

import sample

print('gcd:', sample.gcd(35, 42))
print('in_mandel:', sample.in_mandel(0, 0, 500))
print('in_mandel:', sample.in_mandel(2.0, 1.0, 500))
print('divide:', sample.divide(42, 8))
print('avg:', sample.avg([1, 2, 3]))

p1 = sample.Point(1, 2)
p2 = sample.Point(4, 5)
print('distance:', sample.distance(p1, p2))
                 library_dirs = [],
                 libraries = ['sample']
                 )
         ]
)

import sample
sample.gcd(42,8)

sample.divide(42,8)

p1 = sample.Point(2,3)
p2 = sample.Point(4,5)
sample.distance(p1,p2)

p1.x

p1.y

import array
a = array.array('d',[1,2,3])
sample.avg(a)

p1 = sample.Point(2,3)
# Usage if %extend Point is omitted
p1 = sample.Point()
p1.x = 2.0
p1.y = 3
sample.divide(42,8)

Esempio n. 7
0
import array
from sample import avg

print(avg(array.array('d',[1,2,3])))
try:
    import numpy
    print(avg(numpy.array([1., 2., 3.])))
except ImportError:
    pass

Esempio n. 8
0
import array
from sample import avg

print(avg(array.array('d', [1, 2, 3])))
try:
    import numpy

    print(avg(numpy.array([1., 2., 3.])))
except ImportError:
    pass
Esempio n. 9
0
a[1]

a[2]

import array
a = array.array('d', [1, 2, 3])
a

ptr_ = a.buffer_info()
ptr_

ctypes.cast(ptr, ctypes.POINTER(ctypes.c_double))

import sample
sample.avg([1, 2, 3])

sample.avg((1, 2, 3))

import array
sample.avg(array.array('d', [1, 2, 3]))

import numpy
sample.avg(numpy.array([1.0, 2.0, 3.0]))


class Point(ctypes.Structure):
    _fields_ = [('x', ctypes.c_double), ('y', ctypes.c_double)]


p1 = sample.Point(1, 2)