TEST( MultidimTest, coreArrayByArray) { MultidimArray<double> m1(2,2); MultidimArray<double> m2(2,2); MultidimArray<double> mOut(2,2); MultidimArray<double> mref(2,2); A2D_ELEM(m1,0,0) = 1.; A2D_ELEM(m1,1,0) = 2.; A2D_ELEM(m1,0,1) = 3.; A2D_ELEM(m1,1,1) = 4.; A2D_ELEM(m2,0,0) = 11.; A2D_ELEM(m2,1,0) = 22.; A2D_ELEM(m2,0,1) = 33.; A2D_ELEM(m2,1,1) = 44.; coreArrayByArray(m1, m2, mOut, '+'); A2D_ELEM(mref,0,0) = 12.; A2D_ELEM(mref,1,0) = 24.; A2D_ELEM(mref,0,1) = 36.; A2D_ELEM(mref,1,1) = 48.; EXPECT_EQ(mOut,mref); }
TValue * LJ_FASTCALL lj_meta_equal_cd(lua_State *L, BCIns ins) { ASMFunction cont = (bc_op(ins) & 1) ? lj_cont_condf : lj_cont_condt; int op = (int)bc_op(ins) & ~1; TValue tv; cTValue *mo, *o2, *o1 = &L->base[bc_a(ins)]; cTValue *o1mm = o1; if (op == BC_ISEQV) { o2 = &L->base[bc_d(ins)]; if (!tviscdata(o1mm)) o1mm = o2; } else if (op == BC_ISEQS) { setstrV(L, &tv, gco2str(proto_kgc(curr_proto(L), ~(ptrdiff_t)bc_d(ins)))); o2 = &tv; } else if (op == BC_ISEQN) { o2 = &mref(curr_proto(L)->k, cTValue)[bc_d(ins)]; } else { lua_assert(op == BC_ISEQP); setpriV(&tv, ~bc_d(ins)); o2 = &tv; } mo = lj_meta_lookup(L, o1mm, MM_eq); if (LJ_LIKELY(!tvisnil(mo))) return mmcall(L, cont, mo, o1, o2); else return (TValue *)(intptr_t)(bc_op(ins) & 1); }
TEST(Auto, ConstAndMutableReference) { auto foo = new_syntax::Foo{}; auto& cref = foo.cref(); // cref is a const reference auto& mref = foo.mref(); // mref is a mutable reference static_assert(std::is_const_v<std::remove_reference_t<decltype(cref)>>, ""); static_assert(!std::is_const_v<std::remove_reference_t<decltype(mref)>>, ""); }
/* Restore raw data from the trace exit state. */ static void snap_restoredata(GCtrace *T, ExitState *ex, SnapNo snapno, BloomFilter rfilt, IRRef ref, void *dst, CTSize sz) { IRIns *ir = &T->ir[ref]; RegSP rs = ir->prev; int32_t *src; uint64_t tmp; if (irref_isk(ref)) { if (ir->o == IR_KNUM || ir->o == IR_KINT64) { src = mref(ir->ptr, int32_t); } else if (sz == 8) { tmp = (uint64_t)(uint32_t)ir->i; src = (int32_t *)&tmp; } else { src = &ir->i; } } else { if (LJ_UNLIKELY(bloomtest(rfilt, ref))) rs = snap_renameref(T, snapno, ref, rs); if (ra_hasspill(regsp_spill(rs))) { src = &ex->spill[regsp_spill(rs)]; if (sz == 8 && !irt_is64(ir->t)) { tmp = (uint64_t)(uint32_t)*src; src = (int32_t *)&tmp; } } else { Reg r = regsp_reg(rs); if (ra_noreg(r)) { /* Note: this assumes CNEWI is never used for SOFTFP split numbers. */ lua_assert(sz == 8 && ir->o == IR_CONV && ir->op2 == IRCONV_NUM_INT); snap_restoredata(T, ex, snapno, rfilt, ir->op1, dst, 4); *(lua_Number *)dst = (lua_Number)*(int32_t *)dst; return; } src = (int32_t *)&ex->gpr[r-RID_MIN_GPR]; #if !LJ_SOFTFP if (r >= RID_MAX_GPR) { src = (int32_t *)&ex->fpr[r-RID_MIN_FPR]; #if LJ_TARGET_PPC if (sz == 4) { /* PPC FPRs are always doubles. */ *(float *)dst = (float)*(double *)src; return; } #else if (LJ_BE && sz == 4) src++; #endif } #endif } } lua_assert(sz == 1 || sz == 2 || sz == 4 || sz == 8); if (sz == 4) *(int32_t *)dst = *src; else if (sz == 8) *(int64_t *)dst = *(int64_t *)src; else if (sz == 1) *(int8_t *)dst = (int8_t)*src; else *(int16_t *)dst = (int16_t)*src; }
TEST( MultidimTest, selfCoreArrayByArrayMask) { MultidimArray<double> m1(2,2); MultidimArray<double> m2(2,2); MultidimArray<double> mOut(2,2); MultidimArray<double> mref(2,2); MultidimArray<double> mask(2,2); A2D_ELEM(m1,0,0) = 1.; A2D_ELEM(m1,1,0) = 2.; A2D_ELEM(m1,0,1) = 3.; A2D_ELEM(m1,1,1) = 4.; A2D_ELEM(m2,0,0) = 11.; A2D_ELEM(m2,1,0) = 22.; A2D_ELEM(m2,0,1) = 33.; A2D_ELEM(m2,1,1) = 44.; A2D_ELEM(mask,0,0) = 0.; A2D_ELEM(mask,1,0) = 1.; A2D_ELEM(mask,0,1) = 1.; A2D_ELEM(mask,1,1) = 1.; A2D_ELEM(mOut,0,0) = 0.; A2D_ELEM(mOut,1,0) = 0.; A2D_ELEM(mOut,0,1) = 0.; A2D_ELEM(mOut,1,1) = 1.; selfCoreArrayByArrayMask(m1, m2, mOut, '+', &mask); A2D_ELEM(mref,0,0) = 1.; A2D_ELEM(mref,1,0) = 22.; A2D_ELEM(mref,0,1) = 33.; A2D_ELEM(mref,1,1) = 45.; EXPECT_EQ(mOut,mref); }
/* Unpatch the bytecode modified by a root trace. */ static void trace_unpatch(jit_State *J, GCtrace *T) { BCOp op = bc_op(T->startins); BCIns *pc = mref(T->startpc, BCIns); UNUSED(J); if (op == BC_JMP) return; /* No need to unpatch branches in parent traces (yet). */ switch (bc_op(*pc)) { case BC_JFORL: lua_assert(traceref(J, bc_d(*pc)) == T); *pc = T->startins; pc += bc_j(T->startins); lua_assert(bc_op(*pc) == BC_JFORI); setbc_op(pc, BC_FORI); break; case BC_JITERL: case BC_JLOOP: lua_assert(op == BC_ITERL || op == BC_LOOP || bc_isret(op)); *pc = T->startins; break; case BC_JMP: lua_assert(op == BC_ITERL); pc += bc_j(*pc)+2; if (bc_op(*pc) == BC_JITERL) { lua_assert(traceref(J, bc_d(*pc)) == T); *pc = T->startins; } break; case BC_JFUNCF: lua_assert(op == BC_FUNCF); *pc = T->startins; break; default: /* Already unpatched. */ break; } }
TCWin::TCWin( ChartCanvas *parent, int x, int y, void *pvIDX ) { // As a display optimization.... // if current color scheme is other than DAY, // Then create the dialog ..WITHOUT.. borders and title bar. // This way, any window decorations set by external themes, etc // will not detract from night-vision m_created = false; xSpot = 0; ySpot = 0; m_pTCRolloverWin = NULL; long wstyle = wxCLIP_CHILDREN | wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER ; if( ( global_color_scheme != GLOBAL_COLOR_SCHEME_DAY ) && ( global_color_scheme != GLOBAL_COLOR_SCHEME_RGB ) ) wstyle |= ( wxNO_BORDER ); #ifdef __WXOSX__ wstyle |= wxSTAY_ON_TOP; #endif pParent = parent; m_x = x; m_y = y; RecalculateSize(); wxDialog::Create( parent, wxID_ANY, wxString( _T ( "" ) ), m_position , m_tc_size, wstyle ); m_created = true; wxFont *qFont = GetOCPNScaledFont(_("Dialog")); SetFont( *qFont ); pIDX = (IDX_entry *) pvIDX; gpIDXn++; // Set up plot type if( strchr( "Tt", pIDX->IDX_type ) ) { m_plot_type = TIDE_PLOT; SetTitle( wxString( _( "Tide" ) ) ); gpIDX = pIDX; // remember pointer for routeplan } else { m_plot_type = CURRENT_PLOT; SetTitle( wxString( _( "Current" ) ) ); } int sx, sy; GetClientSize( &sx, &sy ); // Figure out this computer timezone minute offset wxDateTime this_now = gTimeSource; bool cur_time = !gTimeSource.IsValid(); if (cur_time) { this_now = wxDateTime::Now(); } wxDateTime this_gmt = this_now.ToGMT(); #if wxCHECK_VERSION(2, 6, 2) wxTimeSpan diff = this_now.Subtract( this_gmt ); #else wxTimeSpan diff = this_gmt.Subtract ( this_now ); #endif int diff_mins = diff.GetMinutes(); // Correct a bug in wx3.0.2 // If the system TZ happens to be GMT, with DST active (e.g.summer in London), // then wxDateTime returns incorrect results for toGMT() method #if wxCHECK_VERSION(3, 0, 2) if( diff_mins == 0 && this_now.IsDST() ) diff_mins +=60; #endif int station_offset = ptcmgr->GetStationTimeOffset( pIDX ); m_corr_mins = station_offset - diff_mins; if( this_now.IsDST() ) m_corr_mins += 60; // Establish the inital drawing day as today m_graphday = this_now; wxDateTime graphday_00 = this_now; graphday_00.ResetTime(); time_t t_graphday_00 = graphday_00.GetTicks(); // Correct a Bug in wxWidgets time support if( !graphday_00.IsDST() && m_graphday.IsDST() ) t_graphday_00 -= 3600; if( graphday_00.IsDST() && !m_graphday.IsDST() ) t_graphday_00 += 3600; m_t_graphday_00_at_station = t_graphday_00 - ( m_corr_mins * 60 ); btc_valid = false; wxString* TClist = NULL; m_tList = new wxListBox( this, -1, wxPoint( sx * 65 / 100, 11 ), wxSize( ( sx * 32 / 100 ), ( sy * 20 / 100 ) ), 0, TClist, wxLB_SINGLE | wxLB_NEEDED_SB | wxLB_HSCROLL ); // Measure the size of a generic button, with label wxButton *test_button = new wxButton( this, wxID_OK, _( "OK" ), wxPoint( -1, -1), wxDefaultSize ); test_button->GetSize( &m_tsx, &m_tsy ); delete test_button; // In the interest of readability, if the width of the dialog is too narrow, // simply skip showing the "Hi/Lo" list control. if( (m_tsy * 15) > sx ) m_tList->Hide(); OK_button = new wxButton( this, wxID_OK, _( "OK" ), wxPoint( sx - (2 * m_tsy + 10), sy - (m_tsy + 10) ), wxDefaultSize ); PR_button = new wxButton( this, ID_TCWIN_PR, _( "Prev" ), wxPoint( 10, sy - (m_tsy + 10) ), wxSize( -1, -1 ) ); wxSize texc_size = wxSize( ( sx * 60 / 100 ), ( sy *29 / 100 ) ); if( !m_tList->IsShown()){ texc_size = wxSize( ( sx * 90 / 100 ), ( sy *29 / 100 ) ); } m_ptextctrl = new wxTextCtrl( this, -1, _T(""), wxPoint( sx * 3 / 100, 6 ), texc_size , wxTE_MULTILINE | wxTE_READONLY | wxTE_DONTWRAP); int bsx, bsy, bpx, bpy; PR_button->GetSize( &bsx, &bsy ); PR_button->GetPosition( &bpx, &bpy ); NX_button = new wxButton( this, ID_TCWIN_NX, _( "Next" ), wxPoint( bpx + bsx + 5, sy - (m_tsy + 10) ), wxSize( -1, -1 ) ); m_TCWinPopupTimer.SetOwner( this, TCWININF_TIMER ); wxScreenDC dc; int text_height; dc.GetTextExtent(_T("W"), NULL, &text_height); m_button_height = m_tsy; //text_height + 20; // Build graphics tools wxFont *dlg_font = FontMgr::Get().GetFont( _("Dialog") ); int dlg_font_size = dlg_font->GetPointSize(); pSFont = FontMgr::Get().FindOrCreateFont( dlg_font_size-2, wxFONTFAMILY_SWISS, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL, FALSE, wxString( _T ( "Arial" ) ) ); pSMFont = FontMgr::Get().FindOrCreateFont( dlg_font_size-1, wxFONTFAMILY_SWISS, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL, FALSE, wxString( _T ( "Arial" ) ) ); pMFont = FontMgr::Get().FindOrCreateFont( dlg_font_size, wxFONTFAMILY_SWISS, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_BOLD, FALSE, wxString( _T ( "Arial" ) ) ); pLFont = FontMgr::Get().FindOrCreateFont( dlg_font_size+1, wxFONTFAMILY_SWISS, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_BOLD, FALSE, wxString( _T ( "Arial" ) ) ); pblack_1 = wxThePenList->FindOrCreatePen( GetGlobalColor( _T ( "UINFD" ) ), wxMax(1,(int)(m_tcwin_scaler+0.5)), wxPENSTYLE_SOLID ); pblack_2 = wxThePenList->FindOrCreatePen( GetGlobalColor( _T ( "UINFD" ) ), wxMax(2,(int)(2*m_tcwin_scaler+0.5)), wxPENSTYLE_SOLID ); pblack_3 = wxThePenList->FindOrCreatePen( GetGlobalColor( _T ( "UWHIT" ) ), wxMax(1,(int)(m_tcwin_scaler+0.5)), wxPENSTYLE_SOLID ); pred_2 = wxThePenList->FindOrCreatePen( GetGlobalColor( _T ( "UINFR" ) ), wxMax(4,(int)(4*m_tcwin_scaler+0.5)), wxPENSTYLE_SOLID ); pltgray = wxTheBrushList->FindOrCreateBrush( GetGlobalColor( _T ( "UIBCK" ) ), wxBRUSHSTYLE_SOLID ); pltgray2 = wxTheBrushList->FindOrCreateBrush( GetGlobalColor( _T ( "DILG1" ) ), wxBRUSHSTYLE_SOLID ); DimeControl( this ); // Fill in some static text control information // Tidi station information m_ptextctrl->Clear(); wxString locn( pIDX->IDX_station_name, wxConvUTF8 ); wxString locna, locnb; if( locn.Contains( wxString( _T ( "," ) ) ) ) { locna = locn.BeforeFirst( ',' ); locnb = locn.AfterFirst( ',' ); } else { locna = locn; locnb.Empty(); } // write the first line wxTextAttr style; style.SetFont( *pLFont ); m_ptextctrl->SetDefaultStyle( style ); m_ptextctrl->AppendText( locna ); m_ptextctrl->AppendText(_T("\n")); style.SetFont( *pSMFont ); m_ptextctrl->SetDefaultStyle( style ); if( !locnb.IsEmpty() ) m_ptextctrl->AppendText( locnb ); m_ptextctrl->AppendText(_T("\n")); //Reference to the master station if(( 't' == pIDX->IDX_type ) || ( 'c' == pIDX->IDX_type )) { wxString mref( pIDX->IDX_reference_name, wxConvUTF8 ); mref.Prepend(_T(" ")); m_ptextctrl->AppendText( _( "Reference Station :" ) ); m_ptextctrl->AppendText(_T("\n")); m_ptextctrl->AppendText( mref ); m_ptextctrl->AppendText(_T("\n")); } else { m_ptextctrl->AppendText(_T("\n")); } // Show the data source wxString dsource( pIDX->source_ident, wxConvUTF8 ); dsource.Prepend(_T(" ")); m_ptextctrl->AppendText( _( "Data Source :" ) ); m_ptextctrl->AppendText(_T("\n")); m_ptextctrl->AppendText( dsource ); m_ptextctrl->ShowPosition( 0 ); }
void NewtonEulerDSTest::testNewtonEulerDSQuaternionMatrix() { std::cout << "--> Test: quaternion 2" <<std::endl; std::cout <<" ---------- test with q03 (rotation of pi/4 about the y-axis)" << std::endl; SP::SiconosVector q03(new SiconosVector(7)); q03->zero(); double angle=M_PI_4; SP::SiconosVector axis(new SiconosVector(3)); axis->zero(); (*axis)(1)= 1.0; std::cout << "q03 angle : " <<angle<<std::endl; std::cout << "q03 axis : " << std::endl; axis->display(); ::setAxisAngle(q03,axis,angle); std::cout << "q03 : " << std::endl; q03->display(); SP::SiconosVector v(new SiconosVector(3)); SP::SiconosVector vref(new SiconosVector(3)); (*v)(0)=1.0; (*v)(1)=1.0; (*v)(2)=1.0; (*vref)(0)=sqrt(2.0); (*vref)(1)=1.0; (*vref)(2)=0.0; std::cout << "v : "<<std::endl; v->display(); std::cout << "vref : "<<std::endl; vref->display(); std::cout << (*v-*vref).normInf()<<std::endl; //Old version SiconosVector aux(3); SP::SimpleMatrix matrix(new SimpleMatrix(3,3)); ::computeRotationMatrix(q03, matrix); // compute R prod( *matrix, *v, aux); // multiply by R *v=aux; std::cout << "v : "<<std::endl; v->display(); CPPUNIT_ASSERT_EQUAL_MESSAGE("testNewtonEulerDSQuaternion : ", ((*v-*vref).normInf() <= std::numeric_limits<double>::epsilon()*10.0), true); // double transpose version (*v)(0)=1.0; (*v)(1)=1.0; (*v)(2)=1.0; ::computeRotationMatrixTransposed(q03, matrix); // Compute R^T for the moment prod(*v, *matrix, aux); // multiply by R^T^T *v=aux; std::cout << "v : "<<std::endl; v->display(); CPPUNIT_ASSERT_EQUAL_MESSAGE("testNewtonEulerDSQuaternion : ", ((*v-*vref).normInf() <= std::numeric_limits<double>::epsilon()*10.0), true); //New version (*v)(0)=1.0; (*v)(1)=1.0; (*v)(2)=1.0; ::rotateAbsToBody(q03, v); std::cout << "v : "<<std::endl; v->display(); CPPUNIT_ASSERT_EQUAL_MESSAGE("testNewtonEulerDSQuaternion : ", ((*v-*vref).normInf() <= std::numeric_limits<double>::epsilon()*10.0), true); SP::SimpleMatrix m(new SimpleMatrix(3,3)); m->zero(); (*m)(2,0)=1.0; (*m)(0,1)=1.0; (*m)(0,2)=1.0; (*m)(1,2)=1.0; (*m)(2,2)=1.0; SP::SimpleMatrix mref(new SimpleMatrix(3,3)); mref->zero(); (*mref)(0,0) = sqrt(2.0)/2.0; (*mref)(2,0) = sqrt(2.0)/2.0; (*mref)(0,1) = sqrt(2.0)/2.0; (*mref)(2,1) = -sqrt(2.0)/2.0; (*mref)(0,2) = sqrt(2.0); (*mref)(1,2) = 1.0; ::rotateAbsToBody(q03, m); std::cout << "m : "<<std::endl; m->display(); std::cout << "mref : "<<std::endl; mref->display(); CPPUNIT_ASSERT_EQUAL_MESSAGE("testNewtonEulerDSQuaternion : ", ((*m-*mref).normInf() <= std::numeric_limits<double>::epsilon()*10.0), true); }