Skip to content

Commit

Permalink
Merge pull request #162 from akash-akya/fix-typespec
Browse files Browse the repository at this point in the history
Correct typespecs
  • Loading branch information
akash-akya authored Jul 29, 2024
2 parents e5c2a68 + c2c196d commit 851c69d
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 16 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -150,19 +150,20 @@ jobs:
path: |
deps
_build
priv/plts
key: ${{ runner.os }}-${{ matrix.otp }}-${{ matrix.elixir }}-${{ hashFiles('mix.lock') }}

- name: Install Dependencies
if: steps.mix-cache.outputs.cache-hit != 'true'
run: |
mkdir -p priv/plts
mix deps.get
# mix dialyzer --plt
mix dialyzer --plt
- run: mix deps.get
- run: mix clean && mix deep_clean
- run: mix compile --force --warnings-as-errors
- run: mix deps.unlock --check-unused
- run: mix format --check-formatted
- run: mix credo --strict
# - run: mix dialyzer --plt
- run: mix dialyzer --format github
14 changes: 7 additions & 7 deletions lib/vix/operator.ex
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ defmodule Vix.Operator do

image?(a) && is_list(b) ->
when_number_list b do
Operation.linear!(a, [1], b)
Operation.linear!(a, [1.0], b)
end

true ->
Expand All @@ -189,7 +189,7 @@ defmodule Vix.Operator do

image?(a) && is_list(b) ->
when_number_list b do
Operation.linear!(a, b, [0])
Operation.linear!(a, b, [+0.0])
end

true ->
Expand All @@ -212,12 +212,12 @@ defmodule Vix.Operator do
is_list(a) && image?(b) ->
when_number_list a do
# a - b = (b * -1) + a
Operation.linear!(b, [-1], a)
Operation.linear!(b, [-1.0], a)
end

image?(a) && is_list(b) ->
when_number_list b do
Operation.linear!(a, [1], Enum.map(b, &(-&1)))
Operation.linear!(a, [1.0], Enum.map(b, &(-&1)))
end

true ->
Expand All @@ -241,13 +241,13 @@ defmodule Vix.Operator do
when_number_list a do
# a / b = (b^-1) * a = (1 / b) * a
b
|> Operation.math2_const!(:VIPS_OPERATION_MATH2_POW, [-1])
|> Operation.linear!(a, [0])
|> Operation.math2_const!(:VIPS_OPERATION_MATH2_POW, [-1.0])
|> Operation.linear!(a, [+0.0])
end

image?(a) && is_list(b) ->
when_number_list b do
Operation.linear!(a, Enum.map(b, &(1 / &1)), [0])
Operation.linear!(a, Enum.map(b, &(1 / &1)), [+0.0])
end

true ->
Expand Down
15 changes: 8 additions & 7 deletions lib/vix/vips/image.ex
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ defmodule Vix.Vips.Image do
end

@impl Access
def pop(_image, _band, _default \\ nil) do
def pop(_image, _band) do
raise ArgumentError, "pop/3 for Vix.Vips.Image is not supported."
end

Expand Down Expand Up @@ -818,7 +818,7 @@ defmodule Vix.Vips.Image do
end
end

@spec write_area_to_binary(t(), params :: keyword) :: {:ok, binary()} | {:error, term()}
@spec write_area_to_binary(t(), params :: keyword) :: {:ok, map} | {:error, term()}
defp write_area_to_binary(%Image{ref: vips_image}, params \\ []) do
params =
Enum.map(~w(left top width height band_start band_count)a, fn key ->
Expand Down Expand Up @@ -1040,15 +1040,15 @@ defmodule Vix.Vips.Image do
"xoffset" => quote(do: integer()),
"yoffset" => quote(do: integer()),
"filename" => quote(do: String.t()),
"mode" => quote(do: Stringt.t()),
"mode" => quote(do: String.t()),
"scale" => quote(do: float()),
"offset" => quote(do: float()),
"page-height" => quote(do: integer()),
"n-pages" => quote(do: integer()),
"orientation" => quote(do: integer()),
"interpretation" => quote(do: Vix.Vips.Operation.vips_interpretation()),
"coding" => quote(do: Vix.Vips.Operation.vips_coding()),
"format" => quote(do: Vix.Vips.Operatoin.vips_band_format())
"format" => quote(do: Vix.Vips.Operation.vips_band_format())
} do
func_name = name |> String.replace("-", "_") |> String.to_atom()

Expand Down Expand Up @@ -1085,15 +1085,15 @@ defmodule Vix.Vips.Image do
xoffset: integer() | nil,
yoffset: integer() | nil,
filename: String.t() | nil,
mode: Stringt.t() | nil,
mode: String.t() | nil,
scale: float() | nil,
offset: float() | nil,
"page-height": integer() | nil,
"n-pages": integer() | nil,
orientation: integer() | nil,
interpretation: Vix.Vips.Operation.vips_interpretation() | nil,
coding: Vix.Vips.Operation.vips_coding() | nil,
format: Vix.Vips.Operatoin.vips_band_format() | nil
format: Vix.Vips.Operation.vips_band_format() | nil
}
def headers(image) do
[
Expand Down Expand Up @@ -1158,7 +1158,8 @@ defmodule Vix.Vips.Image do
end

@spec validate_matrix_list([[number]] | [number] | Range.t()) ::
{width :: non_neg_integer(), height :: non_neg_integer(), [number]}
{:ok, {width :: non_neg_integer(), height :: non_neg_integer(), [number]}}
| {:error, term}
defp validate_matrix_list(list) do
list = normalize_list(list)

Expand Down
2 changes: 2 additions & 0 deletions lib/vix/vips/mutable_operation.ex
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ defmodule Vix.Vips.MutableOperation do
)
)
if in_opt_spec == [] do
@dialyzer {:no_match, [{bang_func_name, length(req_params)}]}
# operations without optional arguments
def unquote(bang_func_name)(unquote_splicing(req_params)) do
case __MODULE__.unquote(func_name)(unquote_splicing(req_params)) do
Expand All @@ -107,6 +108,7 @@ defmodule Vix.Vips.MutableOperation do
end
end
else
@dialyzer {:no_match, [{bang_func_name, length(req_params) + 1}]}
# operations with optional arguments
def unquote(bang_func_name)(unquote_splicing(req_params), optional \\ []) do
case __MODULE__.unquote(func_name)(unquote_splicing(req_params), optional) do
Expand Down
2 changes: 2 additions & 0 deletions lib/vix/vips/operation.ex
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ defmodule Vix.Vips.Operation do
)
)
if in_opt_spec == [] do
@dialyzer {:no_match, [{bang_func_name, length(req_params)}]}
# operations without optional arguments
def unquote(bang_func_name)(unquote_splicing(req_params)) do
case __MODULE__.unquote(func_name)(unquote_splicing(req_params)) do
Expand All @@ -87,6 +88,7 @@ defmodule Vix.Vips.Operation do
end
end
else
@dialyzer {:no_match, [{bang_func_name, length(req_params) + 1}]}
# operations with optional arguments
def unquote(bang_func_name)(unquote_splicing(req_params), optional \\ []) do
case __MODULE__.unquote(func_name)(unquote_splicing(req_params), optional) do
Expand Down

0 comments on commit 851c69d

Please sign in to comment.