Aussie AI
Code Portability Pitfalls
-
Book Excerpt from "Generative AI in C++"
-
by David Spuler, Ph.D.
Code Portability Pitfalls
Most of the low-level arithmetic code for AI algorithms looks quite standardized. Well, not so much. The general areas where C++ code that looks standard is actually non-portable includes trappy issues such as:
- Data type byte sizes (e.g. how many bytes is an “
int
”). - Arithmetic overflow of integers or
float
operators. - Integer operators and negatives (e.g.
%
and>>
operators). - Floating-point oddities (e.g. negative zero,
Inf
, andNaN
). - Divide-by-zero doesn't always crash.
- Pointer versus integer sizes (e.g. do
void
pointers fit inside anint
?). - Endian-ness of integer byte storage (i.e. do you prefer “big endian” or “little endian”?).
- Zero bytes versus zero integers.
- Order of evaluation of expression operands (e.g. with side-effects).
And there are various other portability issues arising at a higher-level than the AI arithmetic data processing, such as the inputs and outputs of the program. Problematic areas include:
- Text files (e.g.
'\n'
on Linux versus'\r\n'
on Windows). - UTF8 versus Latin1 encodings (e.g. for tokenization).
- Unicode special characters (e.g., Asian languages or unicorn emojis).
- EBCDIC versus ASCII (character-level problems in tokens).
- Operating system accesses (e.g. processes and file permissions).
- Signal handling (low-level).
• Next: • Up: Table of Contents |
The new AI programming book by Aussie AI co-founders:
Get your copy from Amazon: Generative AI in C++ |