# Using @tensor with sparse tensors of SparseArrayKit.jl

**URL:** <https://discourse.julialang.org/t/using-tensor-with-sparse-tensors-of-sparsearraykit-jl/113686>\
**Category:** General Usage\
**Tags:** sparse\
**Created:** [May 1, 2024, 7:53am UTC](https://discourse.julialang.org/t/using-tensor-with-sparse-tensors-of-sparsearraykit-jl/113686 "2024-05-01T07:53:39Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rodrigue](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rodrigue/32/19627_2.png) [@Rodrigue](https://discourse.julialang.org/u/Rodrigue)\
**Post date:** [May 1, 2024, 7:53am UTC](https://discourse.julialang.org/t/using-tensor-with-sparse-tensors-of-sparsearraykit-jl/113686/1 "2024-05-01T07:53:39Z")

</div>

According to the SparseArrayKit.jl documentation, sparse tensors implemented therein are compatible with the @tensor macro from the TensorOperations.jl package. The following simple code

```julia
function randn_sparse(T::Type{<:Number}, sz::Dims, p=0.5)
    a = SparseArray{T}(undef, sz)
    for I in keys(a)
        if rand() < p
            a[I] = randn(T)
        end
    end
    return a
end

X = randn_sparse(Float64, (L, L, L)) # Three-dimensional random tensor
O = ones(L) 

@tensor begin
    C[i,j] := X[i, j, k] * O[k] 
end

```

returns the error

> MethodError: no method matching StridedViews.StridedView(::SparseArray{Float64, 3})

Does anyone know how to fix this ?
