Path: blob/main/contrib/llvm-project/libcxx/include/__random/lognormal_distribution.h
35233 views
//===----------------------------------------------------------------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#ifndef _LIBCPP___RANDOM_LOGNORMAL_DISTRIBUTION_H9#define _LIBCPP___RANDOM_LOGNORMAL_DISTRIBUTION_H1011#include <__config>12#include <__random/is_valid.h>13#include <__random/normal_distribution.h>14#include <cmath>15#include <iosfwd>16#include <limits>1718#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)19# pragma GCC system_header20#endif2122_LIBCPP_PUSH_MACROS23#include <__undef_macros>2425_LIBCPP_BEGIN_NAMESPACE_STD2627template <class _RealType = double>28class _LIBCPP_TEMPLATE_VIS lognormal_distribution {29static_assert(__libcpp_random_is_valid_realtype<_RealType>::value,30"RealType must be a supported floating-point type");3132public:33// types34typedef _RealType result_type;3536class _LIBCPP_TEMPLATE_VIS param_type {37result_type __m_;38result_type __s_;3940public:41typedef lognormal_distribution distribution_type;4243_LIBCPP_HIDE_FROM_ABI explicit param_type(result_type __m = 0, result_type __s = 1) : __m_(__m), __s_(__s) {}4445_LIBCPP_HIDE_FROM_ABI result_type m() const { return __m_; }46_LIBCPP_HIDE_FROM_ABI result_type s() const { return __s_; }4748friend _LIBCPP_HIDE_FROM_ABI bool operator==(const param_type& __x, const param_type& __y) {49return __x.__m_ == __y.__m_ && __x.__s_ == __y.__s_;50}51friend _LIBCPP_HIDE_FROM_ABI bool operator!=(const param_type& __x, const param_type& __y) { return !(__x == __y); }52};5354private:55normal_distribution<result_type> __nd_;5657public:58// constructor and reset functions59#ifndef _LIBCPP_CXX03_LANG60_LIBCPP_HIDE_FROM_ABI lognormal_distribution() : lognormal_distribution(0) {}61_LIBCPP_HIDE_FROM_ABI explicit lognormal_distribution(result_type __m, result_type __s = 1) : __nd_(__m, __s) {}62#else63_LIBCPP_HIDE_FROM_ABI explicit lognormal_distribution(result_type __m = 0, result_type __s = 1) : __nd_(__m, __s) {}64#endif65_LIBCPP_HIDE_FROM_ABI explicit lognormal_distribution(const param_type& __p) : __nd_(__p.m(), __p.s()) {}66_LIBCPP_HIDE_FROM_ABI void reset() { __nd_.reset(); }6768// generating functions69template <class _URNG>70_LIBCPP_HIDE_FROM_ABI result_type operator()(_URNG& __g) {71return std::exp(__nd_(__g));72}7374template <class _URNG>75_LIBCPP_HIDE_FROM_ABI result_type operator()(_URNG& __g, const param_type& __p) {76typename normal_distribution<result_type>::param_type __pn(__p.m(), __p.s());77return std::exp(__nd_(__g, __pn));78}7980// property functions81_LIBCPP_HIDE_FROM_ABI result_type m() const { return __nd_.mean(); }82_LIBCPP_HIDE_FROM_ABI result_type s() const { return __nd_.stddev(); }8384_LIBCPP_HIDE_FROM_ABI param_type param() const { return param_type(__nd_.mean(), __nd_.stddev()); }85_LIBCPP_HIDE_FROM_ABI void param(const param_type& __p) {86typename normal_distribution<result_type>::param_type __pn(__p.m(), __p.s());87__nd_.param(__pn);88}8990_LIBCPP_HIDE_FROM_ABI result_type min() const { return 0; }91_LIBCPP_HIDE_FROM_ABI result_type max() const { return numeric_limits<result_type>::infinity(); }9293friend _LIBCPP_HIDE_FROM_ABI bool operator==(const lognormal_distribution& __x, const lognormal_distribution& __y) {94return __x.__nd_ == __y.__nd_;95}96friend _LIBCPP_HIDE_FROM_ABI bool operator!=(const lognormal_distribution& __x, const lognormal_distribution& __y) {97return !(__x == __y);98}99100template <class _CharT, class _Traits, class _RT>101friend basic_ostream<_CharT, _Traits>&102operator<<(basic_ostream<_CharT, _Traits>& __os, const lognormal_distribution<_RT>& __x);103104template <class _CharT, class _Traits, class _RT>105friend basic_istream<_CharT, _Traits>&106operator>>(basic_istream<_CharT, _Traits>& __is, lognormal_distribution<_RT>& __x);107};108109template <class _CharT, class _Traits, class _RT>110inline _LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>&111operator<<(basic_ostream<_CharT, _Traits>& __os, const lognormal_distribution<_RT>& __x) {112return __os << __x.__nd_;113}114115template <class _CharT, class _Traits, class _RT>116inline _LIBCPP_HIDE_FROM_ABI basic_istream<_CharT, _Traits>&117operator>>(basic_istream<_CharT, _Traits>& __is, lognormal_distribution<_RT>& __x) {118return __is >> __x.__nd_;119}120121_LIBCPP_END_NAMESPACE_STD122123_LIBCPP_POP_MACROS124125#endif // _LIBCPP___RANDOM_LOGNORMAL_DISTRIBUTION_H126127128