static void em_1003sats(struct gps_state *gps) { double elv, azm; int j, svn, nsats = INT16(&packet[WD(14)]); gps->hdop = INT32(&packet[WD(11)]) * 1.0e-2; for (j = 0; j < nsats; j++) { svn = INT16(&packet[WD(15 + (3 * j))]); elv = INT16(&packet[WD(17 + (3 * j))]) * 1.0e-4; azm = INT16(&packet[WD(16 + (3 * j))]) * 1.0e-4; if (elv < 0) elv = 0; if (azm < 0) azm += 2 * M_PI; new_sat(gps, svn, UNKNOWN_TIME, elv, azm, UNKNOWN_SNR, UNKNOWN_USED); } if (nsats) gps->updated = GPS_STATE_SATS; }
static void em_1002chsum(struct gps_state *gps) { int j, status, svn, snr, used, valid; int timestamp, datestamp, time; #define EPOCHDIFF 315532800 /* difference between GPS and UNIX time */ #define LEAP_SECONDS 13 /* hardcoded, bad me, should get it from the receiver */ datestamp = INT16(&packet[WD(10)]) * 7 * 86400 + EPOCHDIFF; timestamp = INT32(&packet[WD(11)]) + LEAP_SECONDS; time = datestamp + timestamp; for (j = 0; j < 12; j++) { status = INT16(&packet[WD(15 + (3 * j))]); used = status & 0x1; valid = status & 0x4; svn = INT16(&packet[WD(16 + (3 * j))]); snr = INT16(&packet[WD(17 + (3 * j))]) / 4; /* scaling snr to 0-16 */ new_sat(gps, svn, valid ? time : UNKNOWN_TIME, UNKNOWN_ELV, UNKNOWN_AZM, snr, used); } gps->updated = GPS_STATE_SIGNALS; }
int main() { long n; GF2X a, b, c, c1, ss, ss1, tt, tt1; double t; long iter, i; cout << WD(12,"n") << WD(12,"OldGCD") << WD(12,"GCD") << WD(12,"OldXGCD") << WD(12, "XGCD") << "\n"; cout.precision(3); cout.setf(ios::scientific); for (n = 32; n <= (1L << 18); n = n << 3) { random(a, n); random(b, n); OldGCD(c, a, b); GCD(c1, a, b); OldXGCD(c, ss, tt, a, b); XGCD(c1, ss1, tt1, a, b); if (c1 != c || ss1 != ss || tt1 != tt) { cerr << "**** GF2XTest FAILED!\n"; return 1; } cout << WD(12,n); iter = 0; do { iter = iter ? (2*iter) : 1; t = GetTime(); for (i = 0; i < iter; i++) OldGCD(c, a, b); t = GetTime()-t; } while (t < 0.5); cout << WD(12,t/iter); iter = 0; do { iter = iter ? (2*iter) : 1; t = GetTime(); for (i = 0; i < iter; i++) GCD(c, a, b); t = GetTime()-t; } while (t < 0.5); cout << WD(12,t/iter); iter = 0; do { iter = iter ? (2*iter) : 1; t = GetTime(); for (i = 0; i < iter; i++) OldXGCD(c, ss, tt, a, b); t = GetTime()-t; } while (t < 0.5); cout << WD(12,t/iter); iter = 0; do { iter = iter ? (2*iter) : 1; t = GetTime(); for (i = 0; i < iter; i++) XGCD(c, ss, tt, a, b); t = GetTime()-t; } while (t < 0.5); cout << WD(12,t/iter); cout << "\n"; } return 0; }
///' Calculate the network properties ///' ///' @details ///' \subsection{Input expectations:}{ ///' Note that this function expects all inputs to be sensible, as checked by ///' the R function 'checkUserInput' and processed by 'networkProperties'. ///' ///' These requirements are: ///' \itemize{ ///' \item{The ordering of node names across 'data' and 'net' is consistent.} ///' \item{The columns of 'data' are the nodes.} ///' \item{'net' is a square matrix, and its rownames are identical to its ///' column names.} ///' \item{'moduleAssigments' is a named character vector, where the names ///' represent node labels found in the discovery dataset. Unlike ///' 'PermutationProcedure', these may include nodes that are not ///' present in 'data' and 'net'.} ///' \item{The module labels specified in 'modules' must occur in ///' 'moduleAssignments'.} ///' } ///' } ///' ///' @param data data matrix from the dataset in which to calculate the network ///' properties. ///' @param net adjacency matrix of network edge weights between all pairs of ///' nodes in the dataset in which to calculate the network properties. ///' @param moduleAssignments a named character vector containing the module ///' each node belongs to in the discovery dataset. ///' @param modules a character vector of modules for which to calculate the ///' network properties for. ///' ///' @return a list containing the summary profile, node contribution, module ///' coherence, weighted degree, and average edge weight for each 'module'. ///' ///' @keywords internal // [[Rcpp::export]] Rcpp::List NetProps ( Rcpp::NumericMatrix data, Rcpp::NumericMatrix net, Rcpp::CharacterVector moduleAssignments, Rcpp::CharacterVector modules ) { // First, scale the matrix data unsigned int nSamples = data.nrow(); unsigned int nNodes = data.ncol(); arma::mat scaledData = Scale(data.begin(), nSamples, nNodes); R_CheckUserInterrupt(); // convert the colnames / rownames to C++ equivalents const std::vector<std::string> nodeNames (Rcpp::as<std::vector<std::string>>(colnames(net))); const std::vector<std::string> sampleNames (Rcpp::as<std::vector<std::string>>(rownames(data))); /* Next, we need to create two mappings: * - From node IDs to indices in the dataset of interest * - From modules to node IDs * - From modules to only node IDs present in the dataset of interest */ const namemap nodeIdxMap = MakeIdxMap(nodeNames); const stringmap modNodeMap = MakeModMap(moduleAssignments); const stringmap modNodePresentMap = MakeModMap(moduleAssignments, nodeIdxMap); // What modules do we actually want to analyse? const std::vector<std::string> mods (Rcpp::as<std::vector<std::string>>(modules)); R_CheckUserInterrupt(); // Calculate the network properties for each module std::string mod; // iterators unsigned int mNodesPresent, mNodes; arma::uvec nodeIdx, propIdx, nodeRank; namemap propIdxMap; std::vector<std::string> modNodeNames; arma::vec WD, SP, NC; // results containers double avgWeight, coherence; Rcpp::NumericVector degree, summary, contribution; // for casting to R equivalents Rcpp::List results; // final storage container for (auto mi = mods.begin(); mi != mods.end(); ++mi) { // What nodes are in this module? mod = *mi; modNodeNames = GetModNodeNames(mod, modNodeMap); // initialise results containers with NA values for nodes not present in // the dataset we're calculating the network properties in. degree = Rcpp::NumericVector(modNodeNames.size(), NA_REAL); contribution = Rcpp::NumericVector(modNodeNames.size(), NA_REAL); summary = Rcpp::NumericVector(nSamples, NA_REAL); avgWeight = NA_REAL; coherence = NA_REAL; degree.names() = modNodeNames; contribution.names() = modNodeNames; // Create a mapping between node names and the result vectors propIdxMap = MakeIdxMap(modNodeNames); // Get just the indices of nodes that are present in the requested dataset nodeIdx = GetNodeIdx(mod, modNodePresentMap, nodeIdxMap); mNodesPresent = nodeIdx.n_elem; // And a mapping of those nodes to the initialised vectors propIdx = GetNodeIdx(mod, modNodePresentMap, propIdxMap); mNodes = propIdx.n_elem; // Calculate the properties if the module has nodes in the test dataset if (nodeIdx.n_elem > 0) { // sort the node indices for sequential memory access nodeRank = SortNodes(nodeIdx.memptr(), mNodesPresent); WD = WeightedDegree(net.begin(), nNodes, nodeIdx.memptr(), mNodesPresent); WD = WD(nodeRank); // reorder results avgWeight = AverageEdgeWeight(WD.memptr(), WD.n_elem); R_CheckUserInterrupt(); SP = SummaryProfile(scaledData.memptr(), nSamples, nNodes, nodeIdx.memptr(), mNodesPresent); R_CheckUserInterrupt(); NC = NodeContribution(scaledData.memptr(), nSamples, nNodes, nodeIdx.memptr(), mNodesPresent, SP.memptr()); NC = NC(nodeRank); // reorder results coherence = ModuleCoherence(NC.memptr(), mNodesPresent); R_CheckUserInterrupt(); // Convert NaNs to NAs SP.elem(arma::find_nonfinite(SP)).fill(NA_REAL); NC.elem(arma::find_nonfinite(NC)).fill(NA_REAL); if (!arma::is_finite(coherence)) { coherence = NA_REAL; } // Fill results vectors Fill(degree, WD.memptr(), mNodesPresent, propIdx.memptr(), mNodes); Fill(contribution, NC.memptr(), mNodesPresent, propIdx.memptr(), mNodes); summary = Rcpp::NumericVector(SP.begin(), SP.end()); } summary.names() = sampleNames; results.push_back( Rcpp::List::create( Rcpp::Named("summary") = summary, Rcpp::Named("contribution") = contribution, Rcpp::Named("coherence") = coherence, Rcpp::Named("degree") = degree, Rcpp::Named("avgWeight") = avgWeight ) ); } results.names() = mods; return(results); }
///' Calculate the network properties, data matrix not provided ///' ///' @details ///' \subsection{Input expectations:}{ ///' Note that this function expects all inputs to be sensible, as checked by ///' the R function 'checkUserInput' and processed by 'networkProperties'. ///' ///' These requirements are: ///' \itemize{ ///' \item{'net' is a square matrix, and its rownames are identical to its ///' column names.} ///' \item{'moduleAssigments' is a named character vector, where the names ///' represent node labels found in the discovery dataset. Unlike ///' 'PermutationProcedure', these may include nodes that are not ///' present in 'data' and 'net'.} ///' \item{The module labels specified in 'modules' must occur in ///' 'moduleAssignments'.} ///' } ///' } ///' ///' @param net adjacency matrix of network edge weights between all pairs of ///' nodes in the dataset in which to calculate the network properties. ///' @param moduleAssignments a named character vector containing the module ///' each node belongs to in the discovery dataset. ///' @param modules a character vector of modules for which to calculate the ///' network properties for. ///' ///' @return a list containing the summary profile, node contribution, module ///' coherence, weighted degree, and average edge weight for each 'module'. ///' ///' @keywords internal // [[Rcpp::export]] Rcpp::List NetPropsNoData ( Rcpp::NumericMatrix net, Rcpp::CharacterVector moduleAssignments, Rcpp::CharacterVector modules ) { // convert the colnames / rownames to C++ equivalents const std::vector<std::string> nodeNames (Rcpp::as<std::vector<std::string>>(colnames(net))); unsigned int nNodes = net.ncol(); R_CheckUserInterrupt(); /* Next, we need to create two mappings: * - From node IDs to indices in the dataset of interest * - From modules to node IDs * - From modules to only node IDs present in the dataset of interest */ const namemap nodeIdxMap = MakeIdxMap(nodeNames); const stringmap modNodeMap = MakeModMap(moduleAssignments); const stringmap modNodePresentMap = MakeModMap(moduleAssignments, nodeIdxMap); // What modules do we actually want to analyse? const std::vector<std::string> mods (Rcpp::as<std::vector<std::string>>(modules)); R_CheckUserInterrupt(); // Calculate the network properties for each module std::string mod; // iterators unsigned int mNodesPresent, mNodes; arma::uvec nodeIdx, propIdx, nodeRank; namemap propIdxMap; std::vector<std::string> modNodeNames; arma::vec WD; // results containers double avgWeight; Rcpp::NumericVector degree; // for casting to R equivalents Rcpp::List results; // final storage container for (auto mi = mods.begin(); mi != mods.end(); ++mi) { // What nodes are in this module? // modNodeNames = names(moduleAssignments[moduleAssignments == mod]) mod = *mi; modNodeNames = GetModNodeNames(mod, modNodeMap); // initialise results containers with NA values for nodes not present in // the dataset we're calculating the network properties in. degree = Rcpp::NumericVector(modNodeNames.size(), NA_REAL); avgWeight = NA_REAL; degree.names() = modNodeNames; // Create a mapping between node names and the result vectors propIdxMap = MakeIdxMap(modNodeNames); // Get just the indices of nodes that are present in the requested dataset nodeIdx = GetNodeIdx(mod, modNodePresentMap, nodeIdxMap); mNodesPresent = nodeIdx.n_elem; // And a mapping of those nodes to the initialised vectors propIdx = GetNodeIdx(mod, modNodePresentMap, propIdxMap); mNodes = propIdx.n_elem; // Calculate the properties if the module has nodes in the test dataset if (nodeIdx.n_elem > 0) { // sort the node indices for sequential memory access nodeRank = SortNodes(nodeIdx.memptr(), mNodesPresent); WD = WeightedDegree(net.begin(), nNodes, nodeIdx.memptr(), mNodesPresent); WD = WD(nodeRank); // reorder results avgWeight = AverageEdgeWeight(WD.memptr(), WD.n_elem); R_CheckUserInterrupt(); // Fill the results vectors appropriately Fill(degree, WD.memptr(), mNodesPresent, propIdx.memptr(), mNodes); } results.push_back( Rcpp::List::create( Rcpp::Named("degree") = degree, Rcpp::Named("avgWeight") = avgWeight ) ); } results.names() = mods; return(results); }
static void em_1000geodpos(struct gps_state *gps) { double speed; int bearing, solinv; solinv = INT16(&packet[WD(10)]) & 0x5; if (solinv) gps->fix &= ~0x3; /* do we know whether it is a 2D or 3D fix? */ else gps->fix |= 0x3; gps->lat = INT32(&packet[WD(27)]) * 1.0e-8; gps->lon = INT32(&packet[WD(29)]) * 1.0e-8; gps->alt = INT32(&packet[WD(31)]) * 1.0e-2; speed = ((unsigned int)INT32(&packet[WD(34)])) * 1.0e-2; bearing = radtodeg(INT16(&packet[WD(36)]) * 1.0e-3); if (bearing < 0) bearing += 2 * M_PI; gps->bearing = radtodeg(bearing); gps->spd_up = 0.0; gps->spd_east = sin(bearing) * speed; gps->spd_north = cos(bearing) * speed; gps->time = conv_date(INT16(&packet[WD(21)]), INT16(&packet[WD(20)]), INT16(&packet[WD(19)])) + INT16(&packet[WD(24)])+(60*INT16(&packet[WD(23)])) + (3600*INT16(&packet[WD(22)])); gps->updated |= GPS_STATE_FIX | GPS_STATE_COORD | GPS_STATE_BEARING | GPS_STATE_SPEED; }
void bwrite(Complx *buffer, size_t num) { // Write num Complx numbers to the buffer, increment the pointer WriteDirect WD(ramdisk, diskbuffer); int sizebytes = num*sizeof(Complx); WD.BlockingAppend(filename, (char*)buffer, sizebytes); }