-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathUtils.jl
51 lines (42 loc) · 1.25 KB
/
Utils.jl
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#minor utility code that does belong anywhere else
#used in implementation of CSRGraph and CSRMatrix
function computeOffsets(rowPtrs::AbstractArray{<: Integer, 1}, numEnts::Integer)
numOffsets = length(rowPtrs)
@simd for i = 1:numOffsets
@inbounds rowPtrs[i] = numEnts*(i-1)+1
end
rowPtrs
end
function computeOffsets(rowPtrs::AbstractArray{<: Integer, 1}, numEnts::Array{<: Integer, 1})
numOffsets = length(rowPtrs)
numCounts = length(numEnts)
if numCounts >= numOffsets
throw(InvalidArgumentError("length(numEnts) = $numCounts "
* ">= length(rowPtrs) = $numOffsets"))
end
sum = 1
for i = 1:numCounts
@inbounds rowPtrs[i] = sum
@inbounds sum += numEnts[i]
end
@inbounds rowPtrs[numCounts+1:numOffsets] .= sum
sum-1
end
export InvalidArgumentError
"""
InvalidArgumentError(msg)
The values passed as arguments are not valid. Argument `msg`
is a descriptive error string.
"""
struct InvalidArgumentError <: Exception
msg::AbstractString
end
export InvalidStateError
"""
InvalidStateError(msg)
An object is not in a valid state for this method. Argument `msg`
is a descriptive error string.
"""
struct InvalidStateError <: Exception
msg::AbstractString
end