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
def _copy_data(self): self._impl = Vector(self._impl)
def apply_one_vector(u): v = Vector(self.range.dim, 0) self._impl.apply(u._impl, v) return WrappedVector(v)
def copy(self): return type(self)(Vector(self._impl))
def make_zeros(cls, subtype): return cls(Vector(subtype, 0))
def zero_vector(self): return WrappedVector(Vector(self.dim, 0))