From fdfbfab58262460b73d4bab4a080536473562704 Mon Sep 17 00:00:00 2001 From: Clonkk Date: Thu, 12 Oct 2023 12:08:46 +0200 Subject: [PATCH 1/2] add contiguous function --- flambeau/raw/bindings/rawtensors.nim | 1 + flambeau/tensors.nim | 5 +++++ tests/tensor/test_accessors_slicer.nim | 5 +++++ 3 files changed, 11 insertions(+) diff --git a/flambeau/raw/bindings/rawtensors.nim b/flambeau/raw/bindings/rawtensors.nim index 4f43511..73b8dde 100644 --- a/flambeau/raw/bindings/rawtensors.nim +++ b/flambeau/raw/bindings/rawtensors.nim @@ -461,6 +461,7 @@ template `==`*(a, b: RawTensor): bool = # Functions.h # ----------------------------------------------------------------------- +func contiguous*(self: RawTensor): RawTensor {.importcpp: "#.contiguous(@)".} func toType*(self: RawTensor, dtype: ScalarKind): RawTensor {.importcpp: "#.toType(@)".} func toSparse*(self: RawTensor): RawTensor {.importcpp: "#.to_sparse()".} func toSparse*(self: RawTensor, sparseDim: int64): RawTensor {.importcpp: "#.to_sparse(@)".} diff --git a/flambeau/tensors.nim b/flambeau/tensors.nim index 30aa2bd..ebbeaf2 100644 --- a/flambeau/tensors.nim +++ b/flambeau/tensors.nim @@ -325,6 +325,11 @@ func backward*[T](self: var Tensor[T]) = # # Functions.h # # ----------------------------------------------------------------------- +func contiguous*[T](self: Tensor[T]) : Tensor[T] = + asTensor[T]( + rawtensors.contiguous(asRaw(self)) + ) + func toType*[T](self: Tensor[T], dtype: ScalarKind): Tensor[T] = asTensor[T]( rawtensors.toType(asRaw(self), dtype) diff --git a/tests/tensor/test_accessors_slicer.nim b/tests/tensor/test_accessors_slicer.nim index 7c51695..fedb8e9 100644 --- a/tests/tensor/test_accessors_slicer.nim +++ b/tests/tensor/test_accessors_slicer.nim @@ -91,6 +91,11 @@ proc main() = let test = @[@[1], @[16], @[81], @[256], @[625]] check: t_van[_.._, 3] == test.toTensor().squeeze() + test "Span slices - foo[_, 3] in assignment": + let test = @[@[1], @[16], @[81], @[256], @[625]] + var tmp = t_van[_, 3] + check tmp == test.toTensor().squeeze() + test "Stepping - foo[1..3|2, 3]": let test = @[@[16], @[256]] check: t_van[1..3|2, 3] == test.toTensor().squeeze() From 90b40e3fdc57c7cfe36fc9172f7eda6c6b65a0d6 Mon Sep 17 00:00:00 2001 From: Regis Caillaud <35006197+Clonkk@users.noreply.github.com> Date: Fri, 13 Oct 2023 11:36:37 +0200 Subject: [PATCH 2/2] Remove unused import --- flambeau/install/torch_installer.nim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flambeau/install/torch_installer.nim b/flambeau/install/torch_installer.nim index fb790a3..4bcf1c4 100644 --- a/flambeau/install/torch_installer.nim +++ b/flambeau/install/torch_installer.nim @@ -6,7 +6,7 @@ # at your option. This file may not be copied, modified, or distributed except according to those terms. import - std/[asyncdispatch, httpclient, + std/[httpclient, strformat, strutils, os], #zippy/ziparchives, zip/zipfiles