void sanguis::server::auras::update_sight::enter( sanguis::server::entities::with_body &_entity, sanguis::collision::world::created const _created ) { fcppt::optional::maybe_void( fcppt::cast::dynamic_cross< sanguis::server::entities::with_id const >( _entity ), [ this, _created ]( fcppt::reference< sanguis::server::entities::with_id const > const _with_id ) { add_( _with_id.get(), _created ); } ); }
/// Adapted from /// https://github.com/pytorch/pytorch/blob/master/torch/optim/adagrad.py void Adagrad::step() { for (auto& pair : model_->parameters()) { auto& name = pair.first; auto& grad = pair.second.grad(); auto& p = pair.second.data(); if (!grad.defined()) continue; auto d_p = torch::autograd::as_variable_ref(grad).data(); if (weight_decay_ > 0) { d_p.add_(p, weight_decay_); }; auto& step = step_[name]; step += 1.0; auto clr = lr_ / (1.0 + (step - 1.0) * lr_decay_); at::Tensor buf; if (sum_.find(name) == sum_.end()) { buf = sum_[name] = at::zeros_like(p); } else { buf = sum_[name]; } buf.addcmul_(d_p, d_p, 1.0); at::Tensor std = buf.sqrt().add_(1e-10); p.addcdiv_(d_p, std, -clr); } }
int main(){ int num,num1; char sim; printf("사칙연산 할 두 수를 적으세요. : "); scanf("%d %d",&num,&num1); printf("사칙연산 할 기호를 적어주세요. : "); scanf(" %c",&sim); int (*add_)(int,int); int (*minus_)(int,int); int (*multi_)(int,int); double (*avg_)(int,int); add_ = add; minus_ = minus; multi_ = multi; avg_ = avg; switch(sim){ case '+' : printf("두 수의 덧셈의 값 : %d\n",add_(num,num1)); break; case '-' : printf("두 수의 뺄셈의 값 : %d\n",minus_(num,num1)); break; case '/' : printf("두 수의 나눗셈의 값 : %.2lf",avg_(num,num1)); break; case '*' : printf("두 수의 곱셈의 값 : %d\n",multi_(num,num1)); break; default : printf("문자를 잘못입력하셨습니다.\n종료합니다.\n"); } return 0; }
void SGD::step() { for (auto& pair : model_->parameters()) { auto& name = pair.first; auto& grad = pair.second.grad(); auto& p = pair.second.data(); if (!grad.defined()) continue; auto d_p = torch::autograd::as_variable_ref(grad).data(); if (weight_decay_ > 0) { d_p.add_(p, weight_decay_); }; if (momentum_ != 0) { at::Tensor buf; if (momentum_buffers_.find(name) == momentum_buffers_.end()) { buf = momentum_buffers_[name] = at::zeros_like(p); buf.mul_(momentum_).add_(d_p); } else { buf = momentum_buffers_[name]; buf.mul_(momentum_).add_(d_p, 1 - dampening_); } if (nesterov_) { d_p = d_p.add(buf, momentum_); } else { d_p = buf; } } p.add_(d_p, -lr_); } }
TEST_F(LQPUtilsTest, LQPFindModifiedTables) { // clang-format off const auto read_only_lqp = PredicateNode::make(greater_than_(a_a, 5), ProjectionNode::make(expression_vector(add_(a_a, a_b), a_a), PredicateNode::make(less_than_(a_b, 4), SortNode::make(expression_vector(a_b), std::vector<OrderByMode>{OrderByMode::Ascending}, node_a)))); // clang-format on EXPECT_EQ(lqp_find_modified_tables(read_only_lqp).size(), 0); // clang-format off const auto insert_lqp = InsertNode::make("insert_table_name", PredicateNode::make(greater_than_(a_a, 5), node_a)); // clang-format on const auto insert_tables = lqp_find_modified_tables(insert_lqp); EXPECT_EQ(insert_tables.size(), 1); EXPECT_NE(insert_tables.find("insert_table_name"), insert_tables.end()); const auto delete_lqp = DeleteNode::make(node_a); const auto delete_tables = lqp_find_modified_tables(delete_lqp); EXPECT_EQ(delete_tables.size(), 1); EXPECT_NE(delete_tables.find("node_a"), delete_tables.end()); }
TEST_F(JoinNodeTest, IsColumnNullableWithoutOuterJoin) { // Test that for LQPs without (Left,Right)Outer Joins, lqp_column_is_nullable() is equivalent to // expression.is_nullable() // clang-format off const auto lqp = JoinNode::make(JoinMode::Inner, equals_(add_(_t_a_a, null_()), _t_b_x), ProjectionNode::make(expression_vector(_t_a_a, _t_a_b, add_(_t_a_a, null_())), _mock_node_a), _mock_node_b); // clang-format on EXPECT_FALSE(lqp->is_column_nullable(ColumnID{0})); EXPECT_FALSE(lqp->is_column_nullable(ColumnID{1})); EXPECT_TRUE(lqp->is_column_nullable(ColumnID{2})); EXPECT_FALSE(lqp->is_column_nullable(ColumnID{3})); EXPECT_FALSE(lqp->is_column_nullable(ColumnID{4})); }
bool Set::add(int val){ if (size > 0){ for (int i = 0; i < size; i++){ if (values[i] == val){ return 0; } if (values[i] > val){ return add_(val, i); } } return add_(val, size); } else{ add_(val, 0); } }
static inline void mul_(num *a,num *b,num *c){ register int i; num t; c->n=1; c->a[0]=0; for(i=0;i<b->n;++i){ shift_left(c,1); mul1_(a,b->a[i],&t); add_(c,&t,c); rm0(c); } }
TEST_F(JoinNodeTest, IsColumnNullableWithOuterJoin) { // Test that columns on the "null-supplying" side of an outer join are always nullable. // Test that is_null_(<nullable>) is never nullable // clang-format off const auto lqp_left_join_basic = JoinNode::make(JoinMode::Left, equals_(_t_a_a, _t_b_x), _mock_node_a, _mock_node_b); // clang-format on EXPECT_FALSE(lqp_left_join_basic->is_column_nullable(ColumnID{0})); EXPECT_FALSE(lqp_left_join_basic->is_column_nullable(ColumnID{1})); EXPECT_FALSE(lqp_left_join_basic->is_column_nullable(ColumnID{2})); EXPECT_TRUE(lqp_left_join_basic->is_column_nullable(ColumnID{3})); EXPECT_TRUE(lqp_left_join_basic->is_column_nullable(ColumnID{4})); // clang-format off const auto lqp_left_join = ProjectionNode::make(expression_vector(_t_a_a, _t_b_x, add_(_t_a_a, _t_b_x), add_(_t_a_a, 3), is_null_(add_(_t_a_a, _t_b_x))), // NOLINT JoinNode::make(JoinMode::Left, equals_(_t_a_a, _t_b_x), _mock_node_a, _mock_node_b)); // clang-format on EXPECT_FALSE(lqp_left_join->is_column_nullable(ColumnID{0})); EXPECT_TRUE(lqp_left_join->is_column_nullable(ColumnID{1})); EXPECT_TRUE(lqp_left_join->is_column_nullable(ColumnID{2})); EXPECT_FALSE(lqp_left_join->is_column_nullable(ColumnID{3})); EXPECT_FALSE(lqp_left_join->is_column_nullable(ColumnID{4})); // clang-format off const auto lqp_right_join = ProjectionNode::make(expression_vector(_t_a_a, _t_b_x, add_(_t_a_a, _t_b_x), add_(_t_a_a, 3), is_null_(add_(_t_a_a, _t_b_x))), // NOLINT JoinNode::make(JoinMode::Right, equals_(_t_a_a, _t_b_x), _mock_node_a, _mock_node_b)); // clang-format on EXPECT_TRUE(lqp_right_join->is_column_nullable(ColumnID{0})); EXPECT_FALSE(lqp_right_join->is_column_nullable(ColumnID{1})); EXPECT_TRUE(lqp_right_join->is_column_nullable(ColumnID{2})); EXPECT_TRUE(lqp_right_join->is_column_nullable(ColumnID{3})); EXPECT_FALSE(lqp_right_join->is_column_nullable(ColumnID{4})); // clang-format off const auto lqp_full_join = ProjectionNode::make(expression_vector(_t_a_a, _t_b_x, add_(_t_a_a, _t_b_x), add_(_t_a_a, 3), is_null_(add_(_t_a_a, _t_b_x))), // NOLINT JoinNode::make(JoinMode::FullOuter, equals_(_t_a_a, _t_b_x), _mock_node_a, _mock_node_b)); // clang-format on EXPECT_TRUE(lqp_full_join->is_column_nullable(ColumnID{0})); EXPECT_TRUE(lqp_full_join->is_column_nullable(ColumnID{1})); EXPECT_TRUE(lqp_full_join->is_column_nullable(ColumnID{2})); EXPECT_TRUE(lqp_full_join->is_column_nullable(ColumnID{3})); EXPECT_FALSE(lqp_full_join->is_column_nullable(ColumnID{4})); }
TEST_F(OperatorsProjectionTest, DontForwardReferencesWithExpression) { const auto table_scan = create_table_scan(table_wrapper_a, ColumnID{0}, PredicateCondition::LessThan, 100'000); table_scan->execute(); const auto projection = std::make_shared<opossum::Projection>(table_scan, expression_vector(a_b, a_a, add_(a_b, a_a))); projection->execute(); const auto input_chunk = table_wrapper_a->get_output()->get_chunk(ChunkID{0}); const auto output_chunk = projection->get_output()->get_chunk(ChunkID{0}); EXPECT_NE(input_chunk->get_segment(ColumnID{1}), output_chunk->get_segment(ColumnID{0})); EXPECT_NE(input_chunk->get_segment(ColumnID{0}), output_chunk->get_segment(ColumnID{1})); }
TEST_F(LQPUtilsTest, LQPSubplanToBooleanExpression_A) { // clang-format off const auto lqp = PredicateNode::make(greater_than_(a_a, 5), ProjectionNode::make(expression_vector(add_(a_a, a_b), a_a), PredicateNode::make(less_than_(a_b, 4), SortNode::make(expression_vector(a_b), std::vector<OrderByMode>{OrderByMode::Ascending}, node_a)))); // clang-format on const auto actual_expression = lqp_subplan_to_boolean_expression(lqp); const auto expected_expression = and_(less_than_(a_b, 4), greater_than_(a_a, 5)); EXPECT_EQ(*actual_expression, *expected_expression); }
static inline sub(num *a,num *b,num *c){ if(a->sbit*b->sbit<0){ add_(a,b,c); c->sbit=a->sbit; }else{ int compare=cmp_(a,b); if(compare>0){ sub_(a,b,c); }else{ sub_(b,a,c); } c->sbit=compare*a->sbit; } rm0(c); }
void Adam::step() { for (auto& pair : model_->parameters()) { auto& name = pair.first; auto& grad = pair.second.grad(); auto& p = pair.second.data(); if (!grad.defined()) continue; if (step_buffer_.find(name) == step_buffer_.end()) { step_buffer_[name] = 0; exp_avg_buffer_[name] = at::zeros_like(p); exp_avg_sq_buffer_[name] = at::zeros_like(p); if (amsgrad_) { max_exp_avg_sq_buffer_[name] = at::zeros_like(p); }; } auto& step = step_buffer_[name]; auto& exp_avg = exp_avg_buffer_[name]; auto& exp_avg_sq = exp_avg_sq_buffer_[name]; step += 1; auto d_p = torch::autograd::as_variable_ref(grad).data(); if (weight_decay_ > 0) { d_p.add_(p, weight_decay_); } exp_avg.mul_(beta1_).add_(d_p, 1 - beta1_); exp_avg_sq.mul_(beta2_).addcmul_(d_p, d_p, 1 - beta2_); at::Tensor denom; if (amsgrad_) { auto& max_exp_avg_sq = max_exp_avg_sq_buffer_[name]; at::max_out(max_exp_avg_sq, max_exp_avg_sq, exp_avg_sq); denom = max_exp_avg_sq.sqrt().add_(eps_); } else { denom = exp_avg_sq.sqrt().add_(eps_); }; auto bias_correction1 = 1 - std::pow(beta1_, step); auto bias_correction2 = 1 - std::pow(beta2_, step); auto step_size = lr_ * std::sqrt(bias_correction2) / bias_correction1; p.addcdiv_(exp_avg, denom, -step_size); } }
Fx* FxManager::getFx( const tstring& resourceID ) { Fx* pEffect = find_( resourceID ); if (!pEffect) { pEffect = new Fx; if (pEffect->create( resourceID )) { add_( pEffect, resourceID ); } else { delete pEffect; pEffect = Fx::getNullObject(); } } return pEffect; }
/// Adapted from /// https://github.com/pytorch/pytorch/blob/master/torch/optim/rmsprop.py void RMSprop::step() { for (auto& pair : model_->parameters()) { auto& name = pair.first; auto& grad = pair.second.grad(); auto& p = pair.second.data(); if (!grad.defined()) continue; if (square_avg_buffer_.find(name) == square_avg_buffer_.end()) { square_avg_buffer_[name] = at::zeros_like(p); if (momentum_) { momentum_buffer_[name] = at::zeros_like(p); }; if (centered_) { grad_avg_buffer_[name] = at::zeros_like(p); }; }; auto d_p = torch::autograd::as_variable_ref(grad).data(); if (weight_decay_ > 0) { d_p.add_(p, weight_decay_); }; auto& square_avg = square_avg_buffer_[name]; square_avg.mul_(alpha_).addcmul_(d_p, d_p, 1.0 - alpha_); at::Tensor avg; if (centered_) { auto& grad_avg = grad_avg_buffer_[name]; grad_avg.mul_(alpha_).add_(d_p, 1.0 - alpha_); avg = square_avg.addcmul(grad_avg, grad_avg, -1.0).sqrt().add_(eps_); } else { avg = square_avg.sqrt().add_(eps_); }; if (momentum_ > 0) { auto& buf = momentum_buffer_[name]; buf.mul_(momentum_).addcdiv_(d_p, avg); p.add_(buf, -lr_); } else { p.addcdiv_(d_p, avg, -lr_); }; } }
// Tokenizes the instruction part of the text command. If it corresponds to one of the supported // instructions, like "add" or "remove", it searches for the next token (the sample name) in the // list of samples and sends its buttonID to the relevant instruction function for further processing void instructionControl(char *string_pointer) { char *buttonID = NULL; int instruction_to_execute; if (!string_pointer) { return; } instruction_to_execute = selectInstruction(string_pointer); string_pointer = strtok(NULL, " \n"); if (string_pointer != NULL) { buttonID = findSampleInArray(string_pointer); // } switch(instruction_to_execute) { case ADD: add_(buttonID); break; case REMOVE: remove_(buttonID); break; case SET: set_(string_pointer); break; case STOP: stopAll_(); break; } }
void xml_compiler::filter_vector::traverse(const extracted_ptree& pt) { for (auto& it : pt) { /* */ if (it.get_tag_name() == "not") { add_(BRIDGE_FILTERTYPE_APPLICATION_NOT, "ApplicationType::", it.get_data()); } else if (it.get_tag_name() == "only") { add_(BRIDGE_FILTERTYPE_APPLICATION_ONLY, "ApplicationType::", it.get_data()); } else if (it.get_tag_name() == "device_not") { add_(BRIDGE_FILTERTYPE_DEVICE_NOT, "", it.get_data()); } else if (it.get_tag_name() == "device_only") { add_(BRIDGE_FILTERTYPE_DEVICE_ONLY, "", it.get_data()); } else if (it.get_tag_name() == "config_not") { add_(BRIDGE_FILTERTYPE_CONFIG_NOT, "ConfigIndex::", it.get_data()); } else if (it.get_tag_name() == "config_only") { add_(BRIDGE_FILTERTYPE_CONFIG_ONLY, "ConfigIndex::", it.get_data()); } else if (it.get_tag_name() == "modifier_not") { add_(BRIDGE_FILTERTYPE_MODIFIER_NOT, "", it.get_data()); } else if (it.get_tag_name() == "modifier_only") { add_(BRIDGE_FILTERTYPE_MODIFIER_ONLY, "", it.get_data()); } else if (it.get_tag_name() == "inputmode_not") { add_(BRIDGE_FILTERTYPE_INPUTMODE_NOT, "InputMode::", it.get_data()); } else if (it.get_tag_name() == "inputmode_only") { add_(BRIDGE_FILTERTYPE_INPUTMODE_ONLY, "InputMode::", it.get_data()); } else if (it.get_tag_name() == "inputmodedetail_not") { add_(BRIDGE_FILTERTYPE_INPUTMODEDETAIL_NOT, "InputModeDetail::", it.get_data()); } else if (it.get_tag_name() == "inputmodedetail_only") { add_(BRIDGE_FILTERTYPE_INPUTMODEDETAIL_ONLY, "InputModeDetail::", it.get_data()); } } }
TEST_F(OperatorsProjectionTest, ForwardsIfPossibleDataTableAndExpression) { const auto projection = std::make_shared<opossum::Projection>(table_wrapper_a, expression_vector(a_b, a_a, add_(a_b, a_a))); projection->execute(); const auto input_chunk = table_wrapper_a->get_output()->get_chunk(ChunkID{0}); const auto output_chunk = projection->get_output()->get_chunk(ChunkID{0}); EXPECT_EQ(input_chunk->get_segment(ColumnID{1}), output_chunk->get_segment(ColumnID{0})); EXPECT_EQ(input_chunk->get_segment(ColumnID{0}), output_chunk->get_segment(ColumnID{1})); }
TEST_F(OperatorsProjectionTest, ExecutedOnAllChunks) { const auto projection = std::make_shared<opossum::Projection>(table_wrapper_a, expression_vector(add_(a_a, a_b))); projection->execute(); EXPECT_TABLE_EQ_UNORDERED(projection->get_output(), load_table("resources/test_data/tbl/projection/int_float_add.tbl")); }
static inline karatsuba(num *a,num *b,num *c){ /* * a=[hi1:lo1] * b=[h2:lo2] * a=hi1*B^m2+lo1 * b=hi2*B^m2+lo2 * a*b=(hi1*hi2)B^(2*m2)+ (l1h2+l2h1) B^m2+lo1*lo2 */ if(a->n<2){ mul1_(b,a->a[0],c); return; } if(b->n<2){ mul1_(a,b->a[0],c); return; } /* printf("%d %d\n",a->n,b->n); printNum(a); printNum(b); printf("case #3\n");*/ int m=max2(a->n,b->n); int m2=m/2; //printf("m2=%d\n",m2); num hi1,lo1,hi2,lo2,z0,z1,z2,t1,t2,lh1,lh2; split_at(a,m2,&hi1,&lo1); split_at(b,m2,&hi2,&lo2); /*puts("--- hi1 ---"); printNum(&hi1); puts("--- lo1 ---"); printNum(&lo1); puts("--- hi2 ---"); printNum(&hi2); puts("--- lo2 ---"); printNum(&lo2); */ add_(&lo1,&hi1,&lh1); add_(&lo2,&hi2,&lh2); karatsuba(&lh1,&lh2,&z1); karatsuba(&lo1,&lo2,&z0); karatsuba(&hi1,&hi2,&z2); /*puts(" z0 z1 z2 "); printNum(&z0); printNum(&z1); printNum(&z2); */ add_(&z0,&z2,&t1); //t1=z0+z2 sub_(&z1,&t1,&t2);//t2=z1-t1 //puts("t2= "); //printNum(&t2); shift_left(&z2,2*m2);//z2*B^2*m2 shift_left(&t2,m2); //t2*B^m2 //printNum(&z2); //printNum(&t2); //printNum(&z0); add_(&z0,&z2,c); //printNum(c); add_(c,&t2,c); rm0(c); //printNum(c); }
int main() { add_(2,3); F77_FUNC(add)(2,3); return 0; }
void xml_compiler::filter_vector::traverse(const extracted_ptree& pt) { for (const auto& it : pt) { /* */ if (it.get_tag_name() == "not") { add_(BRIDGE_FILTERTYPE_APPLICATION_NOT, "ApplicationType::", it.get_data()); } else if (it.get_tag_name() == "only") { add_(BRIDGE_FILTERTYPE_APPLICATION_ONLY, "ApplicationType::", it.get_data()); } else if (it.get_tag_name() == "windowname_not") { add_(BRIDGE_FILTERTYPE_WINDOWNAME_NOT, "WindowName::", it.get_data()); } else if (it.get_tag_name() == "windowname_only") { add_(BRIDGE_FILTERTYPE_WINDOWNAME_ONLY, "WindowName::", it.get_data()); } else if (it.get_tag_name() == "uielementrole_not") { add_(BRIDGE_FILTERTYPE_UIELEMENTROLE_NOT, "UIElementRole::", it.get_data()); } else if (it.get_tag_name() == "uielementrole_only") { add_(BRIDGE_FILTERTYPE_UIELEMENTROLE_ONLY, "UIElementRole::", it.get_data()); } else if (it.get_tag_name() == "config_not") { add_(BRIDGE_FILTERTYPE_CONFIG_NOT, "ConfigIndex::", it.get_data()); } else if (it.get_tag_name() == "config_only") { add_(BRIDGE_FILTERTYPE_CONFIG_ONLY, "ConfigIndex::", it.get_data()); } else if (it.get_tag_name() == "device_not") { add_(BRIDGE_FILTERTYPE_DEVICE_NOT, "", it.get_data()); } else if (it.get_tag_name() == "device_only") { add_(BRIDGE_FILTERTYPE_DEVICE_ONLY, "", it.get_data()); } else if (it.get_tag_name() == "elapsedtimesincelastpressed_greaterthan") { add_(BRIDGE_FILTERTYPE_ELAPSEDTIMESINCELASTPRESSED_GREATERTHAN, "", it.get_data()); } else if (it.get_tag_name() == "elapsedtimesincelastpressed_lessthan") { add_(BRIDGE_FILTERTYPE_ELAPSEDTIMESINCELASTPRESSED_LESSTHAN, "", it.get_data()); } else if (it.get_tag_name() == "modifier_not") { add_(BRIDGE_FILTERTYPE_MODIFIER_NOT, "", it.get_data()); } else if (it.get_tag_name() == "modifier_only") { add_(BRIDGE_FILTERTYPE_MODIFIER_ONLY, "", it.get_data()); } else if (it.get_tag_name() == "modifierlocked_not") { add_(BRIDGE_FILTERTYPE_MODIFIER_LOCKED_NOT, "", it.get_data()); } else if (it.get_tag_name() == "modifierlocked_only") { add_(BRIDGE_FILTERTYPE_MODIFIER_LOCKED_ONLY, "", it.get_data()); } else if (it.get_tag_name() == "modifierstuck_not") { add_(BRIDGE_FILTERTYPE_MODIFIER_STUCK_NOT, "", it.get_data()); } else if (it.get_tag_name() == "modifierstuck_only") { add_(BRIDGE_FILTERTYPE_MODIFIER_STUCK_ONLY, "", it.get_data()); } else if (it.get_tag_name() == "inputsource_not" || it.get_tag_name() == "inputmode_not" || it.get_tag_name() == "inputsourcedetail_not" || it.get_tag_name() == "inputmodedetail_not") { // We allow "inputmode_*", "inputmodedetail_*", "inputsourcedetail_*" for compatibility. add_(BRIDGE_FILTERTYPE_INPUTSOURCE_NOT, "InputSource::", it.get_data()); } else if (it.get_tag_name() == "inputsource_only" || it.get_tag_name() == "inputmode_only" || it.get_tag_name() == "inputsourcedetail_only" || it.get_tag_name() == "inputmodedetail_only") { // We allow "inputmode_*", "inputmodedetail_*", "inputsourcedetail_*" for compatibility. add_(BRIDGE_FILTERTYPE_INPUTSOURCE_ONLY, "InputSource::", it.get_data()); } else if (it.get_tag_name() == "lastpressedphysicalkey_not") { add_(BRIDGE_FILTERTYPE_LASTPRESSEDPHYSICALKEY_NOT, "", it.get_data()); } else if (it.get_tag_name() == "lastpressedphysicalkey_only") { add_(BRIDGE_FILTERTYPE_LASTPRESSEDPHYSICALKEY_ONLY, "", it.get_data()); } else if (it.get_tag_name() == "pressingphysicalkeys_greaterthan") { add_(BRIDGE_FILTERTYPE_PRESSINGPHYSICALKEYS_GREATERTHAN, "Count::RawValue::", it.get_data()); } else if (it.get_tag_name() == "pressingphysicalkeys_lessthan") { add_(BRIDGE_FILTERTYPE_PRESSINGPHYSICALKEYS_LESSTHAN, "Count::RawValue::", it.get_data()); } } }