Beispiel #1
0
// Get a slice with class labels
func (model *Model) labels() []int {
	nClasses := C.get_nr_class_wrap(model.model)
	cLabels := newLabels(nClasses)
	defer C.free(unsafe.Pointer(cLabels))
	C.get_labels_wrap(model.model, cLabels)

	labels := make([]int, int(nClasses))

	for idx, _ := range labels {
		labels[idx] = int(C.get_int_idx(cLabels, C.int(idx)))
	}

	return labels
}
Beispiel #2
0
// Labels returns a slice with class labels.
func (model *Model) Labels() []int {
	if model.labelCache != nil {
		labels := make([]int, len(model.labelCache))
		copy(labels, model.labelCache)
		return labels
	}

	nClasses := C.get_nr_class_wrap(model.model)
	cLabels := newLabels(nClasses)
	defer C.free(unsafe.Pointer(cLabels))
	C.get_labels_wrap(model.model, cLabels)

	labels := make([]int, int(nClasses))

	for idx := range labels {
		labels[idx] = int(C.get_int_idx(cLabels, C.int(idx)))
	}

	model.labelCache = make([]int, len(labels))
	copy(model.labelCache, labels)

	return labels
}