static GstFlowReturn gst_rg_limiter_transform_ip (GstBaseTransform * base, GstBuffer * buf) { GstRgLimiter *filter = GST_RG_LIMITER (base); gfloat *input; guint count; guint i; if (!filter->enabled) return GST_FLOW_OK; if (GST_BUFFER_FLAG_IS_SET (buf, GST_BUFFER_FLAG_GAP)) return GST_FLOW_OK; input = (gfloat *) GST_BUFFER_DATA (buf); count = GST_BUFFER_SIZE (buf) / sizeof (gfloat); for (i = count; i--;) { if (*input > THRES) *input = tanhf ((*input - THRES) / COMPL) * COMPL + THRES; else if (*input < -THRES) *input = tanhf ((*input + THRES) / COMPL) * COMPL - THRES; input++; } return GST_FLOW_OK; }
void CButterXOver::settype(float t) { const float amt = 4.f; const float tmp = 0.5f*amt; t = 0.5f*tanhf(amt*t - tmp)/tanhf(tmp) + 0.5f; //some empirical ch00ning float a = (float)cos(t*3.141592*0.5)*0.7f; float b = (float)sin(t*3.141592*0.5)*0.7f; m2 = (a - b)*0.5f; m1 = (a + b)*0.5f; }
void Image::quantize(uint n) { if (!n) { return; } std::set<float> bins; float binWidth = 100.0f / n; // Create bin values. for (size_t i = 0; i <= n; i++) { bins.insert(binWidth * i); } for (pixel3f *p = _pixels; p < _pixels + _width * _height; p++) { std::set<float>::iterator i = bins.upper_bound(p->L); float nearest; // Determine the nearest bin value. if (i == bins.end()) { nearest = *(i--); } else { float ceilling = *i--; float floor = *i; nearest = p->L - floor < ceilling - p->L ? floor : ceilling; } // Smooth quantization. p->L = nearest + (binWidth / 2.0f) * tanhf(p->L - nearest); } }
float Filter::process(float in) { //TODO: add a flag to calculate coefficients here instead of calculating them at every param change common::add_dc(in); if (m_mode == k_filter_off) return in; //"clamping" with tanh /*#if defined(WIN32) in = tanhf(in); #else in = dnload_tanhf(in); #endif*/ //svf process implementation --m_calc_interval; if (m_calc_coefficients) if (m_calc_interval < 0) { calculateCoefficients(); m_calc_interval = STATE_CALC_INTERVAL; } float yL, yB, yH; getOutputs(in, yL, yB, yH); #if defined(APPROXIMATE_TANH) return m_output_level * common::rational_tanh((m_c_low * yL + m_c_band * yB + m_c_high * yH)*(1.0f + (3.0f*m_drive))); #else #if defined(WIN32) return m_output_level * tanhf((m_c_low * yL + m_c_band * yB + m_c_high * yH)*(1.0f+(3.0f*m_drive))); #else return m_output_level * dnload_tanhf((m_c_low * yL + m_c_band * yB + m_c_high * yH)*(1.0f + (3.0f*m_drive))); #endif #endif }
int main(void) { #pragma STDC FENV_ACCESS ON float y; float d; int e, i, err = 0; struct f_f *p; for (i = 0; i < sizeof t/sizeof *t; i++) { p = t + i; if (p->r < 0) continue; fesetround(p->r); feclearexcept(FE_ALL_EXCEPT); y = tanhf(p->x); e = fetestexcept(INEXACT|INVALID|DIVBYZERO|UNDERFLOW|OVERFLOW); if (!checkexcept(e, p->e, p->r)) { printf("%s:%d: bad fp exception: %s tanhf(%a)=%a, want %s", p->file, p->line, rstr(p->r), p->x, p->y, estr(p->e)); printf(" got %s\n", estr(e)); err++; } d = ulperrf(y, p->y, p->dy); if (!checkulp(d, p->r)) { printf("%s:%d: %s tanhf(%a) want %a got %a ulperr %.3f = %a + %a\n", p->file, p->line, rstr(p->r), p->x, p->y, y, d, d-p->dy, p->dy); err++; } } return !!err; }
void generate_ref(float *out, size_t n) { size_t i; for (i = 0; i < n; i++) out[i] = tanhf(ai[i]); }
unsigned propagaEntrada(void) { int cont1,cont2; Y2temp=0; Y2=0; for (cont1=0;cont1<p;cont1++) { Y1temp[cont1]=0.0; for (cont2=0;cont2<n;cont2++) Y1temp[cont1]+=(W1[cont1][cont2]*entrada[cont2]); Y1[cont1]=tanhf(Y1temp[cont1]+b1[cont1]); Y2temp+=(W2[cont1]*Y1[cont1]); } Y2=tanhf(Y2temp+b2); return(OK); }
void test_tanh() { static_assert((std::is_same<decltype(tanh((double)0)), double>::value), ""); static_assert((std::is_same<decltype(tanhf(0)), float>::value), ""); static_assert((std::is_same<decltype(tanhl(0)), long double>::value), ""); assert(tanh(0) == 0); }
/** * Called when running on the host, this performs some maths operation */ struct value_defn performMathsOp(unsigned short operation, struct value_defn value) { struct value_defn result; result.dtype=SCALAR; if (operation== RANDOM_MATHS_OP) { result.type=INT_TYPE; int r=rand(); cpy(result.data, &r, sizeof(int)); } else { float fvalue, r; if (value.type==REAL_TYPE) { fvalue=*((float*) value.data); } else if (value.type==INT_TYPE) { fvalue=(float) *((int*) value.data); } result.type=REAL_TYPE; if (operation==SQRT_MATHS_OP) r=sqrtf(fvalue); if (operation==SIN_MATHS_OP) r=sinf(fvalue); if (operation==COS_MATHS_OP) r=cosf(fvalue); if (operation==TAN_MATHS_OP) r=tanf(fvalue); if (operation==ASIN_MATHS_OP) r=asinf(fvalue); if (operation==ACOS_MATHS_OP) r=acosf(fvalue); if (operation==ATAN_MATHS_OP) r=atanf(fvalue); if (operation==SINH_MATHS_OP) r=sinhf(fvalue); if (operation==COSH_MATHS_OP) r=coshf(fvalue); if (operation==TANH_MATHS_OP) r=tanhf(fvalue); if (operation==FLOOR_MATHS_OP) r=floorf(fvalue); if (operation==CEIL_MATHS_OP) r=ceilf(fvalue); if (operation==LOG_MATHS_OP) r=logf(fvalue); if (operation==LOG10_MATHS_OP) r=log10f(fvalue); cpy(result.data, &r, sizeof(float)); } return result; }
/** * Performs some maths operation */ static void performMathsOp(struct core_ctrl * core) { if (core->core_command-1000 == RANDOM_MATHS_OP) { core->data[0]=INT_TYPE; int r=rand(); memcpy(&core->data[1], &r, sizeof(int)); } else { float fvalue=0.0, r=0.0; if (core->data[0]==1) { fvalue=*((float*) &core->data[1]); } else if (core->data[0]==0) { fvalue=(float) *((int*) &core->data[1]); } if (core->core_command-1000 == SQRT_MATHS_OP) r=sqrtf(fvalue); if (core->core_command-1000 == SIN_MATHS_OP) r=sinf(fvalue); if (core->core_command-1000 == COS_MATHS_OP) r=cosf(fvalue); if (core->core_command-1000 == TAN_MATHS_OP) r=tanf(fvalue); if (core->core_command-1000 == ASIN_MATHS_OP) r=asinf(fvalue); if (core->core_command-1000 == ACOS_MATHS_OP) r=acosf(fvalue); if (core->core_command-1000 == ATAN_MATHS_OP) r=atanf(fvalue); if (core->core_command-1000 == SINH_MATHS_OP) r=sinhf(fvalue); if (core->core_command-1000 == COSH_MATHS_OP) r=coshf(fvalue); if (core->core_command-1000 == TANH_MATHS_OP) r=tanhf(fvalue); if (core->core_command-1000 == FLOOR_MATHS_OP) r=floorf(fvalue); if (core->core_command-1000 == CEIL_MATHS_OP) r=ceilf(fvalue); if (core->core_command-1000 == LOG_MATHS_OP) r=logf(fvalue); if (core->core_command-1000 == LOG10_MATHS_OP) r=log10f(fvalue); core->data[0]=REAL_TYPE; memcpy(&core->data[1], &r, sizeof(float)); } }
static TACommandVerdict tanhf_cmd(TAThread thread,TAInputStream stream) { float x, res; // Prepare x = readFloat(&stream); errno = 0; START_TARGET_OPERATION(thread); // Execute res = tanhf(x); END_TARGET_OPERATION(thread); // Response writeFloat(thread, res); writeInt(thread, errno); sendResponse(thread); return taDefaultVerdict; }
ATF_TC_BODY(tanhf_inf_pos, tc) { #ifndef __vax__ const float x = 1.0L / 0.0L; ATF_CHECK(tanhf(x) == 1.0); #endif }
static void *tanh_new(t_floatarg f) { t_tanh *x = (t_tanh *)pd_new(tanh_class); /* CHECKME large values */ x->x_value = tanhf(f); outlet_new((t_object *)x, &s_float); return (x); }
ATF_TC_BODY(tanhf_nan, tc) { #ifndef __vax__ const float x = 0.0L / 0.0L; ATF_CHECK(isnan(x) != 0); ATF_CHECK(isnan(tanhf(x)) != 0); #endif }
ATF_TC_BODY(tanhf_zero_pos, tc) { #ifndef __vax__ const float x = 0.0L; float y = tanhf(x); ATF_CHECK(x == y); ATF_CHECK(signbit(x) == 0); ATF_CHECK(signbit(y) == 0); #endif }
float complex ctanf (float complex a) { float rt, it; float complex n, d; rt = tanf (REALPART (a)); it = tanhf (IMAGPART (a)); COMPLEX_ASSIGN (n, rt, it); COMPLEX_ASSIGN (d, 1, - (rt * it)); return n / d; }
mat4 mat4::projection(float fov, float width, float height, float zNear, float zFar) { mat4 r; float aspect = (float)width / (float)height; float tanHalf = tanhf(fov / 2.0f); r.m[0 + 0 * 4] = 1.0f / (aspect * tanHalf); r.m[0 + 1 * 4] = 0; r.m[0 + 2 * 4] = 0; r.m[0 + 3 * 4] = 0; r.m[1 + 0 * 4] = 0; r.m[1 + 1 * 4] = 1.0f / tanHalf; r.m[1 + 2 * 4] = 0; r.m[1 + 3 * 4] = 0; r.m[2 + 0 * 4] = 0; r.m[2 + 1 * 4] = 0; r.m[2 + 2 * 4] = (-zNear - zFar) / (zNear - zFar); r.m[2 + 3 * 4] = 2 * zNear * zFar / (zNear - zFar); r.m[3 + 0 * 4] = 0; r.m[3 + 1 * 4] = 0; r.m[3 + 2 * 4] = 1; r.m[3 + 3 * 4] = 1; return r; }
void ampmodem_demodulate(ampmodem _q, float complex _y, float *_x) { #if DEBUG_AMPMODEM windowcf_push(_q->debug_x, _y); #endif if (_q->suppressed_carrier) { // single side-band suppressed carrier if (_q->type != LIQUID_AMPMODEM_DSB) { *_x = crealf(_y); return; } // coherent demodulation // mix signal down float complex y_hat; nco_crcf_mix_down(_q->oscillator, _y, &y_hat); // compute phase error float phase_error = tanhf( crealf(y_hat) * cimagf(y_hat) ); #if DEBUG_AMPMODEM // compute frequency error float nco_freq = nco_crcf_get_frequency(_q->oscillator); float freq_error = nco_freq/(2*M_PI) - _q->fc/(2*M_PI); // retain phase and frequency errors windowf_push(_q->debug_phase_error, phase_error); windowf_push(_q->debug_freq_error, freq_error); #endif // adjust nco, pll objects nco_crcf_pll_step(_q->oscillator, phase_error); // step NCO nco_crcf_step(_q->oscillator); // set output *_x = crealf(y_hat); } else { // non-coherent demodulation (peak detector) float t = cabsf(_y); // remove DC bias _q->ssb_q_hat = ( _q->ssb_alpha)*t + (1 - _q->ssb_alpha)*_q->ssb_q_hat; *_x = 2.0f*(t - _q->ssb_q_hat); } }
void mix() { // omp-ing this yields a 10% speed increase; not much, but it's something g_wav.resize(g_maxChannelLen); #pragma omp parallel for for(int i = 0; i < g_maxChannelLen; ++i) { float sum(0.f); for(size_t j = 0; j < JAKMUSE_NUMCHANNELS; ++j) { if(g_channels[j].size() <= i) continue; sum += g_channels[j][i]; } g_wav[i] = ((short)(tanhf(sum) * 0x7FFF)); } }
/* tanh(z) = (tanh(a) + itan(b)) / (1 - itanh(a)tan(b)) */ GFC_COMPLEX_4 ctanhf (GFC_COMPLEX_4 a) { GFC_REAL_4 rt; GFC_REAL_4 it; GFC_COMPLEX_4 n; GFC_COMPLEX_4 d; rt = tanhf (REALPART (a)); it = tanf (IMAGPART (a)); COMPLEX_ASSIGN (n, rt, it); COMPLEX_ASSIGN (d, 1, - (rt * it)); return n / d; }
float sandbox_lngammaf(float _z, float * _v) { float v0 = _v[0]; float v1 = _v[1]; // z = 10.^[-3:0.1:1]; // t0 = log(gamma(z)); // t1 = (1+z-0.5).*log(1+z) - (1+z) + 0.5*log(2*pi) - log(z) + 0.0405*(1-tanh(0.5*log(z))); // float g_hat = (0.5f+_z)*logf(1.0f+_z) - (1.0f+_z) + 0.5f*logf(2*M_PI) - logf(_z) + v0*(1.0f - tanhf(v1*logf(_z))); return g_hat; }
pixel3f *Image::createEdges(float stylization) { pixel3f *gaussianE = createGaussian(SIGMA); pixel3f *gaussianR = createGaussian(sqrtf(1.6) * SIGMA); for (int i = 0; i < _width * _height; i++) { // Difference of gaussians mapped to a smoothed step function. float dog = gaussianE[i].L - TAU * gaussianR[i].L; gaussianE[i].L = dog > 0.0f ? 100.0f : 100.0f * (1.0f + tanhf(stylization * dog)); } delete[] gaussianR; return gaussianE; }
inline float tanhf2(float x) { return tanhf(x); }
__device__ inline float occaCuda_fastTanh(const float x){ return tanhf(x); }
float i16tanhs(int16 x) { return (tanhf(x)); }
float compute_IRRate(int azm, int rng, int blocked_percent, Rate_Buf_t* rate_out, Moments_t* bin_moments, short beam_edge_top[MAX_AZM], float* RateZ_table) { float fshield = 0.0; int z_index = 0; short hc_type = 0; /* The AEL calls precip_rate "R(Combined)". */ float precip_rate = QPE_NODATA; float Rate_Z = QPE_NODATA; /* Copy hydro class data to local variable hc_type */ hc_type = bin_moments->HydroClass; /* If the hydrometeor class is Biota or No Echo (AEL 3.1.2.1), * this bin is valid, so mark it filled, and don't go to a higher * elevation. Return 0.0 = no precipitation, for this bin. * * Note: Check RhoHV after BI/NE, because the HCA has already considered * RhoHV in its fuzzy logic classification to determine the * hydrometeor type. The RhoHV check should only be applied to * a precip. generating hydrometeors (not GC/UK/BI/NE). * Ward 24 Mar 08. * * 20081211 Ward - Mark Fresch suggested changing No Echo (NE)" to * "No Data (ND)" to match the HCA AEL. Brian Klein pointed out that * ND means no data above the threshold, as there are always some echoes. * Mike Istok pointed out that AWIPS uses ND, and ND has meant No Data for * over 20 years. It was agreed to go with what AWIPS displays (ND) * -> hca.h NE may change to ND in the future. */ if((hc_type == BI) || (hc_type == NE)) { return(0.0); /* AEL 3.1.2.1 */ } /* The rest of the hydrometeors are precip. generating, * so for non-attenuated radials, check RhoHV next. * Attenuated radials don't do any check. * * The QPE AEL calls art_corr - "THRESHOLD(Minimum RhoHV for Precip)" * * Default art_corr: 0.80 */ if((bin_moments->attenuated == FALSE) && (bin_moments->CorrelCoef < rate_out->qpe_adapt.dpprep_adapt.art_corr)) { /* go to the next elevation */ return(QPE_NODATA); /* AEL 3.1.2.1 */ } /* If beam is partially blocked - AEL 3.2.2 A * * In John Krause's RadialRainfallRates.cpp, the PBB2 correction * for HR/RA/RH is done after the hydroclass switch statement. * This would cause HR/RA/RH to have a rate computed twice, so * we augment Z before looking at hydroclasses. * * A 'blocked_percent >= Min_blockage' check must be applied instead * of always augmenting Z because even at 0 % blockage the * fshield formula adds a correction: * * (0.5*tanh(0.0277*(50.0-0.0)))+ 0.5 = 0.94 * * z_unblocked = (1 / fshield) * z_blocked = 1.06 * z_blocked */ if(blocked_percent >= rate_out->qpe_adapt.dp_adapt.Min_blockage /* 5 */) { /* 20111031 Ward PBB1 method not to be used. * if(rate_out->qpe_adapt.dp_adapt.Use_pbb1 == TRUE) * { * return(compute_Precip_PBB_method1(azm, rng, blocked_percent, * rate_out, bin_moments, stats)); * } */ if(blocked_percent >= rate_out->qpe_adapt.dp_adapt.Kdp_max_beam_blk /* 70 */) { /* Go to the next elevation. This should already have been checked * in the calling routine, Add_bin_to_RR_Polar_Grid(). */ return(QPE_NODATA); } else if(bin_moments->Z == QPE_NODATA) /* we can't correct Z */ { return(QPE_NODATA); } else /* apply the fshield correction to dBZ */ { fshield = (0.5*tanhf(0.0277*(50.0-blocked_percent)))+ 0.5; /* Fshield is a number between 0.59 (100% blocked) and 0.94 (0% blocked). * * z_blocked = z_unblocked * fshield * * dbz_blocked = 10 * log10(z_unblocked * fshield) * * dbz_blocked = 10 * (log10(z_unblocked) + log10(fshield)) * * dbz_blocked = 10 * log10(z_unblocked) + 10 * log10(fshield) * * dbz_blocked = dbz_unblocked + 10 * log10(fshield) * * dbz_blocked - 10 * log10(fshield) = dbz_unblocked * * Augment Z in place, we don't need a Zprime. */ bin_moments->Z -= (10.0 * log10f(fshield)); } } /* end if blocked_percent >= Min_blockage */ /* Most hydroclasses need a base R(Z) */ if(bin_moments->Z == QPE_NODATA) { Rate_Z = QPE_NODATA; } else if(bin_moments->Z <= rate_out->qpe_adapt.dp_adapt.Refl_min) { /* Use the minimum in the rate table */ Rate_Z = RateZ_table[0]; } else if(bin_moments->Z >= rate_out->qpe_adapt.dp_adapt.Refl_max) { /* Use the maximum in the rate table * * index 0 1 2 ... 64 ... 168 169 170 * * refl -32 -31.5 -31 ... 0 ... 52 52.5 53 * * Note: Refl_max and Refl_min are floats with an accuracy * of 0.1 so we typecast to get an int index. */ z_index = (int) 2 * (rate_out->qpe_adapt.dp_adapt.Refl_max - rate_out->qpe_adapt.dp_adapt.Refl_min); Rate_Z = RateZ_table[z_index]; } else /* Refl_min <= bin_moments->Z <= Refl_max */ { if(blocked_percent >= rate_out->qpe_adapt.dp_adapt.Min_blockage /* 5 */) { /* dBZ has been augmented by fshield, so is not on a * 0.5 dBZ boundary, so we must compute R(Z) */ Rate_Z = compute_RateZ(bin_moments->Z, rate_out); } else /* dBZ is on a 0.5 boundary, so we can use a rate table lookup */ { /* Note: Refl_min is a float with an accuracy * of 0.1, so we typecast to get an int index. */ z_index = (int) 2 * (bin_moments->Z - rate_out->qpe_adapt.dp_adapt.Refl_min); Rate_Z = RateZ_table[z_index]; } } /* Calculate a hydroclass based rate. */ switch(hc_type) { /* BD and RA always use R(Z, Zdr) */ case BD: case RA: precip_rate = compute_RateZ_Zdr(bin_moments->Z, bin_moments->Zdr, rate_out); break; /* GR, IC, and WS are multiples of Rate_Z. * * 20080117 Ryzhkov says the IC rate should be 2.8 * R(z) for * all instances of Crystals, independent of the melting layer */ case GR: precip_rate = Rate_Z * rate_out->qpe_adapt.dp_adapt.Gr_mult; /* 0.8 */ break; case IC: precip_rate = Rate_Z * rate_out->qpe_adapt.dp_adapt.Ic_mult; /* 2.8 */ break; case WS: precip_rate = Rate_Z * rate_out->qpe_adapt.dp_adapt.Ws_mult; /* 0.6 */ break; /* The HR formula changes if you're blocked or not. */ case HR: if((blocked_percent >= rate_out->qpe_adapt.dp_adapt.Kdp_min_beam_blk) || /* 20 */ (bin_moments->Z > rate_out->qpe_adapt.dp_adapt.Hr_HighZThresh)) /* 45 */ { precip_rate = compute_RateKdp(bin_moments, Rate_Z, rate_out); } else /* use R(Z, Zdr) */ { precip_rate = compute_RateZ_Zdr(bin_moments->Z, bin_moments->Zdr, rate_out); } break; /* DS and RH require a melting layer, except for RH blocked */ case DS: /* DS is more likely to be above the beam_edge_top. * * The AEL has the same multiplicative coefficient for DS * and IC, but we broke them out separately here. */ if(beam_edge_top[azm] == QPE_NODATA) { precip_rate = QPE_NODATA; } else if(rng > beam_edge_top[azm]) { precip_rate = Rate_Z * rate_out->qpe_adapt.dp_adapt.Ds_mult; /* 2.8 */ } else /* rng <= beam_edge_top[azm] */ { precip_rate = Rate_Z * rate_out->qpe_adapt.dp_adapt.Ds_BelowMLTop_mult; } break; case RH: /* RH is more likely to be below the beam_edge_top */ if(blocked_percent >= rate_out->qpe_adapt.dp_adapt.Min_blockage /* 5 */) { precip_rate = compute_RateKdp(bin_moments, Rate_Z, rate_out); } else if(beam_edge_top[azm] == QPE_NODATA) { precip_rate = QPE_NODATA; } else if(rng <= beam_edge_top[azm]) { precip_rate = compute_RateKdp(bin_moments, Rate_Z, rate_out); } else /* rng > beam_edge_top[azm] */ { precip_rate = Rate_Z * rate_out->qpe_adapt.dp_adapt.Rh_mult; /* 0.8 */ } break; default: /* unknown hydroclass - this should never happen */ return(QPE_NODATA); break; } /* end switch on hydroclass */ /* Fail-safe for an attenuated radial. AEL 3.1.2.4 */ if(bin_moments->attenuated == TRUE) { if(precip_rate == QPE_NODATA) /* 1. Try R(Z, Zdr) */ { precip_rate = compute_RateZ_Zdr(bin_moments->Z, bin_moments->Zdr, rate_out); if(precip_rate == QPE_NODATA) /* 2. Try R(Z) */ { precip_rate = compute_RateZ(bin_moments->Z, rate_out); if(precip_rate == QPE_NODATA) /* 3. Use R(Kdp) */ { precip_rate = compute_RateKdp(bin_moments, Rate_Z, rate_out); } } } } /* end attenuated fail safe */ return(precip_rate); } /* end compute_IRRate() ================================== */
static void tanh_float(t_tanh *x, t_float f) { /* CHECKME large values */ outlet_float(((t_object *)x)->ob_outlet, x->x_value = tanhf(f)); }
// // tanh activation function // float ann_af_tanh(float _mu, float _x) { return tanhf(_mu*_x); }
LogPmQ::LogPmQ(float llr2Value) : m_isPos( !signbit(llr2Value) ), m_val( logf(tanhf(fabsf(llr2Value))) ) {}
double tanh(double x) { return (double)tanhf((float)x); }