Skip to content

Update overflow and trunctation docs post-Eigen - #721

Open
chiphogg wants to merge 3 commits into
mainfrom
chiphogg/of-trunc-docs#70
Open

Update overflow and trunctation docs post-Eigen#721
chiphogg wants to merge 3 commits into
mainfrom
chiphogg/of-trunc-docs#70

Conversation

@chiphogg

Copy link
Copy Markdown
Member

These needed to wait a bit more than the other docs, because the process
of writing them uncovered the need for SameRep and cast<T>.

Fixes #70.

These needed to wait a bit more than the other docs, because the process
of writing them uncovered the need for `SameRep` and `cast<T>`.

Fixes #70.
@chiphogg
chiphogg marked this pull request as ready for review August 12, 2026 17:21
@chiphogg
chiphogg requested a review from a team August 12, 2026 17:21
Comment on lines +173 to +177
```cpp
// Risky conversion caught when output rep specified:
Quantity<Inches, int8_t> length_in = length_ft.as<SameRep>(inches);
// Names the rep at the point of conversion ^^^^^^^^^
```

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this is an interesting example. If I coding this, I'd naturally go for:

Quantity<Inches, int8_t> length_in = length_ft.as<int8_t>(inches);

What I'm really concerned about is that my result fits in the destination type.

Actually, I'd likely use auto here, as I've already specified what I want on the right hand side, so what I'm getting on the left (in the auto) is pretty straight-forward to deduce:

auto length_in = length_ft.as<int8_t>(inches);

All that to say, I'm not sure this is a great example of when SameRep would be used... I could maybe see it with:

auto length_in length_ft.as<SameRep>(inches);

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great callout. I really wrestled with what I was trying to say here.

I even realized there are actually three categories.

  1. Explicit rep
  2. SameRep (as source)
  3. Same rep as target

After reading your example, I had started working on an example where we assign to a field in a struct: it seemed better motivated and easier to understand than manually naming a type like Quantity<Inches, int8_t>. That was when I realized that neither explicit rep nor SameRep gives us what we want. The most ergonomic solution I could think of was something like:

convert_into(make_in_out(data.field), q, target_units);

Obviously, make_in_out isn't something we could ship in Au; that uses Aurora-internal utilities. And I wouldn't want to just take a bare reference, because the callsite readability is poor! So actually adding a feature like this is not a clear slam dunk win. Moreover, it's very easy to write this utility in a client codebase without changing Au at all.

So Au natively supports the first two categories, and it's up to end users to support the third --- definitely today, possibly forever.

And I didn't want to muddle the docs with even more nuance.

So where does that leave us?

I ended up liking the auto in your final example the best. The auto actually pairs really nicely with the SameRep: it's a clear expression of author intent, "stay within the numeric type". I added a brief sentence after just saying that we dropped the explicit typename because it's now clearly determined by the RHS. As the above novel ^ indicates, yes, there is still a lot of subtlety lurking around these issues, but I'm hard pressed to improve this example any further at the moment.

Comment thread docs/discussion/concepts/truncation.md Outdated

### Compound types

Not every rep is a plain arithmetic type. Complex numbers, and Eigen vectors and matrices, are

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Not every rep is a plain arithmetic type. Complex numbers, and Eigen vectors and matrices, are
Not every rep is a plain arithmetic type. Complex numbers and Eigen vectors and matrices, are

I think the Eigen types are a single item in this list? With a third item, it would be:

Complex numbers, Eigen vectors and matrices, and Some Other Fun Library Type 
are common examples ...

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ended up doing "vectors/matrices", which avoids the confusion you pointed out here.

Comment thread docs/discussion/concepts/truncation.md Outdated

Not every rep is a plain arithmetic type. Complex numbers, and Eigen vectors and matrices, are
common examples of _compound_ reps: types built up out of some underlying _scalar_. Au
characterizes each such rep by that scalar --- its

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, an em-dash!

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep --- I explicitly configured the site to replace --- with actual em-dashes in the rendered output. We were liberally using em-dashes long before the LLM era! 🤓

Comment thread docs/discussion/concepts/truncation.md Outdated
a conservative approach. Any cast involving a rep with non-arithmetic scalar type, either as source
or destination, is considered to have truncation risk, and will not be allowed by default: users
must pass `ignore(TRUNCATION_RISK)` as a second argument to override this. We hope to have better
default behavior once we support non-arithmetic types more fully.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to reference #52 here as well?

Suggested change
default behavior once we support non-arithmetic types more fully.
default behavior once we support non-arithmetic types more fully ([#52]).

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. In fact, I think it's better to reference it here only. The other one felt a little redundant, and the link makes more sense here.

@chiphogg
chiphogg requested a review from hoffbrinkle August 13, 2026 17:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support matrices, vectors, and linear algebra

2 participants