4. CyML Language Specification

This document specifies the CyML language, an extended Cython subset supported.

5. Cython file types

  • The implementation files, carrying a .pyx suffix.

5.1. Basic Types

The following basic types are supported

  • bool
  • int
  • float
  • double
  • string

5.2. Complex Types

The following complex types are supported

  • array
  • list
  • datetime

5.3. Conditional Statements

  • IF
  • IF/Else
  • IF/ElseIf/Else

The ELIF and ELSE clauses are optional. An IF statement can appear anywhere that a normal statement or declaration can appear

5.4. Integer For Loops

CyML recognises the usual Python for-in-range integer loop pattern:

for i in range(n):
    ...

Like other Python looping statements, break and continue may be used in the body, without the loop that have an else clause.

5.5. While Loop

  • Like Python While loop

5.6. Function

  • Parameters with declaration
  • Default value is possible

5.7. Return Statement

  • A function needs to return the same data type.

The following code is valid:

def fibonacci(int n):
    if n <= 2:
        return 1
    else:
        return fibonacci(n-1)+fibonacci(n-2)

5.8. Call functions

  • Call to CyML functions are supported if the function
  • is accessible on the module
  • is accessible from import statement

5.9. Operators

Assignment

Assign b = a

Unary operators

UAdd +a
USub -a

Binary operators

Add a + b
Sub a - b
Mult a * b
Div a / b
FloorDiv a // b
Pow a ** b
Mod a % b
LShift a << b
RShift a >> b
BitOr a | b
BitXor a ^ b
BitAnd a & b

Augmented assign statements

AugAdd a += b
AugSub a -= b
AugMult a *= b
AugDiv a /= b

Comparison Operators

Eq a == b
NotEq a != b
Lt a < b
LtE a <= b
Gt a > b
GtE a >= b

Bool Operators

&& a and b
|| a or b

5.10. Array creation routines

`` `` Return a new array of given shape and type, without initializing entries.
`` `` Return a new array of given shape and type, filled with ones.
`` `` Return a new array of given shape and type, filled with zeros.

5.11. Mathematical functions

Trigonometric functions

sin(x) Trigonometric sine, element-wise.
cos(x) Cosine elementwise.
tan(x) Compute tangent element-wise.
arcsin(x) Inverse sine, element-wise.
arccos(x) Trigonometric inverse cosine, element-wise.
arctan(x) Trigonometric inverse tangent, element-wise.

Hyperbolic functions

sinh(x) Hyperbolic sine, element-wise.
cosh(x) Hyperbolic cosine, element-wise.
tanh(x) Compute hyperbolic tangent element-wise.