Taichi: [lang] Add constants like `ti.pi`, `ti.ln2`.

Created on 21 Apr 2020  路  4Comments  路  Source: taichi-dev/taichi

Concisely describe the proposed feature
I would like to add some mathematical constants (e.g. ti.pi) to the language so that users can without handwriting PI = 3.1415926535897.

Describe the solution you'd like (if any)

Additional comments
Also ti.ln2 and ti.ln10 is important since we can simulate log2 and log10 by ti.log(x) / ti.ln2.
Also ti.log(x) * ti.inv_ln2 for faster computation? Btw, @xumingkuan, does our constant_fold convert var / const into var * (1 / const)? The latter is sightly faster, especially for vectors.

feature request good first issue python wontfix

All 4 comments

Actually #510 is not implemented yet, and our constant_fold's function is very limited...

I don't know if we convert var / const into var * (1 / const). To me, if we do convert, it should not be in the constant folding pass -- it's reducing computation burden like a * 2 -> a + a (which we do convert in my memory) does.

Actually #510 is not implemented yet, and our constant_fold's function is very limited...

I don't know if we convert var / const into var * (1 / const). To me, if we do convert, it should not be in the constant folding pass -- it's reducing computation burden like a * 2 -> a + a (which we do convert in my memory) does.

Oh, I see, so we should make another pass before constant_fold? a / 0.5 -> a * 2 -> a + a.
Also should constant_fold do a * 2 * 3 -> a * 6?

Oh, I see, so we should make another pass before constant_fold? a / 0.5 -> a * 2 -> a + a.

Yes, if we didn't.

Also should constant_fold do a * 2 * 3 -> a * 6?

It should... But it doesn't do this now 馃槃

Thanks, but we can probably use math.pi or math.log(2), which will be constant folded during AST generation.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

zdxpan picture zdxpan  路  3Comments

yuanming-hu picture yuanming-hu  路  3Comments

jackalcooper picture jackalcooper  路  4Comments

GeoffreyPlitt picture GeoffreyPlitt  路  4Comments

yuanming-hu picture yuanming-hu  路  3Comments