Table of Contents

Method ConvertFromString

Namespace
Bonsai.ML.Torch
Assembly
Bonsai.ML.Torch.dll

ConvertFromString(string, ScalarType)

Method that converts a string into a tensor. The string value should be in a Python-like syntax. For example, a 2x2 tensor can be created with the following values: "[[1, 2], [3, 4]]".

public static torch.Tensor ConvertFromString(string value, torch.ScalarType scalarType)

Parameters

value string

The string value to convert.

scalarType torch.ScalarType

The scalar type of the tensor.

Returns

torch.Tensor

A tensor created from the string value.

Remarks

This class relies on the PythonDataHelper class to parse the string into the appropriate data type. The Parse method however returns a type of object, so we use pattern matching to determine the type of the data and create the tensor from the typed object.

Exceptions

ArgumentException

Thrown when the tensor data is not supported for converting to .NET data type