idx int64 0 41.2k | question stringlengths 74 4.04k | target stringlengths 7 750 |
|---|---|---|
29,800 | public Field getRelationshipField ( Class < ? > clazz , String fieldName ) { return relationshipFieldMap . get ( clazz ) . get ( fieldName ) ; } | Returns relationship field . |
29,801 | public Class < ? > getRelationshipType ( Class < ? > clazz , String fieldName ) { return relationshipTypeMap . get ( clazz ) . get ( fieldName ) ; } | Returns a type of a relationship . |
29,802 | public String getTypeName ( Class < ? > clazz ) { Type type = typeAnnotations . get ( clazz ) ; if ( type != null ) { return type . value ( ) ; } return null ; } | Resolves and returns name of the type given to provided class . |
29,803 | public Field getRelationshipMetaField ( Class < ? > clazz , String relationshipName ) { return relationshipMetaFieldMap . get ( clazz ) . get ( relationshipName ) ; } | Returns relationship meta field . |
29,804 | public Class < ? > getRelationshipMetaType ( Class < ? > clazz , String relationshipName ) { return relationshipMetaTypeMap . get ( clazz ) . get ( relationshipName ) ; } | Returns a type of a relationship meta field . |
29,805 | public Field getRelationshipLinksField ( Class < ? > clazz , String relationshipName ) { return relationshipLinksFieldMap . get ( clazz ) . get ( relationshipName ) ; } | Returns relationship links field . |
29,806 | public void setTypeResolver ( RelationshipResolver resolver , Class < ? > type ) { if ( resolver != null ) { String typeName = ReflectionUtils . getTypeName ( type ) ; if ( typeName != null ) { typedResolvers . put ( type , resolver ) ; } } } | Registers relationship resolver for given type . Resolver will be used if relationship resolution is enabled trough relationship annotation . |
29,807 | public < T > T readObject ( byte [ ] data , Class < T > clazz ) { return readDocument ( data , clazz ) . get ( ) ; } | Converts raw data input into requested target type . |
29,808 | public < T > List < T > readObjectCollection ( byte [ ] data , Class < T > clazz ) { return readDocumentCollection ( data , clazz ) . get ( ) ; } | Converts rawdata input into a collection of requested output objects . |
29,809 | private < T > T readObject ( JsonNode source , Class < T > clazz , boolean handleRelationships ) throws IOException , IllegalAccessException , InstantiationException { String identifier = createIdentifier ( source ) ; T result = ( T ) resourceCache . get ( identifier ) ; if ( result == null ) { Class < ? > type = getActualType ( source , clazz ) ; if ( source . has ( ATTRIBUTES ) ) { result = ( T ) objectMapper . treeToValue ( source . get ( ATTRIBUTES ) , type ) ; } else { if ( type . isInterface ( ) ) { result = null ; } else { result = ( T ) objectMapper . treeToValue ( objectMapper . createObjectNode ( ) , type ) ; } } if ( source . has ( META ) ) { Field field = configuration . getMetaField ( type ) ; if ( field != null ) { Class < ? > metaType = configuration . getMetaType ( type ) ; Object metaObject = objectMapper . treeToValue ( source . get ( META ) , metaType ) ; field . set ( result , metaObject ) ; } } if ( source . has ( LINKS ) ) { Field linkField = configuration . getLinksField ( type ) ; if ( linkField != null ) { linkField . set ( result , new Links ( mapLinks ( source . get ( LINKS ) ) ) ) ; } } if ( result != null ) { resourceCache . cache ( identifier , result ) ; setIdValue ( result , source . get ( ID ) ) ; if ( handleRelationships ) { handleRelationships ( source , result ) ; } } } return result ; } | Converts provided input into a target object . After conversion completes any relationships defined are resolved . |
29,810 | private Map < String , Object > parseIncluded ( JsonNode parent ) throws IOException , IllegalAccessException , InstantiationException { Map < String , Object > result = new HashMap < > ( ) ; if ( parent . has ( INCLUDED ) ) { Map < String , Object > includedResources = getIncludedResources ( parent ) ; if ( ! includedResources . isEmpty ( ) ) { for ( String identifier : includedResources . keySet ( ) ) { result . put ( identifier , includedResources . get ( identifier ) ) ; } ArrayNode includedArray = ( ArrayNode ) parent . get ( INCLUDED ) ; for ( int i = 0 ; i < includedArray . size ( ) ; i ++ ) { JsonNode node = includedArray . get ( i ) ; Object resourceObject = includedResources . get ( createIdentifier ( node ) ) ; if ( resourceObject != null ) { handleRelationships ( node , resourceObject ) ; } } } } return result ; } | Converts included data and returns it as pairs of its unique identifiers and converted types . |
29,811 | private Map < String , Object > getIncludedResources ( JsonNode parent ) throws IOException , IllegalAccessException , InstantiationException { Map < String , Object > result = new HashMap < > ( ) ; if ( parent . has ( INCLUDED ) ) { for ( JsonNode jsonNode : parent . get ( INCLUDED ) ) { String type = jsonNode . get ( TYPE ) . asText ( ) ; Class < ? > clazz = configuration . getTypeClass ( type ) ; if ( clazz != null ) { Object object = readObject ( jsonNode , clazz , false ) ; if ( object != null ) { result . put ( createIdentifier ( jsonNode ) , object ) ; } } else if ( ! deserializationFeatures . contains ( DeserializationFeature . ALLOW_UNKNOWN_INCLUSIONS ) ) { throw new IllegalArgumentException ( "Included section contains unknown resource type: " + type ) ; } } } return result ; } | Parses out included resources excluding relationships . |
29,812 | private Object parseRelationship ( JsonNode relationshipDataNode , Class < ? > type ) throws IOException , IllegalAccessException , InstantiationException { if ( ValidationUtils . isRelationshipParsable ( relationshipDataNode ) ) { String identifier = createIdentifier ( relationshipDataNode ) ; if ( resourceCache . contains ( identifier ) ) { return resourceCache . get ( identifier ) ; } else { resourceCache . lock ( ) ; try { return readObject ( relationshipDataNode , type , true ) ; } finally { resourceCache . unlock ( ) ; } } } return null ; } | Creates relationship object by consuming provided data node . |
29,813 | private void setIdValue ( Object target , JsonNode idValue ) throws IllegalAccessException { Field idField = configuration . getIdField ( target . getClass ( ) ) ; ResourceIdHandler idHandler = configuration . getIdHandler ( target . getClass ( ) ) ; if ( idValue != null ) { idField . set ( target , idHandler . fromString ( idValue . asText ( ) ) ) ; } } | Sets an id attribute value to a target object . |
29,814 | private RelationshipResolver getResolver ( Class < ? > type ) { RelationshipResolver resolver = typedResolvers . get ( type ) ; return resolver != null ? resolver : globalResolver ; } | Returns relationship resolver for given type . In case no specific type resolver is registered global resolver is returned . |
29,815 | public boolean registerType ( Class < ? > type ) { if ( ! configuration . isRegisteredType ( type ) && ConverterConfiguration . isEligibleType ( type ) ) { return configuration . registerType ( type ) ; } return false ; } | Registers new type to be used with this converter instance . |
29,816 | public static List < Field > getAnnotatedFields ( Class < ? > clazz , Class < ? extends Annotation > annotation , boolean checkSuperclass ) { Field [ ] fields = clazz . getDeclaredFields ( ) ; List < Field > result = new ArrayList < > ( ) ; for ( Field field : fields ) { if ( field . isAnnotationPresent ( annotation ) ) { result . add ( field ) ; } } if ( checkSuperclass && clazz . getSuperclass ( ) != null && ! clazz . getSuperclass ( ) . equals ( Object . class ) ) { result . addAll ( getAnnotatedFields ( clazz . getSuperclass ( ) , annotation , true ) ) ; } return result ; } | Returns all field from a given class that are annotated with provided annotation type . |
29,817 | public static String getTypeName ( Class < ? > clazz ) { Type typeAnnotation = clazz . getAnnotation ( Type . class ) ; return typeAnnotation != null ? typeAnnotation . value ( ) : null ; } | Returns the type name defined using Type annotation on provided class . |
29,818 | public void init ( ) { if ( initDepth . get ( ) == null ) { initDepth . set ( 1 ) ; } else { initDepth . set ( initDepth . get ( ) + 1 ) ; } if ( resourceCache . get ( ) == null ) { resourceCache . set ( new HashMap < String , Object > ( ) ) ; } if ( cacheLocked . get ( ) == null ) { cacheLocked . set ( Boolean . FALSE ) ; } } | Initialises cache for current thread - scope . |
29,819 | public void clear ( ) { verifyState ( ) ; initDepth . set ( initDepth . get ( ) - 1 ) ; if ( initDepth . get ( ) == 0 ) { resourceCache . set ( null ) ; cacheLocked . set ( null ) ; initDepth . set ( null ) ; } } | Clears current thread scope state . |
29,820 | public void cache ( Map < String , Object > resources ) { verifyState ( ) ; if ( ! cacheLocked . get ( ) ) { resourceCache . get ( ) . putAll ( resources ) ; } } | Adds multiple resources to cache . |
29,821 | public void cache ( String identifier , Object resource ) { verifyState ( ) ; if ( ! cacheLocked . get ( ) ) { resourceCache . get ( ) . put ( identifier , resource ) ; } } | Adds resource to cache . |
29,822 | public static < T extends Errors > T parseErrorResponse ( ObjectMapper mapper , ResponseBody errorResponse , Class < T > cls ) throws IOException { return mapper . readValue ( errorResponse . bytes ( ) , cls ) ; } | Parses provided ResponseBody and returns it as T . |
29,823 | public static < T extends Errors > T parseError ( ObjectMapper mapper , JsonNode errorResponse , Class < T > cls ) throws JsonProcessingException { return mapper . treeToValue ( errorResponse , cls ) ; } | Parses provided JsonNode and returns it as T . |
29,824 | public static < L , R > Either < L , R > left ( L l ) { return new Left < > ( l ) ; } | Static factory method for creating a left value . |
29,825 | public static < L , R > Either < L , R > right ( R r ) { return new Right < > ( r ) ; } | Static factory method for creating a right value . |
29,826 | public static < X > Lens . Simple < List < X > , List < X > > asCopy ( ) { return simpleLens ( ArrayList :: new , ( xs , ys ) -> ys ) ; } | Convenience static factory method for creating a lens over a copy of a list . Useful for composition to avoid mutating a list reference . |
29,827 | public static < T extends Throwable , A > Try < T , A > success ( A a ) { return new Success < > ( a ) ; } | Static factory method for creating a success value . |
29,828 | public static < T extends Throwable , A > Try < T , A > failure ( T t ) { return new Failure < > ( t ) ; } | Static factory method for creating a failure value . |
29,829 | public < B > State < S , B > mapState ( Fn1 < ? super Tuple2 < A , S > , ? extends Product2 < B , S > > fn ) { return state ( s -> fn . apply ( run ( s ) ) ) ; } | Map both the result and the final state to a new result and final state . |
29,830 | public State < S , A > withState ( Fn1 < ? super S , ? extends S > fn ) { return state ( s -> run ( fn . apply ( s ) ) ) ; } | Map the final state to a new final state using the provided function . |
29,831 | public static < Head , Tail extends HList > HCons < Head , Tail > cons ( Head head , Tail tail ) { return new HCons < > ( head , tail ) ; } | Static factory method for creating an HList from the given head and tail . |
29,832 | @ SuppressWarnings ( "JavaDoc" ) public static < _1 , _2 > Tuple2 < _1 , _2 > tuple ( _1 _1 , _2 _2 ) { return singletonHList ( _2 ) . cons ( _1 ) ; } | Static factory method for creating a 2 - element HList . |
29,833 | @ SuppressWarnings ( "JavaDoc" ) public static < _1 , _2 , _3 > Tuple3 < _1 , _2 , _3 > tuple ( _1 _1 , _2 _2 , _3 _3 ) { return tuple ( _2 , _3 ) . cons ( _1 ) ; } | Static factory method for creating a 3 - element HList . |
29,834 | @ SuppressWarnings ( "JavaDoc" ) public static < _1 , _2 , _3 , _4 > Tuple4 < _1 , _2 , _3 , _4 > tuple ( _1 _1 , _2 _2 , _3 _3 , _4 _4 ) { return tuple ( _2 , _3 , _4 ) . cons ( _1 ) ; } | Static factory method for creating a 4 - element HList . |
29,835 | @ SuppressWarnings ( "JavaDoc" ) public static < _1 , _2 , _3 , _4 , _5 > Tuple5 < _1 , _2 , _3 , _4 , _5 > tuple ( _1 _1 , _2 _2 , _3 _3 , _4 _4 , _5 _5 ) { return tuple ( _2 , _3 , _4 , _5 ) . cons ( _1 ) ; } | Static factory method for creating a 5 - element HList . |
29,836 | @ SuppressWarnings ( "JavaDoc" ) public static < _1 , _2 , _3 , _4 , _5 , _6 > Tuple6 < _1 , _2 , _3 , _4 , _5 , _6 > tuple ( _1 _1 , _2 _2 , _3 _3 , _4 _4 , _5 _5 , _6 _6 ) { return tuple ( _2 , _3 , _4 , _5 , _6 ) . cons ( _1 ) ; } | Static factory method for creating a 6 - element HList . |
29,837 | @ SuppressWarnings ( "JavaDoc" ) public static < _1 , _2 , _3 , _4 , _5 , _6 , _7 > Tuple7 < _1 , _2 , _3 , _4 , _5 , _6 , _7 > tuple ( _1 _1 , _2 _2 , _3 _3 , _4 _4 , _5 _5 , _6 _6 , _7 _7 ) { return tuple ( _2 , _3 , _4 , _5 , _6 , _7 ) . cons ( _1 ) ; } | Static factory method for creating a 7 - element HList . |
29,838 | @ SuppressWarnings ( "JavaDoc" ) public static < _1 , _2 , _3 , _4 , _5 , _6 , _7 , _8 > Tuple8 < _1 , _2 , _3 , _4 , _5 , _6 , _7 , _8 > tuple ( _1 _1 , _2 _2 , _3 _3 , _4 _4 , _5 _5 , _6 _6 , _7 _7 , _8 _8 ) { return tuple ( _2 , _3 , _4 , _5 , _6 , _7 , _8 ) . cons ( _1 ) ; } | Static factory method for creating an 8 - element HList . |
29,839 | public static < A > Lazy < A > lazy ( Supplier < A > supplier ) { return new Later < > ( fn0 ( supplier ) ) ; } | Wrap a computation in a lazy computation . |
29,840 | public static < K , V > Lens . Simple < Map < K , V > , Map < K , V > > asCopy ( ) { return adapt ( asCopy ( HashMap :: new ) ) ; } | A lens that focuses on a copy of a Map . Useful for composition to avoid mutating a map reference . |
29,841 | public static < K , V > Lens . Simple < Map < K , V > , Set < K > > keys ( ) { return simpleLens ( m -> new HashSet < > ( m . keySet ( ) ) , ( m , ks ) -> { HashSet < K > ksCopy = new HashSet < > ( ks ) ; Map < K , V > updated = new HashMap < > ( m ) ; Set < K > keys = updated . keySet ( ) ; keys . retainAll ( ksCopy ) ; ksCopy . removeAll ( keys ) ; ksCopy . forEach ( k -> updated . put ( k , null ) ) ; return updated ; } ) ; } | A lens that focuses on the keys of a map . |
29,842 | @ SuppressWarnings ( "unchecked" ) public < A , B > Maybe < B > get ( TypeSafeKey < A , B > key ) { return maybe ( ( A ) table . get ( key ) ) . fmap ( view ( key ) ) ; } | Retrieve the value at this key . |
29,843 | public < V > HMap put ( TypeSafeKey < ? , V > key , V value ) { return alter ( t -> t . put ( key , view ( key . mirror ( ) , value ) ) ) ; } | Store a value for the given key . |
29,844 | public static < V > HMap singletonHMap ( TypeSafeKey < ? , V > key , V value ) { return emptyHMap ( ) . put ( key , value ) ; } | Static factory method for creating a singleton HMap . |
29,845 | public static < V1 , V2 > HMap hMap ( TypeSafeKey < ? , V1 > key1 , V1 value1 , TypeSafeKey < ? , V2 > key2 , V2 value2 ) { return singletonHMap ( key1 , value1 ) . put ( key2 , value2 ) ; } | Static factory method for creating an HMap from two given associations . |
29,846 | public static < V1 , V2 , V3 > HMap hMap ( TypeSafeKey < ? , V1 > key1 , V1 value1 , TypeSafeKey < ? , V2 > key2 , V2 value2 , TypeSafeKey < ? , V3 > key3 , V3 value3 ) { return hMap ( key1 , value1 , key2 , value2 ) . put ( key3 , value3 ) ; } | Static factory method for creating an HMap from three given associations . |
29,847 | public final Command createVerbosityCommand ( CountDownLatch latch , int level , boolean noreply ) { return new TextVerbosityCommand ( latch , level , noreply ) ; } | Create verbosity command |
29,848 | protected final int blockingRead ( ) throws ClosedChannelException , IOException { int n = 0 ; int readCount = 0 ; Selector readSelector = SelectorFactory . getSelector ( ) ; SelectionKey tmpKey = null ; try { if ( this . selectableChannel . isOpen ( ) ) { tmpKey = this . selectableChannel . register ( readSelector , 0 ) ; tmpKey . interestOps ( tmpKey . interestOps ( ) | SelectionKey . OP_READ ) ; int code = readSelector . select ( 500 ) ; tmpKey . interestOps ( tmpKey . interestOps ( ) & ~ SelectionKey . OP_READ ) ; if ( code > 0 ) { do { n = ( ( ReadableByteChannel ) this . selectableChannel ) . read ( this . readBuffer . buf ( ) ) ; readCount += n ; if ( log . isDebugEnabled ( ) ) { log . debug ( "use temp selector read " + n + " bytes" ) ; } } while ( n > 0 && this . readBuffer . hasRemaining ( ) ) ; if ( readCount > 0 ) { decodeAndDispatch ( ) ; } } } } finally { if ( tmpKey != null ) { tmpKey . cancel ( ) ; tmpKey = null ; } if ( readSelector != null ) { readSelector . selectNow ( ) ; SelectorFactory . returnSelector ( readSelector ) ; } } return readCount ; } | Blocking read using temp selector |
29,849 | protected byte [ ] encodeString ( String in ) { byte [ ] rv = null ; try { rv = in . getBytes ( this . charset ) ; } catch ( UnsupportedEncodingException e ) { throw new RuntimeException ( e ) ; } return rv ; } | Encode a string into the current character set . |
29,850 | @ SuppressWarnings ( "unchecked" ) public final Command optimiezeMergeBuffer ( Command optimiezeCommand , final Queue writeQueue , final Queue < Command > executingCmds , int sendBufferSize ) { if ( log . isDebugEnabled ( ) ) { log . debug ( "Optimieze merge buffer:" + optimiezeCommand . toString ( ) ) ; } if ( this . optimiezeMergeBuffer && optimiezeCommand . getIoBuffer ( ) . remaining ( ) < sendBufferSize - 24 ) { optimiezeCommand = this . mergeBuffer ( optimiezeCommand , writeQueue , executingCmds , sendBufferSize ) ; } return optimiezeCommand ; } | merge buffers to fit socket s send buffer size |
29,851 | @ SuppressWarnings ( "unchecked" ) public final Command optimiezeGet ( final Queue writeQueue , final Queue < Command > executingCmds , Command optimiezeCommand ) { if ( optimiezeCommand . getCommandType ( ) == CommandType . GET_ONE || optimiezeCommand . getCommandType ( ) == CommandType . GETS_ONE ) { if ( this . optimiezeGet ) { optimiezeCommand = this . mergeGetCommands ( optimiezeCommand , writeQueue , executingCmds , optimiezeCommand . getCommandType ( ) ) ; } } return optimiezeCommand ; } | Merge get operation to multi - get operation |
29,852 | public static AuthInfo plain ( String username , String password ) { return new AuthInfo ( new PlainCallbackHandler ( username , password ) , new String [ ] { "PLAIN" } ) ; } | Get a typical auth descriptor for PLAIN auth with the given username and password . |
29,853 | public static AuthInfo cramMD5 ( String username , String password ) { return new AuthInfo ( new PlainCallbackHandler ( username , password ) , new String [ ] { "CRAM-MD5" } ) ; } | Get a typical auth descriptor for CRAM - MD5 auth with the given username and password . |
29,854 | public AWSElasticCacheClient build ( ) throws IOException { AWSElasticCacheClient memcachedClient = new AWSElasticCacheClient ( this . sessionLocator , this . sessionComparator , this . bufferAllocator , this . configuration , this . socketOptions , this . commandFactory , this . transcoder , this . stateListeners , this . authInfoMap , this . connectionPoolSize , this . connectTimeout , this . name , this . failureMode , configAddrs , this . pollConfigIntervalMs ) ; this . configureClient ( memcachedClient ) ; return memcachedClient ; } | Returns a new instanceof AWSElasticCacheClient . |
29,855 | public static URL getResourceURL ( String resource ) throws IOException { URL url = null ; ClassLoader loader = ResourcesUtils . class . getClassLoader ( ) ; if ( loader != null ) { url = loader . getResource ( resource ) ; } if ( url == null ) { url = ClassLoader . getSystemResource ( resource ) ; } if ( url == null ) { throw new IOException ( "Could not find resource " + resource ) ; } return url ; } | Returns the URL of the resource on the classpath |
29,856 | public static InputStream getResourceAsStream ( String resource ) throws IOException { InputStream in = null ; ClassLoader loader = ResourcesUtils . class . getClassLoader ( ) ; if ( loader != null ) { in = loader . getResourceAsStream ( resource ) ; } if ( in == null ) { in = ClassLoader . getSystemResourceAsStream ( resource ) ; } if ( in == null ) { throw new IOException ( "Could not find resource " + resource ) ; } return in ; } | Returns a resource on the classpath as a Stream object |
29,857 | protected void initialSelectorManager ( ) throws IOException { if ( this . selectorManager == null ) { this . selectorManager = new SelectorManager ( this . selectorPoolSize , this , this . configuration ) ; this . selectorManager . start ( ) ; } } | Start selector manager |
29,858 | public void onRead ( SelectionKey key ) { if ( this . readEventDispatcher == null ) { dispatchReadEvent ( key ) ; } else { this . readEventDispatcher . dispatch ( new ReadTask ( key ) ) ; } } | Read event occured |
29,859 | public void onWrite ( final SelectionKey key ) { if ( this . writeEventDispatcher == null ) { dispatchWriteEvent ( key ) ; } else { this . writeEventDispatcher . dispatch ( new WriteTask ( key ) ) ; } } | Writable event occured |
29,860 | public void closeSelectionKey ( SelectionKey key ) { if ( key . attachment ( ) instanceof Session ) { Session session = ( Session ) key . attachment ( ) ; if ( session != null ) { session . close ( ) ; } } } | Cancel selection key |
29,861 | protected final NioSessionConfig buildSessionConfig ( SelectableChannel sc , Queue < WriteMessage > queue ) { final NioSessionConfig sessionConfig = new NioSessionConfig ( sc , getHandler ( ) , this . selectorManager , getCodecFactory ( ) , getStatistics ( ) , queue , this . dispatchMessageDispatcher , isHandleReadWriteConcurrently ( ) , this . sessionTimeout , this . configuration . getSessionIdleTimeout ( ) ) ; return sessionConfig ; } | Build nio session config |
29,862 | protected void readHeader ( ByteBuffer buffer ) { super . readHeader ( buffer ) ; if ( this . responseStatus != ResponseStatus . NO_ERROR ) { if ( ByteUtils . stepBuffer ( buffer , this . responseTotalBodyLength ) ) { this . decodeStatus = BinaryDecodeStatus . DONE ; } } } | optimistic if response status is greater than zero then skip buffer to next response set result as null |
29,863 | public ClusterConfigration getConfig ( String key ) throws MemcachedException , InterruptedException , TimeoutException { Command cmd = this . commandFactory . createAWSElasticCacheConfigCommand ( "get" , key ) ; final Session session = this . sendCommand ( cmd ) ; this . latchWait ( cmd , opTimeout , session ) ; cmd . getIoBuffer ( ) . free ( ) ; this . checkException ( cmd ) ; String result = ( String ) cmd . getResult ( ) ; if ( result == null ) { throw new MemcachedException ( "Operation fail,may be caused by networking or timeout" ) ; } return AWSUtils . parseConfiguration ( result ) ; } | Get config by key from cache node by network command . |
29,864 | public static final String nextLine ( ByteBuffer buffer ) { if ( buffer == null ) { return null ; } int index = MemcachedDecoder . SPLIT_MATCHER . matchFirst ( com . google . code . yanf4j . buffer . IoBuffer . wrap ( buffer ) ) ; if ( index >= 0 ) { int limit = buffer . limit ( ) ; buffer . limit ( index ) ; byte [ ] bytes = new byte [ buffer . remaining ( ) ] ; buffer . get ( bytes ) ; buffer . limit ( limit ) ; buffer . position ( index + ByteUtils . SPLIT . remaining ( ) ) ; return getString ( bytes ) ; } return null ; } | Read next line from ByteBuffer |
29,865 | protected final void configureSocketChannel ( SocketChannel sc ) throws IOException { sc . socket ( ) . setSoTimeout ( this . soTimeout ) ; sc . configureBlocking ( false ) ; if ( this . socketOptions . get ( StandardSocketOption . SO_REUSEADDR ) != null ) { sc . socket ( ) . setReuseAddress ( StandardSocketOption . SO_REUSEADDR . type ( ) . cast ( this . socketOptions . get ( StandardSocketOption . SO_REUSEADDR ) ) ) ; } if ( this . socketOptions . get ( StandardSocketOption . SO_SNDBUF ) != null ) { sc . socket ( ) . setSendBufferSize ( StandardSocketOption . SO_SNDBUF . type ( ) . cast ( this . socketOptions . get ( StandardSocketOption . SO_SNDBUF ) ) ) ; } if ( this . socketOptions . get ( StandardSocketOption . SO_KEEPALIVE ) != null ) { sc . socket ( ) . setKeepAlive ( StandardSocketOption . SO_KEEPALIVE . type ( ) . cast ( this . socketOptions . get ( StandardSocketOption . SO_KEEPALIVE ) ) ) ; } if ( this . socketOptions . get ( StandardSocketOption . SO_LINGER ) != null ) { sc . socket ( ) . setSoLinger ( this . soLingerOn , StandardSocketOption . SO_LINGER . type ( ) . cast ( this . socketOptions . get ( StandardSocketOption . SO_LINGER ) ) ) ; } if ( this . socketOptions . get ( StandardSocketOption . SO_RCVBUF ) != null ) { sc . socket ( ) . setReceiveBufferSize ( StandardSocketOption . SO_RCVBUF . type ( ) . cast ( this . socketOptions . get ( StandardSocketOption . SO_RCVBUF ) ) ) ; } if ( this . socketOptions . get ( StandardSocketOption . TCP_NODELAY ) != null ) { sc . socket ( ) . setTcpNoDelay ( StandardSocketOption . TCP_NODELAY . type ( ) . cast ( this . socketOptions . get ( StandardSocketOption . TCP_NODELAY ) ) ) ; } } | Confiure socket channel |
29,866 | protected void readHeader ( ByteBuffer buffer ) { super . readHeader ( buffer ) ; if ( this . responseStatus == ResponseStatus . NO_ERROR ) { this . decodeStatus = BinaryDecodeStatus . DONE ; } } | optimistic if no error goto done |
29,867 | public void bind ( InetSocketAddress inetSocketAddress ) throws IOException { if ( inetSocketAddress == null ) { throw new IllegalArgumentException ( "Null inetSocketAddress" ) ; } setLocalSocketAddress ( inetSocketAddress ) ; start ( ) ; } | Bind localhost address |
29,868 | public final void onMessageReceived ( final Session session , final Object msg ) { Command command = ( Command ) msg ; if ( this . statisticsHandler . isStatistics ( ) ) { if ( command . getCopiedMergeCount ( ) > 0 && command instanceof MapReturnValueAware ) { Map < String , CachedData > returnValues = ( ( MapReturnValueAware ) command ) . getReturnValues ( ) ; int size = returnValues . size ( ) ; this . statisticsHandler . statistics ( CommandType . GET_HIT , size ) ; this . statisticsHandler . statistics ( CommandType . GET_MISS , command . getCopiedMergeCount ( ) - size ) ; } else if ( command instanceof TextGetOneCommand || command instanceof BinaryGetCommand ) { if ( command . getResult ( ) != null ) { this . statisticsHandler . statistics ( CommandType . GET_HIT ) ; } else { this . statisticsHandler . statistics ( CommandType . GET_MISS ) ; } } else { if ( command . getCopiedMergeCount ( ) > 0 ) { this . statisticsHandler . statistics ( command . getCommandType ( ) , command . getCopiedMergeCount ( ) ) ; } else this . statisticsHandler . statistics ( command . getCommandType ( ) ) ; } } } | On receive message from memcached server |
29,869 | public void onSessionStarted ( Session session ) { session . setUseBlockingRead ( true ) ; session . setAttribute ( HEART_BEAT_FAIL_COUNT_ATTR , new AtomicInteger ( 0 ) ) ; for ( MemcachedClientStateListener listener : this . client . getStateListeners ( ) ) { listener . onConnected ( this . client , session . getRemoteSocketAddress ( ) ) ; } this . listener . onConnect ( ( MemcachedTCPSession ) session , this . client ) ; } | On session started |
29,870 | protected void reconnect ( MemcachedTCPSession session ) { if ( ! this . client . isShutdown ( ) ) { synchronized ( session ) { if ( ! session . isAllowReconnect ( ) ) { return ; } session . setAllowReconnect ( false ) ; } MemcachedSession memcachedTCPSession = session ; InetSocketAddressWrapper inetSocketAddressWrapper = memcachedTCPSession . getInetSocketAddressWrapper ( ) ; this . client . getConnector ( ) . addToWatingQueue ( new ReconnectRequest ( inetSocketAddressWrapper , 0 , this . client . getHealSessionInterval ( ) ) ) ; } } | Auto reconect to memcached server |
29,871 | public static void setAllocator ( IoBufferAllocator newAllocator ) { if ( newAllocator == null ) { throw new NullPointerException ( "allocator" ) ; } IoBufferAllocator oldAllocator = allocator ; allocator = newAllocator ; if ( null != oldAllocator ) { oldAllocator . dispose ( ) ; } } | Sets the allocator used by existing and new buffers |
29,872 | public static IoBuffer allocate ( int capacity , boolean direct ) { if ( capacity < 0 ) { throw new IllegalArgumentException ( "capacity: " + capacity ) ; } return allocator . allocate ( capacity , direct ) ; } | Returns the buffer which is capable of the specified size . |
29,873 | public static IoBuffer wrap ( byte [ ] byteArray , int offset , int length ) { return wrap ( ByteBuffer . wrap ( byteArray , offset , length ) ) ; } | Wraps the specified byte array into MINA heap buffer . |
29,874 | private boolean lookJVMBug ( long before , int selected , long wait ) throws IOException { boolean seeing = false ; long now = System . currentTimeMillis ( ) ; if ( JVMBUG_THRESHHOLD > 0 && selected == 0 && wait > JVMBUG_THRESHHOLD && now - before < wait / 4 && ! wakenUp . get ( ) && ! Thread . currentThread ( ) . isInterrupted ( ) ) { jvmBug . incrementAndGet ( ) ; if ( jvmBug . get ( ) >= JVMBUG_THRESHHOLD2 ) { gate . lock ( ) ; try { lastJVMBug = now ; log . warn ( "JVM bug occured at " + new Date ( lastJVMBug ) + ",http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6403933,reactIndex=" + reactorIndex ) ; if ( jvmBug1 ) { log . debug ( "seeing JVM BUG(s) - recreating selector,reactIndex=" + reactorIndex ) ; } else { jvmBug1 = true ; log . info ( "seeing JVM BUG(s) - recreating selector,reactIndex=" + reactorIndex ) ; } seeing = true ; final Selector new_selector = SystemUtils . openSelector ( ) ; for ( SelectionKey k : selector . keys ( ) ) { if ( ! k . isValid ( ) || k . interestOps ( ) == 0 ) { continue ; } final SelectableChannel channel = k . channel ( ) ; final Object attachment = k . attachment ( ) ; channel . register ( new_selector , k . interestOps ( ) , attachment ) ; } selector . close ( ) ; selector = new_selector ; } finally { gate . unlock ( ) ; } jvmBug . set ( 0 ) ; } else if ( jvmBug . get ( ) == JVMBUG_THRESHHOLD || jvmBug . get ( ) == JVMBUG_THRESHHOLD1 ) { if ( jvmBug0 ) { log . debug ( "seeing JVM BUG(s) - cancelling interestOps==0,reactIndex=" + reactorIndex ) ; } else { jvmBug0 = true ; log . info ( "seeing JVM BUG(s) - cancelling interestOps==0,reactIndex=" + reactorIndex ) ; } gate . lock ( ) ; seeing = true ; try { for ( SelectionKey k : selector . keys ( ) ) { if ( k . isValid ( ) && k . interestOps ( ) == 0 ) { k . cancel ( ) ; } } } finally { gate . unlock ( ) ; } } } else { jvmBug . set ( 0 ) ; } return seeing ; } | Look jvm bug |
29,875 | public final void dispatchEvent ( Set < SelectionKey > selectedKeySet ) { Iterator < SelectionKey > it = selectedKeySet . iterator ( ) ; boolean skipOpRead = false ; while ( it . hasNext ( ) ) { SelectionKey key = it . next ( ) ; it . remove ( ) ; if ( ! key . isValid ( ) ) { if ( key . attachment ( ) != null ) { controller . closeSelectionKey ( key ) ; } else { key . cancel ( ) ; } continue ; } try { if ( key . isValid ( ) && key . isAcceptable ( ) ) { controller . onAccept ( key ) ; continue ; } if ( key . isValid ( ) && ( key . readyOps ( ) & SelectionKey . OP_WRITE ) == SelectionKey . OP_WRITE ) { key . interestOps ( key . interestOps ( ) & ~ SelectionKey . OP_WRITE ) ; controller . onWrite ( key ) ; if ( ! controller . isHandleReadWriteConcurrently ( ) ) { skipOpRead = true ; } } if ( ! skipOpRead && key . isValid ( ) && ( key . readyOps ( ) & SelectionKey . OP_READ ) == SelectionKey . OP_READ ) { key . interestOps ( key . interestOps ( ) & ~ SelectionKey . OP_READ ) ; if ( ! controller . getStatistics ( ) . isReceiveOverFlow ( ) ) { controller . onRead ( key ) ; } else { key . interestOps ( key . interestOps ( ) | SelectionKey . OP_READ ) ; } } if ( ( key . readyOps ( ) & SelectionKey . OP_CONNECT ) == SelectionKey . OP_CONNECT ) { controller . onConnect ( key ) ; } } catch ( CancelledKeyException e ) { } catch ( RejectedExecutionException e ) { if ( key . attachment ( ) instanceof AbstractNioSession ) { ( ( AbstractNioSession ) key . attachment ( ) ) . onException ( e ) ; } controller . notifyException ( e ) ; if ( selector . isOpen ( ) ) { continue ; } else { break ; } } catch ( Exception e ) { if ( key . attachment ( ) instanceof AbstractNioSession ) { ( ( AbstractNioSession ) key . attachment ( ) ) . onException ( e ) ; } controller . closeSelectionKey ( key ) ; controller . notifyException ( e ) ; log . error ( "Reactor dispatch events error" , e ) ; if ( selector . isOpen ( ) ) { continue ; } else { break ; } } } } | Dispatch selected event |
29,876 | public final void addServer ( final String server , final int port , int weight ) throws IOException { if ( weight <= 0 ) { throw new IllegalArgumentException ( "weight<=0" ) ; } this . checkServerPort ( server , port ) ; this . connect ( new InetSocketAddressWrapper ( this . newSocketAddress ( server , port ) , this . serverOrderCount . incrementAndGet ( ) , weight , null ) ) ; } | add a memcached server to MemcachedClient |
29,877 | private final Collection < List < String > > catalogKeys ( final Collection < String > keyCollections ) { final Map < Session , List < String > > catalogMap = new HashMap < Session , List < String > > ( ) ; for ( String key : keyCollections ) { Session index = this . sessionLocator . getSessionByKey ( key ) ; List < String > tmpKeys = catalogMap . get ( index ) ; if ( tmpKeys == null ) { tmpKeys = new ArrayList < String > ( 10 ) ; catalogMap . put ( index , tmpKeys ) ; } tmpKeys . add ( key ) ; } Collection < List < String > > catalogKeys = catalogMap . values ( ) ; return catalogKeys ; } | Hash key to servers |
29,878 | public final void deleteWithNoReply ( final String key , final int time ) throws InterruptedException , MemcachedException { try { this . delete0 ( key , time , 0 , true , this . opTimeout ) ; } catch ( TimeoutException e ) { throw new MemcachedException ( e ) ; } } | Delete key s data item from memcached . This method doesn t wait for reply |
29,879 | public String getNamespace ( String ns ) throws TimeoutException , InterruptedException , MemcachedException { String key = this . keyProvider . process ( this . getNSKey ( ns ) ) ; byte [ ] keyBytes = ByteUtils . getBytes ( key ) ; ByteUtils . checkKey ( keyBytes ) ; Object item = this . fetch0 ( key , keyBytes , CommandType . GET_ONE , this . opTimeout , this . transcoder ) ; while ( item == null ) { item = String . valueOf ( System . nanoTime ( ) ) ; boolean added = this . add0 ( key , 0 , item , this . transcoder , this . opTimeout ) ; if ( ! added ) { item = this . fetch0 ( key , keyBytes , CommandType . GET_ONE , this . opTimeout , this . transcoder ) ; } } String namespace = item . toString ( ) ; if ( ! ByteUtils . isNumber ( namespace ) ) { throw new IllegalStateException ( "Namespace key already has value.The key is:" + key + ",and the value is:" + namespace ) ; } return namespace ; } | Returns the real namespace of ns . |
29,880 | public final static void setMaxSelectors ( int size ) throws IOException { synchronized ( selectors ) { if ( size < maxSelectors ) { reduce ( size ) ; } else if ( size > maxSelectors ) { grow ( size ) ; } maxSelectors = size ; } } | Set max selector pool size . |
29,881 | private boolean advanceHead ( QNode h , QNode nh ) { if ( h == this . head . get ( ) && this . head . compareAndSet ( h , nh ) ) { h . next = h ; return true ; } return false ; } | Tries to cas nh as new head ; if successful unlink old head s next node to avoid garbage retention . |
29,882 | private QNode getValidatedTail ( ) { for ( ; ; ) { QNode h = this . head . get ( ) ; QNode first = h . next ; if ( first != null && first . next == first ) { advanceHead ( h , first ) ; continue ; } QNode t = this . tail . get ( ) ; QNode last = t . next ; if ( t == this . tail . get ( ) ) { if ( last != null ) { this . tail . compareAndSet ( t , last ) ; } else { return t ; } } } } | Returns validated tail for use in cleaning methods |
29,883 | QNode traversalHead ( ) { for ( ; ; ) { QNode t = this . tail . get ( ) ; QNode h = this . head . get ( ) ; if ( h != null && t != null ) { QNode last = t . next ; QNode first = h . next ; if ( t == this . tail . get ( ) ) { if ( last != null ) { this . tail . compareAndSet ( t , last ) ; } else if ( first != null ) { Object x = first . get ( ) ; if ( x == first ) { advanceHead ( h , first ) ; } else { return h ; } } else { return h ; } } } } } | Return head after performing any outstanding helping steps |
29,884 | public static ClusterConfigration parseConfiguration ( String line ) { String [ ] lines = line . trim ( ) . split ( "(?:\\r?\\n)" ) ; if ( lines . length < 2 ) { throw new IllegalArgumentException ( "Incorrect config response:" + line ) ; } String configversion = lines [ 0 ] ; String nodeListStr = lines [ 1 ] ; if ( ! ByteUtils . isNumber ( configversion ) ) { throw new IllegalArgumentException ( "Invalid configversion: " + configversion + ", it should be a number." ) ; } String [ ] nodeStrs = nodeListStr . split ( "(?:\\s)+" ) ; int version = Integer . parseInt ( configversion ) ; List < CacheNode > nodeList = new ArrayList < CacheNode > ( nodeStrs . length ) ; for ( String nodeStr : nodeStrs ) { if ( nodeStr . equals ( "" ) ) { continue ; } int firstDelimiter = nodeStr . indexOf ( DELIMITER ) ; int secondDelimiter = nodeStr . lastIndexOf ( DELIMITER ) ; if ( firstDelimiter < 1 || firstDelimiter == secondDelimiter ) { throw new IllegalArgumentException ( "Invalid server ''" + nodeStr + "'' in response: " + line ) ; } String hostName = nodeStr . substring ( 0 , firstDelimiter ) . trim ( ) ; String ipAddress = nodeStr . substring ( firstDelimiter + 1 , secondDelimiter ) . trim ( ) ; String portNum = nodeStr . substring ( secondDelimiter + 1 ) . trim ( ) ; int port = Integer . parseInt ( portNum ) ; nodeList . add ( new CacheNode ( hostName , ipAddress , port ) ) ; } return new ClusterConfigration ( version , nodeList ) ; } | Parse response string to ClusterConfiguration instance . |
29,885 | public long get ( ) throws MemcachedException , InterruptedException , TimeoutException { Object result = this . memcachedClient . get ( this . key ) ; if ( result == null ) { throw new MemcachedClientException ( "key is not existed." ) ; } else { if ( result instanceof Long ) return ( Long ) result ; else return Long . valueOf ( ( ( String ) result ) . trim ( ) ) ; } } | Get current value |
29,886 | public void set ( long value ) throws MemcachedException , InterruptedException , TimeoutException { this . memcachedClient . set ( this . key , 0 , String . valueOf ( value ) ) ; } | Set counter s value to expected . |
29,887 | public long addAndGet ( long delta ) throws MemcachedException , InterruptedException , TimeoutException { if ( delta >= 0 ) { return this . memcachedClient . incr ( this . key , delta , this . initialValue ) ; } else { return this . memcachedClient . decr ( this . key , - delta , this . initialValue ) ; } } | Add value and get the result |
29,888 | public static char [ ] getAllowedFunctionCharacters ( ) { char [ ] chars = new char [ 53 ] ; int count = 0 ; for ( int i = 65 ; i < 91 ; i ++ ) { chars [ count ++ ] = ( char ) i ; } for ( int i = 97 ; i < 123 ; i ++ ) { chars [ count ++ ] = ( char ) i ; } chars [ count ] = '_' ; return chars ; } | Get the set of characters which are allowed for use in Function names . |
29,889 | public static Function getBuiltinFunction ( final String name ) { if ( name . equals ( "sin" ) ) { return builtinFunctions [ INDEX_SIN ] ; } else if ( name . equals ( "cos" ) ) { return builtinFunctions [ INDEX_COS ] ; } else if ( name . equals ( "tan" ) ) { return builtinFunctions [ INDEX_TAN ] ; } else if ( name . equals ( "cot" ) ) { return builtinFunctions [ INDEX_COT ] ; } else if ( name . equals ( "asin" ) ) { return builtinFunctions [ INDEX_ASIN ] ; } else if ( name . equals ( "acos" ) ) { return builtinFunctions [ INDEX_ACOS ] ; } else if ( name . equals ( "atan" ) ) { return builtinFunctions [ INDEX_ATAN ] ; } else if ( name . equals ( "sinh" ) ) { return builtinFunctions [ INDEX_SINH ] ; } else if ( name . equals ( "cosh" ) ) { return builtinFunctions [ INDEX_COSH ] ; } else if ( name . equals ( "tanh" ) ) { return builtinFunctions [ INDEX_TANH ] ; } else if ( name . equals ( "abs" ) ) { return builtinFunctions [ INDEX_ABS ] ; } else if ( name . equals ( "log" ) ) { return builtinFunctions [ INDEX_LOG ] ; } else if ( name . equals ( "log10" ) ) { return builtinFunctions [ INDEX_LOG10 ] ; } else if ( name . equals ( "log2" ) ) { return builtinFunctions [ INDEX_LOG2 ] ; } else if ( name . equals ( "log1p" ) ) { return builtinFunctions [ INDEX_LOG1P ] ; } else if ( name . equals ( "ceil" ) ) { return builtinFunctions [ INDEX_CEIL ] ; } else if ( name . equals ( "floor" ) ) { return builtinFunctions [ INDEX_FLOOR ] ; } else if ( name . equals ( "sqrt" ) ) { return builtinFunctions [ INDEX_SQRT ] ; } else if ( name . equals ( "cbrt" ) ) { return builtinFunctions [ INDEX_CBRT ] ; } else if ( name . equals ( "pow" ) ) { return builtinFunctions [ INDEX_POW ] ; } else if ( name . equals ( "exp" ) ) { return builtinFunctions [ INDEX_EXP ] ; } else if ( name . equals ( "expm1" ) ) { return builtinFunctions [ INDEX_EXPM1 ] ; } else if ( name . equals ( "signum" ) ) { return builtinFunctions [ INDEX_SGN ] ; } else { return null ; } } | Get the builtin function for a given name |
29,890 | public static List < Boolean > unmodifiableView ( boolean [ ] array , int length ) { return Collections . unmodifiableList ( view ( array , length ) ) ; } | Creates an returns an unmodifiable view of the given boolean array that requires only a small object allocation . |
29,891 | public static BooleanList view ( boolean [ ] array , int length ) { if ( length > array . length || length < 0 ) throw new IllegalArgumentException ( "length must be non-negative and no more than the size of the array(" + array . length + "), not " + length ) ; return new BooleanList ( array , length ) ; } | Creates and returns a view of the given boolean array that requires only a small object allocation . Changes to the list will be reflected in the array up to a point . If the modification would require increasing the capacity of the array a new array will be allocated - at which point operations will no longer be reflected in the original array . |
29,892 | public void setMomentum ( double momentum ) { if ( momentum < 0 || Double . isNaN ( momentum ) || Double . isInfinite ( momentum ) ) throw new ArithmeticException ( "Momentum must be non negative, not " + momentum ) ; this . momentum = momentum ; } | Sets the non negative momentum used in training . |
29,893 | public void setWeightDecay ( double weightDecay ) { if ( weightDecay < 0 || weightDecay >= 1 || Double . isNaN ( weightDecay ) ) throw new ArithmeticException ( "Weight decay must be in [0,1), not " + weightDecay ) ; this . weightDecay = weightDecay ; } | Sets the weight decay used for each update . The weight decay must be in the range [ 0 1 ) . Weight decay values must often be very small often 1e - 8 or less . |
29,894 | private void setUp ( Random rand ) { Ws = new ArrayList < > ( npl . length ) ; bs = new ArrayList < > ( npl . length ) ; DenseMatrix W = new DenseMatrix ( npl [ 0 ] , inputSize ) ; Vec b = new DenseVector ( W . rows ( ) ) ; initializeWeights ( W , rand ) ; initializeWeights ( b , W . cols ( ) , rand ) ; Ws . add ( W ) ; bs . add ( b ) ; for ( int i = 1 ; i < npl . length ; i ++ ) { W = new DenseMatrix ( npl [ i ] , npl [ i - 1 ] ) ; b = new DenseVector ( W . rows ( ) ) ; initializeWeights ( W , rand ) ; initializeWeights ( b , W . cols ( ) , rand ) ; Ws . add ( W ) ; bs . add ( b ) ; } W = new DenseMatrix ( outputSize , npl [ npl . length - 1 ] ) ; b = new DenseVector ( W . rows ( ) ) ; initializeWeights ( W , rand ) ; initializeWeights ( b , W . cols ( ) , rand ) ; Ws . add ( W ) ; bs . add ( b ) ; } | Creates the weights for the hidden layers and output layer |
29,895 | private double computeOutputDelta ( DataSet dataSet , final int idx , Vec delta_out , Vec a_i , Vec d_i ) { double error = 0 ; if ( dataSet instanceof ClassificationDataSet ) { ClassificationDataSet cds = ( ClassificationDataSet ) dataSet ; final int ct = cds . getDataPointCategory ( idx ) ; for ( int i = 0 ; i < outputSize ; i ++ ) if ( i == ct ) delta_out . set ( i , f . max ( ) - targetBump ) ; else delta_out . set ( i , f . min ( ) + targetBump ) ; for ( int j = 0 ; j < delta_out . length ( ) ; j ++ ) { double val = delta_out . get ( j ) ; error += pow ( ( val - a_i . get ( j ) ) , 2 ) ; val = - ( val - a_i . get ( j ) ) * d_i . get ( j ) ; delta_out . set ( j , val ) ; } } else if ( dataSet instanceof RegressionDataSet ) { RegressionDataSet rds = ( RegressionDataSet ) dataSet ; double val = rds . getTargetValue ( idx ) ; val = f . min ( ) + targetBump + targetMultiplier * ( val - targetMin ) ; error += pow ( ( val - a_i . get ( 0 ) ) , 2 ) ; delta_out . set ( 0 , - ( val - a_i . get ( 0 ) ) * d_i . get ( 0 ) ) ; } else { throw new RuntimeException ( "BUG: please report" ) ; } return error ; } | Computes the delta between the networks output for a same and its true value |
29,896 | private void feedForward ( Vec input , List < Vec > activations , List < Vec > derivatives ) { Vec x = input ; for ( int i = 0 ; i < Ws . size ( ) ; i ++ ) { Matrix W_i = Ws . get ( i ) ; Vec b_i = bs . get ( i ) ; Vec a_i = activations . get ( i ) ; a_i . zeroOut ( ) ; W_i . multiply ( x , 1 , a_i ) ; a_i . mutableAdd ( b_i ) ; a_i . applyFunction ( f ) ; Vec d_i = derivatives . get ( i ) ; a_i . copyTo ( d_i ) ; d_i . applyFunction ( f . getD ( ) ) ; x = a_i ; } } | Feeds a vector through the network to get an output |
29,897 | private Vec feedForward ( Vec input ) { Vec x = input ; for ( int i = 0 ; i < Ws . size ( ) ; i ++ ) { Matrix W_i = Ws . get ( i ) ; Vec b_i = bs . get ( i ) ; Vec a_i = W_i . multiply ( x ) ; a_i . mutableAdd ( b_i ) ; a_i . applyFunction ( f ) ; x = a_i ; } return x ; } | Feeds an input through the network |
29,898 | public void setRegularization ( double regularization ) { if ( Double . isNaN ( regularization ) || Double . isInfinite ( regularization ) || regularization <= 0 ) throw new ArithmeticException ( "Regularization must be a positive constant, not " + regularization ) ; this . regularization = regularization ; } | Sets the amount of regularization to apply . The regularization must be a positive value |
29,899 | public void sortByEigenValue ( Comparator < Double > cmp ) { if ( isComplex ( ) ) throw new ArithmeticException ( "Eigen values can not be sorted due to complex results" ) ; IndexTable it = new IndexTable ( DoubleList . unmodifiableView ( d , d . length ) , cmp ) ; for ( int i = 0 ; i < d . length ; i ++ ) { RowColumnOps . swapCol ( V , i , it . index ( i ) ) ; double tmp = d [ i ] ; d [ i ] = d [ it . index ( i ) ] ; d [ it . index ( i ) ] = tmp ; it . swap ( i , it . index ( i ) ) ; } } | Sorts the eigen values and the corresponding eigenvector columns by the associated eigen value . Sorting can not occur if complex values are present . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.