forked from shogun-toolbox/shogun
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
100 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# Generate automatic shogun-base.i from jinja2 templates | ||
if(SYSTEM_INCLUDES) | ||
INCLUDE_DIRECTORIES(SYSTEM ${SYSTEM_INCLUDES}) | ||
endif() | ||
include_directories(${source_dir}/include ${INCLUDES} ${CMAKE_CURRENT_SOURCE_DIR}) | ||
|
||
# Generate automatic shogun-base.i from jinja2 templates | ||
ADD_CUSTOM_COMMAND(OUTPUT shogun-base.i | ||
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/shogun-base.i.py | ||
${CMAKE_CURRENT_SOURCE_DIR}/shogun-base.i.jinja2 | ||
shogun-base.i | ||
${CMAKE_CURRENT_SOURCE_DIR}/shogun-base-list.txt | ||
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/shogun-base.i.py | ||
${CMAKE_CURRENT_SOURCE_DIR}/shogun-base.i.jinja2 | ||
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} | ||
COMMENT "Generating shogun-base.i") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
\\ Contains list of shogun base classes. The list format is | ||
\\ "'CLASS/TEMPLATE', 'new name for class/template', 'name of class/template in c++'", | ||
|
||
CLASS, String, std::string | ||
CLASS, Int, int32_t | ||
CLASS, Float, float64_t | ||
CLASS, Kernel, CKernel | ||
CLASS, Machine, CMachine | ||
CLASS, Labels, CLabels | ||
CLASS, Features, CFeatures | ||
TEMPLATE, DenseFeatures, CDenseFeatures |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/* | ||
* THIS IS A GENERATED FILE! DO NOT CHANGE THIS FILE! CHANGE THE | ||
* CORRESPONDING TEMPLATE FILE, PLEASE! | ||
*/ | ||
|
||
using namespace shogun; | ||
|
||
{% for class in classes %} | ||
{% if class[0] == 'CLASS' %} | ||
%template(Tag{{class[1]}}) Tag<{{class[2]}}>; | ||
%template(set) CSGObject::set<{{class[2]}}>; | ||
%template(set{{class[1]}}) CSGObject::set<{{class[2]}}, void>; | ||
%template(get) CSGObject::get<{{class[2]}}>; | ||
%template(get{{class[1]}}) CSGObject::get<{{class[2]}}, void>; | ||
%template(has) CSGObject::has<{{class[2]}}>; | ||
%template(has{{class[1]}}) CSGObject::has<{{class[2]}}, void>; | ||
|
||
{% else %} | ||
// TODO: TEMPLATE | ||
{% endif %} | ||
{% endfor %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#!/usr/bin/env python | ||
|
||
# This program is free software; you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation; either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# Written (W) 2016 Sanuj Sharma | ||
|
||
def entry(templateFile, class_list_file): | ||
templateLoader = jinja2.FileSystemLoader(searchpath="/") | ||
templateEnv = jinja2.Environment(loader=templateLoader) | ||
|
||
template = templateEnv.get_template(templateFile) | ||
|
||
classes = [] | ||
with open(class_list_file) as f: | ||
for line in f: | ||
if line[0] is 'C' or line[0] is 'T': | ||
temp = [elt.strip() for elt in line.split(',')] | ||
classes.append(temp) | ||
|
||
|
||
types = ['PT_BOOL', 'PT_CHAR', 'PT_INT8', 'PT_UINT8', 'PT_INT16', 'PT_UINT16', 'PT_INT32', | ||
'PT_UINT32', 'PT_INT64', 'PT_UINT64', 'PT_FLOAT32', 'PT_FLOAT64', 'PT_FLOATMAX'] | ||
|
||
templateVars = {"classes" : classes, "types" : types} | ||
|
||
return template.render(templateVars) | ||
|
||
# execution | ||
# ./shogun-base.i.py <template file> <output file name> <extra args...> | ||
|
||
import sys | ||
TEMPLATE_FILE = sys.argv[1] | ||
output_file = sys.argv[2] | ||
class_list_file = sys.argv[3] | ||
|
||
try: | ||
import jinja2 | ||
outputText = entry(TEMPLATE_FILE, class_list_file) | ||
except ImportError: | ||
import os | ||
basename = os.path.basename(output_file) | ||
basename = basename.replace('.cc', '') | ||
print("Please install jinja2 for shogun-base.i"); | ||
outputText = ['Please install jinja2 to auto-generate content for this file.'] | ||
|
||
f = open(output_file, 'w') | ||
f.writelines(outputText) | ||
f.close() |