org.bytedeco.javacpp.CharPointer Java Examples

The following examples show how to use org.bytedeco.javacpp.CharPointer. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FtModel.java    From djl with Apache License 2.0 6 votes vote down vote up
/**
 * Train the fastText model.
 *
 * @param config the training configuration to use
 * @param trainingSet the training dataset
 * @param validateSet the validation dataset
 * @return the result of the training
 * @throws IOException when IO operation fails in loading a resource
 */
public TrainingResult fit(FtTrainingConfig config, FtDataset trainingSet, FtDataset validateSet)
        throws IOException {
    Path outputDir = config.getOutputDir();
    if (Files.notExists(outputDir)) {
        Files.createDirectory(outputDir);
    }
    String fitModelName = config.getModelName();
    Path modelFile = outputDir.resolve(fitModelName).toAbsolutePath();

    String[] args = config.toCommand(trainingSet.getInputFile().toString());

    fta.runCmd(args.length, new PointerPointer<CharPointer>(args));
    setModelFile(modelFile);

    TrainingResult result = new TrainingResult();
    int epoch = config.getEpoch();
    if (epoch <= 0) {
        epoch = 5;
    }
    result.setEpoch(epoch);
    return result;
}
 
Example #2
Source File: CharIndexer.java    From tapir with MIT License 6 votes vote down vote up
/**
 * Creates a char indexer to access efficiently the data of a pointer.
 *
 * @param pointer data to access via a buffer or to copy to an array
 * @param direct {@code true} to use a direct buffer, see {@link Indexer} for details
 * @return the new char array backed by a buffer or an array
 */
public static CharIndexer create(final CharPointer pointer, int[] sizes, int[] strides, boolean direct) {
    if (direct) {
        return new CharBufferIndexer(pointer.asBuffer(), sizes, strides);
    } else {
        final int position = pointer.position();
        char[] array = new char[pointer.limit() - position];
        pointer.get(array);
        return new CharArrayIndexer(array, sizes, strides) {
            @Override public void release() {
                pointer.position(position).put(array);
                super.release();
            }
        };
    }
}
 
Example #3
Source File: OnnxModelLoader.java    From konduit-serving with Apache License 2.0 5 votes vote down vote up
@Override
public Session loadModel() throws Exception {
    Env env = new Env(ORT_LOGGING_LEVEL_WARNING, new BytePointer("konduit-serving-onnx-session" + System.currentTimeMillis()));

    try (SessionOptions sessionOptions = new SessionOptions()) {
        try (Pointer bp = Loader.getPlatform().toLowerCase().startsWith("windows") ? new CharPointer(modelPath) : new BytePointer(modelPath)) {
            return new Session(env, bp, sessionOptions);
        }
    }
}
 
Example #4
Source File: Generator.java    From tapir with MIT License 4 votes vote down vote up
String[] cppTypeName(Class<?> type) {
    String prefix = "", suffix = "";
    if (type == Buffer.class || type == Pointer.class) {
        prefix = "void*";
    } else if (type == byte[].class || type == ByteBuffer.class || type == BytePointer.class) {
        prefix = "signed char*";
    } else if (type == short[].class || type == ShortBuffer.class || type == ShortPointer.class) {
        prefix = "short*";
    } else if (type == int[].class || type == IntBuffer.class || type == IntPointer.class) {
        prefix = "int*";
    } else if (type == long[].class || type == LongBuffer.class || type == LongPointer.class) {
        prefix = "jlong*";
    } else if (type == float[].class || type == FloatBuffer.class || type == FloatPointer.class) {
        prefix = "float*";
    } else if (type == double[].class || type == DoubleBuffer.class || type == DoublePointer.class) {
        prefix = "double*";
    } else if (type == char[].class || type == CharBuffer.class || type == CharPointer.class) {
        prefix = "unsigned short*";
    } else if (type == boolean[].class) {
        prefix = "unsigned char*";
    } else if (type == PointerPointer.class) {
        prefix = "void**";
    } else if (type == String.class) {
        prefix = "const char*";
    } else if (type == byte.class) {
        prefix = "signed char";
    } else if (type == long.class) {
        prefix = "jlong";
    } else if (type == char.class) {
        prefix = "unsigned short";
    } else if (type == boolean.class) {
        prefix = "unsigned char";
    } else if (type.isPrimitive()) {
        prefix = type.getName();
    } else if (FunctionPointer.class.isAssignableFrom(type)) {
        Method functionMethod = functionMethod(type, null);
        if (functionMethod != null) {
            return cppFunctionTypeName(functionMethod);
        }
    } else {
        String scopedType = cppScopeName(type);
        if (scopedType.length() > 0) {
            prefix = scopedType + "*";
        } else {
            logger.warn("The class " + type.getCanonicalName() +
                    " does not map to any C++ type. Compilation will most likely fail.");
        }
    }
    return new String[] { prefix, suffix };
}
 
Example #5
Source File: CharIndexer.java    From tapir with MIT License 4 votes vote down vote up
/** @return {@code create(pointer, sizes, strides, true)} */
public static CharIndexer create(CharPointer pointer, int[] sizes, int[] strides) {
    return create(pointer, sizes, strides, true);
}