idx
int64
0
41.2k
question
stringlengths
83
4.15k
target
stringlengths
5
715
25,500
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 .
25,501
public void addOpacityBar ( OpacityBar bar ) { mOpacityBar = bar ; mOpacityBar . setColorPicker ( this ) ; mOpacityBar . setColor ( mColor ) ; }
Add a Opacity bar to the color wheel .
25,502
public void setNewCenterColor ( int color ) { mCenterNewColor = color ; mCenterNewPaint . setColor ( color ) ; if ( mCenterOldColor == 0 ) { mCenterOldColor = color ; mCenterOldPaint . setColor ( color ) ; } if ( onColorChangedListener != null && color != oldChangedListenerColor ) { onColorChangedListener . onColorChan...
Change the color of the center which indicates the new color .
25,503
public void setValue ( float value ) { mBarPointerPosition = Math . round ( ( mSVToPosFactor * ( 1 - value ) ) + mBarPointerHaloRadius + ( mBarLength / 2 ) ) ; calculateColor ( mBarPointerPosition ) ; mBarPointerPaint . setColor ( mColor ) ; if ( mPicker != null ) { mPicker . setNewCenterColor ( mColor ) ; mPicker . ch...
Set the pointer on the bar . With the Value value .
25,504
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" , "...
helper to calculate the navigationBar height
25,505
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 ) ; }...
helper to calculate the actionBar height
25,506
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 =...
helper to calculate the statusBar height
25,507
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
25,508
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
25,509
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
25,510
public static int getScreenWidth ( Context context ) { DisplayMetrics metrics = context . getResources ( ) . getDisplayMetrics ( ) ; return metrics . widthPixels ; }
Returns the screen width in pixels
25,511
public static int getScreenHeight ( Context context ) { DisplayMetrics metrics = context . getResources ( ) . getDisplayMetrics ( ) ; return metrics . heightPixels ; }
Returns the screen height in pixels
25,512
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
25,513
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
25,514
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
25,515
public void setStatusBarColor ( int statusBarColor ) { if ( mBuilder . mScrimInsetsLayout != null ) { mBuilder . mScrimInsetsLayout . setInsetForeground ( statusBarColor ) ; mBuilder . mScrimInsetsLayout . getView ( ) . invalidate ( ) ; } }
Set the color for the statusBar
25,516
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 ) { mKeyboa...
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 .
25,517
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
25,518
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
25,519
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 . se...
a small helper to set the text color to a textView null save
25,520
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
25,521
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
25,522
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
25,523
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
25,524
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
25,525
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
25,526
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 ) { image...
decides which icon to apply or hide this view
25,527
public static void applyMultiIconTo ( Drawable icon , int iconColor , Drawable selectedIcon , int selectedIconColor , boolean tinted , ImageView imageView ) { if ( icon != null ) { if ( selectedIcon != null ) { if ( tinted ) { imageView . setImageDrawable ( new PressedEffectStateListDrawable ( icon , selectedIcon , ico...
a small static helper to set a multi state drawable on a view
25,528
public void setHighlightStrength ( float _highlightStrength ) { mHighlightStrength = _highlightStrength ; for ( PieModel model : mPieData ) { highlightSlice ( model ) ; } invalidateGlobal ( ) ; }
Sets the highlight strength for the InnerPaddingOutline .
25,529
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 .
25,530
protected void onDraw ( Canvas canvas ) { super . onDraw ( canvas ) ; if ( Build . VERSION . SDK_INT < 11 ) { tickScrollAnimation ( ) ; if ( ! mScroller . isFinished ( ) ) { mGraph . postInvalidate ( ) ; } } }
Implement this to do your drawing .
25,531
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 . setStart...
Should be called after new data is inserted . Will be automatically called when the view dimensions has changed .
25,532
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 ) , M...
Calculate the highlight color . Saturate at 0xff to make sure that high values don t result in aliasing .
25,533
private void calcCurrentItem ( ) { int pointerAngle ; 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...
Calculate which pie slice is under the pointer and set the current item field accordingly .
25,534
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 ( targe...
Kicks off an animation that will result in the pointer being centered in the pie slice of the currently selected item .
25,535
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 += m...
Calculates the legend bounds for a custom list of legends .
25,536
private void calculateValueTextHeight ( ) { Rect valueRect = new Rect ( ) ; Rect legendRect = new Rect ( ) ; String str = Utils . getFloatString ( mFocusedPoint . getValue ( ) , mShowDecimal ) + ( ! mIndicatorTextUnit . isEmpty ( ) ? " " + mIndicatorTextUnit : "" ) ; mIndicatorPaint . getTextBounds ( str , 0 , str . le...
Calculates the text height for the indicator value and sets its x - coordinate .
25,537
protected void calculateBarPositions ( int _DataSize ) { int dataSize = mScrollEnabled ? mVisibleBars : _DataSize ; float barWidth = mBarWidth ; float margin = mBarMargin ; if ( ! mFixedBarWidth ) { barWidth = ( mAvailableScreenSize / _DataSize ) - margin ; } else { if ( _DataSize < mVisibleBars ) { dataSize = _DataSiz...
Calculates the bar width and bar margin based on the _DataSize and settings and starts the boundary calculation in child classes .
25,538
protected void onGraphDraw ( Canvas _Canvas ) { super . onGraphDraw ( _Canvas ) ; _Canvas . translate ( - mCurrentViewport . left , - mCurrentViewport . top ) ; drawBars ( _Canvas ) ; }
region Override Methods
25,539
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 * _Multiplie...
Calculates the middle point between two points and multiplies its coordinates with the given smoothness _Mulitplier .
25,540
public static void calculateLegendInformation ( List < ? extends BaseModel > _Models , float _StartX , float _EndX , Paint _Paint ) { float textMargin = Utils . dpToPx ( 10.f ) ; float lastX = _StartX ; for ( BaseModel model : _Models ) { if ( ! model . isIgnore ( ) ) { Rect textBounds = new Rect ( ) ; RectF legendBoun...
Calculates the legend positions and which legend title should be displayed or not .
25,541
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 .
25,542
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 .
25,543
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 .
25,544
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 .
25,545
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 .
25,546
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_T...
Decides what the Map Web provider should be used and generates a builder for it .
25,547
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 (...
Used for initialization of the underlying map provider .
25,548
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 ( cl...
Private function to allow looking for the field recursively up the superclasses .
25,549
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 .
25,550
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 .
25,551
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 no...
Adds a child to this node and sets this node as its parent node .
25,552
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 .
25,553
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 .
25,554
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 .
25,555
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 .
25,556
public TFuture < JsonResponse < AdvertiseResponse > > advertise ( ) { final AdvertiseRequest advertiseRequest = new AdvertiseRequest ( ) ; advertiseRequest . addService ( service , 0 ) ; final JsonRequest < AdvertiseRequest > request = new JsonRequest . Builder < AdvertiseRequest > ( HYPERBAHN_SERVICE_NAME , HYPERBAHN_...
Starts advertising on Hyperbahn at a fixed interval .
25,557
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 .
25,558
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 ( ) == J...
Parse a map of objects from a JsonParser .
25,559
public static < E > E parse ( InputStream is , ParameterizedType < E > jsonObjectType ) throws IOException { return mapperFor ( jsonObjectType ) . parse ( is ) ; }
Parse a parameterized object from an InputStream .
25,560
@ 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 .
25,561
@ 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 .
25,562
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 .
25,563
@ 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 .
25,564
public static < E > void registerTypeConverter ( Class < E > cls , TypeConverter < E > converter ) { TYPE_CONVERTERS . put ( cls , converter ) ; }
Register a new TypeConverter for parsing and serialization .
25,565
public int indexOfKey ( Object key ) { return key == null ? indexOfNull ( ) : indexOf ( key , key . hashCode ( ) ) ; }
Returns the index of a key in the set .
25,566
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 ...
Add a new value to the array map .
25,567
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 .
25,568
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 .
25,569
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 .
25,570
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 - ...
Computes the unbiased standard deviation of all the elements .
25,571
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 .
25,572
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 .
25,573
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 { try { stream . close ( ) ; } finally {...
Saves a matrix to disk using Java binary serialization .
25,574
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 ) ; DMatrixSpa...
Randomly generates matrix with the specified number of non - zero elements filled with values from min to max .
25,575
public static DMatrixSparseCSC symmetric ( int N , int nz_total , double min , double max , Random rand ) { int Ntriagle = ( N * N + N ) / 2 ; 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 ;...
Creates a random symmetric matrix . The entire matrix will be filled in not just a triangular portion .
25,576
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...
Creates a triangular matrix where the amount of fill is randomly selected too .
25,577
public static void ensureNotSingular ( DMatrixSparseCSC A , Random rand ) { 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
25,578
public double compute ( DMatrix1Row mat ) { if ( width != mat . numCols || width != mat . numRows ) { throw new RuntimeException ( "Unexpected matrix dimension" ) ; } initStructures ( ) ; int level = 0 ; while ( true ) { int levelWidth = width - level ; int levelIndex = levelIndexes [ level ] ; if ( levelIndex == 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 .
25,579
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 ...
Returns an array of all the singular values in A sorted in ascending order
25,580
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
25,581
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!" ) ; } in...
Returns the matrix s rank . Automatic selection of threshold
25,582
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 I...
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
25,583
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 i...
Computes the null space using QR decomposition . This is much faster than using SVD
25,584
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 metho...
Computes the null space using QRP decomposition . This is faster than using SVD but slower than QR . Much more stable than QR though .
25,585
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 bas...
Computes the null space using SVD . Slowest bust most stable way to find the solution
25,586
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 .
25,587
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 .
25,588
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
25,589
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 .
25,590
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 .
25,591
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
25,592
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
25,593
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 RDI...
Create a new instance of a two input function from an operator character
25,594
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 ; At . reshape ( A . numCols , A . numRows , A . nz_length ) ; CommonOps_DSCC . transpose ( A , At , gw ) ; Arrays . fill ( w , 0 , s , - 1 ) ; ancestor = 0 ; max...
Initializes class data structures and parameters
25,595
public void process ( DMatrixSparseCSC A , int parent [ ] , int post [ ] , int counts [ ] ) { if ( counts . length < A . numCols ) throw new IllegalArgumentException ( "counts must be at least of length A.numCols" ) ; initialize ( A ) ; int delta [ ] = counts ; findFirstDescendant ( parent , post , delta ) ; if ( ata )...
Processes and computes column counts of A
25,596
public static void show ( DMatrixD1 A , String title ) { JFrame frame = new JFrame ( title ) ; int width = 300 ; int height = 300 ; if ( A . numRows > A . numCols ) { width = width * A . numCols / A . numRows ; } else { height = height * A . numRows / A . numCols ; } DMatrixComponent panel = new DMatrixComponent ( widt...
Creates a window visually showing the matrix s state . Block means an element is zero . Red positive and blue negative . More intense the color larger the element s absolute value is .
25,597
public void value2x2 ( double a11 , double a12 , double a21 , double a22 ) { double c , s ; if ( a12 + a21 == 0 ) { c = s = 1.0 / Math . sqrt ( 2 ) ; } else { double aa = ( a11 - a22 ) ; double bb = ( a12 + a21 ) ; double t_hat = aa / bb ; double t = t_hat / ( 1.0 + Math . sqrt ( 1.0 + t_hat * t_hat ) ) ; c = 1.0 / Mat...
if |a11 - a22| >> |a12 + a21| there might be a better way . see pg371
25,598
public void value2x2_fast ( double a11 , double a12 , double a21 , double a22 ) { double left = ( a11 + a22 ) / 2.0 ; double inside = 4.0 * a12 * a21 + ( a11 - a22 ) * ( a11 - a22 ) ; if ( inside < 0 ) { value0 . real = value1 . real = left ; value0 . imaginary = Math . sqrt ( - inside ) / 2.0 ; value1 . imaginary = - ...
Computes the eigenvalues of a 2 by 2 matrix using a faster but more prone to errors method . This is the typical method .
25,599
public void symm2x2_fast ( double a11 , double a12 , double a22 ) { double left = ( a11 + a22 ) * 0.5 ; double b = ( a11 - a22 ) * 0.5 ; double right = Math . sqrt ( b * b + a12 * a12 ) ; value0 . real = left + right ; value1 . real = left - right ; }
See page 385 of Fundamentals of Matrix Computations 2nd