Skip to content

Make tensors generic on their value type - #17

Merged
ppraneth merged 3 commits into
mainfrom
genric
Nov 3, 2026
Merged

ppraneth merged 3 commits into
mainfrom
genric

Conversation

@ppraneth

@ppraneth ppraneth commented Nov 1, 2026

Copy link
Copy Markdown
Collaborator

Closes #9

  • Tensors, reductions and printing are generic on the value type T, which defaults to f32, so existing code works unchanged
  • LeftComposition can change the value type, e.g. a comparison turns f32 into bool
  • Reductions are defined for f32, f64 and i64
  • where_ takes a bool condition
  • square, negate, scale, clamp and the functions that only move indices are generic
  • pow is removed
  • Kept on f32 on purpose:
    • zeros, ones and eye have no input to infer the type from

@ppraneth
ppraneth requested a review from ValerianRey November 1, 2026 05:28

@ValerianRey ValerianRey left a comment

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.

good job ty! you can merge

Comment thread src/functions.rs Outdated
};

pub fn square<T: Tensor + ?Sized>(u: Rc<T>) -> LeftComposition<T> {
pub fn square<V: Mul<Output = V> + Copy + 'static, U: Tensor<V> + ?Sized>(

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.

i think it would be better to stick to a naming convention, like A and B are for value types (like you did in tensor.rs) and U and V are tensor types.

@ppraneth
ppraneth merged commit 38c1026 into main Nov 3, 2026
4 checks passed
@ppraneth
ppraneth deleted the genric branch November 3, 2026 10:15
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.

Make tensors generic on dtype

2 participants