Esempio n. 1
0
class Vector(GenericMethods):
    @generic
    def __init__(self):
        self._vector = ArrayRealVector()
    
    @specmethod.__init__
    @sign(list)
    def init_fromlist(self, data):
        self._vector = ArrayRealVector(data)
    
    @specmethod.__init__
    @sign(ArrayRealVector)
    def init_fromcommons(self, v):
        self._vector = v
    
    def __repr__(self):
        return str(self._vector)
    
    def __add__(self, other):
        return Vector(self._vector.add(other._vector))
    
    def __sub__(self, other):
        return Vector(self._vector.subtract(other._vector))
    
    def __mul__(self, other):
        if isinstance(other, Number):
            return Vector(self._vector.mapMultiply(other))
        else:
            return self._vector.dotProduct(other._vector)

    def __getitem__(self, i):
        if 0 <= i < len(self):
            return self._vector.getEntry(i)
        else:
            raise IndexError
    
    def __setitem__(self, i, val):
        if 0 <= i < len(self):
            return self._vector.setEntry(i, val)
        else:
            raise IndexError

    def __len__(self):
        return self._vector.getDimension()
    
    @property
    def norm(self):
        return self._vector.getNorm()
Esempio n. 2
0
class Vector(GenericMethods):
    @generic
    def __init__(self):
        self._vector = ArrayRealVector()

    @specmethod.__init__
    @sign(list)
    def init_fromlist(self, data):
        self._vector = ArrayRealVector(data)

    @specmethod.__init__
    @sign(ArrayRealVector)
    def init_fromcommons(self, v):
        self._vector = v

    def __repr__(self):
        return str(self._vector)

    def __add__(self, other):
        return Vector(self._vector.add(other._vector))

    def __sub__(self, other):
        return Vector(self._vector.subtract(other._vector))

    def __mul__(self, other):
        if isinstance(other, Number):
            return Vector(self._vector.mapMultiply(other))
        else:
            return self._vector.dotProduct(other._vector)

    def __getitem__(self, i):
        if 0 <= i < len(self):
            return self._vector.getEntry(i)
        else:
            raise IndexError

    def __setitem__(self, i, val):
        if 0 <= i < len(self):
            return self._vector.setEntry(i, val)
        else:
            raise IndexError

    def __len__(self):
        return self._vector.getDimension()

    @property
    def norm(self):
        return self._vector.getNorm()
Esempio n. 3
0
 def __init__(self):
     self._vector = ArrayRealVector()
Esempio n. 4
0
 def init_fromlist(self, data):
     self._vector = ArrayRealVector(data)
Esempio n. 5
0
 def __init__(self):
     self._vector = ArrayRealVector()
Esempio n. 6
0
 def init_fromlist(self, data):
     self._vector = ArrayRealVector(data)