Scale is not defined

UndefVarError: scale not defined

Stacktrace:
[1] spectral_embedding(W::SparseMatrixCSC{Float64, Int64}, nev::Int64)
@ Main .\In[45]:10
[2] top-level scope
@ In[48]:1
[3] eval
@ .\boot.jl:368 [inlined]
[4] include_string(mapexpr::typeof(REPL.softscope), mod::Module, code::String, filename::String)
@ Base .\loading.jl:1428

The “scale” should be a function of one of julia packages. I am new to julia and don’t know what package it belongs to. Can someone help me with that?

where did you get this piece of code to begin with

// #Get embeddings, following algorithm of Ng et al., 2002.
function spectral_embedding(W::SparseMatrixCSC{Float64,Int64}, nev::Int64)
d = sqrt.(vec(sum(W,dims = 1)));
n = length(d);
ai,aj,av = findnz(W);
Ln = sparse(ai, aj, -av./((d[ai].*d[aj])), n, n);
Ln = Ln + 2 * spzeros(n,n);
(lams, V, _) = MatrixNetworks._symeigs_smallest_arpack(Ln,nev,1e-12,300,d);
s = vec(1 ./ sqrt.(sum(V.^2,dims = 2)));
using LinearAlgebra, Statistics;
return scale(s, V);
end

The above code has return value where scale is used.

did someone just send you this code??? or this is something you found online

1 Like

don’t do using inside a function this is not python

1 Like

chonky url :nerd_face:

what’s in include("higher_order_packages.jl")

scale was a function in Base Julia up to version 0.4, before being deprecated in Julia 0.5 in favor of plain or broadcasted multiplication. This was the docstring in Julia 0.4:

  scale(A, b)
  scale(b, A)

  Scale an array A by a scalar b, returning a new array.

  If A is a matrix and b is a vector, then scale(A,b) scales each column i of A by b[i]
  (similar to A*diagm(b)), while scale(b,A) scales each row i of A by b[i] (similar to
  diagm(b)*A), returning a new array.
4 Likes