Skip to content

Trivial tensors fast path into TensorOperations machinery#463

Open
lkdvos wants to merge 2 commits into
mainfrom
lkdvos/trivial-tensorop-fastpath
Open

Trivial tensors fast path into TensorOperations machinery#463
lkdvos wants to merge 2 commits into
mainfrom
lkdvos/trivial-tensorop-fastpath

Conversation

@lkdvos

@lkdvos lkdvos commented Jun 25, 2026

Copy link
Copy Markdown
Member

This bypasses some of the unnecessary machinery for dense trivial tensors to hopefully improve compilation times by being able to re-use some of the precompiled things in TensorOperations.
I also found an allocator argument not being passed on to the permute call, so that should now also be fixed.

@lkdvos lkdvos requested a review from Jutho June 25, 2026 14:21
@codecov

codecov Bot commented Jun 25, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 90.00000% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/tensors/tensoroperations.jl 88.88% 1 Missing ⚠️
Files with missing lines Coverage Δ
src/tensors/indexmanipulations.jl 88.06% <100.00%> (-0.05%) ⬇️
src/tensors/tensoroperations.jl 97.28% <88.88%> (-0.39%) ⬇️

... and 2 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@lkdvos lkdvos requested a review from kshyatt June 25, 2026 18:21
# the fusiontree machinery and act directly on the `t[]` array view.
_has_dense_backing(::AbstractTensorMap) = false
_has_dense_backing(t::TensorMap) = sectortype(t) === Trivial
_has_dense_backing(t::AdjointTensorMap) = _has_dense_backing(parent(t))

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.

Not a great fan of the name/terminology "backing". Do you expect to have relevant cases where this is not simply equivalent to sectortype(t) === Trivial. A call to _has_dense_backing(t) is always followed by t[], and that getindex method is only defined for tensors with sectortype(t) == Trivial.

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'm happy to change the name to whatever, but the use case is blocktensors, for which this is not really what I wanted to implement, even though I definitely could if that is where we want to go, but it would be a reimplementation of the permute and then mul calls

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.

Ok I see. I just don't like introducing a new terminology ("backing") that isn't really well defined. We have storage, but currently all storage is dense. What does it amount to in the blocktensor case? Is it also equivalent to sectortype(t) === Trivial but sectortype is not defined? Or is it at the block level that you want to directly lower to a TensorOperations call, but then the individual blocks can still be nontrivial tensors?

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.

The problem is just that in this case t[] still works, but now produces a single block(sparse) array with dense blocks, for which I don't have tensor contraction defined. How about has_contiguous_storage?
The alternative is to simply use dispatch and define TrivialTensorMap again, but I decided against that since that gets a little messy with adjointtensormap, for which this also works

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.

Ok, after some more (AI-assisted) thinking, I will propose: has_array_view. Given that this is a completely internal function that is just there to avoid having this behavior by default for AbstractTensorMap, I don't think it matters too much and I can't come up with too many better alternatives.

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.

Ok, has_array_view sounds quite good and clear to me.

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.

2 participants