idx
int64
0
165k
question
stringlengths
73
4.15k
target
stringlengths
5
918
len_question
int64
21
890
len_target
int64
3
255
148,900
public static String resolveSvnMigratedRevision ( final Revision revision , final String branch ) { if ( revision == null ) { return null ; } final Pattern pattern = Pattern . compile ( "^git-svn-id: .*" + branch + "@([0-9]+) " , Pattern . MULTILINE ) ; final Matcher matcher = pattern . matcher ( revision . getMessage ( ) ) ; if ( matcher . find ( ) ) { return matcher . group ( 1 ) ; } else { return revision . getRevision ( ) ; } }
Helper method to retrieve a canonical revision for git commits migrated from SVN . Migrated commits are detected by the presence of git - svn - id in the commit message .
124
35
148,901
public T mapRow ( ResultSet rs ) throws SQLException { Map < String , Object > map = new HashMap < String , Object > ( ) ; ResultSetMetaData metadata = rs . getMetaData ( ) ; for ( int i = 1 ; i <= metadata . getColumnCount ( ) ; ++ i ) { String label = metadata . getColumnLabel ( i ) ; final Object value ; // calling getObject on a BLOB/CLOB produces weird results switch ( metadata . getColumnType ( i ) ) { case Types . BLOB : value = rs . getBytes ( i ) ; break ; case Types . CLOB : value = rs . getString ( i ) ; break ; default : value = rs . getObject ( i ) ; } // don't use table name extractor because we don't want aliased table name boolean overwrite = this . tableName != null && this . tableName . equals ( metadata . getTableName ( i ) ) ; String tableName = TABLE_NAME_EXTRACTOR . getTableName ( metadata , i ) ; if ( tableName != null && ! tableName . isEmpty ( ) ) { String qualifiedName = tableName + "." + metadata . getColumnName ( i ) ; add ( map , qualifiedName , value , overwrite ) ; } add ( map , label , value , overwrite ) ; } return objectMapper . convertValue ( map , type ) ; }
Map a single ResultSet row to a T instance .
301
11
148,902
public int getOpacity ( ) { int opacity = Math . round ( ( mPosToOpacFactor * ( mBarPointerPosition - mBarPointerHaloRadius ) ) ) ; if ( opacity < 5 ) { return 0x00 ; } else if ( opacity > 250 ) { return 0xFF ; } else { return opacity ; } }
Get the currently selected opacity .
76
6
148,903
private int calculateColor ( float angle ) { float unit = ( float ) ( angle / ( 2 * Math . PI ) ) ; if ( unit < 0 ) { unit += 1 ; } if ( unit <= 0 ) { mColor = COLORS [ 0 ] ; return COLORS [ 0 ] ; } if ( unit >= 1 ) { mColor = COLORS [ COLORS . length - 1 ] ; return COLORS [ COLORS . length - 1 ] ; } float p = unit * ( COLORS . length - 1 ) ; int i = ( int ) p ; p -= i ; int c0 = COLORS [ i ] ; int c1 = COLORS [ i + 1 ] ; int a = ave ( Color . alpha ( c0 ) , Color . alpha ( c1 ) , p ) ; int r = ave ( Color . red ( c0 ) , Color . red ( c1 ) , p ) ; int g = ave ( Color . green ( c0 ) , Color . green ( c1 ) , p ) ; int b = ave ( Color . blue ( c0 ) , Color . blue ( c1 ) , p ) ; mColor = Color . argb ( a , r , g , b ) ; return Color . argb ( a , r , g , b ) ; }
Calculate the color using the supplied angle .
278
10
148,904
private float colorToAngle ( int color ) { float [ ] colors = new float [ 3 ] ; Color . colorToHSV ( color , colors ) ; return ( float ) Math . toRadians ( - colors [ 0 ] ) ; }
Convert a color to an angle .
52
8
148,905
private float [ ] calculatePointerPosition ( float angle ) { float x = ( float ) ( mColorWheelRadius * Math . cos ( angle ) ) ; float y = ( float ) ( mColorWheelRadius * Math . sin ( angle ) ) ; return new float [ ] { x , y } ; }
Calculate the pointer s coordinates on the color wheel using the supplied angle .
67
16
148,906
public void addOpacityBar ( OpacityBar bar ) { mOpacityBar = bar ; // Give an instance of the color picker to the Opacity bar. mOpacityBar . setColorPicker ( this ) ; mOpacityBar . setColor ( mColor ) ; }
Add a Opacity bar to the color wheel .
61
10
148,907
public void setNewCenterColor ( int color ) { mCenterNewColor = color ; mCenterNewPaint . setColor ( color ) ; if ( mCenterOldColor == 0 ) { mCenterOldColor = color ; mCenterOldPaint . setColor ( color ) ; } if ( onColorChangedListener != null && color != oldChangedListenerColor ) { onColorChangedListener . onColorChanged ( color ) ; oldChangedListenerColor = color ; } invalidate ( ) ; }
Change the color of the center which indicates the new color .
103
12
148,908
public void setValue ( float value ) { mBarPointerPosition = Math . round ( ( mSVToPosFactor * ( 1 - value ) ) + mBarPointerHaloRadius + ( mBarLength / 2 ) ) ; calculateColor ( mBarPointerPosition ) ; mBarPointerPaint . setColor ( mColor ) ; // Check whether the Saturation/Value bar is added to the ColorPicker // wheel if ( mPicker != null ) { mPicker . setNewCenterColor ( mColor ) ; mPicker . changeOpacityBarColor ( mColor ) ; } invalidate ( ) ; }
Set the pointer on the bar . With the Value value .
137
12
148,909
public static int getNavigationBarHeight ( Context context ) { Resources resources = context . getResources ( ) ; int id = resources . getIdentifier ( context . getResources ( ) . getConfiguration ( ) . orientation == Configuration . ORIENTATION_PORTRAIT ? "navigation_bar_height" : "navigation_bar_height_landscape" , "dimen" , "android" ) ; if ( id > 0 ) { return resources . getDimensionPixelSize ( id ) ; } return 0 ; }
helper to calculate the navigationBar height
111
8
148,910
public static int getActionBarHeight ( Context context ) { int actionBarHeight = UIUtils . getThemeAttributeDimensionSize ( context , R . attr . actionBarSize ) ; if ( actionBarHeight == 0 ) { actionBarHeight = context . getResources ( ) . getDimensionPixelSize ( R . dimen . abc_action_bar_default_height_material ) ; } return actionBarHeight ; }
helper to calculate the actionBar height
92
8
148,911
public static int getStatusBarHeight ( Context context , boolean force ) { int result = 0 ; int resourceId = context . getResources ( ) . getIdentifier ( "status_bar_height" , "dimen" , "android" ) ; if ( resourceId > 0 ) { result = context . getResources ( ) . getDimensionPixelSize ( resourceId ) ; } int dimenResult = context . getResources ( ) . getDimensionPixelSize ( R . dimen . tool_bar_top_padding ) ; //if our dimension is 0 return 0 because on those devices we don't need the height if ( dimenResult == 0 && ! force ) { return 0 ; } else { //if our dimens is > 0 && the result == 0 use the dimenResult else the result; return result == 0 ? dimenResult : result ; } }
helper to calculate the statusBar height
184
8
148,912
public static void setTranslucentStatusFlag ( Activity activity , boolean on ) { if ( Build . VERSION . SDK_INT >= 19 ) { setFlag ( activity , WindowManager . LayoutParams . FLAG_TRANSLUCENT_STATUS , on ) ; } }
helper method to set the TranslucentStatusFlag
59
10
148,913
public static void setTranslucentNavigationFlag ( Activity activity , boolean on ) { if ( Build . VERSION . SDK_INT >= 19 ) { setFlag ( activity , WindowManager . LayoutParams . FLAG_TRANSLUCENT_NAVIGATION , on ) ; } }
helper method to set the TranslucentNavigationFlag
62
11
148,914
public static void setFlag ( Activity activity , final int bits , boolean on ) { Window win = activity . getWindow ( ) ; WindowManager . LayoutParams winParams = win . getAttributes ( ) ; if ( on ) { winParams . flags |= bits ; } else { winParams . flags &= ~ bits ; } win . setAttributes ( winParams ) ; }
helper method to activate or deactivate a specific flag
83
11
148,915
public static int getScreenWidth ( Context context ) { DisplayMetrics metrics = context . getResources ( ) . getDisplayMetrics ( ) ; return metrics . widthPixels ; }
Returns the screen width in pixels
38
6
148,916
public static int getScreenHeight ( Context context ) { DisplayMetrics metrics = context . getResources ( ) . getDisplayMetrics ( ) ; return metrics . heightPixels ; }
Returns the screen height in pixels
38
6
148,917
public MaterializeBuilder withActivity ( Activity activity ) { this . mRootView = ( ViewGroup ) activity . findViewById ( android . R . id . content ) ; this . mActivity = activity ; return this ; }
Pass the activity you use the drawer in ; ) This is required if you want to set any values by resource
47
22
148,918
public MaterializeBuilder withContainer ( ViewGroup container , ViewGroup . LayoutParams layoutParams ) { this . mContainer = container ; this . mContainerLayoutParams = layoutParams ; return this ; }
set the layout which will host the ScrimInsetsFrameLayout and its layoutParams
45
18
148,919
public void setFullscreen ( boolean fullscreen ) { if ( mBuilder . mScrimInsetsLayout != null ) { mBuilder . mScrimInsetsLayout . setTintStatusBar ( ! fullscreen ) ; mBuilder . mScrimInsetsLayout . setTintNavigationBar ( ! fullscreen ) ; } }
set the insetsFrameLayout to display the content in fullscreen under the statusBar and navigationBar
71
20
148,920
public void setStatusBarColor ( int statusBarColor ) { if ( mBuilder . mScrimInsetsLayout != null ) { mBuilder . mScrimInsetsLayout . setInsetForeground ( statusBarColor ) ; mBuilder . mScrimInsetsLayout . getView ( ) . invalidate ( ) ; } }
Set the color for the statusBar
71
7
148,921
public void keyboardSupportEnabled ( Activity activity , boolean enable ) { if ( getContent ( ) != null && getContent ( ) . getChildCount ( ) > 0 ) { if ( mKeyboardUtil == null ) { mKeyboardUtil = new KeyboardUtil ( activity , getContent ( ) . getChildAt ( 0 ) ) ; mKeyboardUtil . disable ( ) ; } if ( enable ) { mKeyboardUtil . enable ( ) ; } else { mKeyboardUtil . disable ( ) ; } } }
a helper method to enable the keyboardUtil for a specific activity or disable it . note this will cause some frame drops because of the listener .
115
29
148,922
public void applyTo ( Context ctx , GradientDrawable drawable ) { if ( mColorInt != 0 ) { drawable . setColor ( mColorInt ) ; } else if ( mColorRes != - 1 ) { drawable . setColor ( ContextCompat . getColor ( ctx , mColorRes ) ) ; } }
set the textColor of the ColorHolder to an drawable
72
13
148,923
public void applyToBackground ( View view ) { if ( mColorInt != 0 ) { view . setBackgroundColor ( mColorInt ) ; } else if ( mColorRes != - 1 ) { view . setBackgroundResource ( mColorRes ) ; } }
set the textColor of the ColorHolder to a view
55
12
148,924
public void applyToOr ( TextView textView , ColorStateList colorDefault ) { if ( mColorInt != 0 ) { textView . setTextColor ( mColorInt ) ; } else if ( mColorRes != - 1 ) { textView . setTextColor ( ContextCompat . getColor ( textView . getContext ( ) , mColorRes ) ) ; } else if ( colorDefault != null ) { textView . setTextColor ( colorDefault ) ; } }
a small helper to set the text color to a textView null save
98
14
148,925
public int color ( Context ctx ) { if ( mColorInt == 0 && mColorRes != - 1 ) { mColorInt = ContextCompat . getColor ( ctx , mColorRes ) ; } return mColorInt ; }
a small helper to get the color from the colorHolder
50
12
148,926
public static int color ( ColorHolder colorHolder , Context ctx ) { if ( colorHolder == null ) { return 0 ; } else { return colorHolder . color ( ctx ) ; } }
a small static helper class to get the color from the colorHolder
45
14
148,927
public static void applyToOr ( ColorHolder colorHolder , TextView textView , ColorStateList colorDefault ) { if ( colorHolder != null && textView != null ) { colorHolder . applyToOr ( textView , colorDefault ) ; } else if ( textView != null ) { textView . setTextColor ( colorDefault ) ; } }
a small static helper to set the text color to a textView null save
77
15
148,928
public static void applyToOrTransparent ( ColorHolder colorHolder , Context ctx , GradientDrawable gradientDrawable ) { if ( colorHolder != null && gradientDrawable != null ) { colorHolder . applyTo ( ctx , gradientDrawable ) ; } else if ( gradientDrawable != null ) { gradientDrawable . setColor ( Color . TRANSPARENT ) ; } }
a small static helper to set the color to a GradientDrawable null save
87
16
148,929
public static boolean applyTo ( ImageHolder imageHolder , ImageView imageView , String tag ) { if ( imageHolder != null && imageView != null ) { return imageHolder . applyTo ( imageView , tag ) ; } return false ; }
a small static helper to set the image from the imageHolder nullSave to the imageView
55
19
148,930
public static Drawable decideIcon ( ImageHolder imageHolder , Context ctx , int iconColor , boolean tint ) { if ( imageHolder == null ) { return null ; } else { return imageHolder . decideIcon ( ctx , iconColor , tint ) ; } }
a small static helper which catches nulls for us
60
10
148,931
public static void applyDecidedIconOrSetGone ( ImageHolder imageHolder , ImageView imageView , int iconColor , boolean tint ) { if ( imageHolder != null && imageView != null ) { Drawable drawable = ImageHolder . decideIcon ( imageHolder , imageView . getContext ( ) , iconColor , tint ) ; if ( drawable != null ) { imageView . setImageDrawable ( drawable ) ; imageView . setVisibility ( View . VISIBLE ) ; } else if ( imageHolder . getBitmap ( ) != null ) { imageView . setImageBitmap ( imageHolder . getBitmap ( ) ) ; imageView . setVisibility ( View . VISIBLE ) ; } else { imageView . setVisibility ( View . GONE ) ; } } else if ( imageView != null ) { imageView . setVisibility ( View . GONE ) ; } }
decides which icon to apply or hide this view
200
10
148,932
public static void applyMultiIconTo ( Drawable icon , int iconColor , Drawable selectedIcon , int selectedIconColor , boolean tinted , ImageView imageView ) { //if we have an icon then we want to set it if ( icon != null ) { //if we got a different color for the selectedIcon we need a StateList if ( selectedIcon != null ) { if ( tinted ) { imageView . setImageDrawable ( new PressedEffectStateListDrawable ( icon , selectedIcon , iconColor , selectedIconColor ) ) ; } else { imageView . setImageDrawable ( UIUtils . getIconStateList ( icon , selectedIcon ) ) ; } } else if ( tinted ) { imageView . setImageDrawable ( new PressedEffectStateListDrawable ( icon , iconColor , selectedIconColor ) ) ; } else { imageView . setImageDrawable ( icon ) ; } //make sure we display the icon imageView . setVisibility ( View . VISIBLE ) ; } else { //hide the icon imageView . setVisibility ( View . GONE ) ; } }
a small static helper to set a multi state drawable on a view
237
14
148,933
public void setHighlightStrength ( float _highlightStrength ) { mHighlightStrength = _highlightStrength ; for ( PieModel model : mPieData ) { highlightSlice ( model ) ; } invalidateGlobal ( ) ; }
Sets the highlight strength for the InnerPaddingOutline .
50
13
148,934
public void addPieSlice ( PieModel _Slice ) { highlightSlice ( _Slice ) ; mPieData . add ( _Slice ) ; mTotalValue += _Slice . getValue ( ) ; onDataChanged ( ) ; }
Adds a new Pie Slice to the PieChart . After inserting and calculation of the highlighting color a complete recalculation is initiated .
54
26
148,935
@ Override protected void onDraw ( Canvas canvas ) { super . onDraw ( canvas ) ; // If the API level is less than 11, we can't rely on the view animation system to // do the scrolling animation. Need to tick it here and call postInvalidate() until the scrolling is done. if ( Build . VERSION . SDK_INT < 11 ) { tickScrollAnimation ( ) ; if ( ! mScroller . isFinished ( ) ) { mGraph . postInvalidate ( ) ; } } }
Implement this to do your drawing .
110
8
148,936
@ Override protected void onDataChanged ( ) { super . onDataChanged ( ) ; int currentAngle = 0 ; int index = 0 ; int size = mPieData . size ( ) ; for ( PieModel model : mPieData ) { int endAngle = ( int ) ( currentAngle + model . getValue ( ) * 360.f / mTotalValue ) ; if ( index == size - 1 ) { endAngle = 360 ; } model . setStartAngle ( currentAngle ) ; model . setEndAngle ( endAngle ) ; currentAngle = model . getEndAngle ( ) ; index ++ ; } calcCurrentItem ( ) ; onScrollFinished ( ) ; }
Should be called after new data is inserted . Will be automatically called when the view dimensions has changed .
153
20
148,937
private void highlightSlice ( PieModel _Slice ) { int color = _Slice . getColor ( ) ; _Slice . setHighlightedColor ( Color . argb ( 0xff , Math . min ( ( int ) ( mHighlightStrength * ( float ) Color . red ( color ) ) , 0xff ) , Math . min ( ( int ) ( mHighlightStrength * ( float ) Color . green ( color ) ) , 0xff ) , Math . min ( ( int ) ( mHighlightStrength * ( float ) Color . blue ( color ) ) , 0xff ) ) ) ; }
Calculate the highlight color . Saturate at 0xff to make sure that high values don t result in aliasing .
130
26
148,938
private void calcCurrentItem ( ) { int pointerAngle ; // calculate the correct pointer angle, depending on clockwise drawing or not if ( mOpenClockwise ) { pointerAngle = ( mIndicatorAngle + 360 - mPieRotation ) % 360 ; } else { pointerAngle = ( mIndicatorAngle + 180 + mPieRotation ) % 360 ; } for ( int i = 0 ; i < mPieData . size ( ) ; ++ i ) { PieModel model = mPieData . get ( i ) ; if ( model . getStartAngle ( ) <= pointerAngle && pointerAngle <= model . getEndAngle ( ) ) { if ( i != mCurrentItem ) { setCurrentItem ( i , false ) ; } break ; } } }
Calculate which pie slice is under the pointer and set the current item field accordingly .
168
18
148,939
private void centerOnCurrentItem ( ) { if ( ! mPieData . isEmpty ( ) ) { PieModel current = mPieData . get ( getCurrentItem ( ) ) ; int targetAngle ; if ( mOpenClockwise ) { targetAngle = ( mIndicatorAngle - current . getStartAngle ( ) ) - ( ( current . getEndAngle ( ) - current . getStartAngle ( ) ) / 2 ) ; if ( targetAngle < 0 && mPieRotation > 0 ) targetAngle += 360 ; } else { targetAngle = current . getStartAngle ( ) + ( current . getEndAngle ( ) - current . getStartAngle ( ) ) / 2 ; targetAngle += mIndicatorAngle ; if ( targetAngle > 270 && mPieRotation < 90 ) targetAngle -= 360 ; } mAutoCenterAnimator . setIntValues ( targetAngle ) ; mAutoCenterAnimator . setDuration ( AUTOCENTER_ANIM_DURATION ) . start ( ) ; } }
Kicks off an animation that will result in the pointer being centered in the pie slice of the currently selected item .
231
23
148,940
protected void onLegendDataChanged ( ) { int legendCount = mLegendList . size ( ) ; float margin = ( mGraphWidth / legendCount ) ; float currentOffset = 0 ; for ( LegendModel model : mLegendList ) { model . setLegendBounds ( new RectF ( currentOffset , 0 , currentOffset + margin , mLegendHeight ) ) ; currentOffset += margin ; } Utils . calculateLegendInformation ( mLegendList , 0 , mGraphWidth , mLegendPaint ) ; invalidateGlobal ( ) ; }
Calculates the legend bounds for a custom list of legends .
113
13
148,941
private void calculateValueTextHeight ( ) { Rect valueRect = new Rect ( ) ; Rect legendRect = new Rect ( ) ; String str = Utils . getFloatString ( mFocusedPoint . getValue ( ) , mShowDecimal ) + ( ! mIndicatorTextUnit . isEmpty ( ) ? " " + mIndicatorTextUnit : "" ) ; // calculate the boundaries for both texts mIndicatorPaint . getTextBounds ( str , 0 , str . length ( ) , valueRect ) ; mLegendPaint . getTextBounds ( mFocusedPoint . getLegendLabel ( ) , 0 , mFocusedPoint . getLegendLabel ( ) . length ( ) , legendRect ) ; // calculate string positions in overlay mValueTextHeight = valueRect . height ( ) ; mValueLabelY = ( int ) ( mValueTextHeight + mIndicatorTopPadding ) ; mLegendLabelY = ( int ) ( mValueTextHeight + mIndicatorTopPadding + legendRect . height ( ) + Utils . dpToPx ( 7.f ) ) ; int chosenWidth = valueRect . width ( ) > legendRect . width ( ) ? valueRect . width ( ) : legendRect . width ( ) ; // check if text reaches over screen if ( mFocusedPoint . getCoordinates ( ) . getX ( ) + chosenWidth + mIndicatorLeftPadding > - Utils . getTranslationX ( mDrawMatrixValues ) + mGraphWidth ) { mValueLabelX = ( int ) ( mFocusedPoint . getCoordinates ( ) . getX ( ) - ( valueRect . width ( ) + mIndicatorLeftPadding ) ) ; mLegendLabelX = ( int ) ( mFocusedPoint . getCoordinates ( ) . getX ( ) - ( legendRect . width ( ) + mIndicatorLeftPadding ) ) ; } else { mValueLabelX = mLegendLabelX = ( int ) ( mFocusedPoint . getCoordinates ( ) . getX ( ) + mIndicatorLeftPadding ) ; } }
Calculates the text height for the indicator value and sets its x - coordinate .
452
17
148,942
protected void calculateBarPositions ( int _DataSize ) { int dataSize = mScrollEnabled ? mVisibleBars : _DataSize ; float barWidth = mBarWidth ; float margin = mBarMargin ; if ( ! mFixedBarWidth ) { // calculate the bar width if the bars should be dynamically displayed barWidth = ( mAvailableScreenSize / _DataSize ) - margin ; } else { if ( _DataSize < mVisibleBars ) { dataSize = _DataSize ; } // calculate margin between bars if the bars have a fixed width float cumulatedBarWidths = barWidth * dataSize ; float remainingScreenSize = mAvailableScreenSize - cumulatedBarWidths ; margin = remainingScreenSize / dataSize ; } boolean isVertical = this instanceof VerticalBarChart ; int calculatedSize = ( int ) ( ( barWidth * _DataSize ) + ( margin * _DataSize ) ) ; int contentWidth = isVertical ? mGraphWidth : calculatedSize ; int contentHeight = isVertical ? calculatedSize : mGraphHeight ; mContentRect = new Rect ( 0 , 0 , contentWidth , contentHeight ) ; mCurrentViewport = new RectF ( 0 , 0 , mGraphWidth , mGraphHeight ) ; calculateBounds ( barWidth , margin ) ; mLegend . invalidate ( ) ; mGraph . invalidate ( ) ; }
Calculates the bar width and bar margin based on the _DataSize and settings and starts the boundary calculation in child classes .
294
26
148,943
@ Override protected void onGraphDraw ( Canvas _Canvas ) { super . onGraphDraw ( _Canvas ) ; _Canvas . translate ( - mCurrentViewport . left , - mCurrentViewport . top ) ; drawBars ( _Canvas ) ; }
region Override Methods
60
4
148,944
public static void calculatePointDiff ( Point2D _P1 , Point2D _P2 , Point2D _Result , float _Multiplier ) { float diffX = _P2 . getX ( ) - _P1 . getX ( ) ; float diffY = _P2 . getY ( ) - _P1 . getY ( ) ; _Result . setX ( _P1 . getX ( ) + ( diffX * _Multiplier ) ) ; _Result . setY ( _P1 . getY ( ) + ( diffY * _Multiplier ) ) ; }
Calculates the middle point between two points and multiplies its coordinates with the given smoothness _Mulitplier .
131
26
148,945
public static void calculateLegendInformation ( List < ? extends BaseModel > _Models , float _StartX , float _EndX , Paint _Paint ) { float textMargin = Utils . dpToPx ( 10.f ) ; float lastX = _StartX ; // calculate the legend label positions and check if there is enough space to display the label, // if not the label will not be shown for ( BaseModel model : _Models ) { if ( ! model . isIgnore ( ) ) { Rect textBounds = new Rect ( ) ; RectF legendBounds = model . getLegendBounds ( ) ; _Paint . getTextBounds ( model . getLegendLabel ( ) , 0 , model . getLegendLabel ( ) . length ( ) , textBounds ) ; model . setTextBounds ( textBounds ) ; float centerX = legendBounds . centerX ( ) ; float centeredTextPos = centerX - ( textBounds . width ( ) / 2 ) ; float textStartPos = centeredTextPos - textMargin ; // check if the text is too big to fit on the screen if ( centeredTextPos + textBounds . width ( ) > _EndX - textMargin ) { model . setShowLabel ( false ) ; } else { // check if the current legend label overrides the label before // if the label overrides the label before, the current label will not be shown. // If not the label will be shown and the label position is calculated if ( textStartPos < lastX ) { if ( lastX + textMargin < legendBounds . left ) { model . setLegendLabelPosition ( ( int ) ( lastX + textMargin ) ) ; model . setShowLabel ( true ) ; lastX = lastX + textMargin + textBounds . width ( ) ; } else { model . setShowLabel ( false ) ; } } else { model . setShowLabel ( true ) ; model . setLegendLabelPosition ( ( int ) centeredTextPos ) ; lastX = centerX + ( textBounds . width ( ) / 2 ) ; } } } } }
Calculates the legend positions and which legend title should be displayed or not .
458
16
148,946
public static float calculateMaxTextHeight ( Paint _Paint , String _Text ) { Rect height = new Rect ( ) ; String text = _Text == null ? "MgHITasger" : _Text ; _Paint . getTextBounds ( text , 0 , text . length ( ) , height ) ; return height . height ( ) ; }
Calculates the maximum text height which is possible based on the used Paint and its settings .
76
19
148,947
public static boolean intersectsPointWithRectF ( RectF _Rect , float _X , float _Y ) { return _X > _Rect . left && _X < _Rect . right && _Y > _Rect . top && _Y < _Rect . bottom ; }
Checks if a point is in the given rectangle .
58
11
148,948
private static boolean hasSelfPermissions ( Context context , String ... permissions ) { for ( String permission : permissions ) { if ( checkSelfPermission ( context , permission ) == PackageManager . PERMISSION_GRANTED ) { return true ; } } return false ; }
Returns true if the context has access to any given permissions .
57
12
148,949
static boolean shouldShowRequestPermissionRationale ( Activity activity , String ... permissions ) { for ( String permission : permissions ) { if ( ActivityCompat . shouldShowRequestPermissionRationale ( activity , permission ) ) { return true ; } } return false ; }
Checks given permissions are needed to show rationale .
56
10
148,950
public AirMapViewBuilder builder ( AirMapViewTypes mapType ) { switch ( mapType ) { case NATIVE : if ( isNativeMapSupported ) { return new NativeAirMapViewBuilder ( ) ; } break ; case WEB : return getWebMapViewBuilder ( ) ; } throw new UnsupportedOperationException ( "Requested map type is not supported" ) ; }
Returns the AirMapView implementation as requested by the mapType argument . Use this method if you need to request a specific AirMapView implementation that is not necessarily the preferred type . For example you can use it to explicit request a web - based map implementation .
79
52
148,951
private AirMapViewBuilder getWebMapViewBuilder ( ) { if ( context != null ) { try { ApplicationInfo ai = context . getPackageManager ( ) . getApplicationInfo ( context . getPackageName ( ) , PackageManager . GET_META_DATA ) ; Bundle bundle = ai . metaData ; String accessToken = bundle . getString ( "com.mapbox.ACCESS_TOKEN" ) ; String mapId = bundle . getString ( "com.mapbox.MAP_ID" ) ; if ( ! TextUtils . isEmpty ( accessToken ) && ! TextUtils . isEmpty ( mapId ) ) { return new MapboxWebMapViewBuilder ( accessToken , mapId ) ; } } catch ( PackageManager . NameNotFoundException e ) { Log . e ( TAG , "Failed to load Mapbox access token and map id" , e ) ; } } return new WebAirMapViewBuilder ( ) ; }
Decides what the Map Web provider should be used and generates a builder for it .
204
17
148,952
public void initialize ( FragmentManager fragmentManager ) { AirMapInterface mapInterface = ( AirMapInterface ) fragmentManager . findFragmentById ( R . id . map_frame ) ; if ( mapInterface != null ) { initialize ( fragmentManager , mapInterface ) ; } else { initialize ( fragmentManager , new DefaultAirMapViewBuilder ( getContext ( ) ) . builder ( ) . build ( ) ) ; } }
Used for initialization of the underlying map provider .
88
9
148,953
private Set < Annotation > getFieldAnnotations ( final Class < ? > clazz ) { try { return new LinkedHashSet < Annotation > ( asList ( clazz . getDeclaredField ( propertyName ) . getAnnotations ( ) ) ) ; } catch ( final NoSuchFieldException e ) { if ( clazz . getSuperclass ( ) != null ) { return getFieldAnnotations ( clazz . getSuperclass ( ) ) ; } else { logger . debug ( "Cannot find propertyName: {}, declaring class: {}" , propertyName , clazz ) ; return new LinkedHashSet < Annotation > ( 0 ) ; } } }
Private function to allow looking for the field recursively up the superclasses .
143
16
148,954
public < T > DiffNode compare ( final T working , final T base ) { dispatcher . resetInstanceMemory ( ) ; try { return dispatcher . dispatch ( DiffNode . ROOT , Instances . of ( working , base ) , RootAccessor . getInstance ( ) ) ; } finally { dispatcher . clearInstanceMemory ( ) ; } }
Recursively inspects the given objects and returns a node representing their differences . Both objects have be have the same type .
71
25
148,955
public DiffNode getChild ( final NodePath nodePath ) { if ( parentNode != null ) { return parentNode . getChild ( nodePath . getElementSelectors ( ) ) ; } else { return getChild ( nodePath . getElementSelectors ( ) ) ; } }
Retrieve a child that matches the given absolute path starting from the current node .
59
16
148,956
public void addChild ( final DiffNode node ) { if ( node == this ) { throw new IllegalArgumentException ( "Detected attempt to add a node to itself. " + "This would cause inifite loops and must never happen." ) ; } else if ( node . isRootNode ( ) ) { throw new IllegalArgumentException ( "Detected attempt to add root node as child. " + "This is not allowed and must be a mistake." ) ; } else if ( node . getParentNode ( ) != null && node . getParentNode ( ) != this ) { throw new IllegalArgumentException ( "Detected attempt to add child node that is already the " + "child of another node. Adding nodes multiple times is not allowed, since it could " + "cause infinite loops." ) ; } if ( node . getParentNode ( ) == null ) { node . setParentNode ( this ) ; } children . put ( node . getElementSelector ( ) , node ) ; if ( state == State . UNTOUCHED && node . hasChanges ( ) ) { state = State . CHANGED ; } }
Adds a child to this node and sets this node as its parent node .
241
15
148,957
public final void visit ( final Visitor visitor ) { final Visit visit = new Visit ( ) ; try { visit ( visitor , visit ) ; } catch ( final StopVisitationException ignored ) { } }
Visit this and all child nodes .
42
7
148,958
public final void visitChildren ( final Visitor visitor ) { for ( final DiffNode child : children . values ( ) ) { try { child . visit ( visitor ) ; } catch ( final StopVisitationException e ) { return ; } } }
Visit all child nodes but not this one .
51
9
148,959
public Set < Annotation > getPropertyAnnotations ( ) { if ( accessor instanceof PropertyAwareAccessor ) { return unmodifiableSet ( ( ( PropertyAwareAccessor ) accessor ) . getReadMethodAnnotations ( ) ) ; } return unmodifiableSet ( Collections . < Annotation > emptySet ( ) ) ; }
If this node represents a bean property this method returns all annotations of its getter .
73
17
148,960
protected final void setParentNode ( final DiffNode parentNode ) { if ( this . parentNode != null && this . parentNode != parentNode ) { throw new IllegalStateException ( "The parent of a node cannot be changed, once it's set." ) ; } this . parentNode = parentNode ; }
Sets the parent node .
65
6
148,961
public TFuture < JsonResponse < AdvertiseResponse > > advertise ( ) { final AdvertiseRequest advertiseRequest = new AdvertiseRequest ( ) ; advertiseRequest . addService ( service , 0 ) ; // TODO: options for hard fail, retries etc. final JsonRequest < AdvertiseRequest > request = new JsonRequest . Builder < AdvertiseRequest > ( HYPERBAHN_SERVICE_NAME , HYPERBAHN_ADVERTISE_ENDPOINT ) . setBody ( advertiseRequest ) . setTimeout ( REQUEST_TIMEOUT ) . setRetryLimit ( 4 ) . build ( ) ; final TFuture < JsonResponse < AdvertiseResponse > > future = hyperbahnChannel . send ( request ) ; future . addCallback ( new TFutureCallback < JsonResponse < AdvertiseResponse > > ( ) { @ Override public void onResponse ( JsonResponse < AdvertiseResponse > response ) { if ( response . isError ( ) ) { logger . error ( "Failed to advertise to Hyperbahn: {} - {}" , response . getError ( ) . getErrorType ( ) , response . getError ( ) . getMessage ( ) ) ; } if ( destroyed . get ( ) ) { return ; } scheduleAdvertise ( ) ; } } ) ; return future ; }
Starts advertising on Hyperbahn at a fixed interval .
291
12
148,962
public List < T > parseList ( JsonParser jsonParser ) throws IOException { List < T > list = new ArrayList <> ( ) ; if ( jsonParser . getCurrentToken ( ) == JsonToken . START_ARRAY ) { while ( jsonParser . nextToken ( ) != JsonToken . END_ARRAY ) { list . add ( parse ( jsonParser ) ) ; } } return list ; }
Parse a list of objects from a JsonParser .
90
12
148,963
public Map < String , T > parseMap ( JsonParser jsonParser ) throws IOException { HashMap < String , T > map = new HashMap < String , T > ( ) ; while ( jsonParser . nextToken ( ) != JsonToken . END_OBJECT ) { String key = jsonParser . getText ( ) ; jsonParser . nextToken ( ) ; if ( jsonParser . getCurrentToken ( ) == JsonToken . VALUE_NULL ) { map . put ( key , null ) ; } else { map . put ( key , parse ( jsonParser ) ) ; } } return map ; }
Parse a map of objects from a JsonParser .
131
12
148,964
public static < E > E parse ( InputStream is , ParameterizedType < E > jsonObjectType ) throws IOException { return mapperFor ( jsonObjectType ) . parse ( is ) ; }
Parse a parameterized object from an InputStream .
43
11
148,965
@ SuppressWarnings ( "unchecked" ) public static < E > String serialize ( E object , ParameterizedType < E > parameterizedType ) throws IOException { return mapperFor ( parameterizedType ) . serialize ( object ) ; }
Serialize a parameterized object to a JSON String .
56
11
148,966
@ SuppressWarnings ( "unchecked" ) public static < E > void serialize ( E object , ParameterizedType < E > parameterizedType , OutputStream os ) throws IOException { mapperFor ( parameterizedType ) . serialize ( object , os ) ; }
Serialize a parameterized object to an OutputStream .
61
11
148,967
public static < E > String serialize ( Map < String , E > map , Class < E > jsonObjectClass ) throws IOException { return mapperFor ( jsonObjectClass ) . serialize ( map ) ; }
Serialize a map of objects to a JSON String .
46
11
148,968
@ SuppressWarnings ( "unchecked" ) public static < E > TypeConverter < E > typeConverterFor ( Class < E > cls ) throws NoSuchTypeConverterException { TypeConverter < E > typeConverter = TYPE_CONVERTERS . get ( cls ) ; if ( typeConverter == null ) { throw new NoSuchTypeConverterException ( cls ) ; } return typeConverter ; }
Returns a TypeConverter for a given class .
102
11
148,969
public static < E > void registerTypeConverter ( Class < E > cls , TypeConverter < E > converter ) { TYPE_CONVERTERS . put ( cls , converter ) ; }
Register a new TypeConverter for parsing and serialization .
44
13
148,970
public int indexOfKey ( Object key ) { return key == null ? indexOfNull ( ) : indexOf ( key , key . hashCode ( ) ) ; }
Returns the index of a key in the set .
35
10
148,971
public V put ( K key , V value ) { final int hash ; int index ; if ( key == null ) { hash = 0 ; index = indexOfNull ( ) ; } else { hash = key . hashCode ( ) ; index = indexOf ( key , hash ) ; } if ( index >= 0 ) { index = ( index << 1 ) + 1 ; final V old = ( V ) mArray [ index ] ; mArray [ index ] = value ; return old ; } index = ~ index ; if ( mSize >= mHashes . length ) { final int n = mSize >= ( BASE_SIZE * 2 ) ? ( mSize + ( mSize >> 1 ) ) : ( mSize >= BASE_SIZE ? ( BASE_SIZE * 2 ) : BASE_SIZE ) ; final int [ ] ohashes = mHashes ; final Object [ ] oarray = mArray ; allocArrays ( n ) ; if ( mHashes . length > 0 ) { System . arraycopy ( ohashes , 0 , mHashes , 0 , ohashes . length ) ; System . arraycopy ( oarray , 0 , mArray , 0 , oarray . length ) ; } freeArrays ( ohashes , oarray , mSize ) ; } if ( index < mSize ) { System . arraycopy ( mHashes , index , mHashes , index + 1 , mSize - index ) ; System . arraycopy ( mArray , index << 1 , mArray , ( index + 1 ) << 1 , ( mSize - index ) << 1 ) ; } mHashes [ index ] = hash ; mArray [ index << 1 ] = key ; mArray [ ( index << 1 ) + 1 ] = value ; mSize ++ ; return null ; }
Add a new value to the array map .
373
9
148,972
private void computeUnnamedParams ( ) { unnamedParams . addAll ( rawArgs . stream ( ) . filter ( arg -> ! isNamedParam ( arg ) ) . collect ( Collectors . toList ( ) ) ) ; }
This method computes the list of unnamed parameters by filtering the list of raw arguments stripping out the named parameters .
51
22
148,973
public static StatisticsMatrix wrap ( DMatrixRMaj m ) { StatisticsMatrix ret = new StatisticsMatrix ( ) ; ret . setMatrix ( m ) ; return ret ; }
Wraps a StatisticsMatrix around m . Does NOT create a copy of m but saves a reference to it .
36
22
148,974
public double mean ( ) { double total = 0 ; final int N = getNumElements ( ) ; for ( int i = 0 ; i < N ; i ++ ) { total += get ( i ) ; } return total / N ; }
Computes the mean or average of all the elements .
51
11
148,975
public double stdev ( ) { double m = mean ( ) ; double total = 0 ; final int N = getNumElements ( ) ; if ( N <= 1 ) throw new IllegalArgumentException ( "There must be more than one element to compute stdev" ) ; for ( int i = 0 ; i < N ; i ++ ) { double x = get ( i ) ; total += ( x - m ) * ( x - m ) ; } total /= ( N - 1 ) ; return Math . sqrt ( total ) ; }
Computes the unbiased standard deviation of all the elements .
115
11
148,976
@ Override protected StatisticsMatrix createMatrix ( int numRows , int numCols , MatrixType type ) { return new StatisticsMatrix ( numRows , numCols ) ; }
Returns a matrix of StatisticsMatrix type so that SimpleMatrix functions create matrices of the correct type .
39
20
148,977
@ Override public boolean decompose ( DMatrixRBlock A ) { if ( A . numCols != A . numRows ) throw new IllegalArgumentException ( "A must be square" ) ; this . T = A ; if ( lower ) return decomposeLower ( ) ; else return decomposeUpper ( ) ; }
Decomposes the provided matrix and stores the result in the same matrix .
72
15
148,978
public static void saveBin ( DMatrix A , String fileName ) throws IOException { FileOutputStream fileStream = new FileOutputStream ( fileName ) ; ObjectOutputStream stream = new ObjectOutputStream ( fileStream ) ; try { stream . writeObject ( A ) ; stream . flush ( ) ; } finally { // clean up try { stream . close ( ) ; } finally { fileStream . close ( ) ; } } }
Saves a matrix to disk using Java binary serialization .
92
12
148,979
public static DMatrixSparseCSC rectangle ( int numRows , int numCols , int nz_total , double min , double max , Random rand ) { nz_total = Math . min ( numCols * numRows , nz_total ) ; int [ ] selected = UtilEjml . shuffled ( numRows * numCols , nz_total , rand ) ; Arrays . sort ( selected , 0 , nz_total ) ; DMatrixSparseCSC ret = new DMatrixSparseCSC ( numRows , numCols , nz_total ) ; ret . indicesSorted = true ; // compute the number of elements in each column int hist [ ] = new int [ numCols ] ; for ( int i = 0 ; i < nz_total ; i ++ ) { hist [ selected [ i ] / numRows ] ++ ; } // define col_idx ret . histogramToStructure ( hist ) ; for ( int i = 0 ; i < nz_total ; i ++ ) { int row = selected [ i ] % numRows ; ret . nz_rows [ i ] = row ; ret . nz_values [ i ] = rand . nextDouble ( ) * ( max - min ) + min ; } return ret ; }
Randomly generates matrix with the specified number of non - zero elements filled with values from min to max .
288
21
148,980
public static DMatrixSparseCSC symmetric ( int N , int nz_total , double min , double max , Random rand ) { // compute the number of elements in the triangle, including diagonal int Ntriagle = ( N * N + N ) / 2 ; // create a list of open elements int open [ ] = new int [ Ntriagle ] ; for ( int row = 0 , index = 0 ; row < N ; row ++ ) { for ( int col = row ; col < N ; col ++ , index ++ ) { open [ index ] = row * N + col ; } } // perform a random draw UtilEjml . shuffle ( open , open . length , 0 , nz_total , rand ) ; Arrays . sort ( open , 0 , nz_total ) ; // construct the matrix DMatrixSparseTriplet A = new DMatrixSparseTriplet ( N , N , nz_total * 2 ) ; for ( int i = 0 ; i < nz_total ; i ++ ) { int index = open [ i ] ; int row = index / N ; int col = index % N ; double value = rand . nextDouble ( ) * ( max - min ) + min ; if ( row == col ) { A . addItem ( row , col , value ) ; } else { A . addItem ( row , col , value ) ; A . addItem ( col , row , value ) ; } } DMatrixSparseCSC B = new DMatrixSparseCSC ( N , N , A . nz_length ) ; ConvertDMatrixStruct . convert ( A , B ) ; return B ; }
Creates a random symmetric matrix . The entire matrix will be filled in not just a triangular portion .
358
21
148,981
public static DMatrixSparseCSC triangle ( boolean upper , int N , double minFill , double maxFill , Random rand ) { int nz = ( int ) ( ( ( N - 1 ) * ( N - 1 ) / 2 ) * ( rand . nextDouble ( ) * ( maxFill - minFill ) + minFill ) ) + N ; if ( upper ) { return triangleUpper ( N , 0 , nz , - 1 , 1 , rand ) ; } else { return triangleLower ( N , 0 , nz , - 1 , 1 , rand ) ; } }
Creates a triangular matrix where the amount of fill is randomly selected too .
125
15
148,982
public static void ensureNotSingular ( DMatrixSparseCSC A , Random rand ) { // if( A.numRows < A.numCols ) { // throw new IllegalArgumentException("Fewer equations than variables"); // } int [ ] s = UtilEjml . shuffled ( A . numRows , rand ) ; Arrays . sort ( s ) ; int N = Math . min ( A . numCols , A . numRows ) ; for ( int col = 0 ; col < N ; col ++ ) { A . set ( s [ col ] , col , rand . nextDouble ( ) + 0.5 ) ; } }
Modies the matrix to make sure that at least one element in each column has a value
144
18
148,983
public double compute ( DMatrix1Row mat ) { if ( width != mat . numCols || width != mat . numRows ) { throw new RuntimeException ( "Unexpected matrix dimension" ) ; } // make sure everything is in the proper state before it starts initStructures ( ) ; // System.arraycopy(mat.data,0,minorMatrix[0],0,mat.data.length); int level = 0 ; while ( true ) { int levelWidth = width - level ; int levelIndex = levelIndexes [ level ] ; if ( levelIndex == levelWidth ) { if ( level == 0 ) { return levelResults [ 0 ] ; } int prevLevelIndex = levelIndexes [ level - 1 ] ++ ; double val = mat . get ( ( level - 1 ) * width + levelRemoved [ level - 1 ] ) ; if ( prevLevelIndex % 2 == 0 ) { levelResults [ level - 1 ] += val * levelResults [ level ] ; } else { levelResults [ level - 1 ] -= val * levelResults [ level ] ; } putIntoOpen ( level - 1 ) ; levelResults [ level ] = 0 ; levelIndexes [ level ] = 0 ; level -- ; } else { int excluded = openRemove ( levelIndex ) ; levelRemoved [ level ] = excluded ; if ( levelWidth == minWidth ) { createMinor ( mat ) ; double subresult = mat . get ( level * width + levelRemoved [ level ] ) ; subresult *= UnrolledDeterminantFromMinor_DDRM . det ( tempMat ) ; if ( levelIndex % 2 == 0 ) { levelResults [ level ] += subresult ; } else { levelResults [ level ] -= subresult ; } // put it back into the list putIntoOpen ( level ) ; levelIndexes [ level ] ++ ; } else { level ++ ; } } } }
Computes the determinant for the specified matrix . It must be square and have the same width and height as what was specified in the constructor .
400
29
148,984
public static double [ ] singularValues ( DMatrixRMaj A ) { SingularValueDecomposition_F64 < DMatrixRMaj > svd = DecompositionFactory_DDRM . svd ( A . numRows , A . numCols , false , true , true ) ; if ( svd . inputModified ( ) ) { A = A . copy ( ) ; } if ( ! svd . decompose ( A ) ) { throw new RuntimeException ( "SVD Failed!" ) ; } double sv [ ] = svd . getSingularValues ( ) ; Arrays . sort ( sv , 0 , svd . numberOfSingularValues ( ) ) ; // change the ordering to ascending for ( int i = 0 ; i < sv . length / 2 ; i ++ ) { double tmp = sv [ i ] ; sv [ i ] = sv [ sv . length - i - 1 ] ; sv [ sv . length - i - 1 ] = tmp ; } return sv ; }
Returns an array of all the singular values in A sorted in ascending order
216
14
148,985
public static double ratioSmallestOverLargest ( double [ ] sv ) { if ( sv . length == 0 ) return Double . NaN ; double min = sv [ 0 ] ; double max = min ; for ( int i = 1 ; i < sv . length ; i ++ ) { double v = sv [ i ] ; if ( v > max ) max = v ; else if ( v < min ) min = v ; } return min / max ; }
Computes the ratio of the smallest value to the largest . Does not assume the array is sorted first
97
20
148,986
public static int rank ( DMatrixRMaj A ) { SingularValueDecomposition_F64 < DMatrixRMaj > svd = DecompositionFactory_DDRM . svd ( A . numRows , A . numCols , false , true , true ) ; if ( svd . inputModified ( ) ) { A = A . copy ( ) ; } if ( ! svd . decompose ( A ) ) { throw new RuntimeException ( "SVD Failed!" ) ; } int N = svd . numberOfSingularValues ( ) ; double sv [ ] = svd . getSingularValues ( ) ; double threshold = singularThreshold ( sv , N ) ; int count = 0 ; for ( int i = 0 ; i < sv . length ; i ++ ) { if ( sv [ i ] >= threshold ) { count ++ ; } } return count ; }
Returns the matrix s rank . Automatic selection of threshold
192
10
148,987
public static void checkSvdMatrixSize ( DMatrixRMaj U , boolean tranU , DMatrixRMaj W , DMatrixRMaj V , boolean tranV ) { int numSingular = Math . min ( W . numRows , W . numCols ) ; boolean compact = W . numRows == W . numCols ; if ( compact ) { if ( U != null ) { if ( tranU && U . numRows != numSingular ) throw new IllegalArgumentException ( "Unexpected size of matrix U" ) ; else if ( ! tranU && U . numCols != numSingular ) throw new IllegalArgumentException ( "Unexpected size of matrix U" ) ; } if ( V != null ) { if ( tranV && V . numRows != numSingular ) throw new IllegalArgumentException ( "Unexpected size of matrix V" ) ; else if ( ! tranV && V . numCols != numSingular ) throw new IllegalArgumentException ( "Unexpected size of matrix V" ) ; } } else { if ( U != null && U . numRows != U . numCols ) throw new IllegalArgumentException ( "Unexpected size of matrix U" ) ; if ( V != null && V . numRows != V . numCols ) throw new IllegalArgumentException ( "Unexpected size of matrix V" ) ; if ( U != null && U . numRows != W . numRows ) throw new IllegalArgumentException ( "Unexpected size of W" ) ; if ( V != null && V . numRows != W . numCols ) throw new IllegalArgumentException ( "Unexpected size of W" ) ; } }
Checks to see if all the provided matrices are the expected size for an SVD . If an error is encountered then an exception is thrown . This automatically handles compact and non - compact formats
378
39
148,988
public static DMatrixRMaj nullspaceQR ( DMatrixRMaj A , int totalSingular ) { SolveNullSpaceQR_DDRM solver = new SolveNullSpaceQR_DDRM ( ) ; DMatrixRMaj nullspace = new DMatrixRMaj ( 1 , 1 ) ; if ( ! solver . process ( A , totalSingular , nullspace ) ) throw new RuntimeException ( "Solver failed. try SVD based method instead?" ) ; return nullspace ; }
Computes the null space using QR decomposition . This is much faster than using SVD
114
18
148,989
public static DMatrixRMaj nullspaceQRP ( DMatrixRMaj A , int totalSingular ) { SolveNullSpaceQRP_DDRM solver = new SolveNullSpaceQRP_DDRM ( ) ; DMatrixRMaj nullspace = new DMatrixRMaj ( 1 , 1 ) ; if ( ! solver . process ( A , totalSingular , nullspace ) ) throw new RuntimeException ( "Solver failed. try SVD based method instead?" ) ; return nullspace ; }
Computes the null space using QRP decomposition . This is faster than using SVD but slower than QR . Much more stable than QR though .
114
30
148,990
public static DMatrixRMaj nullspaceSVD ( DMatrixRMaj A , int totalSingular ) { SolveNullSpace < DMatrixRMaj > solver = new SolveNullSpaceSvd_DDRM ( ) ; DMatrixRMaj nullspace = new DMatrixRMaj ( 1 , 1 ) ; if ( ! solver . process ( A , totalSingular , nullspace ) ) throw new RuntimeException ( "Solver failed. try SVD based method instead?" ) ; return nullspace ; }
Computes the null space using SVD . Slowest bust most stable way to find the solution
115
19
148,991
public static int rank ( SingularValueDecomposition_F64 svd , double threshold ) { int numRank = 0 ; double w [ ] = svd . getSingularValues ( ) ; int N = svd . numberOfSingularValues ( ) ; for ( int j = 0 ; j < N ; j ++ ) { if ( w [ j ] > threshold ) numRank ++ ; } return numRank ; }
Extracts the rank of a matrix using a preexisting decomposition .
90
16
148,992
public static int nullity ( SingularValueDecomposition_F64 svd , double threshold ) { int ret = 0 ; double w [ ] = svd . getSingularValues ( ) ; int N = svd . numberOfSingularValues ( ) ; int numCol = svd . numCols ( ) ; for ( int j = 0 ; j < N ; j ++ ) { if ( w [ j ] <= threshold ) ret ++ ; } return ret + numCol - N ; }
Extracts the nullity of a matrix using a preexisting decomposition .
106
17
148,993
public double [ ] getSingularValues ( ) { double ret [ ] = new double [ W . numCols ( ) ] ; for ( int i = 0 ; i < ret . length ; i ++ ) { ret [ i ] = getSingleValue ( i ) ; } return ret ; }
Returns an array of all the singular values
62
8
148,994
public int rank ( ) { if ( is64 ) { return SingularOps_DDRM . rank ( ( SingularValueDecomposition_F64 ) svd , tol ) ; } else { return SingularOps_FDRM . rank ( ( SingularValueDecomposition_F32 ) svd , ( float ) tol ) ; } }
Returns the rank of the decomposed matrix .
78
9
148,995
public int nullity ( ) { if ( is64 ) { return SingularOps_DDRM . nullity ( ( SingularValueDecomposition_F64 ) svd , 10.0 * UtilEjml . EPS ) ; } else { return SingularOps_FDRM . nullity ( ( SingularValueDecomposition_F32 ) svd , 5.0f * UtilEjml . F_EPS ) ; } }
The nullity of the decomposed matrix .
100
9
148,996
public boolean isFunctionName ( String s ) { if ( input1 . containsKey ( s ) ) return true ; if ( inputN . containsKey ( s ) ) return true ; return false ; }
Returns true if the string matches the name of a function
42
11
148,997
public Operation . Info create ( char op , Variable input ) { switch ( op ) { case ' ' : return Operation . transpose ( input , managerTemp ) ; default : throw new RuntimeException ( "Unknown operation " + op ) ; } }
Create a new instance of a single input function from an operator character
51
13
148,998
public Operation . Info create ( Symbol op , Variable left , Variable right ) { switch ( op ) { case PLUS : return Operation . add ( left , right , managerTemp ) ; case MINUS : return Operation . subtract ( left , right , managerTemp ) ; case TIMES : return Operation . multiply ( left , right , managerTemp ) ; case RDIVIDE : return Operation . divide ( left , right , managerTemp ) ; case LDIVIDE : return Operation . divide ( right , left , managerTemp ) ; case POWER : return Operation . pow ( left , right , managerTemp ) ; case ELEMENT_DIVIDE : return Operation . elementDivision ( left , right , managerTemp ) ; case ELEMENT_TIMES : return Operation . elementMult ( left , right , managerTemp ) ; case ELEMENT_POWER : return Operation . elementPow ( left , right , managerTemp ) ; default : throw new RuntimeException ( "Unknown operation " + op ) ; } }
Create a new instance of a two input function from an operator character
206
13
148,999
void initialize ( DMatrixSparseCSC A ) { m = A . numRows ; n = A . numCols ; int s = 4 * n + ( ata ? ( n + m + 1 ) : 0 ) ; gw . reshape ( s ) ; w = gw . data ; // compute the transpose of A At . reshape ( A . numCols , A . numRows , A . nz_length ) ; CommonOps_DSCC . transpose ( A , At , gw ) ; // initialize w Arrays . fill ( w , 0 , s , - 1 ) ; // assign all values in workspace to -1 ancestor = 0 ; maxfirst = n ; prevleaf = 2 * n ; first = 3 * n ; }
Initializes class data structures and parameters
166
7