Skip to content

Instantly share code, notes, and snippets.

@genkuroki
Last active May 20, 2021 09:27
Show Gist options
  • Save genkuroki/707c47fdbea08fd1cef86dd0f11b2372 to your computer and use it in GitHub Desktop.
Save genkuroki/707c47fdbea08fd1cef86dd0f11b2372 to your computer and use it in GitHub Desktop.
Vector of Vectors
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "D = 6\ntensor_size = (1:D) .+ 3\nreqrank = (1:D) .+ 1;",
"execution_count": 1,
"outputs": []
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "using Distributions\n\nbasis_positions = [\n [1; sample(2:tensor_size[d], reqrank[d] - 1; replace=false, ordered=true)]\n for d in 1:6]",
"execution_count": 2,
"outputs": [
{
"output_type": "execute_result",
"execution_count": 2,
"data": {
"text/plain": "6-element Vector{Vector{Int64}}:\n [1, 3]\n [1, 3, 4]\n [1, 2, 4, 6]\n [1, 4, 5, 6, 7]\n [1, 2, 3, 6, 7, 8]\n [1, 3, 4, 5, 7, 8, 9]"
},
"metadata": {}
}
]
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "using Distributions\n\nbasis_positions = ((\n [1; sample(2:tensor_size[d], reqrank[d] - 1; replace=false, ordered=true)]\n for d in 1:6)...,)",
"execution_count": 3,
"outputs": [
{
"output_type": "execute_result",
"execution_count": 3,
"data": {
"text/plain": "([1, 2], [1, 2, 5], [1, 2, 3, 5], [1, 2, 3, 4, 5], [1, 2, 3, 5, 6, 8], [1, 2, 3, 4, 7, 8, 9])"
},
"metadata": {}
}
]
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "using Distributions\n\nbasis_positions = [\n (1, sample(2:tensor_size[d], reqrank[d] - 1; replace=false, ordered=true)...)\n for d in 1:6]",
"execution_count": 4,
"outputs": [
{
"output_type": "execute_result",
"execution_count": 4,
"data": {
"text/plain": "6-element Vector{Tuple{Int64, Int64, Vararg{Int64}}}:\n (1, 2)\n (1, 2, 3)\n (1, 2, 3, 6)\n (1, 2, 3, 6, 7)\n (1, 2, 4, 5, 7, 8)\n (1, 2, 3, 5, 6, 7, 8)"
},
"metadata": {}
}
]
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "using Distributions\n\nbasis_positions = ((\n (1, sample(2:tensor_size[d], reqrank[d] - 1; replace=false, ordered=true)...)\n for d in 1:6)...,)",
"execution_count": 5,
"outputs": [
{
"output_type": "execute_result",
"execution_count": 5,
"data": {
"text/plain": "((1, 4), (1, 2, 3), (1, 2, 4, 5), (1, 2, 3, 4, 6), (1, 2, 3, 4, 7, 8), (1, 2, 3, 4, 5, 7, 8))"
},
"metadata": {}
}
]
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "typeof(basis_positions)",
"execution_count": 6,
"outputs": [
{
"output_type": "execute_result",
"execution_count": 6,
"data": {
"text/plain": "Tuple{Tuple{Int64, Int64}, Tuple{Int64, Int64, Int64}, NTuple{4, Int64}, NTuple{5, Int64}, NTuple{6, Int64}, NTuple{7, Int64}}"
},
"metadata": {}
}
]
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "using Distributions, StaticArrays\n\nbasis_positions = ((\n SVector{reqrank[d]}(1, sample(2:tensor_size[d], reqrank[d] - 1; replace=false, ordered=true)...)\n for d in 1:6)...,)",
"execution_count": 7,
"outputs": [
{
"output_type": "execute_result",
"execution_count": 7,
"data": {
"text/plain": "([1, 2], [1, 2, 4], [1, 3, 4, 5], [1, 2, 3, 4, 6], [1, 2, 4, 5, 6, 7], [1, 4, 5, 6, 7, 8, 9])"
},
"metadata": {}
}
]
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "typeof(basis_positions)",
"execution_count": 8,
"outputs": [
{
"output_type": "execute_result",
"execution_count": 8,
"data": {
"text/plain": "Tuple{SVector{2, Int64}, SVector{3, Int64}, SVector{4, Int64}, SVector{5, Int64}, SVector{6, Int64}, SVector{7, Int64}}"
},
"metadata": {}
}
]
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "",
"execution_count": null,
"outputs": []
}
],
"metadata": {
"kernelspec": {
"name": "julia-1.7-depwarn-o3",
"display_name": "Julia 1.7.0-DEV depwarn -O3",
"language": "julia"
},
"toc": {
"nav_menu": {},
"number_sections": true,
"sideBar": true,
"skip_h1_title": false,
"base_numbering": 1,
"title_cell": "Table of Contents",
"title_sidebar": "Contents",
"toc_cell": false,
"toc_position": {},
"toc_section_display": true,
"toc_window_display": false
},
"language_info": {
"file_extension": ".jl",
"name": "julia",
"mimetype": "application/julia",
"version": "1.7.0"
},
"@webio": {
"lastKernelId": null,
"lastCommId": null
},
"gist": {
"id": "707c47fdbea08fd1cef86dd0f11b2372",
"data": {
"description": "Vector of Vectors",
"public": true
}
},
"_draft": {
"nbviewer_url": "https://gist.github.com/707c47fdbea08fd1cef86dd0f11b2372"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment