示例#1
0
文件: wrapper.py 项目: JuliaBru/pymor
class WrappedVector(CopyOnWriteVector):

    def __init__(self, vector):
        assert isinstance(vector, Vector)
        self._impl = vector

    @classmethod
    def from_instance(cls, instance):
        return cls(instance._impl)

    @classmethod
    def make_zeros(cls, subtype):
        return cls(Vector(subtype, 0))

    @property
    def subtype(self):
        return self._impl.dim

    @property
    def dim(self):
        return self._impl.dim

    @property
    def data(self):
        return np.frombuffer(self._impl.data(), dtype=np.float)

    def _copy_data(self):
        self._impl = Vector(self._impl)

    def _scal(self, alpha):
        self._impl.scal(alpha)

    def _axpy(self, alpha, x):
        self._impl.axpy(alpha, x._impl)

    def dot(self, other):
        return self._impl.dot(other._impl)

    def l1_norm(self):
        raise NotImplementedError

    def l2_norm(self):
        return m.sqrt(self.dot(self))

    def sup_norm(self):
        raise NotImplementedError

    def components(self, component_indices):
        raise NotImplementedError

    def amax(self):
        raise NotImplementedError
示例#2
0
文件: wrapper.py 项目: simon-ca/pymor
class WrappedVector(CopyOnWriteVector):
    def __init__(self, vector):
        assert isinstance(vector, Vector)
        self._impl = vector

    @classmethod
    def from_instance(cls, instance):
        return cls(instance._impl)

    @classmethod
    def make_zeros(cls, subtype):
        return cls(Vector(subtype, 0))

    @property
    def subtype(self):
        return self._impl.dim

    @property
    def dim(self):
        return self._impl.dim

    @property
    def data(self):
        return np.frombuffer(self._impl.data(), dtype=np.float)

    def _copy_data(self):
        self._impl = Vector(self._impl)

    def _scal(self, alpha):
        self._impl.scal(alpha)

    def _axpy(self, alpha, x):
        self._impl.axpy(alpha, x._impl)

    def dot(self, other):
        return self._impl.dot(other._impl)

    def l1_norm(self):
        raise NotImplementedError

    def l2_norm(self):
        return m.sqrt(self.dot(self))

    def sup_norm(self):
        raise NotImplementedError

    def components(self, component_indices):
        raise NotImplementedError

    def amax(self):
        raise NotImplementedError
示例#3
0
 def _copy_data(self):
     self._impl = Vector(self._impl)
示例#4
0
 def apply_one_vector(u):
     v = Vector(self.range.dim, 0)
     self._impl.apply(u._impl, v)
     return WrappedVector(v)
示例#5
0
 def copy(self):
     return type(self)(Vector(self._impl))
示例#6
0
 def make_zeros(cls, subtype):
     return cls(Vector(subtype, 0))
示例#7
0
 def zero_vector(self):
     return WrappedVector(Vector(self.dim, 0))
示例#8
0
 def _copy_data(self):
     self._impl = Vector(self._impl)