inline void PrintFTReal(const std::string& filename, double x_shift = 0.0) { std::ofstream output_file(filename.c_str()); assert(output_file.is_open()); for (int i = total_length(); i < spec_length_; ++i) { output_file << (i-spec_length_)*freq_spacing_nu_ + x_shift << " " << real(fourier_transform_(i)) << std::endl; } for (int i = 0; i < total_length(); ++i) { output_file << i*freq_spacing_nu_ + x_shift << " " << real(fourier_transform_(i)) << std::endl; } output_file.close(); }
void print_array_of_strings(char **a) { char *arr; int i; int j; int size; i = 0; j = 0; size = total_length(a); arr = malloc(size * sizeof(char)); while (a[i] != '\0') { j = 0; while (a[i][j] != '\0') { arr[j] = a[i][j]; print_char(arr[j]); j++; } print_char(' '); i++; } print_char('\n'); }
static rc_t CC build_scaffold_impl(void *const data, VXformInfo const *const info, int64_t const row_id, VRowResult *const rslt, uint32_t const argc, VRowData const argv[]) { self_t const *const self = data; INSDC_coord_one const *const start = argv[0].u.data.base; INSDC_coord_len const *const length = argv[1].u.data.base; NCBI_WGS_component_props const *const props = argv[2].u.data.base; int64_t const *const join = argv[3].u.data.base; unsigned const components = argv[0].u.data.elem_count; rc_t rc; assert(argv[1].u.data.elem_count == components); assert(argv[2].u.data.elem_count == components); assert(start != NULL); assert(length != NULL); assert(props != NULL); assert(join != NULL); assert(rslt->elem_bits == 8); rslt->elem_count = total_length(components, &length[argv[1].u.data.first_elem]); rc = KDataBufferResize(rslt->data, rslt->elem_count); if (rc == 0) rc = self->impl(self, rslt->data->base, components, &start[argv[0].u.data.first_elem], &length[argv[1].u.data.first_elem], &props[argv[2].u.data.first_elem], &join[argv[3].u.data.first_elem]); return rc; }
float total_length_bezier(size_t end = segments) { // TODO assert(end <= segments); return total_length(end * seg_size); }
float total_length_cubic(size_t end = num_points - 1) { // TODO assert(end < num_points); return total_length(end); }
/** * Build any objects that will need to be utilised by this object. * Obtain smart_pointers to any objects that will be used by this object. */ void Data::DoBuild() { length_weight_ = model_->managers().length_weight()->GetLengthWeight(length_weight_label_); if (!length_weight_) LOG_ERROR_P(PARAM_LENGTH_WEIGHT) << "(" << length_weight_label_ << ") could not be found. Have you defined it?"; if (!data_table_) LOG_CODE_ERROR() << "!data_table_"; // basic validation const vector<string>& columns = data_table_->columns(); if (columns.size() != model_->age_spread() + 1) LOG_ERROR_P(PARAM_DATA) << "column count (" << columns.size() << ") must be <year> <ages> for a total of " << model_->age_spread() + 1 << " columns"; if (columns[0] != PARAM_YEAR) LOG_ERROR_P(PARAM_DATA) << "first column label must be 'year'. First column label was '" << columns[0] << "'"; /** * Build our data_by_year map so we can fill the gaps * and use it in the model */ vector<vector<string>>& data = data_table_->data(); vector<Double> total_length(model_->age_spread(), 0.0); Double number_of_years = 0.0; for (vector<string> row : data) { if (row.size() != columns.size()) LOG_CODE_ERROR() << "row.size() != columns.size()"; number_of_years += 1; unsigned year = utilities::ToInline<string, unsigned>(row[0]); for (unsigned i = 1; i < row.size(); ++i) { data_by_year_[year].push_back(utilities::ToInline<string, Double>(row[i])); total_length[i - 1] += utilities::ToInline<string, Double>(row[i]); } } /* * Build our average map for use in initialisation and simulation phases */ for (unsigned i = 0; i < model_->age_spread(); ++i) data_by_age_[model_->min_age() + i] = total_length[i] / number_of_years; /** * Check if we're using a mean method and build a vector of means now * before we modify the data_by_year object by filling the external * gaps */ if (external_gaps_ == PARAM_MEAN || internal_gaps_ == PARAM_MEAN) { for (unsigned i = 0; i < model_->age_spread(); ++i) { Double total = 0.0; for (auto iter = data_by_year_.begin(); iter != data_by_year_.end(); ++iter) total += iter->second[i]; means_.push_back(total / data_by_year_.size()); } } // Fill our gaps FillExternalGaps(); FillInternalGaps(); }
// Similar to FourierPlus, but without the assumption of symmetry // around t = 0. inline void FourierNoSymmPlus() { for (int i = 0; i<length(); ++i) { correlation_function_(i) -= correlation_function_(length()-1); } fourier_transform_ = fft(correlation_function_); freq_spacing_nu_ = 1.0/2.0/C_SPEED/(x_spacing()*total_length()); freq_spacing_omega_ = freq_spacing_nu_*2.0*M_PI*C_SPEED; }
// Similar to FourierPlus, but doesn't shift the time correlation function // to be zero after corr steps. Formerly called run_fftw. inline void Fourier() { for (int i = length()+2*zeros()-1; i<spec_length_; i++) { correlation_function_(i) = std::conj(correlation_function_(spec_length_-i)); } fourier_transform_ = fft(correlation_function_); freq_spacing_nu_ = 1.0/2.0/C_SPEED/(x_spacing()*total_length()); freq_spacing_omega_ = freq_spacing_nu_*2.0*M_PI*C_SPEED; }
Point linear_interpolate (float p) { assert(p <= 1.0f && p >= 0.0f); float d = total_length() * p; int ii = -1; float dd; // OPTIMIZE: Could quicksearch for (int i = (signed int)num_points - 1; i >= 0; --i) { if(total_length(i) <= d) { ii = i; dd = d - total_length(i); break; } } assert(ii != -1); float pp = dd / distance(points[ii], points[ii+1]); return points[ii] + pp * (points[ii+1] - points[ii]); }
char *string_concat(char *a, char *b) { int i; int j = 0; char *str1; int length = total_length(a,b); str1 = malloc(sizeof(char) * length); if (str1 == NULL) { return NULL; } for (i = 0; a[i] != '\0'; i++) { str1[i] = a[i]; /*copying values from one array to the next one*/ } while( b[j] != '\0') { str1[i] = b[j];/*following the continuation of the array copying values*/ i++; j++; } return str1; }
inline size_t _base_helper_impl<HelperTag, ipv4_frame>::payload_length() const { return total_length() - header_length(); }
inline CxTCF(int length, int x_spacing, int interval = 1, int zeros = 0) : TCF(length, x_spacing, interval, zeros), spec_length_(2*total_length()-2) { // TODO(Zak): I think this should be -1 not -2... test that. correlation_function_.zeros(spec_length_); }
bool operator[](int i) const { _p_graph._data[_index*total_length()+i].is_neighbor(); }
// Returns average length of the edges: double avg_len() const { return empty() ? 0 : total_length()/size(); }