build_pln_header.py 1.0 KB

1234567891011121314151617181920212223242526272829303132333435
  1. #!/usr/bin/env python
  2. import sys
  3. import os
  4. def BuildPlnHeader():
  5. if len(sys.argv) < 2:
  6. print >>sys.stderr, "Usage: build_pln_header.py <absolute/path/to/OutFile>"
  7. sys.exit(1)
  8. print >>sys.stdout, "Build Pln Header..."
  9. outPath = sys.argv[1]
  10. tmpPath = outPath + '.tmp'
  11. tmpFile = open(tmpPath, 'w')
  12. tmpFile.write('#include <library/cpp/sse/sse.h>\n')
  13. tmpFile.write('#include <kernel/relevfml/relev_fml.h>\n')
  14. for path in sys.argv[2:]:
  15. name = os.path.basename(path).split(".")[0] # name without extensions
  16. tmpFile.write('\nextern SRelevanceFormula fml{0};\n'.format(name))
  17. tmpFile.write('float {0}(const float* f);\n'.format(name))
  18. tmpFile.write('void {0}SSE(const float* const* factors, float* result);\n'.format(name))
  19. tmpFile.close()
  20. try:
  21. os.remove(outPath)
  22. except:
  23. pass
  24. try:
  25. os.rename(tmpPath, outPath)
  26. except:
  27. print >>sys.stdout, 'Error: Failed to rename ' + tmpPath + ' to ' + outPath
  28. if __name__ == '__main__':
  29. BuildPlnHeader()