How to use the nlp.tools.nullvector.NullVector function in nlp

To help you get started, we’ve selected a few nlp examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github PythonOptimizers / NLP.py / tests / tools / test_nullvector.py View on Github external
def test_add(self):
        uval = np.random.random()
        u = NullVector(self.n, uval, dtype=np.float)
        w = u + self.v
        assert(isinstance(w, NullVector))
        assert(len(w) == self.n)
        assert(w.value == np.float(self.val) + np.float(uval))
        assert(w.dtype == np.result_type(self.v.dtype, u.dtype))

        u = NullVector(self.n + 1, uval, dtype=np.float)
        assert_raises(ValueError, lambda y: y + self.v, u)

        w = u + 2
        assert(isinstance(w, NullVector))
        assert(w.value == uval + 2)

        u += 2
        assert(u.value == np.float(uval) + 2)
github PythonOptimizers / NLP.py / tests / tools / test_nullvector.py View on Github external
def test_div(self):
        uval = np.random.random() + 1  # Ensure nonzero.
        u = NullVector(self.n, uval, dtype=np.float)
        w = self.v / u
        assert(isinstance(w, NullVector))
        assert(len(w) == self.n)
        assert(w.value == np.float(self.val) / np.float(uval))
        assert(w.dtype == np.result_type(self.v.dtype, u.dtype))

        u = NullVector(self.n + 1, uval, dtype=np.float)
        assert_raises(ValueError, lambda y: self.v / y, u)

        w = u / 2
        assert(isinstance(w, NullVector))
        assert(w.value == uval / 2)

        u /= 2
        assert(u.value == np.float(uval) / 2)
github PythonOptimizers / NLP.py / tests / tools / test_nullvector.py View on Github external
def test_sub(self):
        uval = np.random.random()
        u = NullVector(self.n, uval, dtype=np.float)
        w = u - self.v
        assert(isinstance(w, NullVector))
        assert(len(w) == self.n)
        assert(w.value == np.float(uval) - np.float(self.val))
        assert(w.dtype == np.result_type(self.v.dtype, u.dtype))

        u = NullVector(self.n + 1, uval, dtype=np.float)
        assert_raises(ValueError, lambda y: y - self.v, u)

        w = u - 2
        assert(isinstance(w, NullVector))
        assert(w.value == uval - 2)

        u -= 2
        assert(u.value == np.float(uval) - 2)

        z = np.random.random(self.n)
        w = z - self.v
        assert(isinstance(w, np.ndarray))
        assert(len(w) == self.n)
        for i in range(self.n):
            assert(w[i] == z[i] - self.val)
github PythonOptimizers / NLP.py / tests / tools / test_nullvector.py View on Github external
def test_order(self):
        u = NullVector(self.n, self.val, dtype=np.float)
        assert_equal(u == self.v, range(self.n))

        u = NullVector(self.n, self.val + 1, dtype=np.float)
        assert_equal(u == self.v, [])

        u = NullVector(self.n + 1, self.val, dtype=np.float)
        assert_equal(u == self.v, [])
github PythonOptimizers / NLP.py / tests / tools / test_nullvector.py View on Github external
def test_sub(self):
        uval = np.random.random()
        u = NullVector(self.n, uval, dtype=np.float)
        w = u - self.v
        assert(isinstance(w, NullVector))
        assert(len(w) == self.n)
        assert(w.value == np.float(uval) - np.float(self.val))
        assert(w.dtype == np.result_type(self.v.dtype, u.dtype))

        u = NullVector(self.n + 1, uval, dtype=np.float)
        assert_raises(ValueError, lambda y: y - self.v, u)

        w = u - 2
        assert(isinstance(w, NullVector))
        assert(w.value == uval - 2)

        u -= 2
        assert(u.value == np.float(uval) - 2)
github PythonOptimizers / NLP.py / tests / tools / test_nullvector.py View on Github external
def test_order(self):
        u = NullVector(self.n, self.val, dtype=np.float)
        assert_equal(u == self.v, range(self.n))

        u = NullVector(self.n, self.val + 1, dtype=np.float)
        assert_equal(u == self.v, [])

        u = NullVector(self.n + 1, self.val, dtype=np.float)
        assert_equal(u == self.v, [])
github PythonOptimizers / NLP.py / tests / tools / test_nullvector.py View on Github external
def setUp(self):
        self.n = 10
        self.val = np.random.random()
        self.v = NullVector(self.n, self.val, dtype=np.float)
github PythonOptimizers / NLP.py / tests / tools / test_nullvector.py View on Github external
def test_mul(self):
        uval = np.random.random()
        u = NullVector(self.n, uval, dtype=np.float)
        w = u * self.v
        assert(isinstance(w, NullVector))
        assert(len(w) == self.n)
        assert(w.value == np.float(self.val) * np.float(uval))
        assert(w.dtype == np.result_type(self.v.dtype, u.dtype))

        u = NullVector(self.n + 1, uval, dtype=np.float)
        assert_raises(ValueError, lambda y: y * self.v, u)

        w = u * 2
        assert(isinstance(w, NullVector))
        assert(w.value == uval * 2)

        u *= 2
        assert(u.value == np.float(uval) * 2)
github PythonOptimizers / NLP.py / tests / tools / test_nullvector.py View on Github external
def test_mul(self):
        uval = np.random.random()
        u = NullVector(self.n, uval, dtype=np.float)
        w = u * self.v
        assert(isinstance(w, NullVector))
        assert(len(w) == self.n)
        assert(w.value == np.float(self.val) * np.float(uval))
        assert(w.dtype == np.result_type(self.v.dtype, u.dtype))

        u = NullVector(self.n + 1, uval, dtype=np.float)
        assert_raises(ValueError, lambda y: y * self.v, u)

        w = u * 2
        assert(isinstance(w, NullVector))
        assert(w.value == uval * 2)

        u *= 2
        assert(u.value == np.float(uval) * 2)

        z = np.random.random(self.n)
        w = z * self.v
        assert(isinstance(w, np.ndarray))
        assert(len(w) == self.n)
        for i in range(self.n):
            assert(w[i] == z[i] * self.val)