//-------------------------------------------------------------- bool ofxMuiNumberData::addValue(float val, ofxMuiRange _bounds, ofxMuiRange _range) { // prepare iterators // start inserting historyLength.push_back(_defaults->dataHistoryLength); deque<float> initQ(_defaults->dataHistoryLength, val); // create a history values.push_back(initQ); // add the queue bounds.push_back(_bounds); ranges.push_back(_range); displayPrecision.push_back(_defaults->displayPrecision); if(isBoolType() || isIntType()) { incrementValues.push_back(_defaults->incrementInt); } else if(isFloatType()) { incrementValues.push_back(_defaults->incrementFloat); } bool boundsChanged = false; bool rangeChanged = false; bool valueChanged = false; checkRange(boundsChanged, rangeChanged, getNumValues()-1); constrainValue(valueChanged, getNumValues()-1); }
VariablesGrid::operator DMatrix() const { DMatrix tmp(getNumPoints( ), getNumValues( ) + 1); for (uint run1 = 0; run1 < getNumPoints(); ++run1) { tmp(run1, 0) = getTime(run1); for (uint run2 = 0; run2 < getNumValues(); ++run2) tmp(run1, 1 + run2) = operator()(run1, run2); } return tmp; }
std::vector<Section> Config::getSectionList() { int count = getNumValues("project"); std::vector<Section> ret; for(int i = 0; i < count; i++){ std::string filename = getValueStr("project", i); try { std::ifstream in(filename.c_str()); std::string line; while(getline(in, line).good()){ Section sec; if(parseSection(line, sec)){ sec.source = filename; ret.push_back(sec); } } in.close(); } catch (std::ifstream::failure ex){ LOG("could not load file: " << filename, LOG_VERBOSE); } } return ret; }
//-------------------------------------------------------------- bool ofxMuiNumberData::isValidInsertionIndex(int index) const { if(isArrayType() && index > -1 && index <= getNumValues()) { return true; } else { ofLog(OF_LOG_ERROR, "ofxMuiNumberData: invalid insertion index " + ofToString(index) + " where size = " +ofToString(getNumValues())); return false; } }
VariablesGrid VariablesGrid::getValuesSubGrid( uint startIdx, uint endIdx ) const { VariablesGrid newVariablesGrid; if ( ( startIdx >= getNumValues( ) ) || ( endIdx >= getNumValues( ) ) ) return newVariablesGrid; if ( startIdx > endIdx ) return newVariablesGrid; for( uint i=0; i<getNumPoints( ); ++i ) newVariablesGrid.addMatrix( values[i]->getRows( startIdx,endIdx ),getTime( i ) ); return newVariablesGrid; }
//-------------------------------------------------------------- bool ofxMuiNumberData::isValidIndex(int index) const { if(index == 0 || (index > 0 && index < getNumValues() && isArrayType())) { return true; } else { ofLog(OF_LOG_ERROR, "ofxMuiNumberData: invalid index " + index); return false; // a negative index is never good } }
//-------------------------------------------------------------- bool ofxMuiNumberData::canUseSetAll() const { if(getNumValues() > 0 && isArrayType()) { return true; } else { ofLog(OF_LOG_WARNING, "ofxMuiNumberData: unable to set all - invalid numValues < 1 or not array type"); return false; // a negative index is never good } }
std::vector<std::string> Config::getValues(std::string key) { std::vector<std::string> ret; for(int i = 0; i < getNumValues(key); i++) ret.push_back(getValueStr(key, i)); return ret; }
bool Config::containsValue(std::string key, std::string value) { int nv = getNumValues(key); for(int i = 0; i < nv; i++) if(getValueStr(key, i) == value) return true; return false; }
void JointVelAccFeature::computeValuesAndGradients(boost::shared_ptr<learnable_cost_function::Input const> generic_input, std::vector<double>& feature_values, bool compute_gradients, std::vector<Eigen::VectorXd>& gradients, bool& state_validity) { boost::shared_ptr<stomp_ros_interface::StompCostFunctionInput const> input = boost::dynamic_pointer_cast<stomp_ros_interface::StompCostFunctionInput const>(generic_input); // initialize arrays feature_values.clear(); feature_values.resize(getNumValues(), 0.0); if (compute_gradients) { gradients.resize(getNumValues(), Eigen::VectorXd::Zero(input->getNumDimensions())); } for (int j=0; j<num_joints_; ++j) { feature_values[j*2 + 0] = input->joint_angles_vel_(j)*input->joint_angles_vel_(j); feature_values[j*2 + 1] = input->joint_angles_acc_(j)*input->joint_angles_acc_(j); } }
std::string Config::getValueStr(std::string key, std::string addBefore, std::string separator, std::string addAfter, bool reverse) { std::string ret; if(configItems.count(key) != 0 && getValueStr(key, 0) != ""){ ret.append(addBefore); bool first = true; int start = reverse ? getNumValues(key) - 1 : 0; int end = reverse ? -1 : getNumValues(key); for(int i = start; i != end; i += reverse ? -1 : 1){ if(first){ first = false; }else{ ret.append(separator); } ret.append(getValueStr(key, i)); } ret.append(addAfter); } return ret; }
void CartesianOrientationFeature::computeValuesAndGradients(boost::shared_ptr<learnable_cost_function::Input const> generic_input, std::vector<double>& feature_values, bool compute_gradients, std::vector<Eigen::VectorXd>& gradients, bool& state_validity) { boost::shared_ptr<stomp_ros_interface::StompCostFunctionInput const> input = boost::dynamic_pointer_cast<stomp_ros_interface::StompCostFunctionInput const>(generic_input); // initialize arrays feature_values.clear(); feature_values.resize(getNumValues(), 0.0); if (compute_gradients) { gradients.resize(getNumValues(), Eigen::VectorXd::Zero(input->getNumDimensions())); } // abs dot product of end effector orient and cart velocity int i = input->collision_point_pos_.size()-1; int j = input->planning_group_->end_effector_segment_index_; KDL::Vector orient_vector = input->segment_frames_[j].M.UnitZ(); KDL::Vector velocity_vector = input->collision_point_vel_[i]; velocity_vector.Normalize(); feature_values[0] = fabs(KDL::dot(orient_vector, velocity_vector)); }
returnValue VariablesGrid::getIntegral( InterpolationMode mode, Vector& value ) const { value.setZero(); switch( mode ) { case IM_CONSTANT: for( uint i=0; i<getNumIntervals( ); ++i ) { for( uint j=0; j<getNumValues( ); ++j ) { //value(j) += ( getIntervalLength( i ) / getIntervalLength( ) ) * operator()( i,j ); value(j) += getIntervalLength( i ) * operator()( i,j ); } } break; case IM_LINEAR: for( uint i=0; i<getNumIntervals( ); ++i ) { for( uint j=0; j<getNumValues( ); ++j ) { //value(j) += ( getIntervalLength( i ) / getIntervalLength( ) ) * ( operator()( i,j ) + operator()( i+1,j ) ) / 2.0; value(j) += getIntervalLength( i ) * ( operator()( i,j ) + operator()( i+1,j ) ) / 2.0; } } break; default: return ACADOERROR( RET_NOT_YET_IMPLEMENTED ); } return SUCCESSFUL_RETURN; }
void StompCostFeature::initOutputs(const boost::shared_ptr<StompTrajectory const>& trajectory, Eigen::MatrixXd& feature_values, bool compute_gradients, std::vector<Eigen::MatrixXd>& gradients, std::vector<int>& validities) const { int num_features = getNumValues(); feature_values = Eigen::MatrixXd::Zero(trajectory->num_time_steps_, num_features); validities.clear(); validities.resize(trajectory->num_time_steps_, 1); if (compute_gradients) { gradients.resize(num_features); for (int i=0; i<num_features; ++i) { gradients[i] = Eigen::MatrixXd::Zero(trajectory->num_joints_, trajectory->num_time_steps_); } } }
int ResetStateOnTriggerTestProbe::outputState(double timevalue) { getValues(timevalue); // calls calcValues if (parent->columnId()!=0) { return PV_SUCCESS; } if (probeStatus != 0) { int nBatch = getNumValues(); if (nBatch==1) { int nnz = (int) nearbyint(getValuesBuffer()[0]); fprintf(outputstream->fp, "%s t=%f, %d neuron%s the wrong value.\n", getMessage(), timevalue, nnz, nnz==1 ? " has" : "s have"); } else { for (int k=0; k<nBatch; k++) { int nnz = (int) nearbyint(getValuesBuffer()[k]); fprintf(outputstream->fp, "%s t=%f, batch element %d, %d neuron%s the wrong value.\n", getMessage(), timevalue, k, nnz, nnz==1 ? " has" : "s have"); } } } return PV_SUCCESS; }
int ResetStateOnTriggerTestProbe::calcValues(double timevalue) { int nBatch = getNumValues(); if (timevalue > parent->getStartTime()) { int N = targetLayer->getNumNeurons(); int NGlobal = targetLayer->getNumGlobalNeurons(); PVLayerLoc const * loc = targetLayer->getLayerLoc(); PVHalo const * halo = &loc->halo; int inttime = (int) nearbyintf(timevalue/parent->getDeltaTime()); for (int b=0; b<nBatch; b++) { int numDiscreps = 0; pvadata_t const * activity = targetLayer->getLayerData() + b*targetLayer->getNumExtended(); for (int k=0; k<N; k++) { int kex = kIndexExtended(k, loc->nx, loc->ny, loc->nf, halo->lt, halo->rt, halo->dn, halo->up); pvadata_t a = activity[kex]; int kGlobal = globalIndexFromLocal(k, *loc); int correctValue = 4*kGlobal*((inttime + 4)%5+1) + (kGlobal==((((inttime-1)/5)*5)+1)%NGlobal); if ( a != (pvadata_t) correctValue ) { numDiscreps++; } } getValuesBuffer()[b] = (double) numDiscreps; } MPI_Allreduce(MPI_IN_PLACE, getValuesBuffer(), nBatch, MPI_DOUBLE, MPI_SUM, parent->icCommunicator()->communicator()); if (probeStatus==0) { for (int k=0; k<nBatch; k++) { if (getValuesBuffer()[k]) { probeStatus = 1; firstFailureTime = timevalue; } } } } else { for (int b=0; b<nBatch; b++) { getValuesBuffer()[b] = 0.0; } } return PV_SUCCESS; }
GammaPDIndexDecoder(std::vector<std::string> const & rVfn) : Vfn(rVfn), valuesPerFile(0), blocksPerFile(0), indexEntriesPerFile(0) { uint64_t o = 0; for ( uint64_t i = 0; i < Vfn.size(); ++i ) { libmaus2::aio::InputStreamInstance ISI(Vfn[i]); uint64_t const vpf = getNumValues(ISI); if ( vpf ) { valuesPerFile.push_back(vpf); blocksPerFile.push_back(getNumBlocks(ISI)); indexEntriesPerFile.push_back(blocksPerFile.back()+1); indexOffset.push_back(getIndexOffset(ISI)); Vfn[o++] = Vfn[i]; } } // for prefix sum valuesPerFile.push_back(0); Vfn.resize(o); libmaus2::util::PrefixSums::prefixSums(valuesPerFile.begin(),valuesPerFile.end()); }
returnValue VariablesGrid::initializeFromBounds( ) { uint run1, run2; for( run1 = 0; run1 < getNumPoints(); run1++ ){ for( run2 = 0; run2 < getNumValues(); run2++ ){ if( fabs( getLowerBound(run1,run2) ) < 0.999*INFTY && fabs( getUpperBound(run1,run2) ) < 0.999*INFTY ){ operator()(run1,run2) = 0.5*( getLowerBound(run1,run2) + getUpperBound(run1,run2) ); } if( fabs( getLowerBound(run1,run2) ) >= 0.999*INFTY && fabs( getUpperBound(run1,run2) ) < 0.999*INFTY ){ operator()(run1,run2) = getUpperBound(run1,run2); } if( fabs( getLowerBound(run1,run2) ) < 0.999*INFTY && fabs( getUpperBound(run1,run2) ) >= 0.999*INFTY ){ operator()(run1,run2) = getLowerBound(run1,run2); } if( fabs( getLowerBound(run1,run2) ) >= 0.999*INFTY && fabs( getUpperBound(run1,run2) ) >= 0.999*INFTY ){ operator()(run1,run2) = 0.0; } } } return SUCCESSFUL_RETURN; }
void PSViewDictionaryToken:: print() { CStrUtil::printf("-dict-"); if (psview_->getDebug()) { print(); CStrUtil::printf("<<"); for (int i = 1; i <= getNumValues(); i++) { if (i > 1) CStrUtil::printf(" "); getKey(i)->print(); CStrUtil::printf(" "); getValue(i)->print(); } CStrUtil::printf(">>\n"); } }
//-------------------------------------------------------------- void ofxMuiNumberData::toggleAll() { for(int i = 0; i < getNumValues(); i++) { toggle(i); } }
bool TinyAmixerControl::accessHW(bool receive, std::string &error) { CAutoLog autoLog(getConfigurableElement(), "ALSA", isDebugEnabled()); // Mixer handle struct mixer *mixer; // Mixer control handle struct mixer_ctl *mixerControl; uint32_t elementCount; std::string controlName = getControlName(); // Debug conditionnaly enabled in XML logControlInfo(receive); // Check parameter type is ok (deferred error, no exceptions available :-() if (!isTypeSupported()) { error = "Parameter type not supported."; return false; } // Check card number int32_t cardIndex = getCardNumber(); if (cardIndex < 0) { error = "Card " + getCardName() + " not found. Error: " + strerror(-cardIndex); return false; } // Open alsa mixer // getMixerHandle is non-const; we need to forcefully remove the constness // then, we need to cast the generic subsystem into a TinyAlsaSubsystem. mixer = static_cast<TinyAlsaSubsystem *>( const_cast<CSubsystem *>(getSubsystem()))->getMixerHandle(cardIndex); if (!mixer) { error = "Failed to open mixer for card: " + getCardName(); return false; } // Get control handle if (isdigit(controlName[0])) { mixerControl = mixer_get_ctl(mixer, asInteger(controlName)); } else { mixerControl = mixer_get_ctl_by_name(mixer, controlName.c_str()); } // Check control has been found if (!mixerControl) { error = "Failed to open mixer control: " + controlName; return false; } // Get element count elementCount = getNumValues(mixerControl); uint32_t scalarSize = getScalarSize(); // Check available size if (elementCount * scalarSize != getSize()) { error = "ALSA: Control element count (" + asString(elementCount) + ") and configurable scalar element count (" + asString(getSize() / scalarSize) + ") mismatch"; return false; } // Read/Write element bool success; if (receive) { success = readControl(mixerControl, elementCount, error); } else { success = writeControl(mixerControl, elementCount, error); } return success; }
//-------------------------------------------------------------- void ofxMuiNumberData::setAllNormalizedValues(float val) { if(canUseSetAll()) { for(int i = 0; i < getNumValues(); i++) setNormalizedValue(val,i); } }
const int EnviData::getSize() const { return (sizeof(instance) + sizeof(type)+name.length() + sizeof(Value) * getNumValues()); }
//-------------------------------------------------------------- void ofxMuiNumberData::addAll(float value) { for(int i = 0; i < getNumValues(); i++) { add(value, i); } }
//-------------------------------------------------------------- void ofxMuiNumberData::subtractAll(float value) { for(int i = 0; i < getNumValues(); i++) { subtract(value, i); } }
//-------------------------------------------------------------- void ofxMuiNumberData::multiplyAll(float value) { for(int i = 0; i < getNumValues(); i++) { multiply(value, i); } }
//-------------------------------------------------------------- void ofxMuiNumberData::setAllValues(float val) { if(canUseSetAll()) { for(int i = 0; i < getNumValues(); i++) pushNewValue(val,true, i); } }
//-------------------------------------------------------------- void ofxMuiNumberData::divideAll(float value) { for(int i = 0; i < getNumValues(); i++) { divide(value, i); } }
//-------------------------------------------------------------- void ofxMuiNumberData::invertAll() { for(int i = 0; i < getNumValues(); i++) { invert(i); } }