Skip to content

Commit

Permalink
Specifiy type of set in toTensor for HashSet | OrderedSet (#656)
Browse files Browse the repository at this point in the history
* [tensor] avoid usage of `SomeSet` in `toTensor` for sets

The generic + generic type class leads the compiler to become drunk
and chooses to compile code that really does not belong in there.

We might further want to restrict `T` as well, but I don't want to be
too restrictive for now.

* [tensor] reorder the `sets` `toTensor` to use `len` of produced seq
  • Loading branch information
Vindaar authored Jun 16, 2024
1 parent 28b73d7 commit fa856b0
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/arraymancer/laser/tensor/initialization.nim
Original file line number Diff line number Diff line change
Expand Up @@ -276,19 +276,19 @@ proc toTensor*[T; U](a: openArray[T], typ: typedesc[U]): Tensor[U] {.inline.} =
else:
toTensor(a).asType(typ)

proc toTensor*[T](a: SomeSet[T]): auto =
proc toTensor*[T](a: HashSet[T] | OrderedSet[T]): Tensor[T] =
## Convert a HashSet or an OrderedSet into a Tensor
##
## Input:
## - An HashSet or an OrderedSet
## Result:
## - A Tensor of the same shape
var shape = MetaData()
shape.add(a.len)
let data = toSeq(a)
shape.add(data.len)
result = toTensor(data, shape)

proc toTensor*[T; U](a: SomeSet[T], typ: typedesc[U]): Tensor[U] {.inline.} =
proc toTensor*[T; U](a: HashSet[T] | OrderedSet[T], typ: typedesc[U]): Tensor[U] {.inline.} =
## Convert a HashSet or an OrderedSet into a Tensor of type `typ`
##
## This is a convenience function which given an input `a` is equivalent to
Expand Down

0 comments on commit fa856b0

Please sign in to comment.