Make scalar → Tensor0 conversions work without an import, using Scala's into - #169
Conversation
| object AxisAbsent: | ||
| given notContained[T <: Tuple, L](using NotGiven[Tuple.Contains[T, L] =:= true]): AxisAbsent[T, L] = new AxisAbsent[T, L] {} | ||
|
|
||
| import Util.* |
There was a problem hiding this comment.
Note this change is a clean up from the previous PR
There was a problem hiding this comment.
Copilot review overview
🟢 Approval recommended
No unresolved review issues remain, and the supplied assessments indicate approval readiness.
Review effort: Lite
Findings: None
What changed in this PR
This PR makes scalar-to-Tensor0 conversions automatic through Scala’s into class support and removes the obsolete Conversions API.
Changes:
- Adds and exports automatic scalar conversions.
- Removes obsolete imports across source, tests, examples, and documentation.
- Updates Scalafmt to 3.10.3.
| File | Description |
|---|---|
mdocs/docs/quickstart.md |
Updates quickstart imports. |
mdocs/AGENTS.md |
Updates generated documentation guidance. |
examples/src/main/scala/dimwit/dataset/MNISTLoader.scala |
Removes obsolete conversion imports. |
examples/src/main/scala/dimwit/complex/VariationalAutoencoder.scala |
Removes obsolete conversion imports. |
examples/src/main/scala/dimwit/basic/LogisticRegression.scala |
Removes obsolete conversion imports. |
examples/src/main/scala/dimwit/basic/KMeans.scala |
Removes obsolete conversion imports. |
docs/quickstart.md |
Updates quickstart examples and imports. |
core/src/test/scala/dimwit/tensortree/TreeOfSuite.scala |
Updates conversion usage tests. |
core/src/test/scala/dimwit/tensor/TensorOpsReductionSuite.scala |
Updates conversion usage tests. |
core/src/test/scala/dimwit/tensor/TensorOpsFunctionalSuite.scala |
Updates conversion usage tests. |
core/src/test/scala/dimwit/tensor/TensorOpsElementwiseSuite.scala |
Updates conversion usage tests. |
core/src/test/scala/dimwit/tensor/TensorOpsBroadcastSuite.scala |
Updates conversion usage tests. |
core/src/test/scala/dimwit/tensor/TensorCreationSuite.scala |
Updates conversion usage tests. |
core/src/test/scala/dimwit/tensor/TensorCovarianceSuite.scala |
Updates conversion usage tests. |
core/src/test/scala/dimwit/stats/DistributionSuite.scala |
Updates conversion usage tests. |
core/src/test/scala/dimwit/python/PyWrapSuite.scala |
Updates conversion usage tests. |
core/src/test/scala/dimwit/optimizer/GradientOptimizerSuite.scala |
Updates conversion usage tests. |
core/src/test/scala/dimwit/memory/DimWitMemorySuite.scala |
Updates conversion usage tests. |
core/src/test/scala/dimwit/jax/JitSuite.scala |
Updates conversion usage tests. |
core/src/test/scala/dimwit/autodiff/AutodiffSuite.scala |
Updates conversion usage tests. |
core/src/main/scala/dimwit/tensor/ValueExtensions.scala |
Updates conversion documentation. |
core/src/main/scala/dimwit/tensor/tensorops/StructuralOps.scala |
Removes an unused import. |
core/src/main/scala/dimwit/tensor/Tensor0Conversions.scala |
Defines scalar conversion givens. |
core/src/main/scala/dimwit/tensor/Tensor.scala |
Enables into conversions and exports givens. |
core/src/main/scala/dimwit/package.scala |
Removes the obsolete Conversions API. |
core/src/main/scala/dimwit/optimizer/GradientOptimizer.scala |
Removes an obsolete import. |
AGENTS.md |
Updates generated documentation guidance. |
.scalafmt.conf |
Updates Scalafmt configuration. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
marcelluethi
left a comment
There was a problem hiding this comment.
This is a nice ergonomic improvement.
| * @param V The data type of the tensor elements. | ||
| */ | ||
| class Tensor[T <: Tuple: Labels, V] private[dimwit] ( | ||
| into class Tensor[T <: Tuple: Labels, V] private[dimwit] ( |
There was a problem hiding this comment.
I did not know that into also works on the class level. This is much more elegant than the solution I found, which would have used into in every signature that has a Tensor[T, V]. Nice.
Scalar literals such as
t *! 2.0f,2.0f *! tort.pow(2.0f)now work withoutimport dimwit.Conversions.givenand without feature warnings.How
Tensoris now aninto class(Scala 3.9), so conversions toTensorno longer produce a feature warning.private[dimwit] object Tensor0Conversions, and theTensorcompanion exports them, so the compiler finds them automatically.into, and 3.10.7+ would reformat unrelated files.Breaking
dimwit.Conversionsis removed. Delete everyimport dimwit.Conversions.given(and any named imports fromdimwit.Conversions).Behavior
into class Tensor, a user's own conversion toTensorno longer produces a feature warning either.