long FitsFile::GetGroupSize() { if(!HasGroups()) throw FitsIOException("HDU has no groups"); long size = 1; for(int i=2;i<=GetCurrentImageDimensionCount();++i) { size *= GetCurrentImageSize(i); } size += GetParameterCount(); return size; }
bool FitsFile::HasGroupParameter(const std::string ¶meterName) { if(!HasGroups()) return false; int parameterCount = GetParameterCount(); for(int i=1;i<=parameterCount;++i) { std::stringstream s; s << "PTYPE" << i; if(GetKeywordValue(s.str()) == parameterName) return true; } return false; }
void Gaussian::SetParameters(const std::vector<double>& params_){ try{ fParameterManager.SetParameters(params_); } catch(const ParameterCountError&){ throw ParameterCountError("Gaussian", GetParameterCount(), params_.size(), Formatter() << GetNDims() << " means and sigmas" ); } }
int FitsFile::GetGroupParameterIndex(const std::string ¶meterName) { if(!HasGroups()) throw FitsIOException("HDU has no groups"); int parameterCount = GetParameterCount(); for(int i=1;i<=parameterCount;++i) { std::stringstream s; s << "PTYPE" << i; if(GetKeywordValue(s.str()) == parameterName) return i-1; } throw FitsIOException(std::string("Can not find parameter with name ") + parameterName); }
void FitsFile::ReadGroupParameters(long groupIndex, long double *parametersData) { int status = 0; long pSize = GetParameterCount(); double *parameters = new double[pSize]; fits_read_grppar_dbl(_fptr, groupIndex+1, 1, pSize, parameters, &status); CheckStatus(status); for(long i = 0; i<pSize;++i) parametersData[i] = parameters[i]; delete[] parameters; }
TExpressionPtr ExpressionParser::ParseNotParameterizedVariableExpression(StringPtrLen str) const { auto variable = m_variable_mgr.FindVariable(str); if (nullptr == variable) { return TExpressionPtr(); } if (variable->GetParameterCount() > 0) { Error("Parameters are missing during usage of variable '", variable->GetName(), "'."); } return variable->GetExpression()->Clone(); }
TExpressionPtr ExpressionParser::ParseParameterizedVariableExpression(StringPtrLen str) const { BracketsContent content; auto name = content.Parse(str); if (str.Len() == name.Len()) { return TExpressionPtr(); } name.Trim(); CheckQualifier(name, "Variable name"); auto variable = m_variable_mgr.FindVariable(name); if (nullptr == variable) { Error("Usage of undefined variable '", name, "'."); } TExpressionPtrVector actual_params; actual_params.reserve(5); StringPtrLen param; while (content.GetPart(param)) { auto param_expr = ParseExpression(param); actual_params.push_back(std::move(param_expr)); } if (actual_params.size() != variable->GetParameterCount()) { Error("Incorrect amount of parameters during usage of variable '", variable->GetName(), "'. Expected amount - ", variable->GetParameterCount(), ", actual amount - ", actual_params.size(), "."); } return variable->GetExpression()->CloneWithSubstitution(actual_params); }
TFunctionOutputPtr FunctionCaller::ParseAndCall(StringPtrLen str) { TrimFunctionCall(str); str.TrimRight(); CheckBracketBalance(str); BracketsContent content; str = content.Parse(str); str.Trim(); CheckQualifier(str, "Function name"); auto function = FunctionManager::GetInstance().FindFunction(str); if (nullptr == function) { Error("Call of undefined function '", str, "'."); } TStringPtrLenVector params; StringPtrLen param; while (content.GetPart(param)) { param.Trim(); params.push_back(param); } if (function->GetParameterCount() != -1 && params.size() != function->GetParameterCount()) { Error("Incorrect amount of parameters during call of function '", function->GetName(), "'. Expected amount - ", function->GetParameterCount(), ", actual amount - ", params.size(), "."); } return function->Call(m_variable_mgr, params); }
Variable::Variable(const StringPtrLen& name, const Variable& rhs) : VariableDeclaration(name, rhs), m_expression() { const auto param_count = GetParameterCount(); assert(param_count == rhs.GetParameterCount()); TExpressionPtrVector replace_params; replace_params.reserve(param_count); for (auto index = 0L; index < param_count; ++index) { replace_params.push_back( std::make_unique<ParamRefExpression>(*this, index)); } m_expression = rhs.GetExpression()->CloneWithSubstitution(replace_params); }
/// Invokes a procedure by sending a message to the Java stack and waiting for the corresponding response. /// /// @param[in] poConntector connector instance for communication with the Java stack, never NULL /// @param[in] ppArg array of arguments to send to the Java stack. Never NULL, values must never be NULL and there must be a value for each of the expected arguments (as returned by GetParameterCount) /// @param[out] ppResult receives a pointer to the result, left unchanged if there is a problem, NULL if there were no results. Can be NULL if the caller does not want the response /// @param[out] ppInfo receives a pointer to any additional information about the result, left unchanged if there is a problem. Callers should set to NULL before calling this method. Can be NULL if the caller does not require the additional information. /// @return TRUE if a result was returned, FALSE if there was a problem bool CProcedureEntry::Invoke (const CConnector *poConnector, const com_opengamma_language_Data * const *ppArg, com_opengamma_language_Data **ppResult, com_opengamma_rstats_msg_DataInfo **ppInfo) const { LOGDEBUG ("Invoking " << GetName ()); CProcedureInvoke invoke (poConnector); invoke.SetInvocationId (GetInvocationId ()); invoke.SetParameters (GetParameterCount (), ppArg); if (!invoke.Send ()) { LOGWARN (TEXT ("Could not send invocation request")); return false; } com_opengamma_rstats_msg_ProcedureResult *pResult = invoke.Recv (0x7FFFFFFF); if (!pResult) { LOGWARN (TEXT ("Did not receive invocation response")); return false; } if (pResult->fudgeParent.fudgeCountResult == 0) { if (ppResult) { *ppResult = NULL; } if (ppInfo) { *ppInfo = NULL; } return true; } else if (pResult->fudgeParent.fudgeCountResult == 1) { if (ppResult) { *ppResult = pResult->fudgeParent._result[0]; pResult->fudgeParent._result[0] = NULL; } if (ppInfo) { if (pResult->fudgeCountInfo == 1) { *ppInfo = pResult->_info[0]; pResult->_info[0] = NULL; } else { *ppInfo = NULL; } } return true; } else { LOGWARN (TEXT ("Invocation response contained ") << pResult->fudgeParent.fudgeCountResult << TEXT (" results")); return false; } }
static void IO(Reader& reader, IMethodInfo*& value) { ITypeDescriptor* type = 0; WString name; List<WString> parameters; reader << type << name << parameters; auto group = name == L"#ctor" ? type->GetConstructorGroup() : type->GetMethodGroupByName(name, false); CHECK_ERROR(group, L"Failed to load method."); value = 0; vint count = group->GetMethodCount(); for (vint i = 0; i < count; i++) { auto method = group->GetMethod(i); if (method->GetParameterCount() == parameters.Count()) { bool found = true; for (vint j = 0; j < parameters.Count(); j++) { if (method->GetParameter(j)->GetName() != parameters[j]) { found = false; break; } } if (found) { CHECK_ERROR(!value, L"Failed to load method."); value = method; } } } CHECK_ERROR(value, L"Failed to load method."); }
{ "background" , NULL , "1/cm" , 0.0 , -DBL_INF, +DBL_INF, PF_None}, { "M0_sld_sph" , NULL , "1/A^(2)" , 0.0e-6, -DBL_INF, +DBL_INF, PF_Orientation | PF_Magnetic}, { "M_theta_sph" , NULL , "deg" , 0.0 , -DBL_INF, +DBL_INF, PF_Orientation | PF_Magnetic}, { "M_phi_sph" , NULL , "deg" , 0.0 , -DBL_INF, +DBL_INF, PF_Orientation | PF_Magnetic}, { "M0_sld_solv" , NULL , "1/A^(2)" , 0.0e-6, -DBL_INF, +DBL_INF, PF_Orientation | PF_Magnetic}, { "M_theta_solv", NULL , "deg" , 0.0 , -DBL_INF, +DBL_INF, PF_Orientation | PF_Magnetic}, { "M_phi_solv" , NULL , "deg" , 0.0 , -DBL_INF, +DBL_INF, PF_Orientation | PF_Magnetic}, { "Up_frac_i" , NULL , "u/(u+d)" , 0.5 , -DBL_INF, +DBL_INF, PF_Orientation | PF_Magnetic}, { "Up_frac_f" , NULL , "u/(u+d)" , 0.5 , -DBL_INF, +DBL_INF, PF_Orientation | PF_Magnetic}, { "Up_theta" , NULL , "deg" , 0.0 , -DBL_INF, +DBL_INF, PF_Orientation | PF_Magnetic}, }; ModelInfo model_info( "SphereModel", "P(q)=(scale/V)*[3V(sldSph-sldSolv)*(sin(qR)-qRcos(qR))/(qR)^3]^(2)+bkg", GetParameterCount(param_infos), param_infos); // helper bool update_model(void* ptr, void** p) { std::cout << "update model " << ptr << " " << p << std::endl; if ((ptr == NULL) || (p == NULL)) return false; SphereModel* model = (SphereModel*)ptr; Parameter* model_params = &(model->scale); // update model ParameterInfo* param_info = param_infos; std::cout << "npar " << model_info.ParameterCount << std::endl;