Ctype<inplace> _dropout_impl(T& input, double p, bool train) { TORCH_CHECK(p >= 0 && p <= 1, "dropout probability has to be between 0 and 1, but got ", p); if (p == 0 || !train) { return input; } if (p == 1) { return multiply<inplace>(input, at::zeros({}, input.options())); } at::Tensor b; // used for alpha_dropout only auto noise = feature_dropout ? make_feature_noise(input) : at::empty_like(input); noise.bernoulli_(1 - p); if (alpha_dropout) { constexpr double alpha = 1.7580993408473766; double a = 1. / std::sqrt((alpha * alpha * p + 1) * (1 - p)); b = noise.add(-1).mul_(alpha * a).add_(alpha * a * p); noise.mul_(a); } else { noise.div_(1 - p); } if (!alpha_dropout) { return multiply<inplace>(input, noise); } else { return multiply<inplace>(input, noise).add_(b); } }
int maximumGap(vector<int>& nums) { int gap = 0, l = INT_MAX, u = 0; for (int num: nums) { l = min(l, num); u = max(u, num); } if (l < u) { gap = div_(u - l, nums.size() - 1); vector<vector<int>> um(nums.size()); for (int num: nums) um[(num - l) / gap].push_back(num); u = l; for (auto &v: um) if (!v.empty()) { int pu = u; l = INT_MAX; for (int num: v) { l = min(l, num); u = max(u, num); } gap = max(gap, l - pu); } } return gap; }
static inline void forth_vm_execute_instruction(forth_context_type *fc, char cmd) { // printf("%c\n",cmd); // getchar(); switch(cmd) { case '0': push(fc,0); break; case '1': push(fc,1); break; case '2': push(fc,2); break; case '3': push(fc,3); break; case '4': push(fc,4); break; case '5': push(fc,5); break; case '6': push(fc,6); break; case '7': push(fc,7); break; case '8': push(fc,8); break; case '9': push(fc,9); break; case '@': at(fc); break; //@ case '!': to(fc); break; //! case 'd': fc->SP+=fc->cell; break; //drop case 'D': dup(fc); break; //dup case 's': swap_(fc); break; //swap case 'l': push(fc,next_cell(fc)); break; //lit case '+': add(fc); break; //+ case '-': sub(fc); break; //- case '*': mul(fc); break; //* case '/': div_(fc); break; // / case '%': mod(fc); break; //mod case '&': and(fc); break; // and case '|': or(fc); break; // or case '^': xor(fc); break; // xor case '>': more(fc); break; // > case '<': less(fc); break; // < case '=': eq(fc); break; // = case 'b': branch(fc); break; // branch case '?': cbranch(fc); break; // ?branch case 'c': call(fc); break; // call case 'r': ret(fc); break; // ret case 't': to_r(fc); break; // >R case 'f': from_r(fc); break; // R> case 'i': in(fc); break; // in case 'o': out(fc); break; // out case '_': fc->stop=1; break; // stop case 'A': adr0(fc); break; // @0 case 1: push(fc,fc->SP); break; // SP@ case 2: fc->SP=pop(fc); break; // SP! case 3: push(fc,fc->RP); break; // RP@ case 4: fc->RP=pop(fc); break; // RP! case 5: shl(fc); break; // << case 6: shr(fc); break; // >> case 7: push(fc,*(size_t *)(fc->mem+fc->RP)); break; // i case 8: cat(fc); break; // c@ case 9: cto(fc); break; // c! case 10: set_current_state(TASK_INTERRUPTIBLE); schedule_timeout(1); break; // nop case 11: in_ready(fc); break; // ?in case 12: out_ready(fc); break; // ?out case 16: umod(fc); break; // umod case 17: udiv(fc); break; // u/ // kernel case 'K': kalsym_lookup(fc); break; // lookup kallsym address case 18: kcall(fc); break; // kcall } }
int main(int argc, char** argv) { int nStatus = 0; if (argc < 2) { usage(argv[0]); exit(-1); } if (!strcmp(argv[1], "hexdump")) { if (argc == 2) { nStatus = hexdump(NULL); } else if (argc == 3) { nStatus = hexdump(argv[2]); } else { usage(argv[0]); exit(-1); } } else if (!strcmp(argv[1], "enc-base64")) { if (argc == 2) { nStatus = base64encode(NULL); } else if (argc == 3) { nStatus = base64encode(argv[2]); } else { usage(argv[0]); exit(-1); } } else if (!strcmp(argv[1], "dec-base64")) { if (argc == 2) { nStatus = base64decode(NULL); } else if (argc == 3) { nStatus = base64decode(argv[2]); } else { usage(argv[0]); exit(-1); } } else if (!strcmp(argv[1], "mul")) { if (argc != 4) { usage(argv[0]); exit(-1); } checkargs(argv); mul(argv[2], argv[3]); } else if (!strcmp(argv[1], "div")) { if (argc != 4) { usage(argv[0]); exit(-1); } checkargs(argv); div_(argv[2], argv[3]); } else { usage(argv[0]); exit(-1); } return nStatus; }