Exemplo n.º 1
0
def test_fail_vec_mat_mult():
  dims = {'2': (2, 5),
          '3': (3, 7),
          '4': (4, 13),
          '6': (13, 19),
          'X': (6, 4)}
  for k, v in vectors.items():
    m = e.MatrixXd(*dims[k])
    assert_raises(TypeError, lambda x,y: x*y, v, m)
Exemplo n.º 2
0
def test_vec_mat_mult():
  cols = {'2': 5,
          '3': 7,
          '4': 13,
          '6': 19,
          'X': 4}
  for k, v in vectors.items():
    m = e.MatrixXd(1, cols[k])
    res = v*m
    assert(isinstance(res, e.MatrixXd))
    assert(res.rows() == v.rows())
    assert(res.cols() == cols[k])
    assert((abs(np.array(res) - np.array(v).dot(np.array(m))) < precision).all())
Exemplo n.º 3
0
  def __init__(self):
    self.nrvar = 6
    self.nreq = 3
    self.nrineq = 2

    self.Q = eigen.MatrixXd.Identity(self.nrvar, self.nrvar)

    self.Aeq = eigen.MatrixXd([ [1., -1., 1., 0., 3., 1.],
                                [-1., 0., -3., -4., 5., 6.],
                                [2., 5., 3., 0., 1., 0.] ])
    self.Beq = eigen.VectorXd([1., 2., 3.])

    self.Aineq = eigen.MatrixXd([ [0., 1., 0., 1., 2., -1.],
                                  [-1., 0., 2., 1., 1., 0.] ])
    self.Bineq = eigen.VectorXd([-1., 2.5])

    self.XL = eigen.VectorXd([ -1000., -10000., 0., -1000., -1000.,-1000. ])
    self.XU = eigen.VectorXd([ 10000., 100., 1.5, 100., 100., 1000. ])

    self.C = eigen.VectorXd([ 1., 2., 3., 4., 5., 6. ])

    self.X = eigen.VectorXd([ 1.7975426, -0.3381487, 0.1633880, -4.9884023, 0.6054943, -3.1155623 ])
Exemplo n.º 4
0
print dir(y)

x1 = x()
print x1
y1 = y()
print y1

print dir(x1)
print dir(y1)

x2 = x(10)
print x2[0]

print dir(x2[0])

print dir(eigen)

s = eigen.MatrixXd(3, 4)
print s

r = eigen.VectorXd(10)
print r

print dir(r)

r.__setitem__(0, 20)
print r

print type(s)
print type(r)
Exemplo n.º 5
0
# -*- encoding=utf-8 -*-

import numpy as np
import sys
import eigen
from ctypes import *

# 查看python模块默认安装路径
print sys.path

A = np.random.random((2000, 50))
B = eigen.MatrixXd(A)

n = np.linalg.norm(B)  # Implicit conversion to numpy object

vector_1D = eigen.VectorXd(3)
vector_1D.coeff(1, 2)
print type(vector_1D)
print vector_1D

matrix_1D = eigen.MatrixXd(3, 1)
matrix_1D.setZero()
print matrix_1D