From fa856b07064295ad1db88f942809b063f489e327 Mon Sep 17 00:00:00 2001 From: Vindaar Date: Sun, 16 Jun 2024 19:03:44 +0200 Subject: [PATCH] Specifiy type of set in `toTensor` for `HashSet | OrderedSet` (#656) * [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 --- src/arraymancer/laser/tensor/initialization.nim | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/arraymancer/laser/tensor/initialization.nim b/src/arraymancer/laser/tensor/initialization.nim index 37821b4f..2a7134e4 100644 --- a/src/arraymancer/laser/tensor/initialization.nim +++ b/src/arraymancer/laser/tensor/initialization.nim @@ -276,7 +276,7 @@ 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: @@ -284,11 +284,11 @@ proc toTensor*[T](a: SomeSet[T]): auto = ## 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