/** * Initialize a compression descriptor * based on the given data buffer (for the sizes) * and the compressor to get the opType * @param buffer * @param compressor */ public CompressionDescriptor(DataBuffer buffer, NDArrayCompressor compressor) { this(buffer, compressor.getDescriptor()); this.compressionType = compressor.getCompressionType(); }
protected void loadCompressors() { /* We scan classpath for NDArrayCompressor implementations and add them one by one to codecs map */ codecs = new ConcurrentHashMap<>(); ServiceLoader<NDArrayCompressor> loader = ServiceLoader.load(NDArrayCompressor.class); for (NDArrayCompressor compressor : loader) { codecs.put(compressor.getDescriptor().toUpperCase(), compressor); } if(codecs.isEmpty()){ //No compressors found - bad uber-jar? String msg = "Error loading ND4J Compressors via service loader: No compressors were found. This usually occurs" + " when running ND4J UI from an uber-jar, which was built incorrectly (without services resource" + " files being included)"; log.error(msg); throw new RuntimeException(msg); } }
/** * Initialize a compression descriptor * based on the given data buffer (for the sizes) * and the compressor to get the type * @param buffer * @param compressor */ public CompressionDescriptor(DataBuffer buffer, NDArrayCompressor compressor) { this(buffer, compressor.getDescriptor()); this.compressionType = compressor.getCompressionType(); }
protected void loadCompressors() { /* We scan classpath for NDArrayCompressor implementations and add them one by one to codecs map */ codecs = new ConcurrentHashMap<>(); Set<Class<? extends NDArrayCompressor>> classes = new Reflections(new ConfigurationBuilder() .filterInputsBy(new FilterBuilder().include(FilterBuilder.prefix("org.nd4j")) .exclude("^(?!.*\\.class$).*$")) //Consider only .class files (to avoid debug messages etc. on .dlls, etc .setUrls(ClasspathHelper.forPackage("org.nd4j")).setScanners(new SubTypesScanner())) .getSubTypesOf(NDArrayCompressor.class); for (Class<? extends NDArrayCompressor> impl : classes) { if (Modifier.isAbstract(impl.getModifiers()) || impl.isInterface()) continue; try { NDArrayCompressor compressor = impl.newInstance(); codecs.put(compressor.getDescriptor().toUpperCase(), compressor); } catch (InstantiationException i) { ; // we need catch there, to avoid exceptions at abstract classes } catch (Exception e) { throw new RuntimeException(e); } } }