Skip to content

Commit

Permalink
Updated cast methods documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
ulises-jeremias committed Oct 7, 2023
1 parent afbb97c commit 8dc078b
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/cast.v
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
module vtl

// as_bool casts the Tensor to a Tensor of bools.
// If the original Tensor is not a Tensor of bools, then each value is cast to a bool,
// otherwise the original Tensor is returned.
[inline]
pub fn (t &Tensor[T]) as_bool[T]() &Tensor[bool] {
$if T is bool {
Expand All @@ -19,6 +21,8 @@ pub fn (t &Tensor[T]) as_bool[T]() &Tensor[bool] {
}

// as_f32 casts the Tensor to a Tensor of f32s.
// If the original Tensor is not a Tensor of f32s, then each value is cast to a f32,
// otherwise the original Tensor is returned.
[inline]
pub fn (t &Tensor[T]) as_f32[T]() &Tensor[f32] {
$if T is f32 {
Expand All @@ -37,6 +41,8 @@ pub fn (t &Tensor[T]) as_f32[T]() &Tensor[f32] {
}

// as_f64 casts the Tensor to a Tensor of f64s.
// If the original Tensor is not a Tensor of f64s, then each value is cast to a f64,
// otherwise the original Tensor is returned.
[inline]
pub fn (t &Tensor[T]) as_f64[T]() &Tensor[f64] {
$if T is f64 {
Expand All @@ -55,6 +61,8 @@ pub fn (t &Tensor[T]) as_f64[T]() &Tensor[f64] {
}

// as_i16 casts the Tensor to a Tensor of i16 values.
// If the original Tensor is not a Tensor of i16s, then each value is cast to a i16,
// otherwise the original Tensor is returned.
[inline]
pub fn (t &Tensor[T]) as_i16[T]() &Tensor[i16] {
$if T is i16 {
Expand All @@ -73,6 +81,8 @@ pub fn (t &Tensor[T]) as_i16[T]() &Tensor[i16] {
}

// as_i8 casts the Tensor to a Tensor of i8 values.
// If the original Tensor is not a Tensor of i8s, then each value is cast to a i8,
// otherwise the original Tensor is returned.
[inline]
pub fn (t &Tensor[T]) as_i8[T]() &Tensor[i8] {
$if T is i8 {
Expand All @@ -91,6 +101,8 @@ pub fn (t &Tensor[T]) as_i8[T]() &Tensor[i8] {
}

// as_int casts the Tensor to a Tensor of ints.
// If the original Tensor is not a Tensor of ints, then each value is cast to a int,
// otherwise the original Tensor is returned.
[inline]
pub fn (t &Tensor[T]) as_int[T]() &Tensor[int] {
$if T is int {
Expand All @@ -109,6 +121,8 @@ pub fn (t &Tensor[T]) as_int[T]() &Tensor[int] {
}

// as_string casts the Tensor to a Tensor of string values.
// If the original Tensor is not a Tensor of strings, then each value is cast to a string,
// otherwise the original Tensor is returned.
[inline]
pub fn (t &Tensor[T]) as_string[T]() &Tensor[string] {
$if T is string {
Expand All @@ -127,6 +141,8 @@ pub fn (t &Tensor[T]) as_string[T]() &Tensor[string] {
}

// as_u8 casts the Tensor to a Tensor of u8 values.
// If the original Tensor is not a Tensor of u8s, then each value is cast to a u8,
// otherwise the original Tensor is returned.
[inline]
pub fn (t &Tensor[T]) as_u8[T]() &Tensor[u8] {
$if T is u8 {
Expand Down

0 comments on commit 8dc078b

Please sign in to comment.