-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
89 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
function operate!!(op, args...) | ||
T = typeof.(args) | ||
if mutability(T[1], op, T...) isa IsMutable | ||
return operate!(op, args...) | ||
else | ||
return op(args...) | ||
end | ||
end | ||
function operate_to!!(output, op, args...) | ||
O = typeof(output) | ||
T = typeof.(args) | ||
if mutability(O, op, T...) isa IsMutable | ||
return operate_to!(output, op, args...) | ||
else | ||
return op(args...) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
function Base.:*(A::Matrix{S}, b::Vector{T}) where {S,T} | ||
c = Vector{U}(undef, size(A, 1)) # What is U ? | ||
return mul_to!(c, A, b) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
function mul!!(a::Rational{S}, b::Rational{T}) | ||
if # S can be mutated to `*(::S, ::T)` | ||
mul!(a.num, b.num) | ||
mul!(a.den, b.den) | ||
return a | ||
else | ||
return a * b | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
struct Rational{T} | ||
num::T | ||
den::T | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
function sum(x::Vector) | ||
acc = zero(eltype(x)) | ||
for el in x | ||
acc = acc + el | ||
end | ||
return acc | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
struct Term{T} | ||
coef::T | ||
sym::SymbolicVariable | ||
end | ||
struct Sum{T} | ||
terms::Vector{Term{T}} | ||
end | ||
Base.:+(s::Sum, t::Term) = Sum(push!(copy(s.terms), t)) | ||
Base.zero(::Type{Term{T}}) where {T} = Sum(Term{T}[]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
function sum(x) | ||
acc = zero(eltype(x)) | ||
for el in x | ||
acc = add!!(acc, el) | ||
end | ||
return acc | ||
end | ||
add!!(a, b) = a + b # default fallback | ||
add!!(a::BigInt, b::BigInt) = Base.GMP.MPZ.add!(a, b) | ||
function add!!(s::Sum, t::Term) | ||
push!(s.terms, t) | ||
return s | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
module Verify | ||
using MutableArithmetics | ||
struct SymbolicVariable end | ||
for file in readdir(@__DIR__) | ||
path = joinpath(@__DIR__, file) | ||
if path != (@__FILE__) && file != "mul.jl" | ||
include(file) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters