CARVIEW |
Select Language
HTTP/2 200
date: Sat, 26 Jul 2025 07:34:10 GMT
content-type: text/html; charset=utf-8
vary: X-PJAX, X-PJAX-Container, Turbo-Visit, Turbo-Frame, X-Requested-With,Accept-Encoding, Accept, X-Requested-With
etag: W/"ce8bc966234eac760521c1f890a2a75b"
cache-control: max-age=0, private, must-revalidate
strict-transport-security: max-age=31536000; includeSubdomains; preload
x-frame-options: deny
x-content-type-options: nosniff
x-xss-protection: 0
referrer-policy: no-referrer-when-downgrade
content-security-policy: default-src 'none'; base-uri 'self'; child-src github.githubassets.com github.com/assets-cdn/worker/ github.com/assets/ gist.github.com/assets-cdn/worker/; connect-src 'self' uploads.github.com www.githubstatus.com collector.github.com raw.githubusercontent.com api.github.com github-cloud.s3.amazonaws.com github-production-repository-file-5c1aeb.s3.amazonaws.com github-production-upload-manifest-file-7fdce7.s3.amazonaws.com github-production-user-asset-6210df.s3.amazonaws.com *.rel.tunnels.api.visualstudio.com wss://*.rel.tunnels.api.visualstudio.com objects-origin.githubusercontent.com copilot-proxy.githubusercontent.com proxy.individual.githubcopilot.com proxy.business.githubcopilot.com proxy.enterprise.githubcopilot.com *.actions.githubusercontent.com wss://*.actions.githubusercontent.com productionresultssa0.blob.core.windows.net/ productionresultssa1.blob.core.windows.net/ productionresultssa2.blob.core.windows.net/ productionresultssa3.blob.core.windows.net/ productionresultssa4.blob.core.windows.net/ productionresultssa5.blob.core.windows.net/ productionresultssa6.blob.core.windows.net/ productionresultssa7.blob.core.windows.net/ productionresultssa8.blob.core.windows.net/ productionresultssa9.blob.core.windows.net/ productionresultssa10.blob.core.windows.net/ productionresultssa11.blob.core.windows.net/ productionresultssa12.blob.core.windows.net/ productionresultssa13.blob.core.windows.net/ productionresultssa14.blob.core.windows.net/ productionresultssa15.blob.core.windows.net/ productionresultssa16.blob.core.windows.net/ productionresultssa17.blob.core.windows.net/ productionresultssa18.blob.core.windows.net/ productionresultssa19.blob.core.windows.net/ github-production-repository-image-32fea6.s3.amazonaws.com github-production-release-asset-2e65be.s3.amazonaws.com insights.github.com wss://alive.github.com api.githubcopilot.com api.individual.githubcopilot.com api.business.githubcopilot.com api.enterprise.githubcopilot.com; font-src github.githubassets.com; form-action 'self' github.com gist.github.com copilot-workspace.githubnext.com objects-origin.githubusercontent.com; frame-ancestors 'none'; frame-src viewscreen.githubusercontent.com notebooks.githubusercontent.com; img-src 'self' data: blob: github.githubassets.com media.githubusercontent.com camo.githubusercontent.com identicons.github.com avatars.githubusercontent.com private-avatars.githubusercontent.com github-cloud.s3.amazonaws.com objects.githubusercontent.com release-assets.githubusercontent.com secured-user-images.githubusercontent.com/ user-images.githubusercontent.com/ private-user-images.githubusercontent.com opengraph.githubassets.com copilotprodattachments.blob.core.windows.net/github-production-copilot-attachments/ github-production-user-asset-6210df.s3.amazonaws.com customer-stories-feed.github.com spotlights-feed.github.com objects-origin.githubusercontent.com *.githubusercontent.com; manifest-src 'self'; media-src github.com user-images.githubusercontent.com/ secured-user-images.githubusercontent.com/ private-user-images.githubusercontent.com github-production-user-asset-6210df.s3.amazonaws.com gist.github.com; script-src github.githubassets.com; style-src 'unsafe-inline' github.githubassets.com; upgrade-insecure-requests; worker-src github.githubassets.com github.com/assets-cdn/worker/ github.com/assets/ gist.github.com/assets-cdn/worker/
server: github.com
content-encoding: gzip
accept-ranges: bytes
set-cookie: _gh_sess=tvoi%2FzJVncyYN1CTJYLhddTfNTIdTf8WKLVDJlVxf4ywpITiBySaTs0wJLouVyDTlrrUH5IwkFNHRm9Rinw74gf0kwyQOnKQ9DjfI7qQ%2BUkZ8tfzoSEbf6Z%2FLvdF23qGNZ3LfoGA4DsnNLJUukobUM%2FSGiwos8s2Y0M2Pv%2BdBEGrWfeeyIiJOjzZ4AlnDoqfQ9d6Y1KgUah8ffV0XbYj9PpY69LE%2F%2By5TujwCgysYIWhr1QGGZqNvegIf%2BDUgUQ%2FQRcR6qGuXC6n3iUOPzhAMQ%3D%3D--gNk%2BUj2C6v0NU4N8--MIVfW7KtoLvvLonwngmWoA%3D%3D; Path=/; HttpOnly; Secure; SameSite=Lax
set-cookie: _octo=GH1.1.363555121.1753515249; Path=/; Domain=github.com; Expires=Sun, 26 Jul 2026 07:34:09 GMT; Secure; SameSite=Lax
set-cookie: logged_in=no; Path=/; Domain=github.com; Expires=Sun, 26 Jul 2026 07:34:09 GMT; HttpOnly; Secure; SameSite=Lax
x-github-request-id: 9578:29FD1F:2E524F:3F1E5D:688484F1
Tensor construction and initialisation · romeric/Fastor Wiki · GitHub
Skip to content
Navigation Menu
{{ message }}
-
Notifications
You must be signed in to change notification settings - Fork 76
Tensor construction and initialisation
Roman edited this page Oct 1, 2023
·
5 revisions
-
Tensor Constructors
- Initializer list constructors
- Constructing Tensors from a scalar
- Constructing Tensors from C arrays
- Constructing from std::array/std::vector
- Initialiser methods
There are many ways to construct Fastor tensors. The easiest way is using initializer lists or braces
Tensor<double,2,3> mat = {{1,2,3},
{4,5,6}};
You can create tensors of any order using braces for instances for a 3D tensor you do
Tensor<double,2,2,3> array_3d = {{{1,2,3},
{4,5,6}},
{{8,9,10},
{11,12,13}}};
Note the number of opening and closing braces should match the dimension (rank) of the tensor.
You can initialise all values of a tensor to a given scalar if you want
Tensor<int,4,4> a(5);
Tensor<float,2,2> b(0.f);
If you already have data stored in a C array or a pointer you can initialise your tensor as
double c_array[4] = {1,2,3,4};
Tensor<double,4> a(c_array); // construct a vector from c_array
Tensor<double,2,2> a(c_array); // construct a matrix from c_array
You can also construct a tensor from a std::array or std::vector
std::array<double,4> std_array = {1,2,3,4};
Tensor<double,2,2> a(std_array); // construct a matrix from std::array
std::vector<double> std_vec = {1,2,3,4};
Tensor<double,2,2> a(std_vec); // construct a matrix from std::vector
Note that you don't have to give the size as the size and dimension of the tensor is encoded in the type of the tensor
There are many initialiser methods provided that you can use for filling your tensors
Tensor<float,3,4,5> a;
a.zeros(); // fill all the elements with zero
a.ones(); // fill all the elements with one
a.fill(2.5); // fill all the elements with 2.5
a.random(); // fill all the elements with random numbers
a.iota(3); // fill all the elements with sequentially ascending number starting from 3
a.arange(3); // fill all the elements with sequentially ascending number starting from 3. Same as above
Clone this wiki locally
You can’t perform that action at this time.