File: collections.go

package info (click to toggle)
golang-github-gorgonia-tensor 0.9.24-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,696 kB
  • sloc: sh: 18; asm: 18; makefile: 8
file content (30 lines) | stat: -rw-r--r-- 714 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package tensor

import "github.com/pkg/errors"

func densesToTensors(a []*Dense) []Tensor {
	retVal := make([]Tensor, len(a))
	for i, t := range a {
		retVal[i] = t
	}
	return retVal
}

func densesToDenseTensors(a []*Dense) []DenseTensor {
	retVal := make([]DenseTensor, len(a))
	for i, t := range a {
		retVal[i] = t
	}
	return retVal
}

func tensorsToDenseTensors(a []Tensor) ([]DenseTensor, error) {
	retVal := make([]DenseTensor, len(a))
	var ok bool
	for i, t := range a {
		if retVal[i], ok = t.(DenseTensor); !ok {
			return nil, errors.Errorf("can only convert Tensors of the same type to DenseTensors. Trying to convert %T (#%d in slice)", t, i)
		}
	}
	return retVal, nil
}