5. Writing Optimized Compiled Code With Sage

This chapter is about how to write fast compiled optimized code for Sage. It was written mainly by William Stein with contributions from David Harvey, Martin Albrecht, David Joyner, Alex Clemesha. Some of the text is closely copied or translated (to mathematical language) from Greg Ewing's original Pyrex manual.

This chapter assumes that you have a C compiler suite (e.g., GCC) installed on your computer, since you should not write compiled extension code on a computer without a C compiler. If you are using OS X, download and install the latest version of XCode.5.1 For Linux, use your package manager to install GCC. If you're using Microsoft Windows, then you should be using Sage via colinux, which includes GCC by default.

Interpreted code: way easier to debug, trace, document, structure (multiple inheritence), etc.; good when few for loops; lots of structure and calls to compiled code.

Compiled code: two reasons to use--make fast code and make optimal use of libraries written in a compiled language; hard to write and debug; takes longer to write. The methods explained in this chapter can produce code where speed is only limited by your choice of algorithm.

TODO:

  1. Module name and file name must agree!



Footnotes

... XCode.5.1
The download is about 1GB, and you must sign up for the Apple Developer Network. http://developer.apple.com/tools/xcode/



Subsections
See About this document... for information on suggesting changes.