Skip to content

Make scalar → Tensor0 conversions work without an import, using Scala's into - #169

Merged
benikm91 merged 1 commit into
dimwit-dev:mainfrom
benikm91:implement-into
Sep 27, 2026
Merged

benikm91 merged 1 commit into
dimwit-dev:mainfrom
benikm91:implement-into

Conversation

@benikm91

Copy link
Copy Markdown
Collaborator

Scalar literals such as t *! 2.0f, 2.0f *! t or t.pow(2.0f) now work without import dimwit.Conversions.given and without feature warnings.

How

  • Tensor is now an into class (Scala 3.9), so conversions to Tensor no longer produce a feature warning.
  • The conversion givens moved to private[dimwit] object Tensor0Conversions, and the Tensor companion exports them, so the compiler finds them automatically.
  • scalafmt 3.9.8 → 3.10.3. 3.9.8 cannot parse into, and 3.10.7+ would reformat unrelated files.

Breaking

  • dimwit.Conversions is removed. Delete every import dimwit.Conversions.given (and any named imports from dimwit.Conversions).

Behavior

  • Wherever the old import was in scope, conversions behave exactly as before.
  • Conversions are now always on. There is no way to opt out per file, as the import used to allow.
  • Because of into class Tensor, a user's own conversion to Tensor no longer produces a feature warning either.
  • API breaking: Conversions object was removed; import Conversions.given result in errors rather than NOOP

object AxisAbsent:
given notContained[T <: Tuple, L](using NotGiven[Tuple.Contains[T, L] =:= true]): AxisAbsent[T, L] = new AxisAbsent[T, L] {}

import Util.*

@benikm91 benikm91 Sep 27, 2026 •

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Note this change is a clean up from the previous PR

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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 marcelluethi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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] (

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

@benikm91
benikm91 merged commit 05ff62d into dimwit-dev:main Sep 27, 2026
1 check passed
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.

3 participants