堆栈:检测到随机依赖性周期

问题描述

stack.yaml的内容如下:

resolver: lts-16.19

packages:
  - .

extra-deps:
  - text-1.2.4.0
  - random-1.2.0
  - git: https://github.com/LeventErkok/sbv.git # sbv
    commit: 4f4baa7b5970ef2ab9b322c6694bf9df6ccdbc4b
  - git: https://github.com/bos/aeson # aeson
    commit: 8579faf30e0f977425fbf330038fb1d5c2c34727
  - data-fix-0.3.0@sha256:058a266d1e658500e0ffb8babe68195b0ce06a081dcfc3814afc784b083fd9a5,1645
  - strict-0.4@sha256:1b50c7c9c636c3a1bbc7f8873b9be48f6ca0faca4df6eec6a014de6208fb1c0e,4200

test具有以下部分:

executable test
  hs-source-dirs:      src
  main-is:             Main.hs
  default-language:    Haskell2010
  build-depends:       text,random,sbv,aeson,base >= 4.7 && < 5

我添加了textrandom,因为如果不这样做,则在运行stack ghci时会出现以下错误:

Could not load module ‘Data.Text’
Could not load module ‘System.Random’

但是现在,在上面添加了这些软件包的情况下,Stack抱怨循环依赖:

$ stack setup
$ stack ghci

Error: While constructing the build plan,the following exceptions were encountered:

In the dependencies for QuickCheck-2.13.2:
    random dependency cycle detected: random,splitmix,uuid-types,test
needed due to test-0.1.0.0 -> QuickCheck-2.13.2

In the dependencies for test-0.1.0.0:
    random dependency cycle detected: random,test
needed since test is a build target.

Dependency cycle detected in packages:
    [random,test]

In the dependencies for sbv-8.8.5:
    random dependency cycle detected: random,test
needed due to test-0.1.0.0 -> sbv-8.8.5

In the dependencies for splitmix-0.0.5:
    random dependency cycle detected: random,test
needed due to test-0.1.0.0 -> splitmix-0.0.5

Some different approaches to resolving this:


Error: Plan construction failed.

根据错误消息,看起来splitmixrandom之间有一个循环。我只问了random,所以不确定如何解决这个问题。

任何解决此问题并使导入工作的方式都可以避免此循环导入问题,将不胜感激。

解决方法

最新的splitmixlts-16.19快照中的旧版本的splitmix不兼容。在extra-deps中添加新版本的extra-deps: - ... # your other extra-deps - splitmix-0.1.0.3

import numpy as np
import random

data=np.load("olivetti_faces.npy")
target=np.load("olivetti_faces_target.npy")

# target is groups of 10,so select random index in each block
for i in range(40):  # class 0-39
   rndindex.append(i*10 + random.randint(0,9)) # one per class
   
for i in range(60):  # up to 100
   idx = rndindex[0]
   while idx in rndindex:  # prevent duplicates
       idx = random.randint(0,399)  # other indexes can be anywhere
   rndindex.append(idx)

rand_indeces = []  # np array objects
for idx in rndindex:
   rand_indeces.append(data[idx])

print(rndindex)
#print(rand_indeces)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...