void NonlinearPoissonResidual<EvalT, Traits>:: evaluateFields(typename Traits::EvalData workset) { // u residual for (std::size_t cell = 0; cell < workset.numCells; ++cell) { for (std::size_t node = 0; node < num_nodes_; ++node) { residual_(cell,node) = 0.0; } for (std::size_t qp = 0; qp < num_qps_; ++qp) { for (std::size_t node = 0; node < num_nodes_; ++node) { for (std::size_t i = 0; i < num_dims_; ++i) { residual_(cell,node) += (1.0 + u_(cell,qp)*u_(cell,qp)) * u_grad_(cell,qp,i) * w_grad_bf_(cell,node,qp,i); } } } } // source function for (std::size_t cell = 0; cell < workset.numCells; ++cell) { for (std::size_t qp = 0; qp < num_qps_; ++qp) { for (std::size_t node = 0; node < num_nodes_; ++node) { residual_(cell,node) -= w_bf_(cell,node,qp) * source_(cell,qp); } } } }
float SVDPredictor::Predict(int user, int item, int k) { assert(k <= sv_.rows()); float ret = RatingMeanByUser(user); for (int i = 0; i < k; i++) { ret += u_(user, i) * sv_(i, 0) * v_(item, i); } #if 0 const Eigen::MatrixXf d = (u_ * sv_.asDiagonal()) * v_.transpose(); printf("ret(%d, %d)=%f\n", user, item, d(user, item) + RatingMeanByUser(user)); #endif return ret; }
double Solve(const int &row_reduction_times) { ColumnReduction(); std::vector<int> init_freeRows; ReductionTransfer(init_freeRows); std::vector<int> freeRows; AugmentingRowReduction(init_freeRows, freeRows); for(int time=1 ; time<row_reduction_times ; time++) { std::vector<int> tmp_freeRows(freeRows); freeRows.clear(); AugmentingRowReduction(tmp_freeRows, freeRows); } Augmentation(freeRows); CheckAssignments(); /// double cost = 0.0; for(int row=1 ; row<=n_ ; row++) { int col = x_(row-1); u_(row-1) = cost_mat_(row-1, col-1) - v_(col-1); cost += u_(row-1) + v_(col-1); } return cost; }
double CalculateError(int n, double * approx) { double h = L / n; double max_err = 0; for (int i = 0; i < n - 1; i++) for (int j = 0; j < n - 1; j++) { double cur_err = fabs(approx[i * (n - 1) + j] - u_((i + 1) * h, (j + 1) * h)); if (cur_err > max_err) max_err = cur_err; } return max_err; }
void Spine::update_mesh() { if (!dirty_mesh) return; int N = n * p * q; int M = m; while ((N + 1) * (M + 1) >= 65536) N--; dirty_mesh = false; vec3 points[(N + 1) * (M + 1)]; vec3 norms[(N + 1) * (M + 1)]; vec4 params[(N + 1) * (M + 1)]; struct sv2 { unsigned short a, b; }; sv2 quad_indices[N * (M + 1)]; for (int i = 0; i <= N; ++i) { Turns t_(i, N); Radians t = t_; vec3 Ct = C(t); vec3 Bt = B(t); norm3(Bt); vec3 Nt = this->N(t); norm3(Nt); for (int j = 0; j <= M; ++j) { Turns u_(j, M); Radians u = u_; params[i * (M + 1) + j] = {t_.value() * q, u_.value(), 0, 1}; norms[i * (M + 1) + j] = s * cos_(u) * Bt + r * sin_(u) * Nt; norm3(norms[i * (M + 1) + j]); points[i * (M + 1) + j] = Ct + r * cos_(u) * Bt + s * sin_(u) * Nt; if (i == N) continue; quad_indices[i * (M + 1) + j] = { (unsigned short)(i * (M + 1) + j), (unsigned short)((i + 1) * (M + 1) + j), }; } } char filename[256]; sprintf(filename, "data/spiral-%.10e,%.10e,%.10e,%.10e-%d,%d,%d,%d.mesh", a, b, r, s, p, q, N, M); FILE *fp = fopen(filename, "w"); fprintf(fp, "textures:\n"); fprintf(fp, " ambient: data/earthlights1k.bmp\n"); fprintf(fp, " diffuse: data/earthmap1k.bmp\n"); fprintf(fp, " specular: data/earthspec1k.bmp\n"); fprintf(fp, "\nvertices:\n"); for (int i = 0; i < (N + 1) * (M + 1); ++i) { auto p = vec4(points[i], 1.0f); auto t = params[i]; auto n = vec4(norms[i], 1.0f); fprintf(fp, " - position: [%.10e, %.10e, %.10e, %.10e]\n", p.x, p.y, p.z, p.w); fprintf(fp, " texture: [%.10e, %.10e, %.10e, %.10e]\n", t.x * this->q, t.y, t.z, t.w); fprintf(fp, " normal: [%.10e, %.10e, %.10e, %.10e]\n", n.x, n.y, n.z, n.w); } fprintf(fp, "\nfaces:\n"); for (int j = 1; j < N * (M + 1); ++j) { ivec3 f1 = { quad_indices[j - 1].a, quad_indices[j - 1].b, quad_indices[j].a, }; ivec3 f2 = { quad_indices[j - 1].b, quad_indices[j].b, quad_indices[j].a, }; fprintf(fp, " - [%d, %d, %d]\n", f1.x, f1.y, f1.z); fprintf(fp, " - [%d, %d, %d]\n", f2.x, f2.y, f2.z); } fclose(fp); glBindBuffer(GL_ARRAY_BUFFER, mesh_points); glBufferData(GL_ARRAY_BUFFER, sizeof(points), points, GL_STATIC_DRAW); glBindBuffer(GL_ARRAY_BUFFER, mesh_norms); glBufferData(GL_ARRAY_BUFFER, sizeof(norms), norms, GL_STATIC_DRAW); glBindBuffer(GL_ARRAY_BUFFER, mesh_params); glBufferData(GL_ARRAY_BUFFER, sizeof(params), params, GL_STATIC_DRAW); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, mesh_indices); glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(quad_indices), quad_indices, GL_STATIC_DRAW); }
} static int tester_op_getId(lua_State *L) { TESTER_OBJ** ptx = check_tester(L, 1); lua_Number id = (*ptx)->id; lua_pushnumber(L, id); return 1; } #define _(name) { #name, tester_op_##name } #define u_(name) { #name, luabdb_unimplemented } static luaL_Reg tester_funcs[] = { _(getId), u_(associate), { NULL, NULL } }; #undef _ #undef u_ static int tester__gc(lua_State *L) { DB_TXN** ptx = check_txn(L, 1); DB_TXN* tx = *ptx; if (tx != NULL) { dbgprint("aborting a transaction 0x%x\n", tx); int status = tx->abort(tx); *ptx = NULL; handle_dbexception(L, status);