int luaRotate(lua_State *L) { int n=(int)lua_tonumber(L, 1); float x=(float)lua_tonumber(L, 2); float y=(float)lua_tonumber(L, 3); float z=(float)lua_tonumber(L, 4); if(n<0 || n>=World->ChipCount) return 0; if(World->Rigid[n]) { GMatrix m=GMatrix().rotateX(x*(float)M_PI/180.0f).rotateY(y*(float)M_PI/180.0f).rotateZ(z*(float)M_PI/180.0f); World->Rigid[n]->Top->RotateWithChild(m,World->Rigid[n]->Top->X); World->Rigid[n]->Top->ResetXfWithChild(); } return 0; }
int luaDirectObj(lua_State *L) { int n=(int)lua_tonumber(L, 1); float x=(float)lua_tonumber(L, 2); float y=(float)lua_tonumber(L, 3); float z=(float)lua_tonumber(L, 4); if(n<0 || n>=GOBJMAX) return 0; if(World->Object[n]) { GMatrix m=GMatrix().rotateX(x*(float)M_PI/180.0f).rotateY(y*(float)M_PI/180.0f).rotateZ(z*(float)M_PI/180.0f); World->Object[n]->RotateWithChildAbs(m,World->Object[n]->X); World->Object[n]->ResetXfWithChild(); } return 0; }
void KernelLogisticRegression::computeGramMatrix() { NUKLEI_TRACE_BEGIN(); gramMatrix_ = GMatrix(trainSet_.size(), trainSet_.size()); for (unsigned i = 0; i < trainSet_.size(); ++i) { for (unsigned j = 0; j < trainSet_.size(); ++j) { gramMatrix_(i, j) = trainSet_.at(i).polyEval(trainSet_.at(j)); } } NUKLEI_TRACE_END(); }
void Vertex4::prepareAmputated(std::vector<IndexCombination*>& in) { NonTrivialAmputatedCombinations=in; INFO("Vertex4: Inverting Greens Function..."); ParticleIndex N_bit = IndexInfo.getIndexSize(); for(long MatsubaraNumber=-NumberOfMatsubaras; MatsubaraNumber<NumberOfMatsubaras; ++MatsubaraNumber){ MatrixType GMatrix(N_bit,N_bit); GMatrix.setIdentity(); for(ParticleIndex index1=0; index1 < N_bit; ++index1) for(ParticleIndex index2=0; index2 < N_bit; ++index2){ GMatrix(index1,index2) = g(index1,index2,MatsubaraNumber); } //DEBUG(" GF[" << MatsubaraNumber << "] = " << GMatrix ); //DEBUG("InvertedGF[" << MatsubaraNumber << "] = " << GMatrix.inverse() ); InvertedGFs[MatsubaraNumber+NumberOfMatsubaras] = GMatrix.inverse(); } INFO("Vertex4: Preparing amputated value container map ..."); for (std::vector<IndexCombination*>::const_iterator it1=NonTrivialAmputatedCombinations.begin(); it1!=NonTrivialAmputatedCombinations.end(); ++it1){ mapAmputatedValues[**it1]= new MatsubaraContainer(beta); mapAmputatedValues[**it1]->prepare(NumberOfMatsubaras); } };
int luaCollisionObjRingArea(lua_State *L) { int rn=(int)lua_tonumber(L, 1); //リング番号 int n=(int)lua_tonumber(L, 2); //オブジェクト番号 int b=0; if((n>=0 && n<GOBJMAX) && (rn>=0 && rn<GRINGMAX) && World->Object[n]!=NULL) { GMatrix m=GMatrix().rotateX(Ring[rn].Dir.x*(float)M_PI/180.0f).rotateY(Ring[rn].Dir.y*(float)M_PI/180.0f).rotateZ(Ring[rn].Dir.z*(float)M_PI/180.0f); GVector norm; norm.x=m.elem[2][0]; norm.y=m.elem[2][1]; norm.z=m.elem[2][2]; float t=World->Object[n]->preX.distanceOnFaceAndLine(norm,Ring[rn].Point,(World->Object[n]->X-World->Object[n]->preX)); if(t>=0 && t<=1.0f) { GVector p=World->Object[n]->preX+(World->Object[n]->X-World->Object[n]->preX)*t; if((Ring[rn].Point-p).abs()<=Ring[rn].Scale) b=1; } } lua_pushnumber(L,b); return 1; }
/***********************************************************************//** * @brief Test matrix allocation ***************************************************************************/ void TestGMatrixSparse::alloc_matrix(void) { // Allocate zero matrix. The allocation should fail. test_try("Allocate zero matrix"); try { GMatrixSparse test(0,0); test_try_failure("Expected GException::empty exception."); } catch (GException::empty &e) { test_try_success(); } catch (std::exception &e) { test_try_failure(e); } // Setup a symmetric sparse matrix int size = 30; GMatrixSparse symmetric(size,size); for (int i = 0; i < size; i+=2) { for (int j = 0; j < size; j+=2) { symmetric(i,j) = 1.0+i+j; } } // Convert to GMatrix test_try("Test symmetric GMatrix conversion"); try { GMatrix cnv_matrix = GMatrix(symmetric); GMatrixSparse back_matrix = GMatrixSparse(cnv_matrix); test_assert((symmetric == back_matrix), "Test symmetric GMatrixSparse - GMatrix conversion", "Found:\n"+back_matrix.print()+"\nExpected:\n"+symmetric.print()); test_try_success(); } catch (GException::empty &e) { test_try_success(); } catch (std::exception &e) { test_try_failure(e); } // Test GMatrix conversion test_try("Test GMatrix conversion"); try { GMatrix cnv_matrix = GMatrix(m_test); GMatrixSparse back_matrix = GMatrixSparse(cnv_matrix); test_assert((m_test == back_matrix), "Test GMatrixSparse - GMatrix conversion", "Found:\n"+back_matrix.print()+"\nExpected:\n"+m_test.print()); test_try_success(); } catch (std::exception &e) { test_try_failure(e); } // Test GMatrixSparse <-> GMatrixSymmetric conversion test_try("Test GMatrixSymmetric conversion"); try { GMatrixSymmetric cnv_sym = GMatrixSymmetric(symmetric); GMatrixSparse back_sym = GMatrixSparse(cnv_sym); test_assert((symmetric == back_sym), "Test GMatrixSparse - GMatrixSymmetric conversion", "Found:\n"+back_sym.print()+"\nExpected:\n"+symmetric.print()); test_try_success(); } catch (std::exception &e) { test_try_failure(e); } // Test invalid GMatrixSparse <-> GMatrixSymmetric conversion test_try("Test invalid GMatrixSymmetric conversion"); try { GMatrixSymmetric bad_sym = GMatrixSymmetric(m_test); test_try_failure("Expected GException::matrix_not_symmetric exception."); } catch (GException::matrix_not_symmetric &e) { test_try_success(); } catch (std::exception &e) { test_try_failure(e); } // Return return; }
/***********************************************************************//** * @brief Test Cholesky decomposition ***************************************************************************/ void TestGSymMatrix::matrix_cholesky(void) { // Test Cholesky decomposition GSymMatrix cd = cholesky_decompose(m_test); GMatrix cd_lower = cd.extract_lower_triangle(); GMatrix cd_upper = transpose(cd_lower); GMatrix cd_product = cd_lower * cd_upper; GMatrix cd_residuals = GMatrix(m_test) - cd_product; double res = (abs(cd_residuals)).max(); test_value(res, 0.0, 1.0e-15, "Test cholesky_decompose() method"); // Test compressed Cholesky decomposition GSymMatrix test_zero = set_matrix_zero(); GSymMatrix cd_zero = cholesky_decompose(test_zero); GMatrix cd_zero_lower = cd_zero.extract_lower_triangle(); GMatrix cd_zero_upper = transpose(cd_zero_lower); GMatrix cd_zero_product = cd_zero_lower * cd_zero_upper; GMatrix cd_zero_residuals = GMatrix(test_zero) - cd_zero_product; res = (abs(cd_zero_residuals)).max(); test_value(res, 0.0, 1.0e-15, "Test compressed cholesky_decompose() method"); // Test Cholesky inplace decomposition GSymMatrix test = m_test; test.cholesky_decompose(); GMatrix cd_lower2 = test.extract_lower_triangle(); test_assert((cd_lower2 == cd_lower), "Test inplace cholesky_decompose() method"); // Test Cholesky solver (first test) GVector e0(g_rows); GVector a0(g_rows); e0[0] = 1.0; e0[1] = 0.0; e0[2] = 0.0; a0[0] = g_matrix[0]; a0[1] = g_matrix[3]; a0[2] = g_matrix[6]; GVector s0 = cd.cholesky_solver(a0) - e0; res = max(abs(s0)); test_value(res, 0.0, 1.0e-15, "Test cholesky_solver() method"); // Test Cholesky solver (second test) e0[0] = 0.0; e0[1] = 1.0; e0[2] = 0.0; a0[0] = g_matrix[1]; a0[1] = g_matrix[4]; a0[2] = g_matrix[7]; s0 = cd.cholesky_solver(a0) - e0; res = max(abs(s0)); test_value(res, 0.0, 1.0e-15, "Test cholesky_solver() method"); // Test Cholesky solver (third test) e0[0] = 0.0; e0[1] = 0.0; e0[2] = 1.0; a0[0] = g_matrix[2]; a0[1] = g_matrix[5]; a0[2] = g_matrix[8]; s0 = cd.cholesky_solver(a0) - e0; res = max(abs(s0)); test_value(res, 0.0, 1.0e-15, "Test cholesky_solver() method"); // Test compressed Cholesky solver (first test) e0 = GVector(g_rows+1); a0 = GVector(g_rows+1); e0[0] = 1.0; e0[1] = 0.0; e0[2] = 0.0; e0[3] = 0.0; a0[0] = g_matrix[0]; a0[1] = g_matrix[3]; a0[2] = 0.0; a0[3] = g_matrix[6]; s0 = cd_zero.cholesky_solver(a0) - e0; res = max(abs(s0)); test_value(res, 0.0, 1.0e-15, "Test compressed cholesky_solver() method"); // Test compressed Cholesky solver (second test) e0[0] = 0.0; e0[1] = 1.0; e0[2] = 0.0; e0[3] = 0.0; a0[0] = g_matrix[1]; a0[1] = g_matrix[4]; a0[2] = 0.0; a0[3] = g_matrix[7]; s0 = cd_zero.cholesky_solver(a0) - e0; res = max(abs(s0)); test_value(res, 0.0, 1.0e-15, "Test compressed cholesky_solver() method"); // Test compressed Cholesky solver (third test) e0[0] = 0.0; e0[1] = 0.0; e0[2] = 0.0; e0[3] = 1.0; a0[0] = g_matrix[2]; a0[1] = g_matrix[5]; a0[2] = 0.0; a0[3] = g_matrix[8]; s0 = cd_zero.cholesky_solver(a0) - e0; res = max(abs(s0)); test_value(res, 0.0, 1.0e-15, "Test compressed cholesky_solver() method"); // Test Cholesky inverter GSymMatrix unit(g_rows,g_cols); unit(0,0) = unit(1,1) = unit(2,2) = 1.0; GSymMatrix test_inv = m_test; test_inv.cholesky_invert(); GMatrix ci_product = m_test * test_inv; GMatrix ci_residuals = ci_product - unit; res = (abs(ci_residuals)).max(); test_value(res, 0.0, 1.0e-15, "Test cholesky_invert method"); // Test Cholesky inverter for compressed matrix unit = GSymMatrix(4,4); unit(0,0) = unit(1,1) = unit(3,3) = 1.0; GSymMatrix test_zero_inv = test_zero; test_zero_inv.cholesky_invert(); GMatrix ciz_product = test_zero * test_zero_inv; GMatrix ciz_residuals = ciz_product - unit; res = (abs(ciz_residuals)).max(); test_value(res, 0.0, 1.0e-15, "Test compressed cholesky_invert method"); // Return return; }
/***********************************************************************//** * @brief Test matrix functions * * Tests matrix functions. ***************************************************************************/ void TestGSymMatrix::matrix_functions(void) { // Minimum double min = m_test.min(); // Check mimimum double value = g_matrix[0]; for (int row = 0; row < g_rows; ++row) { for (int col = 0; col < g_cols; ++col) { if (g_matrix[col+row*g_cols] < value) { value = g_matrix[col+row*g_cols]; } } } test_value(min, value, 0.0, "Test minimum function"); // Maximum double max = m_test.max(); // Check maximum value = g_matrix[0]; for (int row = 0; row < g_rows; ++row) { for (int col = 0; col < g_cols; ++col) { if (g_matrix[col+row*g_cols] > value) { value = g_matrix[col+row*g_cols]; } } } test_value(max, value, 0.0, "Test maximum function"); // Sum double sum = m_test.sum(); // Check sum value = 0.0; for (int row = 0; row < g_rows; ++row) { for (int col = 0; col < g_cols; ++col) { value += g_matrix[col+row*g_cols]; } } test_value(sum, value, 1.0e-20, "Test sum function"); // Transpose function GSymMatrix test1 = transpose(m_test); test_assert(check_matrix(m_test), "Test source matrix"); test_assert(check_matrix(test1, 1.0, 0.0), "Test transpose(GSymMatrix) function", "Unexpected transposed matrix:\n"+test1.print()); // Transpose method test1 = m_test; test1.transpose(); test_assert(check_matrix(m_test), "Test source matrix"); test_assert(check_matrix(test1, 1.0, 0.0), "Test GSymMatrix.transpose() method", "Unexpected transposed matrix:\n"+test1.print()); // Convert to general matrix GMatrix test2 = GMatrix(m_test); test_assert(check_matrix(m_test), "Test source matrix"); test_assert(check_matrix(test2, 1.0, 0.0), "Test GMatrix(GSymMatrix) constructor", "Unexpected GMatrix:\n"+test2.print()); // Extract lower triangle test2 = m_test.extract_lower_triangle(); test_assert(check_matrix(m_test), "Test source matrix"); test_assert(check_matrix_lt(test2, 1.0, 0.0), "Test GSymMatrix.extract_lower_triangle() method", "Unexpected GMatrix:\n"+test2.print()); // Extract upper triangle test2 = m_test.extract_upper_triangle(); test_assert(check_matrix(m_test), "Test source matrix"); test_assert(check_matrix_ut(test2, 1.0, 0.0), "Test GSymMatrix.extract_upper_triangle() method", "Unexpected GMatrix:\n"+test2.print()); // Return return; }
static GMatrix matrix_identity(int w, int h) { return GMatrix(); }